Pass the ASTContext object around when deserializing Decl and Stmt objects, so
they can be created using the same allocator as in the "from source code" case.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49353 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp
index 433e8e2..41569df 100644
--- a/lib/AST/StmtSerialization.cpp
+++ b/lib/AST/StmtSerialization.cpp
@@ -27,7 +27,7 @@
   S.FlushRecord();
 }  
 
-Stmt* Stmt::Create(Deserializer& D) {
+Stmt* Stmt::Create(Deserializer& D, ASTContext& C) {
   StmtClass SC = static_cast<StmtClass>(D.ReadInt());
   
   switch (SC) {
@@ -36,155 +36,155 @@
       return NULL;
     
     case AddrLabelExprClass:
-      return AddrLabelExpr::CreateImpl(D);
+      return AddrLabelExpr::CreateImpl(D, C);
       
     case ArraySubscriptExprClass:
-      return ArraySubscriptExpr::CreateImpl(D);
+      return ArraySubscriptExpr::CreateImpl(D, C);
       
     case AsmStmtClass:
-      return AsmStmt::CreateImpl(D);
+      return AsmStmt::CreateImpl(D, C);
       
     case BinaryOperatorClass:
-      return BinaryOperator::CreateImpl(D);
+      return BinaryOperator::CreateImpl(D, C);
       
     case BreakStmtClass:
-      return BreakStmt::CreateImpl(D);
+      return BreakStmt::CreateImpl(D, C);
      
     case CallExprClass:
-      return CallExpr::CreateImpl(D);
+      return CallExpr::CreateImpl(D, C);
       
     case CaseStmtClass:
-      return CaseStmt::CreateImpl(D);
+      return CaseStmt::CreateImpl(D, C);
     
     case CastExprClass:
-      return CastExpr::CreateImpl(D);
+      return CastExpr::CreateImpl(D, C);
       
     case CharacterLiteralClass:
-      return CharacterLiteral::CreateImpl(D);
+      return CharacterLiteral::CreateImpl(D, C);
       
     case CompoundAssignOperatorClass:
-      return CompoundAssignOperator::CreateImpl(D);
+      return CompoundAssignOperator::CreateImpl(D, C);
       
     case CompoundLiteralExprClass:
-      return CompoundLiteralExpr::CreateImpl(D);
+      return CompoundLiteralExpr::CreateImpl(D, C);
       
     case CompoundStmtClass:
-      return CompoundStmt::CreateImpl(D);
+      return CompoundStmt::CreateImpl(D, C);
     
     case ConditionalOperatorClass:
-      return ConditionalOperator::CreateImpl(D);
+      return ConditionalOperator::CreateImpl(D, C);
       
     case ContinueStmtClass:
-      return ContinueStmt::CreateImpl(D);
+      return ContinueStmt::CreateImpl(D, C);
       
     case DeclRefExprClass:
-      return DeclRefExpr::CreateImpl(D);
+      return DeclRefExpr::CreateImpl(D, C);
       
     case DeclStmtClass:
-      return DeclStmt::CreateImpl(D);
+      return DeclStmt::CreateImpl(D, C);
       
     case DefaultStmtClass:
-      return DefaultStmt::CreateImpl(D);
+      return DefaultStmt::CreateImpl(D, C);
     
     case DoStmtClass:
-      return DoStmt::CreateImpl(D);
+      return DoStmt::CreateImpl(D, C);
       
     case FloatingLiteralClass:
-      return FloatingLiteral::CreateImpl(D);
+      return FloatingLiteral::CreateImpl(D, C);
 
     case ForStmtClass:
-      return ForStmt::CreateImpl(D);
+      return ForStmt::CreateImpl(D, C);
     
     case GotoStmtClass:
-      return GotoStmt::CreateImpl(D);
+      return GotoStmt::CreateImpl(D, C);
       
     case IfStmtClass:
-      return IfStmt::CreateImpl(D);
+      return IfStmt::CreateImpl(D, C);
     
     case ImaginaryLiteralClass:
-      return ImaginaryLiteral::CreateImpl(D);
+      return ImaginaryLiteral::CreateImpl(D, C);
       
     case ImplicitCastExprClass:
-      return ImplicitCastExpr::CreateImpl(D);
+      return ImplicitCastExpr::CreateImpl(D, C);
       
     case IndirectGotoStmtClass:
-      return IndirectGotoStmt::CreateImpl(D);
+      return IndirectGotoStmt::CreateImpl(D, C);
       
     case InitListExprClass:
-      return InitListExpr::CreateImpl(D);
+      return InitListExpr::CreateImpl(D, C);
       
     case IntegerLiteralClass:
-      return IntegerLiteral::CreateImpl(D);
+      return IntegerLiteral::CreateImpl(D, C);
       
     case LabelStmtClass:
-      return LabelStmt::CreateImpl(D);
+      return LabelStmt::CreateImpl(D, C);
       
     case MemberExprClass:
-      return MemberExpr::CreateImpl(D);
+      return MemberExpr::CreateImpl(D, C);
       
     case NullStmtClass:
-      return NullStmt::CreateImpl(D);
+      return NullStmt::CreateImpl(D, C);
       
     case ParenExprClass:
-      return ParenExpr::CreateImpl(D);
+      return ParenExpr::CreateImpl(D, C);
       
     case PreDefinedExprClass:
-      return PreDefinedExpr::CreateImpl(D);
+      return PreDefinedExpr::CreateImpl(D, C);
       
     case ReturnStmtClass:
-      return ReturnStmt::CreateImpl(D);
+      return ReturnStmt::CreateImpl(D, C);
     
     case SizeOfAlignOfTypeExprClass:
-      return SizeOfAlignOfTypeExpr::CreateImpl(D);
+      return SizeOfAlignOfTypeExpr::CreateImpl(D, C);
       
     case StmtExprClass:
-      return StmtExpr::CreateImpl(D);
+      return StmtExpr::CreateImpl(D, C);
       
     case StringLiteralClass:
-      return StringLiteral::CreateImpl(D);
+      return StringLiteral::CreateImpl(D, C);
       
     case SwitchStmtClass:
-      return SwitchStmt::CreateImpl(D);
+      return SwitchStmt::CreateImpl(D, C);
       
     case UnaryOperatorClass:
-      return UnaryOperator::CreateImpl(D);
+      return UnaryOperator::CreateImpl(D, C);
       
     case WhileStmtClass:
-      return WhileStmt::CreateImpl(D);
+      return WhileStmt::CreateImpl(D, C);
       
     //==--------------------------------------==//
     //    Objective C
     //==--------------------------------------==//
     
     case ObjCAtCatchStmtClass:
-      return ObjCAtCatchStmt::CreateImpl(D);
+      return ObjCAtCatchStmt::CreateImpl(D, C);
       
     case ObjCAtFinallyStmtClass:
-      return ObjCAtFinallyStmt::CreateImpl(D);
+      return ObjCAtFinallyStmt::CreateImpl(D, C);
     
     case ObjCAtSynchronizedStmtClass:
-      return ObjCAtSynchronizedStmt::CreateImpl(D);
+      return ObjCAtSynchronizedStmt::CreateImpl(D, C);
       
     case ObjCAtThrowStmtClass:
-      return ObjCAtThrowStmt::CreateImpl(D);
+      return ObjCAtThrowStmt::CreateImpl(D, C);
       
     case ObjCAtTryStmtClass:
-      return ObjCAtTryStmt::CreateImpl(D);
+      return ObjCAtTryStmt::CreateImpl(D, C);
     
     case ObjCEncodeExprClass:
-      return ObjCEncodeExpr::CreateImpl(D);
+      return ObjCEncodeExpr::CreateImpl(D, C);
       
     case ObjCForCollectionStmtClass:
-      return ObjCForCollectionStmt::CreateImpl(D);
+      return ObjCForCollectionStmt::CreateImpl(D, C);
       
     case ObjCIvarRefExprClass:
-      return ObjCIvarRefExpr::CreateImpl(D);
+      return ObjCIvarRefExpr::CreateImpl(D, C);
       
     case ObjCSelectorExprClass:
-      return ObjCSelectorExpr::CreateImpl(D);
+      return ObjCSelectorExpr::CreateImpl(D, C);
       
     case ObjCStringLiteralClass:
-      return ObjCStringLiteral::CreateImpl(D);
+      return ObjCStringLiteral::CreateImpl(D, C);
   }
 }
 
@@ -199,7 +199,7 @@
   S.EmitPtr(Label);
 }
 
