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/Index/IndexingContext.cpp | |
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/Index/IndexingContext.cpp')
-rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
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) { |