From 37f2f52fbc16b0d426d4d86c7e1662e5c6b9e3b8 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 3 Oct 2012 21:05:44 +0000 Subject: [PATCH] [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 --- include/clang-c/Index.h | 7 +------ tools/c-index-test/c-index-test.c | 7 +++---- tools/libclang/IndexDecl.cpp | 6 +----- tools/libclang/Indexing.cpp | 3 +-- tools/libclang/IndexingContext.cpp | 19 ++++++++++--------- tools/libclang/IndexingContext.h | 4 +--- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 6ef028a077..fba2ba8337 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -4937,12 +4937,7 @@ typedef struct { * \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 5b71e5ce25..f4efa900cb 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -2359,10 +2359,9 @@ static CXIdxClientFile index_importedASTFile(CXClientData client_data, 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 65b0b16a37..513038119d 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 @@ public: } 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 6b9abbcf03..6cf3a637ac 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -74,8 +74,7 @@ public: 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 3a3c010370..c964e963c7 100644 --- a/tools/libclang/IndexingContext.cpp +++ b/tools/libclang/IndexingContext.cpp @@ -253,21 +253,20 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc, 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 @@ bool IndexingContext::shouldIgnoreIfImplicit(const Decl *D) { return false; if (isa(D)) return false; + if (isa(D)) + return false; return true; } diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h index f74dd1ad0a..e556d4dd5f 100644 --- a/tools/libclang/IndexingContext.h +++ b/tools/libclang/IndexingContext.h @@ -382,9 +382,7 @@ public: 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(); -- 2.40.0