-AddrLabelExpr* AddrLabelExpr::CreateImpl(Deserializer& D) {
+AddrLabelExpr* AddrLabelExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation AALoc = SourceLocation::ReadVal(D);
   SourceLocation LLoc = SourceLocation::ReadVal(D);
@@ -214,11 +214,11 @@
   S.BatchEmitOwnedPtrs(getLHS(),getRHS());
 }
 
-ArraySubscriptExpr* ArraySubscriptExpr::CreateImpl(Deserializer& D) {
+ArraySubscriptExpr* ArraySubscriptExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   Expr *LHS, *RHS;
-  D.BatchReadOwnedPtrs(LHS,RHS);
+  D.BatchReadOwnedPtrs(LHS, RHS, C);
   return new ArraySubscriptExpr(LHS,RHS,t,L);  
 }
 
@@ -249,9 +249,9 @@
     Clobbers[i]->EmitImpl(S);
 }
 
-AsmStmt* AsmStmt::CreateImpl(Deserializer& D) {
+AsmStmt* AsmStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation ALoc = SourceLocation::ReadVal(D);
-  StringLiteral *AsmStr = StringLiteral::CreateImpl(D);
+  StringLiteral *AsmStr = StringLiteral::CreateImpl(D, C);
   SourceLocation PLoc = SourceLocation::ReadVal(D);
   
   bool IsVolatile = D.ReadBool();
@@ -275,16 +275,16 @@
 
   Stmt->Constraints.reserve(size);
   for (unsigned i = 0; i < size; ++i)
-    Stmt->Constraints.push_back(StringLiteral::CreateImpl(D));
+    Stmt->Constraints.push_back(StringLiteral::CreateImpl(D, C));
   
   Stmt->Exprs.reserve(size);
   for (unsigned i = 0; i < size; ++i)
-    Stmt->Exprs.push_back(D.ReadOwnedPtr<Expr>());
+    Stmt->Exprs.push_back(D.ReadOwnedPtr<Expr>(C));
   
   unsigned NumClobbers = D.ReadInt();
   Stmt->Clobbers.reserve(NumClobbers);
   for (unsigned i = 0; i < NumClobbers; ++i)
-    Stmt->Clobbers.push_back(StringLiteral::CreateImpl(D));
+    Stmt->Clobbers.push_back(StringLiteral::CreateImpl(D, C));
   
   return Stmt;
 }
