Mercurial > projects > ddmd
diff dmd/codegen/Util.d @ 108:6da99741178e
e2ir.c changes, mainly accounts for static arrays being value types now
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 21:41:01 +0200 |
parents | be2ab491772e |
children | 3482c73a991b |
line wrap: on
line diff
--- a/dmd/codegen/Util.d Tue Aug 31 18:18:31 2010 +0200 +++ b/dmd/codegen/Util.d Tue Aug 31 21:41:01 2010 +0200 @@ -5,6 +5,7 @@ import dmd.IRState; import dmd.Type; import dmd.Array; +import dmd.Declaration; import dmd.Dsymbol; import dmd.FuncDeclaration; import dmd.Identifier; @@ -60,10 +61,21 @@ import core.memory; + +/* If variable var of type typ is a reference + */ +version(SARRAYVALUE) +{ + bool ISREF(Declaration var, Type tb) {return var.isOut() || var.isRef();} +} +else + bool ISREF(Declaration var, Type tb) {return (var.isParameter() && tb.ty == TY.Tsarray) || var.isOut() || var.isRef();} + + + /************************************ * Call a function. */ - elem* callfunc(Loc loc, IRState* irs, int directcall, // 1: don't do virtual call @@ -126,13 +138,11 @@ // j=1 if _arguments[] is first argument int j = (tf.linkage == LINK.LINKd && tf.varargs == 1); - for (i = 0; i < arguments.dim ; i++) + foreach (size_t i, Expression arg; arguments) { - Expression arg; elem* ea; - arg = cast(Expression)arguments.data[i]; - //printf("\targ[%d]: %s\n", i, arg.toChars()); + //writef("\targ[%d]: %s\n", i, arg.toChars()); size_t nparams = Argument.dim(tf.parameters); if (i - j < nparams && i >= j) @@ -150,11 +160,11 @@ } ea = arg.toElem(irs); L1: - if (tybasic(ea.Ety) == TYM.TYstruct) + if (tybasic(ea.Ety) == TYM.TYstruct || tybasic(ea.Ety) == TYarray) { ea = el_una(OPER.OPstrpar, TYM.TYstruct, ea); ea.Enumbytes = ea.E1.Enumbytes; - assert(ea.Enumbytes); + //assert(ea.Enumbytes); } if (reverse) ep = el_param(ep,ea); @@ -170,10 +180,12 @@ // Don't have one, so create one type* tt; - if (tf.next.toBasetype().ty == TY.Tstruct) - tt = tf.next.toCtype(); + Type tret2 = tf.next; // in dmd tret is shadowed here, so -> tret2 + if (tret2.toBasetype().ty == Tstruct || + tret2.toBasetype().ty == Tsarray) + tt = tret2.toCtype(); else - tt = type_fake(tf.next.totym()); + tt = type_fake(tret2.totym()); Symbol* stmp = symbol_genauto(tt); ehidden = el_ptr(stmp); @@ -284,9 +296,9 @@ e = el_una(op,tyret,ep); } else if (ep) - e = el_bin(tf.ispure ? OPER.OPcallns : OPER.OPcall, tyret, ec, ep); + e = el_bin((tf.ispure && tf.isnothrow) ? OPER.OPcallns : OPER.OPcall, tyret, ec, ep); else - e = el_una(tf.ispure ? OPER.OPucallns : OPER.OPucall, tyret, ec); + e = el_una((tf.ispure && tf.isnothrow) ? OPER.OPucallns : OPER.OPucall, tyret, ec); if (retmethod == RET.RETstack) { @@ -792,7 +804,6 @@ * edim number of times to write evalue to eptr[] * tb type of evalue */ - elem* setArray(elem* eptr, elem* edim, Type tb, elem* evalue, IRState* irs, int op) { int r; @@ -852,7 +863,7 @@ edim = el_bin(OPER.OPmul, TYM.TYuint, edim, el_long(TYM.TYuint, sz)); } - if (tybasic(evalue.Ety) == TYM.TYstruct) + if (tybasic(evalue.Ety) == TYM.TYstruct || tybasic(evalue.Ety) == TYarray) { evalue = el_una(OPER.OPstrpar, TYM.TYstruct, evalue); evalue.Enumbytes = evalue.E1.Enumbytes; @@ -987,7 +998,7 @@ break; case TY.Tsarray: - e = el_una(OPER.OPaddr, TYM.TYnptr, e); + e = addressElem(e, t); dim = cast(uint)(cast(TypeSArray)t).dim.toInteger(); e = el_pair(TYM.TYullong, el_long(TYM.TYint, dim), e); break; @@ -1062,12 +1073,13 @@ return el_combine(ef, e); } +/************************************ + */ elem* sarray_toDarray(Loc loc, Type tfrom, Type tto, elem* e) { //printf("sarray_toDarray()\n"); //elem_print(e); - elem* elen; uint dim = cast(uint)(cast(TypeSArray)tfrom).dim.toInteger(); if (tto) @@ -1084,8 +1096,8 @@ } L1: - elen = el_long(TYM.TYint, dim); - e = el_una(OPER.OPaddr, TYM.TYnptr, e); + elem* elen = el_long(TYM.TYint, dim); + e = addressElem(e, tfrom); e = el_pair(TYM.TYullong, elen, e); return e; }