diff options
author | Sam McCall <sam.mccall@gmail.com> | 2018-04-09 14:12:51 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2018-04-09 14:12:51 +0000 |
commit | cc026ebf32de97bc685ded159dd9a2aa8710eaa3 (patch) | |
tree | 6278c508f7360ac56c3f89eb853d9806c9c3a64b /clang/lib/Index/IndexingContext.cpp | |
parent | 6400c03e6a7aff8e7c8c41d31c6c1d123d48aa5b (diff) | |
download | bcm5719-llvm-cc026ebf32de97bc685ded159dd9a2aa8710eaa3.tar.gz bcm5719-llvm-cc026ebf32de97bc685ded159dd9a2aa8710eaa3.zip |
[Index] Return SourceLocation to consumers, not FileID/Offset pair.
Summary:
The FileID/Offset conversion is lossy. The code takes the fileLoc, which loses
e.g. the spelling location in some macro cases.
Instead, pass the original SourceLocation which preserves all information, and
update consumers to match current behavior.
This allows us to fix two bugs in clangd that need the spelling location.
Reviewers: akyrtzi, arphaman
Subscribers: ilya-biryukov, ioeric, cfe-commits
Differential Revision: https://reviews.llvm.org/D45014
llvm-svn: 329570
Diffstat (limited to 'clang/lib/Index/IndexingContext.cpp')
-rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index de9fe39df03..97b3e10450d 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -82,14 +82,9 @@ bool IndexingContext::importedModule(const ImportDecl *ImportD) { Loc = IdLocs.front(); else Loc = ImportD->getLocation(); - SourceManager &SM = Ctx->getSourceManager(); - Loc = SM.getFileLoc(Loc); - if (Loc.isInvalid()) - return true; - FileID FID; - unsigned Offset; - std::tie(FID, Offset) = SM.getDecomposedLoc(Loc); + SourceManager &SM = Ctx->getSourceManager(); + FileID FID = SM.getFileID(SM.getFileLoc(Loc)); if (FID.isInvalid()) return true; @@ -112,7 +107,7 @@ bool IndexingContext::importedModule(const ImportDecl *ImportD) { if (ImportD->isImplicit()) Roles |= (unsigned)SymbolRole::Implicit; - return DataConsumer.handleModuleOccurence(ImportD, Roles, FID, Offset); + return DataConsumer.handleModuleOccurence(ImportD, Roles, Loc); } bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) { @@ -327,13 +322,7 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, return true; SourceManager &SM = Ctx->getSourceManager(); - Loc = SM.getFileLoc(Loc); - if (Loc.isInvalid()) - return true; - - FileID FID; - unsigned Offset; - std::tie(FID, Offset) = SM.getDecomposedLoc(Loc); + FileID FID = SM.getFileID(SM.getFileLoc(Loc)); if (FID.isInvalid()) return true; @@ -414,7 +403,6 @@ bool IndexingContext::handleDeclOccurrence(const Decl *D, SourceLocation Loc, Rel.RelatedSymbol->getCanonicalDecl())); } - IndexDataConsumer::ASTNodeInfo Node{ OrigE, OrigD, Parent, ContainerDC }; - return DataConsumer.handleDeclOccurence(D, Roles, FinalRelations, FID, Offset, - Node); + IndexDataConsumer::ASTNodeInfo Node{OrigE, OrigD, Parent, ContainerDC}; + return DataConsumer.handleDeclOccurence(D, Roles, FinalRelations, Loc, Node); } |