[cfe-commits] r67890 - in /cfe/trunk: include/clang/Sema/ParseAST.h lib/Sema/ParseAST.cpp tools/clang-cc/clang.cpp

Chris Lattner sabre at nondot.org
Fri Mar 27 18:37:18 PDT 2009


Author: lattner
Date: Fri Mar 27 20:37:17 2009
New Revision: 67890

URL: http://llvm.org/viewvc/llvm-project?rev=67890&view=rev
Log:
simplify ParseAST by sucking -disable-free handling logic up into
clang.cpp

Modified:
    cfe/trunk/include/clang/Sema/ParseAST.h
    cfe/trunk/lib/Sema/ParseAST.cpp
    cfe/trunk/tools/clang-cc/clang.cpp

Modified: cfe/trunk/include/clang/Sema/ParseAST.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParseAST.h?rev=67890&r1=67889&r2=67890&view=diff

==============================================================================
--- cfe/trunk/include/clang/Sema/ParseAST.h (original)
+++ cfe/trunk/include/clang/Sema/ParseAST.h Fri Mar 27 20:37:17 2009
@@ -20,14 +20,10 @@
   class TranslationUnit;
 
   /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
-  /// the file is parsed.
+  /// the file is parsed.  This inserts the parsed decls into TU.
   ///
-  /// \param TU If 0, then memory used for AST elements will be allocated only
-  /// for the duration of the ParseAST() call. In this case, the client should
-  /// not access any AST elements after ParseAST() returns.
   void ParseAST(Preprocessor &pp, ASTConsumer *C, 
-                TranslationUnit *TU = 0,
-                bool PrintStats = false);
+                TranslationUnit &TU, bool PrintStats = false);
 
 }  // end namespace clang
 

Modified: cfe/trunk/lib/Sema/ParseAST.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/ParseAST.cpp?rev=67890&r1=67889&r2=67890&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Fri Mar 27 20:37:17 2009
@@ -25,40 +25,24 @@
 //===----------------------------------------------------------------------===//
 
 /// ParseAST - Parse the entire file specified, notifying the ASTConsumer as
-/// the file is parsed.
+/// the file is parsed.  This inserts the parsed decls into TU.
 ///
-/// \param TU If 0, then memory used for AST elements will be allocated only
-/// for the duration of the ParseAST() call. In this case, the client should
-/// not access any AST elements after ParseAST() returns.
 void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer,
-                     TranslationUnit *TU, bool PrintStats) {
+                     TranslationUnit &TU, bool PrintStats) {
   // Collect global stats on Decls/Stmts (until we have a module streamer).
   if (PrintStats) {
     Decl::CollectingStats(true);
     Stmt::CollectingStats(true);
   }
 
-  llvm::OwningPtr<ASTContext> ContextOwner;
-  llvm::OwningPtr<TranslationUnit> TranslationUnitOwner;
-  if (TU == 0) {
-    ASTContext *Context = new ASTContext(PP.getLangOptions(),
-                                         PP.getSourceManager(),
-                                         PP.getTargetInfo(),
-                                         PP.getIdentifierTable(),
-                                         PP.getSelectorTable());
-    ContextOwner.reset(Context);
-    TU = new TranslationUnit(*Context);
-    TranslationUnitOwner.reset(TU);
-  }
-
-  Sema S(PP, TU->getContext(), *Consumer);
+  Sema S(PP, TU.getContext(), *Consumer);
   Parser P(PP, S);
   PP.EnterMainSourceFile();
     
   // Initialize the parser.
   P.Initialize();
   
-  Consumer->InitializeTU(*TU);
+  Consumer->InitializeTU(TU);
   
   Parser::DeclTy *ADecl;
   
@@ -72,12 +56,12 @@
     }
   };
   
-  Consumer->HandleTranslationUnit(*TU);
+  Consumer->HandleTranslationUnit(TU);
 
   if (PrintStats) {
     fprintf(stderr, "\nSTATISTICS:\n");
     P.getActions().PrintStats();
-    TU->getContext().PrintStats();
+    TU.getContext().PrintStats();
     Decl::PrintStats();
     Stmt::PrintStats();
     Consumer->PrintStats();

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

==============================================================================
--- cfe/trunk/tools/clang-cc/clang.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang.cpp Fri Mar 27 20:37:17 2009
@@ -1476,17 +1476,26 @@
   }
 
   if (Consumer) {
-    TranslationUnit *TU = 0;
+    llvm::OwningPtr<ASTContext> ContextOwner;
+    llvm::OwningPtr<TranslationUnit> TranslationUnitOwner;
+
+    ContextOwner.reset(new ASTContext(PP.getLangOptions(),
+                                      PP.getSourceManager(),
+                                      PP.getTargetInfo(),
+                                      PP.getIdentifierTable(),
+                                      PP.getSelectorTable(),
+                                      /* FreeMemory = */ !DisableFree));
+    TranslationUnitOwner.reset(new TranslationUnit(*ContextOwner.get()));
+    
+    
+    ParseAST(PP, Consumer.get(), *TranslationUnitOwner.get(), Stats);
+    
+    // If in -disable-free mode, don't deallocate these when they go out of
+    // scope.
     if (DisableFree) {
-      ASTContext *Context = new ASTContext(PP.getLangOptions(),
-                                           PP.getSourceManager(),
-                                           PP.getTargetInfo(),
-                                           PP.getIdentifierTable(),
-                                           PP.getSelectorTable(),
-                                           /* FreeMemory = */ false);
-      TU = new TranslationUnit(*Context);
+      ContextOwner.take();
+      TranslationUnitOwner.take();
     }
-    ParseAST(PP, Consumer.get(), TU, Stats);
   }
 
   if (VerifyDiagnostics)





More information about the cfe-commits mailing list