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.
getCodeCompleteLoc()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.
codeCompleteOperationAttributeName(StringRef opName)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.
codeCompleteDialectName()61   virtual void codeCompleteDialectName() {}
62 
63   /// Signal code completion for an operation name in the given dialect.
codeCompleteOperationName(StringRef dialectName)64   virtual void codeCompleteOperationName(StringRef dialectName) {}
65 
66   /// Signal code completion for Pattern metadata.
codeCompletePatternMetadata()67   virtual void codeCompletePatternMetadata() {}
68 
69   /// Signal code completion for an include filename.
codeCompleteIncludeFilename(StringRef curPath)70   virtual void codeCompleteIncludeFilename(StringRef curPath) {}
71 
72   //===--------------------------------------------------------------------===//
73   // Signature Hooks
74   //===--------------------------------------------------------------------===//
75 
76   /// Signal code completion for the signature of a callable.
codeCompleteCallSignature(const ast::CallableDecl * callable,unsigned currentNumArgs)77   virtual void codeCompleteCallSignature(const ast::CallableDecl *callable,
78                                          unsigned currentNumArgs) {}
79 
80   /// Signal code completion for the signature of an operation's operands.
81   virtual void
codeCompleteOperationOperandsSignature(Optional<StringRef> opName,unsigned currentNumOperands)82   codeCompleteOperationOperandsSignature(Optional<StringRef> opName,
83                                          unsigned currentNumOperands) {}
84 
85   /// Signal code completion for the signature of an operation's results.
86   virtual void
codeCompleteOperationResultsSignature(Optional<StringRef> opName,unsigned currentNumResults)87   codeCompleteOperationResultsSignature(Optional<StringRef> opName,
88                                         unsigned currentNumResults) {}
89 
90 protected:
91   /// Create a new code completion context with the given code complete
92   /// location.
CodeCompleteContext(SMLoc codeCompleteLoc)93   explicit CodeCompleteContext(SMLoc codeCompleteLoc)
94       : codeCompleteLoc(codeCompleteLoc) {}
95 
96 private:
97   /// The location used to code complete.
98   SMLoc codeCompleteLoc;
99 };
100 } // namespace pdll
101 } // namespace mlir
102 
103 #endif // MLIR_TOOLS_PDLL_PARSER_CODECOMPLETE_H_
104