aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/c-index-test/c-index-test.c20
-rw-r--r--tools/libclang/IndexDecl.cpp9
-rw-r--r--tools/libclang/Indexing.cpp6
-rw-r--r--tools/libclang/IndexingContext.cpp21
-rw-r--r--tools/libclang/IndexingContext.h4
5 files changed, 59 insertions, 1 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 85dcddd91c..28ad59e4a9 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -2349,6 +2349,24 @@ static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
return (CXIdxClientFile)info->file;
}
+static CXIdxClientFile index_importedASTFile(CXClientData client_data,
+ const CXIdxImportedASTFileInfo *info) {
+ IndexData *index_data;
+ index_data = (IndexData *)client_data;
+ printCheck(index_data);
+
+ printf("[importedASTFile]: ");
+ 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);
+
+ return (CXIdxClientFile)info->file;
+}
+
static CXIdxClientContainer index_startedTranslationUnit(CXClientData client_data,
void *reserved) {
IndexData *index_data;
@@ -2479,7 +2497,7 @@ static IndexerCallbacks IndexCB = {
index_diagnostic,
index_enteredMainFile,
index_ppIncludedFile,
- 0, /*importedASTFile*/
+ index_importedASTFile,
index_startedTranslationUnit,
index_indexDeclaration,
index_indexEntityReference
diff --git a/tools/libclang/IndexDecl.cpp b/tools/libclang/IndexDecl.cpp
index 53a98f111c..65b0b16a37 100644
--- a/tools/libclang/IndexDecl.cpp
+++ b/tools/libclang/IndexDecl.cpp
@@ -10,6 +10,7 @@
#include "IndexingContext.h"
#include "clang/AST/DeclVisitor.h"
+#include "clang/Basic/Module.h"
using namespace clang;
using namespace cxindex;
@@ -305,6 +306,14 @@ public:
IndexCtx.indexTypeSourceInfo(D->getTemplatedDecl()->getTypeSourceInfo(), D);
return true;
}
+
+ bool VisitImportDecl(ImportDecl *D) {
+ Module *Imported = D->getImportedModule();
+ if (Imported)
+ IndexCtx.importedModule(D->getLocation(), Imported->getFullModuleName(),
+ /*isIncludeDirective=*/false, Imported);
+ return true;
+ }
};
} // anonymous namespace
diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp
index c4fba96849..efae7eecd8 100644
--- a/tools/libclang/Indexing.cpp
+++ b/tools/libclang/Indexing.cpp
@@ -73,6 +73,12 @@ public:
StringRef SearchPath,
StringRef RelativePath,
const Module *Imported) {
+ if (Imported) {
+ IndexCtx.importedModule(HashLoc, FileName, /*isIncludeDirective=*/true,
+ Imported);
+ return;
+ }
+
bool isImport = (IncludeTok.is(tok::identifier) &&
IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 210dc36d52..3a3c010370 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -253,6 +253,27 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
FileMap[File] = idxFile;
}
+void IndexingContext::importedModule(SourceLocation Loc,
+ StringRef name, bool isIncludeDirective,
+ const Module *module) {
+ if (!CB.importedASTFile)
+ return;
+
+ std::string ModuleName = module->getFullModuleName();
+
+ ScratchAlloc SA(*this);
+ CXIdxImportedASTFileInfo Info = {
+ (CXFile)module->getASTFile(),
+ getIndexLoc(Loc),
+ /*isModule=*/true,
+ isIncludeDirective,
+ SA.toCStr(name),
+ ModuleName.c_str(),
+ };
+ CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
+ (void)astFile;
+}
+
void IndexingContext::startedTranslationUnit() {
CXIdxClientContainer idxCont = 0;
if (CB.startedTranslationUnit)
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index be21927c5b..f74dd1ad0a 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -382,6 +382,10 @@ public:
StringRef filename, const FileEntry *File,
bool isImport, bool isAngled);
+ void importedModule(SourceLocation Loc,
+ StringRef name, bool isIncludeDirective,
+ const Module *module);
+
void startedTranslationUnit();
void indexDecl(const Decl *D);