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

Ted Kremenek kremenek at apple.com
Wed Nov 14 00:06:37 PST 2007


Author: kremenek
Date: Wed Nov 14 02:06:37 2007
New Revision: 44106

URL: http://llvm.org/viewvc/llvm-project?rev=44106&view=rev
Log:
Implemented serialization of RecordDecls. Changed serialization of TagType to
have an owning pointer to the referred TagDecl. This should hopefully fix a
bug where TagDecls (including decls from structs, etc.) were not serialized.

Modified:
    cfe/trunk/AST/DeclSerialization.cpp
    cfe/trunk/AST/TypeSerialization.cpp
    cfe/trunk/include/clang/AST/Decl.h
    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=44106&r1=44105&r2=44106&view=diff

==============================================================================
--- cfe/trunk/AST/DeclSerialization.cpp (original)
+++ cfe/trunk/AST/DeclSerialization.cpp Wed Nov 14 02:06:37 2007
@@ -52,6 +52,9 @@
     case Function:
       return FunctionDecl::CreateImpl(D);
       
+    case Struct:
+      return RecordDecl::CreateImpl(k,D);
+      
     case Typedef:
       return TypedefDecl::CreateImpl(D);
   }
@@ -268,6 +271,46 @@
 }
 
 //===----------------------------------------------------------------------===//
+//      RecordDecl Serialization.
+//===----------------------------------------------------------------------===//
+
+void RecordDecl::EmitImpl(llvm::Serializer& S) const {
+  ScopedDecl::EmitInRec(S);
+  S.EmitBool(hasFlexibleArrayMember());
+  S.EmitSInt(getNumMembers());
+  if (getNumMembers() > 0) {
+    assert (Members);
+    S.BatchEmitOwnedPtrs((unsigned) getNumMembers(),
+                         (Decl**) &Members[0],getNextDeclarator());
+  }
+  else
+    ScopedDecl::EmitOutRec(S);
+}
+
+RecordDecl* RecordDecl::CreateImpl(Decl::Kind DK, Deserializer& D) {
+  RecordDecl* decl = new RecordDecl(DK,SourceLocation(),NULL,NULL);
+  
+  decl->ScopedDecl::ReadInRec(D);
+  decl->setHasFlexibleArrayMember(D.ReadBool());
+  decl->NumMembers = D.ReadSInt();
+  
+  if (decl->getNumMembers() > 0) {
+    Decl* next_declarator;
+    decl->Members = new FieldDecl*[(unsigned) decl->getNumMembers()];
+                              
+    D.BatchReadOwnedPtrs((unsigned) decl->getNumMembers(),
+                         (Decl**) &decl->Members[0],
+                         next_declarator);
+    
+    decl->setNextDeclarator(cast_or_null<ScopedDecl>(next_declarator));                             
+  }
+  else
+    decl->ScopedDecl::ReadOutRec(D);
+  
+  return decl;
+}
+
+//===----------------------------------------------------------------------===//
 //      TypedefDecl Serialization.
 //===----------------------------------------------------------------------===//
 

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

==============================================================================
--- cfe/trunk/AST/TypeSerialization.cpp (original)
+++ cfe/trunk/AST/TypeSerialization.cpp Wed Nov 14 02:06:37 2007
@@ -86,7 +86,7 @@
       break;
       
     case Type::Tagged:
-      D.RegisterPtr(PtrID,TagType::CreateImpl(Context,D));
+      TagType::CreateImpl(Context,PtrID,D);
       break;
       
     case Type::TypeName:
@@ -189,12 +189,24 @@
 //===----------------------------------------------------------------------===//
 
 void TagType::EmitImpl(Serializer& S) const {
-  S.EmitPtr(Decl);
+  S.EmitOwnedPtr(getDecl());
 }
 
-Type* TagType::CreateImpl(ASTContext& Context, Deserializer& D) {
-  TagType* T = cast<TagType>(Context.getTagDeclType(NULL).getTypePtr());
-  D.ReadPtr(T->Decl); // May be backpatched.  
+Type* TagType::CreateImpl(ASTContext& Context, SerializedPtrID& PtrID,
+                          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>());
+
   return T;
 }
 
@@ -215,7 +227,7 @@
   Types.push_back(T);
   
   D.ReadPtr(T->Decl); // May be backpatched.
-  
+  assert(false);
   return T;
 }
   

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Nov 14 02:06:37 2007
@@ -701,6 +701,15 @@
     return D->getKind() >= RecordFirst && D->getKind() <= RecordLast;
   }
   static bool classof(const RecordDecl *D) { return true; }
+
+protected:
+  /// EmitImpl - Serialize this TypedefDecl.  Called by Decl::Emit.
+  virtual void EmitImpl(llvm::Serializer& S) const;
+  
+  /// CreateImpl - Deserialize a TypedefDecl.  Called by Decl::Create.
+  static RecordDecl* CreateImpl(Kind DK, llvm::Deserializer& D);
+  
+  friend Decl* Decl::Create(llvm::Deserializer& D);
 };
 
 }  // end namespace clang

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Wed Nov 14 02:06:37 2007
@@ -874,12 +874,12 @@
 };
 
 class TagType : public Type {
-  TagDecl *Decl;
-  TagType(TagDecl *D, QualType can) : Type(Tagged, can), Decl(D) {}
+  TagDecl *decl;
+  TagType(TagDecl *D, QualType can) : Type(Tagged, can), decl(D) {}
   friend class ASTContext;  // ASTContext creates these.
 public:
     
-  TagDecl *getDecl() const { return Decl; }
+  TagDecl *getDecl() const { return decl; }
   
   virtual void getAsStringInternal(std::string &InnerString) const;
   
@@ -888,7 +888,8 @@
   
 protected:  
   virtual void EmitImpl(llvm::Serializer& S) const;
-  static Type* CreateImpl(ASTContext& Context, llvm::Deserializer& D);
+  static Type* CreateImpl(ASTContext& Context, llvm::SerializedPtrID& PtrID, 
+                          llvm::Deserializer& D);
   friend class Type;
 };
 





More information about the cfe-commits mailing list