[cfe-commits] r57588 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/StmtSerialization.cpp

Daniel Dunbar daniel at zuster.org
Wed Oct 15 10:52:30 PDT 2008


Author: ddunbar
Date: Wed Oct 15 12:52:29 2008
New Revision: 57588

URL: http://llvm.org/viewvc/llvm-project?rev=57588&view=rev
Log:
Use BatchEmitOwnedPtrs for writing multiple child exprs, per review.

Also added serialization support to OverloadExpr.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/StmtSerialization.cpp

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Oct 15 12:52:29 2008
@@ -1353,6 +1353,9 @@
   // Iterators
   virtual child_iterator child_begin();
   virtual child_iterator child_end();
+
+  virtual void EmitImpl(llvm::Serializer& S) const;
+  static OverloadExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C);
 };
 
 /// VAArgExpr, used for the builtin function __builtin_va_start.

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

==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Wed Oct 15 12:52:29 2008
@@ -827,8 +827,7 @@
   S.Emit(BuiltinLoc);
   S.Emit(RParenLoc);
   S.EmitInt(NumExprs);
-  for (unsigned i = 0; i < NumExprs; ++i)
-    S.EmitOwnedPtr(getExpr(i));
+  S.BatchEmitOwnedPtrs(NumExprs, &SubExprs[0]);
 }
 
 ShuffleVectorExpr* ShuffleVectorExpr::CreateImpl(llvm::Deserializer& D, 
@@ -837,10 +836,9 @@
   SourceLocation BL = SourceLocation::ReadVal(D);
   SourceLocation RP = SourceLocation::ReadVal(D);
   unsigned NumExprs = D.ReadInt();
+  // FIXME: Avoid extra allocation.
   llvm::SmallVector<Expr*, 4> Exprs(NumExprs);
-  for (unsigned i = 0; i < NumExprs; ++i)
-    Exprs[i] = D.ReadOwnedPtr<Expr>(C);
-
+  D.BatchReadOwnedPtrs(NumExprs, Exprs.begin(), C);
   return new ShuffleVectorExpr(Exprs.begin(), NumExprs, T, BL, RP);
 }
 
@@ -848,19 +846,37 @@
   S.Emit(getType());
   S.Emit(BuiltinLoc);
   S.Emit(RParenLoc);
-  S.EmitOwnedPtr(getCond());
-  S.EmitOwnedPtr(getLHS());
-  S.EmitOwnedPtr(getRHS());
+  S.BatchEmitOwnedPtrs((unsigned) END_EXPR, &SubExprs[0]);
 }
 
 ChooseExpr* ChooseExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) {
   QualType T = QualType::ReadVal(D);
   SourceLocation BL = SourceLocation::ReadVal(D);
   SourceLocation RP = SourceLocation::ReadVal(D);
-  Expr *Cond = D.ReadOwnedPtr<Expr>(C);
-  Expr *LHS = D.ReadOwnedPtr<Expr>(C);
-  Expr *RHS = D.ReadOwnedPtr<Expr>(C);
-  return new ChooseExpr(BL, Cond, LHS, RHS, T, RP);
+  ChooseExpr *CE = new ChooseExpr(BL, 0, 0, 0, T, RP);
+  D.BatchReadOwnedPtrs((unsigned) END_EXPR, &CE->SubExprs[0], C);
+  return CE;
+}
+
+void OverloadExpr::EmitImpl(llvm::Serializer& S) const {
+  S.Emit(getType());
+  S.Emit(BuiltinLoc);
+  S.Emit(RParenLoc);
+  S.EmitInt(FnIndex);
+  S.EmitInt(NumExprs);
+  S.BatchEmitOwnedPtrs(NumExprs, &SubExprs[0]);
+}
+
+OverloadExpr* OverloadExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) {
+  QualType T = QualType::ReadVal(D);
+  SourceLocation BL = SourceLocation::ReadVal(D);
+  SourceLocation RP = SourceLocation::ReadVal(D);
+  unsigned FnIndex = D.ReadInt();
+  unsigned NumExprs = D.ReadInt();
+  // FIXME: Avoid extra allocation.
+  llvm::SmallVector<Expr*, 4> Exprs(NumExprs);
+  D.BatchReadOwnedPtrs(NumExprs, Exprs.begin(), C);
+  return new OverloadExpr(Exprs.begin(), NumExprs, FnIndex, T, BL, RP);
 }
 
 void VAArgExpr::EmitImpl(llvm::Serializer& S) const {





More information about the cfe-commits mailing list