[liblang] Introduce clang_getModuleForFile, which given a CXFile header file, returns the module that contains it, if one exists.
llvm-svn: 208822
This commit is contained in:
parent
becce11112
commit
f6d49c36b2
|
@ -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) \
|
||||
|
@ -3586,6 +3586,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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -194,6 +194,7 @@ clang_getInclusions
|
|||
clang_getInstantiationLocation
|
||||
clang_getLocation
|
||||
clang_getLocationForOffset
|
||||
clang_getModuleForFile
|
||||
clang_getNullCursor
|
||||
clang_getNullLocation
|
||||
clang_getNullRange
|
||||
|
|
Loading…
Reference in New Issue