clang 8.0.0

Public Types | Public Member Functions | Public Attributes | List of all members
clang::CodeCompletionResult Class Reference

Captures a result of code completion. More...

`#include "clang/Sema/CodeCompleteConsumer.h"`

Collaboration diagram for clang::CodeCompletionResult:
[legend]

## Public Types
enum | ResultKind { RK_Declaration = 0, RK_Keyword, RK_Macro, RK_Pattern }
| Describes the kind of result generated. More...

## Public Member Functions
| 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. More...
| CodeCompletionResult (const char *Keyword, unsigned Priority=CCP_Keyword)
| Build a result that refers to a keyword or symbol. More...
| CodeCompletionResult (const IdentifierInfo *Macro, const MacroInfo *MI=nullptr, unsigned Priority=CCP_Macro)
| Build a result that refers to a macro. More...
| 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. More...
| CodeCompletionResult (CodeCompletionString *Pattern, const NamedDecl *D, unsigned Priority)
| Build a result that refers to a pattern with an associated declaration. More...
const NamedDecl * | getDeclaration () const
| Retrieve the declaration stored in this result. More...
const char * | getKeyword () const
| Retrieve the keyword stored in this result. More...
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. More...
CodeCompletionString * | CreateCodeCompletionString (ASTContext &Ctx, Preprocessor &PP, const CodeCompletionContext &CCContext, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments)
| If possible, create a new code completion string for the given result. More...
CodeCompletionString * | CreateCodeCompletionStringForMacro (Preprocessor &PP, CodeCompletionAllocator &Allocator, CodeCompletionTUInfo &CCTUInfo)
| Creates a new code-completion string for the macro result. More...
CodeCompletionString * | createCodeCompletionStringForDecl (Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, bool IncludeBriefComments, const CodeCompletionContext &CCContext, PrintingPolicy &Policy)
CodeCompletionString * | createCodeCompletionStringForOverride (Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result, bool IncludeBriefComments, const CodeCompletionContext &CCContext, PrintingPolicy &Policy)
StringRef | getOrderedName (std::string &Saved) const
| Retrieve the name that should be used to order a result. More...

## Public Attributes
const NamedDecl * | Declaration = nullptr
| When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to. More...
union {
const char * Keyword
| When Kind == RK_Keyword, the string representing the keyword or symbol's spelling. More...
CodeCompletionString * Pattern
| When Kind == RK_Pattern, the code-completion string that describes the completion text to insert. More...
const IdentifierInfo * Macro
| When Kind == RK_Macro, the identifier that refers to a macro. More...
}; |
unsigned | Priority
| The priority of this particular code-completion result. More...
unsigned | StartParameter = 0
| Specifies which parameter (of a function, Objective-C method, macro, etc.) we should start with when formatting the result. More...
ResultKind | Kind
| The kind of result stored here. More...
CXCursorKind | CursorKind
| The cursor kind that describes this result. More...
CXAvailabilityKind | Availability = CXAvailability_Available
| The availability of this result. More...
std::vector< FixItHint > | FixIts
| Fix-its that must be applied before inserting the text for the corresponding completion. More...
bool | Hidden: 1
| Whether this result is hidden by another name. More...
bool | InBaseClass: 1
| Whether this is a class member from base class. More...
bool | QualifierIsInformative: 1
| Whether this result was found via lookup into a base class. More...
bool | StartsNestedNameSpecifier: 1
| Whether this declaration is the beginning of a nested-name-specifier and, therefore, should be followed by '::'. More...
bool | AllParametersAreInformative: 1
| Whether all parameters (of a function, Objective-C method, etc.) should be considered "informative". More...
bool | DeclaringEntity: 1
| Whether we're completing a declaration of the given entity, rather than a use of that entity. More...
NestedNameSpecifier * | Qualifier = nullptr
| If the result should have a nested-name-specifier, this is it. More...
const UsingShadowDecl * | ShadowDecl = nullptr
| If this Decl was unshadowed by using declaration, this can store a pointer to the UsingShadowDecl which was used in the unshadowing process. More...
const MacroInfo * | MacroDefInfo = nullptr
| If the result is RK_Macro, this can store the information about the macro definition. More...

