14 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 15 #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);
360 : CCKind(CCKind), SelIdents(SelIdents) {
392 this->ScopeSpecifier = std::move(SS);
397 VisitedContexts.insert(Ctx);
402 return VisitedContexts;
407 return ScopeSpecifier.getPointer();
525 static Chunk CreateText(
const char *
Text);
531 static Chunk CreatePlaceholder(
const char *Placeholder);
534 static Chunk CreateInformative(
const char *Informative);
537 static Chunk CreateResultType(
const char *ResultType);
540 static Chunk CreateCurrentParameter(
const char *CurrentParameter);
548 unsigned NumChunks : 16;
551 unsigned NumAnnotations : 16;
554 unsigned Priority : 16;
557 unsigned Availability : 2;
560 StringRef ParentName;
564 const char *BriefComment;
568 const char **Annotations,
unsigned NumAnnotations,
569 StringRef ParentName,
570 const char *BriefComment);
581 bool empty()
const {
return NumChunks == 0; }
582 unsigned size()
const {
return NumChunks; }
585 assert(I < size() &&
"Chunk index out-of-range");
590 const char *getTypedText()
const;
599 unsigned getAnnotationCount()
const;
602 const char *getAnnotation(
unsigned AnnotationNr)
const;
622 const char *CopyString(
const Twine &String);
629 llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
630 std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
634 std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
635 : AllocatorRef(
std::move(Allocator)) {}
642 assert(AllocatorRef);
643 return *AllocatorRef;
654 static const bool value =
true;
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;
849 bool QualifierIsInformative =
false,
850 bool Accessible =
true,
851 std::vector<FixItHint> FixIts = std::vector<FixItHint>())
852 : Declaration(Declaration), Priority(Priority), Kind(RK_Declaration),
853 FixIts(
std::move(FixIts)), Hidden(
false),
854 QualifierIsInformative(QualifierIsInformative),
855 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
856 DeclaringEntity(
false), Qualifier(Qualifier) {
858 computeCursorKindAndAvailability(Accessible);
863 : Keyword(Keyword), Priority(Priority), Kind(RK_Keyword),
865 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
866 AllParametersAreInformative(
false), DeclaringEntity(
false) {}
871 : Macro(Macro), Priority(Priority), Kind(RK_Macro),
873 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
874 AllParametersAreInformative(
false), DeclaringEntity(
false) {}
882 : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
883 CursorKind(CursorKind), Availability(Availability), Hidden(
false),
884 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
885 AllParametersAreInformative(
false), DeclaringEntity(
false) {}
891 : Declaration(D), Pattern(Pattern), Priority(Priority), Kind(RK_Pattern),
893 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
894 DeclaringEntity(
false) {
895 computeCursorKindAndAvailability();
901 assert(((Kind == RK_Declaration) || (Kind == RK_Pattern)) &&
902 "Not a declaration or pattern result");
908 assert(Kind == RK_Keyword &&
"Not a keyword result");
923 bool IncludeBriefComments);
929 bool IncludeBriefComments);
942 StringRef getOrderedName(std::string &Saved)
const;
945 void computeCursorKindAndAvailability(
bool Accessible =
true);
1014 : Kind(CK_Function), Function(Function) {}
1017 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) {}
1020 : Kind(CK_FunctionType), Type(Type) {}
1031 assert(
getKind() == CK_FunctionTemplate &&
"Not a function template");
1032 return FunctionTemplate;
1045 bool IncludeBriefComments)
const;
1049 bool OutputIsBinary)
1050 : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary) {}
1107 unsigned NumResults) {}
1119 unsigned NumCandidates) {}
1165 unsigned NumResults)
override;
1167 void ProcessOverloadCandidates(
Sema &S,
unsigned CurrentArg,
1169 unsigned NumCandidates)
override;
1182 #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.
CodeCompletionResult(const IdentifierInfo *Macro, unsigned Priority=CCP_Macro)
Build a result that refers to a macro.
std::vector< FixItHint > FixIts
Fix-its that must be applied before inserting the text for the corresponding completion.
Priority for the Objective-C "_cmd" implicit parameter.
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.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
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.
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
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.
Decl - This represents one declaration (or definition), e.g.
CandidateKind
Describes the type of overload candidate.
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. ...
Priority for a member declaration found from the current method or member function.
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.
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 ('[').
bool isOutputBinary() const
Determine whether the output of this consumer is binary.
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.
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability)
One of these records is kept for each identifier that is lexed.
OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
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.
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.
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...
Divide by this factor when a code-completion result's type exactly matches the type we expect...
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.
Priority for a constant value (e.g., enumerator).
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.
A right brace ('}').
An Objective-C method being used as a property.
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.
Priority for a preprocessor macro.
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
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.
Code completion occurred where a new name is expected.
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.
Priority for a non-type declaration.
void addVisitedContext(DeclContext *Ctx)
Adds a visited context.
unsigned IncludeNamespaceLevelDecls
Show decls in namespace (including the global namespace) in code completion results.
An Objective-C block property completed as a setter with a block placeholder.
A semicolon (';').
Captures a result of code completion.
ArrayRef< IdentifierInfo * > getSelIdents() const
Retrieve the Objective-C selector identifiers.
Code completion occurred where a new name is expected and a qualified name is permissible.
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.
Priority for a result that isn't likely to be what the user wants, but is included for completeness...
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...
Priority for the next initialization in a constructor initializer list.
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.
Priority for a send-to-super completion.
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.
CodeCompleteConsumer(const CodeCompleteOptions &CodeCompleteOpts, bool OutputIsBinary)
virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates)
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A right bracket (']').
Represents a canonical, potentially-qualified type.
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
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 ('{').
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...
Priority for a declaration that is in the local scope.
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.
Divide by this factor when a code-completion result's type is similar to the type we expect (e...
const RawComment * getPatternCompletionComment(const ASTContext &Ctx, const NamedDecl *Decl)
Get the documentation comment used to produce CodeCompletionString::BriefComment for RK_Pattern...
The result is in a base class.
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...
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.
Priority for a language keyword (that isn't any of the other categories).
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.
Priority for a nested-name-specifier.
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.
The selector of the given message exactly matches the selector of the current method, which might imply that some kind of delegation is occurring.
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 ('>').
Adjustment for KVC code pattern priorities when it doesn't look like the.
bool OutputIsBinary
Whether the output format for the code-completion consumer is binary.
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 code pattern.
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.
Priority for an enumeration constant inside a switch whose condition is of the enumeration type...
bool includeGlobals() const
Whether to include global (top-level) declaration results.