]> granicus.if.org Git - clang/commitdiff
ASTUnit: simplify remapping files by using the exact same logic in Preprocessor
authorDmitri Gribenko <gribozavr@gmail.com>
Mon, 10 Feb 2014 12:31:34 +0000 (12:31 +0000)
committerDmitri Gribenko <gribozavr@gmail.com>
Mon, 10 Feb 2014 12:31:34 +0000 (12:31 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201082 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/ASTUnit.cpp

index 37838ea46fa532725af2db4d02bfca83aa45492a..dd08282252fb057de79ecdf384722c0b0b18a677 100644 (file)
@@ -711,22 +711,10 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
                                          AST->ASTFileLangOpts,
                                          /*Target=*/0));
 
-  for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) {
-    const llvm::MemoryBuffer *MemBuf = RemappedFiles[I].second;
-    // Create the file entry for the file that we're mapping from.
-    const FileEntry *FromFile = AST->getFileManager().getVirtualFile(
-        RemappedFiles[I].first, MemBuf->getBufferSize(), 0);
-    if (!FromFile) {
-      AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file)
-          << RemappedFiles[I].first;
-      delete MemBuf;
-      continue;
-    }
+  PreprocessorOptions *PPOpts = new PreprocessorOptions();
 
-    // Override the contents of the "from" file with the contents of
-    // the "to" file.
-    AST->getSourceManager().overrideFileContents(FromFile, MemBuf);
-  }
+  for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I)
+    PPOpts->addRemappedFile(RemappedFiles[I].first, RemappedFiles[I].second);
 
   // Gather Info for preprocessor construction later on.
 
@@ -735,7 +723,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
 
   OwningPtr<ASTReader> Reader;
 
-  AST->PP = new Preprocessor(new PreprocessorOptions(),
+  AST->PP = new Preprocessor(PPOpts,
                              AST->getDiagnostics(), AST->ASTFileLangOpts,
                              /*Target=*/0, AST->getSourceManager(), HeaderInfo, 
                              *AST,