Implement libclang support for using directives (cursor + visitation +
suppressing USRs). Also, fix up the source location information for
using directives so that the declaration location refers to the
namespace name.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112693 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 230631b..d849186 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -317,7 +317,8 @@
bool VisitLinkageSpecDecl(LinkageSpecDecl *D);
bool VisitNamespaceDecl(NamespaceDecl *D);
bool VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
-
+ bool VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
+
// Name visitor
bool VisitDeclarationNameInfo(DeclarationNameInfo Name);
@@ -871,6 +872,13 @@
D->getTargetNameLoc(), TU));
}
+bool CursorVisitor::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+ // FIXME: Visit nested-name-specifier
+
+ return Visit(MakeCursorNamespaceRef(D->getNominatedNamespaceAsWritten(),
+ D->getIdentLocation(), TU));
+}
+
bool CursorVisitor::VisitDeclarationNameInfo(DeclarationNameInfo Name) {
switch (Name.getName().getNameKind()) {
case clang::DeclarationName::Identifier:
@@ -2022,6 +2030,9 @@
// ObjCCategoryImplDecl returns the category name.
return createCXString(CIMP->getIdentifier()->getNameStart());
+ if (isa<UsingDirectiveDecl>(D))
+ return createCXString("");
+
llvm::SmallString<1024> S;
llvm::raw_svector_ostream os(S);
ND->printName(os);
@@ -2219,6 +2230,8 @@
return createCXString("ClassTemplatePartialSpecialization");
case CXCursor_NamespaceAlias:
return createCXString("NamespaceAlias");
+ case CXCursor_UsingDirective:
+ return createCXString("UsingDirective");
}
llvm_unreachable("Unhandled CXCursorKind");
diff --git a/tools/libclang/CIndexUSRs.cpp b/tools/libclang/CIndexUSRs.cpp
index 9ef851a..5628aef 100644
--- a/tools/libclang/CIndexUSRs.cpp
+++ b/tools/libclang/CIndexUSRs.cpp
@@ -82,9 +82,11 @@
void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
void VisitLinkageSpecDecl(LinkageSpecDecl *D) {
IgnoreResults = true;
- return;
}
-
+ void VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
+ IgnoreResults = true;
+ }
+
/// Generate the string component containing the location of the
/// declaration.
bool GenLoc(const Decl *D);
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 3edbc4d..75806ff 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -69,6 +69,7 @@
case Decl::ClassTemplate: return CXCursor_ClassTemplate;
case Decl::ClassTemplatePartialSpecialization:
return CXCursor_ClassTemplatePartialSpecialization;
+ case Decl::UsingDirective: return CXCursor_UsingDirective;
default:
if (TagDecl *TD = dyn_cast<TagDecl>(D)) {