[PATCH] D64748: Refactor threshold checking

Endre Fülöp via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 09:12:20 PDT 2019


gamesh411 updated this revision to Diff 209882.
gamesh411 added a comment.

Incremental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64748/new/

https://reviews.llvm.org/D64748

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp


Index: clang/lib/CrossTU/CrossTranslationUnit.cpp
===================================================================
--- clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -395,6 +395,18 @@
       ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts());
 }
 
+llvm::Expected<std::string>
+CrossTranslationUnitContext::getASTFileNameForLookup(
+    StringRef LookupName) const {
+  auto NameFileMapEntry = NameFileMap.find(LookupName);
+  if (NameFileMapEntry != NameFileMap.end()) {
+    return NameFileMapEntry->second;
+  } else {
+    ++NumNotInOtherTU;
+    return llvm::make_error<IndexError>(index_error_code::missing_definition);
+  }
+}
+
 llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST(
     StringRef LookupName, StringRef CrossTUDir, StringRef IndexName,
     bool DisplayCTUProgress) {
@@ -418,21 +430,19 @@
   if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName))
     return std::move(InitFailed);
 
-  auto It = NameFileMap.find(LookupName);
-  if (It == NameFileMap.end()) {
-    ++NumNotInOtherTU;
-    return llvm::make_error<IndexError>(index_error_code::missing_definition);
-  }
-  StringRef ASTFileName = It->second;
-  auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName);
+  llvm::Expected<std::string> ASTFileName = getASTFileNameForLookup(LookupName);
+  if (!ASTFileName)
+    return ASTFileName.takeError();
+
+  auto ASTCacheEntry = FileASTUnitMap.find(*ASTFileName);
   if (ASTCacheEntry == FileASTUnitMap.end()) {
     // Load the ASTUnit from the pre-dumped AST file specified by ASTFileName.
-    std::unique_ptr<ASTUnit> LoadedUnit = loadFromASTFile(ASTFileName);
+  std::unique_ptr<ASTUnit> LoadedUnit = loadFromASTFile(*ASTFileName);
     Unit = LoadedUnit.get();
-    FileASTUnitMap[ASTFileName] = std::move(LoadedUnit);
+    FileASTUnitMap[*ASTFileName] = std::move(LoadedUnit);
     ++NumASTLoaded;
     if (DisplayCTUProgress) {
-      llvm::errs() << "CTU loaded AST file: " << ASTFileName << "\n";
+      llvm::errs() << "CTU loaded AST file: " << *ASTFileName << "\n";
     }
   } else {
     Unit = ASTCacheEntry->second.get();
Index: clang/include/clang/CrossTU/CrossTranslationUnit.h
===================================================================
--- clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -167,6 +167,9 @@
   llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName);
   ASTUnit *getCachedASTUnitForName(StringRef LookupName) const;
   std::unique_ptr<ASTUnit> loadFromASTFile(StringRef ASTFileName) const;
+  llvm::Expected<std::string>
+  getASTFileNameForLookup(StringRef LookupName) const;
+
   void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU);
   ASTImporter &getOrCreateASTImporter(ASTContext &From);
   template <typename T>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64748.209882.patch
Type: text/x-patch
Size: 2860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190715/44cddc1d/attachment-0001.bin>


More information about the cfe-commits mailing list