[cfe-commits] r87079 - in /cfe/trunk: include/clang/Frontend/CompilerInstance.h lib/Frontend/CompilerInstance.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Thu Nov 12 20:12:08 PST 2009


Author: ddunbar
Date: Thu Nov 12 22:12:06 2009
New Revision: 87079

URL: http://llvm.org/viewvc/llvm-project?rev=87079&view=rev
Log:
Add {File,Source}Manager to CompilerInstance.

Modified:
    cfe/trunk/include/clang/Frontend/CompilerInstance.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=87079&r1=87078&r2=87079&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Thu Nov 12 22:12:06 2009
@@ -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

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=87079&r1=87078&r2=87079&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Nov 12 22:12:06 2009
@@ -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());
+}

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=87079&r1=87078&r2=87079&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Thu Nov 12 22:12:06 2009
@@ -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");
   }
 





More information about the cfe-commits mailing list