[cfe-commits] r44143 - in /cfe/trunk: AST/DeclSerialization.cpp AST/TypeSerialization.cpp include/clang/AST/Type.h

Ted Kremenek kremenek at apple.com
Wed Nov 14 14:51:05 PST 2007


Author: kremenek
Date: Wed Nov 14 16:51:02 2007
New Revision: 44143

URL: http://llvm.org/viewvc/llvm-project?rev=44143&view=rev
Log:
Added QualType::ReadBackpatch to allow QualType initialization with
backpatching. This original was available, but then we removed it. It is back
again to help with deserialization of FieldDecls. Because FieldDecls are
currently owned by RecordDecls, which are owned by a TagType, the type of the
FieldDecl may not be deserialized prior to deserializing the FieldDecl. Thus
backpatching solves the problem of constructing a FieldDecl that references a
type that has not yet been deserialized.

Simplified serialization of TagType to not require passing in the
SerializedPtrID. Registration of the materialized type object is done after
the CreateImpl method returns (as with other types).

Modified:
    cfe/trunk/AST/DeclSerialization.cpp
    cfe/trunk/AST/TypeSerialization.cpp
    cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/AST/DeclSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/DeclSerialization.cpp?rev=44143&r1=44142&r2=44143&view=diff

==============================================================================
--- cfe/trunk/AST/DeclSerialization.cpp (original)
+++ cfe/trunk/AST/DeclSerialization.cpp Wed Nov 14 16:51:02 2007
@@ -295,8 +295,8 @@
 }
 
 FieldDecl* FieldDecl::CreateImpl(Deserializer& D) {
-  QualType DeclType = QualType::ReadVal(D);
-  FieldDecl* decl = new FieldDecl(SourceLocation(),NULL,DeclType);
+  FieldDecl* decl = new FieldDecl(SourceLocation(),NULL,QualType());
+  decl->DeclType.ReadBackpatch(D);  
   decl->ReadInRec(D);
   decl->BitWidth = D.ReadOwnedPtr<Expr>();
   return decl;

Modified: cfe/trunk/AST/TypeSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/TypeSerialization.cpp?rev=44143&r1=44142&r2=44143&view=diff

==============================================================================
--- cfe/trunk/AST/TypeSerialization.cpp (original)
+++ cfe/trunk/AST/TypeSerialization.cpp Wed Nov 14 16:51:02 2007
@@ -35,6 +35,11 @@
   return Q;
 }
 
+void QualType::ReadBackpatch(Deserializer& D) {
+  D.ReadUIntPtr(ThePtr,true);
+  ThePtr |= D.ReadInt();
+}
+
 //===----------------------------------------------------------------------===//
 // Type Serialization: Dispatch code to handle specific types.
 //===----------------------------------------------------------------------===//
@@ -87,7 +92,7 @@
       break;
       
     case Type::Tagged:
-      TagType::CreateImpl(Context,PtrID,D);
+      D.RegisterPtr(PtrID,TagType::CreateImpl(Context,D));
       break;
       
     case Type::TypeName:
@@ -193,18 +198,13 @@
   S.EmitOwnedPtr(getDecl());
 }
 
-Type* TagType::CreateImpl(ASTContext& Context, SerializedPtrID& PtrID,
-                          Deserializer& D) {
-  
+Type* TagType::CreateImpl(ASTContext& Context, Deserializer& D) {
   std::vector<Type*>& Types = 
     const_cast<std::vector<Type*>&>(Context.getTypes());
   
   TagType* T = new TagType(NULL,QualType());
   Types.push_back(T);
   
-  // Forward register the type pointer before deserializing the decl.
-  D.RegisterPtr(PtrID,T);
-
   // Deserialize the decl.
   T->decl = cast<TagDecl>(D.ReadOwnedPtr<Decl>());
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Nov 14 16:51:02 2007
@@ -32,6 +32,7 @@
   class TagDecl;
   class RecordDecl;
   class EnumDecl;
+  class FieldDecl;
   class ObjcInterfaceDecl;
   class ObjcProtocolDecl;
   class ObjcMethodDecl;
@@ -161,6 +162,10 @@
   
   /// Read - Deserialize a QualType from Bitcode.
   static QualType ReadVal(llvm::Deserializer& D);
+  
+private:
+  void ReadBackpatch(llvm::Deserializer& D);
+  friend class FieldDecl;
 };
 
 } // end clang.
@@ -888,8 +893,7 @@
   
 protected:  
   virtual void EmitImpl(llvm::Serializer& S) const;
-  static Type* CreateImpl(ASTContext& Context, llvm::SerializedPtrID& PtrID, 
-                          llvm::Deserializer& D);
+  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
   friend class Type;
 };
 





More information about the cfe-commits mailing list