## Detailed Description

Captures a result of code completion.

Definition at line 745 of file CodeCompleteConsumer.h.

## Member Enumeration Documentation

## ◆ ResultKind

enum clang::CodeCompletionResult::ResultKind

Describes the kind of result generated.

Enumerator
RK_Declaration | Refers to a declaration.
RK_Keyword | Refers to a keyword or symbol.
RK_Macro | Refers to a macro.
RK_Pattern | Refers to a precomputed pattern.

Definition at line 748 of file CodeCompleteConsumer.h.

## Constructor & Destructor Documentation

## ◆ CodeCompletionResult() [1/5]

clang::CodeCompletionResult::CodeCompletionResult | ( | const NamedDecl * | Declaration,
|  | unsigned | Priority,
|  | NestedNameSpecifier * | Qualifier = `nullptr`,
|  | bool | QualifierIsInformative = `false`,
|  | bool | Accessible = `true`,
|  | std::vector< FixItHint > | FixIts = `std::vector<FixItHint>()`
| ) |  |
| inline

Build a result that refers to a declaration.

Definition at line 863 of file CodeCompleteConsumer.h.

## ◆ CodeCompletionResult() [2/5]

clang::CodeCompletionResult::CodeCompletionResult | ( | const char * | Keyword,
|  | unsigned | Priority = `CCP_Keyword`
| ) |  |
| inline

Build a result that refers to a keyword or symbol.

Definition at line 878 of file CodeCompleteConsumer.h.

## ◆ CodeCompletionResult() [3/5]

clang::CodeCompletionResult::CodeCompletionResult | ( | const IdentifierInfo * | Macro,
|  | const MacroInfo * | MI = `nullptr`,
|  | unsigned | Priority = `CCP_Macro`
| ) |  |
| inline

Build a result that refers to a macro.

Definition at line 885 of file CodeCompleteConsumer.h.

## ◆ CodeCompletionResult() [4/5]

clang::CodeCompletionResult::CodeCompletionResult | ( | CodeCompletionString * | Pattern,
|  | unsigned | Priority = `CCP_CodePattern`,
|  | CXCursorKind | CursorKind = `CXCursor_NotImplemented`,
|  | CXAvailabilityKind | Availability = `CXAvailability_Available`,
|  | const NamedDecl * | D = `nullptr`
| ) |  |
| inline

Build a result that refers to a pattern.

Definition at line 895 of file CodeCompleteConsumer.h.

## ◆ CodeCompletionResult() [5/5]

clang::CodeCompletionResult::CodeCompletionResult | ( | CodeCompletionString * | Pattern,
|  | const NamedDecl * | D,
|  | unsigned | Priority
| ) |  |
| inline

Build a result that refers to a pattern with an associated declaration.

Definition at line 908 of file CodeCompleteConsumer.h.

## Member Function Documentation

## ◆ CreateCodeCompletionString() [1/2]

CodeCompletionString * CodeCompletionResult::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.

Parameters

  S | The semantic analysis that created the result.
  Allocator | The allocator that will be used to allocate the string itself.

Definition at line 2860 of file SemaCodeComplete.cpp.

## ◆ CreateCodeCompletionString() [2/2]

CodeCompletionString * CodeCompletionResult::CreateCodeCompletionString | ( | ASTContext & | Ctx,
|  | Preprocessor & | PP,
|  | const CodeCompletionContext & | CCContext,
|  | CodeCompletionAllocator & | Allocator,
|  | CodeCompletionTUInfo & | CCTUInfo,
|  | bool | IncludeBriefComments
| ) |  |

If possible, create a new code completion string for the given result.

Returns
  Either a new, heap-allocated code completion string describing how to use this result, or NULL to indicate that the string or name of the result is all that is needed.

Definition at line 2920 of file SemaCodeComplete.cpp.

