From cc026ebf32de97bc685ded159dd9a2aa8710eaa3 Mon Sep 17 00:00:00 2001 From: Sam McCall Date: Mon, 9 Apr 2018 14:12:51 +0000 Subject: [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 --- clang/lib/Index/IndexingContext.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'clang/lib/Index/IndexingContext.cpp') 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); } -- cgit v1.2.3