13 #ifndef LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 14 #define LLVM_CLANG_SEMA_CODECOMPLETECONSUMER_H 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/SmallVector.h" 24 #include "llvm/ADT/StringRef.h" 25 #include "llvm/Support/Allocator.h" 145 bool PreferredTypeIsPointer =
false);
296 SelIdents(SelIdents) {
328 this->ScopeSpecifier = std::move(SS);
333 return ScopeSpecifier.getPointer();
429 static Chunk CreateText(
const char *
Text);
435 static Chunk CreatePlaceholder(
const char *Placeholder);
438 static Chunk CreateInformative(
const char *Informative);
441 static Chunk CreateResultType(
const char *ResultType);
444 static Chunk CreateCurrentParameter(
const char *CurrentParameter);
449 unsigned NumChunks : 16;
452 unsigned NumAnnotations : 16;
455 unsigned Priority : 16;
458 unsigned Availability : 2;
461 StringRef ParentName;
465 const char *BriefComment;
472 const char **Annotations,
unsigned NumAnnotations,
473 StringRef ParentName,
474 const char *BriefComment);
482 iterator
begin()
const {
return reinterpret_cast<const Chunk *
>(
this + 1); }
483 iterator
end()
const {
return begin() + NumChunks; }
484 bool empty()
const {
return NumChunks == 0; }
485 unsigned size()
const {
return NumChunks; }
488 assert(I < size() &&
"Chunk index out-of-range");
493 const char *getTypedText()
const;
502 unsigned getAnnotationCount()
const;
505 const char *getAnnotation(
unsigned AnnotationNr)
const;
525 const char *CopyString(
const Twine &String);
532 llvm::DenseMap<const DeclContext *, StringRef> ParentNames;
533 std::shared_ptr<GlobalCodeCompletionAllocator> AllocatorRef;
537 std::shared_ptr<GlobalCodeCompletionAllocator> Allocator)
538 : AllocatorRef(
std::move(Allocator)) {}
544 assert(AllocatorRef);
545 return *AllocatorRef;
555 static const bool value =
true;
571 StringRef ParentName;
572 const char *BriefComment;
582 : Allocator(Allocator), CCTUInfo(CCTUInfo),
584 BriefComment(nullptr) { }
589 : Allocator(Allocator), CCTUInfo(CCTUInfo),
590 Priority(Priority), Availability(Availability),
591 BriefComment(nullptr) { }
605 void AddTypedTextChunk(
const char *
Text);
608 void AddTextChunk(
const char *Text);
614 void AddPlaceholderChunk(
const char *Placeholder);
617 void AddInformativeChunk(
const char *Text);
623 void AddCurrentParameterChunk(
const char *CurrentParameter);
634 void addBriefComment(StringRef Comment);
710 bool QualifierIsInformative =
false,
711 bool Accessible =
true)
712 : Declaration(Declaration), Priority(Priority),
713 StartParameter(0), Kind(RK_Declaration),
715 QualifierIsInformative(QualifierIsInformative),
716 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
717 DeclaringEntity(
false), Qualifier(Qualifier) {
718 computeCursorKindAndAvailability(Accessible);
723 : Declaration(nullptr), Keyword(Keyword), Priority(Priority),
726 QualifierIsInformative(0), StartsNestedNameSpecifier(
false),
727 AllParametersAreInformative(
false), DeclaringEntity(
false),
728 Qualifier(nullptr) {}
733 : Declaration(nullptr), Macro(Macro), Priority(Priority), StartParameter(0),
736 QualifierIsInformative(0), StartsNestedNameSpecifier(
false),
737 AllParametersAreInformative(
false), DeclaringEntity(
false),
738 Qualifier(nullptr) {}
746 : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0),
747 Kind(RK_Pattern), CursorKind(CursorKind), Availability(Availability),
748 Hidden(
false), QualifierIsInformative(0),
749 StartsNestedNameSpecifier(
false), AllParametersAreInformative(
false),
750 DeclaringEntity(
false), Qualifier(nullptr)
758 : Declaration(D), Pattern(Pattern), Priority(Priority), StartParameter(0),
760 QualifierIsInformative(
false), StartsNestedNameSpecifier(
false),
761 AllParametersAreInformative(
false), DeclaringEntity(
false),
763 computeCursorKindAndAvailability();
768 assert(Kind == RK_Declaration &&
"Not a declaration result");
774 assert(Kind == RK_Keyword &&
"Not a keyword result");
789 bool IncludeBriefComments);
795 bool IncludeBriefComments);
801 StringRef getOrderedName(std::string &Saved)
const;
804 void computeCursorKindAndAvailability(
bool Accessible =
true);
872 : Kind(CK_Function), Function(Function) { }
875 : Kind(CK_FunctionTemplate), FunctionTemplate(FunctionTemplateDecl) { }
878 : Kind(CK_FunctionType), Type(Type) { }
889 assert(
getKind() == CK_FunctionTemplate &&
"Not a function template");
890 return FunctionTemplate;
903 bool IncludeBriefComments)
const;
908 : CodeCompleteOpts(CodeCompleteOpts), OutputIsBinary(OutputIsBinary)
956 unsigned NumResults) { }
968 unsigned NumCandidates) { }
997 unsigned NumResults)
override;
999 void ProcessOverloadCandidates(
Sema &S,
unsigned CurrentArg,
1001 unsigned NumCandidates)
override;
1014 #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...
Priority for a declaration that is in the local scope.
CodeCompletionAllocator & getAllocator() const
An instance of this class is created to represent a function declaration or definition.
ResultKind Kind
The kind of result stored here.
An Objective-C method being used as a property.
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.
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.
FunctionType - C99 6.7.5.3 - Function Declarators.
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.
Adjustment for KVC code pattern priorities when it doesn't look like the.
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 ...
An Objective-C block property completed as a setter with a block placeholder.
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.
Priority for an enumeration constant inside a switch whose condition is of the enumeration type...
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.
Adjustment to the "bool" type in Objective-C, where the typedef "BOOL" is preferred.
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)
Priority for a language keyword (that isn't any of the other categories).
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...
Priority for a nested-name-specifier.
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.
Priority for the Objective-C "_cmd" implicit parameter.
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.
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.
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.
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...
CXAvailabilityKind Availability
The availability of this result.
Code completion occurred where a new name is expected.
Divide by this factor when a code-completion result's type is similar to the type we expect (e...
llvm::StringRef getAsString(SyncScope S)
const FunctionProtoType * T
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.
unsigned IncludeNamespaceLevelDecls
Show decls in namespace (including the global namespace) in code completion results.
const NamedDecl * Declaration
When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to.
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.
std::shared_ptr< GlobalCodeCompletionAllocator > getAllocatorRef() const
Priority for a member declaration found from the current method or member function.
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...
Divide by this factor when a code-completion result's type exactly matches the type we expect...
virtual bool isResultFilteredOut(StringRef Filter, CodeCompletionResult Results)
FunctionDecl * Function
The function overload candidate, available when Kind == CK_Function.
Priority for a result that isn't likely to be what the user wants, but is included for completeness...
A piece of text that should be placed in the buffer, e.g., parentheses or a comma in a function call...
StringRef getParentContextName() const
Retrieve the name of the parent context.
CandidateKind getKind() const
Determine the kind of overload candidate.
unsigned StartParameter
Specifies which parameter (of a function, Objective-C method, macro, etc.) we should start with when ...
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.
The result is in a base class.
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 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 (']').
SimplifiedTypeClass getSimplifiedTypeClass(CanQualType T)
Determine the simplified type class of the given canonical type.
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
ChunkKind Kind
The kind of data stored in this piece of the code completion string.
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...
A piece of text that describes something about the result but should not be inserted into the buffer...
Priority for a send-to-super completion.
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.
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.
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...
A builder class used to construct new code-completion strings.
Code completion where an Objective-C instance message is expected.
CodeCompletionContext(enum Kind Kind, QualType T, ArrayRef< IdentifierInfo *> SelIdents=None)
Construct a new code-completion context of the given kind.
The result is a C++ non-static member function whose qualifiers exactly match the object type on whic...
const char * getKeyword() const
Retrieve the keyword stored in this result.
Priority for a constant value (e.g., enumerator).
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.
Priority for a preprocessor macro.
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.
bool Hidden
Whether this result is hidden by another name.
unsigned getAvailability() const
Retrieve the availability of this code completion result.
A left parenthesis ('(').
enum Kind getKind() const
Retrieve the kind of code-completion context.
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 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.
A left angle bracket ('<').
void setCXXScopeSpecifier(CXXScopeSpec SS)
Sets the scope specifier that comes before the completion token.
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
The selector of the given message exactly matches the selector of the current method, which might imply that some kind of delegation is occurring.
CodeCompletionContext(enum Kind Kind)
Construct a new code-completion context of the given kind.
CodeCompletionTUInfo(std::shared_ptr< GlobalCodeCompletionAllocator > Allocator)
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)
NamedDecl - This represents a decl with a name.
bool includeNamespaceLevelDecls() const
Whether to include declarations in namespace contexts (including the global namespace).
Declaration of a template function.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool includeGlobals() const
Whether to include global (top-level) declaration results.
Priority for a non-type declaration.
Priority for the next initialization in a constructor initializer list.