MLIR  20.0.0git
CodeComplete.h
Go to the documentation of this file.
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.
31 public:
33 
34  /// Return the location used to provide code completion.
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.
46 
47  /// Signal code completion for a member access into the given operation type.
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.
59  virtual void codeCompleteDialectName() {}
60 
61  /// Signal code completion for an operation name in the given dialect.
62  virtual void codeCompleteOperationName(StringRef dialectName) {}
63 
64  /// Signal code completion for Pattern metadata.
65  virtual void codeCompletePatternMetadata() {}
66 
67  /// Signal code completion for an include filename.
68  virtual void codeCompleteIncludeFilename(StringRef curPath) {}
69 
70  //===--------------------------------------------------------------------===//
71  // Signature Hooks
72  //===--------------------------------------------------------------------===//
73 
74  /// Signal code completion for the signature of a callable.
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
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
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.
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_
This class provides an abstract interface into the parser for hooking in code completion events.
Definition: CodeComplete.h:30
virtual void codeCompleteConstraintName(ast::Type currentType, bool allowInlineTypeConstraints, const ast::DeclScope *scope)
Signal code completion for a constraint name with an optional decl scope.
CodeCompleteContext(SMLoc codeCompleteLoc)
Create a new code completion context with the given code complete location.
Definition: CodeComplete.h:91
virtual void codeCompleteOperationAttributeName(StringRef opName)
Signal code completion for a member access into the given operation type.
Definition: CodeComplete.h:48
virtual void codeCompleteOperationOperandsSignature(std::optional< StringRef > opName, unsigned currentNumOperands)
Signal code completion for the signature of an operation's operands.
Definition: CodeComplete.h:80
virtual void codeCompleteOperationName(StringRef dialectName)
Signal code completion for an operation name in the given dialect.
Definition: CodeComplete.h:62
virtual void codeCompleteOperationResultsSignature(std::optional< StringRef > opName, unsigned currentNumResults)
Signal code completion for the signature of an operation's results.
Definition: CodeComplete.h:85
virtual void codeCompleteDialectName()
Signal code completion for a dialect name.
Definition: CodeComplete.h:59
SMLoc getCodeCompleteLoc() const
Return the location used to provide code completion.
Definition: CodeComplete.h:35
virtual void codeCompleteOperationMemberAccess(ast::OperationType opType)
Signal code completion for a member access into the given operation type.
virtual void codeCompleteTupleMemberAccess(ast::TupleType tupleType)
Signal code completion for a member access into the given tuple type.
virtual void codeCompletePatternMetadata()
Signal code completion for Pattern metadata.
Definition: CodeComplete.h:65
virtual void codeCompleteCallSignature(const ast::CallableDecl *callable, unsigned currentNumArgs)
Signal code completion for the signature of a callable.
Definition: CodeComplete.h:75
virtual void codeCompleteIncludeFilename(StringRef curPath)
Signal code completion for an include filename.
Definition: CodeComplete.h:68
This decl represents a shared interface for all callable decls.
Definition: Nodes.h:1188
This class represents a scope for named AST decls.
Definition: Nodes.h:64
This class represents a PDLL type that corresponds to an mlir::Operation.
Definition: Types.h:163
This class represents a PDLL tuple type, i.e.
Definition: Types.h:249
@ Type
An inlay hint that for a type annotation.
Include the generated interface declarations.