diff options
| author | Ilya Biryukov <ibiryukov@google.com> | 2019-07-18 15:43:26 +0000 |
|---|---|---|
| committer | Ilya Biryukov <ibiryukov@google.com> | 2019-07-18 15:43:26 +0000 |
| commit | abc744d2631fd8467c342a05c7c3bc83ad9de54f (patch) | |
| tree | f9909c5273e5abebd7c5e46b63ed2b1c9c23fffa /clang/lib/CrossTU/CrossTranslationUnit.cpp | |
| parent | 6acdf83cfa57503e1202bc5b5e5582c6c9cdacfa (diff) | |
| download | bcm5719-llvm-abc744d2631fd8467c342a05c7c3bc83ad9de54f.tar.gz bcm5719-llvm-abc744d2631fd8467c342a05c7c3bc83ad9de54f.zip | |
Revert r366449: [CrossTU] Add a function to retrieve original source location.
Reason: the commit breaks layering by adding a dependency on ASTUnit
(which is inside clangFrontend) from the ASTImporter (which is inside
clangAST).
llvm-svn: 366453
Diffstat (limited to 'clang/lib/CrossTU/CrossTranslationUnit.cpp')
| -rw-r--r-- | clang/lib/CrossTU/CrossTranslationUnit.cpp | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp index 1985d056440..977fd4b8dd3 100644 --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -295,7 +295,7 @@ llvm::Expected<const T *> CrossTranslationUnitContext::getCrossTUDefinitionImpl( TranslationUnitDecl *TU = Unit->getASTContext().getTranslationUnitDecl(); if (const T *ResultDecl = findDefInDeclContext<T>(TU, LookupName)) - return importDefinition(ResultDecl, Unit); + return importDefinition(ResultDecl); return llvm::make_error<IndexError>(index_error_code::failed_import); } @@ -411,13 +411,10 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST( template <typename T> llvm::Expected<const T *> -CrossTranslationUnitContext::importDefinitionImpl(const T *D, ASTUnit *Unit) { +CrossTranslationUnitContext::importDefinitionImpl(const T *D) { assert(hasBodyOrInit(D) && "Decls to be imported should have body or init."); - assert(&D->getASTContext() == &Unit->getASTContext() && - "ASTContext of Decl and the unit should match."); - ASTImporter &Importer = getOrCreateASTImporter(Unit); - + ASTImporter &Importer = getOrCreateASTImporter(D->getASTContext()); auto ToDeclOrError = Importer.Import(D); if (!ToDeclOrError) { handleAllErrors(ToDeclOrError.takeError(), @@ -444,15 +441,13 @@ CrossTranslationUnitContext::importDefinitionImpl(const T *D, ASTUnit *Unit) { } llvm::Expected<const FunctionDecl *> -CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD, - ASTUnit *Unit) { - return importDefinitionImpl(FD, Unit); +CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD) { + return importDefinitionImpl(FD); } llvm::Expected<const VarDecl *> -CrossTranslationUnitContext::importDefinition(const VarDecl *VD, - ASTUnit *Unit) { - return importDefinitionImpl(VD, Unit); +CrossTranslationUnitContext::importDefinition(const VarDecl *VD) { + return importDefinitionImpl(VD); } void CrossTranslationUnitContext::lazyInitImporterSharedSt( @@ -462,40 +457,17 @@ void CrossTranslationUnitContext::lazyInitImporterSharedSt( } ASTImporter & -CrossTranslationUnitContext::getOrCreateASTImporter(ASTUnit *Unit) { - ASTContext &From = Unit->getASTContext(); - +CrossTranslationUnitContext::getOrCreateASTImporter(ASTContext &From) { auto I = ASTUnitImporterMap.find(From.getTranslationUnitDecl()); if (I != ASTUnitImporterMap.end()) return *I->second; lazyInitImporterSharedSt(Context.getTranslationUnitDecl()); - ASTImporter *NewImporter = - new ASTImporter(Context, Context.getSourceManager().getFileManager(), - *Unit, false, ImporterSharedSt); + ASTImporter *NewImporter = new ASTImporter( + Context, Context.getSourceManager().getFileManager(), From, + From.getSourceManager().getFileManager(), false, ImporterSharedSt); ASTUnitImporterMap[From.getTranslationUnitDecl()].reset(NewImporter); return *NewImporter; } -llvm::Optional<std::pair<SourceLocation, ASTUnit *>> -CrossTranslationUnitContext::getImportedFromSourceLocation( - const clang::SourceLocation &ToLoc) const { - if (!ImporterSharedSt) - return {}; - - const SourceManager &SM = Context.getSourceManager(); - auto DecToLoc = SM.getDecomposedLoc(ToLoc); - - auto I = ImporterSharedSt->getImportedFileIDs().find(DecToLoc.first); - if (I == ImporterSharedSt->getImportedFileIDs().end()) - return {}; - - FileID FromID = I->second.first; - clang::ASTUnit *Unit = I->second.second; - SourceLocation FromLoc = - Unit->getSourceManager().getComposedLoc(FromID, DecToLoc.second); - - return std::make_pair(FromLoc, Unit); -} - } // namespace cross_tu } // namespace clang |

