2007-10-27 00:24:35 +04:00
|
|
|
//===--- TypeSerialization.cpp - Serialization of Decls ---------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 22:59:25 +03:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-10-27 00:24:35 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2008-03-06 13:40:09 +03:00
|
|
|
// This file defines methods that implement bitcode serialization for Types.
|
2007-10-27 00:24:35 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Type.h"
|
2007-10-31 20:50:23 +03:00
|
|
|
#include "clang/AST/Expr.h"
|
2007-11-14 01:02:55 +03:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2007-10-27 00:24:35 +04:00
|
|
|
#include "llvm/Bitcode/Serialize.h"
|
|
|
|
#include "llvm/Bitcode/Deserialize.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
2007-11-14 01:02:55 +03:00
|
|
|
using llvm::Serializer;
|
|
|
|
using llvm::Deserializer;
|
|
|
|
using llvm::SerializedPtrID;
|
2007-10-27 00:24:35 +04:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
|
|
|
|
void QualType::Emit(Serializer& S) const {
|
2007-11-15 02:35:01 +03:00
|
|
|
S.EmitPtr(getTypePtr());
|
2008-02-20 23:55:12 +03:00
|
|
|
S.EmitInt(getCVRQualifiers());
|
2007-10-27 00:24:35 +04:00
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
QualType QualType::ReadVal(Deserializer& D) {
|
|
|
|
QualType Q;
|
|
|
|
D.ReadUIntPtr(Q.ThePtr,false);
|
|
|
|
Q.ThePtr |= D.ReadInt();
|
|
|
|
return Q;
|
2007-10-27 00:24:35 +04:00
|
|
|
}
|
|
|
|
|
2007-11-15 01:51:02 +03:00
|
|
|
void QualType::ReadBackpatch(Deserializer& D) {
|
|
|
|
D.ReadUIntPtr(ThePtr,true);
|
|
|
|
ThePtr |= D.ReadInt();
|
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type Serialization: Dispatch code to handle specific types.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-10-27 03:52:52 +04:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
void Type::Emit(Serializer& S) const {
|
|
|
|
S.EmitInt(getTypeClass());
|
|
|
|
S.EmitPtr(this);
|
|
|
|
|
|
|
|
if (!isa<BuiltinType>(this))
|
|
|
|
EmitImpl(S);
|
2007-10-27 03:52:52 +04:00
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
void Type::EmitImpl(Serializer& S) const {
|
|
|
|
assert (false && "Serializization for type not supported.");
|
|
|
|
}
|
2007-10-27 00:24:35 +04:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
void Type::Create(ASTContext& Context, unsigned i, Deserializer& D) {
|
|
|
|
Type::TypeClass K = static_cast<Type::TypeClass>(D.ReadInt());
|
|
|
|
SerializedPtrID PtrID = D.ReadPtrID();
|
|
|
|
|
|
|
|
switch (K) {
|
2007-10-27 00:24:35 +04:00
|
|
|
default:
|
2007-11-14 01:02:55 +03:00
|
|
|
assert (false && "Deserialization for type not supported.");
|
2007-10-27 00:24:35 +04:00
|
|
|
break;
|
2007-11-14 01:02:55 +03:00
|
|
|
|
2007-10-27 00:24:35 +04:00
|
|
|
case Type::Builtin:
|
2007-11-14 01:02:55 +03:00
|
|
|
assert (i < Context.getTypes().size());
|
|
|
|
assert (isa<BuiltinType>(Context.getTypes()[i]));
|
|
|
|
D.RegisterPtr(PtrID,Context.getTypes()[i]);
|
2007-10-27 00:24:35 +04:00
|
|
|
break;
|
2007-11-14 01:02:55 +03:00
|
|
|
|
2008-02-04 05:31:56 +03:00
|
|
|
case Type::ASQual:
|
|
|
|
D.RegisterPtr(PtrID,ASQualType::CreateImpl(Context,D));
|
|
|
|
break;
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
case Type::Complex:
|
|
|
|
D.RegisterPtr(PtrID,ComplexType::CreateImpl(Context,D));
|
|
|
|
break;
|
|
|
|
|
2007-11-14 03:17:21 +03:00
|
|
|
case Type::ConstantArray:
|
|
|
|
D.RegisterPtr(PtrID,ConstantArrayType::CreateImpl(Context,D));
|
2007-11-14 22:33:01 +03:00
|
|
|
break;
|
2007-11-14 03:17:21 +03:00
|
|
|
|
2007-11-14 03:38:50 +03:00
|
|
|
case Type::FunctionNoProto:
|
|
|
|
D.RegisterPtr(PtrID,FunctionTypeNoProto::CreateImpl(Context,D));
|
|
|
|
break;
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
case Type::FunctionProto:
|
|
|
|
D.RegisterPtr(PtrID,FunctionTypeProto::CreateImpl(Context,D));
|
|
|
|
break;
|
|
|
|
|
2008-02-15 21:16:39 +03:00
|
|
|
case Type::IncompleteArray:
|
|
|
|
D.RegisterPtr(PtrID,IncompleteArrayType::CreateImpl(Context,D));
|
|
|
|
break;
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
case Type::Pointer:
|
|
|
|
D.RegisterPtr(PtrID,PointerType::CreateImpl(Context,D));
|
2007-11-14 03:03:56 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::Tagged:
|
2007-11-15 01:51:02 +03:00
|
|
|
D.RegisterPtr(PtrID,TagType::CreateImpl(Context,D));
|
2007-11-14 03:03:56 +03:00
|
|
|
break;
|
2007-11-14 03:27:46 +03:00
|
|
|
|
|
|
|
case Type::TypeName:
|
|
|
|
D.RegisterPtr(PtrID,TypedefType::CreateImpl(Context,D));
|
|
|
|
break;
|
2007-11-14 03:31:36 +03:00
|
|
|
|
|
|
|
case Type::VariableArray:
|
|
|
|
D.RegisterPtr(PtrID,VariableArrayType::CreateImpl(Context,D));
|
|
|
|
break;
|
2007-10-27 00:24:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-04 05:31:56 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ASQualType
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ASQualType::EmitImpl(Serializer& S) const {
|
2008-02-20 23:55:12 +03:00
|
|
|
S.EmitPtr(getBaseType());
|
2008-02-04 05:31:56 +03:00
|
|
|
S.EmitInt(getAddressSpace());
|
|
|
|
}
|
|
|
|
|
|
|
|
Type* ASQualType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
QualType BaseTy = QualType::ReadVal(D);
|
|
|
|
unsigned AddressSpace = D.ReadInt();
|
|
|
|
return Context.getASQualType(BaseTy, AddressSpace).getTypePtr();
|
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ComplexType
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-10-27 00:24:35 +04:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
void ComplexType::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getElementType());
|
2007-10-27 00:24:35 +04:00
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
Type* ComplexType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
return Context.getComplexType(QualType::ReadVal(D)).getTypePtr();
|
2007-10-27 00:24:35 +04:00
|
|
|
}
|
|
|
|
|
2007-11-14 03:17:21 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ConstantArray
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void ConstantArrayType::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getElementType());
|
|
|
|
S.EmitInt(getSizeModifier());
|
|
|
|
S.EmitInt(getIndexTypeQualifier());
|
|
|
|
S.Emit(Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
Type* ConstantArrayType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
QualType ElTy = QualType::ReadVal(D);
|
|
|
|
ArraySizeModifier am = static_cast<ArraySizeModifier>(D.ReadInt());
|
|
|
|
unsigned ITQ = D.ReadInt();
|
|
|
|
|
|
|
|
llvm::APInt Size;
|
|
|
|
D.Read(Size);
|
|
|
|
|
|
|
|
return Context.getConstantArrayType(ElTy,Size,am,ITQ).getTypePtr();
|
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-11-14 03:38:50 +03:00
|
|
|
// FunctionTypeNoProto
|
2007-11-14 01:02:55 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-10-27 00:24:35 +04:00
|
|
|
|
2007-11-14 22:33:01 +03:00
|
|
|
void FunctionTypeNoProto::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getResultType());
|
|
|
|
}
|
|
|
|
|
|
|
|
Type* FunctionTypeNoProto::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
return Context.getFunctionTypeNoProto(QualType::ReadVal(D)).getTypePtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// FunctionTypeProto
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
void FunctionTypeProto::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getResultType());
|
|
|
|
S.EmitBool(isVariadic());
|
|
|
|
S.EmitInt(getNumArgs());
|
2007-10-27 00:24:35 +04:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
for (arg_type_iterator I=arg_type_begin(), E=arg_type_end(); I!=E; ++I)
|
|
|
|
S.Emit(*I);
|
2007-10-31 20:50:23 +03:00
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
Type* FunctionTypeProto::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
QualType ResultType = QualType::ReadVal(D);
|
|
|
|
bool isVariadic = D.ReadBool();
|
|
|
|
unsigned NumArgs = D.ReadInt();
|
2007-10-31 20:50:23 +03:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
llvm::SmallVector<QualType,15> Args;
|
2007-11-14 03:38:50 +03:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
for (unsigned j = 0; j < NumArgs; ++j)
|
|
|
|
Args.push_back(QualType::ReadVal(D));
|
2007-11-14 03:38:50 +03:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
return Context.getFunctionType(ResultType,&*Args.begin(),
|
2007-11-14 03:38:50 +03:00
|
|
|
NumArgs,isVariadic).getTypePtr();
|
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PointerType
|
|
|
|
//===----------------------------------------------------------------------===//
|
2007-10-27 23:58:08 +04:00
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
void PointerType::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getPointeeType());
|
2007-10-29 00:21:04 +03:00
|
|
|
}
|
|
|
|
|
2007-11-14 01:02:55 +03:00
|
|
|
Type* PointerType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
return Context.getPointerType(QualType::ReadVal(D)).getTypePtr();
|
2007-10-29 00:21:04 +03:00
|
|
|
}
|
2007-11-14 03:03:56 +03:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TagType
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void TagType::EmitImpl(Serializer& S) const {
|
2007-11-14 11:06:37 +03:00
|
|
|
S.EmitOwnedPtr(getDecl());
|
2007-11-14 03:03:56 +03:00
|
|
|
}
|
|
|
|
|
2007-11-15 01:51:02 +03:00
|
|
|
Type* TagType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
2007-11-14 11:06:37 +03:00
|
|
|
std::vector<Type*>& Types =
|
|
|
|
const_cast<std::vector<Type*>&>(Context.getTypes());
|
|
|
|
|
|
|
|
TagType* T = new TagType(NULL,QualType());
|
|
|
|
Types.push_back(T);
|
|
|
|
|
|
|
|
// Deserialize the decl.
|
2008-04-08 01:55:54 +04:00
|
|
|
T->decl = cast<TagDecl>(D.ReadOwnedPtr<Decl>(Context));
|
2007-11-14 11:06:37 +03:00
|
|
|
|
2007-11-14 03:03:56 +03:00
|
|
|
return T;
|
|
|
|
}
|
2007-11-14 03:27:46 +03:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// TypedefType
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void TypedefType::EmitImpl(Serializer& S) const {
|
2008-07-27 07:47:53 +04:00
|
|
|
S.Emit(getCanonicalTypeInternal());
|
2007-11-14 03:27:46 +03:00
|
|
|
S.EmitPtr(Decl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Type* TypedefType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
std::vector<Type*>& Types =
|
|
|
|
const_cast<std::vector<Type*>&>(Context.getTypes());
|
|
|
|
|
2008-07-27 07:47:53 +04:00
|
|
|
TypedefType* T = new TypedefType(Type::TypeName, NULL, QualType::ReadVal(D));
|
2007-11-14 03:27:46 +03:00
|
|
|
Types.push_back(T);
|
|
|
|
|
|
|
|
D.ReadPtr(T->Decl); // May be backpatched.
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2007-11-14 03:31:36 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// VariableArrayType
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void VariableArrayType::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getElementType());
|
|
|
|
S.EmitInt(getSizeModifier());
|
|
|
|
S.EmitInt(getIndexTypeQualifier());
|
|
|
|
S.EmitOwnedPtr(SizeExpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
Type* VariableArrayType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
QualType ElTy = QualType::ReadVal(D);
|
|
|
|
ArraySizeModifier am = static_cast<ArraySizeModifier>(D.ReadInt());
|
|
|
|
unsigned ITQ = D.ReadInt();
|
2008-04-08 01:55:54 +04:00
|
|
|
Expr* SizeExpr = D.ReadOwnedPtr<Expr>(Context);
|
2007-11-14 03:31:36 +03:00
|
|
|
|
|
|
|
return Context.getVariableArrayType(ElTy,SizeExpr,am,ITQ).getTypePtr();
|
|
|
|
}
|
2008-02-15 21:16:39 +03:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IncompleteArrayType
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void IncompleteArrayType::EmitImpl(Serializer& S) const {
|
|
|
|
S.Emit(getElementType());
|
|
|
|
S.EmitInt(getSizeModifier());
|
|
|
|
S.EmitInt(getIndexTypeQualifier());
|
|
|
|
}
|
|
|
|
|
|
|
|
Type* IncompleteArrayType::CreateImpl(ASTContext& Context, Deserializer& D) {
|
|
|
|
QualType ElTy = QualType::ReadVal(D);
|
|
|
|
ArraySizeModifier am = static_cast<ArraySizeModifier>(D.ReadInt());
|
|
|
|
unsigned ITQ = D.ReadInt();
|
|
|
|
|
|
|
|
return Context.getIncompleteArrayType(ElTy,am,ITQ).getTypePtr();
|
|
|
|
}
|