Mercurial > projects > ddmd
diff dmd/TypeTypedef.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | a8b50ff7f201 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/TypeTypedef.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,296 @@ +module dmd.TypeTypedef; + +import dmd.Type; +import dmd.TypedefDeclaration; +import dmd.MOD; +import dmd.Loc; +import dmd.Id; +import dmd.Dsymbol; +import dmd.Scope; +import dmd.OutBuffer; +import dmd.HdrGenState; +import dmd.Expression; +import dmd.Identifier; +import dmd.ArrayTypes; +import dmd.MATCH; +import dmd.TypeSArray; +import dmd.CppMangleState; +import dmd.TypeInfoDeclaration; +import dmd.TypeInfoTypedefDeclaration; +import dmd.TY; + +import dmd.backend.TYPE; +import dmd.backend.dt_t; + +class TypeTypedef : Type +{ + TypedefDeclaration sym; + + this(TypedefDeclaration sym) + { + super(Ttypedef); + this.sym = sym; + } + +version (DumbClone) { +} else { + Type clone() + { + assert(false); + } +} + + Type syntaxCopy() + { + assert(false); + } + + ulong size(Loc loc) + { + return sym.basetype.size(loc); + } + + uint alignsize() + { + assert(false); + } + + string toChars() + { + assert(false); + } + + Type semantic(Loc loc, Scope sc) + { + //printf("TypeTypedef::semantic(%s), sem = %d\n", toChars(), sym->sem); + sym.semantic(sc); + return merge(); + } + + Dsymbol toDsymbol(Scope sc) + { + return sym; + } + + void toDecoBuffer(OutBuffer buf, int flag) + { + Type.toDecoBuffer(buf, flag); + string name = sym.mangle(); + buf.printf("%s", name); + } + + void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) + { + assert(false); + } + + Expression dotExp(Scope sc, Expression e, Identifier ident) + { + version (LOGDOTEXP) { + printf("TypeTypedef.dotExp(e = '%s', ident = '%s') '%s'\n", e.toChars(), ident.toChars(), toChars()); + } + if (ident is Id.init_) + { + return Type.dotExp(sc, e, ident); + } + return sym.basetype.dotExp(sc, e, ident); + } + + Expression getProperty(Loc loc, Identifier ident) + { + assert(false); + } + + bool isbit() + { + assert(false); + } + + bool isintegral() + { + //printf("TypeTypedef::isintegral()\n"); + //printf("sym = '%s'\n", sym->toChars()); + //printf("basetype = '%s'\n", sym->basetype->toChars()); + return sym.basetype.isintegral(); + } + + bool isfloating() + { + return sym.basetype.isfloating(); + } + + bool isreal() + { + return sym.basetype.isreal(); + } + + bool isimaginary() + { + return sym.basetype.isimaginary(); + } + + bool iscomplex() + { + return sym.basetype.iscomplex(); + } + + bool isscalar() + { + return sym.basetype.isscalar(); + } + + bool isunsigned() + { + return sym.basetype.isunsigned(); + } + + bool checkBoolean() + { + assert(false); + } + + int isAssignable() + { + return sym.basetype.isAssignable(); + } + + Type toBasetype() + { + if (sym.inuse) + { + sym.error("circular definition"); + sym.basetype = Type.terror; + return Type.terror; + } + sym.inuse = 1; + Type t = sym.basetype.toBasetype(); + sym.inuse = 0; + t = t.addMod(mod); + return t; + } + + MATCH implicitConvTo(Type to) + { + MATCH m; + + //printf("TypeTypedef::implicitConvTo(to = %s) %s\n", to->toChars(), toChars()); + if (equals(to)) + m = MATCHexact; // exact match + else if (sym.basetype.implicitConvTo(to)) + m = MATCHconvert; // match with conversions + else if (ty == to.ty && sym == (cast(TypeTypedef)to).sym) + { + m = constConv(to); + } + else + m = MATCHnomatch; // no match + return m; + } + + MATCH constConv(Type to) + { + assert(false); + } + + Expression defaultInit(Loc loc) + { + Expression e; + Type bt; + + version (LOGDEFAULTINIT) { + printf("TypeTypedef::defaultInit() '%s'\n", toChars()); + } + if (sym.init) + { + //sym->init->toExpression()->print(); + return sym.init.toExpression(); + } + bt = sym.basetype; + e = bt.defaultInit(loc); + e.type = this; + while (bt.ty == Tsarray) + { + TypeSArray tsa = cast(TypeSArray)bt; + e.type = tsa.next; + bt = tsa.next.toBasetype(); + } + return e; + } + + bool isZeroInit(Loc loc) + { + if (sym.init) + { + if (sym.init.isVoidInitializer()) + return true; // initialize voids to 0 + Expression e = sym.init.toExpression(); + if (e && e.isBool(false)) + return true; + + return false; // assume not + } + if (sym.inuse) + { + sym.error("circular definition"); + sym.basetype = Type.terror; + } + sym.inuse = 1; + bool result = sym.basetype.isZeroInit(loc); + sym.inuse = 0; + + return result; + } + + dt_t** toDt(dt_t** pdt) + { + if (sym.init) + { + dt_t* dt = sym.init.toDt(); + + while (*pdt) + pdt = &((*pdt).DTnext); + *pdt = dt; + return pdt; + } + + sym.basetype.toDt(pdt); + return pdt; + } + + MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) + { + assert(false); + } + + TypeInfoDeclaration getTypeInfoDeclaration() + { + return new TypeInfoTypedefDeclaration(this); + } + + bool hasPointers() + { + return toBasetype().hasPointers(); + } + + Type toHeadMutable() + { + assert(false); + } + +version (CPP_MANGLE) { + void toCppMangle(OutBuffer buf, CppMangleState* cms) + { + assert(false); + } +} + + type* toCtype() + { + return sym.basetype.toCtype(); + } + + type* toCParamtype() + { + return sym.basetype.toCParamtype(); + } +} \ No newline at end of file