diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-04-26 22:47:49 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2013-04-26 22:47:49 +0000 |
commit | e858e667c14ce4a9df5a4bbae770a0a3a3c8723e (patch) | |
tree | c90137a5944cf218d836524ad4b99018c5009269 | |
parent | 888d34566a4de6097896863a2f6660ed1537ddb9 (diff) | |
download | clang-e858e667c14ce4a9df5a4bbae770a0a3a3c8723e.tar.gz clang-e858e667c14ce4a9df5a4bbae770a0a3a3c8723e.tar.bz2 clang-e858e667c14ce4a9df5a4bbae770a0a3a3c8723e.tar.xz |
[libclang] Introduce clang_Module_getASTFile function that returns the module file where a module object came from.
rdar://13743084
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180643 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang-c/Index.h | 7 | ||||
-rw-r--r-- | test/Index/annotate-module.m | 7 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 11 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 7 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 1 |
5 files changed, 30 insertions, 3 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 37072a7658..d8c37ebd70 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -3467,6 +3467,13 @@ CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C); /** * \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. */ diff --git a/test/Index/annotate-module.m b/test/Index/annotate-module.m index 33ca3f8324..55e21d235e 100644 --- a/test/Index/annotate-module.m +++ b/test/Index/annotate-module.m @@ -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 diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 3f39a78625..e575234167 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -2105,14 +2105,19 @@ static int inspect_cursor_at(int argc, const char **argv) { { 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); diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 0a8a068998..a43c1ab7e4 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -6055,6 +6055,13 @@ CXModule clang_Cursor_getModule(CXCursor C) { 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; diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index c7508bc544..0c9912e520 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -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 |