forked from OSchip/llvm-project
[libclang] Implement the importedASTFile indexing callback to provide
info about imported modules. llvm-svn: 165020
This commit is contained in:
parent
bc2724f6e0
commit
472eda06b0
|
@ -4921,16 +4921,35 @@ typedef struct {
|
||||||
* \brief Data for IndexerCallbacks#importedASTFile.
|
* \brief Data for IndexerCallbacks#importedASTFile.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
/**
|
||||||
|
* \brief Top level AST file containing the imported PCH, module or submodule.
|
||||||
|
*/
|
||||||
CXFile file;
|
CXFile file;
|
||||||
/**
|
/**
|
||||||
* \brief Location where the file is imported. It is useful mostly for
|
* \brief Location where the file is imported. Applicable only for modules.
|
||||||
* modules.
|
|
||||||
*/
|
*/
|
||||||
CXIdxLoc loc;
|
CXIdxLoc loc;
|
||||||
/**
|
/**
|
||||||
* \brief Non-zero if the AST file is a module otherwise it's a PCH.
|
* \brief Non-zero if the AST file is a module otherwise it's a PCH.
|
||||||
*/
|
*/
|
||||||
int isModule;
|
int isModule;
|
||||||
|
/**
|
||||||
|
* \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;
|
||||||
|
/**
|
||||||
|
* \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"
|
||||||
|
* Applicable only for modules.
|
||||||
|
*/
|
||||||
|
const char *moduleName;
|
||||||
|
|
||||||
} CXIdxImportedASTFileInfo;
|
} CXIdxImportedASTFileInfo;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -5182,8 +5201,8 @@ typedef struct {
|
||||||
*
|
*
|
||||||
* AST files will not get indexed (there will not be callbacks to index all
|
* AST files will not get indexed (there will not be callbacks to index all
|
||||||
* the entities in an AST file). The recommended action is that, if the AST
|
* the entities in an AST file). The recommended action is that, if the AST
|
||||||
* file is not already indexed, to block further indexing and initiate a new
|
* file is not already indexed, to initiate a new indexing job specific to
|
||||||
* indexing job specific to the AST file.
|
* the AST file.
|
||||||
*/
|
*/
|
||||||
CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
|
CXIdxClientASTFile (*importedASTFile)(CXClientData client_data,
|
||||||
const CXIdxImportedASTFileInfo *);
|
const CXIdxImportedASTFileInfo *);
|
||||||
|
|
|
@ -2349,6 +2349,24 @@ static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
|
||||||
return (CXIdxClientFile)info->file;
|
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,
|
static CXIdxClientContainer index_startedTranslationUnit(CXClientData client_data,
|
||||||
void *reserved) {
|
void *reserved) {
|
||||||
IndexData *index_data;
|
IndexData *index_data;
|
||||||
|
@ -2479,7 +2497,7 @@ static IndexerCallbacks IndexCB = {
|
||||||
index_diagnostic,
|
index_diagnostic,
|
||||||
index_enteredMainFile,
|
index_enteredMainFile,
|
||||||
index_ppIncludedFile,
|
index_ppIncludedFile,
|
||||||
0, /*importedASTFile*/
|
index_importedASTFile,
|
||||||
index_startedTranslationUnit,
|
index_startedTranslationUnit,
|
||||||
index_indexDeclaration,
|
index_indexDeclaration,
|
||||||
index_indexEntityReference
|
index_indexEntityReference
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "IndexingContext.h"
|
#include "IndexingContext.h"
|
||||||
|
|
||||||
#include "clang/AST/DeclVisitor.h"
|
#include "clang/AST/DeclVisitor.h"
|
||||||
|
#include "clang/Basic/Module.h"
|
||||||
|
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
using namespace cxindex;
|
using namespace cxindex;
|
||||||
|
@ -305,6 +306,14 @@ public:
|
||||||
IndexCtx.indexTypeSourceInfo(D->getTemplatedDecl()->getTypeSourceInfo(), D);
|
IndexCtx.indexTypeSourceInfo(D->getTemplatedDecl()->getTypeSourceInfo(), D);
|
||||||
return true;
|
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
|
} // anonymous namespace
|
||||||
|
|
|
@ -73,6 +73,12 @@ public:
|
||||||
StringRef SearchPath,
|
StringRef SearchPath,
|
||||||
StringRef RelativePath,
|
StringRef RelativePath,
|
||||||
const Module *Imported) {
|
const Module *Imported) {
|
||||||
|
if (Imported) {
|
||||||
|
IndexCtx.importedModule(HashLoc, FileName, /*isIncludeDirective=*/true,
|
||||||
|
Imported);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool isImport = (IncludeTok.is(tok::identifier) &&
|
bool isImport = (IncludeTok.is(tok::identifier) &&
|
||||||
IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
|
IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
|
||||||
IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);
|
IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);
|
||||||
|
|
|
@ -253,6 +253,27 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
|
||||||
FileMap[File] = idxFile;
|
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() {
|
void IndexingContext::startedTranslationUnit() {
|
||||||
CXIdxClientContainer idxCont = 0;
|
CXIdxClientContainer idxCont = 0;
|
||||||
if (CB.startedTranslationUnit)
|
if (CB.startedTranslationUnit)
|
||||||
|
|
|
@ -382,6 +382,10 @@ public:
|
||||||
StringRef filename, const FileEntry *File,
|
StringRef filename, const FileEntry *File,
|
||||||
bool isImport, bool isAngled);
|
bool isImport, bool isAngled);
|
||||||
|
|
||||||
|
void importedModule(SourceLocation Loc,
|
||||||
|
StringRef name, bool isIncludeDirective,
|
||||||
|
const Module *module);
|
||||||
|
|
||||||
void startedTranslationUnit();
|
void startedTranslationUnit();
|
||||||
|
|
||||||
void indexDecl(const Decl *D);
|
void indexDecl(const Decl *D);
|
||||||
|
|
Loading…
Reference in New Issue