aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-31 20:11:04 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-31 20:11:04 +0000
commite3a6198400453c0d9623207718e4942f7c111f87 (patch)
tree58a5df0abe91c7ace437145acce130e7b2553eb9
parentbaf58c3f1fb13eec46fe339287662f180bb566da (diff)
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> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51825 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/ASTConsumers.cpp5
-rw-r--r--Driver/RewriteObjC.cpp8
-rw-r--r--include/clang/AST/ASTConsumer.h3
-rw-r--r--lib/AST/ASTConsumer.cpp6
-rw-r--r--lib/Sema/ParseAST.cpp2
5 files changed, 19 insertions, 5 deletions
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp
index ba9fc90f03..9ab6157cfa 100644
--- a/Driver/ASTConsumers.cpp
+++ b/Driver/ASTConsumers.cpp
@@ -877,9 +877,8 @@ public:
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) {
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp
index c523b03d56..f679e554d0 100644
--- a/Driver/RewriteObjC.cpp
+++ b/Driver/RewriteObjC.cpp
@@ -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 @@ namespace {
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.
diff --git a/include/clang/AST/ASTConsumer.h b/include/clang/AST/ASTConsumer.h
index bfaa141573..c08f97e640 100644
--- a/include/clang/AST/ASTConsumer.h
+++ b/include/clang/AST/ASTConsumer.h
@@ -16,6 +16,7 @@
namespace clang {
class ASTContext;
+ class TranslationUnit;
class Decl;
class TagDecl;
class HandleTagDeclDefinition;
@@ -31,6 +32,8 @@ public:
/// 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) {}
diff --git a/lib/AST/ASTConsumer.cpp b/lib/AST/ASTConsumer.cpp
index b3d1271092..3f92990f36 100644
--- a/lib/AST/ASTConsumer.cpp
+++ b/lib/AST/ASTConsumer.cpp
@@ -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 @@ void ASTConsumer::HandleTopLevelDeclaration(Decl* d) {
else
HandleTopLevelDecl(d);
}
+
+void ASTConsumer::InitializeTU(TranslationUnit& TU) {
+ Initialize(TU.getContext());
+}
diff --git a/lib/Sema/ParseAST.cpp b/lib/Sema/ParseAST.cpp
index cff3ef7612..9199179af7 100644
--- a/lib/Sema/ParseAST.cpp
+++ b/lib/Sema/ParseAST.cpp
@@ -46,7 +46,7 @@ void clang::ParseAST(Preprocessor &PP, ASTConsumer *Consumer, bool PrintStats) {
// Initialize the parser.
P.Initialize();
- Consumer->Initialize(Context);
+ Consumer->InitializeTU(TU);
Parser::DeclTy *ADecl;