Author: arphaman Date: Thu Apr 20 05:43:22 2017 New Revision: 300832 URL: http://llvm.org/viewvc/llvm-project?rev=300832&view=rev Log: [index] Record class template specializations using a new 'SpecializationOf' relationship
rdar://31603531 Differential Revision: https://reviews.llvm.org/D32010 Modified: cfe/trunk/include/clang/Index/IndexSymbol.h cfe/trunk/lib/Index/IndexDecl.cpp cfe/trunk/lib/Index/IndexSymbol.cpp cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp cfe/trunk/lib/Index/IndexingContext.cpp cfe/trunk/lib/Index/IndexingContext.h cfe/trunk/test/Index/Core/index-source.cpp Modified: cfe/trunk/include/clang/Index/IndexSymbol.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/include/clang/Index/IndexSymbol.h (original) +++ cfe/trunk/include/clang/Index/IndexSymbol.h Thu Apr 20 05:43:22 2017 @@ -106,8 +106,9 @@ enum class SymbolRole : uint32_t { RelationAccessorOf = 1 << 15, RelationContainedBy = 1 << 16, RelationIBTypeOf = 1 << 17, + RelationSpecializationOf = 1 << 18, }; -static const unsigned SymbolRoleBitNum = 18; +static const unsigned SymbolRoleBitNum = 19; typedef unsigned SymbolRoleSet; /// Represents a relation to another symbol for a symbol occurrence. Modified: cfe/trunk/lib/Index/IndexDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/lib/Index/IndexDecl.cpp (original) +++ cfe/trunk/lib/Index/IndexDecl.cpp Thu Apr 20 05:43:22 2017 @@ -495,8 +495,18 @@ public: ClassTemplateSpecializationDecl *D) { // FIXME: Notify subsequent callbacks if info comes from implicit // instantiation. - if (D->isThisDeclarationADefinition()) - IndexCtx.indexTagDecl(D); + if (D->isThisDeclarationADefinition()) { + llvm::PointerUnion<ClassTemplateDecl *, + ClassTemplatePartialSpecializationDecl *> + Template = D->getSpecializedTemplateOrPartial(); + const Decl *SpecializationOf = + Template.is<ClassTemplateDecl *>() + ? (Decl *)Template.get<ClassTemplateDecl *>() + : Template.get<ClassTemplatePartialSpecializationDecl *>(); + IndexCtx.indexTagDecl( + D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf), + SpecializationOf)); + } return true; } Modified: cfe/trunk/lib/Index/IndexSymbol.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/lib/Index/IndexSymbol.cpp (original) +++ cfe/trunk/lib/Index/IndexSymbol.cpp Thu Apr 20 05:43:22 2017 @@ -346,6 +346,7 @@ bool index::applyForEachSymbolRoleInterr APPLY_FOR_ROLE(RelationAccessorOf); APPLY_FOR_ROLE(RelationContainedBy); APPLY_FOR_ROLE(RelationIBTypeOf); + APPLY_FOR_ROLE(RelationSpecializationOf); #undef APPLY_FOR_ROLE @@ -386,6 +387,7 @@ void index::printSymbolRoles(SymbolRoleS case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break; case SymbolRole::RelationContainedBy: OS << "RelCont"; break; case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break; + case SymbolRole::RelationSpecializationOf: OS << "RelSpecialization"; break; } }); } Modified: cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp (original) +++ cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp Thu Apr 20 05:43:22 2017 @@ -208,11 +208,12 @@ void IndexingContext::indexNestedNameSpe } } -void IndexingContext::indexTagDecl(const TagDecl *D) { +void IndexingContext::indexTagDecl(const TagDecl *D, + ArrayRef<SymbolRelation> Relations) { if (!shouldIndexFunctionLocalSymbols() && isFunctionLocalSymbol(D)) return; - if (handleDecl(D)) { + if (handleDecl(D, /*Roles=*/SymbolRoleSet(), Relations)) { if (D->isThisDeclarationADefinition()) { indexNestedNameSpecifierLoc(D->getQualifierLoc(), D); if (auto CXXRD = dyn_cast<CXXRecordDecl>(D)) { Modified: cfe/trunk/lib/Index/IndexingContext.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/lib/Index/IndexingContext.cpp (original) +++ cfe/trunk/lib/Index/IndexingContext.cpp Thu Apr 20 05:43:22 2017 @@ -233,6 +233,7 @@ static bool shouldReportOccurrenceForSys case SymbolRole::RelationReceivedBy: case SymbolRole::RelationCalledBy: case SymbolRole::RelationContainedBy: + case SymbolRole::RelationSpecializationOf: return true; } llvm_unreachable("Unsupported SymbolRole value!"); Modified: cfe/trunk/lib/Index/IndexingContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.h?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/lib/Index/IndexingContext.h (original) +++ cfe/trunk/lib/Index/IndexingContext.h Thu Apr 20 05:43:22 2017 @@ -80,7 +80,8 @@ public: bool indexDecl(const Decl *D); - void indexTagDecl(const TagDecl *D); + void indexTagDecl(const TagDecl *D, + ArrayRef<SymbolRelation> Relations = None); void indexTypeSourceInfo(TypeSourceInfo *TInfo, const NamedDecl *Parent, const DeclContext *DC = nullptr, Modified: cfe/trunk/test/Index/Core/index-source.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=300832&r1=300831&r2=300832&view=diff ============================================================================== --- cfe/trunk/test/Index/Core/index-source.cpp (original) +++ cfe/trunk/test/Index/Core/index-source.cpp Thu Apr 20 05:43:22 2017 @@ -50,6 +50,12 @@ public: // CHECK-NEXT: RelChild | TemplCls | c:@ST>1#T@TemplCls }; +template<> +class TemplCls<double> { +// CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | TemplCls | c:@S@TemplCls>#d | <no-cgname> | Def,RelSpecialization | rel: 1 +// CHECK: RelSpecialization | TemplCls | c:@ST>1#T@TemplCls +}; + TemplCls<int> gtv(0); // CHECK: [[@LINE-1]]:1 | class(Gen)/C++ | TemplCls | c:@ST>1#T@TemplCls | <no-cgname> | Ref,RelCont | rel: 1 @@ -91,3 +97,17 @@ int gvi = tmplVar<int>; // CHECK: [[@LINE+2]]:5 | variable/C | gvf | c:@gvf | _gvf | Def | rel: 0 // CHECK: [[@LINE+1]]:11 | variable(Gen)/C++ | tmplVar | c:index-source.cpp@VT>1#T@tmplVar | __ZL7tmplVar | Ref,Read,RelCont | rel: 1 int gvf = tmplVar<float>; + +template<typename A, typename B> +class PartialSpecilizationClass { }; +// CHECK: [[@LINE-1]]:7 | class(Gen)/C++ | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass | <no-cgname> | Def | rel: 0 + +template<typename B> +class PartialSpecilizationClass<int, B *> { }; +// CHECK: [[@LINE-1]]:7 | class(Gen,TPS)/C++ | PartialSpecilizationClass | c:@SP>1#T@PartialSpecilizationClass>#I#*t0.0 | <no-cgname> | Def,RelSpecialization | rel: 1 +// CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass + +template<> +class PartialSpecilizationClass<int, int> { }; +// CHECK: [[@LINE-1]]:7 | class(Gen,TS)/C++ | PartialSpecilizationClass | c:@S@PartialSpecilizationClass>#I#I | <no-cgname> | Def,RelSpecialization | rel: 1 +// CHECK-NEXT: RelSpecialization | PartialSpecilizationClass | c:@ST>2#T#T@PartialSpecilizationClass _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits