[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG4bc085f5b3ed: [clangd] Add OverridenBy Relation to index. (authored by usaxena95). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 Files: clang-tools-extra/clangd/index/Relation.cpp clang-tools-extra/clangd/index/Relation.h clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp === --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -97,6 +97,9 @@ const Range &Range = ::testing::get<1>(arg); return rangesMatch(Pos.Location, Range); } +MATCHER_P2(OverriddenBy, Subject, Object, "") { + return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID}; +} ::testing::Matcher &> HaveRanges(const std::vector Ranges) { return ::testing::UnorderedPointwise(RefRange(), Ranges); @@ -1031,7 +1034,7 @@ HaveRanges(Header.ranges("macro"); } -TEST_F(SymbolCollectorTest, Relations) { +TEST_F(SymbolCollectorTest, BaseOfRelations) { std::string Header = R"( class Base {}; class Derived : public Base {}; @@ -1043,6 +1046,77 @@ Contains(Relation{Base.ID, RelationKind::BaseOf, Derived.ID})); } +TEST_F(SymbolCollectorTest, OverrideRelationsSimpleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B : public A { + void foo() override; // A::foo + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar +}; +class D: public C { + void foo() override; // B::foo + void bar() override; // C::bar +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BFoo = findSymbol(Symbols, "B::foo"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(AFoo, BFoo), OverriddenBy(BBar, CBar), + OverriddenBy(BFoo, DFoo), OverriddenBy(CBar, DBar))); +} + +TEST_F(SymbolCollectorTest, OverrideRelationsMultipleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B { + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar + virtual void baz(); +} +class D : public A, C { + void foo() override; // A::foo + void bar() override; // C::bar + void baz() override; // C::baz +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &CBaz = findSymbol(Symbols, "C::baz"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + const Symbol &DBaz = findSymbol(Symbols, "D::baz"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(BBar, CBar), OverriddenBy(AFoo, DFoo), + OverriddenBy(CBar, DBar), OverriddenBy(CBaz, DBaz))); +} + TEST_F(SymbolCollectorTest, CountReferences) { const std::string Header = R"( class W; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h @@ -1,4 +1,6 @@ #pragma once // Introduce a symbol. -struct Foo {}; +struct Foo { + virtual void Func() {} +}; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp +++ clang-tools-extr
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
usaxena95 updated this revision to Diff 305976. usaxena95 marked an inline comment as done. usaxena95 added a comment. Addressed final comments. Ready to land. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 Files: clang-tools-extra/clangd/index/Relation.cpp clang-tools-extra/clangd/index/Relation.h clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp === --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -97,6 +97,9 @@ const Range &Range = ::testing::get<1>(arg); return rangesMatch(Pos.Location, Range); } +MATCHER_P2(OverriddenBy, Subject, Object, "") { + return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID}; +} ::testing::Matcher &> HaveRanges(const std::vector Ranges) { return ::testing::UnorderedPointwise(RefRange(), Ranges); @@ -1031,7 +1034,7 @@ HaveRanges(Header.ranges("macro"); } -TEST_F(SymbolCollectorTest, Relations) { +TEST_F(SymbolCollectorTest, BaseOfRelations) { std::string Header = R"( class Base {}; class Derived : public Base {}; @@ -1043,6 +1046,77 @@ Contains(Relation{Base.ID, RelationKind::BaseOf, Derived.ID})); } +TEST_F(SymbolCollectorTest, OverrideRelationsSimpleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B : public A { + void foo() override; // A::foo + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar +}; +class D: public C { + void foo() override; // B::foo + void bar() override; // C::bar +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BFoo = findSymbol(Symbols, "B::foo"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(AFoo, BFoo), OverriddenBy(BBar, CBar), + OverriddenBy(BFoo, DFoo), OverriddenBy(CBar, DBar))); +} + +TEST_F(SymbolCollectorTest, OverrideRelationsMultipleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B { + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar + virtual void baz(); +} +class D : public A, C { + void foo() override; // A::foo + void bar() override; // C::bar + void baz() override; // C::baz +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &CBaz = findSymbol(Symbols, "C::baz"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + const Symbol &DBaz = findSymbol(Symbols, "D::baz"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(BBar, CBar), OverriddenBy(AFoo, DFoo), + OverriddenBy(CBar, DBar), OverriddenBy(CBaz, DBaz))); +} + TEST_F(SymbolCollectorTest, CountReferences) { const std::string Header = R"( class W; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h @@ -1,4 +1,6 @@ #pragma once // Introduce a symbol. -struct Foo {}; +struct Foo { + virtual void Func() {} +}; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp @@ -2,4 +2,7 @@ #i
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
hokein accepted this revision. hokein added inline comments. This revision is now accepted and ready to land. Comment at: clang-tools-extra/clangd/index/Relation.h:31 +/// { Subject = A, Predicate = BaseOf, Object = B }. +/// - "A::Foo is overriden by B::Foo" is represented as +/// { Subject = A::Foo, Predicate = OverriddenBy, Object = B::Foo }. nit: I would explicitly indicate the base hierarchy here, maybe `Derived::Foo() overrides Base::Foo()`. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
usaxena95 updated this revision to Diff 305802. usaxena95 added a comment. Typo fix. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 Files: clang-tools-extra/clangd/index/Relation.cpp clang-tools-extra/clangd/index/Relation.h clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp === --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -97,6 +97,9 @@ const Range &Range = ::testing::get<1>(arg); return rangesMatch(Pos.Location, Range); } +MATCHER_P2(OverriddenBy, Subject, Object, "") { + return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID}; +} ::testing::Matcher &> HaveRanges(const std::vector Ranges) { return ::testing::UnorderedPointwise(RefRange(), Ranges); @@ -1031,7 +1034,7 @@ HaveRanges(Header.ranges("macro"); } -TEST_F(SymbolCollectorTest, Relations) { +TEST_F(SymbolCollectorTest, BaseOfRelations) { std::string Header = R"( class Base {}; class Derived : public Base {}; @@ -1043,6 +1046,77 @@ Contains(Relation{Base.ID, RelationKind::BaseOf, Derived.ID})); } +TEST_F(SymbolCollectorTest, OverrideRelationsSimpleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B : public A { + void foo() override; // A::foo + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar +}; +class D: public C { + void foo() override; // B::foo + void bar() override; // C::bar +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BFoo = findSymbol(Symbols, "B::foo"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(AFoo, BFoo), OverriddenBy(BBar, CBar), + OverriddenBy(BFoo, DFoo), OverriddenBy(CBar, DBar))); +} + +TEST_F(SymbolCollectorTest, OverrideRelationsMultipleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B { + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar + virtual void baz(); +} +class D : public A, C { + void foo() override; // A::foo + void bar() override; // C::bar + void baz() override; // C::baz +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &CBaz = findSymbol(Symbols, "C::baz"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + const Symbol &DBaz = findSymbol(Symbols, "D::baz"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(BBar, CBar), OverriddenBy(AFoo, DFoo), + OverriddenBy(CBar, DBar), OverriddenBy(CBaz, DBaz))); +} + TEST_F(SymbolCollectorTest, CountReferences) { const std::string Header = R"( class W; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h @@ -1,4 +1,6 @@ #pragma once // Introduce a symbol. -struct Foo {}; +struct Foo { + virtual void Func() {} +}; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp @@ -2,4 +2,7 @@ #include "sample.h" // This introduces a symbol, a reference and a relatio
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
usaxena95 updated this revision to Diff 305787. usaxena95 marked an inline comment as done. usaxena95 added a comment. Add documentation for change in index test. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 Files: clang-tools-extra/clangd/index/Relation.cpp clang-tools-extra/clangd/index/Relation.h clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp === --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -97,6 +97,9 @@ const Range &Range = ::testing::get<1>(arg); return rangesMatch(Pos.Location, Range); } +MATCHER_P2(OverriddenBy, Subject, Object, "") { + return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID}; +} ::testing::Matcher &> HaveRanges(const std::vector Ranges) { return ::testing::UnorderedPointwise(RefRange(), Ranges); @@ -1031,7 +1034,7 @@ HaveRanges(Header.ranges("macro"); } -TEST_F(SymbolCollectorTest, Relations) { +TEST_F(SymbolCollectorTest, BaseOfRelations) { std::string Header = R"( class Base {}; class Derived : public Base {}; @@ -1043,6 +1046,77 @@ Contains(Relation{Base.ID, RelationKind::BaseOf, Derived.ID})); } +TEST_F(SymbolCollectorTest, OverrideRelationsSimpleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B : public A { + void foo() override; // A::foo + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar +}; +class D: public C { + void foo() override; // B::foo + void bar() override; // C::bar +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BFoo = findSymbol(Symbols, "B::foo"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(AFoo, BFoo), OverriddenBy(BBar, CBar), + OverriddenBy(BFoo, DFoo), OverriddenBy(CBar, DBar))); +} + +TEST_F(SymbolCollectorTest, OverrideRelationsMultipleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B { + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar + virtual void baz(); +} +class D : public A, C { + void foo() override; // A::foo + void bar() override; // C::bar + void baz() override; // C::baz +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &CBaz = findSymbol(Symbols, "C::baz"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + const Symbol &DBaz = findSymbol(Symbols, "D::baz"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(BBar, CBar), OverriddenBy(AFoo, DFoo), + OverriddenBy(CBar, DBar), OverriddenBy(CBaz, DBaz))); +} + TEST_F(SymbolCollectorTest, CountReferences) { const std::string Header = R"( class W; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h @@ -1,4 +1,6 @@ #pragma once // Introduce a symbol. -struct Foo {}; +struct Foo { + virtual void Func() {} +}; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp @@ -2,4 +2,7 @@
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
usaxena95 updated this revision to Diff 305783. usaxena95 marked 2 inline comments as done. usaxena95 added a comment. s/OverridenBy/OverriddenBy Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 Files: clang-tools-extra/clangd/index/Relation.cpp clang-tools-extra/clangd/index/Relation.h clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h clang-tools-extra/clangd/test/index-serialization/Inputs/sample.idx clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp === --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -97,6 +97,9 @@ const Range &Range = ::testing::get<1>(arg); return rangesMatch(Pos.Location, Range); } +MATCHER_P2(OverriddenBy, Subject, Object, "") { + return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID}; +} ::testing::Matcher &> HaveRanges(const std::vector Ranges) { return ::testing::UnorderedPointwise(RefRange(), Ranges); @@ -1031,7 +1034,7 @@ HaveRanges(Header.ranges("macro"); } -TEST_F(SymbolCollectorTest, Relations) { +TEST_F(SymbolCollectorTest, BaseOfRelations) { std::string Header = R"( class Base {}; class Derived : public Base {}; @@ -1043,6 +1046,77 @@ Contains(Relation{Base.ID, RelationKind::BaseOf, Derived.ID})); } +TEST_F(SymbolCollectorTest, OverrideRelationsSimpleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B : public A { + void foo() override; // A::foo + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar +}; +class D: public C { + void foo() override; // B::foo + void bar() override; // C::bar +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BFoo = findSymbol(Symbols, "B::foo"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(AFoo, BFoo), OverriddenBy(BBar, CBar), + OverriddenBy(BFoo, DFoo), OverriddenBy(CBar, DBar))); +} + +TEST_F(SymbolCollectorTest, OverrideRelationsMultipleInheritance) { + std::string Header = R"cpp( +class A { + virtual void foo(); +}; +class B { + virtual void bar(); +}; +class C : public B { + void bar() override; // B::bar + virtual void baz(); +} +class D : public A, C { + void foo() override; // A::foo + void bar() override; // C::bar + void baz() override; // C::baz +}; + )cpp"; + runSymbolCollector(Header, /*Main=*/""); + const Symbol &AFoo = findSymbol(Symbols, "A::foo"); + const Symbol &BBar = findSymbol(Symbols, "B::bar"); + const Symbol &CBar = findSymbol(Symbols, "C::bar"); + const Symbol &CBaz = findSymbol(Symbols, "C::baz"); + const Symbol &DFoo = findSymbol(Symbols, "D::foo"); + const Symbol &DBar = findSymbol(Symbols, "D::bar"); + const Symbol &DBaz = findSymbol(Symbols, "D::baz"); + + std::vector Result; + for (const Relation &R : Relations) +if (R.Predicate == RelationKind::OverriddenBy) + Result.push_back(R); + EXPECT_THAT(Result, UnorderedElementsAre( + OverriddenBy(BBar, CBar), OverriddenBy(AFoo, DFoo), + OverriddenBy(CBar, DBar), OverriddenBy(CBaz, DBaz))); +} + TEST_F(SymbolCollectorTest, CountReferences) { const std::string Header = R"( class W; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.h @@ -1,4 +1,6 @@ #pragma once // Introduce a symbol. -struct Foo {}; +struct Foo { + virtual void Func() {} +}; Index: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp === --- clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp +++ clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp @@ -2,4 +2,6 @@ #include "sample
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
usaxena95 added inline comments. Comment at: clang-tools-extra/clangd/index/Relation.h:24 BaseOf, + OverridenBy, }; Quuxplusone wrote: > s/Overriden/Overridden/g Thanks. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D91610: [clangd] Add OverriddenBy Relation to index.
kadircet added inline comments. Comment at: clang-tools-extra/clangd/test/index-serialization/Inputs/sample.cpp:6 +struct Bar : public Foo { + void Func() override {} +}; could you also add a comment for the reason we have this in the test (i.e. Introduces an `OverridenBy` relation) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91610/new/ https://reviews.llvm.org/D91610 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits