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

Ted Kremenek kremenek at apple.com
Fri Oct 26 13:24:35 PDT 2007


Author: kremenek
Date: Fri Oct 26 15:24:35 2007
New Revision: 43397

URL: http://llvm.org/viewvc/llvm-project?rev=43397&view=rev
Log:
Added skeleton implementation of serialization for types (not complete).

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

Added: cfe/trunk/AST/TypeSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/TypeSerialization.cpp?rev=43397&view=auto

==============================================================================
--- cfe/trunk/AST/TypeSerialization.cpp (added)
+++ cfe/trunk/AST/TypeSerialization.cpp Fri Oct 26 15:24:35 2007
@@ -0,0 +1,127 @@
+//===--- TypeSerialization.cpp - Serialization of Decls ---------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Ted Kremenek and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This files defines methods that implement bitcode serialization for Types.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/AST/Type.h"
+#include "llvm/Bitcode/Serialize.h"
+#include "llvm/Bitcode/Deserialize.h"
+
+using namespace clang;
+
+void QualType::Emit(llvm::Serializer& S) const {
+  S.EmitPtr(getAsOpaquePtr());
+  S.EmitInt(getQualifiers());
+}
+
+void QualType::Read(llvm::Deserializer& D) {
+  D.ReadPtr(ThePtr);
+  ThePtr |= D.ReadInt();
+}
+
+/*  FIXME: Either remove this method or complete it.
+
+void Type::Emit(llvm::Serializer& S) {
+  switch (getTypeClass()) {
+    default:
+      assert (false && "Serialization for type class not implemented.");
+      break;
+      
+    case Type::Builtin:
+      cast<BuiltinType>(this)->Emit(S);
+      break;
+  }
+}
+ */
+
+void Type::EmitTypeInternal(llvm::Serializer& S) const {
+  S.Emit(CanonicalType);
+}
+
+void Type::ReadTypeInternal(llvm::Deserializer& D) {
+  D.Read(CanonicalType);
+}
+
+void ComplexType::Emit(llvm::Serializer& S) const {
+  EmitTypeInternal(S);
+  S.Emit(ElementType);
+}
+
+ComplexType* ComplexType::Materialize(llvm::Deserializer& D) {
+  ComplexType* T = new ComplexType(QualType(),QualType());
+  T->ReadTypeInternal(D);
+  D.Read(T->ElementType);
+  return T;
+}
+
+void PointerType::Emit(llvm::Serializer& S) const {
+  EmitTypeInternal(S);
+  S.Emit(PointeeType);
+}
+
+PointerType* PointerType::Materialize(llvm::Deserializer& D) {
+  PointerType* T = new PointerType(QualType(),QualType());
+  T->ReadTypeInternal(D);
+  D.Read(T->PointeeType);
+  return T;
+}
+
+void ReferenceType::Emit(llvm::Serializer& S) const {
+  EmitTypeInternal(S);
+  S.Emit(ReferenceeType);
+}
+
+ReferenceType* ReferenceType::Materialize(llvm::Deserializer& D) {
+  ReferenceType* T = new ReferenceType(QualType(),QualType());
+  T->ReadTypeInternal(D);
+  D.Read(T->ReferenceeType);
+  return T;
+}
+
+void ArrayType::EmitArrayTypeInternal(llvm::Serializer& S) const {
+  EmitTypeInternal(S);
+  S.Emit(ElementType);
+  S.EmitInt(SizeModifier);
+  S.EmitInt(IndexTypeQuals);
+}
+
+void ArrayType::ReadArrayTypeInternal(llvm::Deserializer& D) {
+  ReadTypeInternal(D);
+  D.Read(ElementType);
+  SizeModifier = static_cast<ArraySizeModifier>(D.ReadInt());
+  IndexTypeQuals = D.ReadInt();
+}
+
+void ConstantArrayType::Emit(llvm::Serializer& S) const {
+#if 0
+  // FIXME: APInt serialization
+  S.Emit(Size);
+#endif
+  EmitArrayTypeInternal(S);
+}
+
+ConstantArrayType* ConstantArrayType::Materialize(llvm::Deserializer& D) {
+#if 0
+  llvm::APInt x = S.ReadVal<llvm::APInt>(D);
+  
+  // "Default" construct the array.
+  ConstantArrayType* T =
+    new ConstantArrayType(QualType(), QualType(), x, ArrayType::Normal, 0);
+  
+  // Deserialize the internal values.
+  T->ReadArrayTypeInternal(D);
+
+  return T;
+#else
+  return NULL;
+#endif
+
+}

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

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Oct 26 15:24:35 2007
@@ -17,6 +17,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/Bitcode/SerializationFwd.h"
 
 using llvm::isa;
 using llvm::cast;