@@ -296,12 +296,12 @@
   S.BatchEmitOwnedPtrs(getLHS(),getRHS());
 }
 
-BinaryOperator* BinaryOperator::CreateImpl(Deserializer& D) {
+BinaryOperator* BinaryOperator::CreateImpl(Deserializer& D, ASTContext& C) {
   Opcode Opc = static_cast<Opcode>(D.ReadInt());
   SourceLocation OpLoc = SourceLocation::ReadVal(D);
   QualType Result = QualType::ReadVal(D);
   Expr *LHS, *RHS;
-  D.BatchReadOwnedPtrs(LHS,RHS);
+  D.BatchReadOwnedPtrs(LHS, RHS, C);
 
   return new BinaryOperator(LHS,RHS,Opc,Result,OpLoc);
 }
@@ -310,7 +310,7 @@
   S.Emit(BreakLoc);
 }
 
-BreakStmt* BreakStmt::CreateImpl(Deserializer& D) {
+BreakStmt* BreakStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   return new BreakStmt(Loc);
 }
@@ -322,12 +322,12 @@
   S.BatchEmitOwnedPtrs(NumArgs+1,SubExprs);  
 }
 
-CallExpr* CallExpr::CreateImpl(Deserializer& D) {
+CallExpr* CallExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   unsigned NumArgs = D.ReadInt();
   Expr** SubExprs = new Expr*[NumArgs+1];
-  D.BatchReadOwnedPtrs(NumArgs+1,SubExprs);
+  D.BatchReadOwnedPtrs(NumArgs+1, SubExprs, C);
 
   return new CallExpr(SubExprs,NumArgs,t,L);  
 }
@@ -338,11 +338,11 @@
   S.BatchEmitOwnedPtrs((unsigned) END_EXPR,&SubExprs[0]);
 }
 
-CaseStmt* CaseStmt::CreateImpl(Deserializer& D) {
+CaseStmt* CaseStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation CaseLoc = SourceLocation::ReadVal(D);
   CaseStmt* stmt = new CaseStmt(NULL,NULL,NULL,CaseLoc);  
   D.ReadPtr(stmt->NextSwitchCase);
-  D.BatchReadOwnedPtrs((unsigned) END_EXPR,&stmt->SubExprs[0]);
+  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubExprs[0], C);
   return stmt;
 }
 
@@ -352,10 +352,10 @@
   S.EmitOwnedPtr(Op);
 }
 
-CastExpr* CastExpr::CreateImpl(Deserializer& D) {
+CastExpr* CastExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation Loc = SourceLocation::ReadVal(D);
-  Expr* Op = D.ReadOwnedPtr<Expr>();
+  Expr* Op = D.ReadOwnedPtr<Expr>(C);
   return new CastExpr(t,Op,Loc);
 }
   
