From: Argyrios Kyrtzidis Date: Mon, 29 Feb 2016 07:56:07 +0000 (+0000) Subject: [index] Print and test module import references. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf6bc2febef128c40996325dfa20192e9f203211;p=clang [index] Print and test module import references. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262208 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index 39812c4fe4..62e2facde1 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/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/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp index 9ac22f85e1..1645a9ab0b 100644 --- a/lib/Index/IndexingContext.cpp +++ b/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/test/Index/Core/Inputs/module/ModA.h b/test/Index/Core/Inputs/module/ModA.h new file mode 100644 index 0000000000..081d86cc45 --- /dev/null +++ b/test/Index/Core/Inputs/module/ModA.h @@ -0,0 +1,2 @@ + +void ModA_func(void); diff --git a/test/Index/Core/Inputs/module/module.modulemap b/test/Index/Core/Inputs/module/module.modulemap new file mode 100644 index 0000000000..a132562eaf --- /dev/null +++ b/test/Index/Core/Inputs/module/module.modulemap @@ -0,0 +1 @@ +module ModA { header "ModA.h" export * } diff --git a/test/Index/Core/index-with-module.m b/test/Index/Core/index-with-module.m new file mode 100644 index 0000000000..646a48a2c9 --- /dev/null +++ b/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/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index e72b9f93ef..1881e31e20 100644 --- a/tools/c-index-test/core_main.cpp +++ b/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