13 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 14 #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 22 #include "llvm/ADT/ArrayRef.h" 23 #include "llvm/ADT/DenseMap.h" 24 #include "llvm/ADT/None.h" 25 #include "llvm/ADT/Optional.h" 26 #include "llvm/ADT/SmallPtrSet.h" 27 #include "llvm/ADT/SmallVector.h" 28 #include "llvm/ADT/StringRef.h" 29 #include "llvm/Support/Allocator.h" 30 #include "llvm/Support/type_traits.h" 42 class FunctionTemplateDecl;
46 class NestedNameSpecifier;
50 class UsingShadowDecl;
179 bool PreferredTypeIsPointer =
false);
345 bool IsUsingDeclaration;
368 : CCKind(CCKind), IsUsingDeclaration(
false), SelIdents(
None) {}
373 : CCKind(CCKind), IsUsingDeclaration(
false), SelIdents(SelIdents) {
409 this->ScopeSpecifier = std::move(SS);
414 VisitedContexts.insert(Ctx);
419 return VisitedContexts;
424 return ScopeSpecifier.getPointer();
542 static Chunk CreateText(
const char *
Text);
548 static Chunk CreatePlaceholder(
const char *Placeholder);
551 static Chunk CreateInformative(
const char *Informative);
554 static Chunk CreateResultType(
const char *ResultType);
557 static Chunk CreateCurrentParameter(
const char *CurrentParameter);
565 unsigned NumChunks : 16;
568 unsigned NumAnnotations : 16;
574 unsigned Availability : 2;
577 StringRef ParentName;
581 const char *BriefComment;
585 const char **Annotations,
unsigned NumAnnotations,
586 StringRef ParentName,
587 const char *BriefComment);
598 bool empty()
const {
return NumChunks == 0; }
599 unsigned size()
const {
return NumChunks; }
602 assert(I < size() &&
"Chunk index out-of-range");
607 const char *getTypedText()
const;
616 unsigned getAnnotationCount()
const;
619 const char *getAnnotation(
unsigned AnnotationNr)
const;
639 const char *CopyString(
const Twine &String);
646 llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
647 std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
651 std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
652 : AllocatorRef(
std::move(Allocator)) {}
659 assert(AllocatorRef);
660 return *AllocatorRef;
680 StringRef ParentName;
681 const char *BriefComment =
nullptr;
691 : Allocator(Allocator), CCTUInfo(CCTUInfo) {}
696 : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),
697 Availability(Availability) {}
711 void AddTypedTextChunk(
const char *
Text);
714 void AddTextChunk(
const char *Text);
720 void AddPlaceholderChunk(
const char *Placeholder);
723 void AddInformativeChunk(
const char *Text);
729 void AddCurrentParameterChunk(
const char *CurrentParameter);
740 void addBriefComment(StringRef Comment);
785 unsigned StartParameter = 0;
866 bool QualifierIsInformative =
false,
867 bool Accessible =
true,
868 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
869 : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
870 FixIts(
std::move(FixIts)), Hidden(
false), InBaseClass(
false),
871 QualifierIsInformative(QualifierIsInformative),
872 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
873 DeclaringEntity(
false), Qualifier(Qualifier) {
875 computeCursorKindAndAvailability(Accessible);
880 : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
882 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
883 AllParametersAreInformative(
false), DeclaringEntity(
false) {}
889 : Macro(Macro), Priority(Priority), Kind(RK_Macro),
891 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
892 AllParametersAreInformative(
false), DeclaringEntity(
false),
901 : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
902 CursorKind(CursorKind), Availability(Availability), Hidden(
false),
903 InBaseClass(
false), QualifierIsInformative(
false),
904 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
905 DeclaringEntity(
false) {}
911 : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
913 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
914 DeclaringEntity(
false) {
915 computeCursorKindAndAvailability();
921 assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) &&
922 "Not a declaration or pattern result");
928 assert(Kind == RK_Keyword &&
"Not a keyword result");
943 bool IncludeBriefComments);
949 bool IncludeBriefComments);
972 StringRef getOrderedName(std::string &Saved)
const;
975 void computeCursorKindAndAvailability(
bool Accessible =
true);
1040 : Kind(CK_Function), Function(Function) {}
1043 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {}
1046 : Kind(CK_FunctionType), Type(Type) {}
1057 assert(
getKind() == CK_FunctionTemplate &&
"Not a function template");
1058 return FunctionTemplate;
1071 bool IncludeBriefComments)
const;
1075 : CodeCompleteOpts(CodeCompleteOpts) {}
1129 unsigned NumResults) {}
1144 unsigned NumCandidates,
1191 unsigned NumResults)
override;
1193 void ProcessOverloadCandidates(
Sema &S,
unsigned CurrentArg,
1195 unsigned NumCandidates,
1209 #endif // LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H One piece of the code completion string.
An unknown context, in which we are recovering from a parsing error and don't know which completions ...
A code completion string that is entirely optional.
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
CodeCompletionAllocator & getAllocator() const
Represents a function declaration or definition.
llvm::SmallPtrSet< DeclContext *, 8 > VisitedContextSet
ResultKind Kind
The kind of result stored here.
std::vector< FixItHint > FixIts
Fix-its that must be applied before inserting the text for the corresponding completion.
const FunctionType * Type
The function type that describes the entity being called, when Kind == CK_FunctionType.
CXCursorKind CursorKind
The cursor kind that describes this result.
Divide by this factor when a code-completion result's type is similar to the type we expect (e...
A (possibly-)qualified type.
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
Priority for a declaration that is in the local scope.
llvm::Optional< const CXXScopeSpec * > getCXXScopeSpecifier()
Code completion for a selector, as in an @selector expression.
Code completion occurred where an existing name(such as type, function or variable) is expected...
unsigned IncludeGlobals
Show top-level decls in code completion results.
unsigned getMacroUsagePriority(StringRef MacroName, const LangOptions &LangOpts, bool PreferredTypeIsPointer=false)
Determine the priority to be given to a macro code completion result with the given name...
Code completion where an Objective-C class message is expected.
FunctionType - C99 6.7.5.3 - Function Declarators.
CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority, NestedNameSpecifier *Qualifier=nullptr, bool QualifierIsInformative=false, bool Accessible=true, std::vector< FixItHint > FixIts=std::vector< FixItHint >())
Build a result that refers to a declaration.
C Language Family Type Representation.
Code completion within a type-qualifier list.
static void AddResultTypeChunk(ASTContext &Context, const PrintingPolicy &Policy, const NamedDecl *ND, QualType BaseType, CodeCompletionBuilder &Result)
If the given declaration has an associated type, add it as a result type chunk.
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
Decl - This represents one declaration (or definition), e.g.
CandidateKind
Describes the type of overload candidate.
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
Defines the clang::MacroInfo and clang::MacroDirective classes.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
The base class of the type hierarchy.
An unspecified code-completion context.
Allocator for a cached set of global code completions.
Priority for an enumeration constant inside a switch whose condition is of the enumeration type...
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
bool loadExternal() const
Hint whether to load data from the external AST in order to provide full results. ...
Code completion occurred where an Objective-C message receiver is expected.
The candidate is a function template.
unsigned Priority
The priority of this particular code-completion result.
void setPreferredType(QualType T)
Code completion occurred on the right-hand side of a member access expression using the arrow operato...
ChunkKind
The different kinds of "chunks" that can occur within a code completion string.
Code completion occurred after the "enum" keyword, to indicate an enumeration name.
Priority for a send-to-super completion.
A left bracket ('[').
A piece of text that describes the type of an entity or, for functions and methods, the return type.
bool StartsNestedNameSpecifier
Whether this declaration is the beginning of a nested-name-specifier and, therefore, should be followed by '::'.
const char * Keyword
When Kind == RK_Keyword, the string representing the keyword or symbol's spelling.
Code completion occurred within the instance variable list of an Objective-C interface, implementation, or category implementation.
Describes how types, statements, expressions, and declarations should be printed. ...
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability)
Priority for a preprocessor macro.
Code completion occurred where both a new name and an existing symbol is permissible.
void setIsUsingDeclaration(bool V)
One of these records is kept for each identifier that is lexed.
OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
CodeCompletionResult(const IdentifierInfo *Macro, const MacroInfo *MI=nullptr, unsigned Priority=CCP_Macro)
Build a result that refers to a macro.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A "string" used to describe how code completion can be performed for an entity.
Priority for the next initialization in a constructor initializer list.
Adjustment for KVC code pattern priorities when it doesn't look like the.
An Objective-C method being used as a property.
Kind getKind() const
Retrieve the kind of code-completion context.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool isUsingDeclaration() const
OverloadCandidate(const FunctionType *Type)
Priority for a code pattern.
unsigned IncludeCodePatterns
Show code patterns in code completion results.
An allocator used specifically for the purpose of code completion.
CodeCompletionString * Pattern
When Kind == RK_Pattern, the code-completion string that describes the completion text to insert...
The result is in a base class.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Code completion occurred where a preprocessor directive is expected.
Code completion occurred within an Objective-C implementation or category implementation.
Priority for a nested-name-specifier.
bool QualifierIsInformative
Whether this result was found via lookup into a base class.
FunctionTemplateDecl * FunctionTemplate
The function template overload candidate, available when Kind == CK_FunctionTemplate.
QualType getDeclUsageType(ASTContext &C, const NamedDecl *ND)
Determine the type that this declaration will have if it is used as a type or in an expression...
Code completion occurred where a namespace or namespace alias is expected.
Represents a C++ nested-name-specifier or a global scope specifier.
Priority for a non-type declaration.
Priority for a constant value (e.g., enumerator).
A right brace ('}').
The piece of text that the user is expected to type to match the code-completion string, typically a keyword or the name of a declarator or macro.
A comma separator (',').
bool wantConstructorResults() const
Determines whether we want C++ constructors as results within this context.
Refers to a keyword or symbol.
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates, SourceLocation OpenParLoc)
CXCursorKind
Describes the kind of entity that a cursor refers to.
FunctionTemplateDecl * getFunctionTemplate() const
Retrieve the function template overload candidate.
CodeCompletionAllocator & getAllocator() const
Retrieve the allocator into which the code completion strings should be allocated.
A right parenthesis (')').
Code completion where an Objective-C category name is expected.
Sema - This implements semantic analysis and AST building for C.
Code completion occurred within a "top-level" completion context, e.g., at namespace or global scope...
Priority for a member declaration found from the current method or member function.
Divide by this factor when a code-completion result's type exactly matches the type we expect...
Priority for the Objective-C "_cmd" implicit parameter.
CodeCompletionTUInfo & getCodeCompletionTUInfo() override
Code completion occurred where a protocol name is expected.
CXCursorKind getCursorKindForDecl(const Decl *D)
Determine the libclang cursor kind associated with the given declaration.
const RawComment * getCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Declaration...
A simple code-completion consumer that prints the results it receives in a simple format...
QualType getPreferredType() const
Retrieve the type that this expression would prefer to have, e.g., if the expression is a variable in...
llvm::StringRef getCompletionKindString(CodeCompletionContext::Kind Kind)
Get string representation of Kind, useful for for debugging.
llvm::StringRef getAsString(SyncScope S)
CodeCompletionResult(CodeCompletionString *Pattern, const NamedDecl *D, unsigned Priority)
Build a result that refers to a pattern with an associated declaration.
const char * Text
The text string associated with a CK_Text, CK_Placeholder, CK_Informative, or CK_Comma chunk...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults)
Process the finalized code-completion results.
void addVisitedContext(DeclContext *Ctx)
Adds a visited context.
unsigned IncludeNamespaceLevelDecls
Show decls in namespace (including the global namespace) in code completion results.
A semicolon (';').
Captures a result of code completion.
ArrayRef< IdentifierInfo * > getSelIdents() const
Retrieve the Objective-C selector identifiers.
CodeCompletionContext(Kind CCKind)
Construct a new code-completion context of the given kind.
std::shared_ptr< GlobalCodeCompletionAllocator > getAllocatorRef() const
Code completion in a parenthesized expression, which means that we may also have types here in C and ...
Code completion occurred in a context where natural language is expected, e.g., a comment or string l...
virtual bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results)
FunctionDecl * Function
The function overload candidate, available when Kind == CK_Function.
A piece of text that should be placed in the buffer, e.g., parentheses or a comma in a function call...
The result type of a method or function.
StringRef getParentContextName() const
Retrieve the name of the parent context.
CandidateKind getKind() const
Determine the kind of overload candidate.
CodeCompletionString * Optional
The code completion string associated with a CK_Optional chunk.
The context in which code completion occurred, so that the code-completion consumer can process the r...
const IdentifierInfo * Macro
When Kind == RK_Macro, the identifier that refers to a macro.
PrintingCodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, raw_ostream &OS)
Create a new printing code-completion consumer that prints its results to the given raw output stream...
Code completion occurred within a class, struct, or union.
const VisitedContextSet & getVisitedContexts() const
Retrieves all visited contexts.
Encodes a location in the source.
Code completion occurred where a new name is expected.
const char * getBriefComment() const
Code completion where the name of an Objective-C class is expected.
const Chunk & operator[](unsigned I) const
The selector of the given message exactly matches the selector of the current method, which might imply that some kind of delegation is occurring.
Code completion occurred within an Objective-C interface, protocol, or category interface.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A right bracket (']').
Represents a canonical, potentially-qualified type.
An Objective-C block property completed as a setter with a block placeholder.
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
const RawComment * getParameterComment(const ASTContext &Ctx, const CodeCompleteConsumer::OverloadCandidate &Result, unsigned ArgIndex)
Get the documentation comment used to produce CodeCompletionString::BriefComment for OverloadCandidat...
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
const char * getBriefComment() const
bool includeMacros() const
Whether the code-completion consumer wants to see macros.
A left brace ('{').
bool InBaseClass
Whether this is a class member from base class.
CodeCompletionTUInfo & getCodeCompletionTUInfo() const
Abstract interface for a consumer of code-completion information.
Options controlling the behavior of code completion.
Dataflow Directional Tag Classes.
Code completion occurred where an macro is being defined.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
A piece of text that describes something about the result but should not be inserted into the buffer...
Code completion occurred after the "struct" or "class" keyword, to indicate a struct or class name...
CodeCompletionResult(CodeCompletionString *Pattern, unsigned Priority=CCP_CodePattern, CXCursorKind CursorKind=CXCursor_NotImplemented, CXAvailabilityKind Availability=CXAvailability_Available, const NamedDecl *D=nullptr)
Build a result that refers to a pattern.
Code completion occurred after the "union" keyword, to indicate a union name.
Code completion occurred where a macro name is expected (without any arguments, in the case of a func...
bool includeFixIts() const
Whether to include completion items with small fix-its, e.g.
A builder class used to construct new code-completion strings.
Code completion where an Objective-C instance message is expected.
const RawComment * getPatternCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Pattern...
const char * getKeyword() const
Retrieve the keyword stored in this result.
Code completion occurred where a statement (or declaration) is expected in a function, method, or block.
OverloadCandidate(FunctionDecl *Function)
Code completion occurred on the right-hand side of an Objective-C property access expression...
Encapsulates the data about a macro definition (e.g.
const CodeCompleteOptions CodeCompleteOpts
CodeCompletionResult(const char *Keyword, unsigned Priority=CCP_Keyword)
Build a result that refers to a keyword or symbol.
const NamedDecl * getDeclaration() const
Retrieve the declaration stored in this result.
QualType getBaseType() const
Retrieve the type of the base object in a member-access expression.
bool includeBriefComments() const
Whether to include brief documentation comments within the set of code completions returned...
A piece of text that describes the parameter that corresponds to the code-completion location within ...
A string that acts as a placeholder for, e.g., a function call argument.
CodeCompletionContext(Kind CCKind, QualType T, ArrayRef< IdentifierInfo *> SelIdents=None)
Construct a new code-completion context of the given kind.
bool Hidden
Whether this result is hidden by another name.
unsigned getAvailability() const
Retrieve the availability of this code completion result.
A left parenthesis ('(').
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
StringRef getParentName() const
Code completion occurred within a preprocessor expression.
Code completion occurred where an expression is expected.
Code completion inside the filename part of a #include directive.
bool AllParametersAreInformative
Whether all parameters (of a function, Objective-C method, etc.) should be considered "informative"...
An unspecified code-completion context where we should also add macro completions.
CodeCompletionAllocator & getAllocator() override
Retrieve the allocator that will be used to allocate code completion strings.
unsigned IncludeFixIts
Include results after corrections (small fix-its), e.g.
A left angle bracket ('<').
void setCXXScopeSpecifier(CXXScopeSpec SS)
Sets the scope specifier that comes before the completion token.
A right angle bracket ('>').
ResultKind
Describes the kind of result generated.
CodeCompletionTUInfo(std::shared_ptr< GlobalCodeCompletionAllocator > Allocator)
Priority for a result that isn't likely to be what the user wants, but is included for completeness...
unsigned LoadExternal
Hint whether to load data from the external AST to provide full results.
Code completion occurred on the right-hand side of a member access expression using the dot operator...
SimplifiedTypeClass
A simplified classification of types used when determining "similar" types for code completion...
Code completion occurred where a type name is expected.
Horizontal whitespace (' ').
bool includeCodePatterns() const
Whether the code-completion consumer wants to see code patterns.
The candidate is a function declaration.
void AddAnnotation(const char *A)
Priority for a language keyword (that isn't any of the other categories).
bool DeclaringEntity
Whether we're completing a declaration of the given entity, rather than a use of that entity...
unsigned getPriority() const
Retrieve the priority of this code completion result.
unsigned IncludeMacros
Show macros in code completion results.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
This represents a decl that may have a name.
bool includeNamespaceLevelDecls() const
Whether to include declarations in namespace contexts (including the global namespace).
Declaration of a template function.
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts)
bool includeGlobals() const
Whether to include global (top-level) declaration results.