diff options
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/Sema/CodeCompleteConsumer.h')
-rw-r--r-- | contrib/llvm-project/clang/include/clang/Sema/CodeCompleteConsumer.h | 146 |
1 files changed, 118 insertions, 28 deletions
diff --git a/contrib/llvm-project/clang/include/clang/Sema/CodeCompleteConsumer.h b/contrib/llvm-project/clang/include/clang/Sema/CodeCompleteConsumer.h index 87646ab95025..274eaac819af 100644 --- a/contrib/llvm-project/clang/include/clang/Sema/CodeCompleteConsumer.h +++ b/contrib/llvm-project/clang/include/clang/Sema/CodeCompleteConsumer.h @@ -21,8 +21,6 @@ #include "clang/Sema/DeclSpec.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/None.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" @@ -30,6 +28,7 @@ #include "llvm/Support/type_traits.h" #include <cassert> #include <memory> +#include <optional> #include <string> #include <utility> @@ -329,9 +328,20 @@ public: /// Code completion inside the filename part of a #include directive. CCC_IncludedFile, + /// Code completion of an attribute name. + CCC_Attribute, + /// An unknown context, in which we are recovering from a parsing /// error and don't know which completions we should give. - CCC_Recovery + CCC_Recovery, + + /// Code completion in a @class forward declaration. + CCC_ObjCClassForwardDecl, + + /// Code completion at a top level, i.e. in a namespace or global scope, + /// but also in expression statements. This is because REPL inputs can be + /// declarations or expression statements. + CCC_TopLevelOrExpression, }; using VisitedContextSet = llvm::SmallPtrSet<DeclContext *, 8>; @@ -356,7 +366,7 @@ private: /// The scope specifier that comes before the completion token e.g. /// "a::b::" - llvm::Optional<CXXScopeSpec> ScopeSpecifier; + std::optional<CXXScopeSpec> ScopeSpecifier; /// A set of declaration contexts visited by Sema when doing lookup for /// code completion. @@ -365,11 +375,11 @@ private: public: /// Construct a new code-completion context of the given kind. CodeCompletionContext(Kind CCKind) - : CCKind(CCKind), IsUsingDeclaration(false), SelIdents(None) {} + : CCKind(CCKind), IsUsingDeclaration(false), SelIdents(std::nullopt) {} /// Construct a new code-completion context of the given kind. CodeCompletionContext(Kind CCKind, QualType T, - ArrayRef<IdentifierInfo *> SelIdents = None) + ArrayRef<IdentifierInfo *> SelIdents = std::nullopt) : CCKind(CCKind), IsUsingDeclaration(false), SelIdents(SelIdents) { if (CCKind == CCC_DotMemberAccess || CCKind == CCC_ArrowMemberAccess || CCKind == CCC_ObjCPropertyAccess || CCKind == CCC_ObjCClassMessage || @@ -419,14 +429,14 @@ public: return VisitedContexts; } - llvm::Optional<const CXXScopeSpec *> getCXXScopeSpecifier() { + std::optional<const CXXScopeSpec *> getCXXScopeSpecifier() { if (ScopeSpecifier) - return ScopeSpecifier.getPointer(); - return llvm::None; + return &*ScopeSpecifier; + return std::nullopt; } }; -/// Get string representation of \p Kind, useful for for debugging. +/// Get string representation of \p Kind, useful for debugging. llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind); /// A "string" used to describe how code completion can @@ -603,9 +613,12 @@ public: return begin()[I]; } - /// Returns the text in the TypedText chunk. + /// Returns the text in the first TypedText chunk. const char *getTypedText() const; + /// Returns the combined text from all TypedText chunks. + std::string getAllTypedText() const; + /// Retrieve the priority of this code completion result. unsigned getPriority() const { return Priority; } @@ -844,6 +857,12 @@ public: /// rather than a use of that entity. bool DeclaringEntity : 1; + /// When completing a function, whether it can be a call. This will usually be + /// true, but we have some heuristics, e.g. when a pointer to a non-static + /// member function is completed outside of that class' scope, it can never + /// be a call. + bool FunctionCanBeCall : 1; + /// If the result should have a nested-name-specifier, this is it. /// When \c QualifierIsInformative, the nested-name-specifier is /// informative rather than required. @@ -870,7 +889,7 @@ public: FixIts(std::move(FixIts)), Hidden(false), InBaseClass(false), QualifierIsInformative(QualifierIsInformative), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false), Qualifier(Qualifier) { + DeclaringEntity(false), FunctionCanBeCall(true), Qualifier(Qualifier) { // FIXME: Add assert to check FixIts range requirements. computeCursorKindAndAvailability(Accessible); } @@ -880,7 +899,8 @@ public: : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword), CursorKind(CXCursor_NotImplemented), Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), - AllParametersAreInformative(false), DeclaringEntity(false) {} + AllParametersAreInformative(false), DeclaringEntity(false), + FunctionCanBeCall(true) {} /// Build a result that refers to a macro. CodeCompletionResult(const IdentifierInfo *Macro, @@ -890,7 +910,7 @@ public: CursorKind(CXCursor_MacroDefinition), Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), DeclaringEntity(false), - MacroDefInfo(MI) {} + FunctionCanBeCall(true), MacroDefInfo(MI) {} /// Build a result that refers to a pattern. CodeCompletionResult( @@ -902,7 +922,7 @@ public: CursorKind(CursorKind), Availability(Availability), Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false) {} + DeclaringEntity(false), FunctionCanBeCall(true) {} /// Build a result that refers to a pattern with an associated /// declaration. @@ -911,7 +931,7 @@ public: : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern), Hidden(false), InBaseClass(false), QualifierIsInformative(false), StartsNestedNameSpecifier(false), AllParametersAreInformative(false), - DeclaringEntity(false) { + DeclaringEntity(false), FunctionCanBeCall(true) { computeCursorKindAndAvailability(); } @@ -1006,12 +1026,22 @@ public: /// The candidate is a function declaration. CK_Function, - /// The candidate is a function template. + /// The candidate is a function template, arguments are being completed. CK_FunctionTemplate, /// The "candidate" is actually a variable, expression, or block /// for which we only have a function prototype. - CK_FunctionType + CK_FunctionType, + + /// The candidate is a variable or expression of function type + /// for which we have the location of the prototype declaration. + CK_FunctionProtoTypeLoc, + + /// The candidate is a template, template arguments are being completed. + CK_Template, + + /// The candidate is aggregate initialization of a record type. + CK_Aggregate, }; private: @@ -1030,17 +1060,48 @@ public: /// The function type that describes the entity being called, /// when Kind == CK_FunctionType. const FunctionType *Type; + + /// The location of the function prototype that describes the entity being + /// called, when Kind == CK_FunctionProtoTypeLoc. + FunctionProtoTypeLoc ProtoTypeLoc; + + /// The template overload candidate, available when + /// Kind == CK_Template. + const TemplateDecl *Template; + + /// The class being aggregate-initialized, + /// when Kind == CK_Aggregate + const RecordDecl *AggregateType; }; public: OverloadCandidate(FunctionDecl *Function) - : Kind(CK_Function), Function(Function) {} + : Kind(CK_Function), Function(Function) { + assert(Function != nullptr); + } OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl) - : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {} + : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) { + assert(FunctionTemplateDecl != nullptr); + } OverloadCandidate(const FunctionType *Type) - : Kind(CK_FunctionType), Type(Type) {} + : Kind(CK_FunctionType), Type(Type) { + assert(Type != nullptr); + } + + OverloadCandidate(FunctionProtoTypeLoc Prototype) + : Kind(CK_FunctionProtoTypeLoc), ProtoTypeLoc(Prototype) { + assert(!Prototype.isNull()); + } + + OverloadCandidate(const RecordDecl *Aggregate) + : Kind(CK_Aggregate), AggregateType(Aggregate) { + assert(Aggregate != nullptr); + } + + OverloadCandidate(const TemplateDecl *Template) + : Kind(CK_Template), Template(Template) {} /// Determine the kind of overload candidate. CandidateKind getKind() const { return Kind; } @@ -1059,13 +1120,40 @@ public: /// function is stored. const FunctionType *getFunctionType() const; + /// Retrieve the function ProtoTypeLoc candidate. + /// This can be called for any Kind, but returns null for kinds + /// other than CK_FunctionProtoTypeLoc. + const FunctionProtoTypeLoc getFunctionProtoTypeLoc() const; + + const TemplateDecl *getTemplate() const { + assert(getKind() == CK_Template && "Not a template"); + return Template; + } + + /// Retrieve the aggregate type being initialized. + const RecordDecl *getAggregate() const { + assert(getKind() == CK_Aggregate); + return AggregateType; + } + + /// Get the number of parameters in this signature. + unsigned getNumParams() const; + + /// Get the type of the Nth parameter. + /// Returns null if the type is unknown or N is out of range. + QualType getParamType(unsigned N) const; + + /// Get the declaration of the Nth parameter. + /// Returns null if the decl is unknown or N is out of range. + const NamedDecl *getParamDecl(unsigned N) const; + /// Create a new code-completion string that describes the function /// signature of this overload candidate. - CodeCompletionString *CreateSignatureString(unsigned CurrentArg, - Sema &S, - CodeCompletionAllocator &Allocator, - CodeCompletionTUInfo &CCTUInfo, - bool IncludeBriefComments) const; + CodeCompletionString * + CreateSignatureString(unsigned CurrentArg, Sema &S, + CodeCompletionAllocator &Allocator, + CodeCompletionTUInfo &CCTUInfo, + bool IncludeBriefComments, bool Braced) const; }; CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts) @@ -1139,7 +1227,8 @@ public: virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, - SourceLocation OpenParLoc) {} + SourceLocation OpenParLoc, + bool Braced) {} //@} /// Retrieve the allocator that will be used to allocate @@ -1190,7 +1279,8 @@ public: void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, - SourceLocation OpenParLoc) override; + SourceLocation OpenParLoc, + bool Braced) override; bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results) override; |