[index] Print and test module import references.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 29 Feb 2016 07:56:07 +0000 (07:56 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 29 Feb 2016 07:56:07 +0000 (07:56 +0000)
llvm-svn: 262208

clang/lib/Index/IndexSymbol.cpp
clang/lib/Index/IndexingContext.cpp
clang/test/Index/Core/Inputs/module/ModA.h [new file with mode: 0644]
clang/test/Index/Core/Inputs/module/module.modulemap [new file with mode: 0644]
clang/test/Index/Core/index-with-module.m [new file with mode: 0644]
clang/tools/c-index-test/core_main.cpp

index 39812c4..62e2fac 100644 (file)
@@ -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:
index 9ac22f8..1645a9a 100644 (file)
@@ -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 (file)
index 0000000..081d86c
--- /dev/null
@@ -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 (file)
index 0000000..a132562
--- /dev/null
@@ -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 (file)
index 0000000..646a48a
--- /dev/null
@@ -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
index e72b9f9..1881e31 100644 (file)
@@ -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