aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-10-05 00:22:37 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-10-05 00:22:37 +0000
commit5d04b1af7b76ed536557d4bba24005ad0d2fd608 (patch)
treefdbe5b477cdb0ff28007dae53af68c60a66b086e /tools
parentc7782d96c657eeb767bfea5117db49dc40e6356c (diff)
[libclang] Introduce new C functions that provide information about modules:
clang_Cursor_getModule clang_Module_getParent clang_Module_getName clang_Module_getFullName clang_Module_getNumTopLevelHeaders clang_Module_getTopLevelHeader git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165280 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/c-index-test/c-index-test.c19
-rw-r--r--tools/libclang/CIndex.cpp48
-rw-r--r--tools/libclang/libclang.exports6
3 files changed, 73 insertions, 0 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index f4efa900cb..caa50d0167 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -1956,6 +1956,25 @@ static int inspect_cursor_at(int argc, const char **argv) {
if (clang_Cursor_isDynamicCall(Cursor))
printf(" Dynamic-call");
+ {
+ CXModule mod = clang_Cursor_getModule(Cursor);
+ CXString name;
+ unsigned i, numHeaders;
+ if (mod) {
+ name = clang_Module_getFullName(mod);
+ numHeaders = clang_Module_getNumTopLevelHeaders(mod);
+ printf(" ModuleName=%s Headers(%d):",
+ clang_getCString(name), numHeaders);
+ clang_disposeString(name);
+ for (i = 0; i < numHeaders; ++i) {
+ CXFile file = clang_Module_getTopLevelHeader(mod, i);
+ CXString filename = clang_getFileName(file);
+ printf("\n%s", clang_getCString(filename));
+ clang_disposeString(filename);
+ }
+ }
+ }
+
if (completionString != NULL) {
printf("\nCompletion string: ");
print_completion_string(completionString, stdout);
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index abe3eea4af..3543a39f7a 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -5834,6 +5834,54 @@ CXComment clang_Cursor_getParsedComment(CXCursor C) {
return cxcomment::createCXComment(FC, getCursorTU(C));
}
+CXModule clang_Cursor_getModule(CXCursor C) {
+ if (C.kind == CXCursor_ModuleImportDecl) {
+ if (ImportDecl *ImportD = dyn_cast_or_null<ImportDecl>(getCursorDecl(C)))
+ return ImportD->getImportedModule();
+ }
+
+ return 0;
+}
+
+CXModule clang_Module_getParent(CXModule CXMod) {
+ if (!CXMod)
+ return 0;
+ Module *Mod = static_cast<Module*>(CXMod);
+ return Mod->Parent;
+}
+
+CXString clang_Module_getName(CXModule CXMod) {
+ if (!CXMod)
+ return createCXString("");
+ Module *Mod = static_cast<Module*>(CXMod);
+ return createCXString(Mod->Name);
+}
+
+CXString clang_Module_getFullName(CXModule CXMod) {
+ if (!CXMod)
+ return createCXString("");
+ Module *Mod = static_cast<Module*>(CXMod);
+ return createCXString(Mod->getFullModuleName());
+}
+
+unsigned clang_Module_getNumTopLevelHeaders(CXModule CXMod) {
+ if (!CXMod)
+ return 0;
+ Module *Mod = static_cast<Module*>(CXMod);
+ return Mod->TopHeaders.size();
+}
+
+CXFile clang_Module_getTopLevelHeader(CXModule CXMod, unsigned Index) {
+ if (!CXMod)
+ return 0;
+ Module *Mod = static_cast<Module*>(CXMod);
+
+ if (Index < Mod->TopHeaders.size())
+ return const_cast<FileEntry *>(Mod->TopHeaders[Index]);
+
+ return 0;
+}
+
} // end: extern "C"
//===----------------------------------------------------------------------===//
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 610bd91c6a..ec77fafa7b 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -15,6 +15,12 @@ clang_Cursor_getSpellingNameRange
clang_Cursor_getTranslationUnit
clang_Cursor_isDynamicCall
clang_Cursor_isNull
+clang_Cursor_getModule
+clang_Module_getParent
+clang_Module_getName
+clang_Module_getFullName
+clang_Module_getNumTopLevelHeaders
+clang_Module_getTopLevelHeader
clang_IndexAction_create
clang_IndexAction_dispose
clang_Range_isNull