Rewrote type serialization to used the same methodology as we do for Decls.
Removed tons of dead code in ASTContext concerning how types use to be
serialized.
Removed serialization methods from QualType that are no longer used.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44070 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/ASTContext.cpp b/AST/ASTContext.cpp
index 1438992..132224c 100644
--- a/AST/ASTContext.cpp
+++ b/AST/ASTContext.cpp
@@ -1319,59 +1319,6 @@
   return true; // should never get here...
 }
 
-
-template <typename T> static inline
-void EmitSet(const llvm::FoldingSet<T>& set, llvm::Serializer& S) {
-  S.EmitInt(set.size());
-  
-  for (typename llvm::FoldingSet<T>::const_iterator I=set.begin(), E=set.end();
-       I!=E; ++I)
-    S.EmitOwnedPtr(&*I);
-}
-
-template <typename T> static inline
-void ReadSet(llvm::FoldingSet<T>& set, std::vector<Type*>& V, 
-             llvm::Deserializer& D) {
-  
-  unsigned size = D.ReadInt();
-
-  for (unsigned i = 0 ; i < size; ++i) {
-    T* t = D.ReadOwnedPtr<T>();
-    set.GetOrInsertNode(t);
-    V.push_back(t);
-  }
-}
-
-template <typename T> static inline
-void EmitVector(const std::vector<T*>& V, llvm::Serializer& S) {
-  S.EmitInt(V.size());
-
-  for (typename std::vector<T*>::const_iterator I=V.begin(),E=V.end(); I!=E;++I)
-    S.EmitOwnedPtr(*I);
-}
- 
-template <typename T> static inline
-void ReadVector(std::vector<T*>& V, std::vector<Type*>& Types, 
-                llvm::Deserializer& D) {
-  
-  unsigned size = D.ReadInt();
-  V.reserve(size);
-  
-  for (unsigned i = 0 ; i < size ; ++i) {
-    T* t = D.Create<T>();
-    V.push_back(t);
-    Types.push_back(t);
-  }
-}
-
-static inline void EmitBuiltin(llvm::Serializer& S, QualType Q) {
-  S.EmitPtr(Q.getTypePtr());  
-}
-
-static inline void RegisterBuiltin(llvm::Deserializer& D, QualType Q) {
-  D.RegisterPtr(Q.getTypePtr());
-}
-
 /// Emit - Serialize an ASTContext object to Bitcode.
 void ASTContext::Emit(llvm::Serializer& S) const {
   S.EmitRef(SourceMgr);
@@ -1383,131 +1330,10 @@
   // when we reconstitute the ASTContext object.
   S.EmitInt(Types.size());
   
-  for (std::vector<Type*>::const_iterator I=Types.begin(), E=Types.end();
-         I!=E; ++I) {
-    
-    Type* t = *I;    
-    Type::TypeClass k = t->getTypeClass();
-    
-    S.EmitInt(k);
-    
-    switch (k) {
-      default:
-        assert (false && "Serialization for type not supported.");
-        break;
-      
-      case Type::Builtin:
-        break;
-        
-      case Type::Complex:
-        S.Emit(cast<ComplexType>(t)->getElementType());
-        break;
-        
-      case Type::Pointer:
-        S.Emit(cast<PointerType>(t)->getPointeeType());
-        break;
-        
-      case Type::FunctionProto: {
-        FunctionTypeProto& FT = *cast<FunctionTypeProto>(t);
-        
-        S.Emit(FT.getResultType());
-        S.Emit(FT.isVariadic());
-        S.Emit(FT.getNumArgs());
+  for (std::vector<Type*>::const_iterator I=Types.begin(), E=Types.end(); 
+                                          I!=E;++I)    
+    (*I)->Emit(S);
 
-        for (FunctionTypeProto::arg_type_iterator
-              I=FT.arg_type_begin(), E=FT.arg_type_end(); I!=E; ++I)
-          S.Emit(*I);
-
-        break;
-      }
-    }
-    
-    S.EmitPtr(t);
-  }
-  
-  
-  // Emit pointers to builtin types.  Although these objects will be
-  // reconsituted automatically when ASTContext is created, any pointers to them
-  // will not be (and will need to be patched).  Thus we must register them 
-  // with the Serializer anyway as pointed-to-objects, even if we won't 
-  // serialize them out using EmitOwnedPtr.  This "registration" will then
-  // be used by the Deserializer to backpatch references to the builtins.
-#if 0
-  {
-  EmitBuiltin(S,VoidTy);
-  EmitBuiltin(S,BoolTy);
-  EmitBuiltin(S,CharTy);
-  EmitBuiltin(S,SignedCharTy);
-  EmitBuiltin(S,ShortTy);
-  EmitBuiltin(S,IntTy);
-  EmitBuiltin(S,LongTy);
-  EmitBuiltin(S,LongLongTy);
-  EmitBuiltin(S,UnsignedCharTy);
-  EmitBuiltin(S,UnsignedShortTy);
-  EmitBuiltin(S,UnsignedIntTy);
-  EmitBuiltin(S,UnsignedLongTy);
-  EmitBuiltin(S,UnsignedLongLongTy);
-  EmitBuiltin(S,FloatTy);
-  EmitBuiltin(S,DoubleTy);
-  EmitBuiltin(S,LongDoubleTy);
-  EmitBuiltin(S,FloatComplexTy);
-  EmitBuiltin(S,DoubleComplexTy);
-  EmitBuiltin(S,LongDoubleComplexTy);
-  EmitBuiltin(S,VoidPtrTy);
-
-  // Emit the remaining types.
-
-  assert (ComplexTypes.size() >= 3);
-  S.EmitInt(ComplexTypes.size() - 3);
-  
-  if (ComplexTypes.size() > 3) {
-    
-    for (llvm::FoldingSet<ComplexType>::const_iterator
-           I=ComplexTypes.begin(), E=ComplexTypes.end(); I!=E; ++I) {
-      
-      const ComplexType* T = &*I;
-    
-      if (T != FloatComplexTy.getTypePtr() &&
-          T != DoubleComplexTy.getTypePtr() &&
-          T != LongDoubleComplexTy.getTypePtr())
-        S.EmitOwnedPtr(&*I);
-    }
-  }
-  
-  assert (PointerTypes.size() >= 1);  
-  S.EmitInt(PointerTypes.size() - 1);
-  
-  if (PointerTypes.size() > 1) {
-    
-    for (llvm::FoldingSet<PointerType>::const_iterator
-         I=PointerTypes.begin(), E=PointerTypes.end(); I!=E; ++I) {
-      
-      const PointerType* T = &*I;
-      
-      if (T != VoidPtrTy.getTypePtr())
-        S.EmitOwnedPtr(&*I);
-    }
-  }
-  
-  EmitSet(ReferenceTypes, S);
-  EmitSet(ConstantArrayTypes, S);
-  EmitSet(IncompleteVariableArrayTypes, S);
-  EmitVector(CompleteVariableArrayTypes, S);
-  EmitSet(VectorTypes,S);
-  EmitSet(FunctionTypeNoProtos,S);
-  EmitSet(FunctionTypeProtos,S);
-  // FIXME: EmitSet(ObjcQualifiedInterfaceTypes,S);
-  
-  S.Emit(BuiltinVaListType);
-  }
-#endif
-// FIXME:  S.Emit(ObjcIdType);
-// FIXME:  S.EmitPtr(IdStructType);
-// FIXME:  S.Emit(ObjcProtoType);
- // FIXME:  S.EmitPtr(ProtoStructType);
- // FIXME: S.Emit(ObjcClassType);
-// FIXME:  S.EmitPtr(ClassStructType);
-// FIXME:  S.Emit(ObjcConstantStringType);
   // FIXME: S.EmitOwnedPtr(CFConstantStringTypeDecl);
 }
 