@@ -366,7 +366,7 @@
   S.Emit(getType());
 }
 
-CharacterLiteral* CharacterLiteral::CreateImpl(Deserializer& D) {
+CharacterLiteral* CharacterLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   unsigned value = D.ReadInt();
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);
@@ -382,13 +382,13 @@
 }
 
 CompoundAssignOperator* 
-CompoundAssignOperator::CreateImpl(Deserializer& D) {
+CompoundAssignOperator::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   QualType c = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   Opcode Opc = static_cast<Opcode>(D.ReadInt());
   Expr* LHS, *RHS;
-  D.BatchReadOwnedPtrs(LHS,RHS);
+  D.BatchReadOwnedPtrs(LHS, RHS, C);
   
   return new CompoundAssignOperator(LHS,RHS,Opc,t,c,L);
 }
@@ -400,11 +400,11 @@
   S.EmitOwnedPtr(Init);
 }
 
-CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D) {
+CompoundLiteralExpr* CompoundLiteralExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType Q = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   bool fileScope = D.ReadBool();
-  Expr* Init = D.ReadOwnedPtr<Expr>();
+  Expr* Init = D.ReadOwnedPtr<Expr>(C);
   return new CompoundLiteralExpr(L, Q, Init, fileScope);
 }
 
@@ -417,7 +417,7 @@
     S.EmitOwnedPtr(*I);
 }
 
-CompoundStmt* CompoundStmt::CreateImpl(Deserializer& D) {
+CompoundStmt* CompoundStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation LB = SourceLocation::ReadVal(D);
   SourceLocation RB = SourceLocation::ReadVal(D);
   unsigned size = D.ReadInt();
@@ -427,7 +427,7 @@
   stmt->Body.reserve(size);
   
   for (unsigned i = 0; i < size; ++i)
-    stmt->Body.push_back(D.ReadOwnedPtr<Stmt>());
+    stmt->Body.push_back(D.ReadOwnedPtr<Stmt>(C));
   
   return stmt;
 }
@@ -437,10 +437,12 @@
   S.BatchEmitOwnedPtrs((unsigned) END_EXPR, SubExprs);
 }
 
-ConditionalOperator* ConditionalOperator::CreateImpl(Deserializer& D) {
+ConditionalOperator* ConditionalOperator::CreateImpl(Deserializer& D,
+                                                     ASTContext& C) {
+
   QualType t = QualType::ReadVal(D);
   ConditionalOperator* c = new ConditionalOperator(NULL,NULL,NULL,t);
-  D.BatchReadOwnedPtrs((unsigned) END_EXPR, c->SubExprs);
+  D.BatchReadOwnedPtrs((unsigned) END_EXPR, c->SubExprs, C);
   return c;
 }
 
@@ -448,7 +450,7 @@
   S.Emit(ContinueLoc);
 }
 
-ContinueStmt* ContinueStmt::CreateImpl(Deserializer& D) {
+ContinueStmt* ContinueStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   return new ContinueStmt(Loc);
 }
@@ -490,7 +492,7 @@
   }
 }
 
-DeclRefExpr* DeclRefExpr::CreateImpl(Deserializer& D) {
+DeclRefExpr* DeclRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);  
   bool OwnsDecl = D.ReadBool();
@@ -499,14 +501,13 @@
   if (!OwnsDecl)
     D.ReadPtr(decl,false); // No backpatching.
   else
-    decl = cast<ValueDecl>(D.ReadOwnedPtr<Decl>());
+    decl = cast<ValueDecl>(D.ReadOwnedPtr<Decl>(C));
   
   return new DeclRefExpr(decl,T,Loc);
 }
 
-
-DeclStmt* DeclStmt::CreateImpl(Deserializer& D) {
-  ScopedDecl* decl = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>());
+DeclStmt* DeclStmt::CreateImpl(Deserializer& D, ASTContext& C) {
+  ScopedDecl* decl = cast<ScopedDecl>(D.ReadOwnedPtr<Decl>(C));
   SourceLocation StartLoc = SourceLocation::ReadVal(D);
   SourceLocation EndLoc = SourceLocation::ReadVal(D);
   return new DeclStmt(decl, StartLoc, EndLoc);
@@ -518,9 +519,9 @@
   S.EmitPtr(getNextSwitchCase());
 }
 
