diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-05-14 23:14:37 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-05-14 23:14:37 +0000 |
commit | 1e80e4c5dee95c2d0f93bb600400569f944f604c (patch) | |
tree | c067fcc5779119a05d00b62b53ab5ccafb1351cc | |
parent | c85839cf5e69572d949ee7795043ba03c3627451 (diff) | |
download | clang-1e80e4c5dee95c2d0f93bb600400569f944f604c.tar.gz clang-1e80e4c5dee95c2d0f93bb600400569f944f604c.tar.bz2 clang-1e80e4c5dee95c2d0f93bb600400569f944f604c.tar.xz |
[liblang] Introduce clang_getModuleForFile, which given a CXFile header file, returns the module that contains it, if one exists.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208822 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang-c/Index.h | 8 | ||||
-rw-r--r-- | test/Index/index-module.m | 14 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 16 | ||||
-rw-r--r-- | tools/libclang/CIndex.cpp | 20 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 1 |
5 files changed, 50 insertions, 9 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 87b1f432fa..f8cbb9be6c 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -32,7 +32,7 @@ * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable. */ #define CINDEX_VERSION_MAJOR 0 -#define CINDEX_VERSION_MINOR 26 +#define CINDEX_VERSION_MINOR 27 #define CINDEX_VERSION_ENCODE(major, minor) ( \ ((major) * 10000) \ @@ -3587,6 +3587,12 @@ typedef void *CXModule; CINDEX_LINKAGE CXModule clang_Cursor_getModule(CXCursor C); /** + * \brief Given a CXFile header file, return the module that contains it, if one + * exists. + */ +CINDEX_LINKAGE CXModule clang_getModuleForFile(CXTranslationUnit, CXFile); + +/** * \param Module a module object. * * \returns the module file where the provided module object came from. diff --git a/test/Index/index-module.m b/test/Index/index-module.m index d6953136d8..8e0155607d 100644 --- a/test/Index/index-module.m +++ b/test/Index/index-module.m @@ -18,13 +18,13 @@ int glob; // RUN: c-index-test -index-tu %t.cache/DependsOnModule.pcm | FileCheck %s -check-prefix=CHECK-DMOD // CHECK-DMOD: [startedTranslationUnit] -// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_MODULE_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]DependsOnModule\.h]] | {{.*}} | hash loc: <invalid> -// CHECK-DMOD-NEXT: [ppIncludedFile]: {{.*}}/Modules/Inputs/Module.framework{{[/\\]}}Headers{{[/\\]}}Module.h | name: "Module/Module.h" | hash loc: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h:1:1 | isImport: 0 | isAngled: 1 | isModule: 1 -// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_OTHER_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]other\.h]] | {{.*}} | hash loc: <invalid> -// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_NOT_CXX_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]not_cxx\.h]] | {{.*}} | hash loc: <invalid> -// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Frameworks[/\\]SubFramework\.framework[/\\]Headers[/\\]SubFramework\.h]] | {{.*}} | hash loc: <invalid> -// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_OTHER_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]Frameworks/SubFramework\.framework/Headers/Other\.h]] | name: "SubFramework/Other.h" | hash loc: [[DMOD_SUB_H]]:1:1 | isImport: 0 | isAngled: 0 -// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_PRIVATE_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]PrivateHeaders[/\\]DependsOnModulePrivate.h]] | {{.*}} | hash loc: <invalid> +// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_MODULE_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]DependsOnModule\.h]] | {{.*}} | hash loc: <invalid> | {{.*}} | module: DependsOnModule +// CHECK-DMOD-NEXT: [ppIncludedFile]: {{.*}}/Modules/Inputs/Module.framework{{[/\\]}}Headers{{[/\\]}}Module.h | name: "Module/Module.h" | hash loc: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h:1:1 | isImport: 0 | isAngled: 1 | isModule: 1 | module: Module +// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_OTHER_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]other\.h]] | {{.*}} | hash loc: <invalid> | {{.*}} | module: DependsOnModule +// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_NOT_CXX_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]not_cxx\.h]] | {{.*}} | hash loc: <invalid> | {{.*}} | module: DependsOnModule.NotCXX +// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Frameworks[/\\]SubFramework\.framework[/\\]Headers[/\\]SubFramework\.h]] | {{.*}} | hash loc: <invalid> | {{.*}} | module: DependsOnModule.SubFramework +// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_OTHER_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]Frameworks/SubFramework\.framework/Headers/Other\.h]] | name: "SubFramework/Other.h" | hash loc: [[DMOD_SUB_H]]:1:1 | isImport: 0 | isAngled: 0 | isModule: 0 | module: DependsOnModule.SubFramework.Other +// CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_PRIVATE_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]PrivateHeaders[/\\]DependsOnModulePrivate.h]] | {{.*}} | hash loc: <invalid> | {{.*}} | module: DependsOnModule.Private.DependsOnModule // CHECK-DMOD-NEXT: [importedASTFile]: {{.*}}.cache{{[/\\]}}Module.pcm | loc: [[DMOD_MODULE_H]]:1:2 | name: "Module" | isImplicit: 1 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: depends_on_module_other | {{.*}} | loc: [[DMOD_OTHER_H]]:1:5 // CHECK-DMOD-NEXT: [indexDeclaration]: kind: variable | name: template | {{.*}} | loc: [[DMOD_NOT_CXX_H]]:1:12 diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 7ed88dee66..9192b3a38b 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -2544,6 +2544,7 @@ typedef struct { const char *main_filename; ImportedASTFilesData *importedASTs; IndexDataStringList *strings; + CXTranslationUnit TU; } IndexData; static void free_client_data(IndexData *index_data) { @@ -2813,6 +2814,7 @@ static CXIdxClientFile index_enteredMainFile(CXClientData client_data, static CXIdxClientFile index_ppIncludedFile(CXClientData client_data, const CXIdxIncludedFileInfo *info) { IndexData *index_data; + CXModule Mod; index_data = (IndexData *)client_data; printCheck(index_data); @@ -2821,8 +2823,18 @@ static CXIdxClientFile index_ppIncludedFile(CXClientData client_data, printf(" | name: \"%s\"", info->filename); printf(" | hash loc: "); printCXIndexLoc(info->hashLoc, client_data); - printf(" | isImport: %d | isAngled: %d | isModule: %d\n", + printf(" | isImport: %d | isAngled: %d | isModule: %d", info->isImport, info->isAngled, info->isModuleImport); + + Mod = clang_getModuleForFile(index_data->TU, (CXFile)info->file); + if (Mod) { + CXString str = clang_Module_getFullName(Mod); + const char *cstr = clang_getCString(str); + printf(" | module: %s", cstr); + clang_disposeString(str); + } + + printf("\n"); return (CXIdxClientFile)info->file; } @@ -3032,6 +3044,7 @@ static int index_compile_args(int num_args, const char **args, index_data.main_filename = ""; index_data.importedASTs = importedASTs; index_data.strings = NULL; + index_data.TU = NULL; index_opts = getIndexOptions(); result = clang_indexSourceFile(idxAction, &index_data, @@ -3068,6 +3081,7 @@ static int index_ast_file(const char *ast_file, index_data.main_filename = ""; index_data.importedASTs = importedASTs; index_data.strings = NULL; + index_data.TU = TU; index_opts = getIndexOptions(); result = clang_indexTranslationUnit(idxAction, &index_data, diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index 754026eae1..f38d4c2bc8 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -6329,6 +6329,26 @@ CXModule clang_Cursor_getModule(CXCursor C) { return 0; } +CXModule clang_getModuleForFile(CXTranslationUnit TU, CXFile File) { + if (isNotUsableTU(TU)) { + LOG_BAD_TU(TU); + return nullptr; + } + if (!File) + return nullptr; + FileEntry *FE = static_cast<FileEntry *>(File); + + ASTUnit &Unit = *cxtu::getASTUnit(TU); + HeaderSearch &HS = Unit.getPreprocessor().getHeaderSearchInfo(); + ModuleMap::KnownHeader Header = HS.findModuleForHeader(FE); + + if (Module *Mod = Header.getModule()) { + if (Header.getRole() != ModuleMap::ExcludedHeader) + return Mod; + } + return nullptr; +} + CXFile clang_Module_getASTFile(CXModule CXMod) { if (!CXMod) return 0; diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index df8d85c01f..f761c044c2 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -194,6 +194,7 @@ clang_getInclusions clang_getInstantiationLocation clang_getLocation clang_getLocationForOffset +clang_getModuleForFile clang_getNullCursor clang_getNullLocation clang_getNullRange |