Mercurial > projects > ddmd
comparison 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 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
5 import dmd.Loc; | 5 import dmd.Loc; |
6 import dmd.Expression; | 6 import dmd.Expression; |
7 import dmd.Scope; | 7 import dmd.Scope; |
8 import dmd.InterState; | 8 import dmd.InterState; |
9 import dmd.SliceExp; | 9 import dmd.SliceExp; |
10 import dmd.ErrorExp; | |
10 import dmd.Identifier; | 11 import dmd.Identifier; |
11 import dmd.IRState; | 12 import dmd.IRState; |
12 import dmd.TOK; | 13 import dmd.TOK; |
13 import dmd.TY; | 14 import dmd.TY; |
14 import dmd.Id; | 15 import dmd.Id; |
54 Type tb1 = e1.type.toBasetype(); | 55 Type tb1 = e1.type.toBasetype(); |
55 Type tb2 = e2.type.toBasetype(); | 56 Type tb2 = e2.type.toBasetype(); |
56 | 57 |
57 e2.rvalue(); | 58 e2.rvalue(); |
58 | 59 |
60 Type tb1next = tb1.nextOf(); | |
61 | |
59 if ((tb1.ty == Tarray) && | 62 if ((tb1.ty == Tarray) && |
60 (tb2.ty == Tarray || tb2.ty == Tsarray) && | 63 (tb2.ty == Tarray || tb2.ty == Tsarray) && |
61 (e2.implicitConvTo(e1.type) || | 64 (e2.implicitConvTo(e1.type) || |
62 tb2.nextOf().implicitConvTo(tb1.nextOf())) | 65 //version(DMDV2) { |
66 tb2.nextOf().implicitConvTo(tb1next) | |
67 //} | |
68 ) | |
69 | |
63 ) | 70 ) |
64 { // Append array | 71 { // Append array |
65 e2 = e2.castTo(sc, e1.type); | 72 e2 = e2.castTo(sc, e1.type); |
66 type = e1.type; | 73 type = e1.type; |
67 e = this; | 74 e = this; |
68 } | 75 } |
69 else if ((tb1.ty == Tarray) && | 76 else if ((tb1.ty == Tarray) && |
70 e2.implicitConvTo(tb1.nextOf()) | 77 e2.implicitConvTo(tb1next) |
71 ) | 78 ) |
72 { // Append element | 79 { // Append element |
73 e2 = e2.castTo(sc, tb1.nextOf()); | 80 e2 = e2.castTo(sc, tb1next); |
74 type = e1.type; | 81 type = e1.type; |
75 e = this; | 82 e = this; |
76 } | 83 } |
77 else | 84 else if (tb1.ty == Tarray && |
78 { | 85 (tb1next.ty == Tchar || tb1next.ty == Twchar) && |
79 error("cannot append type %s to type %s", tb2.toChars(), tb1.toChars()); | 86 e2.implicitConvTo(Type.tdchar) |
80 type = Type.tint32; | 87 ) |
81 e = this; | 88 { // Append dchar to char[] or wchar[] |
82 } | 89 e2 = e2.castTo(sc, Type.tdchar); |
90 type = e1.type; | |
91 e = this; | |
92 | |
93 /* Do not allow appending wchar to char[] because if wchar happens | |
94 * to be a surrogate pair, nothing good can result. | |
95 */ | |
96 } | |
97 else | |
98 { | |
99 error("cannot append type %s to type %s", tb2.toChars(), tb1.toChars()); | |
100 e = new ErrorExp(); | |
101 } | |
83 return e; | 102 return e; |
84 } | 103 } |
85 | 104 |
86 override Expression interpret(InterState istate) | 105 override Expression interpret(InterState istate) |
87 { | 106 { |
98 //printf("CatAssignExp.toElem('%s')\n", toChars()); | 117 //printf("CatAssignExp.toElem('%s')\n", toChars()); |
99 elem* e; | 118 elem* e; |
100 Type tb1 = e1.type.toBasetype(); | 119 Type tb1 = e1.type.toBasetype(); |
101 Type tb2 = e2.type.toBasetype(); | 120 Type tb2 = e2.type.toBasetype(); |
102 | 121 |
103 if (tb1.ty == Tarray || tb2.ty == Tsarray) | 122 if (tb1.ty == Tarray && tb2.ty == Tdchar && |
104 { elem* e1; | 123 (tb1.nextOf().ty == Tchar || tb1.nextOf().ty == Twchar)) |
105 elem* e2; | 124 { // Append dchar to char[] or wchar[] |
106 elem* ep; | |
107 | 125 |
108 e1 = this.e1.toElem(irs); | 126 auto e1 = this.e1.toElem(irs); |
109 e1 = el_una(OPaddr, TYnptr, e1); | 127 e1 = el_una(OPaddr, TYnptr, e1); |
110 | 128 |
111 e2 = this.e2.toElem(irs); | 129 auto e2 = this.e2.toElem(irs); |
130 | |
131 auto ep = el_params(e2, e1, null); | |
132 int rtl = (tb1.nextOf().ty == Tchar) | |
133 ? RTLSYM_ARRAYAPPENDCD | |
134 : RTLSYM_ARRAYAPPENDWD; | |
135 e = el_bin(OPcall, TYdarray, el_var(rtlsym[rtl]), ep); | |
136 el_setLoc(e,loc); | |
137 } | |
138 else if (tb1.ty == Tarray || tb2.ty == Tsarray) | |
139 { | |
140 auto e1 = this.e1.toElem(irs); | |
141 e1 = el_una(OPaddr, TYnptr, e1); | |
142 | |
143 auto e2 = this.e2.toElem(irs); | |
144 | |
112 if (tybasic(e2.Ety) == TYstruct || tybasic(e2.Ety) == TYarray) | 145 if (tybasic(e2.Ety) == TYstruct || tybasic(e2.Ety) == TYarray) |
113 { | 146 { |
114 e2 = el_una(OPstrpar, TYstruct, e2); | 147 e2 = el_una(OPstrpar, TYstruct, e2); |
115 e2.Enumbytes = e2.E1.Enumbytes; | 148 e2.Enumbytes = e2.E1.Enumbytes; |
116 assert(e2.Enumbytes); | 149 assert(e2.Enumbytes); |
118 | 151 |
119 Type tb1n = tb1.nextOf().toBasetype(); | 152 Type tb1n = tb1.nextOf().toBasetype(); |
120 if ((tb2.ty == Tarray || tb2.ty == Tsarray) && | 153 if ((tb2.ty == Tarray || tb2.ty == Tsarray) && |
121 tb1n.equals(tb2.nextOf().toBasetype())) | 154 tb1n.equals(tb2.nextOf().toBasetype())) |
122 { // Append array | 155 { // Append array |
123 static if (true) { | 156 auto ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); |
124 ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); | |
125 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); | 157 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDT]), ep); |
126 } else { | |
127 ep = el_params(el_long(TYint, tb1n.size()), e2, e1, null); | |
128 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPEND]), ep); | |
129 } | |
130 } | 158 } |
131 else | 159 else |
132 { // Append element | 160 { // Append element |
133 static if (true) { | 161 auto ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); |
134 ep = el_params(e2, e1, this.e1.type.getTypeInfo(null).toElem(irs), null); | |
135 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); | 162 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDCT]), ep); |
136 } else { | |
137 ep = el_params(e2, el_long(TYint, tb1n.size()), e1, null); | |
138 e = el_bin(OPcall, TYdarray, el_var(rtlsym[RTLSYM_ARRAYAPPENDC]), ep); | |
139 } | |
140 } | 163 } |
141 el_setLoc(e,loc); | 164 el_setLoc(e,loc); |
142 } | 165 } |
143 else | 166 else |
144 assert(0); | 167 assert(0); |