21#define TRY_DECL(D,CALL_EXPR) \
23 if (!IndexCtx.shouldIndex(D)) return true; \
28#define TRY_TO(CALL_EXPR) \
36class IndexingDeclVisitor :
public ConstDeclVisitor<IndexingDeclVisitor, bool> {
41 : IndexCtx(indexCtx) { }
68 if (
const NamedDecl *TTD = TD->getTemplatedDecl())
82 D->isInstanceMethod());
90 bool isIBType =
false) {
94 Parent->getLexicalDeclContext(),
97 auto IndexDefaultParmeterArgument = [&](
const ParmVarDecl *Parm,
104 if (
const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
106 if (
auto *FD = dyn_cast<FunctionDecl>(DC)) {
108 FD->isThisDeclarationADefinition())
110 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(DC)) {
111 if (MD->isThisDeclarationADefinition())
116 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
118 FD->isThisDeclarationADefinition()) {
119 for (
const auto *PI : FD->parameters()) {
120 IndexDefaultParmeterArgument(PI, D);
127 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
128 if (FD->isThisDeclarationADefinition()) {
129 for (
const auto *PV : FD->parameters()) {
130 IndexDefaultParmeterArgument(PV, D);
135 if (
auto *
C = D->getTrailingRequiresClause())
144 D->getOverriddenMethods(Overriden);
145 for(
auto overridden: Overriden) {
146 Relations.emplace_back((
unsigned) SymbolRole::RelationOverrideOf,
150 Relations.emplace_back((
unsigned)SymbolRole::RelationAccessorOf,
162 if (AssociatedProp) {
163 bool isGetter = !D->param_size();
165 AssociatedProp->getGetterNameLoc():
166 AssociatedProp->getSetterNameLoc();
176 }
else if (AttrLoc.
isValid()) {
183 bool hasIBActionAndFirst = D->
hasAttr<IBActionAttr>();
184 for (
const auto *I : D->parameters()) {
185 handleDeclarator(I, D, hasIBActionAndFirst);
186 hasIBActionAndFirst =
false;
189 if (D->isThisDeclarationADefinition()) {
205 gatherTemplatePseudoOverrides(
const NamedDecl *D,
218 bool TypeOverride = isa<TypeDecl>(D);
220 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(ND))
221 ND = CTD->getTemplatedDecl();
222 if (ND->isImplicit())
226 if (ND->getKind() != D->
getKind())
228 }
else if (!isa<TypeDecl>(ND))
230 if (
const auto *FD = dyn_cast<FunctionDecl>(ND)) {
231 const auto *DFD = cast<FunctionDecl>(D);
233 if (FD->getStorageClass() != DFD->getStorageClass() ||
234 FD->getNumParams() != DFD->getNumParams())
237 Relations.emplace_back(
246 if (
auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
247 if (CXXMD->isVirtual())
248 Roles |= (
unsigned)SymbolRole::Dynamic;
250 Relations.emplace_back((
unsigned)SymbolRole::RelationOverrideOf, O);
253 gatherTemplatePseudoOverrides(D, Relations);
257 Base->getTemplatedDecl()));
264 Ctor->getParent(), Ctor->getDeclContext(),
265 (
unsigned)SymbolRole::NameReference);
268 for (
const auto *Init : Ctor->inits()) {
269 if (Init->isWritten()) {
273 (
unsigned)SymbolRole::Write);
274 IndexCtx.
indexBody(Init->getInit(), D, D);
278 if (
auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
280 TypeNameInfo->getTypeLoc().getBeginLoc(),
281 Dtor->getParent(), Dtor->getDeclContext(),
282 (
unsigned)SymbolRole::NameReference);
284 }
else if (
const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
285 IndexCtx.
handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),
286 Guide->getLocation(), Guide,
287 Guide->getDeclContext());
292 for (
const auto &Arg : TemplateArgInfo->arguments())
305 bool VisitVarDecl(
const VarDecl *D) {
307 gatherTemplatePseudoOverrides(D, Relations);
315 for (
const auto *Binding : D->
bindings())
317 return Base::VisitDecompositionDecl(D);
320 bool VisitFieldDecl(
const FieldDecl *D) {
322 gatherTemplatePseudoOverrides(D, Relations);
357 gatherTemplatePseudoOverrides(D, Relations);
364 bool VisitTagDecl(
const TagDecl *D) {
369 gatherTemplatePseudoOverrides(D, Relations);
373 gatherTemplatePseudoOverrides(D, Relations);
381 bool VisitEnumDecl(
const EnumDecl *ED) {
395 I = ProtList.
begin(), E = ProtList.
end(); I != E; ++I, ++LI) {
412 bool hasSuperTypedef =
false;
414 if (
auto *TT = TInfo->getType()->getAs<
TypedefType>()) {
415 if (
auto *TD = TT->getDecl()) {
416 hasSuperTypedef =
true;
456 if (
Class->isImplicitInterfaceDecl())
465 if (I->getLocation().isInvalid())
468 for (
const auto *I : D->
decls()) {
469 if (!isa<ObjCPropertyImplDecl>(I) ||
470 cast<ObjCPropertyImplDecl>(I)->getLocation().isValid())
485 (
unsigned)SymbolRole::RelationExtendedBy, D
526 handleObjCMethod(MD, D);
529 handleObjCMethod(MD, D);
531 if (IBOutletCollectionAttr *
attr = D->
getAttr<IBOutletCollectionAttr>())
546 Relations.push_back({(
SymbolRoleSet)SymbolRole::RelationAccessorOf, ID});
548 Loc = Container->getLocation();
560 if (MD->isPropertyAccessor() && !hasUserDefined(MD, Container))
561 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
564 if (MD->isPropertyAccessor() && !hasUserDefined(MD, Container))
565 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
568 if (IvarD->getSynthesize()) {
578 IvarLoc = Container->getLocation();
606 bool VisitUsingDecl(
const UsingDecl *D) {
613 for (
const auto *I : D->
shadows()) {
617 if (isa<UnresolvedUsingIfExistsDecl>(I->getUnderlyingDecl()))
660 bool VisitClassTemplateSpecializationDecl(
const
667 const Decl *SpecializationOf =
682 static bool shouldIndexTemplateParameterDefaultValue(
const NamedDecl *D) {
687 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
688 return FD->getCanonicalDecl() == FD;
689 else if (
const auto *TD = dyn_cast<TagDecl>(D))
690 return TD->getCanonicalDecl() == TD;
691 else if (
const auto *VD = dyn_cast<VarDecl>(D))
692 return VD->getCanonicalDecl() == VD;
701 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) {
702 if (TTP->hasDefaultArgument())
704 if (
auto *
C = TTP->getTypeConstraint())
706 Parent, TTP->getLexicalDeclContext());
707 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) {
709 if (NTTP->hasDefaultArgument())
711 }
else if (
const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) {
712 if (TTPD->hasDefaultArgument())
713 handleTemplateArgumentLoc(TTPD->getDefaultArgument(),
Parent,
714 TP->getLexicalDeclContext());
717 if (
auto *R = Params->getRequiresClause())
728 if (Params && shouldIndexTemplateParameterDefaultValue(
Parent)) {
729 indexTemplateParameters(Params,
Parent);
737 indexTemplateParameters(Params, D);
776 if (D->
isImplicit() && shouldIgnoreIfImplicit(D))
782 IndexingDeclVisitor Visitor(*
this);
783 bool ShouldContinue = Visitor.Visit(D);
787 if (!Visitor.Handled && isa<DeclContext>(D))
794 for (
const auto *I : DC->
decls())
804 if (isa<ObjCMethodDecl>(D))
This file provides AST data structures related to concepts.
Defines the C++ template declaration subclasses.
#define TRY_DECL(D, CALL_EXPR)
#define TRY_TO(CALL_EXPR)
shadow_range shadows() const
Represents a C++ constructor within a class.
Represents a C++ destructor within a class.
Represents a static or instance method of a struct/union/class.
overridden_method_range overridden_methods() const
Represents a C++ struct/union/class.
Declaration of a class template.
Represents a class template specialization, which refers to a class template with a given set of temp...
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this.
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
Declaration of a C++20 concept.
Expr * getConstraintExpr() const
A simple visitor class that helps create declaration visitors.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Decl - This represents one declaration (or definition), e.g.
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
virtual Stmt * getBody() const
getBody - If this Decl represents a declaration for a body of code, such as a function or method defi...
SourceLocation getLocation() const
DeclContext * getDeclContext()
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Represents a ValueDecl that came out of a declarator.
A decomposition declaration.
ArrayRef< BindingDecl * > bindings() const
An instance of this object exists for each enum constant that is defined.
const Expr * getInitExpr() const
TypeSourceInfo * getIntegerTypeSourceInfo() const
Return the type source info for the underlying integer type, if no type source info exists,...
Represents a member of a struct/union/class.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
bool isBitField() const
Determines whether this field is a bitfield.
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Expr * getBitWidth() const
Returns the expression that represents the bit width, if this field is a bit field.
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Represents a function declaration or definition.
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
An instance of this class represents the declaration of a property member.
This represents a decl that may have a name.
Represents a C++ namespace alias.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
Represent a C++ namespace.
ObjCCategoryDecl - Represents a category declaration.
ObjCInterfaceDecl * getClassInterface()
const ObjCProtocolList & getReferencedProtocols() const
SourceLocation getCategoryNameLoc() const
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
SourceLocation getCategoryNameLoc() const
ObjCCategoryDecl * getCategoryDecl() const
ObjCContainerDecl - Represents a container for method declarations.
propimpl_range property_impls() const
const ObjCInterfaceDecl * getClassInterface() const
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
const ObjCProtocolList & getReferencedProtocols() const
ObjCProtocolList::iterator protocol_iterator
ObjCInterfaceDecl * getSuperClass() const
TypeSourceInfo * getSuperClassTInfo() const
ObjCIvarDecl - Represents an ObjC instance variable.
bool getSynthesize() const
ObjCMethodDecl - Represents an instance or class method declaration.
bool isPropertyAccessor() const
bool isSynthesizedAccessorStub() const
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
Represents one property declaration in an Objective-C interface.
ObjCMethodDecl * getGetterMethodDecl() const
ObjCMethodDecl * getSetterMethodDecl() const
TypeSourceInfo * getTypeSourceInfo() const
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
ObjCIvarDecl * getPropertyIvarDecl() const
SourceLocation getPropertyIvarDeclLoc() const
Kind getPropertyImplementation() const
ObjCPropertyDecl * getPropertyDecl() const
Represents an Objective-C protocol declaration.
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
const ObjCProtocolList & getReferencedProtocols() const
A list of Objective-C protocols, along with the source locations at which they were referenced.
loc_iterator loc_begin() const
Represents a parameter to a function.
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
bool hasUninstantiatedDefaultArg() const
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Represents a C++11 static_assert declaration.
Stmt - This represents one statement.
Represents the declaration of a struct/union/class/enum.
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
Location wrapper for a TemplateArgument.
TemplateArgumentLocInfo getLocInfo() const
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
@ Template
The template argument is a template name that was provided for a template template parameter.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ Type
The template argument is a type.
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
The base class of all kinds of template declarations (e.g., class, function, etc.).
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
A container of type source information.
Base class for declarations which introduce a typedef-name.
TypeSourceInfo * getTypeSourceInfo() const
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type,...
Represents a dependent using declaration which was marked with typename.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Represents a dependent using declaration which was not marked with typename.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Represents a C++ using-declaration.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
Represents C++ using-directive.
NamedDecl * getNominatedNamespaceAsWritten()
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
Represents a variable declaration or definition.
const Expr * getInit() const
RetTy VisitDecl(PTR(Decl) D)
bool shouldIndexImplicitInstantiation() const
bool importedModule(const ImportDecl *ImportD)
bool shouldIndex(const Decl *D)
bool indexDeclContext(const DeclContext *DC)
bool shouldIndexFunctionLocalSymbols() const
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
bool indexTopLevelDecl(const Decl *D)
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt, const Expr *RefE=nullptr)
bool shouldIndexTemplateParameters() const
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
bool shouldIndexParametersInDeclarations() const
bool indexDeclGroupRef(DeclGroupRef DG)
static bool isTemplateImplicitInstantiation(const Decl *D)
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations=std::nullopt)
const LangOptions & getLangOpts() const
bool indexDecl(const Decl *D)
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=std::nullopt)
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
@ C
Languages that the frontend can parse and compile.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Location information for a TemplateArgument.
TypeSourceInfo * getAsTypeSourceInfo() const
std::function< bool(const Decl *)> ShouldTraverseDecl
Represents a relation to another symbol for a symbol occurrence.