summaryrefslogtreecommitdiffstats
path: root/lib/CrossTU/CrossTranslationUnit.cpp
diff options
context:
space:
mode:
authorJordan Rupprecht <rupprecht@google.com>2019-01-18 19:46:00 +0000
committerJordan Rupprecht <rupprecht@google.com>2019-01-18 19:46:00 +0000
commit3748d41833787fcbf59cc5624e8d2b042a8991bc (patch)
treef3fcdba7decca7ee845a1bb3f885cb0baa1b4d83 /lib/CrossTU/CrossTranslationUnit.cpp
parent55c8788102d8fd203270fabd6513247b2d7fbd87 (diff)
parente054eb577a1f469b1a4a49fce08572c76e2dddf2 (diff)
Creating branches/google/stable and tags/google/stable/2019-01-18 from r351319
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/google/stable@351578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CrossTU/CrossTranslationUnit.cpp')
-rw-r--r--lib/CrossTU/CrossTranslationUnit.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/lib/CrossTU/CrossTranslationUnit.cpp b/lib/CrossTU/CrossTranslationUnit.cpp
index 5286b90f93..7c97beb498 100644
--- a/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/lib/CrossTU/CrossTranslationUnit.cpp
@@ -120,26 +120,26 @@ std::error_code IndexError::convertToErrorCode() const {
llvm::Expected<llvm::StringMap<std::string>>
parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir) {
- std::ifstream ExternalFnMapFile(IndexPath);
- if (!ExternalFnMapFile)
+ std::ifstream ExternalMapFile(IndexPath);
+ if (!ExternalMapFile)
return llvm::make_error<IndexError>(index_error_code::missing_index_file,
IndexPath.str());
llvm::StringMap<std::string> Result;
std::string Line;
unsigned LineNo = 1;
- while (std::getline(ExternalFnMapFile, Line)) {
+ while (std::getline(ExternalMapFile, Line)) {
const size_t Pos = Line.find(" ");
if (Pos > 0 && Pos != std::string::npos) {
StringRef LineRef{Line};
- StringRef FunctionLookupName = LineRef.substr(0, Pos);
- if (Result.count(FunctionLookupName))
+ StringRef LookupName = LineRef.substr(0, Pos);
+ if (Result.count(LookupName))
return llvm::make_error<IndexError>(
index_error_code::multiple_definitions, IndexPath.str(), LineNo);
StringRef FileName = LineRef.substr(Pos + 1);
SmallString<256> FilePath = CrossTUDir;
llvm::sys::path::append(FilePath, FileName);
- Result[FunctionLookupName] = FilePath.str().str();
+ Result[LookupName] = FilePath.str().str();
} else
return llvm::make_error<IndexError>(
index_error_code::invalid_index_format, IndexPath.str(), LineNo);
@@ -208,9 +208,6 @@ CrossTranslationUnitContext::getCrossTUDefinition(const FunctionDecl *FD,
if (!ASTUnitOrError)
return ASTUnitOrError.takeError();
ASTUnit *Unit = *ASTUnitOrError;
- if (!Unit)
- return llvm::make_error<IndexError>(
- index_error_code::failed_to_get_external_ast);
assert(&Unit->getFileManager() ==
&Unit->getASTContext().getSourceManager().getFileManager());
@@ -253,7 +250,7 @@ void CrossTranslationUnitContext::emitCrossTUDiagnostics(const IndexError &IE) {
<< IE.getFileName();
break;
case index_error_code::invalid_index_format:
- Context.getDiagnostics().Report(diag::err_fnmap_parsing)
+ Context.getDiagnostics().Report(diag::err_extdefmap_parsing)
<< IE.getFileName() << IE.getLineNum();
break;
case index_error_code::multiple_definitions:
@@ -324,6 +321,9 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST(
} else {
Unit = FnUnitCacheEntry->second;
}
+ if (!Unit)
+ return llvm::make_error<IndexError>(
+ index_error_code::failed_to_get_external_ast);
return Unit;
}
@@ -342,14 +342,21 @@ CrossTranslationUnitContext::importDefinition(const FunctionDecl *FD) {
return ToDecl;
}
+void CrossTranslationUnitContext::lazyInitLookupTable(
+ TranslationUnitDecl *ToTU) {
+ if (!LookupTable)
+ LookupTable = llvm::make_unique<ASTImporterLookupTable>(*ToTU);
+}
+
ASTImporter &
CrossTranslationUnitContext::getOrCreateASTImporter(ASTContext &From) {
auto I = ASTUnitImporterMap.find(From.getTranslationUnitDecl());
if (I != ASTUnitImporterMap.end())
return *I->second;
- ASTImporter *NewImporter =
- new ASTImporter(Context, Context.getSourceManager().getFileManager(),
- From, From.getSourceManager().getFileManager(), false);
+ lazyInitLookupTable(Context.getTranslationUnitDecl());
+ ASTImporter *NewImporter = new ASTImporter(
+ Context, Context.getSourceManager().getFileManager(), From,
+ From.getSourceManager().getFileManager(), false, LookupTable.get());
ASTUnitImporterMap[From.getTranslationUnitDecl()].reset(NewImporter);
return *NewImporter;
}