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 #include <optional> 15 16 namespace mlir { 17 namespace pdll { 18 namespace ast { 19 class CallableDecl; 20 class DeclScope; 21 class Expr; 22 class OperationType; 23 class TupleType; 24 class Type; 25 class VariableDecl; 26 } // namespace ast 27 28 /// This class provides an abstract interface into the parser for hooking in 29 /// code completion events. 30 class CodeCompleteContext { 31 public: 32 virtual ~CodeCompleteContext(); 33 34 /// Return the location used to provide code completion. getCodeCompleteLoc()35 SMLoc getCodeCompleteLoc() const { return codeCompleteLoc; } 36 37 //===--------------------------------------------------------------------===// 38 // Completion Hooks 39 //===--------------------------------------------------------------------===// 40 41 /// Signal code completion for a member access into the given tuple type. 42 virtual void codeCompleteTupleMemberAccess(ast::TupleType tupleType); 43 44 /// Signal code completion for a member access into the given operation type. 45 virtual void codeCompleteOperationMemberAccess(ast::OperationType opType); 46 47 /// Signal code completion for a member access into the given operation type. codeCompleteOperationAttributeName(StringRef opName)48 virtual void codeCompleteOperationAttributeName(StringRef opName) {} 49 50 /// Signal code completion for a constraint name with an optional decl scope. 51 /// `currentType` is the current type of the variable that will use the 52 /// constraint, or nullptr if a type is unknown. `allowInlineTypeConstraints` 53 /// enables inline type constraints for Attr/Value/ValueRange. 54 virtual void codeCompleteConstraintName(ast::Type currentType, 55 bool allowInlineTypeConstraints, 56 const ast::DeclScope *scope); 57 58 /// Signal code completion for a dialect name. codeCompleteDialectName()59 virtual void codeCompleteDialectName() {} 60 61 /// Signal code completion for an operation name in the given dialect. codeCompleteOperationName(StringRef dialectName)62 virtual void codeCompleteOperationName(StringRef dialectName) {} 63 64 /// Signal code completion for Pattern metadata. codeCompletePatternMetadata()65 virtual void codeCompletePatternMetadata() {} 66 67 /// Signal code completion for an include filename. codeCompleteIncludeFilename(StringRef curPath)68 virtual void codeCompleteIncludeFilename(StringRef curPath) {} 69 70 //===--------------------------------------------------------------------===// 71 // Signature Hooks 72 //===--------------------------------------------------------------------===// 73 74 /// Signal code completion for the signature of a callable. codeCompleteCallSignature(const ast::CallableDecl * callable,unsigned currentNumArgs)75 virtual void codeCompleteCallSignature(const ast::CallableDecl *callable, 76 unsigned currentNumArgs) {} 77 78 /// Signal code completion for the signature of an operation's operands. 79 virtual void codeCompleteOperationOperandsSignature(std::optional<StringRef> opName,unsigned currentNumOperands)80 codeCompleteOperationOperandsSignature(std::optional<StringRef> opName, 81 unsigned currentNumOperands) {} 82 83 /// Signal code completion for the signature of an operation's results. 84 virtual void codeCompleteOperationResultsSignature(std::optional<StringRef> opName,unsigned currentNumResults)85 codeCompleteOperationResultsSignature(std::optional<StringRef> opName, 86 unsigned currentNumResults) {} 87 88 protected: 89 /// Create a new code completion context with the given code complete 90 /// location. CodeCompleteContext(SMLoc codeCompleteLoc)91 explicit CodeCompleteContext(SMLoc codeCompleteLoc) 92 : codeCompleteLoc(codeCompleteLoc) {} 93 94 private: 95 /// The location used to code complete. 96 SMLoc codeCompleteLoc; 97 }; 98 } // namespace pdll 99 } // namespace mlir 100 101 #endif // MLIR_TOOLS_PDLL_PARSER_CODECOMPLETE_H_ 102