aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-10-18 00:17:05 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-10-18 00:17:05 +0000
commit8d7a24e94b58676e57fd3f47353cbdbc59917d81 (patch)
tree8292f3559d0fcbb646eae94042ed784e3d09e143
parentff9c9e1d71ec8f994c08d185f5acc01c0a685d0d (diff)
[libclang] Invoke a ppIncludedFile callback when indexing implicit module imports.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166161 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang-c/Index.h5
-rw-r--r--test/Index/index-module.m2
-rw-r--r--tools/c-index-test/c-index-test.c3
-rw-r--r--tools/libclang/Indexing.cpp27
-rw-r--r--tools/libclang/IndexingContext.cpp5
-rw-r--r--tools/libclang/IndexingContext.h2
6 files changed, 24 insertions, 20 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index b122faa443..650e633940 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -4985,6 +4985,11 @@ typedef struct {
CXFile file;
int isImport;
int isAngled;
+ /**
+ * \brief Non-zero if the directive was automatically turned into a module
+ * import.
+ */
+ int isModuleImport;
} CXIdxIncludedFileInfo;
/**
diff --git a/test/Index/index-module.m b/test/Index/index-module.m
index 04eb99ac19..0af4e37f3c 100644
--- a/test/Index/index-module.m
+++ b/test/Index/index-module.m
@@ -9,6 +9,7 @@ int glob;
// CHECK-NOT: [indexDeclaration]
// CHECK: [importedASTFile]: [[PCM:.*[/\\]DependsOnModule\.pcm]] | loc: 2:2 | name: "DependsOnModule" | isImplicit: 1
+// CHECK-NEXT: [ppIncludedFile]: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h | name: "DependsOnModule/DependsOnModule.h" | hash loc: 2:1 | isImport: 0 | isAngled: 1 | isModule: 1
// CHECK-NOT: [indexDeclaration]
// CHECK: [importedASTFile]: [[PCM]] | loc: 3:1 | name: "DependsOnModule" | isImplicit: 0
// CHECK-NEXT: [indexDeclaration]: kind: variable | name: glob | {{.*}} | loc: 4:5
@@ -18,6 +19,7 @@ int glob;
// 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_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
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index c46ba74ce4..eda82d1872 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -2363,7 +2363,8 @@ 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\n", info->isImport, info->isAngled);
+ printf(" | isImport: %d | isAngled: %d | isModule: %d\n",
+ info->isImport, info->isAngled, info->isModuleImport);
return (CXIdxClientFile)info->file;
}
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 887b5fc1ee..36442fa232 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -73,14 +73,10 @@ public:
StringRef SearchPath,
StringRef RelativePath,
const Module *Imported) {
- if (Imported) {
- // We handle implicit imports via ImportDecls.
- return;
- }
-
bool isImport = (IncludeTok.is(tok::identifier) &&
IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
- IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);
+ IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled,
+ Imported);
}
/// MacroDefined - This hook is called whenever a macro definition is seen.
@@ -458,16 +454,15 @@ static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
PreprocessedEntity *PPE = *I;
if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
- if (!ID->importedModule()) {
- SourceLocation Loc = ID->getSourceRange().getBegin();
- // Modules have synthetic main files as input, give an invalid location
- // if the location points to such a file.
- if (isModuleFile && Unit.isInMainFileID(Loc))
- Loc = SourceLocation();
- IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
- ID->getFile(), ID->getKind() == InclusionDirective::Import,
- !ID->wasInQuotes());
- }
+ SourceLocation Loc = ID->getSourceRange().getBegin();
+ // Modules have synthetic main files as input, give an invalid location
+ // if the location points to such a file.
+ if (isModuleFile && Unit.isInMainFileID(Loc))
+ Loc = SourceLocation();
+ IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
+ ID->getFile(),
+ ID->getKind() == InclusionDirective::Import,
+ !ID->wasInQuotes(), ID->importedModule());
}
}
}
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 74b3cf362b..09efebb62f 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -240,7 +240,8 @@ void IndexingContext::enteredMainFile(const FileEntry *File) {
void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
StringRef filename,
const FileEntry *File,
- bool isImport, bool isAngled) {
+ bool isImport, bool isAngled,
+ bool isModuleImport) {
if (!CB.ppIncludedFile)
return;
@@ -248,7 +249,7 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc),
SA.toCStr(filename),
(CXFile)File,
- isImport, isAngled };
+ isImport, isAngled, isModuleImport };
CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info);
FileMap[File] = idxFile;
}
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index 7671e6c2f1..78a8abc270 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -369,7 +369,7 @@ public:
void ppIncludedFile(SourceLocation hashLoc,
StringRef filename, const FileEntry *File,
- bool isImport, bool isAngled);
+ bool isImport, bool isAngled, bool isModuleImport);
void importedModule(const ImportDecl *ImportD);
void importedPCH(const FileEntry *File);