[libclang] Simplify indexing of module imports by handling implicit
imports via ImportDecls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165160 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 6ef028a..fba2ba8 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -4937,12 +4937,7 @@
* \brief Non-zero if an inclusion directive was automatically turned into
* a module import.
*/
- int isIncludeDirective;
- /**
- * \brief The name of the file being included or the module being imported,
- * as written in the source code.
- */
- const char *sourceName;
+ int isImplicit;
/**
* \brief The actual name of the module or submodule being imported.
* The syntax is a sequence of identifiers separated by dots, e.g "std.vector"
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 5b71e5c..f4efa90 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -2359,10 +2359,9 @@
printCXIndexFile((CXIdxClientFile)info->file);
printf(" | loc: ");
printCXIndexLoc(info->loc, client_data);
- printf(" | module name: \"%s\"", info->moduleName);
- printf(" | source name: \"%s\"", info->sourceName);
- printf(" | isModule: %d | isIncludeDirective: %d\n",
- info->isModule, info->isIncludeDirective);
+ printf(" | name: \"%s\"", info->moduleName);
+ printf(" | isModule: %d | isImplicit: %d\n",
+ info->isModule, info->isImplicit);
return (CXIdxClientFile)info->file;
}
diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp
index 65b0b16..5130381 100644
--- a/tools/libclang/IndexDecl.cpp
+++ b/tools/libclang/IndexDecl.cpp
@@ -10,7 +10,6 @@
#include "IndexingContext.h"
#include "clang/AST/DeclVisitor.h"
-#include "clang/Basic/Module.h"
using namespace clang;
using namespace cxindex;
@@ -308,10 +307,7 @@
}
bool VisitImportDecl(ImportDecl *D) {
- Module *Imported = D->getImportedModule();
- if (Imported)
- IndexCtx.importedModule(D->getLocation(), Imported->getFullModuleName(),
- /*isIncludeDirective=*/false, Imported);
+ IndexCtx.importedModule(D);
return true;
}
};
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index 6b9abbc..6cf3a63 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -74,8 +74,7 @@
StringRef RelativePath,
const Module *Imported) {
if (Imported) {
- IndexCtx.importedModule(HashLoc, FileName, /*isIncludeDirective=*/true,
- Imported);
+ // We handle implicit imports via ImportDecls.
return;
}
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 3a3c010..c964e96 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -253,21 +253,20 @@
FileMap[File] = idxFile;
}
-void IndexingContext::importedModule(SourceLocation Loc,
- StringRef name, bool isIncludeDirective,
- const Module *module) {
+void IndexingContext::importedModule(const ImportDecl *ImportD) {
if (!CB.importedASTFile)
return;
- std::string ModuleName = module->getFullModuleName();
+ Module *Mod = ImportD->getImportedModule();
+ if (!Mod)
+ return;
+ std::string ModuleName = Mod->getFullModuleName();
- ScratchAlloc SA(*this);
CXIdxImportedASTFileInfo Info = {
- (CXFile)module->getASTFile(),
- getIndexLoc(Loc),
+ (CXFile)Mod->getASTFile(),
+ getIndexLoc(ImportD->getLocation()),
/*isModule=*/true,
- isIncludeDirective,
- SA.toCStr(name),
+ ImportD->isImplicit(),
ModuleName.c_str(),
};
CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
@@ -1110,6 +1109,8 @@
return false;
if (isa<ObjCMethodDecl>(D))
return false;
+ if (isa<ImportDecl>(D))
+ return false;
return true;
}
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index f74dd1a..e556d4d 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -382,9 +382,7 @@
StringRef filename, const FileEntry *File,
bool isImport, bool isAngled);
- void importedModule(SourceLocation Loc,
- StringRef name, bool isIncludeDirective,
- const Module *module);
+ void importedModule(const ImportDecl *ImportD);
void startedTranslationUnit();