nridge created this revision. nridge added a reviewer: hokein. Herald added subscribers: cfe-commits, arphaman. Herald added a project: clang. nridge requested review of this revision.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D86424 Files: clang/lib/Index/IndexTypeSourceInfo.cpp clang/unittests/Index/IndexTests.cpp Index: clang/unittests/Index/IndexTests.cpp =================================================================== --- clang/unittests/Index/IndexTests.cpp +++ clang/unittests/Index/IndexTests.cpp @@ -334,6 +334,20 @@ WrittenAt(Position(3, 20))))); } +TEST(IndexTest, RelationBaseOf) { + std::string Code = R"cpp( + class A {}; + template <typename> class B {}; + class C : B<A> {}; + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + // A should not be the base of anything. + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference), + Not(HasRole(SymbolRole::RelationBaseOf))))); +} + } // namespace } // namespace index } // namespace clang Index: clang/lib/Index/IndexTypeSourceInfo.cpp =================================================================== --- clang/lib/Index/IndexTypeSourceInfo.cpp +++ clang/lib/Index/IndexTypeSourceInfo.cpp @@ -160,6 +160,25 @@ return true; } + bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { + if (!WalkUpFromTemplateSpecializationTypeLoc(TL)) + return false; + if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName())) + return false; + + // The relations we have to `Parent` do not apply to our template arguments, + // so clear them while visiting the args. + SmallVector<SymbolRelation, 3> SavedRelations = Relations; + // Relations.clear(); + for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { + if (!TraverseTemplateArgumentLoc(TL.getArgLoc(I))) + return false; + } + Relations = SavedRelations; + + return true; + } + bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) { auto *T = TL.getTypePtr(); if (!T)
Index: clang/unittests/Index/IndexTests.cpp =================================================================== --- clang/unittests/Index/IndexTests.cpp +++ clang/unittests/Index/IndexTests.cpp @@ -334,6 +334,20 @@ WrittenAt(Position(3, 20))))); } +TEST(IndexTest, RelationBaseOf) { + std::string Code = R"cpp( + class A {}; + template <typename> class B {}; + class C : B<A> {}; + )cpp"; + auto Index = std::make_shared<Indexer>(); + tooling::runToolOnCode(std::make_unique<IndexAction>(Index), Code); + // A should not be the base of anything. + EXPECT_THAT(Index->Symbols, + Contains(AllOf(QName("A"), HasRole(SymbolRole::Reference), + Not(HasRole(SymbolRole::RelationBaseOf))))); +} + } // namespace } // namespace index } // namespace clang Index: clang/lib/Index/IndexTypeSourceInfo.cpp =================================================================== --- clang/lib/Index/IndexTypeSourceInfo.cpp +++ clang/lib/Index/IndexTypeSourceInfo.cpp @@ -160,6 +160,25 @@ return true; } + bool TraverseTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { + if (!WalkUpFromTemplateSpecializationTypeLoc(TL)) + return false; + if (!TraverseTemplateName(TL.getTypePtr()->getTemplateName())) + return false; + + // The relations we have to `Parent` do not apply to our template arguments, + // so clear them while visiting the args. + SmallVector<SymbolRelation, 3> SavedRelations = Relations; + // Relations.clear(); + for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) { + if (!TraverseTemplateArgumentLoc(TL.getArgLoc(I))) + return false; + } + Relations = SavedRelations; + + return true; + } + bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) { auto *T = TL.getTypePtr(); if (!T)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits