[cfe-commits] r54410 - /cfe/trunk/lib/AST/StmtSerialization.cpp

Ted Kremenek kremenek at apple.com
Wed Aug 6 08:51:01 PDT 2008


Author: kremenek
Date: Wed Aug  6 10:50:59 2008
New Revision: 54410

URL: http://llvm.org/viewvc/llvm-project?rev=54410&view=rev
Log:
Reorder serialization methods.
When serializing DeclStmt, encode a bit indicating whether or not the DeclStmt owns the Decl.  This is an interim solution.

Modified:
    cfe/trunk/lib/AST/StmtSerialization.cpp

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

==============================================================================
--- cfe/trunk/lib/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/lib/AST/StmtSerialization.cpp Wed Aug  6 10:50:59 2008
@@ -470,11 +470,33 @@
 }
 
 void DeclStmt::EmitImpl(Serializer& S) const {
-  // FIXME: special handling for struct decls.
-  S.EmitOwnedPtr(getDecl());  
   S.Emit(StartLoc);
   S.Emit(EndLoc);
+
+  // FIXME: Clean up ownership of the Decl.
+  const ScopedDecl* d = getDecl();
+  
+  if (!S.isRegistered(d)) {
+    S.EmitBool(true);
+    S.EmitOwnedPtr(d);
+  }
+  else {
+    S.EmitBool(false);
+    S.EmitPtr(d);
+  }
+}
+    
+DeclStmt* DeclStmt::CreateImpl(Deserializer& D, ASTContext& C) {
+  SourceLocation StartLoc = SourceLocation::ReadVal(D);
+  SourceLocation EndLoc = SourceLocation::ReadVal(D);
+  
+  bool OwnsDecl = D.ReadBool();  
+  ScopedDecl* decl = cast<ScopedDecl>(OwnsDecl ? D.ReadOwnedPtr<Decl>(C)
+                                               : D.ReadPtr<Decl>());
+  
+  return new DeclStmt(decl, StartLoc, EndLoc);
 }
+    
 
 void DeclRefExpr::EmitImpl(Serializer& S) const {
   S.Emit(Loc);
@@ -520,24 +542,6 @@
   return new DeclRefExpr(decl,T,Loc);
 }
 
-void ObjCSuperRefExpr::EmitImpl(Serializer& S) const {
-  S.Emit(Loc);
-  S.Emit(getType());
-}
-
-ObjCSuperRefExpr* ObjCSuperRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
-  SourceLocation Loc = SourceLocation::ReadVal(D);
-  QualType T = QualType::ReadVal(D); 
-  return new ObjCSuperRefExpr(T, Loc); 
-}
-
-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);
-}
-
 void DefaultStmt::EmitImpl(Serializer& S) const {
   S.Emit(DefaultLoc);
   S.EmitOwnedPtr(getSubStmt());
@@ -1101,6 +1105,17 @@
   return new ObjCStringLiteral(String,T,L);
 }
 
+void ObjCSuperRefExpr::EmitImpl(Serializer& S) const {
+  S.Emit(Loc);
+  S.Emit(getType());
+}
+
+ObjCSuperRefExpr* ObjCSuperRefExpr::CreateImpl(Deserializer& D, ASTContext& C) {
+  SourceLocation Loc = SourceLocation::ReadVal(D);
+  QualType T = QualType::ReadVal(D); 
+  return new ObjCSuperRefExpr(T, Loc); 
+}
+
 //===----------------------------------------------------------------------===//
 //   C++ Serialization
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list