@@ -1521,106 +1347,9 @@
   
   ASTContext* A = new ASTContext(SM,t,idents,sels,size_reserve);
   
-  for (unsigned i = 0; i < size_reserve; ++i) {
-    Type::TypeClass K = static_cast<Type::TypeClass>(D.ReadInt());
-    
-    switch (K) {
-      default:
-        assert (false && "Deserializaton for type not supported.");
-        break;
-        
-      case Type::Builtin:
-        assert (i < A->Types.size());
-        assert (isa<BuiltinType>(A->Types[i]));
-        D.RegisterPtr(A->Types[i]);
-        break;
-        
-      case Type::Complex: {
-        QualType ElementType;
-        D.Read(ElementType);
-        D.RegisterPtr(A->getComplexType(ElementType).getTypePtr());
-        break;
-      }
-        
-      case Type::Pointer: {
-        QualType PointeeType;
-        D.Read(PointeeType);
-        D.RegisterPtr(A->getPointerType(PointeeType).getTypePtr());
-        break;
-      }
-        
-      case Type::FunctionProto: {
-        QualType ResultType;
-        D.Read(ResultType);
-        
-        bool isVariadic = D.ReadBool();
-        
-        unsigned NumArgs = D.ReadInt();        
-        llvm::SmallVector<QualType,15> Args;
-        for (unsigned j = 0; j < NumArgs; ++j) { 
-          QualType Q;
-          D.Read(Q);
-          Args.push_back(Q);
-        }
+  for (unsigned i = 0; i < size_reserve; ++i)
+    Type::Create(*A,i,D);
 
-        D.RegisterPtr(A->getFunctionType(ResultType,&*Args.begin(),
-                                         NumArgs,isVariadic).getTypePtr());
-                       
-        break;
-      }
-
-    }
-  }
-  
-  // Register the addresses of the BuiltinTypes with the Deserializer.
-#if 0
-  {
-  RegisterBuiltin(D,A->VoidTy);
-  RegisterBuiltin(D,A->BoolTy);
-  RegisterBuiltin(D,A->CharTy);
-  RegisterBuiltin(D,A->SignedCharTy);
-  RegisterBuiltin(D,A->ShortTy);
-  RegisterBuiltin(D,A->IntTy);
-  RegisterBuiltin(D,A->LongTy);
-  RegisterBuiltin(D,A->LongLongTy);
-  RegisterBuiltin(D,A->UnsignedCharTy);
-  RegisterBuiltin(D,A->UnsignedShortTy);
-  RegisterBuiltin(D,A->UnsignedIntTy);
-  RegisterBuiltin(D,A->UnsignedLongTy);
-  RegisterBuiltin(D,A->UnsignedLongLongTy);
-  RegisterBuiltin(D,A->FloatTy);
-  RegisterBuiltin(D,A->DoubleTy);
-  RegisterBuiltin(D,A->LongDoubleTy);
-  RegisterBuiltin(D,A->FloatComplexTy);
-  RegisterBuiltin(D,A->DoubleComplexTy);
-  RegisterBuiltin(D,A->LongDoubleComplexTy);
-  RegisterBuiltin(D,A->VoidPtrTy);
-
-  // Deserialize all other types.  
-  ReadSet<ComplexType>(A->ComplexTypes, A->Types, D);
-  ReadSet(A->PointerTypes, A->Types, D);
-  ReadSet(A->ReferenceTypes, A->Types, D);
-  ReadSet(A->ConstantArrayTypes, A->Types, D);
-  ReadSet(A->IncompleteVariableArrayTypes, A->Types, D);
-  ReadVector(A->CompleteVariableArrayTypes, A->Types, D);
-  ReadSet(A->VectorTypes, A->Types, D);
-  ReadSet(A->FunctionTypeNoProtos, A->Types, D);
-  ReadSet(A->FunctionTypeProtos, A->Types, D);
-  // ReadSet(A->ObjcQualifiedInterfaceTypes,D);
-
-
-  
-  D.Read(A->BuiltinVaListType);
-  }
-#endif
-  
-// FIXME:  D.Read(A->ObjcIdType);
-// FIXME:  D.ReadPtr(A->IdStructType);
-// FIXME:  D.Read(A->ObjcProtoType);
-// FIXME:  D.ReadPtr(A->ProtoStructType);
-// FIXME:  D.Read(A->ObjcClassType);
-// FIXME:  D.ReadPtr(A->ClassStructType);
-// FIXME:  D.Read(A->ObjcConstantStringType);
   // FIXME: A->CFConstantStringTypeDecl = D.ReadOwnedPtr<RecordDecl>();
   
   return A;