From 113387e08e55e28d0614373e168b5202bc83339a Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Mon, 29 Feb 2016 07:56:07 +0000 Subject: [PATCH] [index] Print and test module import references. llvm-svn: 262208 --- clang/lib/Index/IndexSymbol.cpp | 3 +++ clang/lib/Index/IndexingContext.cpp | 9 +++++++-- clang/test/Index/Core/Inputs/module/ModA.h | 2 ++ clang/test/Index/Core/Inputs/module/module.modulemap | 1 + clang/test/Index/Core/index-with-module.m | 12 ++++++++++++ clang/tools/c-index-test/core_main.cpp | 20 ++++++++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 clang/test/Index/Core/Inputs/module/ModA.h create mode 100644 clang/test/Index/Core/Inputs/module/module.modulemap create mode 100644 clang/test/Index/Core/index-with-module.m diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp index 39812c4..62e2fac 100644 --- a/clang/lib/Index/IndexSymbol.cpp +++ b/clang/lib/Index/IndexSymbol.cpp @@ -53,6 +53,9 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { } else { switch (D->getKind()) { + case Decl::Import: + Info.Kind = SymbolKind::Module; + break; case Decl::Typedef: Info.Kind = SymbolKind::Typedef; break; case Decl::Function: diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index 9ac22f8..1645a9a 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -58,7 +58,12 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, } bool IndexingContext::importedModule(const ImportDecl *ImportD) { - SourceLocation Loc = ImportD->getLocation(); + SourceLocation Loc; + auto IdLocs = ImportD->getIdentifierLocs(); + if (!IdLocs.empty()) + Loc = IdLocs.front(); + else + Loc = ImportD->getLocation(); SourceManager &SM = Ctx->getSourceManager(); Loc = SM.getFileLoc(Loc); if (Loc.isInvalid()) @@ -85,7 +90,7 @@ bool IndexingContext::importedModule(const ImportDecl *ImportD) { } } - SymbolRoleSet Roles{}; + SymbolRoleSet Roles = (unsigned)SymbolRole::Reference; if (ImportD->isImplicit()) Roles |= (unsigned)SymbolRole::Implicit; diff --git a/clang/test/Index/Core/Inputs/module/ModA.h b/clang/test/Index/Core/Inputs/module/ModA.h new file mode 100644 index 0000000..081d86c --- /dev/null +++ b/clang/test/Index/Core/Inputs/module/ModA.h @@ -0,0 +1,2 @@ + +void ModA_func(void); diff --git a/clang/test/Index/Core/Inputs/module/module.modulemap b/clang/test/Index/Core/Inputs/module/module.modulemap new file mode 100644 index 0000000..a132562 --- /dev/null +++ b/clang/test/Index/Core/Inputs/module/module.modulemap @@ -0,0 +1 @@ +module ModA { header "ModA.h" export * } diff --git a/clang/test/Index/Core/index-with-module.m b/clang/test/Index/Core/index-with-module.m new file mode 100644 index 0000000..646a48a --- /dev/null +++ b/clang/test/Index/Core/index-with-module.m @@ -0,0 +1,12 @@ +// RUN: rm -rf %t.mcp +// RUN: c-index-test core -print-source-symbols -- %s -I %S/Inputs/module -fmodules -fmodules-cache-path=%t.mcp | FileCheck %s + +// CHECK: [[@LINE+1]]:9 | module/C | ModA | Ref | +@import ModA; +// CHECK: [[@LINE+1]]:1 | module/C | ModA | Ref,Impl | +#include "ModA.h" + +void foo() { + // CHECK: [[@LINE+1]]:3 | function/C | ModA_func | c:@F@ModA_func | {{.*}} | Ref,Call,RelCall | rel: 1 + ModA_func(); +} \ No newline at end of file diff --git a/clang/tools/c-index-test/core_main.cpp b/clang/tools/c-index-test/core_main.cpp index e72b9f9..1881e31 100644 --- a/clang/tools/c-index-test/core_main.cpp +++ b/clang/tools/c-index-test/core_main.cpp @@ -107,6 +107,26 @@ public: return true; } + + bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, + FileID FID, unsigned Offset) override { + ASTContext &Ctx = ImportD->getASTContext(); + SourceManager &SM = Ctx.getSourceManager(); + + unsigned Line = SM.getLineNumber(FID, Offset); + unsigned Col = SM.getColumnNumber(FID, Offset); + OS << Line << ':' << Col << " | "; + + printSymbolInfo(getSymbolInfo(ImportD), OS); + OS << " | "; + + OS << ImportD->getImportedModule()->getFullModuleName() << " | "; + + printSymbolRoles(Roles, OS); + OS << " |\n"; + + return true; + } }; } // anonymous namespace -- 2.7.4