[PATCH] D41759: [clangd] Catch more symbols in SymbolCollector.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 5 02:48:58 PST 2018
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added a subscriber: klimek.
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.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D41759
Files:
clangd/index/SymbolCollector.cpp
unittests/clangd/SymbolCollectorTests.cpp
Index: unittests/clangd/SymbolCollectorTests.cpp
===================================================================
--- unittests/clangd/SymbolCollectorTests.cpp
+++ 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 @@
};
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) {
Index: clangd/index/SymbolCollector.cpp
===================================================================
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -80,8 +80,13 @@
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.
+ // 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41759.128722.patch
Type: text/x-patch
Size: 2880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180105/d7cca811/attachment.bin>
More information about the cfe-commits
mailing list