Rename Type::irtype to ctype for consistency with dmd and gdc

This commit is contained in:
Alexey Prokhin 2014-09-22 18:52:44 +04:00
parent 0f7a3b64c5
commit 66a392a5c2
14 changed files with 46 additions and 66 deletions

View file

@ -147,13 +147,7 @@ Type::Type(TY ty)
this->rto = NULL; this->rto = NULL;
this->arrayof = NULL; this->arrayof = NULL;
this->vtinfo = NULL; this->vtinfo = NULL;
#if IN_DMD
this->ctype = NULL; this->ctype = NULL;
#endif
#if IN_LLVM
this->irtype = NULL;
#endif
} }
const char *Type::kind() const char *Type::kind()
@ -419,9 +413,7 @@ Type *Type::nullAttributes()
t->swto = NULL; t->swto = NULL;
t->swcto = NULL; t->swcto = NULL;
t->vtinfo = NULL; t->vtinfo = NULL;
#if !IN_LLVM
t->ctype = NULL; t->ctype = NULL;
#endif
if (t->ty == Tstruct) ((TypeStruct *)t)->att = RECfwdref; if (t->ty == Tstruct) ((TypeStruct *)t)->att = RECfwdref;
if (t->ty == Tclass) ((TypeClass *)t)->att = RECfwdref; if (t->ty == Tclass) ((TypeClass *)t)->att = RECfwdref;
return t; return t;
@ -596,9 +588,7 @@ Type *Type::unSharedOf()
{ {
t = this->nullAttributes(); t = this->nullAttributes();
t->mod = mod & ~MODshared; t->mod = mod & ~MODshared;
#if !IN_LLVM
t->ctype = ctype; t->ctype = ctype;
#endif
t = t->merge(); t = t->merge();
t->fixTo(this); t->fixTo(this);

View file

@ -23,12 +23,7 @@
#include "expression.h" #include "expression.h"
//#include "visitor.h" //#include "visitor.h"
#if IN_LLVM
#include "../ir/irfuncty.h" #include "../ir/irfuncty.h"
namespace llvm { class Type; }
class IrType;
#endif
struct Scope; struct Scope;
class Identifier; class Identifier;
class Expression; class Expression;
@ -52,6 +47,7 @@ class Parameter;
#ifdef IN_GCC #ifdef IN_GCC
typedef union tree_node type; typedef union tree_node type;
#elif IN_LLVM #elif IN_LLVM
typedef class IrType type;
#else #else
typedef struct TYPE type; typedef struct TYPE type;
#endif #endif
@ -169,9 +165,7 @@ public:
Type *arrayof; // array of this type Type *arrayof; // array of this type
TypeInfoDeclaration *vtinfo; // TypeInfo object for this Type TypeInfoDeclaration *vtinfo; // TypeInfo object for this Type
#if IN_DMD
type *ctype; // for back end type *ctype; // for back end
#endif
static Type *tvoid; static Type *tvoid;
static Type *tint8; static Type *tint8;
@ -374,10 +368,6 @@ public:
// For eliminating dynamic_cast // For eliminating dynamic_cast
virtual TypeBasic *isTypeBasic(); virtual TypeBasic *isTypeBasic();
virtual void accept(Visitor *v) { v->visit(this); } virtual void accept(Visitor *v) { v->visit(this); }
#if IN_LLVM
IrType* irtype;
#endif
}; };
class TypeError : public Type class TypeError : public Type

View file

@ -254,7 +254,7 @@ DValue* DtoCastClass(Loc& loc, DValue* val, Type* _to)
// get the from class // get the from class
ClassDeclaration* cd = fc->sym->isClassDeclaration(); ClassDeclaration* cd = fc->sym->isClassDeclaration();
DtoResolveClass(cd); // add this DtoResolveClass(cd); // add this
IrTypeClass* typeclass = stripModifiers(fc)->irtype->isClass(); IrTypeClass* typeclass = stripModifiers(fc)->ctype->isClass();
// find interface impl // find interface impl

View file

@ -285,7 +285,7 @@ llvm::DIType ldc::DIBuilder::CreateCompositeType(Type *type)
// Use the actual type associated with the declaration, ignoring any // Use the actual type associated with the declaration, ignoring any
// const/wrappers. // const/wrappers.
LLType *T = DtoType(sd->type); LLType *T = DtoType(sd->type);
IrTypeAggr *ir = sd->type->irtype->isAggr(); IrTypeAggr *ir = sd->type->ctype->isAggr();
assert(ir); assert(ir);
if (static_cast<llvm::MDNode *>(ir->diCompositeType) != 0) if (static_cast<llvm::MDNode *>(ir->diCompositeType) != 0)

View file

@ -1047,7 +1047,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
Type* t = fd->type->toBasetype(); Type* t = fd->type->toBasetype();
TypeFunction* f = static_cast<TypeFunction*>(t); TypeFunction* f = static_cast<TypeFunction*>(t);
// assert(f->irtype); // assert(f->ctype);
llvm::Function* func = irFunc->func; llvm::Function* func = irFunc->func;

View file

@ -719,8 +719,8 @@ void Module::genmoduleinfo()
RTTIBuilder b(moduleinfo); RTTIBuilder b(moduleinfo);
// some types // some types
LLType* moduleinfoTy = moduleinfo->type->irtype->getLLType(); LLType* moduleinfoTy = moduleinfo->type->ctype->getLLType();
LLType* classinfoTy = Type::typeinfoclass->type->irtype->getLLType(); LLType* classinfoTy = Type::typeinfoclass->type->ctype->getLLType();
// importedModules[] // importedModules[]
std::vector<LLConstant*> importInits; std::vector<LLConstant*> importInits;

View file

@ -324,7 +324,7 @@ public:
if (InterfaceDeclaration* it = static_cast<TypeClass*>(tb)->sym->isInterfaceDeclaration()) { if (InterfaceDeclaration* it = static_cast<TypeClass*>(tb)->sym->isInterfaceDeclaration()) {
assert(it->isBaseOf(cd, NULL)); assert(it->isBaseOf(cd, NULL));
IrTypeClass* typeclass = cd->type->irtype->isClass(); IrTypeClass* typeclass = cd->type->ctype->isClass();
// find interface impl // find interface impl
size_t i_index = typeclass->getInterfaceIndex(it); size_t i_index = typeclass->getInterfaceIndex(it);
@ -624,7 +624,7 @@ public:
else else
{ {
value->globalVar = new llvm::GlobalVariable(*p->module, value->globalVar = new llvm::GlobalVariable(*p->module,
origClass->type->irtype->isClass()->getMemoryLLType(), origClass->type->ctype->isClass()->getMemoryLLType(),
false, llvm::GlobalValue::InternalLinkage, 0, ".classref"); false, llvm::GlobalValue::InternalLinkage, 0, ".classref");
std::map<VarDeclaration*, llvm::Constant*> varInits; std::map<VarDeclaration*, llvm::Constant*> varInits;
@ -683,7 +683,7 @@ public:
if (InterfaceDeclaration* it = targetClass->isInterfaceDeclaration()) { if (InterfaceDeclaration* it = targetClass->isInterfaceDeclaration()) {
assert(it->isBaseOf(origClass, NULL)); assert(it->isBaseOf(origClass, NULL));
IrTypeClass* typeclass = origClass->type->irtype->isClass(); IrTypeClass* typeclass = origClass->type->ctype->isClass();
// find interface impl // find interface impl
size_t i_index = typeclass->getInterfaceIndex(it); size_t i_index = typeclass->getInterfaceIndex(it);

View file

@ -107,9 +107,9 @@ LLType* DtoType(Type* t)
{ {
t = stripModifiers( t ); t = stripModifiers( t );
if (t->irtype) if (t->ctype)
{ {
return t->irtype->getLLType(); return t->ctype->getLLType();
} }
IF_LOG Logger::println("Building type: %s", t->toChars()); IF_LOG Logger::println("Building type: %s", t->toChars());
@ -168,26 +168,26 @@ LLType* DtoType(Type* t)
case Tstruct: case Tstruct:
{ {
TypeStruct* ts = static_cast<TypeStruct*>(t); TypeStruct* ts = static_cast<TypeStruct*>(t);
if (ts->sym->type->irtype) if (ts->sym->type->ctype)
{ {
// This should not happen, but the frontend seems to be buggy. Not // This should not happen, but the frontend seems to be buggy. Not
// sure if this is the best way to handle the situation, but we // sure if this is the best way to handle the situation, but we
// certainly don't want to override ts->sym->type->irtype. // certainly don't want to override ts->sym->type->ctype.
IF_LOG Logger::cout() << "Struct with multiple Types detected: " << IF_LOG Logger::cout() << "Struct with multiple Types detected: " <<
ts->toChars() << " (" << ts->sym->locToChars() << ")" << std::endl; ts->toChars() << " (" << ts->sym->locToChars() << ")" << std::endl;
return ts->sym->type->irtype->getLLType(); return ts->sym->type->ctype->getLLType();
} }
return IrTypeStruct::get(ts->sym)->getLLType(); return IrTypeStruct::get(ts->sym)->getLLType();
} }
case Tclass: case Tclass:
{ {
TypeClass* tc = static_cast<TypeClass*>(t); TypeClass* tc = static_cast<TypeClass*>(t);
if (tc->sym->type->irtype) if (tc->sym->type->ctype)
{ {
// See Tstruct case. // See Tstruct case.
IF_LOG Logger::cout() << "Class with multiple Types detected: " << IF_LOG Logger::cout() << "Class with multiple Types detected: " <<
tc->toChars() << " (" << tc->sym->locToChars() << ")" << std::endl; tc->toChars() << " (" << tc->sym->locToChars() << ")" << std::endl;
return tc->sym->type->irtype->getLLType(); return tc->sym->type->ctype->getLLType();
} }
return IrTypeClass::get(tc->sym)->getLLType(); return IrTypeClass::get(tc->sym)->getLLType();
} }

View file

@ -822,7 +822,7 @@ void TypeInfoDeclaration_codegen(TypeInfoDeclaration *decl, IRState* p)
assert(irg->type->isStructTy()); assert(irg->type->isStructTy());
} else { } else {
if (decl->tinfo->builtinTypeInfo()) // this is a declaration of a builtin __initZ var if (decl->tinfo->builtinTypeInfo()) // this is a declaration of a builtin __initZ var
irg->type = Type::dtypeinfo->type->irtype->isClass()->getMemoryLLType(); irg->type = Type::dtypeinfo->type->ctype->isClass()->getMemoryLLType();
else else
irg->type = LLStructType::create(gIR->context(), decl->toPrettyChars()); irg->type = LLStructType::create(gIR->context(), decl->toPrettyChars());
irg->value = new llvm::GlobalVariable(*gIR->module, irg->type, true, irg->value = new llvm::GlobalVariable(*gIR->module, irg->type, true,

View file

@ -51,7 +51,7 @@ LLGlobalVariable * IrAggr::getVtblSymbol()
initname.append(mangle(aggrdecl)); initname.append(mangle(aggrdecl));
initname.append("6__vtblZ"); initname.append("6__vtblZ");
LLType* vtblTy = stripModifiers(type)->irtype->isClass()->getVtbl(); LLType* vtblTy = stripModifiers(type)->ctype->isClass()->getVtbl();
vtbl = getOrCreateGlobal(aggrdecl->loc, vtbl = getOrCreateGlobal(aggrdecl->loc,
*gIR->module, vtblTy, true, llvm::GlobalValue::ExternalLinkage, NULL, initname); *gIR->module, vtblTy, true, llvm::GlobalValue::ExternalLinkage, NULL, initname);
@ -80,7 +80,7 @@ LLGlobalVariable * IrAggr::getClassInfoSymbol()
// member. // member.
ClassDeclaration* cinfo = Type::typeinfoclass; ClassDeclaration* cinfo = Type::typeinfoclass;
DtoType(cinfo->type); DtoType(cinfo->type);
IrTypeClass* tc = stripModifiers(cinfo->type)->irtype->isClass(); IrTypeClass* tc = stripModifiers(cinfo->type)->ctype->isClass();
assert(tc && "invalid ClassInfo type"); assert(tc && "invalid ClassInfo type");
// classinfos cannot be constants since they're used as locks for synchronized // classinfos cannot be constants since they're used as locks for synchronized
@ -121,7 +121,7 @@ LLGlobalVariable * IrAggr::getInterfaceArraySymbol()
ClassDeclaration* cd = aggrdecl->isClassDeclaration(); ClassDeclaration* cd = aggrdecl->isClassDeclaration();
size_t n = stripModifiers(type)->irtype->isClass()->getNumInterfaceVtbls(); size_t n = stripModifiers(type)->ctype->isClass()->getNumInterfaceVtbls();
assert(n > 0 && "getting ClassInfo.interfaces storage symbol, but we " assert(n > 0 && "getting ClassInfo.interfaces storage symbol, but we "
"don't implement any interfaces"); "don't implement any interfaces");
@ -223,12 +223,12 @@ LLConstant * IrAggr::getVtblInit()
} }
// build the constant struct // build the constant struct
LLType* vtblTy = stripModifiers(type)->irtype->isClass()->getVtbl(); LLType* vtblTy = stripModifiers(type)->ctype->isClass()->getVtbl();
constVtbl = LLConstantStruct::get(isaStruct(vtblTy), constants); constVtbl = LLConstantStruct::get(isaStruct(vtblTy), constants);
#if 0 #if 0
IF_LOG Logger::cout() << "constVtbl type: " << *constVtbl->getType() << std::endl; IF_LOG Logger::cout() << "constVtbl type: " << *constVtbl->getType() << std::endl;
IF_LOG Logger::cout() << "vtbl type: " << *stripModifiers(type)->irtype->isClass()->getVtbl() << std::endl; IF_LOG Logger::cout() << "vtbl type: " << *stripModifiers(type)->ctype->isClass()->getVtbl() << std::endl;
#endif #endif
#if 0 #if 0
@ -248,7 +248,7 @@ LLConstant * IrAggr::getVtblInit()
#endif #endif
assert(constVtbl->getType() == stripModifiers(type)->irtype->isClass()->getVtbl() && assert(constVtbl->getType() == stripModifiers(type)->ctype->isClass()->getVtbl() &&
"vtbl initializer type mismatch"); "vtbl initializer type mismatch");
return constVtbl; return constVtbl;
@ -411,7 +411,7 @@ LLConstant * IrAggr::getClassInfoInterfaces()
assert(cd); assert(cd);
size_t n = interfacesWithVtbls.size(); size_t n = interfacesWithVtbls.size();
assert(stripModifiers(type)->irtype->isClass()->getNumInterfaceVtbls() == n && assert(stripModifiers(type)->ctype->isClass()->getNumInterfaceVtbls() == n &&
"inconsistent number of interface vtables in this class"); "inconsistent number of interface vtables in this class");
VarDeclaration *interfaces_idx = Type::typeinfoclass->fields[3]; VarDeclaration *interfaces_idx = Type::typeinfoclass->fields[3];
@ -446,7 +446,7 @@ LLConstant * IrAggr::getClassInfoInterfaces()
IrAggr* irinter = getIrAggr(it->base); IrAggr* irinter = getIrAggr(it->base);
assert(irinter && "interface has null IrStruct"); assert(irinter && "interface has null IrStruct");
IrTypeClass* itc = stripModifiers(irinter->type)->irtype->isClass(); IrTypeClass* itc = stripModifiers(irinter->type)->ctype->isClass();
assert(itc && "null interface IrTypeClass"); assert(itc && "null interface IrTypeClass");
// classinfo // classinfo

View file

@ -32,7 +32,7 @@ IrType::IrType(Type* dt, LLType* lt)
{ {
assert(dt && "null D Type"); assert(dt && "null D Type");
assert(lt && "null LLVM Type"); assert(lt && "null LLVM Type");
assert(!dt->irtype && "already has IrType"); assert(!dt->ctype && "already has IrType");
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -49,7 +49,7 @@ IrTypeBasic::IrTypeBasic(Type * dt)
IrTypeBasic* IrTypeBasic::get(Type* dt) IrTypeBasic* IrTypeBasic::get(Type* dt)
{ {
IrTypeBasic* t = new IrTypeBasic(dt); IrTypeBasic* t = new IrTypeBasic(dt);
dt->irtype = t; dt->ctype = t;
return t; return t;
} }
@ -156,7 +156,7 @@ IrTypePointer::IrTypePointer(Type* dt, LLType* lt)
IrTypePointer* IrTypePointer::get(Type* dt) IrTypePointer* IrTypePointer::get(Type* dt)
{ {
assert(!dt->irtype); assert(!dt->ctype);
assert((dt->ty == Tpointer || dt->ty == Tnull) && "not pointer/null type"); assert((dt->ty == Tpointer || dt->ty == Tnull) && "not pointer/null type");
LLType* elemType; LLType* elemType;
@ -170,12 +170,12 @@ IrTypePointer* IrTypePointer::get(Type* dt)
// DtoType could have already created the same type, e.g. for // DtoType could have already created the same type, e.g. for
// dt == Node* in struct Node { Node* n; }. // dt == Node* in struct Node { Node* n; }.
if (dt->irtype) if (dt->ctype)
return dt->irtype->isPointer(); return dt->ctype->isPointer();
} }
IrTypePointer* t = new IrTypePointer(dt, llvm::PointerType::get(elemType, 0)); IrTypePointer* t = new IrTypePointer(dt, llvm::PointerType::get(elemType, 0));
dt->irtype = t; dt->ctype = t;
return t; return t;
} }
@ -193,7 +193,7 @@ IrTypeSArray::IrTypeSArray(Type * dt)
IrTypeSArray* IrTypeSArray::get(Type* dt) IrTypeSArray* IrTypeSArray::get(Type* dt)
{ {
IrTypeSArray* t = new IrTypeSArray(dt); IrTypeSArray* t = new IrTypeSArray(dt);
dt->irtype = t; dt->ctype = t;
return t; return t;
} }
@ -221,21 +221,21 @@ IrTypeArray::IrTypeArray(Type* dt, LLType* lt)
IrTypeArray* IrTypeArray::get(Type* dt) IrTypeArray* IrTypeArray::get(Type* dt)
{ {
assert(!dt->irtype); assert(!dt->ctype);
assert(dt->ty == Tarray && "not dynamic array type"); assert(dt->ty == Tarray && "not dynamic array type");
LLType* elemType = i1ToI8(voidToI8(DtoType(dt->nextOf()))); LLType* elemType = i1ToI8(voidToI8(DtoType(dt->nextOf())));
// Could have already built the type as part of a struct forward reference, // Could have already built the type as part of a struct forward reference,
// just as for pointers. // just as for pointers.
if (!dt->irtype) if (!dt->ctype)
{ {
llvm::Type *types[] = { DtoSize_t(), llvm::PointerType::get(elemType, 0) }; llvm::Type *types[] = { DtoSize_t(), llvm::PointerType::get(elemType, 0) };
LLType* at = llvm::StructType::get(llvm::getGlobalContext(), types, false); LLType* at = llvm::StructType::get(llvm::getGlobalContext(), types, false);
dt->irtype = new IrTypeArray(dt, at); dt->ctype = new IrTypeArray(dt, at);
} }
return dt->irtype->isArray(); return dt->ctype->isArray();
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -252,7 +252,7 @@ IrTypeVector::IrTypeVector(Type* dt)
IrTypeVector* IrTypeVector::get(Type* dt) IrTypeVector* IrTypeVector::get(Type* dt)
{ {
IrTypeVector* t = new IrTypeVector(dt); IrTypeVector* t = new IrTypeVector(dt);
dt->irtype = t; dt->ctype = t;
return t; return t;
} }

View file

@ -232,7 +232,7 @@ void IrTypeClass::addBaseClassData(
IrTypeClass* IrTypeClass::get(ClassDeclaration* cd) IrTypeClass* IrTypeClass::get(ClassDeclaration* cd)
{ {
IrTypeClass* t = new IrTypeClass(cd); IrTypeClass* t = new IrTypeClass(cd);
cd->type->irtype = t; cd->type->ctype = t;
IF_LOG Logger::println("Building class type %s @ %s", cd->toPrettyChars(), cd->loc.toChars()); IF_LOG Logger::println("Building class type %s @ %s", cd->toPrettyChars(), cd->loc.toChars());
LOG_SCOPE; LOG_SCOPE;

View file

@ -27,15 +27,15 @@ IrTypeFunction::IrTypeFunction(Type* dt, LLType* lt)
IrTypeFunction* IrTypeFunction::get(Type* dt, Type* nestedContextOverride) IrTypeFunction* IrTypeFunction::get(Type* dt, Type* nestedContextOverride)
{ {
assert(!dt->irtype); assert(!dt->ctype);
assert(dt->ty == Tfunction); assert(dt->ty == Tfunction);
TypeFunction* tf = static_cast<TypeFunction*>(dt); TypeFunction* tf = static_cast<TypeFunction*>(dt);
llvm::Type* lt = DtoFunctionType(tf, tf->irFty, NULL, nestedContextOverride); llvm::Type* lt = DtoFunctionType(tf, tf->irFty, NULL, nestedContextOverride);
if (!dt->irtype) if (!dt->irtype)
dt->irtype = new IrTypeFunction(dt, lt); dt->ctype = new IrTypeFunction(dt, lt);
return dt->irtype->isFunction(); return dt->ctype->isFunction();
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -47,13 +47,13 @@ IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt)
IrTypeDelegate* IrTypeDelegate::get(Type* t) IrTypeDelegate* IrTypeDelegate::get(Type* t)
{ {
assert(!t->irtype); assert(!t->ctype);
assert(t->ty == Tdelegate); assert(t->ty == Tdelegate);
assert(t->nextOf()->ty == Tfunction); assert(t->nextOf()->ty == Tfunction);
TypeDelegate *dt = (TypeDelegate*)t; TypeDelegate *dt = (TypeDelegate*)t;
if (!dt->irtype) if (!dt->ctype)
{ {
TypeFunction* tf = static_cast<TypeFunction*>(dt->nextOf()); TypeFunction* tf = static_cast<TypeFunction*>(dt->nextOf());
llvm::Type* ltf = DtoFunctionType(tf, dt->irFty, NULL, Type::tvoid->pointerTo()); llvm::Type* ltf = DtoFunctionType(tf, dt->irFty, NULL, Type::tvoid->pointerTo());
@ -61,8 +61,8 @@ IrTypeDelegate* IrTypeDelegate::get(Type* t)
llvm::Type *types[] = { getVoidPtrType(), llvm::Type *types[] = { getVoidPtrType(),
getPtrToType(ltf) }; getPtrToType(ltf) };
LLStructType* lt = LLStructType::get(gIR->context(), types, false); LLStructType* lt = LLStructType::get(gIR->context(), types, false);
dt->irtype = new IrTypeDelegate(dt, lt); dt->ctype = new IrTypeDelegate(dt, lt);
} }
return dt->irtype->isDelegate(); return dt->ctype->isDelegate();
} }

View file

@ -96,7 +96,7 @@ bool var_offset_sort_cb(const VarDeclaration* v1, const VarDeclaration* v2)
IrTypeStruct* IrTypeStruct::get(StructDeclaration* sd) IrTypeStruct* IrTypeStruct::get(StructDeclaration* sd)
{ {
IrTypeStruct* t = new IrTypeStruct(sd); IrTypeStruct* t = new IrTypeStruct(sd);
sd->type->irtype = t; sd->type->ctype = t;
IF_LOG Logger::println("Building struct type %s @ %s", IF_LOG Logger::println("Building struct type %s @ %s",
sd->toPrettyChars(), sd->loc.toChars()); sd->toPrettyChars(), sd->loc.toChars());