From: Ted Kremenek Date: Wed, 14 Nov 2007 22:51:02 +0000 (+0000) Subject: Added QualType::ReadBackpatch to allow QualType initialization with X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=21d50e12c3c412d8457071dc419363b7a7e8b855;p=clang 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). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44143 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/DeclSerialization.cpp b/AST/DeclSerialization.cpp index 555c33edf6..208e81ca0f 100644 --- a/AST/DeclSerialization.cpp +++ b/AST/DeclSerialization.cpp @@ -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(); return decl; diff --git a/AST/TypeSerialization.cpp b/AST/TypeSerialization.cpp index 08d3194f19..e46abe4df1 100644 --- a/AST/TypeSerialization.cpp +++ b/AST/TypeSerialization.cpp @@ -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& Types = const_cast&>(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(D.ReadOwnedPtr()); diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index c42a1b00c9..d6dc5f7d6b 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -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; };