1 //===- CodeComplete.h - PDLL Frontend CodeComplete Context ------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_TOOLS_PDLL_PARSER_CODECOMPLETE_H_
10 #define MLIR_TOOLS_PDLL_PARSER_CODECOMPLETE_H_
11 
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/Support/SourceMgr.h"
14 
15 namespace mlir {
16 namespace pdll {
17 namespace ast {
18 class CallableDecl;
19 class DeclScope;
20 class Expr;
21 class OperationType;
22 class TupleType;
23 class Type;
24 class VariableDecl;
25 } // namespace ast
26 
27 /// This class provides an abstract interface into the parser for hooking in
28 /// code completion events.
29 class CodeCompleteContext {
30 public:
31   virtual ~CodeCompleteContext();
32 
33   /// Return the location used to provide code completion.
34   SMLoc getCodeCompleteLoc() const { return codeCompleteLoc; }
35 
36   //===--------------------------------------------------------------------===//
37   // Completion Hooks
38   //===--------------------------------------------------------------------===//
39 
40   /// Signal code completion for a member access into the given tuple type.
41   virtual void codeCompleteTupleMemberAccess(ast::TupleType tupleType);
42 
43   /// Signal code completion for a member access into the given operation type.
44   virtual void codeCompleteOperationMemberAccess(ast::OperationType opType);
45 
46   /// Signal code completion for a member access into the given operation type.
47   virtual void codeCompleteOperationAttributeName(StringRef opName) {}
48 
49   /// Signal code completion for a constraint name with an optional decl scope.
50   /// `currentType` is the current type of the variable that will use the
51   /// constraint, or nullptr if a type is unknown. `allowNonCoreConstraints`
52   /// indicates if user defined constraints are allowed in the completion
53   /// results. `allowInlineTypeConstraints` enables inline type constraints for
54   /// Attr/Value/ValueRange.
55   virtual void codeCompleteConstraintName(ast::Type currentType,
56                                           bool allowNonCoreConstraints,
57                                           bool allowInlineTypeConstraints,
58                                           const ast::DeclScope *scope);
59 
60   /// Signal code completion for a dialect name.
61   virtual void codeCompleteDialectName() {}
62 
63   /// Signal code completion for an operation name in the given dialect.
64   virtual void codeCompleteOperationName(StringRef dialectName) {}
65 
66   /// Signal code completion for Pattern metadata.
67   virtual void codeCompletePatternMetadata() {}
68 
69   //===--------------------------------------------------------------------===//
70   // Signature Hooks
71   //===--------------------------------------------------------------------===//
72 
73   /// Signal code completion for the signature of a callable.
74   virtual void codeCompleteCallSignature(const ast::CallableDecl *callable,
75                                          unsigned currentNumArgs) {}
76 
77   /// Signal code completion for the signature of an operation's operands.
78   virtual void
79   codeCompleteOperationOperandsSignature(Optional<StringRef> opName,
80                                          unsigned currentNumOperands) {}
81 
82   /// Signal code completion for the signature of an operation's results.
83   virtual void
84   codeCompleteOperationResultsSignature(Optional<StringRef> opName,
85                                         unsigned currentNumResults) {}
86 
87 protected:
88   /// Create a new code completion context with the given code complete
89   /// location.
90   explicit CodeCompleteContext(SMLoc codeCompleteLoc)
91       : codeCompleteLoc(codeCompleteLoc) {}
92 
93 private:
94   /// The location used to code complete.
95   SMLoc codeCompleteLoc;
96 };
97 } // namespace pdll
98 } // namespace mlir
99 
100 #endif // MLIR_TOOLS_PDLL_PARSER_CODECOMPLETE_H_
101