-DefaultStmt* DefaultStmt::CreateImpl(Deserializer& D) {
+DefaultStmt* DefaultStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
-  Stmt* SubStmt = D.ReadOwnedPtr<Stmt>();
+  Stmt* SubStmt = D.ReadOwnedPtr<Stmt>(C);
   
   DefaultStmt* stmt = new DefaultStmt(Loc,SubStmt);
   stmt->setNextSwitchCase(D.ReadPtr<SwitchCase>());
@@ -534,10 +535,10 @@
   S.EmitOwnedPtr(getBody());
 }
 
-DoStmt* DoStmt::CreateImpl(Deserializer& D) {
+DoStmt* DoStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation DoLoc = SourceLocation::ReadVal(D);
-  Expr* Cond = D.ReadOwnedPtr<Expr>();
-  Stmt* Body = D.ReadOwnedPtr<Stmt>();
+  Expr* Cond = D.ReadOwnedPtr<Expr>(C);
+  Stmt* Body = D.ReadOwnedPtr<Stmt>(C);
   return new DoStmt(Body,Cond,DoLoc);
 }
 
@@ -548,7 +549,7 @@
   S.Emit(Value);
 }
 
-FloatingLiteral* FloatingLiteral::CreateImpl(Deserializer& D) {
+FloatingLiteral* FloatingLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType t = QualType::ReadVal(D);
   bool isExact = D.ReadBool();
@@ -565,12 +566,12 @@
   S.EmitOwnedPtr(getBody());
 }
 
-ForStmt* ForStmt::CreateImpl(Deserializer& D) {
+ForStmt* ForStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation ForLoc = SourceLocation::ReadVal(D);
-  Stmt* Init = D.ReadOwnedPtr<Stmt>();
-  Expr* Cond = D.ReadOwnedPtr<Expr>();
-  Expr* Inc = D.ReadOwnedPtr<Expr>();
-  Stmt* Body = D.ReadOwnedPtr<Stmt>();
+  Stmt* Init = D.ReadOwnedPtr<Stmt>(C);
+  Expr* Cond = D.ReadOwnedPtr<Expr>(C);
+  Expr* Inc = D.ReadOwnedPtr<Expr>(C);
+  Stmt* Body = D.ReadOwnedPtr<Stmt>(C);
   return new ForStmt(Init,Cond,Inc,Body,ForLoc);
 }
 
@@ -580,7 +581,7 @@
   S.EmitPtr(Label);
 }
 
-GotoStmt* GotoStmt::CreateImpl(Deserializer& D) {
+GotoStmt* GotoStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation GotoLoc = SourceLocation::ReadVal(D);
   SourceLocation LabelLoc = SourceLocation::ReadVal(D);
   GotoStmt* stmt = new GotoStmt(NULL,GotoLoc,LabelLoc);
@@ -595,11 +596,11 @@
   S.EmitOwnedPtr(getElse());
 }
 
-IfStmt* IfStmt::CreateImpl(Deserializer& D) {
+IfStmt* IfStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation L = SourceLocation::ReadVal(D);
-  Expr* Cond = D.ReadOwnedPtr<Expr>();
-  Stmt* Then = D.ReadOwnedPtr<Stmt>();
-  Stmt* Else = D.ReadOwnedPtr<Stmt>();
+  Expr* Cond = D.ReadOwnedPtr<Expr>(C);
+  Stmt* Then = D.ReadOwnedPtr<Stmt>(C);
+  Stmt* Else = D.ReadOwnedPtr<Stmt>(C);
   return new IfStmt(L,Cond,Then,Else);
 }
 
@@ -608,9 +609,9 @@
   S.EmitOwnedPtr(Val);    
 }
 
-ImaginaryLiteral* ImaginaryLiteral::CreateImpl(Deserializer& D) {
+ImaginaryLiteral* ImaginaryLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
-  Expr* expr = D.ReadOwnedPtr<Expr>();
+  Expr* expr = D.ReadOwnedPtr<Expr>(C);
   assert (isa<FloatingLiteral>(expr) || isa<IntegerLiteral>(expr));
   return new ImaginaryLiteral(expr,t);
 }
@@ -620,9 +621,9 @@
   S.EmitOwnedPtr(Op);
 }
 
-ImplicitCastExpr* ImplicitCastExpr::CreateImpl(Deserializer& D) {
+ImplicitCastExpr* ImplicitCastExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
-  Expr* Op = D.ReadOwnedPtr<Expr>();
+  Expr* Op = D.ReadOwnedPtr<Expr>(C);
   return new ImplicitCastExpr(t,Op);
 }
 
@@ -630,8 +631,8 @@
   S.EmitOwnedPtr(Target);  
 }
 
