[cfe-commits] r51825 - in /cfe/trunk: Driver/ASTConsumers.cpp Driver/RewriteObjC.cpp include/clang/AST/ASTConsumer.h lib/AST/ASTConsumer.cpp lib/Sema/ParseAST.cpp

Ted Kremenek kremenek at apple.com
Sat May 31 13:11:04 PDT 2008


Author: kremenek
Date: Sat May 31 15:11:04 2008
New Revision: 51825

URL: http://llvm.org/viewvc/llvm-project?rev=51825&view=rev
Log:
Added "InitializeTU" to ASTConsumer. This is used by Sema::ParseAST to pass a
TranslationUnit object instead of an ASTContext. By default it calls
Initialize(ASTConstext& Context) (to match with the current interface used by
most ASTConsumers).

Modified the ObjC-Rewriter to use InitializeTU, and to tell the TranslationUnit
to not free its Decls.  This is a workaround for: <rdar://problem/5966749>

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/include/clang/AST/ASTConsumer.h
    cfe/trunk/lib/AST/ASTConsumer.cpp
    cfe/trunk/lib/Sema/ParseAST.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=51825&r1=51824&r2=51825&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sat May 31 15:11:04 2008
@@ -877,9 +877,8 @@
     
   virtual ~ASTSerializer() { delete TU; }
   
-  virtual void Initialize(ASTContext &Context) {
-    if (!TU) TU = new TranslationUnit(Context, lang);
-    TU->SetOwnsDecls(false);
+  virtual void InitializeTU(TranslationUnit &TU) {
+    TU.SetOwnsDecls(false);
   }
   
   virtual void HandleTopLevelDecl(Decl *D) {

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=51825&r1=51824&r2=51825&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Sat May 31 15:11:04 2008
@@ -15,6 +15,7 @@
 #include "clang/Rewrite/Rewriter.h"
 #include "clang/AST/AST.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/AST/TranslationUnit.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/Diagnostic.h"
@@ -94,7 +95,12 @@
     
     static const int OBJC_ABI_VERSION =7 ;
   public:
-    void Initialize(ASTContext &context);
+    virtual void Initialize(ASTContext &context);
+
+    virtual void InitializeTU(TranslationUnit &TU) {
+      TU.SetOwnsDecls(false);
+      Initialize(TU.getContext());
+    }
     
 
     // Top Level Driver code.

Modified: cfe/trunk/include/clang/AST/ASTConsumer.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTConsumer.h?rev=51825&r1=51824&r2=51825&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTConsumer.h (original)
+++ cfe/trunk/include/clang/AST/ASTConsumer.h Sat May 31 15:11:04 2008
@@ -16,6 +16,7 @@
 
 namespace clang {
   class ASTContext;
+  class TranslationUnit;
   class Decl;
   class TagDecl;
   class HandleTagDeclDefinition;
@@ -31,6 +32,8 @@
   /// ASTContext.
   virtual void Initialize(ASTContext &Context) {}
   
+  virtual void InitializeTU(TranslationUnit& TU);
+  
   /// HandleTopLevelDecl - Handle the specified top-level declaration.  This is
   ///  called by HandleTopLevelDeclaration to process every top-level Decl*.
   virtual void HandleTopLevelDecl(Decl *D) {}

Modified: cfe/trunk/lib/AST/ASTConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTConsumer.cpp?rev=51825&r1=51824&r2=51825&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTConsumer.cpp (original)
+++ cfe/trunk/lib/AST/ASTConsumer.cpp Sat May 31 15:11:04 2008
@@ -13,6 +13,8 @@
 
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/TranslationUnit.h"
+
 using namespace clang;
 
 ASTConsumer::~ASTConsumer() {}
@@ -26,3 +28,7 @@
   else
     HandleTopLevelDecl(d);
 }
+
+void ASTConsumer::InitializeTU(TranslationUnit& TU) {
+  Initialize(TU.getContext());
+}

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

==============================================================================
--- cfe/trunk/lib/Sema/ParseAST.cpp (original)
+++ cfe/trunk/lib/Sema/ParseAST.cpp Sat May 31 15:11:04 2008
@@ -46,7 +46,7 @@
   // Initialize the parser.
   P.Initialize();
   
-  Consumer->Initialize(Context);
+  Consumer->InitializeTU(TU);
   
   Parser::DeclTy *ADecl;
   





More information about the cfe-commits mailing list