Mercurial > projects > ddmd
diff dmd/CatAssignExp.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | fe941d774f4a |
children | e3afd1303184 |
line wrap: on
line diff
--- a/dmd/CatAssignExp.d Sun Sep 05 15:32:22 2010 +0400 +++ b/dmd/CatAssignExp.d Thu Sep 09 22:51:44 2010 +0100 @@ -7,6 +7,7 @@ import dmd.Scope; import dmd.InterState; import dmd.SliceExp; +import dmd.ErrorExp; import dmd.Identifier; import dmd.IRState; import dmd.TOK; @@ -56,10 +57,16 @@ e2.rvalue(); + Type tb1next = tb1.nextOf(); + if ((tb1.ty == Tarray) && (tb2.ty == Tarray || tb2.ty == Tsarray) && (e2.implicitConvTo(e1.type) || - tb2.nextOf().implicitConvTo(tb1.nextOf())) +//version(DMDV2) { + tb2.nextOf().implicitConvTo(tb1next) +//} + ) + ) { // Append array e2 = e2.castTo(sc, e1.type); @@ -67,19 +74,31 @@ e = this; } else if ((tb1.ty == Tarray) && - e2.implicitConvTo(tb1.nextOf()) + e2.implicitConvTo(tb1next) ) { // Append element - e2 = e2.castTo(sc, tb1.nextOf()); + e2 = e2.castTo(sc, tb1next); type = e1.type; e = this; } - else - { - error("cannot append type %s to type %s", tb2.toChars(), tb1.toChars()); - type = Type.tint32; - e = this; - } + else if (tb1.ty == Tarray && + (tb1next.ty == Tchar || tb1next.ty == Twchar) && + e2.implicitConvTo(Type.tdchar) + ) + { // Append dchar to char[] or wchar[] + e2 = e2.castTo(sc, Type.tdchar); + type = e1.type; + e = this; + + /* Do not allow appending wchar to char[] because if wchar happens + * to be a surrogate pair, nothing good can result. + */ + } + else + { + error("cannot append type %s to type %s", tb2.toChars(), tb1.toChars()); + e = new ErrorExp(); + } return e; } @@ -100,15 +119,29 @@ Type tb1 = e1.type.toBasetype(); Type tb2 = e2.type.toBasetype(); - if (tb1.ty == Tarray || tb2.ty == Tsarray) - { elem* e1; - elem* e2; - elem* ep; + if (tb1.ty == Tarray && tb2.ty == Tdchar && + (tb1.nextOf().ty == Tchar || tb1.nextOf().ty == Twchar)) + { // Append dchar to char[] or wchar[] - e1 = this.e1.toElem(irs); + auto e1 = this.e1.toElem(irs); e1 = el_una(OPaddr, TYnptr, e1); - e2 = this.e2.toElem(irs); + auto e2 = this.e2.toElem(irs); + + auto ep = el_params(e2, e1, null); + int rtl = (tb1.nextOf().ty == Tchar) + ? RTLSYM_ARRAYAPPENDCD + : RTLSYM_ARRAYAPPENDWD; + e = el_bin(OPcall, TYdarray, el_var(rtlsym[rtl]), ep); + el_setLoc(e,loc); + } + else if (tb1.ty == Tarray || tb2.ty == Tsarray) + { + auto e1 = this.e1.toElem(irs); + e1 = el_una(OPaddr, TYnptr, e1); + + auto e2 = this.e2.toElem(irs); + if (tybasic(e2.Ety) == TYstruct || tybasic(e2.Ety) == TYarray) { e2 = el_una(OPstrpar, TYstruct, e2); @@ -120,23 +153,13 @@ if ((tb2.ty == Tarray || tb2.ty == Tsarray) && tb1n.equals(tb2.nextOf().toBasetype())) { // Append array - static if (true) { - ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); + auto ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); - } else { - ep = el_params(el_long(TYint, tb1n.size()), e2, e1, null); - e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep); - } } else { // Append element - static if (true) { - ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); + auto ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); - } else { - ep = el_params(e2, el_long(TYint, tb1n.size()), e1, null); - e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep); - } } el_setLoc(e,loc); }