* \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"
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;
}
#include "IndexingContext.h"
#include "clang/AST/DeclVisitor.h"
-#include "clang/Basic/Module.h"
using namespace clang;
using namespace cxindex;
}
bool VisitImportDecl(ImportDecl *D) {
- Module *Imported = D->getImportedModule();
- if (Imported)
- IndexCtx.importedModule(D->getLocation(), Imported->getFullModuleName(),
- /*isIncludeDirective=*/false, Imported);
+ IndexCtx.importedModule(D);
return true;
}
};
StringRef RelativePath,
const Module *Imported) {
if (Imported) {
- IndexCtx.importedModule(HashLoc, FileName, /*isIncludeDirective=*/true,
- Imported);
+ // We handle implicit imports via ImportDecls.
return;
}
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);
return false;
if (isa<ObjCMethodDecl>(D))
return false;
+ if (isa<ImportDecl>(D))
+ return false;
return true;
}
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();