|
@@ -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
|