@@ -153,6 +154,17 @@
   /// appropriate type qualifiers on it.
   inline QualType getCanonicalType() const;
   
+  /// Emit - Serialize a QualType using a Bitcode Serializer.
+  void Emit(llvm::Serializer& S) const;
+  
+  /// Read - Deserialize a QualType using a Bitcode Deserializer.  This
+  ///  deserialization requires that a QualType be default constructed
+  ///  first.  This is because internally the deserialization relies on
+  ///  pointer backpatching performed by the Deserializer.  Deserialization
+  ///  of a QualType should only be done on an instance of QualType that
+  ///  exists, in place, within its containing object.
+  void Read(llvm::Deserializer& D);
+  
 private:
 };
 
@@ -169,7 +181,8 @@
 };
 template<> struct simplify_type< ::clang::QualType>
   : public simplify_type<const ::clang::QualType> {};
-}
+  
+} // end namespace llvm
 
 namespace clang {
 
@@ -223,6 +236,10 @@
     : CanonicalType(Canonical.isNull() ? QualType(this_(),0) : Canonical), TC(tc){}
   virtual ~Type();
   friend class ASTContext;
+  
+  void EmitTypeInternal(llvm::Serializer& S) const;
+  void ReadTypeInternal(llvm::Deserializer& D);
+  
 public:
   TypeClass getTypeClass() const { return static_cast<TypeClass>(TC); }
   
@@ -359,6 +376,8 @@
   
   static bool classof(const Type *T) { return T->getTypeClass() == Builtin; }
   static bool classof(const BuiltinType *) { return true; }
+  
+  void Emit(llvm::Serializer& S) const;
 };
 
 /// ComplexType - C99 6.2.5p11 - Complex values.  This supports the C99 complex
@@ -385,6 +404,9 @@
   
   static bool classof(const Type *T) { return T->getTypeClass() == Complex; }
   static bool classof(const ComplexType *) { return true; }
+  
+  void Emit(llvm::Serializer& S) const;
+  static ComplexType* Materialize(llvm::Deserializer& D);
 };
 
 
@@ -412,6 +434,9 @@
   
   static bool classof(const Type *T) { return T->getTypeClass() == Pointer; }
   static bool classof(const PointerType *) { return true; }
+  
+  void Emit(llvm::Serializer& S) const;
+  static PointerType* Materialize(llvm::Deserializer& D);
 };
 
 /// ReferenceType - C++ 8.3.2 - Reference Declarators.
@@ -436,6 +461,9 @@
 
   static bool classof(const Type *T) { return T->getTypeClass() == Reference; }
   static bool classof(const ReferenceType *) { return true; }
+  
+  void Emit(llvm::Serializer& S) const;
+  static ReferenceType* Materialize(llvm::Deserializer& D);
 };
 
 /// ArrayType - C99 6.7.5.2 - Array Declarators.
@@ -482,6 +510,10 @@
            T->getTypeClass() == VariableArray;
   }
   static bool classof(const ArrayType *) { return true; }
+  
+protected:
+  void EmitArrayTypeInternal(llvm::Serializer& S) const;
+  void ReadArrayTypeInternal(llvm::Deserializer& S);
 };
 
 class ConstantArrayType : public ArrayType, public llvm::FoldingSetNode {
@@ -519,6 +551,9 @@
     return T->getTypeClass() == ConstantArray; 
   }
   static bool classof(const ConstantArrayType *) { return true; }
+  
+  void Emit(llvm::Serializer& S) const;
+  static ConstantArrayType* Materialize(llvm::Deserializer& D);
 };
 
 // FIXME: VariableArrayType's aren't uniqued (since expressions aren't).





More information about the cfe-commits mailing list