[clang][Index] Visit UsingDecls and generate USRs for them
Summary: Add indexing of UsingDecl itself. Also enable generation of USRs for UsingDecls, using the qualified name of the decl. Reviewers: ilya-biryukov, akyrtzi Subscribers: arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D58340 llvm-svn: 354878
This commit is contained in:
parent
c032e2ab7c
commit
a87ada0dad
|
@ -580,9 +580,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VisitUsingDecl(const UsingDecl *D) {
|
bool VisitUsingDecl(const UsingDecl *D) {
|
||||||
|
IndexCtx.handleDecl(D);
|
||||||
|
|
||||||
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
|
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
|
||||||
const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
|
const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
|
||||||
|
|
||||||
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
|
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
|
||||||
D->getLexicalDeclContext());
|
D->getLexicalDeclContext());
|
||||||
for (const auto *I : D->shadows())
|
for (const auto *I : D->shadows())
|
||||||
|
|
|
@ -316,6 +316,10 @@ SymbolInfo index::getSymbolInfo(const Decl *D) {
|
||||||
Info.Lang = SymbolLanguage::CXX;
|
Info.Lang = SymbolLanguage::CXX;
|
||||||
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
|
||||||
break;
|
break;
|
||||||
|
case Decl::Using:
|
||||||
|
Info.Kind = SymbolKind::Using;
|
||||||
|
Info.Lang = SymbolLanguage::CXX;
|
||||||
|
break;
|
||||||
case Decl::Binding:
|
case Decl::Binding:
|
||||||
Info.Kind = SymbolKind::Variable;
|
Info.Kind = SymbolKind::Variable;
|
||||||
Info.Lang = SymbolLanguage::CXX;
|
Info.Lang = SymbolLanguage::CXX;
|
||||||
|
|
|
@ -111,7 +111,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisitUsingDecl(const UsingDecl *D) {
|
void VisitUsingDecl(const UsingDecl *D) {
|
||||||
IgnoreResults = true;
|
VisitDeclContext(D->getDeclContext());
|
||||||
|
Out << "@UD@";
|
||||||
|
|
||||||
|
bool EmittedDeclName = !EmitDeclName(D);
|
||||||
|
assert(EmittedDeclName && "EmitDeclName can not fail for UsingDecls");
|
||||||
|
(void)EmittedDeclName;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShouldGenerateLocation(const NamedDecl *D);
|
bool ShouldGenerateLocation(const NamedDecl *D);
|
||||||
|
|
|
@ -158,7 +158,7 @@ __m128 vectorOverload(__m128 f);
|
||||||
// CHECK: usrs.cpp c:@NA@foo_alias
|
// CHECK: usrs.cpp c:@NA@foo_alias
|
||||||
// CHECK-NOT: foo
|
// CHECK-NOT: foo
|
||||||
// CHECK: usrs.cpp c:@NA@foo_alias2
|
// CHECK: usrs.cpp c:@NA@foo_alias2
|
||||||
// CHECK-NOT: ClsB
|
// CHECK: usrs.cpp c:@UD@ClsB Extent=[64:1 - 64:16]
|
||||||
// CHECK: usrs.cpp c:@NA@foo_alias3
|
// CHECK: usrs.cpp c:@NA@foo_alias3
|
||||||
// CHECK: usrs.cpp c:@aN Extent=[68:1 - 73:2]
|
// CHECK: usrs.cpp c:@aN Extent=[68:1 - 73:2]
|
||||||
// CHECK: usrs.cpp c:usrs.cpp@aN@S@RDar9371763_Foo Extent=[69:1 - 72:2]
|
// CHECK: usrs.cpp c:usrs.cpp@aN@S@RDar9371763_Foo Extent=[69:1 - 72:2]
|
||||||
|
|
|
@ -57,6 +57,7 @@ struct TestSymbol {
|
||||||
std::string QName;
|
std::string QName;
|
||||||
Position WrittenPos;
|
Position WrittenPos;
|
||||||
Position DeclPos;
|
Position DeclPos;
|
||||||
|
SymbolInfo SymInfo;
|
||||||
// FIXME: add more information.
|
// FIXME: add more information.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,6 +79,7 @@ public:
|
||||||
if (!ND)
|
if (!ND)
|
||||||
return true;
|
return true;
|
||||||
TestSymbol S;
|
TestSymbol S;
|
||||||
|
S.SymInfo = getSymbolInfo(D);
|
||||||
S.QName = ND->getQualifiedNameAsString();
|
S.QName = ND->getQualifiedNameAsString();
|
||||||
S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager());
|
S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager());
|
||||||
S.DeclPos =
|
S.DeclPos =
|
||||||
|
@ -140,6 +142,7 @@ using testing::UnorderedElementsAre;
|
||||||
MATCHER_P(QName, Name, "") { return arg.QName == Name; }
|
MATCHER_P(QName, Name, "") { return arg.QName == Name; }
|
||||||
MATCHER_P(WrittenAt, Pos, "") { return arg.WrittenPos == Pos; }
|
MATCHER_P(WrittenAt, Pos, "") { return arg.WrittenPos == Pos; }
|
||||||
MATCHER_P(DeclAt, Pos, "") { return arg.DeclPos == Pos; }
|
MATCHER_P(DeclAt, Pos, "") { return arg.DeclPos == Pos; }
|
||||||
|
MATCHER_P(Kind, SymKind, "") { return arg.SymInfo.Kind == SymKind; }
|
||||||
|
|
||||||
TEST(IndexTest, Simple) {
|
TEST(IndexTest, Simple) {
|
||||||
auto Index = std::make_shared<Indexer>();
|
auto Index = std::make_shared<Indexer>();
|
||||||
|
@ -240,6 +243,20 @@ TEST(IndexTest, IndexTypeParmDecls) {
|
||||||
Contains(QName("Foo::C")), Contains(QName("Foo::NoRef"))));
|
Contains(QName("Foo::C")), Contains(QName("Foo::NoRef"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(IndexTest, UsingDecls) {
|
||||||
|
std::string Code = R"cpp(
|
||||||
|
void foo(int bar);
|
||||||
|
namespace std {
|
||||||
|
using ::foo;
|
||||||
|
}
|
||||||
|
)cpp";
|
||||||
|
auto Index = std::make_shared<Indexer>();
|
||||||
|
IndexingOptions Opts;
|
||||||
|
tooling::runToolOnCode(new IndexAction(Index, Opts), Code);
|
||||||
|
EXPECT_THAT(Index->Symbols,
|
||||||
|
Contains(AllOf(QName("std::foo"), Kind(SymbolKind::Using))));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace index
|
} // namespace index
|
||||||
} // namespace clang
|
} // namespace clang
|
||||||
|
|
Loading…
Reference in a new issue