Lines Matching +full:- +full:d
1 //===- IndexDecl.cpp - Indexing declarations ------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
21 #define TRY_DECL(D,CALL_EXPR) \
23 if (!IndexCtx.shouldIndex(D)) return true; \
45 bool VisitDecl(const Decl *D) {
68 if (const NamedDecl *TTD = TD->getTemplatedDecl())
79 static bool hasUserDefined(const ObjCMethodDecl *D,
81 const ObjCMethodDecl *MD = Container->getMethod(D->getSelector(),
82 D->isInstanceMethod());
83 return MD && !MD->isImplicit() && MD->isThisDeclarationADefinition() &&
84 !MD->isSynthesizedAccessorStub();
88 void handleDeclarator(const DeclaratorDecl *D,
91 if (!Parent) Parent = D;
93 IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), Parent,
94 Parent->getLexicalDeclContext(),
96 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent);
99 if (Parm->hasDefaultArg() && !Parm->hasUninstantiatedDefaultArg() &&
100 !Parm->hasUnparsedDefaultArg())
101 IndexCtx.indexBody(Parm->getDefaultArg(), Parent);
104 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
105 auto *DC = Parm->getDeclContext();
108 FD->isThisDeclarationADefinition())
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())
139 bool handleObjCMethod(const ObjCMethodDecl *D,
144 D->getOverriddenMethods(Overriden);
155 SourceLocation MethodLoc = D->getSelectorStartLoc();
157 MethodLoc = D->getLocation();
163 bool isGetter = !D->param_size();
165 AssociatedProp->getGetterNameLoc():
166 AssociatedProp->getSetterNameLoc();
170 if (D->isImplicit()) {
177 IndexCtx.handleReference(D, AttrLoc, cast<NamedDecl>(D->getDeclContext()),
178 D->getDeclContext(), 0);
181 TRY_DECL(D, IndexCtx.handleDecl(D, MethodLoc, Roles, Relations));
182 IndexCtx.indexTypeSourceInfo(D->getReturnTypeSourceInfo(), D);
183 bool hasIBActionAndFirst = D->hasAttr<IBActionAttr>();
184 for (const auto *I : D->parameters()) {
185 handleDeclarator(I, D, /*isIBType=*/hasIBActionAndFirst);
189 if (D->isThisDeclarationADefinition()) {
190 const Stmt *Body = D->getBody();
192 IndexCtx.indexBody(Body, D, D);
198 /// Gather the declarations which the given declaration \D overrides in a
199 /// pseudo-override manner.
201 /// Pseudo-overrides occur when a class template specialization declares
203 /// non-specialized template.
205 gatherTemplatePseudoOverrides(const NamedDecl *D,
210 dyn_cast<ClassTemplateSpecializationDecl>(D->getLexicalDeclContext());
215 Template = CTSD->getSpecializedTemplateOrPartial();
217 const CXXRecordDecl *Pattern = CTD->getTemplatedDecl();
218 bool TypeOverride = isa<TypeDecl>(D);
219 for (const NamedDecl *ND : Pattern->lookup(D->getDeclName())) {
221 ND = CTD->getTemplatedDecl();
222 if (ND->isImplicit())
226 if (ND->getKind() != D->getKind())
231 const auto *DFD = cast<FunctionDecl>(D);
233 if (FD->getStorageClass() != DFD->getStorageClass() ||
234 FD->getNumParams() != DFD->getNumParams())
243 bool VisitFunctionDecl(const FunctionDecl *D) {
246 if (auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) {
247 if (CXXMD->isVirtual())
249 for (const CXXMethodDecl *O : CXXMD->overridden_methods()) {
253 gatherTemplatePseudoOverrides(D, Relations);
254 if (const auto *Base = D->getPrimaryTemplate())
257 Base->getTemplatedDecl()));
259 TRY_DECL(D, IndexCtx.handleDecl(D, Roles, Relations));
260 handleDeclarator(D);
262 if (const CXXConstructorDecl *Ctor = dyn_cast<CXXConstructorDecl>(D)) {
263 IndexCtx.handleReference(Ctor->getParent(), Ctor->getLocation(),
264 Ctor->getParent(), Ctor->getDeclContext(),
268 for (const auto *Init : Ctor->inits()) {
269 if (Init->isWritten()) {
270 IndexCtx.indexTypeSourceInfo(Init->getTypeSourceInfo(), D);
271 if (const FieldDecl *Member = Init->getAnyMember())
272 IndexCtx.handleReference(Member, Init->getMemberLocation(), D, D,
274 IndexCtx.indexBody(Init->getInit(), D, D);
277 } else if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(D)) {
278 if (auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
279 IndexCtx.handleReference(Dtor->getParent(),
280 TypeNameInfo->getTypeLoc().getBeginLoc(),
281 Dtor->getParent(), Dtor->getDeclContext(),
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())
293 handleTemplateArgumentLoc(Arg, D, D->getLexicalDeclContext());
296 if (D->isThisDeclarationADefinition()) {
297 const Stmt *Body = D->getBody();
299 IndexCtx.indexBody(Body, D, D);
305 bool VisitVarDecl(const VarDecl *D) {
307 gatherTemplatePseudoOverrides(D, Relations);
308 TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
309 handleDeclarator(D);
310 IndexCtx.indexBody(D->getInit(), D);
314 bool VisitDecompositionDecl(const DecompositionDecl *D) {
315 for (const auto *Binding : D->bindings())
317 return Base::VisitDecompositionDecl(D);
320 bool VisitFieldDecl(const FieldDecl *D) {
322 gatherTemplatePseudoOverrides(D, Relations);
323 TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
324 handleDeclarator(D);
325 if (D->isBitField())
326 IndexCtx.indexBody(D->getBitWidth(), D);
327 else if (D->hasInClassInitializer())
328 IndexCtx.indexBody(D->getInClassInitializer(), D);
332 bool VisitObjCIvarDecl(const ObjCIvarDecl *D) {
333 if (D->getSynthesize()) {
337 TRY_DECL(D, IndexCtx.handleDecl(D));
338 handleDeclarator(D);
342 bool VisitMSPropertyDecl(const MSPropertyDecl *D) {
343 TRY_DECL(D, IndexCtx.handleDecl(D));
344 handleDeclarator(D);
348 bool VisitEnumConstantDecl(const EnumConstantDecl *D) {
349 TRY_DECL(D, IndexCtx.handleDecl(D));
350 IndexCtx.indexBody(D->getInitExpr(), D);
354 bool VisitTypedefNameDecl(const TypedefNameDecl *D) {
355 if (!D->isTransparentTag()) {
357 gatherTemplatePseudoOverrides(D, Relations);
358 TRY_DECL(D, IndexCtx.handleDecl(D, SymbolRoleSet(), Relations));
359 IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
364 bool VisitTagDecl(const TagDecl *D) {
365 // Non-free standing tags are handled in indexTypeSourceInfo.
366 if (D->isFreeStanding()) {
367 if (D->isThisDeclarationADefinition()) {
369 gatherTemplatePseudoOverrides(D, Relations);
370 IndexCtx.indexTagDecl(D, Relations);
373 gatherTemplatePseudoOverrides(D, Relations);
374 return IndexCtx.handleDecl(D, D->getLocation(), SymbolRoleSet(),
375 Relations, D->getLexicalDeclContext());
384 // visit integer-base here, which is different than other TagDecl bases.
385 if (auto *TSI = ED->getIntegerTypeSourceInfo())
407 bool VisitObjCInterfaceDecl(const ObjCInterfaceDecl *D) {
408 if (D->isThisDeclarationADefinition()) {
409 TRY_DECL(D, IndexCtx.handleDecl(D));
410 SourceLocation SuperLoc = D->getSuperClassLoc();
411 if (auto *SuperD = D->getSuperClass()) {
413 if (auto *TInfo = D->getSuperClassTInfo()) {
414 if (auto *TT = TInfo->getType()->getAs<TypedefType>()) {
415 if (auto *TD = TT->getDecl()) {
417 TRY_TO(IndexCtx.handleReference(TD, SuperLoc, D, D,
425 TRY_TO(IndexCtx.handleReference(SuperD, SuperLoc, D, D, superRoles,
426 SymbolRelation{(unsigned)SymbolRole::RelationBaseOf, D}));
428 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
430 TRY_TO(IndexCtx.indexDeclContext(D));
432 return IndexCtx.handleReference(D, D->getLocation(), nullptr,
433 D->getDeclContext(), SymbolRoleSet());
438 bool VisitObjCProtocolDecl(const ObjCProtocolDecl *D) {
439 if (D->isThisDeclarationADefinition()) {
440 TRY_DECL(D, IndexCtx.handleDecl(D));
441 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
443 TRY_TO(IndexCtx.indexDeclContext(D));
445 return IndexCtx.handleReference(D, D->getLocation(), nullptr,
446 D->getDeclContext(), SymbolRoleSet());
451 bool VisitObjCImplementationDecl(const ObjCImplementationDecl *D) {
452 const ObjCInterfaceDecl *Class = D->getClassInterface();
456 if (Class->isImplicitInterfaceDecl())
459 TRY_DECL(D, IndexCtx.handleDecl(D));
463 // serves no purpose other than to simplify the FileCheck-based tests.
464 for (const auto *I : D->property_impls()) {
465 if (I->getLocation().isInvalid())
468 for (const auto *I : D->decls()) {
470 cast<ObjCPropertyImplDecl>(I)->getLocation().isValid())
477 bool VisitObjCCategoryDecl(const ObjCCategoryDecl *D) {
478 if (!IndexCtx.shouldIndex(D))
480 const ObjCInterfaceDecl *C = D->getClassInterface();
483 TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D, SymbolRoleSet(),
485 (unsigned)SymbolRole::RelationExtendedBy, D
487 SourceLocation CategoryLoc = D->getCategoryNameLoc();
489 CategoryLoc = D->getLocation();
490 TRY_TO(IndexCtx.handleDecl(D, CategoryLoc));
491 TRY_TO(handleReferencedProtocols(D->getReferencedProtocols(), D,
493 TRY_TO(IndexCtx.indexDeclContext(D));
497 bool VisitObjCCategoryImplDecl(const ObjCCategoryImplDecl *D) {
498 const ObjCCategoryDecl *Cat = D->getCategoryDecl();
501 const ObjCInterfaceDecl *C = D->getClassInterface();
503 TRY_TO(IndexCtx.handleReference(C, D->getLocation(), D, D,
505 SourceLocation CategoryLoc = D->getCategoryNameLoc();
507 CategoryLoc = D->getLocation();
508 TRY_DECL(D, IndexCtx.handleDecl(D, CategoryLoc));
509 IndexCtx.indexDeclContext(D);
513 bool VisitObjCMethodDecl(const ObjCMethodDecl *D) {
514 // Methods associated with a property, even user-declared ones, are
516 if (D->isPropertyAccessor())
519 handleObjCMethod(D);
523 bool VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
524 if (ObjCMethodDecl *MD = D->getGetterMethodDecl())
525 if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
526 handleObjCMethod(MD, D);
527 if (ObjCMethodDecl *MD = D->getSetterMethodDecl())
528 if (MD->getLexicalDeclContext() == D->getLexicalDeclContext())
529 handleObjCMethod(MD, D);
530 TRY_DECL(D, IndexCtx.handleDecl(D));
531 if (IBOutletCollectionAttr *attr = D->getAttr<IBOutletCollectionAttr>())
532 IndexCtx.indexTypeSourceInfo(attr->getInterfaceLoc(), D,
533 D->getLexicalDeclContext(), false, true);
534 IndexCtx.indexTypeSourceInfo(D->getTypeSourceInfo(), D);
538 bool VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
539 ObjCPropertyDecl *PD = D->getPropertyDecl();
540 auto *Container = cast<ObjCImplDecl>(D->getDeclContext());
541 SourceLocation Loc = D->getLocation();
545 if (ObjCIvarDecl *ID = D->getPropertyIvarDecl())
548 Loc = Container->getLocation();
551 TRY_DECL(D, IndexCtx.handleDecl(D, Loc, Roles, Relations));
553 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic)
556 assert(D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize);
559 if (ObjCMethodDecl *MD = PD->getGetterMethodDecl()) {
560 if (MD->isPropertyAccessor() && !hasUserDefined(MD, Container))
563 if (ObjCMethodDecl *MD = PD->getSetterMethodDecl()) {
564 if (MD->isPropertyAccessor() && !hasUserDefined(MD, Container))
567 if (ObjCIvarDecl *IvarD = D->getPropertyIvarDecl()) {
568 if (IvarD->getSynthesize()) {
576 SourceLocation IvarLoc = D->getPropertyIvarDeclLoc();
577 if (D->getLocation().isInvalid()) {
578 IvarLoc = Container->getLocation();
580 } else if (D->getLocation() == IvarLoc) {
585 IndexCtx.handleReference(IvarD, D->getPropertyIvarDeclLoc(), nullptr,
586 D->getDeclContext(), SymbolRoleSet());
592 bool VisitNamespaceDecl(const NamespaceDecl *D) {
593 TRY_DECL(D, IndexCtx.handleDecl(D));
594 IndexCtx.indexDeclContext(D);
598 bool VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
599 TRY_DECL(D, IndexCtx.handleDecl(D));
600 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
601 IndexCtx.handleReference(D->getAliasedNamespace(), D->getTargetNameLoc(), D,
602 D->getLexicalDeclContext());
606 bool VisitUsingDecl(const UsingDecl *D) {
607 IndexCtx.handleDecl(D);
609 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
611 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
612 D->getLexicalDeclContext());
613 for (const auto *I : D->shadows()) {
614 // Skip unresolved using decls - we already have a decl for the using
617 if (isa<UnresolvedUsingIfExistsDecl>(I->getUnderlyingDecl()))
620 IndexCtx.handleReference(I->getUnderlyingDecl(), D->getLocation(), Parent,
621 D->getLexicalDeclContext(), SymbolRoleSet());
626 bool VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
627 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
632 if (!D->getParentFunctionOrMethod())
633 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
634 D->getLexicalDeclContext());
636 return IndexCtx.handleReference(D->getNominatedNamespaceAsWritten(),
637 D->getLocation(), Parent,
638 D->getLexicalDeclContext(),
642 bool VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
643 TRY_DECL(D, IndexCtx.handleDecl(D));
644 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
646 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
647 D->getLexicalDeclContext());
651 bool VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) {
652 TRY_DECL(D, IndexCtx.handleDecl(D));
653 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
655 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
656 D->getLexicalDeclContext());
661 ClassTemplateSpecializationDecl *D) {
666 Template = D->getSpecializedTemplateOrPartial();
671 if (!D->isThisDeclarationADefinition())
672 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
674 D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
678 D->getTemplateArgsAsWritten()) {
679 for (const auto &Arg : TemplateArgInfo->arguments())
680 handleTemplateArgumentLoc(Arg, D, D->getLexicalDeclContext());
685 static bool shouldIndexTemplateParameterDefaultValue(const NamedDecl *D) {
688 if (!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;
705 if (TTP->hasDefaultArgument())
706 handleTemplateArgumentLoc(TTP->getDefaultArgument(), Parent,
707 TP->getLexicalDeclContext());
708 if (auto *C = TTP->getTypeConstraint())
709 IndexCtx.handleReference(C->getNamedConcept(), C->getConceptNameLoc(),
710 Parent, TTP->getLexicalDeclContext());
712 IndexCtx.indexTypeSourceInfo(NTTP->getTypeSourceInfo(), Parent);
713 if (NTTP->hasDefaultArgument())
714 handleTemplateArgumentLoc(NTTP->getDefaultArgument(), Parent,
715 TP->getLexicalDeclContext());
717 if (TTPD->hasDefaultArgument())
718 handleTemplateArgumentLoc(TTPD->getDefaultArgument(), Parent,
719 TP->getLexicalDeclContext());
722 if (auto *R = Params->getRequiresClause())
726 bool VisitTemplateDecl(const TemplateDecl *D) {
727 const NamedDecl *Parent = D->getTemplatedDecl();
732 auto *Params = D->getTemplateParameters();
740 bool VisitConceptDecl(const ConceptDecl *D) {
741 if (auto *Params = D->getTemplateParameters())
742 indexTemplateParameters(Params, D);
743 if (auto *E = D->getConstraintExpr())
744 IndexCtx.indexBody(E, D);
745 return IndexCtx.handleDecl(D);
748 bool VisitFriendDecl(const FriendDecl *D) {
749 if (auto ND = D->getFriendDecl()) {
756 if (isa<ClassTemplateDecl>(ND) && D->getDeclContext()->isDependentContext())
760 if (auto Ty = D->getFriendType()) {
761 IndexCtx.indexTypeSourceInfo(Ty, cast<NamedDecl>(D->getDeclContext()));
766 bool VisitImportDecl(const ImportDecl *D) {
767 return IndexCtx.importedModule(D);
770 bool VisitStaticAssertDecl(const StaticAssertDecl *D) {
771 IndexCtx.indexBody(D->getAssertExpr(),
772 dyn_cast<NamedDecl>(D->getDeclContext()),
773 D->getLexicalDeclContext());
780 bool IndexingContext::indexDecl(const Decl *D) {
781 if (D->isImplicit() && shouldIgnoreIfImplicit(D))
784 if (isTemplateImplicitInstantiation(D) && !shouldIndexImplicitInstantiation())
788 bool ShouldContinue = Visitor.Visit(D);
792 if (!Visitor.Handled && isa<DeclContext>(D))
793 return indexDeclContext(cast<DeclContext>(D));
799 for (const auto *I : DC->decls())
805 bool IndexingContext::indexTopLevelDecl(const Decl *D) {
806 if (!D || D->getLocation().isInvalid())
809 if (isa<ObjCMethodDecl>(D))
812 if (IndexOpts.ShouldTraverseDecl && !IndexOpts.ShouldTraverseDecl(D))
815 return indexDecl(D);