diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang-c/Index.h | 8 | ||||
-rw-r--r-- | clang/test/Index/index-module.m | 14 | ||||
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 16 | ||||
-rw-r--r-- | clang/tools/libclang/CIndex.cpp | 20 | ||||
-rw-r--r-- | clang/tools/libclang/libclang.exports | 1 |
5 files changed, 50 insertions, 9 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 87b1f432fa5..f8cbb9be6c6 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/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/clang/test/Index/index-module.m b/clang/test/Index/index-module.m index d6953136d86..8e0155607dd 100644 --- a/clang/test/Index/index-module.m +++ b/clang/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/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index 7ed88dee66d..9192b3a38b4 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/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/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 754026eae17..f38d4c2bc87 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/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/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports index df8d85c01f4..f761c044c2f 100644 --- a/clang/tools/libclang/libclang.exports +++ b/clang/tools/libclang/libclang.exports @@ -194,6 +194,7 @@ clang_getInclusions clang_getInstantiationLocation clang_getLocation clang_getLocationForOffset +clang_getModuleForFile clang_getNullCursor clang_getNullLocation clang_getNullRange |