-IndirectGotoStmt* IndirectGotoStmt::CreateImpl(Deserializer& D) {
-  Expr* Target = D.ReadOwnedPtr<Expr>();
+IndirectGotoStmt* IndirectGotoStmt::CreateImpl(Deserializer& D, ASTContext& C) {
+  Expr* Target = D.ReadOwnedPtr<Expr>(C);
   return new IndirectGotoStmt(Target);
 }
 
@@ -642,14 +643,14 @@
   S.BatchEmitOwnedPtrs(NumInits,InitExprs);
 }
 
-InitListExpr* InitListExpr::CreateImpl(Deserializer& D) {
+InitListExpr* InitListExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   InitListExpr* expr = new InitListExpr();
   expr->LBraceLoc = SourceLocation::ReadVal(D);
   expr->RBraceLoc = SourceLocation::ReadVal(D);
   expr->NumInits = D.ReadInt();
   assert(expr->NumInits);
   expr->InitExprs = new Expr*[expr->NumInits];
-  D.BatchReadOwnedPtrs(expr->NumInits,expr->InitExprs);
+  D.BatchReadOwnedPtrs(expr->NumInits, expr->InitExprs, C);
   return expr;
 }
 
@@ -659,7 +660,7 @@
   S.Emit(getValue());
 }
 
-IntegerLiteral* IntegerLiteral::CreateImpl(Deserializer& D) {
+IntegerLiteral* IntegerLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);
   
@@ -678,10 +679,10 @@
   S.EmitOwnedPtr(SubStmt);
 }
 
-LabelStmt* LabelStmt::CreateImpl(Deserializer& D) {
+LabelStmt* LabelStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   IdentifierInfo* Label = D.ReadPtr<IdentifierInfo>();
   SourceLocation IdentLoc = SourceLocation::ReadVal(D);
-  Stmt* SubStmt = D.ReadOwnedPtr<Stmt>();
+  Stmt* SubStmt = D.ReadOwnedPtr<Stmt>(C);
   return new LabelStmt(IdentLoc,Label,SubStmt);
 }
 
@@ -693,12 +694,12 @@
   S.EmitOwnedPtr(Base);
 }
 
-MemberExpr* MemberExpr::CreateImpl(Deserializer& D) {
+MemberExpr* MemberExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation L = SourceLocation::ReadVal(D);
   FieldDecl* MemberDecl = cast<FieldDecl>(D.ReadPtr<Decl>());
   bool IsArrow = D.ReadBool();
   QualType T = QualType::ReadVal(D);
-  Expr* base = D.ReadOwnedPtr<Expr>();
+  Expr* base = D.ReadOwnedPtr<Expr>(C);
   
   return new MemberExpr(base,IsArrow,MemberDecl,L,T); 
 }
@@ -707,7 +708,7 @@
   S.Emit(SemiLoc);
 }
 
-NullStmt* NullStmt::CreateImpl(Deserializer& D) {
+NullStmt* NullStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation SemiLoc = SourceLocation::ReadVal(D);
   return new NullStmt(SemiLoc);
 }
@@ -718,10 +719,10 @@
   S.EmitOwnedPtr(Val);
 }
 
-ParenExpr* ParenExpr::CreateImpl(Deserializer& D) {
+ParenExpr* ParenExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation L = SourceLocation::ReadVal(D);
   SourceLocation R = SourceLocation::ReadVal(D);
-  Expr* val = D.ReadOwnedPtr<Expr>();  
+  Expr* val = D.ReadOwnedPtr<Expr>(C);
   return new ParenExpr(L,R,val);
 }
 
@@ -731,7 +732,7 @@
   S.Emit(getType());  
 }
 
-PreDefinedExpr* PreDefinedExpr::CreateImpl(Deserializer& D) {
+PreDefinedExpr* PreDefinedExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   IdentType it = static_cast<IdentType>(D.ReadInt());
   QualType Q = QualType::ReadVal(D);
@@ -743,9 +744,9 @@
   S.EmitOwnedPtr(RetExpr);
 }
 
-ReturnStmt* ReturnStmt::CreateImpl(Deserializer& D) {
+ReturnStmt* ReturnStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation RetLoc = SourceLocation::ReadVal(D);
-  Expr* RetExpr = D.ReadOwnedPtr<Expr>();  
+  Expr* RetExpr = D.ReadOwnedPtr<Expr>(C);
   return new ReturnStmt(RetLoc,RetExpr);
 }
 
@@ -757,7 +758,7 @@
   S.Emit(RParenLoc);
 }
 
