Removed storing inode and device number in TranslationUnit.

Added "SourceFile" string to TranslationUnit to record corresponding
source file.

Updated serialization of TranslationUnits and logic in the driver to
correctly pass the source file information to the serializer.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45211 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 8afd718..dc435f9 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -39,6 +39,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/System/Signals.h"
 #include "llvm/Config/config.h"
+#include "llvm/ADT/scoped_ptr.h"
 #include <memory>
 using namespace clang;
 
@@ -887,7 +888,7 @@
 /// CreateASTConsumer - Create the ASTConsumer for the corresponding program
 ///  action.  These consumers can operate on both ASTs that are freshly
 ///  parsed from source files as well as those deserialized from Bitcode.
-static ASTConsumer* CreateASTConsumer(const std::string& InFile,
+static ASTConsumer* CreateASTConsumer(const std::string& SourceFile,
                                       Diagnostic& Diag, FileManager& FileMgr, 
                                       const LangOptions& LangOpts) {
   switch (ProgAction) {
@@ -917,14 +918,14 @@
       return CreateUnitValsChecker(Diag);
       
     case TestSerialization:
-      return CreateSerializationTest(Diag, FileMgr, LangOpts);
+      return CreateSerializationTest(SourceFile, Diag, FileMgr, LangOpts);
       
     case EmitLLVM:
       return CreateLLVMEmitter(Diag, LangOpts);
       
     case SerializeAST:
       // FIXME: Allow user to tailor where the file is written.
-      return CreateASTSerializer(InFile, Diag, LangOpts);
+      return CreateASTSerializer(SourceFile, Diag, LangOpts);
       
     case RewriteTest:
       return CreateCodeRewriterTest(Diag);
@@ -934,7 +935,7 @@
 /// ProcessInputFile - Process a single input file with the specified state.
 ///
 static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID,
-                             const std::string &InFile,
+                             const std::string &SourceFile,
                              TextDiagnostics &OurDiagnosticClient) {
 
   ASTConsumer* Consumer = NULL;
@@ -942,7 +943,7 @@
   
   switch (ProgAction) {
   default:
-    Consumer = CreateASTConsumer(InFile, PP.getDiagnostics(),
+    Consumer = CreateASTConsumer(SourceFile, PP.getDiagnostics(),
                                  PP.getFileManager(),
                                  PP.getLangOptions());
     
@@ -1005,7 +1006,7 @@
   }
   
   if (Stats) {
-    fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
+    fprintf(stderr, "\nSTATISTICS FOR '%s':\n", SourceFile.c_str());
     PP.PrintStats();
     PP.getIdentifierTable().PrintStats();
     PP.getHeaderSearchInfo().PrintStats();
@@ -1036,7 +1037,7 @@
     exit (1);
   }
   
-  TranslationUnit* TU = ReadASTBitcodeFile(Filename,FileMgr);
+  llvm::scoped_ptr<TranslationUnit> TU(ReadASTBitcodeFile(Filename,FileMgr));
   
   if (!TU) {
     fprintf(stderr, "error: file '%s' could not be deserialized\n", 
@@ -1044,8 +1045,11 @@
     exit (1);
   }
   
-  ASTConsumer* Consumer = CreateASTConsumer(InFile,Diag,
-                                            FileMgr,TU->getLangOpts());
+  // Observe that we use the source file name stored in the deserialized
+  // translation unit, rather than InFile.
+  llvm::scoped_ptr<ASTConsumer>
+    Consumer(CreateASTConsumer(TU->getSourceFile(), Diag, FileMgr,
+                               TU->getLangOpts()));
   
   if (!Consumer) {      
     fprintf(stderr, "Unsupported program action with serialized ASTs!\n");
@@ -1053,12 +1057,10 @@
   }
   
   // FIXME: only work on consumers that do not require MainFileID.
-  Consumer->Initialize(*TU->getContext(),0);
+  Consumer->Initialize(*TU->getContext(), 0);
   
   for (TranslationUnit::iterator I=TU->begin(), E=TU->end(); I!=E; ++I)
     Consumer->HandleTopLevelDecl(*I);
-
-  delete Consumer;
 }