[cfe-commits] r142004 - in /cfe/trunk: include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Oct 14 14:22:05 PDT 2011


Author: akirtzidis
Date: Fri Oct 14 16:22:05 2011
New Revision: 142004

URL: http://llvm.org/viewvc/llvm-project?rev=142004&view=rev
Log:
Allow calling ASTUnit::LoadFromCompilerInvocationAction with a previously created ASTUnit.

Modified:
    cfe/trunk/include/clang/Frontend/ASTUnit.h
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=142004&r1=142003&r2=142004&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Fri Oct 14 16:22:05 2011
@@ -450,6 +450,8 @@
   const ASTContext &getASTContext() const { return *Ctx; }
         ASTContext &getASTContext()       { return *Ctx; }
 
+  void setASTContext(ASTContext *ctx) { Ctx = ctx; }
+
   bool hasSema() const { return TheSema; }
   Sema &getSema() const { 
     assert(TheSema && "ASTUnit does not have a Sema object!");
@@ -641,9 +643,13 @@
   ///
   /// \param Action - The ASTFrontendAction to invoke. Its ownership is not
   /// transfered.
+  ///
+  /// \param Unit - optionally an already created ASTUnit. Its ownership is not
+  /// transfered.
   static ASTUnit *LoadFromCompilerInvocationAction(CompilerInvocation *CI,
                               llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
-                                             ASTFrontendAction *Action = 0);
+                                             ASTFrontendAction *Action = 0,
+                                             ASTUnit *Unit = 0);
 
   /// LoadFromCompilerInvocation - Create an ASTUnit from a source file, via a
   /// CompilerInvocation object.

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=142004&r1=142003&r2=142004&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Oct 14 16:22:05 2011
@@ -1511,30 +1511,33 @@
   AST->Invocation = CI;
   AST->FileSystemOpts = CI->getFileSystemOpts();
   AST->FileMgr = new FileManager(AST->FileSystemOpts);
-  AST->SourceMgr = new SourceManager(*Diags, *AST->FileMgr);
+  AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr);
 
   return AST.take();
 }
 
 ASTUnit *ASTUnit::LoadFromCompilerInvocationAction(CompilerInvocation *CI,
                               llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags,
-                                             ASTFrontendAction *Action) {
+                                             ASTFrontendAction *Action,
+                                             ASTUnit *Unit) {
   assert(CI && "A CompilerInvocation is required");
 
-  // Create the AST unit.
-  llvm::OwningPtr<ASTUnit> AST;
-  AST.reset(new ASTUnit(false));
-  ConfigureDiags(Diags, 0, 0, *AST, /*CaptureDiagnostics*/false);
-  AST->Diagnostics = Diags;
+  llvm::OwningPtr<ASTUnit> OwnAST;
+  ASTUnit *AST = Unit;
+  if (!AST) {
+    // Create the AST unit.
+    OwnAST.reset(create(CI, Diags));
+    AST = OwnAST.get();
+  }
+  
   AST->OnlyLocalDecls = false;
   AST->CaptureDiagnostics = false;
   AST->TUKind = Action ? Action->getTranslationUnitKind() : TU_Complete;
   AST->ShouldCacheCodeCompletionResults = false;
-  AST->Invocation = CI;
 
   // Recover resources if we crash before exiting this method.
   llvm::CrashRecoveryContextCleanupRegistrar<ASTUnit>
-    ASTUnitCleanup(AST.get());
+    ASTUnitCleanup(OwnAST.get());
   llvm::CrashRecoveryContextCleanupRegistrar<DiagnosticsEngine,
     llvm::CrashRecoveryContextReleaseRefCleanup<DiagnosticsEngine> >
     DiagCleanup(Diags.getPtr());
@@ -1582,9 +1585,6 @@
          "IR inputs not supported here!");
 
   // Configure the various subsystems.
-  AST->FileSystemOpts = Clang->getFileSystemOpts();
-  AST->FileMgr = new FileManager(AST->FileSystemOpts);
-  AST->SourceMgr = new SourceManager(AST->getDiagnostics(), *AST->FileMgr);
   AST->TheSema.reset();
   AST->Ctx = 0;
   AST->PP = 0;
@@ -1625,7 +1625,10 @@
   
   Act->EndSourceFile();
 
-  return AST.take();
+  if (OwnAST)
+    return OwnAST.take();
+  else
+    return AST;
 }
 
 bool ASTUnit::LoadFromCompilerInvocation(bool PrecompilePreamble) {





More information about the cfe-commits mailing list