]> granicus.if.org Git - clang/commitdiff
Added QualType::ReadBackpatch to allow QualType initialization with
authorTed Kremenek <kremenek@apple.com>
Wed, 14 Nov 2007 22:51:02 +0000 (22:51 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 14 Nov 2007 22:51:02 +0000 (22:51 +0000)
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).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44143 91177308-0d34-0410-b5e6-96231b3b80d8

AST/DeclSerialization.cpp
AST/TypeSerialization.cpp
include/clang/AST/Type.h

index 555c33edf68d36a187f66bdbd9d6075945113cfd..208e81ca0f927a9cfedc8c9f28730e724768a24b 100644 (file)
@@ -295,8 +295,8 @@ void FieldDecl::EmitImpl(Serializer& S) const {
 }
 
 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;
index 08d3194f195b31c228a4a88b3e31ffdf437aca56..e46abe4df1d2a0036deb36bd14cac4a6c713dbf0 100644 (file)
@@ -35,6 +35,11 @@ QualType QualType::ReadVal(Deserializer& D) {
   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 @@ void Type::Create(ASTContext& Context, unsigned i, Deserializer& D) {
       break;
       
     case Type::Tagged:
-      TagType::CreateImpl(Context,PtrID,D);
+      D.RegisterPtr(PtrID,TagType::CreateImpl(Context,D));
       break;
       
     case Type::TypeName:
@@ -193,18 +198,13 @@ void TagType::EmitImpl(Serializer& S) const {
   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>());
 
index c42a1b00c9ce9823e9729682cc7f457f69eac619..d6dc5f7d6bcd41d9140e96d94ec9ece540e9eab4 100644 (file)
@@ -32,6 +32,7 @@ namespace clang {
   class TagDecl;
   class RecordDecl;
   class EnumDecl;
+  class FieldDecl;
   class ObjcInterfaceDecl;
   class ObjcProtocolDecl;
   class ObjcMethodDecl;
@@ -161,6 +162,10 @@ public:
   
   /// 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 @@ public:
   
 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;
 };