r180643 - [libclang] Introduce clang_Module_getASTFile function that returns the module file where a module object came from.

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Apr 26 15:47:50 PDT 2013


Author: akirtzidis
Date: Fri Apr 26 17:47:49 2013
New Revision: 180643

URL: http://llvm.org/viewvc/llvm-project?rev=180643&view=rev
Log:
[libclang] Introduce clang_Module_getASTFile function that returns the module file where a module object came from.

rdar://13743084

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/annotate-module.m
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CIndex.cpp
    cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=180643&r1=180642&r2=180643&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Apr 26 17:47:49 2013
@@ -3467,6 +3467,13 @@ CINDEX_LINKAGE CXModule clang_Cursor_get
 /**
  * \param Module a module object.
  *
+ * \returns the module file where the provided module object came from.
+ */
+CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
+
+/**
+ * \param Module a module object.
+ *
  * \returns the parent of a sub-module or NULL if the given module is top-level,
  * e.g. for 'std.vector' it will return the 'std' module.
  */

Modified: cfe/trunk/test/Index/annotate-module.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-module.m?rev=180643&r1=180642&r2=180643&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-module.m (original)
+++ cfe/trunk/test/Index/annotate-module.m Fri Apr 26 17:47:49 2013
@@ -40,3 +40,10 @@ int glob;
 // CHECK-MOD-NEXT: Punctuation: "*" [2:5 - 2:6] VarDecl=Module_Sub:2:6
 // CHECK-MOD-NEXT: Identifier: "Module_Sub" [2:6 - 2:16] VarDecl=Module_Sub:2:6
 // CHECK-MOD-NEXT: Punctuation: ";" [2:16 - 2:17]
+
+// RUN: c-index-test -cursor-at=%s:3:11 %s -fmodules-cache-path=%t.cache -fmodules -F %S/../Modules/Inputs \
+// RUN:     | FileCheck %s -check-prefix=CHECK-CURSOR
+
+// CHECK-CURSOR:      3:1 ModuleImport=DependsOnModule:3:1 (Definition) Extent=[3:1 - 3:24] Spelling=DependsOnModule ([3:9 - 3:24]) ModuleName=DependsOnModule ({{.*}}DependsOnModule.pcm) Headers(2):
+// CHECK-CURSOR-NEXT: {{.*}}other.h
+// CHECK-CURSOR-NEXT: {{.*}}DependsOnModule.h

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=180643&r1=180642&r2=180643&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Fri Apr 26 17:47:49 2013
@@ -2105,14 +2105,19 @@ static int inspect_cursor_at(int argc, c
 
         {
           CXModule mod = clang_Cursor_getModule(Cursor);
-          CXString name;
+          CXFile astFile;
+          CXString name, astFilename;
           unsigned i, numHeaders;
           if (mod) {
+            astFile = clang_Module_getASTFile(mod);
+            astFilename = clang_getFileName(astFile);
             name = clang_Module_getFullName(mod);
             numHeaders = clang_Module_getNumTopLevelHeaders(TU, mod);
-            printf(" ModuleName=%s Headers(%d):",
-                   clang_getCString(name), numHeaders);
+            printf(" ModuleName=%s (%s) Headers(%d):",
+                   clang_getCString(name), clang_getCString(astFilename),
+                   numHeaders);
             clang_disposeString(name);
+            clang_disposeString(astFilename);
             for (i = 0; i < numHeaders; ++i) {
               CXFile file = clang_Module_getTopLevelHeader(TU, mod, i);
               CXString filename = clang_getFileName(file);

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=180643&r1=180642&r2=180643&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Fri Apr 26 17:47:49 2013
@@ -6055,6 +6055,13 @@ CXModule clang_Cursor_getModule(CXCursor
   return 0;
 }
 
+CXFile clang_Module_getASTFile(CXModule CXMod) {
+  if (!CXMod)
+    return 0;
+  Module *Mod = static_cast<Module*>(CXMod);
+  return const_cast<FileEntry *>(Mod->getASTFile());
+}
+
 CXModule clang_Module_getParent(CXModule CXMod) {
   if (!CXMod)
     return 0;

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=180643&r1=180642&r2=180643&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Fri Apr 26 17:47:49 2013
@@ -21,6 +21,7 @@ clang_Cursor_isDynamicCall
 clang_Cursor_isNull
 clang_Cursor_isVariadic
 clang_Cursor_getModule
+clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
 clang_Module_getFullName





More information about the cfe-commits mailing list