}
bool VisitUsingDecl(const UsingDecl *D) {
+ IndexCtx.handleDecl(D);
+
const DeclContext *DC = D->getDeclContext()->getRedeclContext();
const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
-
IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
D->getLexicalDeclContext());
for (const auto *I : D->shadows())
Info.Lang = SymbolLanguage::CXX;
Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
break;
+ case Decl::Using:
+ Info.Kind = SymbolKind::Using;
+ Info.Lang = SymbolLanguage::CXX;
+ break;
case Decl::Binding:
Info.Kind = SymbolKind::Variable;
Info.Lang = SymbolLanguage::CXX;
}
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);
// CHECK: usrs.cpp c:@NA@foo_alias
// CHECK-NOT: foo
// 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:@aN Extent=[68:1 - 73:2]
// CHECK: usrs.cpp c:usrs.cpp@aN@S@RDar9371763_Foo Extent=[69:1 - 72:2]
std::string QName;
Position WrittenPos;
Position DeclPos;
+ SymbolInfo SymInfo;
// FIXME: add more information.
};
if (!ND)
return true;
TestSymbol S;
+ S.SymInfo = getSymbolInfo(D);
S.QName = ND->getQualifiedNameAsString();
S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager());
S.DeclPos =
MATCHER_P(QName, Name, "") { return arg.QName == Name; }
MATCHER_P(WrittenAt, Pos, "") { return arg.WrittenPos == Pos; }
MATCHER_P(DeclAt, Pos, "") { return arg.DeclPos == Pos; }
+MATCHER_P(Kind, SymKind, "") { return arg.SymInfo.Kind == SymKind; }
TEST(IndexTest, Simple) {
auto Index = std::make_shared<Indexer>();
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 index
} // namespace clang