diff options
| author | Haojian Wu <hokein@google.com> | 2018-01-09 10:44:09 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2018-01-09 10:44:09 +0000 |
| commit | fe22b7474b6ff40c98c9dfa877a9dfec41e38e37 (patch) | |
| tree | 79880709fb2333ca7d610072cda57714c0a92871 | |
| parent | 5e9da2d06bf3db8d79a2dd10a5253cf0d7ed100a (diff) | |
| download | bcm5719-llvm-fe22b7474b6ff40c98c9dfa877a9dfec41e38e37.tar.gz bcm5719-llvm-fe22b7474b6ff40c98c9dfa877a9dfec41e38e37.zip | |
[clangd] Catch more symbols in SymbolCollector.
Summary:
We currently only collect external-linkage symbols in the collector,
which results in missing some typical symbols (like no-linkage type alias symbols).
This patch relaxes the constraint a bit to allow collecting more symbols.
Reviewers: ilya-biryukov
Reviewed By: ilya-biryukov
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D41759
llvm-svn: 322067
| -rw-r--r-- | clang-tools-extra/clangd/index/SymbolCollector.cpp | 11 | ||||
| -rw-r--r-- | clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp | 42 |
2 files changed, 49 insertions, 4 deletions
diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 3ffc1d1b3b2..291ee592aad 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -80,8 +80,15 @@ bool SymbolCollector::handleDeclOccurence( return true; if (const NamedDecl *ND = llvm::dyn_cast<NamedDecl>(D)) { - // FIXME: Should we include the internal linkage symbols? - if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace()) + // FIXME: figure out a way to handle internal linkage symbols (e.g. static + // variables, function) defined in the .cc files. Also we skip the symbols + // in anonymous namespace as the qualifier names of these symbols are like + // `foo::<anonymous>::bar`, which need a special handling. + // In real world projects, we have a relatively large set of header files + // that define static variables (like "static const int A = 1;"), we still + // want to collect these symbols, although they cause potential ODR + // violations. + if (ND->isInAnonymousNamespace()) return true; llvm::SmallString<128> USR; diff --git a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp index 1a6dc970242..010c66ffd8b 100644 --- a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp +++ b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp @@ -29,6 +29,7 @@ using testing::Eq; using testing::Field; using testing::UnorderedElementsAre; +using testing::UnorderedElementsAreArray; // GMock helpers for matching Symbol. MATCHER_P(QName, Name, "") { @@ -97,16 +98,53 @@ TEST_F(SymbolCollectorTest, CollectSymbol) { }; void f1(); inline void f2() {} + static const int KInt = 2; + const char* kStr = "123"; )"; const std::string Main = R"( namespace { void ff() {} // ignore } + void f1() {} + + namespace foo { + // Type alias + typedef int int32; + using int32_t = int32; + + // Variable + int v1; + + // Namespace + namespace bar { + int v2; + } + // Namespace alias + namespace baz = bar; + + // FIXME: using declaration is not supported as the IndexAction will ignore + // implicit declarations (the implicit using shadow declaration) by default, + // and there is no way to customize this behavior at the moment. + using bar::v2; + } // namespace foo )"; runSymbolCollector(Header, Main); - EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Foo::f"), - QName("f1"), QName("f2"))); + EXPECT_THAT(Symbols, + UnorderedElementsAreArray( + {QName("Foo"), + QName("Foo::f"), + QName("f1"), + QName("f2"), + QName("KInt"), + QName("kStr"), + QName("foo"), + QName("foo::bar"), + QName("foo::int32"), + QName("foo::int32_t"), + QName("foo::v1"), + QName("foo::bar::v2"), + QName("foo::baz")})); } TEST_F(SymbolCollectorTest, YAMLConversions) { |