References clang::CodeCompletionBuilder::addBriefComment(), clang::CodeCompletionBuilder::addParentContext(), clang::CodeCompletionBuilder::AddTypedTextChunk(), clang::CodeCompletionBuilder::getBriefComment(), getCompletionPrintingPolicy(), clang::CodeCompletionBuilder::getParentName(), clang::getPatternCompletionComment(), and clang::CodeCompletionBuilder::TakeString().

## ◆ createCodeCompletionStringForDecl()

CodeCompletionString * CodeCompletionResult::createCodeCompletionStringForDecl | ( | Preprocessor & | PP,
|  | ASTContext & | Ctx,
|  | CodeCompletionBuilder & | Result,
|  | bool | IncludeBriefComments,
|  | const CodeCompletionContext & | CCContext,
|  | PrintingPolicy & | Policy
| ) |  |

Definition at line 2972 of file SemaCodeComplete.cpp.

References clang::CodeCompletionBuilder::AddAnnotation(), clang::CodeCompletionBuilder::addBriefComment(), clang::CodeCompletionBuilder::AddChunk(), AddFunctionParameterChunks(), AddFunctionTypeQualsToCompletionString(), clang::CodeCompletionBuilder::AddInformativeChunk(), clang::CodeCompletionBuilder::addParentContext(), clang::CodeCompletionBuilder::AddPlaceholderChunk(), AddQualifierToCompletionString(), AddResultTypeChunk(), AddTemplateParameterChunks(), clang::CodeCompletionBuilder::AddTextChunk(), AddTypedNameChunk(), clang::CodeCompletionBuilder::AddTypedTextChunk(), clang::CodeCompletionString::CK_HorizontalSpace, clang::CodeCompletionString::CK_LeftAngle, clang::CodeCompletionString::CK_LeftParen, clang::CodeCompletionString::CK_RightAngle, clang::CodeCompletionString::CK_RightParen, clang::CodeCompletionAllocator::CopyString(), FormatFunctionParameter(), formatObjCParamQualifiers(), clang::CodeCompletionBuilder::getAllocator(), clang::QualType::getAsString(), clang::CodeCompletionContext::getBaseType(), clang::getCompletionComment(), clang::Decl::getDeclContext(), clang::Selector::getIdentifierInfoForSlot(), clang::NamedDecl::getNameAsString(), clang::Selector::getNameForSlot(), clang::Type::getObjCSubstitutions(), clang::Type::isBlockPointerType(), clang::QualType::isNull(), clang::Selector::isUnarySelector(), clang::Sema::MarkDeducedTemplateParameters(), MaybeAddSentinel(), P, clang::Parameter, clang::Decl::specific_attrs(), clang::QualType::substObjCTypeArgs(), and clang::CodeCompletionBuilder::TakeString().

## ◆ CreateCodeCompletionStringForMacro()

CodeCompletionString * CodeCompletionResult::CreateCodeCompletionStringForMacro | ( | Preprocessor & | PP,
|  | CodeCompletionAllocator & | Allocator,
|  | CodeCompletionTUInfo & | CCTUInfo
| ) |  |

Creates a new code-completion string for the macro result.

Similar to the above overloads, except this only requires preprocessor information. The result kind must be `RK_Macro`.

Definition at line 2868 of file SemaCodeComplete.cpp.

References clang::CodeCompletionBuilder::AddChunk(), clang::CodeCompletionBuilder::AddPlaceholderChunk(), clang::CodeCompletionBuilder::AddTypedTextChunk(), clang::CodeCompletionString::CK_Comma, clang::CodeCompletionString::CK_LeftParen, clang::CodeCompletionString::CK_RightParen, clang::CodeCompletionAllocator::CopyString(), clang::CodeCompletionBuilder::getAllocator(), clang::Preprocessor::getMacroInfo(), clang::MacroInfo::isC99Varargs(), clang::MacroInfo::isFunctionLike(), clang::MacroInfo::isVariadic(), clang::MacroInfo::param_begin(), clang::MacroInfo::param_end(), and clang::CodeCompletionBuilder::TakeString().

## ◆ createCodeCompletionStringForOverride()

CodeCompletionString * CodeCompletionResult::createCodeCompletionStringForOverride | ( | Preprocessor & | PP,
|  | ASTContext & | Ctx,
|  | CodeCompletionBuilder & | Result,
|  | bool | IncludeBriefComments,
|  | const CodeCompletionContext & | CCContext,
|  | PrintingPolicy & | Policy
| ) |  |

Definition at line 2957 of file SemaCodeComplete.cpp.

References clang::CodeCompletionBuilder::AddTypedTextChunk(), clang::CodeCompletionAllocator::CopyString(), clang::CodeCompletionBuilder::getAllocator(), printOverrideString(), and clang::CodeCompletionBuilder::TakeString().

## ◆ getDeclaration()

const NamedDecl* clang::CodeCompletionResult::getDeclaration | ( |  | ) | const
| inline

Retrieve the declaration stored in this result.

This might be nullptr if Kind is RK_Pattern.

Definition at line 919 of file CodeCompleteConsumer.h.

## ◆ getKeyword()

const char* clang::CodeCompletionResult::getKeyword | ( |  | ) | const
| inline

Retrieve the keyword stored in this result.

Definition at line 926 of file CodeCompleteConsumer.h.

## ◆ getOrderedName()

StringRef CodeCompletionResult::getOrderedName | ( | std::string & | Saved | ) | const

Retrieve the name that should be used to order a result.

If the name needs to be constructed as a string, that string will be saved into Saved and the returned StringRef will refer to it.

Definition at line 729 of file CodeCompleteConsumer.cpp.

Referenced by clang::operator<().

## Member Data Documentation

## ◆ @208

union { ... }

## ◆ AllParametersAreInformative

bool clang::CodeCompletionResult::AllParametersAreInformative

Whether all parameters (of a function, Objective-C method, etc.) should be considered "informative".

Definition at line 840 of file CodeCompleteConsumer.h.

## ◆ Availability

CXAvailabilityKind clang::CodeCompletionResult::Availability = CXAvailability_Available

The availability of this result.

Definition at line 793 of file CodeCompleteConsumer.h.

## ◆ CursorKind

CXCursorKind clang::CodeCompletionResult::CursorKind

The cursor kind that describes this result.

Definition at line 790 of file CodeCompleteConsumer.h.

## ◆ Declaration

const NamedDecl* clang::CodeCompletionResult::Declaration = nullptr

When Kind == RK_Declaration or RK_Pattern, the declaration we are referring to.

In the latter case, the declaration might be NULL.

Definition at line 764 of file CodeCompleteConsumer.h.

Referenced by clang::PrintingCodeCompleteConsumer::isResultFilteredOut().

## ◆ DeclaringEntity

bool clang::CodeCompletionResult::DeclaringEntity

Whether we're completing a declaration of the given entity, rather than a use of that entity.

Definition at line 844 of file CodeCompleteConsumer.h.

## ◆ FixIts

std::vector<FixItHint> clang::CodeCompletionResult::FixIts

Fix-its that must be applied before inserting the text for the corresponding completion.

By default, CodeCompletionBuilder only returns completions with empty fix-its. Extra completions with non-empty fix-its should be explicitly requested by setting CompletionOptions::IncludeFixIts.

For the clients to be able to compute position of the cursor after applying fix-its, the following conditions are guaranteed to hold for RemoveRange of the stored fix-its:

- Ranges in the fix-its are guaranteed to never contain the completion point (or identifier under completion point, if any) inside them, except at the start or at the end of the range.
- If a fix-it range starts or ends with completion point (or starts or ends after the identifier under completion point), it will contain at least one character. It allows to unambiguously recompute completion point after applying the fix-it.

The intuition is that provided fix-its change code around the identifier we complete, but are not allowed to touch the identifier itself or the completion point. One example of completions with corrections are the ones replacing '.' with '->' and vice versa:

std::unique_ptr<std::vector<int>> vec_ptr; In 'vec_ptr.^', one of the completions is 'push_back', it requires replacing '.' with '->'. In 'vec_ptr->^', one of the completions is 'release', it requires replacing '->' with '.'.

Definition at line 823 of file CodeCompleteConsumer.h.

## ◆ Hidden

bool clang::CodeCompletionResult::Hidden

Whether this result is hidden by another name.

Definition at line 826 of file CodeCompleteConsumer.h.

## ◆ InBaseClass

bool clang::CodeCompletionResult::InBaseClass

Whether this is a class member from base class.

Definition at line 829 of file CodeCompleteConsumer.h.

Referenced by setInBaseClass().

## ◆ Keyword

const char* clang::CodeCompletionResult::Keyword

When Kind == RK_Keyword, the string representing the keyword or symbol's spelling.

Definition at line 769 of file CodeCompleteConsumer.h.

Referenced by clang::PrintingCodeCompleteConsumer::isResultFilteredOut().

## ◆ Kind

ResultKind clang::CodeCompletionResult::Kind

The kind of result stored here.

Definition at line 787 of file CodeCompleteConsumer.h.

Referenced by clang::PrintingCodeCompleteConsumer::isResultFilteredOut().

## ◆ Macro

const IdentifierInfo* clang::CodeCompletionResult::Macro

When Kind == RK_Macro, the identifier that refers to a macro.

Definition at line 776 of file CodeCompleteConsumer.h.

Referenced by clang::PrintingCodeCompleteConsumer::isResultFilteredOut().

## ◆ MacroDefInfo

const MacroInfo* clang::CodeCompletionResult::MacroDefInfo = nullptr

If the result is RK_Macro, this can store the information about the macro definition.

This should be set in most cases but can be missing when the macro has been undefined.

Definition at line 860 of file CodeCompleteConsumer.h.

## ◆ Pattern

CodeCompletionString* clang::CodeCompletionResult::Pattern

When Kind == RK_Pattern, the code-completion string that describes the completion text to insert.

Definition at line 773 of file CodeCompleteConsumer.h.

Referenced by clang::PrintingCodeCompleteConsumer::isResultFilteredOut().

## ◆ Priority

unsigned clang::CodeCompletionResult::Priority

The priority of this particular code-completion result.

Definition at line 780 of file CodeCompleteConsumer.h.

Referenced by setInBaseClass().

## ◆ Qualifier

NestedNameSpecifier* clang::CodeCompletionResult::Qualifier = nullptr

If the result should have a nested-name-specifier, this is it.

When `QualifierIsInformative`, the nested-name-specifier is informative rather than required.

Definition at line 849 of file CodeCompleteConsumer.h.

## ◆ QualifierIsInformative

bool clang::CodeCompletionResult::QualifierIsInformative

Whether this result was found via lookup into a base class.

Definition at line 832 of file CodeCompleteConsumer.h.

## ◆ ShadowDecl

const UsingShadowDecl* clang::CodeCompletionResult::ShadowDecl = nullptr

If this Decl was unshadowed by using declaration, this can store a pointer to the UsingShadowDecl which was used in the unshadowing process.

This information can be used to uprank CodeCompletionResults / which have corresponding `using decl::qualified::name;` nearby.

Definition at line 855 of file CodeCompleteConsumer.h.

Referenced by isConstructor(), and setInBaseClass().

## ◆ StartParameter

unsigned clang::CodeCompletionResult::StartParameter = 0

Specifies which parameter (of a function, Objective-C method, macro, etc.) we should start with when formatting the result.

Definition at line 784 of file CodeCompleteConsumer.h.

## ◆ StartsNestedNameSpecifier

bool clang::CodeCompletionResult::StartsNestedNameSpecifier

Whether this declaration is the beginning of a nested-name-specifier and, therefore, should be followed by '::'.

Definition at line 836 of file CodeCompleteConsumer.h.

The documentation for this class was generated from the following files:

- include/clang/Sema/CodeCompleteConsumer.h
- lib/Sema/CodeCompleteConsumer.cpp
- lib/Sema/SemaCodeComplete.cpp