diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2018-09-18 15:02:56 +0000 |
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2018-09-18 15:02:56 +0000 |
| commit | 32e5d8626d006337416ae4a4190bd498e8a5478a (patch) | |
| tree | 4b582e1928277a1f749a0fe27d0eecec752d4309 /clang/lib | |
| parent | 9f9cdd41ccb90ed75fa8903307214f16e56ed51a (diff) | |
| download | bcm5719-llvm-32e5d8626d006337416ae4a4190bd498e8a5478a.tar.gz bcm5719-llvm-32e5d8626d006337416ae4a4190bd498e8a5478a.zip | |
[index] Enhance indexing for module references
* Create a USR for the occurrences of the 'module' symbol kind
* Record module references for each identifier in an import declaration
llvm-svn: 342484
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Index/IndexingAction.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 26 | ||||
| -rw-r--r-- | clang/lib/Index/USRGeneration.cpp | 26 |
3 files changed, 51 insertions, 2 deletions
diff --git a/clang/lib/Index/IndexingAction.cpp b/clang/lib/Index/IndexingAction.cpp index cb5c951f38a..5cdec4b4528 100644 --- a/clang/lib/Index/IndexingAction.cpp +++ b/clang/lib/Index/IndexingAction.cpp @@ -37,6 +37,7 @@ bool IndexDataConsumer::handleMacroOccurence(const IdentifierInfo *Name, } bool IndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD, + const Module *Mod, SymbolRoleSet Roles, SourceLocation Loc) { return true; diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index 333f9dc3091..bba6c8390b5 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -80,11 +80,27 @@ bool IndexingContext::handleReference(const NamedDecl *D, SourceLocation Loc, RefE, RefD, DC); } +static void reportModuleReferences(const Module *Mod, + ArrayRef<SourceLocation> IdLocs, + const ImportDecl *ImportD, + IndexDataConsumer &DataConsumer) { + if (!Mod) + return; + reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD, + DataConsumer); + DataConsumer.handleModuleOccurence(ImportD, Mod, + (SymbolRoleSet)SymbolRole::Reference, + IdLocs.back()); +} + bool IndexingContext::importedModule(const ImportDecl *ImportD) { + if (ImportD->isInvalidDecl()) + return true; + SourceLocation Loc; auto IdLocs = ImportD->getIdentifierLocs(); if (!IdLocs.empty()) - Loc = IdLocs.front(); + Loc = IdLocs.back(); else Loc = ImportD->getLocation(); @@ -108,11 +124,17 @@ bool IndexingContext::importedModule(const ImportDecl *ImportD) { } } + const Module *Mod = ImportD->getImportedModule(); + if (!ImportD->isImplicit() && Mod->Parent && !IdLocs.empty()) { + reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD, + DataConsumer); + } + SymbolRoleSet Roles = (unsigned)SymbolRole::Declaration; if (ImportD->isImplicit()) Roles |= (unsigned)SymbolRole::Implicit; - return DataConsumer.handleModuleOccurence(ImportD, Roles, Loc); + return DataConsumer.handleModuleOccurence(ImportD, Mod, Roles, Loc); } bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) { diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index 62ae7108fc6..8194c9508fb 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -1094,3 +1094,29 @@ bool clang::index::generateUSRForMacro(StringRef MacroName, SourceLocation Loc, Out << MacroName; return false; } + +bool clang::index::generateFullUSRForModule(const Module *Mod, + raw_ostream &OS) { + if (!Mod->Parent) + return generateFullUSRForTopLevelModuleName(Mod->Name, OS); + if (generateFullUSRForModule(Mod->Parent, OS)) + return true; + return generateUSRFragmentForModule(Mod, OS); +} + +bool clang::index::generateFullUSRForTopLevelModuleName(StringRef ModName, + raw_ostream &OS) { + OS << getUSRSpacePrefix(); + return generateUSRFragmentForModuleName(ModName, OS); +} + +bool clang::index::generateUSRFragmentForModule(const Module *Mod, + raw_ostream &OS) { + return generateUSRFragmentForModuleName(Mod->Name, OS); +} + +bool clang::index::generateUSRFragmentForModuleName(StringRef ModName, + raw_ostream &OS) { + OS << "@M@" << ModName; + return false; +} |

