Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit e858e66

Browse files
committed
[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
1 parent 888d345 commit e858e66

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

Diff for: include/clang-c/Index.h

+7
Original file line numberDiff line numberDiff line change
@@ -3464,6 +3464,13 @@ typedef void *CXModule;
34643464
*/
34653465
CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C);
34663466

3467+
/**
3468+
* \param Module a module object.
3469+
*
3470+
* \returns the module file where the provided module object came from.
3471+
*/
3472+
CINDEX_LINKAGE CXFile clang_Module_getASTFile(CXModule Module);
3473+
34673474
/**
34683475
* \param Module a module object.
34693476
*

Diff for: test/Index/annotate-module.m

+7
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,10 @@
4040
// CHECK-MOD-NEXT: Punctuation: "*" [2:5 - 2:6] VarDecl=Module_Sub:2:6
4141
// CHECK-MOD-NEXT: Identifier: "Module_Sub" [2:6 - 2:16] VarDecl=Module_Sub:2:6
4242
// CHECK-MOD-NEXT: Punctuation: ";" [2:16 - 2:17]
43+
44+
// RUN: c-index-test -cursor-at=%s:3:11 %s -fmodules-cache-path=%t.cache -fmodules -F %S/../Modules/Inputs \
45+
// RUN: | FileCheck %s -check-prefix=CHECK-CURSOR
46+
47+
// 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):
48+
// CHECK-CURSOR-NEXT: {{.*}}other.h
49+
// CHECK-CURSOR-NEXT: {{.*}}DependsOnModule.h

Diff for: tools/c-index-test/c-index-test.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -2105,14 +2105,19 @@ static int inspect_cursor_at(int argc, const char **argv) {
21052105

21062106
{
21072107
CXModule mod = clang_Cursor_getModule(Cursor);
2108-
CXString name;
2108+
CXFile astFile;
2109+
CXString name, astFilename;
21092110
unsigned i, numHeaders;
21102111
if (mod) {
2112+
astFile = clang_Module_getASTFile(mod);
2113+
astFilename = clang_getFileName(astFile);
21112114
name = clang_Module_getFullName(mod);
21122115
numHeaders = clang_Module_getNumTopLevelHeaders(TU, mod);
2113-
printf(" ModuleName=%s Headers(%d):",
2114-
clang_getCString(name), numHeaders);
2116+
printf(" ModuleName=%s (%s) Headers(%d):",
2117+
clang_getCString(name), clang_getCString(astFilename),
2118+
numHeaders);
21152119
clang_disposeString(name);
2120+
clang_disposeString(astFilename);
21162121
for (i = 0; i < numHeaders; ++i) {
21172122
CXFile file = clang_Module_getTopLevelHeader(TU, mod, i);
21182123
CXString filename = clang_getFileName(file);

Diff for: tools/libclang/CIndex.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -6055,6 +6055,13 @@ CXModule clang_Cursor_getModule(CXCursor C) {
60556055
return 0;
60566056
}
60576057

6058+
CXFile clang_Module_getASTFile(CXModule CXMod) {
6059+
if (!CXMod)
6060+
return 0;
6061+
Module *Mod = static_cast<Module*>(CXMod);
6062+
return const_cast<FileEntry *>(Mod->getASTFile());
6063+
}
6064+
60586065
CXModule clang_Module_getParent(CXModule CXMod) {
60596066
if (!CXMod)
60606067
return 0;

Diff for: tools/libclang/libclang.exports

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ clang_Cursor_isDynamicCall
2121
clang_Cursor_isNull
2222
clang_Cursor_isVariadic
2323
clang_Cursor_getModule
24+
clang_Module_getASTFile
2425
clang_Module_getParent
2526
clang_Module_getName
2627
clang_Module_getFullName

0 commit comments

Comments
 (0)