-SizeOfAlignOfTypeExpr* SizeOfAlignOfTypeExpr::CreateImpl(Deserializer& D) {
+SizeOfAlignOfTypeExpr* SizeOfAlignOfTypeExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   bool isSizeof = D.ReadBool();
   QualType Ty = QualType::ReadVal(D);
   QualType Res = QualType::ReadVal(D);
@@ -774,11 +775,11 @@
   S.EmitOwnedPtr(SubStmt);
 }
 
-StmtExpr* StmtExpr::CreateImpl(Deserializer& D) {
+StmtExpr* StmtExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   SourceLocation R = SourceLocation::ReadVal(D);
-  CompoundStmt* SubStmt = cast<CompoundStmt>(D.ReadOwnedPtr<Stmt>());
+  CompoundStmt* SubStmt = cast<CompoundStmt>(D.ReadOwnedPtr<Stmt>(C));
   return new StmtExpr(SubStmt,t,L,R);
 }
 
@@ -793,7 +794,7 @@
     S.EmitInt(StrData[i]);
 }
 
-StringLiteral* StringLiteral::CreateImpl(Deserializer& D) {
+StringLiteral* StringLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation firstTokLoc = SourceLocation::ReadVal(D);
   SourceLocation lastTokLoc = SourceLocation::ReadVal(D);
@@ -819,10 +820,10 @@
   S.EmitPtr(FirstCase);  
 }
 
-SwitchStmt* SwitchStmt::CreateImpl(Deserializer& D) {
+SwitchStmt* SwitchStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
-  Stmt* Cond = D.ReadOwnedPtr<Stmt>();
-  Stmt* Body = D.ReadOwnedPtr<Stmt>();
+  Stmt* Cond = D.ReadOwnedPtr<Stmt>(C);
+  Stmt* Body = D.ReadOwnedPtr<Stmt>(C);
   SwitchCase* FirstCase = cast<SwitchCase>(D.ReadPtr<Stmt>());
   
   SwitchStmt* stmt = new SwitchStmt(cast<Expr>(Cond));
@@ -839,11 +840,11 @@
   S.EmitOwnedPtr(Val);
 }
 
-UnaryOperator* UnaryOperator::CreateImpl(Deserializer& D) {
+UnaryOperator* UnaryOperator::CreateImpl(Deserializer& D, ASTContext& C) {
   QualType t = QualType::ReadVal(D);
   SourceLocation L = SourceLocation::ReadVal(D);
   Opcode Opc = static_cast<Opcode>(D.ReadInt());
-  Expr* Val = D.ReadOwnedPtr<Expr>();
+  Expr* Val = D.ReadOwnedPtr<Expr>(C);
   return new UnaryOperator(Val,Opc,t,L);
 }
 
@@ -853,10 +854,10 @@
   S.EmitOwnedPtr(getBody());
 }
 
-WhileStmt* WhileStmt::CreateImpl(Deserializer& D) {
+WhileStmt* WhileStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation WhileLoc = SourceLocation::ReadVal(D);
-  Expr* Cond = D.ReadOwnedPtr<Expr>();
-  Stmt* Body = D.ReadOwnedPtr<Stmt>();
+  Expr* Cond = D.ReadOwnedPtr<Expr>(C);
+  Stmt* Body = D.ReadOwnedPtr<Stmt>(C);
   return new WhileStmt(Cond,Body,WhileLoc);
 }
 
@@ -870,12 +871,12 @@
   S.BatchEmitOwnedPtrs((unsigned) END_EXPR, &SubExprs[0]);
 }
 
-ObjCAtCatchStmt* ObjCAtCatchStmt::CreateImpl(Deserializer& D) {
+ObjCAtCatchStmt* ObjCAtCatchStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation AtCatchLoc = SourceLocation::ReadVal(D);
   SourceLocation RParenLoc = SourceLocation::ReadVal(D);
   
   ObjCAtCatchStmt* stmt = new ObjCAtCatchStmt(AtCatchLoc,RParenLoc);
-  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubExprs[0]);
+  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubExprs[0], C);
 
   return stmt;
 }
@@ -885,9 +886,9 @@
   S.EmitOwnedPtr(AtFinallyStmt);
 }
 
-ObjCAtFinallyStmt* ObjCAtFinallyStmt::CreateImpl(Deserializer& D) {
+ObjCAtFinallyStmt* ObjCAtFinallyStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
-  Stmt* AtFinallyStmt = D.ReadOwnedPtr<Stmt>();
+  Stmt* AtFinallyStmt = D.ReadOwnedPtr<Stmt>(C);
   return new ObjCAtFinallyStmt(Loc,AtFinallyStmt);  
 }
 
