13 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
14 #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Allocator.h"
137 const LangOptions &LangOpts,
138 bool PreferredTypeIsPointer =
false);
146 class FunctionTemplateDecl;
147 class IdentifierInfo;
149 class NestedNameSpecifier;
285 SelIdents(SelIdents) {
426 unsigned NumChunks : 16;
429 unsigned NumAnnotations : 16;
432 unsigned Priority : 16;
435 unsigned Availability : 2;
438 StringRef ParentName;
442 const char *BriefComment;
449 const char **Annotations,
unsigned NumAnnotations,
450 StringRef ParentName,
451 const char *BriefComment);
461 bool empty()
const {
return NumChunks == 0; }
462 unsigned size()
const {
return NumChunks; }
465 assert(I <
size() &&
"Chunk index out-of-range");
514 llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
520 : AllocatorRef(Allocator) { }
526 assert(AllocatorRef);
527 return *AllocatorRef;
536 template <>
struct isPodLike<clang::CodeCompletionString::Chunk> {
537 static const bool value =
true;
553 StringRef ParentName;
554 const char *BriefComment;
564 : Allocator(Allocator), CCTUInfo(CCTUInfo),
566 BriefComment(nullptr) { }
571 : Allocator(Allocator), CCTUInfo(CCTUInfo),
572 Priority(Priority), Availability(Availability),
573 BriefComment(nullptr) { }
693 bool Accessible =
true)
694 : Declaration(Declaration), Priority(Priority),
700 computeCursorKindAndAvailability(Accessible);
745 computeCursorKindAndAvailability();
771 bool IncludeBriefComments);
777 bool IncludeBriefComments);
780 void computeCursorKindAndAvailability(
bool Accessible =
true);
783 bool operator<(
const CodeCompletionResult &
X,
const CodeCompletionResult &Y);
802 const CodeCompletionString &CCS);
879 bool IncludeBriefComments)
const;
884 : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary)
920 unsigned NumResults) { }
932 unsigned NumCandidates) { }
961 unsigned NumResults)
override;
965 unsigned NumCandidates)
override;
976 #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. For example, an optional code completion string t...
CXAvailabilityKind
Describes the availability of a particular entity, which indicates whether the use of this entity wil...
ResultKind Kind
The kind of result stored here.
FunctionDecl * getFunction() const
Retrieve the function overload candidate or the templated function declaration for a function templat...
CodeCompletionResult(const IdentifierInfo *Macro, unsigned Priority=CCP_Macro)
Build a result that refers to a macro.
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.
CodeCompletionString * CreateSignatureString(unsigned CurrentArg, Sema &S, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments) const
Create a new code-completion string that describes the function signature of this overload candidate...
CodeCompletionContext(enum Kind Kind, QualType T, ArrayRef< IdentifierInfo * > SelIdents=None)
Construct a new code-completion context of the given kind.
bool includeGlobals() const
Whether to include global (top-level) declaration results.
CodeCompletionString * CreateCodeCompletionString(Sema &S, const CodeCompletionContext &CCContext, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments)
Create a new code-completion string that describes how to insert this result into a program...
StringRef getParentName(const DeclContext *DC)
Priority for the Objective-C "_cmd" implicit parameter.
Code completion for a selector, as in an @selector expression.
bool includeMacros() const
Whether the code-completion consumer wants to see macros.
void AddTextChunk(const char *Text)
Add a new text chunk.
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.
FunctionTemplateDecl * getFunctionTemplate() const
Retrieve the function template overload candidate.
Code completion within a type-qualifier list.
void AddChunk(CodeCompletionString::ChunkKind CK, const char *Text="")
Add a new chunk.
CandidateKind
Describes the type of overload candidate.
const DiagnosticBuilder & operator<<(const DiagnosticBuilder &DB, const Attr *At)
static Chunk CreateText(const char *Text)
Create a new text chunk.
An unspecified code-completion context.
Allocator for a cached set of global code completions.
static Chunk CreateOptional(CodeCompletionString *Optional)
Create a new optional chunk.
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.
Priority for a member declaration found from the current method or member function.
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.
unsigned getAvailability() const
Retrieve the availability of this code completion result.
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.
static Chunk CreateResultType(const char *ResultType)
Create a new result type chunk.
void AddOptionalChunk(CodeCompletionString *Optional)
Add a new optional chunk.
Priority for a constant value (e.g., enumerator).
Code completion occurred within the instance variable list of an Objective-C interface, implementation, or category implementation.
void AddTypedTextChunk(const char *Text)
Add a new typed-text chunk.
StringRef getParentContextName() const
Retrieve the name of the parent context.
bool operator<=(DeclarationName LHS, DeclarationName RHS)
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, unsigned Priority, CXAvailabilityKind Availability)
const FunctionType * getFunctionType() const
Retrieve the function type of the entity, regardless of how the function is stored.
CodeCompletionString * TakeString()
Take the resulting completion string.
OverloadCandidate(FunctionTemplateDecl *FunctionTemplateDecl)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
static Chunk CreateInformative(const char *Informative)
Create a new informative chunk.
unsigned getAnnotationCount() const
Retrieve the number of annotations for this code completion result.
A "string" used to describe how code completion can be performed for an entity.
The selector of the given message exactly matches the selector of the current method, which might imply that some kind of delegation is occurring.
void AddResultTypeChunk(const char *ResultType)
Add a new result-type chunk.
bool operator>(DeclarationName LHS, DeclarationName RHS)
CodeCompletionTUInfo(IntrusiveRefCntPtr< GlobalCodeCompletionAllocator > Allocator)
OverloadCandidate(const FunctionType *Type)
static Chunk CreatePlaceholder(const char *Placeholder)
Create a new placeholder chunk.
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...
Code completion occurred where a preprocessor directive is expected.
virtual CodeCompletionTUInfo & getCodeCompletionTUInfo()=0
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.
bool wantConstructorResults() const
Determines whether we want C++ constructors as results within this context.
The "candidate" is actually a variable, expression, or block for which we only have a function protot...
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.
static Chunk CreateCurrentParameter(const char *CurrentParameter)
Create a new current-parameter chunk.
CodeCompletionTUInfo & getCodeCompletionTUInfo() const
const char * getKeyword() const
Retrieve the keyword stored in this result.
QualType getBaseType() const
Retrieve the type of the base object in a member-access expression.
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.
bool includeBriefComments() const
Whether to include brief documentation comments within the set of code completions returned...
QualType getPreferredType() const
Retrieve the type that this expression would prefer to have, e.g., if the expression is a variable in...
Refers to a keyword or symbol.
CXCursorKind
Describes the kind of entity that a cursor refers to.
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...
Divide by this factor when a code-completion result's type exactly matches the type we expect...
CodeCompletionTUInfo & getCodeCompletionTUInfo() override
const char * getTypedText() const
Returns the text in the TypedText chunk.
CodeCompletionAllocator & getAllocator() const
Code completion occurred where a protocol name is expected.
CXCursorKind getCursorKindForDecl(const Decl *D)
Determine the libclang cursor kind associated with the given declaration.
A simple code-completion consumer that prints the results it receives in a simple format...
const NamedDecl * getDeclaration() const
Retrieve the declaration stored in this result.
CXAvailabilityKind Availability
The availability of this result.
Code completion occurred where a new name is expected.
unsigned IncludeCodePatterns
Show code patterns in code completion results.
const char * Text
The text string associated with a CK_Text, CK_Placeholder, CK_Informative, or CK_Comma chunk...
virtual void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults)
Process the finalized code-completion results.
bool includeCodePatterns() const
Whether the code-completion consumer wants to see code patterns.
The result is in a base class.
const NamedDecl * Declaration
When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to. In the latter case...
unsigned getPriority() const
Retrieve the priority of this code completion result.
ArrayRef< IdentifierInfo * > getSelIdents() const
Retrieve the Objective-C selector identifiers.
Captures a result of code completion.
Code completion occurred where a new name is expected and a qualified name is permissible.
Priority for a result that isn't likely to be what the user wants, but is included for completeness...
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...
FunctionDecl * Function
The function overload candidate, available when Kind == CK_Function.
IntrusiveRefCntPtr< GlobalCodeCompletionAllocator > getAllocatorRef() const
A piece of text that should be placed in the buffer, e.g., parentheses or a comma in a function call...
Priority for the next initialization in a constructor initializer list.
const char * CopyString(const Twine &String)
Copy the given string into this allocator.
const char * getBriefComment() const
unsigned StartParameter
Specifies which parameter (of a function, Objective-C method, macro, etc.) we should start with when ...
CandidateKind getKind() const
Determine the kind of overload candidate.
CodeCompletionString * Optional
The code completion string associated with a CK_Optional chunk. The optional code completion string i...
Options controlling the behavior of code completion.
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.
OverloadCandidate - A single candidate in an overload set (C++ 13.3).
bool isOutputBinary() const
Determine whether the output of this consumer is binary.
Code completion where the name of an Objective-C class is expected.
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
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>::".
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
Priority for a non-type declaration.
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
bool operator>=(DeclarationName LHS, DeclarationName RHS)
void addParentContext(const DeclContext *DC)
Add the parent context information to this code completion.
bool operator<(DeclarationName LHS, DeclarationName RHS)
ChunkKind Kind
The kind of data stored in this piece of the code completion string.
const char * getBriefComment() const
void addBriefComment(StringRef Comment)
Priority for a nested-name-specifier.
Priority for a declaration that is in the local scope.
StringRef getParentName() const
Abstract interface for a consumer of code-completion information.
unsigned IncludeGlobals
Show top-level decls in code completion results.
Code completion occurred where an macro is being defined.
Adjustment for KVC code pattern priorities when it doesn't look like the.
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...
void ProcessCodeCompleteResults(Sema &S, CodeCompletionContext Context, CodeCompletionResult *Results, unsigned NumResults) override
Prints the finalized code-completion results.
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.
CodeCompletionResult(const NamedDecl *Declaration, unsigned Priority, NestedNameSpecifier *Qualifier=nullptr, bool QualifierIsInformative=false, bool Accessible=true)
Build a result that refers to a declaration.
NestedNameSpecifier * Qualifier
If the result should have a nested-name-specifier, this is it. When QualifierIsInformative, the nested-name-specifier is informative rather than required.
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...
std::string getAsString() const
Retrieve a string representation of the code completion string, which is mainly useful for debugging...
A builder class used to construct new code-completion strings.
Code completion where an Objective-C instance message is expected.
Priority for a send-to-super completion.
Refers to a precomputed pattern.
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...
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
const CodeCompleteOptions CodeCompleteOpts
void AddInformativeChunk(const char *Text)
Add a new informative chunk.
CodeCompletionResult(const char *Keyword, unsigned Priority=CCP_Keyword)
Build a result that refers to a keyword or symbol.
void AddCurrentParameterChunk(const char *CurrentParameter)
Add a new current-parameter chunk.
enum Kind getKind() const
Retrieve the kind of code-completion context.
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.
Priority for a language keyword (that isn't any of the other categories).
CodeCompletionResult(CodeCompletionString *Pattern, NamedDecl *D, unsigned Priority)
Build a result that refers to a pattern with an associated declaration.
An Objective-C method being used as a property.
bool Hidden
Whether this result is hidden by another name.
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
A left parenthesis ('(').
Code completion occurred within a preprocessor expression.
Code completion occurred where an expression is expected.
virtual CodeCompletionAllocator & getAllocator()=0
Retrieve the allocator that will be used to allocate code completion strings.
const Chunk & operator[](unsigned I) const
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 IncludeMacros
Show macros in code completion results.
const char * getAnnotation(unsigned AnnotationNr) const
Retrieve the annotation string specified by AnnotationNr.
A left angle bracket ('<').
A right angle bracket ('>').
bool OutputIsBinary
Whether the output format for the code-completion consumer is binary.
ResultKind
Describes the kind of result generated.
CodeCompletionString::Chunk Chunk
Vertical whitespace ('\n' or '\r\n', depending on the platform).
CodeCompletionContext(enum Kind Kind)
Construct a new code-completion context of the given kind.
void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, unsigned NumCandidates) override
CodeCompletionAllocator & getAllocator() const
Retrieve the allocator into which the code completion strings should be allocated.
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...
void AddPlaceholderChunk(const char *Placeholder)
Add a new placeholder chunk.
Code completion occurred where a type name is expected.
Horizontal whitespace (' ').
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...
CodeCompletionBuilder(CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
virtual ~CodeCompleteConsumer()
Deregisters and destroys this code-completion consumer.
Declaration of a template function.
Divide by this factor when a code-completion result's type is similar to the type we expect (e...
Priority for a code pattern.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Priority for a preprocessor macro.
Priority for an enumeration constant inside a switch whose condition is of the enumeration type...