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);
367 : CCKind(CCKind), SelIdents(SelIdents) {
400 this->ScopeSpecifier = std::move(SS);
405 VisitedContexts.insert(Ctx);
410 return VisitedContexts;
415 return ScopeSpecifier.getPointer();
533 static Chunk CreateText(
const char *
Text);
539 static Chunk CreatePlaceholder(
const char *Placeholder);
542 static Chunk CreateInformative(
const char *Informative);
545 static Chunk CreateResultType(
const char *ResultType);
548 static Chunk CreateCurrentParameter(
const char *CurrentParameter);
556 unsigned NumChunks : 16;
559 unsigned NumAnnotations : 16;
562 unsigned Priority : 16;
565 unsigned Availability : 2;
568 StringRef ParentName;
572 const char *BriefComment;
576 const char **Annotations,
unsigned NumAnnotations,
577 StringRef ParentName,
578 const char *BriefComment);
589 bool empty()
const {
return NumChunks == 0; }
590 unsigned size()
const {
return NumChunks; }
593 assert(I < size() &&
"Chunk index out-of-range");
598 const char *getTypedText()
const;
607 unsigned getAnnotationCount()
const;
610 const char *getAnnotation(
unsigned AnnotationNr)
const;
630 const char *CopyString(
const Twine &String);
637 llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
638 std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
642 std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
643 : AllocatorRef(
std::move(Allocator)) {}
650 assert(AllocatorRef);
651 return *AllocatorRef;
669 unsigned Priority = 0;
671 StringRef ParentName;
672 const char *BriefComment =
nullptr;
682 : Allocator(Allocator), CCTUInfo(CCTUInfo) {}
687 : Allocator(Allocator), CCTUInfo(CCTUInfo), Priority(Priority),
688 Availability(Availability) {}
702 void AddTypedTextChunk(
const char *
Text);
705 void AddTextChunk(
const char *Text);
711 void AddPlaceholderChunk(
const char *Placeholder);
714 void AddInformativeChunk(
const char *Text);
720 void AddCurrentParameterChunk(
const char *CurrentParameter);
731 void addBriefComment(StringRef Comment);
776 unsigned StartParameter = 0;
857 bool QualifierIsInformative =
false,
858 bool Accessible =
true,
859 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
860 : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
861 FixIts(
std::move(FixIts)), Hidden(
false), InBaseClass(
false),
862 QualifierIsInformative(QualifierIsInformative),
863 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
864 DeclaringEntity(
false), Qualifier(Qualifier) {
866 computeCursorKindAndAvailability(Accessible);
871 : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
873 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
874 AllParametersAreInformative(
false), DeclaringEntity(
false) {}
880 : Macro(Macro), Priority(Priority), Kind(RK_Macro),
882 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
883 AllParametersAreInformative(
false), DeclaringEntity(
false),
892 : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
893 CursorKind(CursorKind), Availability(Availability), Hidden(
false),
894 InBaseClass(
false), QualifierIsInformative(
false),
895 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
896 DeclaringEntity(
false) {}
902 : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
904 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
905 DeclaringEntity(
false) {
906 computeCursorKindAndAvailability();
912 assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) &&
913 "Not a declaration or pattern result");
919 assert(Kind == RK_Keyword &&
"Not a keyword result");
934 bool IncludeBriefComments);
940 bool IncludeBriefComments);
963 StringRef getOrderedName(std::string &Saved)
const;
966 void computeCursorKindAndAvailability(
bool Accessible =
true);
1031 : Kind(CK_Function), Function(Function) {}
1034 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {}
1037 : Kind(CK_FunctionType), Type(Type) {}
1048 assert(
getKind() == CK_FunctionTemplate &&
"Not a function template");
1049 return FunctionTemplate;
1062 bool IncludeBriefComments)
const;
1066 : CodeCompleteOpts(CodeCompleteOpts) {}
1120 unsigned NumResults) {}
1135 unsigned NumCandidates,
1182 unsigned NumResults)
override;
1184 void ProcessOverloadCandidates(
Sema &S,
unsigned CurrentArg,
1186 unsigned NumCandidates,
1200 #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
Priority for a preprocessor macro.
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.
A (possibly-)qualified type.
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
llvm::Optional< const CXXScopeSpec * > getCXXScopeSpecifier()
Code completion for a selector, as in an @selector expression.
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
Code completion occurred where an existing name(such as type, function or variable) is expected...
Priority for an enumeration constant inside a switch whose condition is of the enumeration type...
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.
Priority for a result that isn't likely to be what the user wants, but is included for completeness...
C Language Family Type Representation.
Code completion within a type-qualifier list.
Priority for the next initialization in a constructor initializer 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.
Decl - This represents one declaration (or definition), e.g.
Divide by this factor when a code-completion result's type exactly matches the type we expect...
CandidateKind
Describes the type of overload candidate.
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.
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.
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)
Code completion occurred where both a new name and an existing symbol is permissible.
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.
An Objective-C block property completed as a setter with a block placeholder.
Priority for a language keyword (that isn't any of the other categories).
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.
Priority for a declaration that is in the local scope.
OverloadCandidate(const FunctionType *Type)
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...
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.
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 send-to-super completion.
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...
CodeCompletionTUInfo & getCodeCompletionTUInfo() override
Divide by this factor when a code-completion result's type is similar to the type we expect (e...
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 ...
The selector of the given message exactly matches the selector of the current method, which might imply that some kind of delegation is occurring.
The result is in a base class.
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
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.
Adjustment for KVC code pattern priorities when it doesn't look like the.
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.
An Objective-C method being used as a property.
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.
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
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.
Priority for a constant value (e.g., enumerator).
const CodeCompleteOptions CodeCompleteOpts
CodeCompletionResult(const char *Keyword, unsigned Priority=CCP_Keyword)
Build a result that refers to a keyword or symbol.
Priority for the Objective-C "_cmd" implicit parameter.
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.
Priority for a code pattern.
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.
Priority for a nested-name-specifier.
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)
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)
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).
Priority for a member declaration found from the current method or member function.
Declaration of a template function.
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Priority for a non-type 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.