@@ -896,10 +897,12 @@
   S.BatchEmitOwnedPtrs((unsigned) END_EXPR,&SubStmts[0]);
  }
 
-ObjCAtSynchronizedStmt* ObjCAtSynchronizedStmt::CreateImpl(Deserializer& D) {
+ObjCAtSynchronizedStmt* ObjCAtSynchronizedStmt::CreateImpl(Deserializer& D,
+                                                           ASTContext& C) {
+
   SourceLocation L = SourceLocation::ReadVal(D);
   ObjCAtSynchronizedStmt* stmt = new ObjCAtSynchronizedStmt(L,0,0);
-  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubStmts[0]);
+  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubStmts[0], C);
   return stmt;
 }
 
@@ -908,9 +911,9 @@
   S.EmitOwnedPtr(Throw);
 }
 
-ObjCAtThrowStmt* ObjCAtThrowStmt::CreateImpl(Deserializer& D) {
+ObjCAtThrowStmt* ObjCAtThrowStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation L = SourceLocation::ReadVal(D);
-  Stmt* Throw = D.ReadOwnedPtr<Stmt>();
+  Stmt* Throw = D.ReadOwnedPtr<Stmt>(C);
   return new ObjCAtThrowStmt(L,Throw);  
 }
   
@@ -919,10 +922,10 @@
   S.BatchEmitOwnedPtrs((unsigned) END_EXPR, &SubStmts[0]);
 }
 
-ObjCAtTryStmt* ObjCAtTryStmt::CreateImpl(Deserializer& D) {
+ObjCAtTryStmt* ObjCAtTryStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation L = SourceLocation::ReadVal(D);
   ObjCAtTryStmt* stmt = new ObjCAtTryStmt(L,NULL,NULL,NULL);
-  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubStmts[0]);
+  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &stmt->SubStmts[0], C);
   return stmt;
 }
 
@@ -933,7 +936,7 @@
   S.Emit(EncType);
 }
 
-ObjCEncodeExpr* ObjCEncodeExpr::CreateImpl(Deserializer& D) {
+ObjCEncodeExpr* ObjCEncodeExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation AtLoc = SourceLocation::ReadVal(D);
   SourceLocation RParenLoc = SourceLocation::ReadVal(D);  
   QualType T = QualType::ReadVal(D);
@@ -947,13 +950,13 @@
   S.BatchEmitOwnedPtrs(getElement(),getCollection(),getBody());
 }
 
-ObjCForCollectionStmt* ObjCForCollectionStmt::CreateImpl(Deserializer& D) {
+ObjCForCollectionStmt* ObjCForCollectionStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation ForLoc = SourceLocation::ReadVal(D);
   SourceLocation RParenLoc = SourceLocation::ReadVal(D);
   Stmt* Element;
   Expr* Collection;
   Stmt* Body;
-  D.BatchReadOwnedPtrs(Element,Collection,Body);  
+  D.BatchReadOwnedPtrs(Element, Collection, Body, C);
   return new ObjCForCollectionStmt(Element,Collection,Body,ForLoc, RParenLoc);
 }
 
@@ -963,7 +966,7 @@
   S.EmitPtr(getDecl());
 }
   
-ObjCIvarRefExpr* ObjCIvarRefExpr::CreateImpl(Deserializer& D) {
+ObjCIvarRefExpr* ObjCIvarRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);
   ObjCIvarRefExpr* dr = new ObjCIvarRefExpr(NULL,T,Loc);
@@ -978,7 +981,7 @@
   S.Emit(SelName);
 }
 
-ObjCSelectorExpr* ObjCSelectorExpr::CreateImpl(Deserializer& D) {
+ObjCSelectorExpr* ObjCSelectorExpr::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation AtLoc = SourceLocation::ReadVal(D);
   SourceLocation RParenLoc = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);
@@ -993,9 +996,9 @@
   S.EmitOwnedPtr(String);
 }
 
-ObjCStringLiteral* ObjCStringLiteral::CreateImpl(Deserializer& D) {
+ObjCStringLiteral* ObjCStringLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation L = SourceLocation::ReadVal(D);
   QualType T = QualType::ReadVal(D);
-  StringLiteral* String = cast<StringLiteral>(D.ReadOwnedPtr<Stmt>());
+  StringLiteral* String = cast<StringLiteral>(D.ReadOwnedPtr<Stmt>(C));
   return new ObjCStringLiteral(String,T,L);
 }