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())
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);
254 if (
const auto *
Base =
D->getPrimaryTemplate())
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);
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());
291 D->getTemplateSpecializationArgsAsWritten()) {
292 for (
const auto &Arg : TemplateArgInfo->arguments())
296 if (
D->isThisDeclarationADefinition()) {
305 bool VisitVarDecl(
const VarDecl *
D) {
307 gatherTemplatePseudoOverrides(
D, Relations);
315 for (
const auto *Binding :
D->bindings())
317 return Base::VisitDecompositionDecl(
D);
322 gatherTemplatePseudoOverrides(
D, Relations);
327 else if (
D->hasInClassInitializer())
333 if (
D->getSynthesize()) {
355 if (!
D->isTransparentTag()) {
357 gatherTemplatePseudoOverrides(
D, Relations);
364 bool VisitTagDecl(
const TagDecl *
D) {
366 if (
D->isFreeStanding()) {
367 if (
D->isThisDeclarationADefinition()) {
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) {
408 if (
D->isThisDeclarationADefinition()) {
411 if (
auto *SuperD =
D->getSuperClass()) {
412 bool hasSuperTypedef =
false;
413 if (
auto *TInfo =
D->getSuperClassTInfo()) {
414 if (
auto *TT = TInfo->getType()->getAs<
TypedefType>()) {
415 if (
auto *TD = TT->getDecl()) {
416 hasSuperTypedef =
true;
428 TRY_TO(handleReferencedProtocols(
D->getReferencedProtocols(),
D,
439 if (
D->isThisDeclarationADefinition()) {
441 TRY_TO(handleReferencedProtocols(
D->getReferencedProtocols(),
D,
456 if (
Class->isImplicitInterfaceDecl())
464 for (
const auto *
I :
D->property_impls()) {
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
491 TRY_TO(handleReferencedProtocols(
D->getReferencedProtocols(),
D,
516 if (
D->isPropertyAccessor())
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();
613 for (
const auto *
I :
D->shadows()) {
617 if (isa<UnresolvedUsingIfExistsDecl>(
I->getUnderlyingDecl()))
660 bool VisitClassTemplateSpecializationDecl(
const
666 Template =
D->getSpecializedTemplateOrPartial();
667 const Decl *SpecializationOf =
671 if (!
D->isThisDeclarationADefinition())
678 D->getTemplateArgsAsWritten()) {
679 for (
const auto &Arg : TemplateArgInfo->arguments())
685 static bool shouldIndexTemplateParameterDefaultValue(
const NamedDecl *
D) {
690 if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
691 return FD->getCanonicalDecl() == FD;
692 else if (
const auto *TD = dyn_cast<TagDecl>(
D))
693 return TD->getCanonicalDecl() == TD;
694 else if (
const auto *VD = dyn_cast<VarDecl>(
D))
695 return VD->getCanonicalDecl() == VD;
704 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) {
705 if (TTP->hasDefaultArgument())
706 handleTemplateArgumentLoc(TTP->getDefaultArgument(),
Parent,
707 TP->getLexicalDeclContext());
708 if (
auto *
C = TTP->getTypeConstraint())
710 Parent, TTP->getLexicalDeclContext());
711 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) {
713 if (NTTP->hasDefaultArgument())
714 handleTemplateArgumentLoc(NTTP->getDefaultArgument(),
Parent,
715 TP->getLexicalDeclContext());
716 }
else if (
const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) {
717 if (TTPD->hasDefaultArgument())
718 handleTemplateArgumentLoc(TTPD->getDefaultArgument(),
Parent,
719 TP->getLexicalDeclContext());
722 if (
auto *R = Params->getRequiresClause())
732 auto *Params =
D->getTemplateParameters();
733 if (Params && shouldIndexTemplateParameterDefaultValue(
Parent)) {
734 indexTemplateParameters(Params,
Parent);
741 if (
auto *Params =
D->getTemplateParameters())
742 indexTemplateParameters(Params,
D);
743 if (
auto *
E =
D->getConstraintExpr())
749 if (
auto ND =
D->getFriendDecl()) {
760 if (
auto Ty =
D->getFriendType()) {
787 IndexingDeclVisitor Visitor(*
this);
788 bool ShouldContinue = Visitor.Visit(
D);
792 if (!Visitor.Handled && isa<DeclContext>(
D))
799 for (
const auto *
I : DC->
decls())
809 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)
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.
Declaration of a C++20 concept.
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.
An instance of this object exists for each enum constant that is defined.
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.
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Represents a function declaration or definition.
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.
Represent a C++ namespace.
ObjCCategoryDecl - Represents a category declaration.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
ObjCContainerDecl - Represents a container for method declarations.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
ObjCProtocolList::iterator protocol_iterator
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCMethodDecl - Represents an instance or class method declaration.
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
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Represents an Objective-C protocol declaration.
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.
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.).
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.
Base class for declarations which introduce a typedef-name.
Represents a dependent using declaration which was marked with typename.
Represents a dependent using declaration which was not marked with typename.
Represents a C++ using-declaration.
Represents C++ using-directive.
Represents a variable declaration or definition.
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.
The JSON file list parser is used to communicate input to InstallAPI.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
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.