r262208 - [index] Print and test module import references.

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 28 23:56:07 PST 2016


Author: akirtzidis
Date: Mon Feb 29 01:56:07 2016
New Revision: 262208

URL: http://llvm.org/viewvc/llvm-project?rev=262208&view=rev
Log:
[index] Print and test module import references.

Added:
    cfe/trunk/test/Index/Core/Inputs/
    cfe/trunk/test/Index/Core/Inputs/module/
    cfe/trunk/test/Index/Core/Inputs/module/ModA.h
    cfe/trunk/test/Index/Core/Inputs/module/module.modulemap
    cfe/trunk/test/Index/Core/index-with-module.m
Modified:
    cfe/trunk/lib/Index/IndexSymbol.cpp
    cfe/trunk/lib/Index/IndexingContext.cpp
    cfe/trunk/tools/c-index-test/core_main.cpp

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=262208&r1=262207&r2=262208&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Mon Feb 29 01:56:07 2016
@@ -53,6 +53,9 @@ SymbolInfo index::getSymbolInfo(const De
 
   } else {
     switch (D->getKind()) {
+    case Decl::Import:
+      Info.Kind = SymbolKind::Module;
+      break;
     case Decl::Typedef:
       Info.Kind = SymbolKind::Typedef; break;
     case Decl::Function:

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=262208&r1=262207&r2=262208&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Mon Feb 29 01:56:07 2016
@@ -58,7 +58,12 @@ bool IndexingContext::handleReference(co
 }
 
 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(con
     }
   }
 
-  SymbolRoleSet Roles{};
+  SymbolRoleSet Roles = (unsigned)SymbolRole::Reference;
   if (ImportD->isImplicit())
     Roles |= (unsigned)SymbolRole::Implicit;
 

Added: cfe/trunk/test/Index/Core/Inputs/module/ModA.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/Inputs/module/ModA.h?rev=262208&view=auto
==============================================================================
--- cfe/trunk/test/Index/Core/Inputs/module/ModA.h (added)
+++ cfe/trunk/test/Index/Core/Inputs/module/ModA.h Mon Feb 29 01:56:07 2016
@@ -0,0 +1,2 @@
+
+void ModA_func(void);

Added: cfe/trunk/test/Index/Core/Inputs/module/module.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/Inputs/module/module.modulemap?rev=262208&view=auto
==============================================================================
--- cfe/trunk/test/Index/Core/Inputs/module/module.modulemap (added)
+++ cfe/trunk/test/Index/Core/Inputs/module/module.modulemap Mon Feb 29 01:56:07 2016
@@ -0,0 +1 @@
+module ModA { header "ModA.h" export * }

Added: cfe/trunk/test/Index/Core/index-with-module.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-with-module.m?rev=262208&view=auto
==============================================================================
--- cfe/trunk/test/Index/Core/index-with-module.m (added)
+++ cfe/trunk/test/Index/Core/index-with-module.m Mon Feb 29 01:56:07 2016
@@ -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 |
+ at 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 at ModA_func | {{.*}} | Ref,Call,RelCall | rel: 1
+  ModA_func();
+}
\ No newline at end of file

Modified: cfe/trunk/tools/c-index-test/core_main.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=262208&r1=262207&r2=262208&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/core_main.cpp (original)
+++ cfe/trunk/tools/c-index-test/core_main.cpp Mon Feb 29 01:56:07 2016
@@ -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




More information about the cfe-commits mailing list