Add {File,Source}Manager to CompilerInstance.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@87079 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h
index c503d7a..fb52383 100644
--- a/include/clang/Frontend/CompilerInstance.h
+++ b/include/clang/Frontend/CompilerInstance.h
@@ -20,6 +20,8 @@
 namespace clang {
 class Diagnostic;
 class DiagnosticClient;
+class FileManager;
+class SourceManager;
 class TargetInfo;
 
 /// CompilerInstance - Helper class for managing a single instance of the Clang
@@ -57,6 +59,12 @@
   /// The target being compiled for.
   llvm::OwningPtr<TargetInfo> Target;
 
+  /// The file manager.
+  llvm::OwningPtr<FileManager> FileMgr;
+
+  /// The source manager.
+  llvm::OwningPtr<SourceManager> SourceMgr;
+
 public:
   /// Create a new compiler instance with the given LLVM context, optionally
   /// taking ownership of it.
@@ -192,6 +200,44 @@
   void setTarget(TargetInfo *Value) { Target.reset(Value); }
 
   /// }
+  /// @name File Manager
+  /// {
+
+  FileManager &getFileManager() const { return *FileMgr; }
+
+  /// takeFileManager - Remove the current file manager and give ownership to
+  /// the caller.
+  FileManager *takeFileManager() { return FileMgr.take(); }
+
+  /// setFileManager - Replace the current file manager; the compiler instance
+  /// takes ownership of \arg Value.
+  void setFileManager(FileManager *Value) { FileMgr.reset(Value); }
+
+  /// }
+  /// @name Source Manager
+  /// {
+
+  SourceManager &getSourceManager() const { return *SourceMgr; }
+
+  /// takeSourceManager - Remove the current source manager and give ownership
+  /// to the caller.
+  SourceManager *takeSourceManager() { return SourceMgr.take(); }
+
+  /// setSourceManager - Replace the current source manager; the compiler
+  /// instance takes ownership of \arg Value.
+  void setSourceManager(SourceManager *Value) { SourceMgr.reset(Value); }
+
+  /// }
+  /// @name Construction Utility Methods
+  /// {
+
+  /// Create the file manager and replace any existing one with it.
+  void createFileManager();
+
+  /// Create the source manager and replace any existing one with it.
+  void createSourceManager();
+
+  /// }
 };
 
 } // end namespace clang
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp
index e791f24..2d1f498 100644
--- a/lib/Frontend/CompilerInstance.cpp
+++ b/lib/Frontend/CompilerInstance.cpp
@@ -9,6 +9,8 @@
 
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/LLVMContext.h"
 using namespace clang;
@@ -23,3 +25,11 @@
   if (OwnsLLVMContext)
     delete LLVMContext;
 }
+
+void CompilerInstance::createFileManager() {
+  FileMgr.reset(new FileManager());
+}
+
+void CompilerInstance::createSourceManager() {
+  SourceMgr.reset(new SourceManager());
+}
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 3f3cd6e..6c8d78e 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -762,8 +762,7 @@
 /// ProcessInputFile - Process a single AST input file with the specified state.
 ///
 static void ProcessASTInputFile(CompilerInstance &CI, const std::string &InFile,
-                                ProgActions PA, FileManager &FileMgr) {
-  const FrontendOptions &FEOpts = CI.getFrontendOpts();
+                                ProgActions PA) {
   std::string Error;
   llvm::OwningPtr<ASTUnit> AST(ASTUnit::LoadFromPCHFile(InFile, &Error));
   if (!AST) {
@@ -793,12 +792,13 @@
 
   // Stream the input AST to the consumer.
   CI.getDiagnostics().getClient()->BeginSourceFile(PP.getLangOptions());
-  ParseAST(PP, Consumer.get(), AST->getASTContext(), FEOpts.ShowStats);
+  ParseAST(PP, Consumer.get(), AST->getASTContext(),
+           CI.getFrontendOpts().ShowStats);
   CI.getDiagnostics().getClient()->EndSourceFile();
 
   // Release the consumer and the AST, in that order since the consumer may
   // perform actions in its destructor which require the context.
-  if (FEOpts.DisableFree) {
+  if (CI.getFrontendOpts().DisableFree) {
     Consumer.take();
     AST.take();
   } else {
@@ -988,23 +988,23 @@
     ProgAction = InheritanceView;
 
   // Create the source manager.
-  SourceManager SourceMgr;
+  Clang.createSourceManager();
 
   // Create a file manager object to provide access to and cache the filesystem.
-  FileManager FileMgr;
+  Clang.createFileManager();
 
   for (unsigned i = 0, e = Clang.getFrontendOpts().Inputs.size(); i != e; ++i) {
     const std::string &InFile = Clang.getFrontendOpts().Inputs[i].second;
 
     // AST inputs are handled specially.
     if (IsAST) {
-      ProcessASTInputFile(Clang, InFile, ProgAction, FileMgr);
+      ProcessASTInputFile(Clang, InFile, ProgAction);
       continue;
     }
 
     // Reset the ID tables if we are reusing the SourceManager.
     if (i)
-      SourceMgr.clearIDTables();
+      Clang.getSourceManager().clearIDTables();
 
     // Set up the preprocessor with these options.
     llvm::OwningPtr<Preprocessor>
@@ -1012,7 +1012,8 @@
                             Clang.getPreprocessorOpts(),
                             Clang.getHeaderSearchOpts(),
                             Clang.getDependencyOutputOpts(),
-                            Clang.getTarget(), SourceMgr, FileMgr));
+                            Clang.getTarget(), Clang.getSourceManager(),
+                            Clang.getFileManager()));
 
     // Process the source file.
     Clang.getDiagnostics().getClient()->BeginSourceFile(Clang.getLangOpts());
@@ -1026,7 +1027,7 @@
               (NumDiagnostics == 1 ? "" : "s"));
 
   if (Clang.getFrontendOpts().ShowStats) {
-    FileMgr.PrintStats();
+    Clang.getFileManager().PrintStats();
     fprintf(stderr, "\n");
   }