13 using namespace clang;
14 using namespace index;
16 #define TRY_DECL(D,CALL_EXPR) \ 18 if (!IndexCtx.shouldIndex(D)) return true; \ 23 #define TRY_TO(CALL_EXPR) \ 31 class IndexingDeclVisitor :
public ConstDeclVisitor<IndexingDeclVisitor, bool> {
36 : IndexCtx(indexCtx) { }
40 bool VisitDecl(
const Decl *D) {
72 if (
const NamedDecl *TTD = TD->getTemplatedDecl())
83 bool isIBType =
false) {
84 if (!Parent) Parent = D;
91 if (
const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
92 auto *DC = Parm->getDeclContext();
93 if (
auto *FD = dyn_cast<FunctionDecl>(DC)) {
95 FD->isThisDeclarationADefinition())
97 }
else if (
auto *MD = dyn_cast<ObjCMethodDecl>(DC)) {
98 if (MD->isThisDeclarationADefinition())
103 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
105 FD->isThisDeclarationADefinition()) {
106 for (
auto PI : FD->parameters()) {
113 if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
114 if (FD->isThisDeclarationADefinition()) {
115 for (
const auto *PV : FD->parameters()) {
116 if (PV->hasDefaultArg() && !PV->hasUninstantiatedDefaultArg() &&
117 !PV->hasUnparsedDefaultArg())
118 IndexCtx.
indexBody(PV->getDefaultArg(), D);
131 for(
auto overridden: Overriden) {
148 if (AssociatedProp) {
151 AssociatedProp->getGetterNameLoc():
152 AssociatedProp->getSetterNameLoc();
162 }
else if (AttrLoc.
isValid()) {
169 bool hasIBActionAndFirst = D->
hasAttr<IBActionAttr>();
171 handleDeclarator(I, D, hasIBActionAndFirst);
172 hasIBActionAndFirst =
false;
191 gatherTemplatePseudoOverrides(
const NamedDecl *D,
202 if (
const auto *CTD = Template.dyn_cast<ClassTemplateDecl *>()) {
204 bool TypeOverride = isa<TypeDecl>(D);
206 if (
const auto *CTD = dyn_cast<ClassTemplateDecl>(ND))
207 ND = CTD->getTemplatedDecl();
208 if (ND->isImplicit())
212 if (ND->getKind() != D->
getKind())
214 }
else if (!isa<TypeDecl>(ND))
216 if (
const auto *FD = dyn_cast<FunctionDecl>(ND)) {
217 const auto *DFD = cast<FunctionDecl>(D);
219 if (FD->getStorageClass() != DFD->getStorageClass() ||
220 FD->getNumParams() != DFD->getNumParams())
223 Relations.emplace_back(
232 if (
auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
233 if (CXXMD->isVirtual())
239 gatherTemplatePseudoOverrides(D, Relations);
243 Base->getTemplatedDecl()));
250 Ctor->getParent(), Ctor->getDeclContext(),
254 for (
const auto *Init : Ctor->inits()) {
255 if (Init->isWritten()) {
257 if (
const FieldDecl *Member = Init->getAnyMember())
260 IndexCtx.
indexBody(Init->getInit(), D, D);
264 if (
auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
266 TypeNameInfo->getTypeLoc().getBeginLoc(),
267 Dtor->getParent(), Dtor->getDeclContext(),
270 }
else if (
const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
271 IndexCtx.
handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),
272 Guide->getLocation(), Guide,
273 Guide->getDeclContext());
278 for (
const auto &Arg : TemplateArgInfo->arguments())
291 bool VisitVarDecl(
const VarDecl *D) {
293 gatherTemplatePseudoOverrides(D, Relations);
301 for (
const auto *Binding : D->
bindings())
303 return Base::VisitDecompositionDecl(D);
306 bool VisitFieldDecl(
const FieldDecl *D) {
308 gatherTemplatePseudoOverrides(D, Relations);
343 gatherTemplatePseudoOverrides(D, Relations);
350 bool VisitTagDecl(
const TagDecl *D) {
355 gatherTemplatePseudoOverrides(D, Relations);
359 gatherTemplatePseudoOverrides(D, Relations);
372 I = ProtList.
begin(), E = ProtList.
end(); I != E; ++I, ++LI) {
389 bool hasSuperTypedef =
false;
391 if (
auto *TT = TInfo->getType()->getAs<
TypedefType>()) {
392 if (
auto *TD = TT->getDecl()) {
393 hasSuperTypedef =
true;
442 if (I->getLocation().isInvalid())
445 for (
const auto *I : D->
decls()) {
446 if (!isa<ObjCPropertyImplDecl>(I) ||
447 cast<ObjCPropertyImplDecl>(I)->getLocation().isValid())
465 if (!CategoryLoc.isValid())
466 CategoryLoc = D->getLocation();
468 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
484 CategoryLoc = D->getLocation();
503 handleObjCMethod(MD, D);
506 handleObjCMethod(MD, D);
508 if (IBOutletCollectionAttr *attr = D->
getAttr<IBOutletCollectionAttr>())
523 Relations.push_back({(SymbolRoleSet)SymbolRole::RelationAccessorOf, ID});
524 if (Loc.isInvalid()) {
537 if (MD->isPropertyAccessor() &&
538 !hasUserDefined(MD, Container))
539 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
542 if (MD->isPropertyAccessor() &&
543 !hasUserDefined(MD, Container))
544 IndexCtx.
handleDecl(MD, Loc, AccessorMethodRoles, {}, Container);
547 if (IvarD->getSynthesize()) {
585 bool VisitUsingDecl(
const UsingDecl *D) {
592 for (
const auto *I : D->
shadows())
632 bool VisitClassTemplateSpecializationDecl(
const 639 const Decl *SpecializationOf =
640 Template.is<ClassTemplateDecl *>()
641 ? (
Decl *)Template.get<ClassTemplateDecl *>()
654 static bool shouldIndexTemplateParameterDefaultValue(
const NamedDecl *D) {
659 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
660 return FD->getCanonicalDecl() == FD;
661 else if (
const auto *TD = dyn_cast<TagDecl>(D))
662 return TD->getCanonicalDecl() == TD;
663 else if (
const auto *VD = dyn_cast<VarDecl>(D))
664 return VD->getCanonicalDecl() == VD;
676 shouldIndexTemplateParameterDefaultValue(Parent)) {
681 if (
const auto *TTP = dyn_cast<TemplateTypeParmDecl>(TP)) {
682 if (TTP->hasDefaultArgument())
684 }
else if (
const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(TP)) {
685 if (NTTP->hasDefaultArgument())
687 }
else if (
const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) {
688 if (TTPD->hasDefaultArgument())
689 handleTemplateArgumentLoc(TTPD->getDefaultArgument(),
Parent,
690 TP->getLexicalDeclContext());
695 return Visit(Parent);
731 if (D->
isImplicit() && shouldIgnoreIfImplicit(D))
734 if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation())
737 IndexingDeclVisitor Visitor(*
this);
738 bool ShouldContinue = Visitor.Visit(D);
742 if (!Visitor.Handled && isa<DeclContext>(D))
743 return indexDeclContext(cast<DeclContext>(D));
749 for (
const auto *I : DC->
decls())
759 if (isa<ObjCMethodDecl>(D))
767 if (!indexTopLevelDecl(*I))
Represents a function declaration or definition.
bool isThisDeclarationADefinition() const
Returns whether this specific method is a definition.
Represents a relation to another symbol for a symbol occurrence.
unsigned param_size() const
ObjCInterfaceDecl * getClassInterface()
bool isThisDeclarationADefinition() const
Determine whether this particular declaration of this class is actually also a definition.
ObjCIvarDecl * getPropertyIvarDecl() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Stmt - This represents one statement.
Expr * getBitWidth() const
#define TRY_DECL(D, CALL_EXPR)
const ASTTemplateArgumentListInfo * getTemplateSpecializationArgsAsWritten() const
Retrieve the template argument list as written in the sources, if any.
An instance of this object exists for each enum constant that is defined.
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
Decl - This represents one declaration (or definition), e.g.
NamedDecl * getTemplatedDecl() const
Get the underlying, templated declaration.
bool indexTopLevelDecl(const Decl *D)
Represent a C++ namespace.
A container of type source information.
Represents a C++ constructor within a class.
const DeclContext * getParentFunctionOrMethod() const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext...
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
SourceLocation getTargetNameLoc() const
Returns the location of the identifier in the named namespace.
FriendDecl - Represents the declaration of a friend entity, which can be a function, a type, or a templated function or type.
TRY_TO(TraverseType(T->getPointeeType()))
Represents a variable declaration or definition.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
ObjCMethodDecl - Represents an instance or class method declaration.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Stores a list of template parameters for a TemplateDecl and its derived classes.
Represents a parameter to a function.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a class template specialization, which refers to a class template with a given set of temp...
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
const LangOptions & getLangOpts() const
const ObjCProtocolList & getReferencedProtocols() const
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Represents a member of a struct/union/class.
ObjCMethodDecl * getSetterMethodDecl() const
NamedDecl * getFriendDecl() const
If this friend declaration doesn't name a type, return the inner declaration.
loc_iterator loc_begin() const
bool shouldIndexParametersInDeclarations() const
Represents a C++ using-declaration.
ArrayRef< BindingDecl * > bindings() const
bool isBitField() const
Determines whether this field is a bitfield.
bool shouldIndexTemplateParameters() const
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
ObjCContainerDecl - Represents a container for method declarations.
NamedDecl * getNominatedNamespaceAsWritten()
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
bool shouldIndexFunctionLocalSymbols() const
void getOverriddenMethods(SmallVectorImpl< const ObjCMethodDecl *> &Overridden) const
Return overridden methods for the given Method.
bool indexDecl(const Decl *D)
const Expr * getInitExpr() const
SourceLocation getPropertyIvarDeclLoc() const
Represents an Objective-C protocol declaration.
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
Represents an ObjC class declaration.
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
FunctionTemplateDecl * getPrimaryTemplate() const
Retrieve the primary template that this function template specialization either specializes or was in...
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Represents a ValueDecl that came out of a declarator.
TypeSourceInfo * getTypeSourceInfo() const
bool isTransparentTag() const
Determines if this typedef shares a name and spelling location with its underlying tag type...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source-location information.
TypeSourceInfo * getSuperClassTInfo() const
TypeSourceInfo * getTypeSourceInfo() const
bool indexDeclContext(const DeclContext *DC)
Represents a C++ destructor within a class.
bool isThisDeclarationADefinition() const
Returns whether this specific declaration of the function is also a definition that does not contain ...
bool isThisDeclarationADefinition() const
Determine whether this particular declaration is also the definition.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
SourceLocation getSelectorStartLoc() const
overridden_method_range overridden_methods() const
DeclContext * getDeclContext()
ObjCInterfaceDecl * getSuperClass() const
bool indexDeclGroupRef(DeclGroupRef DG)
llvm::PointerUnion< ClassTemplateDecl *, ClassTemplatePartialSpecializationDecl * > getSpecializedTemplateOrPartial() const
Retrieve the class template or class template partial specialization which was specialized by this...
propimpl_range property_impls() const
bool handleReference(const NamedDecl *D, SourceLocation Loc, const NamedDecl *Parent, const DeclContext *DC, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None, const Expr *RefE=nullptr, const Decl *RefD=nullptr)
bool isInstanceMethod() const
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Selector getSelector() const
ObjCProtocolList::iterator protocol_iterator
TypeSourceInfo * getAsTypeSourceInfo() const
TypeSourceInfo * getReturnTypeSourceInfo() const
Encodes a location in the source.
bool getSynthesize() const
Represents the declaration of a struct/union/class/enum.
ObjCCategoryDecl * getCategoryDecl() const
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.
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set...
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Represents a static or instance method of a struct/union/class.
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
ObjCCategoryDecl - Represents a category declaration.
Represents one property declaration in an Objective-C interface.
TypeSourceInfo * getTypeAsWritten() const
Gets the type of this specialization as it was written by the user, if it was so written.
bool isImplicitInterfaceDecl() const
isImplicitInterfaceDecl - check that this is an implicitly declared ObjCInterfaceDecl node...
Represents a C++11 static_assert declaration.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier (with source-location information) that qualifies the name of this...
Base class for declarations which introduce a typedef-name.
const ObjCInterfaceDecl * getClassInterface() const
bool shouldIndex(const Decl *D)
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
const TemplateArgument & getArgument() const
bool handleDecl(const Decl *D, SymbolRoleSet Roles=SymbolRoleSet(), ArrayRef< SymbolRelation > Relations=None)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
The base class of all kinds of template declarations (e.g., class, function, etc.).
Kind getPropertyImplementation() const
The template argument is a pack expansion of a template name that was provided for a template templat...
const ObjCProtocolList & getReferencedProtocols() const
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name of the namespace, with source-location inf...
const Expr * getInit() const
A decomposition declaration.
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.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC=nullptr, bool isBase=false, bool isIBType=false)
Location wrapper for a TemplateArgument.
void indexNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, const NamedDecl *Parent, const DeclContext *DC=nullptr)
void indexTagDecl(const TagDecl *D, ArrayRef< SymbolRelation > Relations=None)
TypeSourceInfo * getTypeSourceInfo() const
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
bool importedModule(const ImportDecl *ImportD)
A list of Objective-C protocols, along with the source locations at which they were referenced...
The template argument is a type.
ArgKind getKind() const
Return the kind of stored template argument.
shadow_range shadows() const
bool isThisDeclarationADefinition() const
Return true if this declaration is a completion definition of the type.
Represents a C++ struct/union/class.
The template argument is a template name that was provided for a template template parameter...
TemplateArgumentLocInfo getLocInfo() const
ObjCIvarDecl - Represents an ObjC instance variable.
Location information for a TemplateArgument.
Declaration of a class template.
ObjCPropertyDecl * getPropertyDecl() const
SourceLocation getTemplateNameLoc() const
void indexBody(const Stmt *S, const NamedDecl *Parent, const DeclContext *DC=nullptr)
An instance of this class represents the declaration of a property member.
ObjCMethodDecl * getMethod(Selector Sel, bool isInstance, bool AllowHidden=false) const
ObjCMethodDecl * getGetterMethodDecl() const
This represents a decl that may have a name.
Represents a C++ namespace alias.
bool isPropertyAccessor() const
Represents C++ using-directive.
A simple visitor class that helps create declaration visitors.
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion, return the pattern as a template name.
bool isFreeStanding() const
True if this tag is free standing, e.g. "struct foo;".
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
SourceLocation getLocation() const
ArrayRef< ParmVarDecl * > parameters() const
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...