Mercurial > projects > ddmd
annotate dmd/BinExp.d @ 154:14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
and enabled warnings
+ reduced warnings by adding appriopriate overrides
+ IfStatement.interpret()
+ ScopeStatement.interpret()
+ TypeSArray.constConv()
+ TypedefDeclaration.syntaxCopy()
* fixed a bug in StringExp
author | trass3r |
---|---|
date | Wed, 15 Sep 2010 15:32:31 +0200 |
parents | af1bebfd96a4 |
children | af724d3510d7 |
rev | line source |
---|---|
0 | 1 module dmd.BinExp; |
2 | |
114 | 3 import dmd.common; |
63 | 4 import dmd.SliceExp; |
5 import dmd.IndexExp; | |
6 import dmd.StructDeclaration; | |
7 import dmd.expression.ArrayLength; | |
8 import dmd.expression.Equal; | |
9 import dmd.expression.Index; | |
10 import dmd.ArrayLiteralExp; | |
11 import dmd.AssocArrayLiteralExp; | |
12 import dmd.StringExp; | |
13 import dmd.TypeSArray; | |
14 import dmd.PtrExp; | |
15 import dmd.SymOffExp; | |
16 import dmd.Declaration; | |
17 import dmd.StructLiteralExp; | |
0 | 18 import dmd.Expression; |
63 | 19 import dmd.interpret.Util; |
20 import dmd.GlobalExpressions; | |
21 import dmd.Cast; | |
22 import dmd.CastExp; | |
23 import dmd.VarDeclaration; | |
24 import dmd.DotVarExp; | |
0 | 25 import dmd.Loc; |
26 import dmd.ClassDeclaration; | |
27 import dmd.OutBuffer; | |
28 import dmd.HdrGenState; | |
29 import dmd.TOK; | |
30 import dmd.IRState; | |
31 import dmd.Scope; | |
32 import dmd.Type; | |
33 import dmd.InterState; | |
34 import dmd.InlineCostState; | |
35 import dmd.InlineScanState; | |
36 import dmd.InlineDoState; | |
37 import dmd.AggregateDeclaration; | |
38 import dmd.Identifier; | |
39 import dmd.MATCH; | |
40 import dmd.declaration.Match; | |
41 import dmd.ArrayTypes; | |
42 import dmd.TY; | |
43 import dmd.TypeClass; | |
44 import dmd.TypeStruct; | |
45 import dmd.Dsymbol; | |
46 import dmd.FuncDeclaration; | |
47 import dmd.TemplateDeclaration; | |
48 import dmd.DotIdExp; | |
49 import dmd.ErrorExp; | |
50 import dmd.WANT; | |
51 import dmd.IntegerExp; | |
52 import dmd.MulExp; | |
53 import dmd.Token; | |
54 import dmd.PREC; | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
55 import dmd.StringValue; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
56 import dmd.StringTable; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
57 import dmd.Parameter; |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
58 import dmd.Statement; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
59 import dmd.ForeachRangeStatement; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
60 import dmd.ArrayLengthExp; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
61 import dmd.IdentifierExp; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
62 import dmd.ExpStatement; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
63 import dmd.CompoundStatement; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
64 import dmd.TypeFunction; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
65 import dmd.LINK; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
66 import dmd.Lexer; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
67 import dmd.ReturnStatement; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
68 import dmd.Id; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
69 import dmd.STC; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
70 import dmd.PROT; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
71 import dmd.VarExp; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
72 import dmd.CallExp; |
0 | 73 |
74 import dmd.expression.Util; | |
75 | |
76 import dmd.backend.elem; | |
77 import dmd.backend.Util; | |
78 | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
79 import dmd.backend.iasm : binary; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
80 |
63 | 81 import std.exception : assumeUnique; |
82 import core.stdc.stdlib : calloc; | |
0 | 83 import std.stdio : writef; |
84 | |
85 /************************************** | |
86 * Combine types. | |
87 * Output: | |
88 * *pt merged type, if *pt is not null | |
89 * *pe1 rewritten e1 | |
90 * *pe2 rewritten e2 | |
91 * Returns: | |
92 * !=0 success | |
93 * 0 failed | |
94 */ | |
95 | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
96 /************************************** |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
97 * Hash table of array op functions already generated or known about. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
98 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
99 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
100 __gshared StringTable arrayfuncs; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
101 |
0 | 102 int typeMerge(Scope sc, Expression e, Type* pt, Expression* pe1, Expression* pe2) |
103 { | |
60 | 104 //printf("typeMerge() %.*s op %.*s\n", (*pe1).toChars(), (*pe2).toChars()); |
0 | 105 //dump(0); |
106 | |
107 Expression e1 = (*pe1).integralPromotions(sc); | |
108 Expression e2 = (*pe2).integralPromotions(sc); | |
109 | |
110 Type t1 = e1.type; | |
111 Type t2 = e2.type; | |
112 assert(t1); | |
113 Type t = t1; | |
114 | |
115 //if (t1) printf("\tt1 = %s\n", t1.toChars()); | |
116 //if (t2) printf("\tt2 = %s\n", t2.toChars()); | |
117 debug { | |
118 if (!t2) writef("\te2 = '%s'\n", e2.toChars()); | |
119 } | |
120 assert(t2); | |
121 | |
122 Type t1b = t1.toBasetype(); | |
123 Type t2b = t2.toBasetype(); | |
124 | |
125 TY ty = cast(TY)Type.impcnvResult[t1b.ty][t2b.ty]; | |
126 if (ty != TY.Terror) | |
127 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
128 auto ty1 = cast(TY)Type.impcnvType1[t1b.ty][t2b.ty]; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
129 auto ty2 = cast(TY)Type.impcnvType2[t1b.ty][t2b.ty]; |
0 | 130 |
131 if (t1b.ty == ty1) // if no promotions | |
132 { | |
133 if (t1 == t2) | |
134 { | |
135 t = t1; | |
136 goto Lret; | |
137 } | |
138 | |
139 if (t1b == t2b) | |
140 { | |
141 t = t1b; | |
142 goto Lret; | |
143 } | |
144 } | |
145 | |
146 t = Type.basic[ty]; | |
147 | |
148 t1 = Type.basic[ty1]; | |
149 t2 = Type.basic[ty2]; | |
150 | |
151 e1 = e1.castTo(sc, t1); | |
152 e2 = e2.castTo(sc, t2); | |
153 //printf("after typeCombine():\n"); | |
154 //dump(0); | |
155 //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2); | |
156 goto Lret; | |
157 } | |
158 | |
159 t1 = t1b; | |
160 t2 = t2b; | |
161 | |
162 Lagain: | |
163 if (t1 == t2) | |
164 { | |
165 } | |
166 else if (t1.ty == TY.Tpointer && t2.ty == TY.Tpointer) | |
167 { | |
168 // Bring pointers to compatible type | |
169 Type t1n = t1.nextOf(); | |
170 Type t2n = t2.nextOf(); | |
171 | |
172 if (t1n == t2n) { | |
173 ; | |
174 } else if (t1n.ty == TY.Tvoid) {// pointers to void are always compatible | |
175 t = t2; | |
176 } else if (t2n.ty == TY.Tvoid) { | |
177 ; | |
178 } else if (t1n.mod != t2n.mod) { | |
179 t1 = t1n.mutableOf().constOf().pointerTo(); | |
180 t2 = t2n.mutableOf().constOf().pointerTo(); | |
181 t = t1; | |
182 goto Lagain; | |
183 } else if (t1n.ty == TY.Tclass && t2n.ty == TY.Tclass) { | |
184 ClassDeclaration cd1 = t1n.isClassHandle(); | |
185 ClassDeclaration cd2 = t2n.isClassHandle(); | |
186 int offset; | |
187 | |
188 if (cd1.isBaseOf(cd2, &offset)) | |
189 { | |
190 if (offset) | |
191 e2 = e2.castTo(sc, t); | |
192 } | |
193 else if (cd2.isBaseOf(cd1, &offset)) | |
194 { | |
195 t = t2; | |
196 if (offset) | |
197 e1 = e1.castTo(sc, t); | |
198 } | |
199 else | |
200 goto Lincompatible; | |
201 } else { | |
202 goto Lincompatible; | |
203 } | |
204 } | |
205 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray) && | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
206 (e2.op == TOK.TOKnull && t2.ty == TY.Tpointer && t2.nextOf().ty == TY.Tvoid || |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
207 e2.op == TOK.TOKarrayliteral && t2.ty == TY.Tsarray && t2.nextOf().ty == TY.Tvoid && (cast(TypeSArray)t2).dim.toInteger() == 0) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
208 ) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
209 { /* (T[n] op void*) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
210 * (T[] op void*) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
211 * (T[n] op void[0]) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
212 * (T[] op void[0]) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
213 */ |
0 | 214 goto Lx1; |
215 } | |
216 else if ((t2.ty == TY.Tsarray || t2.ty == TY.Tarray) && | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
217 (e1.op == TOK.TOKnull && t1.ty == TY.Tpointer && t1.nextOf().ty == TY.Tvoid || |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
218 e1.op == TOK.TOKarrayliteral && t1.ty == TY.Tsarray && t1.nextOf().ty == TY.Tvoid && (cast(TypeSArray)t1).dim.toInteger() == 0) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
219 ) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
220 { /* (void* op T[n]) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
221 * (void* op T[]) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
222 * (void[0] op T[n]) => T[] |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
223 * (void[0] op T[]) => T[] |
0 | 224 */ |
225 goto Lx2; | |
226 } | |
227 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray) && t1.implicitConvTo(t2)) | |
228 { | |
229 goto Lt2; | |
230 } | |
231 else if ((t2.ty == TY.Tsarray || t2.ty == TY.Tarray) && t2.implicitConvTo(t1)) | |
232 { | |
233 goto Lt1; | |
234 } | |
235 /* If one is mutable and the other invariant, then retry | |
236 * with both of them as const | |
237 */ | |
238 else if ((t1.ty == TY.Tsarray || t1.ty == TY.Tarray || t1.ty == TY.Tpointer) && | |
239 (t2.ty == TY.Tsarray || t2.ty == TY.Tarray || t2.ty == TY.Tpointer) && | |
240 t1.nextOf().mod != t2.nextOf().mod | |
241 ) | |
242 { | |
243 if (t1.ty == TY.Tpointer) | |
244 t1 = t1.nextOf().mutableOf().constOf().pointerTo(); | |
245 else | |
246 t1 = t1.nextOf().mutableOf().constOf().arrayOf(); | |
247 | |
248 if (t2.ty == TY.Tpointer) | |
249 t2 = t2.nextOf().mutableOf().constOf().pointerTo(); | |
250 else | |
251 t2 = t2.nextOf().mutableOf().constOf().arrayOf(); | |
252 t = t1; | |
253 goto Lagain; | |
254 } | |
255 else if (t1.ty == TY.Tclass || t2.ty == TY.Tclass) | |
256 { | |
257 while (1) | |
258 { | |
259 int i1 = e2.implicitConvTo(t1); | |
260 int i2 = e1.implicitConvTo(t2); | |
261 | |
262 if (i1 && i2) | |
263 { | |
264 // We have the case of class vs. void*, so pick class | |
265 if (t1.ty == TY.Tpointer) | |
266 i1 = 0; | |
267 else if (t2.ty == TY.Tpointer) | |
268 i2 = 0; | |
269 } | |
270 | |
271 if (i2) | |
272 { | |
273 goto Lt2; | |
274 } | |
275 else if (i1) | |
276 { | |
277 goto Lt1; | |
278 } | |
279 else if (t1.ty == TY.Tclass && t2.ty == TY.Tclass) | |
280 { | |
281 TypeClass tc1 = cast(TypeClass)t1; | |
282 TypeClass tc2 = cast(TypeClass)t2; | |
283 | |
284 /* Pick 'tightest' type | |
285 */ | |
286 ClassDeclaration cd1 = tc1.sym.baseClass; | |
287 ClassDeclaration cd2 = tc2.sym.baseClass; | |
288 | |
289 if (cd1 && cd2) | |
290 { t1 = cd1.type; | |
291 t2 = cd2.type; | |
292 } | |
293 else if (cd1) | |
294 t1 = cd1.type; | |
295 else if (cd2) | |
296 t2 = cd2.type; | |
297 else | |
298 goto Lincompatible; | |
299 } | |
300 else | |
301 goto Lincompatible; | |
302 } | |
303 } | |
304 else if (t1.ty == TY.Tstruct && t2.ty == TY.Tstruct) | |
305 { | |
306 if ((cast(TypeStruct)t1).sym != (cast(TypeStruct)t2).sym) | |
307 goto Lincompatible; | |
308 } | |
309 else if ((e1.op == TOK.TOKstring || e1.op == TOK.TOKnull) && e1.implicitConvTo(t2)) | |
310 { | |
311 goto Lt2; | |
312 } | |
313 else if ((e2.op == TOK.TOKstring || e2.op == TOK.TOKnull) && e2.implicitConvTo(t1)) | |
314 { | |
315 goto Lt1; | |
316 } | |
317 else if (t1.ty == TY.Tsarray && t2.ty == TY.Tsarray && | |
318 e2.implicitConvTo(t1.nextOf().arrayOf())) | |
319 { | |
320 Lx1: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
321 t = t1.nextOf().arrayOf(); // T[] |
0 | 322 e1 = e1.castTo(sc, t); |
323 e2 = e2.castTo(sc, t); | |
324 } | |
325 else if (t1.ty == TY.Tsarray && t2.ty == TY.Tsarray && | |
326 e1.implicitConvTo(t2.nextOf().arrayOf())) | |
327 { | |
328 Lx2: | |
329 t = t2.nextOf().arrayOf(); | |
330 e1 = e1.castTo(sc, t); | |
331 e2 = e2.castTo(sc, t); | |
332 } | |
333 else if (t1.isintegral() && t2.isintegral()) | |
334 { | |
335 assert(0); | |
336 } | |
98 | 337 else if (e1.isArrayOperand() && t1.ty == TY.Tarray && |
0 | 338 e2.implicitConvTo(t1.nextOf())) |
339 { // T[] op T | |
340 e2 = e2.castTo(sc, t1.nextOf()); | |
341 t = t1.nextOf().arrayOf(); | |
342 } | |
98 | 343 else if (e2.isArrayOperand() && t2.ty == TY.Tarray && |
0 | 344 e1.implicitConvTo(t2.nextOf())) |
345 { // T op T[] | |
346 e1 = e1.castTo(sc, t2.nextOf()); | |
347 t = t2.nextOf().arrayOf(); | |
348 | |
349 //printf("test %s\n", e.toChars()); | |
350 e1 = e1.optimize(WANT.WANTvalue); | |
351 if (e && e.isCommutative() && e1.isConst()) | |
352 { /* Swap operands to minimize number of functions generated | |
353 */ | |
354 //printf("swap %s\n", e.toChars()); | |
355 Expression tmp = e1; | |
356 e1 = e2; | |
357 e2 = tmp; | |
358 } | |
359 } | |
360 else | |
361 { | |
362 Lincompatible: | |
363 return 0; | |
364 } | |
365 Lret: | |
366 if (!*pt) | |
367 *pt = t; | |
368 *pe1 = e1; | |
369 *pe2 = e2; | |
370 static if (false) { | |
371 printf("-typeMerge() %s op %s\n", e1.toChars(), e2.toChars()); | |
372 if (e1.type) printf("\tt1 = %s\n", e1.type.toChars()); | |
373 if (e2.type) printf("\tt2 = %s\n", e2.type.toChars()); | |
374 printf("\ttype = %s\n", t.toChars()); | |
375 } | |
376 //dump(0); | |
377 return 1; | |
378 | |
379 | |
380 Lt1: | |
381 e2 = e2.castTo(sc, t1); | |
382 t = t1; | |
383 goto Lret; | |
384 | |
385 Lt2: | |
386 e1 = e1.castTo(sc, t2); | |
387 t = t2; | |
388 goto Lret; | |
389 } | |
390 | |
391 class BinExp : Expression | |
392 { | |
393 Expression e1; | |
394 Expression e2; | |
395 | |
396 this(Loc loc, TOK op, int size, Expression e1, Expression e2) | |
397 { | |
398 super(loc, op, size); | |
399 this.e1 = e1; | |
400 this.e2 = e2; | |
401 } | |
402 | |
72 | 403 override Expression syntaxCopy() |
0 | 404 { |
405 BinExp e = cast(BinExp)copy(); | |
406 e.type = null; | |
407 e.e1 = e.e1.syntaxCopy(); | |
408 e.e2 = e.e2.syntaxCopy(); | |
409 | |
410 return e; | |
411 } | |
412 | |
72 | 413 override Expression semantic(Scope sc) |
0 | 414 { |
415 version (LOGSEMANTIC) { | |
60 | 416 printf("BinExp.semantic('%.*s')\n", toChars()); |
0 | 417 } |
418 e1 = e1.semantic(sc); | |
419 if (!e1.type && !(op == TOK.TOKassign && e1.op == TOK.TOKdottd)) // a.template = e2 | |
420 { | |
421 error("%s has no value", e1.toChars()); | |
422 e1.type = Type.terror; | |
423 } | |
424 e2 = e2.semantic(sc); | |
425 if (!e2.type) | |
426 { | |
427 error("%s has no value", e2.toChars()); | |
428 e2.type = Type.terror; | |
429 } | |
430 return this; | |
431 } | |
432 | |
433 Expression semanticp(Scope sc) | |
434 { | |
60 | 435 BinExp.semantic(sc); |
436 | |
437 e1 = resolveProperties(sc, e1); | |
438 e2 = resolveProperties(sc, e2); | |
0 | 439 return this; |
440 } | |
441 | |
56 | 442 /*************************** |
443 * Common semantic routine for some xxxAssignExp's. | |
444 */ | |
0 | 445 Expression commonSemanticAssign(Scope sc) |
446 { | |
56 | 447 Expression e; |
448 | |
449 if (!type) | |
450 { | |
451 BinExp.semantic(sc); | |
452 e2 = resolveProperties(sc, e2); | |
453 | |
454 e = op_overload(sc); | |
455 if (e) | |
456 return e; | |
457 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
458 if (e1.op == TOK.TOKarraylength) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
459 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
460 e = ArrayLengthExp.rewriteOpAssign(this); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
461 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
462 return e; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
463 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
464 |
56 | 465 if (e1.op == TOKslice) |
466 { | |
467 // T[] op= ... | |
468 typeCombine(sc); | |
469 type = e1.type; | |
470 return arrayOp(sc); | |
471 } | |
472 | |
473 e1 = e1.modifiableLvalue(sc, e1); | |
474 e1.checkScalar(); | |
475 type = e1.type; | |
476 if (type.toBasetype().ty == Tbool) | |
477 { | |
478 error("operator not allowed on bool expression %s", toChars()); | |
479 } | |
480 typeCombine(sc); | |
481 e1.checkArithmetic(); | |
482 e2.checkArithmetic(); | |
483 | |
484 if (op == TOKmodass && e2.type.iscomplex()) | |
485 { error("cannot perform modulo complex arithmetic"); | |
486 return new ErrorExp(); | |
487 } | |
488 } | |
489 return this; | |
0 | 490 } |
491 | |
492 Expression commonSemanticAssignIntegral(Scope sc) | |
493 { | |
494 Expression e; | |
495 | |
496 if (!type) | |
497 { | |
498 BinExp.semantic(sc); | |
499 e2 = resolveProperties(sc, e2); | |
500 | |
501 e = op_overload(sc); | |
502 if (e) | |
503 return e; | |
504 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
505 if (e1.op == TOKarraylength) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
506 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
507 e = ArrayLengthExp.rewriteOpAssign(this); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
508 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
509 return e; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
510 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
511 |
0 | 512 if (e1.op == TOK.TOKslice) |
513 { // T[] op= ... | |
514 typeCombine(sc); | |
515 type = e1.type; | |
516 return arrayOp(sc); | |
517 } | |
518 | |
519 e1 = e1.modifiableLvalue(sc, e1); | |
520 e1.checkScalar(); | |
521 type = e1.type; | |
522 if (type.toBasetype().ty == TY.Tbool) | |
523 { | |
524 e2 = e2.implicitCastTo(sc, type); | |
525 } | |
526 | |
527 typeCombine(sc); | |
528 e1.checkIntegral(); | |
529 e2.checkIntegral(); | |
530 } | |
531 | |
532 return this; | |
533 } | |
534 | |
72 | 535 override bool checkSideEffect(int flag) |
0 | 536 { |
537 switch (op) { | |
538 case TOK.TOKplusplus: | |
539 case TOK.TOKminusminus: | |
540 case TOK.TOKassign: | |
541 case TOK.TOKconstruct: | |
542 case TOK.TOKblit: | |
543 case TOK.TOKaddass: | |
544 case TOK.TOKminass: | |
545 case TOK.TOKcatass: | |
546 case TOK.TOKmulass: | |
547 case TOK.TOKdivass: | |
548 case TOK.TOKmodass: | |
549 case TOK.TOKshlass: | |
550 case TOK.TOKshrass: | |
551 case TOK.TOKushrass: | |
552 case TOK.TOKandass: | |
553 case TOK.TOKorass: | |
554 case TOK.TOKxorass: | |
135 | 555 case TOK.TOKpowass: |
0 | 556 case TOK.TOKin: |
557 case TOK.TOKremove: | |
558 return true; | |
559 | |
560 default: | |
561 return Expression.checkSideEffect(flag); | |
562 } | |
563 } | |
564 | |
72 | 565 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 566 { |
567 expToCBuffer(buf, hgs, e1, precedence[op]); | |
568 buf.writeByte(' '); | |
569 buf.writestring(Token.toChars(op)); | |
570 buf.writeByte(' '); | |
571 expToCBuffer(buf, hgs, e2, cast(PREC)(precedence[op] + 1)); | |
572 } | |
573 | |
574 /**************************************** | |
575 * Scale addition/subtraction to/from pointer. | |
576 */ | |
577 Expression scaleFactor(Scope sc) | |
578 { | |
579 ulong stride; | |
580 Type t1b = e1.type.toBasetype(); | |
581 Type t2b = e2.type.toBasetype(); | |
582 | |
583 if (t1b.ty == Tpointer && t2b.isintegral()) | |
584 { | |
585 // Need to adjust operator by the stride | |
586 // Replace (ptr + int) with (ptr + (int * stride)) | |
587 Type t = Type.tptrdiff_t; | |
588 | |
589 stride = t1b.nextOf().size(loc); | |
590 if (!t.equals(t2b)) | |
591 e2 = e2.castTo(sc, t); | |
592 e2 = new MulExp(loc, e2, new IntegerExp(Loc(0), stride, t)); | |
593 e2.type = t; | |
594 type = e1.type; | |
595 } | |
596 else if (t2b.ty == Tpointer && t1b.isintegral()) | |
597 { | |
598 // Need to adjust operator by the stride | |
599 // Replace (int + ptr) with (ptr + (int * stride)) | |
600 Type t = Type.tptrdiff_t; | |
601 Expression e; | |
602 | |
603 stride = t2b.nextOf().size(loc); | |
604 if (!t.equals(t1b)) | |
605 e = e1.castTo(sc, t); | |
606 else | |
607 e = e1; | |
608 e = new MulExp(loc, e, new IntegerExp(Loc(0), stride, t)); | |
609 e.type = t; | |
610 type = e2.type; | |
611 e1 = e2; | |
612 e2 = e; | |
613 } | |
614 return this; | |
615 } | |
616 | |
617 /************************************ | |
618 * Bring leaves to common type. | |
619 */ | |
620 Expression typeCombine(Scope sc) | |
621 { | |
622 Type t1 = e1.type.toBasetype(); | |
623 Type t2 = e2.type.toBasetype(); | |
624 | |
625 if (op == TOK.TOKmin || op == TOK.TOKadd) | |
626 { | |
627 if (t1.ty == TY.Tstruct) | |
628 { | |
629 if (t2.ty == TY.Tstruct && (cast(TypeStruct)t1).sym is (cast(TypeStruct)t2).sym) | |
630 goto Lerror; | |
631 } | |
632 else if (t1.ty == TY.Tclass) | |
633 { | |
634 if (t2.ty == TY.Tclass) | |
635 goto Lerror; | |
636 } | |
637 } | |
638 | |
639 if (!typeMerge(sc, this, &type, &e1, &e2)) | |
640 goto Lerror; | |
641 return this; | |
642 | |
643 Lerror: | |
644 incompatibleTypes(); | |
645 type = Type.terror; | |
646 e1 = new ErrorExp(); | |
647 e2 = new ErrorExp(); | |
648 return this; | |
649 } | |
650 | |
72 | 651 override Expression optimize(int result) |
0 | 652 { |
653 //printf("BinExp.optimize(result = %d) %s\n", result, toChars()); | |
654 if (op != TOK.TOKconstruct && op != TOK.TOKblit) // don't replace const variable with its initializer | |
655 e1 = e1.optimize(result); | |
656 | |
657 e2 = e2.optimize(result); | |
658 if (op == TOK.TOKshlass || op == TOK.TOKshrass || op == TOK.TOKushrass) | |
659 { | |
660 if (e2.isConst() == 1) | |
661 { | |
662 long i2 = e2.toInteger(); | |
663 ulong sz = e1.type.size() * 8; | |
664 | |
665 if (i2 < 0 || i2 > sz) | |
666 { | |
667 error("shift assign by %jd is outside the range 0..%zu", i2, sz); | |
668 e2 = new IntegerExp(0); | |
669 } | |
670 } | |
671 } | |
672 | |
673 return this; | |
674 } | |
675 | |
676 bool isunsigned() | |
677 { | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
678 return e1.type.isunsigned() || e2.type.isunsigned(); |
0 | 679 } |
680 | |
681 void incompatibleTypes() | |
682 { | |
683 error("incompatible types for ((%s) %s (%s)): '%s' and '%s'", | |
684 e1.toChars(), Token.toChars(op), e2.toChars(), | |
685 e1.type.toChars(), e2.type.toChars()); | |
686 } | |
687 | |
72 | 688 override void dump(int indent) |
0 | 689 { |
690 assert(false); | |
691 } | |
692 | |
154
14feb7ae01a6
* changed the build system to build a release version if the debug one compiles
trass3r
parents:
135
diff
changeset
|
693 override void scanForNestedRef(Scope sc) |
0 | 694 { |
123 | 695 e1.scanForNestedRef(sc); |
696 e2.scanForNestedRef(sc); | |
0 | 697 } |
698 | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
699 Expression interpretCommon(InterState istate, Expression function(Type, Expression, Expression) fp) |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
700 { |
116 | 701 Expression e; |
702 Expression e1; | |
703 Expression e2; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
704 |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
705 version(LOG) |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
706 { |
116 | 707 writef("BinExp::interpretCommon() %s\n", toChars()); |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
708 } |
116 | 709 e1 = this.e1.interpret(istate); |
710 if (e1 is EXP_CANT_INTERPRET) | |
711 goto Lcant; | |
712 if (e1.isConst() != 1) | |
713 goto Lcant; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
714 |
116 | 715 e2 = this.e2.interpret(istate); |
716 if (e2 is EXP_CANT_INTERPRET) | |
717 goto Lcant; | |
718 if (e2.isConst() != 1) | |
719 goto Lcant; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
720 |
116 | 721 e = fp(type, e1, e2); |
722 return e; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
723 |
116 | 724 Lcant: |
725 return EXP_CANT_INTERPRET; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
726 } |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
727 |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
728 Expression interpretCommon2(InterState istate, Expression function(TOK, Type, Expression, Expression) fp) |
0 | 729 { |
116 | 730 Expression e; |
731 Expression e1; | |
732 Expression e2; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
733 |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
734 version(LOG) |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
735 { |
116 | 736 writef("BinExp::interpretCommon2() %s\n", toChars()); |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
737 } |
116 | 738 e1 = this.e1.interpret(istate); |
739 if (e1 is EXP_CANT_INTERPRET) | |
740 goto Lcant; | |
741 if (e1.isConst() != 1 && | |
742 e1.op != TOKnull && | |
743 e1.op != TOKstring && | |
744 e1.op != TOKarrayliteral && | |
745 e1.op != TOKstructliteral) | |
746 goto Lcant; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
747 |
116 | 748 e2 = this.e2.interpret(istate); |
749 if (e2 is EXP_CANT_INTERPRET) | |
750 goto Lcant; | |
751 if (e2.isConst() != 1 && | |
752 e2.op != TOKnull && | |
753 e2.op != TOKstring && | |
754 e2.op != TOKarrayliteral && | |
755 e2.op != TOKstructliteral) | |
756 goto Lcant; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
757 |
116 | 758 e = fp(op, type, e1, e2); |
759 return e; | |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
760 |
116 | 761 Lcant: |
762 return EXP_CANT_INTERPRET; | |
0 | 763 } |
764 | |
116 | 765 Expression interpretAssignCommon(InterState istate, Expression function(Type, Expression, Expression) fp, int post = 0) |
0 | 766 { |
116 | 767 version (LOG) |
768 { | |
769 writef("BinExp.interpretAssignCommon() %.*s\n", toChars()); | |
63 | 770 } |
771 Expression e = EXP_CANT_INTERPRET; | |
772 Expression e1 = this.e1; | |
773 | |
774 if (fp) | |
775 { | |
776 if (e1.op == TOKcast) | |
777 { | |
778 CastExp ce = cast(CastExp)e1; | |
779 e1 = ce.e1; | |
780 } | |
781 } | |
782 if (e1 is EXP_CANT_INTERPRET) | |
783 return e1; | |
784 Expression e2 = this.e2.interpret(istate); | |
785 if (e2 is EXP_CANT_INTERPRET) | |
786 return e2; | |
787 | |
788 // Chase down rebinding of out and ref. | |
789 if (e1.op == TOKvar) | |
790 { | |
791 VarExp ve = cast(VarExp)e1; | |
792 VarDeclaration v = ve.var.isVarDeclaration(); | |
793 if (v && v.value && v.value.op == TOKvar) | |
794 { | |
795 VarExp ve2 = cast(VarExp)v.value; | |
796 if (ve2.var.isSymbolDeclaration()) | |
797 { | |
798 // This can happen if v is a struct initialized to | |
799 // 0 using an __initZ SymbolDeclaration from | |
800 // TypeStruct.defaultInit() | |
801 } | |
802 else | |
803 e1 = v.value; | |
804 } | |
805 else if (v && v.value && (v.value.op==TOKindex || v.value.op == TOKdotvar)) | |
806 { | |
135 | 807 // It is no longer a TOKvar, eg when a[4] is passed by ref. |
63 | 808 e1 = v.value; |
809 } | |
810 } | |
811 | |
812 // To reduce code complexity of handling dotvar expressions, | |
813 // extract the aggregate now. | |
814 Expression aggregate; | |
815 if (e1.op == TOKdotvar) { | |
816 aggregate = (cast(DotVarExp)e1).e1; | |
817 // Get rid of 'this'. | |
818 if (aggregate.op == TOKthis && istate.localThis) | |
819 aggregate = istate.localThis; | |
820 } | |
821 | |
822 /* Assignment to variable of the form: | |
823 * v = e2 | |
824 */ | |
825 if (e1.op == TOKvar) | |
826 { | |
827 VarExp ve = cast(VarExp)e1; | |
828 VarDeclaration v = ve.var.isVarDeclaration(); | |
829 assert(v); | |
135 | 830 if (v && !v.isCTFE()) |
63 | 831 { |
832 // Can't modify global or static data | |
833 error("%s cannot be modified at compile time", v.toChars()); | |
834 return EXP_CANT_INTERPRET; | |
835 } | |
135 | 836 if (v && v.isCTFE()) |
63 | 837 { |
838 Expression ev = v.value; | |
839 if (fp && !ev) | |
840 { | |
841 error("variable %s is used before initialization", v.toChars()); | |
842 return e; | |
843 } | |
844 if (fp) | |
845 e2 = (*fp)(v.type, ev, e2); | |
846 else | |
847 { | |
848 /* Look for special case of struct being initialized with 0. | |
849 */ | |
850 if (v.type.toBasetype().ty == Tstruct && e2.op == TOKint64) | |
851 { | |
135 | 852 e2 = v.type.defaultInitLiteral(Loc(0)); |
63 | 853 } |
854 e2 = Cast(v.type, v.type, e2); | |
855 } | |
856 if (e2 is EXP_CANT_INTERPRET) | |
857 return e2; | |
858 | |
859 addVarToInterstate(istate, v); | |
860 v.value = e2; | |
861 e = Cast(type, type, post ? ev : e2); | |
862 } | |
863 } | |
864 else if (e1.op == TOKdotvar && aggregate.op == TOKdotvar) | |
865 { | |
866 // eg v.u.var = e2, v[3].u.var = e2, etc. | |
867 error("Nested struct assignment %s is not yet supported in CTFE", toChars()); | |
868 } | |
869 /* Assignment to struct member of the form: | |
870 * v.var = e2 | |
871 */ | |
872 else if (e1.op == TOKdotvar && aggregate.op == TOKvar) | |
873 { | |
874 VarDeclaration v = (cast(VarExp)aggregate).var.isVarDeclaration(); | |
875 | |
135 | 876 if (!v.isCTFE()) |
63 | 877 { |
878 // Can't modify global or static data | |
879 error("%s cannot be modified at compile time", v.toChars()); | |
880 return EXP_CANT_INTERPRET; | |
881 } else { | |
882 // Chase down rebinding of out and ref | |
883 if (v.value && v.value.op == TOKvar) | |
884 { | |
885 VarExp ve2 = cast(VarExp)v.value; | |
886 if (ve2.var.isSymbolDeclaration()) | |
887 { | |
888 // This can happen if v is a struct initialized to | |
889 // 0 using an __initZ SymbolDeclaration from | |
890 // TypeStruct.defaultInit() | |
891 } | |
892 else | |
893 v = ve2.var.isVarDeclaration(); | |
894 assert(v); | |
895 } | |
896 } | |
897 if (fp && !v.value) | |
898 { | |
899 error("variable %s is used before initialization", v.toChars()); | |
900 return e; | |
901 } | |
902 if (v.value is null && v.init.isVoidInitializer()) | |
903 { | |
904 /* Since a void initializer initializes to undefined | |
905 * values, it is valid here to use the default initializer. | |
906 * No attempt is made to determine if someone actually relies | |
907 * on the void value - to do that we'd need a VoidExp. | |
908 * That's probably a good enhancement idea. | |
909 */ | |
910 v.value = v.type.defaultInit(Loc(0)); | |
911 } | |
912 Expression vie = v.value; | |
913 if (vie.op == TOKvar) | |
914 { | |
915 Declaration d = (cast(VarExp)vie).var; | |
916 vie = getVarExp(e1.loc, istate, d); | |
917 } | |
918 if (vie.op != TOKstructliteral) | |
919 return EXP_CANT_INTERPRET; | |
920 StructLiteralExp se = cast(StructLiteralExp)vie; | |
921 VarDeclaration vf = (cast(DotVarExp)e1).var.isVarDeclaration(); | |
922 if (!vf) | |
923 return EXP_CANT_INTERPRET; | |
924 int fieldi = se.getFieldIndex(type, vf.offset); | |
925 if (fieldi == -1) | |
926 return EXP_CANT_INTERPRET; | |
927 Expression ev = se.getField(type, vf.offset); | |
928 if (fp) | |
929 e2 = (*fp)(type, ev, e2); | |
930 else | |
931 e2 = Cast(type, type, e2); | |
932 if (e2 is EXP_CANT_INTERPRET) | |
933 return e2; | |
934 | |
935 addVarToInterstate(istate, v); | |
936 | |
937 /* Create new struct literal reflecting updated fieldi | |
938 */ | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
939 auto expsx = changeOneElement(se.elements, fieldi, e2); |
63 | 940 v.value = new StructLiteralExp(se.loc, se.sd, expsx); |
941 v.value.type = se.type; | |
942 | |
943 e = Cast(type, type, post ? ev : e2); | |
944 } | |
945 /* Assignment to struct member of the form: | |
946 * *(symoffexp) = e2 | |
947 */ | |
948 else if (e1.op == TOKstar && (cast(PtrExp)e1).e1.op == TOKsymoff) | |
949 { | |
950 SymOffExp soe = cast(SymOffExp)(cast(PtrExp)e1).e1; | |
951 VarDeclaration v = soe.var.isVarDeclaration(); | |
952 | |
135 | 953 if (!v.isCTFE()) |
63 | 954 { |
955 error("%s cannot be modified at compile time", v.toChars()); | |
956 return EXP_CANT_INTERPRET; | |
957 } | |
958 if (fp && !v.value) | |
959 { | |
960 error("variable %s is used before initialization", v.toChars()); | |
961 return e; | |
962 } | |
963 Expression vie = v.value; | |
964 if (vie.op == TOKvar) | |
965 { | |
966 Declaration d = (cast(VarExp)vie).var; | |
967 vie = getVarExp(e1.loc, istate, d); | |
968 } | |
969 if (vie.op != TOKstructliteral) | |
970 return EXP_CANT_INTERPRET; | |
971 StructLiteralExp se = cast(StructLiteralExp)vie; | |
972 int fieldi = se.getFieldIndex(type, soe.offset); | |
973 if (fieldi == -1) | |
974 return EXP_CANT_INTERPRET; | |
975 Expression ev = se.getField(type, soe.offset); | |
976 if (fp) | |
977 e2 = (*fp)(type, ev, e2); | |
978 else | |
979 e2 = Cast(type, type, e2); | |
980 if (e2 is EXP_CANT_INTERPRET) | |
981 return e2; | |
982 | |
983 addVarToInterstate(istate, v); | |
984 | |
985 /* Create new struct literal reflecting updated fieldi | |
986 */ | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
987 auto expsx = changeOneElement(se.elements, fieldi, e2); |
63 | 988 v.value = new StructLiteralExp(se.loc, se.sd, expsx); |
989 v.value.type = se.type; | |
990 | |
991 e = Cast(type, type, post ? ev : e2); | |
992 } | |
993 /* Assignment to array element of the form: | |
994 * a[i] = e2 | |
995 */ | |
996 else if (e1.op == TOKindex && (cast(IndexExp)e1).e1.op == TOKvar) | |
997 { | |
998 IndexExp ie = cast(IndexExp)e1; | |
999 VarExp ve = cast(VarExp)ie.e1; | |
1000 VarDeclaration v = ve.var.isVarDeclaration(); | |
135 | 1001 if (!v || !v.isCTFE()) |
63 | 1002 { |
1003 error("%s cannot be modified at compile time", v ? v.toChars(): "void"); | |
1004 return EXP_CANT_INTERPRET; | |
1005 } | |
1006 if (v.value && v.value.op == TOKvar) | |
1007 { | |
1008 VarExp ve2 = cast(VarExp)v.value; | |
1009 if (ve2.var.isSymbolDeclaration()) | |
1010 { | |
1011 // This can happen if v is a struct initialized to | |
1012 // 0 using an __initZ SymbolDeclaration from | |
1013 // TypeStruct.defaultInit() | |
1014 } | |
1015 else | |
1016 v = ve2.var.isVarDeclaration(); | |
1017 assert(v); | |
1018 } | |
1019 if (!v.value) | |
1020 { | |
1021 if (fp) | |
1022 { | |
1023 error("variable %s is used before initialization", v.toChars()); | |
1024 return e; | |
1025 } | |
1026 | |
1027 Type t = v.type.toBasetype(); | |
1028 if (t.ty == Tsarray) | |
1029 { | |
1030 /* This array was void initialized. Create a | |
1031 * default initializer for it. | |
1032 * What we should do is fill the array literal with | |
1033 * null data, so use-before-initialized can be detected. | |
1034 * But we're too lazy at the moment to do it, as that | |
1035 * involves redoing Index() and whoever calls it. | |
1036 */ | |
1037 | |
1038 size_t dim = cast(size_t)(cast(TypeSArray)t).dim.toInteger(); | |
1039 v.value = createBlockDuplicatedArrayLiteral(v.type, | |
1040 v.type.defaultInit(Loc(0)), dim); | |
1041 } | |
1042 else | |
1043 return EXP_CANT_INTERPRET; | |
1044 } | |
1045 | |
1046 ArrayLiteralExp ae = null; | |
1047 AssocArrayLiteralExp aae = null; | |
1048 StringExp se = null; | |
1049 if (v.value.op == TOKarrayliteral) | |
1050 ae = cast(ArrayLiteralExp)v.value; | |
1051 else if (v.value.op == TOKassocarrayliteral) | |
1052 aae = cast(AssocArrayLiteralExp)v.value; | |
1053 else if (v.value.op == TOKstring) | |
1054 se = cast(StringExp)v.value; | |
1055 else if (v.value.op == TOKnull) | |
1056 { | |
1057 // This would be a runtime segfault | |
1058 error("Cannot index null array %.*s", v.toChars()); | |
1059 return EXP_CANT_INTERPRET; | |
1060 } | |
1061 else | |
1062 return EXP_CANT_INTERPRET; | |
1063 | |
1064 /* Set the $ variable | |
1065 */ | |
1066 Expression ee = ArrayLength(Type.tsize_t, v.value); | |
1067 if (ee !is EXP_CANT_INTERPRET && ie.lengthVar) | |
1068 ie.lengthVar.value = ee; | |
1069 Expression index = ie.e2.interpret(istate); | |
1070 if (index is EXP_CANT_INTERPRET) | |
1071 return EXP_CANT_INTERPRET; | |
1072 Expression ev; | |
1073 if (fp || ae || se) // not for aae, because key might not be there | |
1074 { | |
1075 ev = Index(type, v.value, index); | |
1076 if (ev is EXP_CANT_INTERPRET) | |
1077 return EXP_CANT_INTERPRET; | |
1078 } | |
1079 | |
1080 if (fp) | |
1081 e2 = (*fp)(type, ev, e2); | |
1082 else | |
1083 e2 = Cast(type, type, e2); | |
1084 if (e2 is EXP_CANT_INTERPRET) | |
1085 return e2; | |
1086 | |
1087 addVarToInterstate(istate, v); | |
1088 if (ae) | |
1089 { | |
1090 /* Create new array literal reflecting updated elem | |
1091 */ | |
1092 int elemi = cast(int)index.toInteger(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1093 auto expsx = changeOneElement(ae.elements, elemi, e2); |
63 | 1094 v.value = new ArrayLiteralExp(ae.loc, expsx); |
1095 v.value.type = ae.type; | |
1096 } | |
1097 else if (aae) | |
1098 { | |
1099 /* Create new associative array literal reflecting updated key/value | |
1100 */ | |
1101 Expressions keysx = aae.keys; | |
1102 Expressions valuesx = new Expressions(); | |
1103 valuesx.setDim(aae.values.dim); | |
1104 int updated = 0; | |
1105 for (size_t j = valuesx.dim; j; ) | |
1106 { | |
1107 j--; | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1108 Expression ekey = aae.keys[j]; |
63 | 1109 Expression ex = Equal(TOKequal, Type.tbool, ekey, index); |
1110 if (ex is EXP_CANT_INTERPRET) | |
1111 return EXP_CANT_INTERPRET; | |
1112 if (ex.isBool(true)) | |
1113 { | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1114 valuesx[j] = e2; |
63 | 1115 updated = 1; |
1116 } | |
1117 else | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1118 valuesx[j] = aae.values[j]; |
63 | 1119 } |
1120 if (!updated) | |
1121 { | |
1122 // Append index/e2 to keysx[]/valuesx[] | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1123 valuesx.push(e2); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1124 keysx = keysx.copy(); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1125 keysx.push(index); |
63 | 1126 } |
1127 v.value = new AssocArrayLiteralExp(aae.loc, keysx, valuesx); | |
1128 v.value.type = aae.type; | |
1129 } | |
1130 else if (se) | |
1131 { | |
1132 /* Create new string literal reflecting updated elem | |
1133 */ | |
1134 int elemi = cast(int)index.toInteger(); | |
1135 char* s; | |
1136 s = cast(char*)calloc(se.len + 1, se.sz); | |
1137 memcpy(s, se.string_, se.len * se.sz); | |
1138 dchar value = cast(dchar)e2.toInteger(); | |
1139 switch (se.sz) | |
1140 { | |
1141 case 1: s[elemi] = cast(char)value; break; | |
1142 case 2: (cast(wchar*)s)[elemi] = cast(wchar)value; break; | |
1143 case 4: (cast(dchar*)s)[elemi] = value; break; | |
1144 default: | |
1145 assert(0); | |
1146 break; | |
1147 } | |
1148 StringExp se2 = new StringExp(se.loc, assumeUnique(s[0..se.len])); | |
1149 se2.committed = se.committed; | |
1150 se2.postfix = se.postfix; | |
1151 se2.type = se.type; | |
1152 v.value = se2; | |
1153 } | |
1154 else | |
1155 assert(0); | |
1156 | |
1157 e = Cast(type, type, post ? ev : e2); | |
1158 } | |
1159 | |
1160 /* Assignment to struct element in array, of the form: | |
1161 * a[i].var = e2 | |
1162 */ | |
1163 else if (e1.op == TOKdotvar && aggregate.op == TOKindex && | |
1164 (cast(IndexExp)aggregate).e1.op == TOKvar) | |
1165 { | |
1166 IndexExp ie = cast(IndexExp)aggregate; | |
1167 VarExp ve = cast(VarExp)(ie.e1); | |
1168 VarDeclaration v = ve.var.isVarDeclaration(); | |
135 | 1169 if (!v || !v.isCTFE()) |
63 | 1170 { |
1171 error("%s cannot be modified at compile time", v ? v.toChars(): "void"); | |
1172 return EXP_CANT_INTERPRET; | |
1173 } | |
1174 Type t = ve.type.toBasetype(); | |
1175 ArrayLiteralExp ae = cast(ArrayLiteralExp)v.value; | |
1176 if (!ae) | |
1177 { | |
1178 // assignment to one element in an uninitialized (static) array. | |
1179 // This is quite difficult, because defaultInit() for a struct is a VarExp, | |
1180 // not a StructLiteralExp. | |
1181 Type t2 = v.type.toBasetype(); | |
1182 if (t2.ty != Tsarray) | |
1183 { | |
1184 error("Cannot index an uninitialized variable"); | |
1185 return EXP_CANT_INTERPRET; | |
1186 } | |
1187 | |
1188 Type telem = (cast(TypeSArray)t2).nextOf().toBasetype(); | |
1189 if (telem.ty != Tstruct) { return EXP_CANT_INTERPRET; } | |
1190 | |
1191 // Create a default struct literal... | |
135 | 1192 Expression structinit = telem.defaultInitLiteral(v.loc); |
63 | 1193 |
1194 // ... and use to create a blank array literal | |
1195 size_t dim = cast(size_t)(cast(TypeSArray)t2).dim.toInteger(); | |
1196 ae = createBlockDuplicatedArrayLiteral(v.type, structinit, dim); | |
1197 v.value = ae; | |
1198 } | |
1199 if (cast(Expression)(ae.elements) is EXP_CANT_INTERPRET) | |
1200 { | |
1201 // Note that this would be a runtime segfault | |
1202 error("Cannot index null array %s", v.toChars()); | |
1203 return EXP_CANT_INTERPRET; | |
1204 } | |
1205 // Set the $ variable | |
1206 Expression ee = ArrayLength(Type.tsize_t, v.value); | |
1207 if (ee !is EXP_CANT_INTERPRET && ie.lengthVar) | |
1208 ie.lengthVar.value = ee; | |
1209 // Determine the index, and check that it's OK. | |
1210 Expression index = ie.e2.interpret(istate); | |
1211 if (index is EXP_CANT_INTERPRET) | |
1212 return EXP_CANT_INTERPRET; | |
1213 | |
1214 int elemi = cast(int)index.toInteger(); | |
1215 if (elemi >= ae.elements.dim) | |
1216 { | |
1217 error("array index %d is out of bounds %s[0..%d]", elemi, | |
1218 v.toChars(), ae.elements.dim); | |
1219 return EXP_CANT_INTERPRET; | |
1220 } | |
1221 // Get old element | |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1222 auto vie = ae.elements[elemi]; |
63 | 1223 if (vie.op != TOKstructliteral) |
1224 return EXP_CANT_INTERPRET; | |
1225 | |
1226 // Work out which field needs to be changed | |
90
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1227 auto se = cast(StructLiteralExp)vie; |
39648eb578f6
more Expressions work
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
84
diff
changeset
|
1228 auto vf = (cast(DotVarExp)e1).var.isVarDeclaration(); |
63 | 1229 if (!vf) |
1230 return EXP_CANT_INTERPRET; | |
1231 | |
1232 int fieldi = se.getFieldIndex(type, vf.offset); | |
1233 if (fieldi == -1) | |
1234 return EXP_CANT_INTERPRET; | |
1235 | |
1236 Expression ev = se.getField(type, vf.offset); | |
1237 if (fp) | |
1238 e2 = (*fp)(type, ev, e2); | |
1239 else | |
1240 e2 = Cast(type, type, e2); | |
1241 if (e2 == EXP_CANT_INTERPRET) | |
1242 return e2; | |
1243 | |
1244 // Create new struct literal reflecting updated field | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1245 auto expsx = changeOneElement(se.elements, fieldi, e2); |
63 | 1246 Expression newstruct = new StructLiteralExp(se.loc, se.sd, expsx); |
1247 | |
1248 // Create new array literal reflecting updated struct elem | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1249 ae.elements = changeOneElement(ae.elements, elemi, newstruct); |
63 | 1250 return ae; |
1251 } | |
1252 /* Slice assignment, initialization of static arrays | |
1253 * a[] = e | |
1254 */ | |
1255 else if (e1.op == TOKslice && (cast(SliceExp)e1).e1.op == TOKvar) | |
1256 { | |
1257 SliceExp sexp = cast(SliceExp)e1; | |
1258 VarExp ve = cast(VarExp)(sexp.e1); | |
1259 VarDeclaration v = ve.var.isVarDeclaration(); | |
135 | 1260 if (!v || !v.isCTFE()) |
63 | 1261 { |
1262 error("%s cannot be modified at compile time", v.toChars()); | |
1263 return EXP_CANT_INTERPRET; | |
1264 } | |
1265 // Chase down rebinding of out and ref | |
1266 if (v.value && v.value.op == TOKvar) | |
1267 { | |
1268 VarExp ve2 = cast(VarExp)v.value; | |
1269 if (ve2.var.isSymbolDeclaration()) | |
1270 { | |
1271 // This can happen if v is a struct initialized to | |
1272 // 0 using an __initZ SymbolDeclaration from | |
1273 // TypeStruct.defaultInit() | |
1274 } | |
1275 else | |
1276 v = ve2.var.isVarDeclaration(); | |
1277 assert(v); | |
1278 } | |
1279 /* Set the $ variable | |
1280 */ | |
1281 Expression ee = v.value ? ArrayLength(Type.tsize_t, v.value) | |
1282 : EXP_CANT_INTERPRET; | |
1283 if (ee !is EXP_CANT_INTERPRET && sexp.lengthVar) | |
1284 sexp.lengthVar.value = ee; | |
1285 Expression upper = null; | |
1286 Expression lower = null; | |
1287 if (sexp.upr) | |
1288 { | |
1289 upper = sexp.upr.interpret(istate); | |
1290 if (upper is EXP_CANT_INTERPRET) | |
1291 return EXP_CANT_INTERPRET; | |
1292 } | |
1293 if (sexp.lwr) | |
1294 { | |
1295 lower = sexp.lwr.interpret(istate); | |
1296 if (lower is EXP_CANT_INTERPRET) | |
1297 return EXP_CANT_INTERPRET; | |
1298 } | |
1299 Type t = v.type.toBasetype(); | |
1300 size_t dim; | |
1301 if (t.ty == Tsarray) | |
1302 dim = cast(size_t)(cast(TypeSArray)t).dim.toInteger(); | |
1303 else if (t.ty == Tarray) | |
1304 { | |
1305 if (!v.value || v.value.op == TOKnull) | |
1306 { | |
1307 error("cannot assign to null array %s", v.toChars()); | |
1308 return EXP_CANT_INTERPRET; | |
1309 } | |
1310 if (v.value.op == TOKarrayliteral) | |
1311 dim = (cast(ArrayLiteralExp)v.value).elements.dim; | |
1312 else if (v.value.op ==TOKstring) | |
1313 { | |
1314 error("String slice assignment is not yet supported in CTFE"); | |
1315 return EXP_CANT_INTERPRET; | |
1316 } | |
1317 } | |
1318 else | |
1319 { | |
1320 error("%s cannot be evaluated at compile time", toChars()); | |
1321 return EXP_CANT_INTERPRET; | |
1322 } | |
1323 int upperbound = upper ? cast(int)upper.toInteger() : dim; | |
1324 int lowerbound = lower ? cast(int)lower.toInteger() : 0; | |
1325 | |
1326 ArrayLiteralExp existing; | |
1327 if ((cast(int)lowerbound < 0) || (upperbound > dim)) | |
1328 { | |
1329 error("Array bounds [0..%d] exceeded in slice [%d..%d]", dim, lowerbound, upperbound); | |
1330 return EXP_CANT_INTERPRET; | |
1331 } | |
1332 if (upperbound-lowerbound != dim) | |
1333 { | |
1334 // Only modifying part of the array. Must create a new array literal. | |
1335 // If the existing array is uninitialized (this can only happen | |
1336 // with static arrays), create it. | |
1337 if (v.value && v.value.op == TOKarrayliteral) | |
1338 existing = cast(ArrayLiteralExp)v.value; | |
1339 else | |
1340 { | |
1341 // this can only happen with static arrays | |
1342 existing = createBlockDuplicatedArrayLiteral(v.type, v.type.defaultInit(Loc(0)), dim); | |
1343 } | |
1344 } | |
1345 | |
1346 if (e2.op == TOKarrayliteral) | |
1347 { | |
1348 // Static array assignment from literal | |
1349 ArrayLiteralExp ae = cast(ArrayLiteralExp)e2; | |
1350 if (ae.elements.dim != (upperbound - lowerbound)) | |
1351 { | |
1352 error("Array length mismatch assigning [0..%d] to [%d..%d]", ae.elements.dim, lowerbound, upperbound); | |
1353 return e; | |
1354 } | |
1355 if (upperbound - lowerbound == dim) | |
1356 v.value = ae; | |
1357 else | |
1358 { | |
1359 // value[] = value[0..lower] ~ ae ~ value[upper..$] | |
1360 existing.elements = spliceElements(existing.elements, ae.elements, lowerbound); | |
1361 v.value = existing; | |
1362 } | |
1363 return e2; | |
1364 } | |
1365 else if (t.nextOf().ty == e2.type.ty) | |
1366 { | |
1367 // Static array block assignment | |
1368 if (upperbound-lowerbound ==dim) | |
1369 v.value = createBlockDuplicatedArrayLiteral(v.type, e2, dim); | |
1370 else | |
1371 { | |
1372 // value[] = value[0..lower] ~ ae ~ value[upper..$] | |
1373 existing.elements = spliceElements(existing.elements, createBlockDuplicatedArrayLiteral(v.type, e2, upperbound-lowerbound).elements, lowerbound); | |
1374 v.value = existing; | |
1375 } | |
1376 return e2; | |
1377 } | |
1378 else if (e2.op == TOKstring) | |
1379 { | |
1380 StringExp se = cast(StringExp)e2; | |
1381 // This is problematic. char[8] should be storing | |
1382 // values as a string literal, not | |
1383 // as an array literal. Then, for static arrays, we | |
1384 // could do modifications | |
1385 // in-place, with a dramatic memory and speed improvement. | |
1386 error("String slice assignment is not yet supported in CTFE"); | |
1387 return e2; | |
1388 } | |
1389 else | |
1390 { | |
1391 error("Slice operation %s cannot be evaluated at compile time", toChars()); | |
1392 return e; | |
1393 } | |
1394 } | |
1395 else | |
1396 { | |
1397 error("%s cannot be evaluated at compile time", toChars()); | |
1398 version (DEBUG) { | |
1399 dump(0); | |
1400 } | |
1401 } | |
1402 return e; | |
0 | 1403 } |
115
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
1404 |
6caaf0256da1
+ interpretation of (non-assign) binary expressions
Trass3r
parents:
114
diff
changeset
|
1405 version(DMDV2) |
72 | 1406 override bool canThrow() |
0 | 1407 { |
1408 return e1.canThrow() || e2.canThrow(); | |
1409 } | |
73 | 1410 |
1411 // generate an error if this is a nonsensical *=,/=, or %=, eg real *= imaginary | |
1412 void checkComplexMulAssign() | |
1413 { | |
1414 // Any multiplication by an imaginary or complex number yields a complex result. | |
1415 // r *= c, i*=c, r*=i, i*=i are all forbidden operations. | |
1416 string opstr = Token.toChars(op); | |
1417 if ( e1.type.isreal() && e2.type.iscomplex()) | |
1418 { | |
1419 error("%s %s %s is undefined. Did you mean %s %s %s.re ?", | |
1420 e1.type.toChars(), opstr, e2.type.toChars(), | |
1421 e1.type.toChars(), opstr, e2.type.toChars()); | |
1422 } | |
1423 else if (e1.type.isimaginary() && e2.type.iscomplex()) | |
1424 { | |
1425 error("%s %s %s is undefined. Did you mean %s %s %s.im ?", | |
1426 e1.type.toChars(), opstr, e2.type.toChars(), | |
1427 e1.type.toChars(), opstr, e2.type.toChars()); | |
1428 } | |
1429 else if ((e1.type.isreal() || e1.type.isimaginary()) && e2.type.isimaginary()) | |
1430 { | |
1431 error("%s %s %s is an undefined operation", e1.type.toChars(), | |
1432 opstr, e2.type.toChars()); | |
1433 } | |
1434 } | |
1435 | |
1436 // generate an error if this is a nonsensical += or -=, eg real += imaginary | |
1437 void checkComplexAddAssign() | |
1438 { | |
1439 // Addition or subtraction of a real and an imaginary is a complex result. | |
1440 // Thus, r+=i, r+=c, i+=r, i+=c are all forbidden operations. | |
1441 if ( (e1.type.isreal() && (e2.type.isimaginary() || e2.type.iscomplex())) || | |
1442 (e1.type.isimaginary() && (e2.type.isreal() || e2.type.iscomplex())) | |
1443 ) | |
1444 { | |
1445 error("%s %s %s is undefined (result is complex)", | |
1446 e1.type.toChars(), Token.toChars(op), e2.type.toChars()); | |
1447 } | |
1448 } | |
1449 | |
0 | 1450 |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1451 /*********************************** |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1452 * Construct the array operation expression. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1453 */ |
0 | 1454 Expression arrayOp(Scope sc) |
1455 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1456 //printf("BinExp.arrayOp() %s\n", toChars()); |
73 | 1457 |
1458 if (type.toBasetype().nextOf().toBasetype().ty == Tvoid) | |
1459 { | |
1460 error("Cannot perform array operations on void[] arrays"); | |
1461 return new ErrorExp(); | |
1462 } | |
79 | 1463 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1464 auto arguments = new Expressions(); |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1465 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1466 /* The expression to generate an array operation for is mangled |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1467 * into a name to use as the array operation function name. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1468 * Mangle in the operands and operators in RPN order, and type. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1469 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1470 scope OutBuffer buf = new OutBuffer(); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1471 buf.writestring("_array"); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1472 buildArrayIdent(buf, arguments); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1473 buf.writeByte('_'); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1474 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1475 /* Append deco of array element type |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1476 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1477 version (DMDV2) { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1478 buf.writestring(type.toBasetype().nextOf().toBasetype().mutableOf().deco); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1479 } else { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1480 buf.writestring(type.toBasetype().nextOf().toBasetype().deco); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1481 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1482 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1483 size_t namelen = buf.offset; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1484 buf.writeByte(0); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1485 immutable(char)* name = cast(immutable(char)*)buf.extractData(); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1486 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1487 /* Look up name in hash table |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1488 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1489 if (arrayfuncs is null) arrayfuncs = new StringTable(); /// HACK! |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1490 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1491 StringValue* sv = arrayfuncs.update(name[0..namelen]); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1492 FuncDeclaration fd = cast(FuncDeclaration)sv.ptrvalue; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1493 if (!fd) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1494 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1495 /* Some of the array op functions are written as library functions, |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1496 * presumably to optimize them with special CPU vector instructions. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1497 * List those library functions here, in alpha order. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1498 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1499 static const(char)*[] libArrayopFuncs = |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1500 [ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1501 "_arrayExpSliceAddass_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1502 "_arrayExpSliceAddass_d", // T[]+=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1503 "_arrayExpSliceAddass_f", // T[]+=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1504 "_arrayExpSliceAddass_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1505 "_arrayExpSliceAddass_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1506 "_arrayExpSliceAddass_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1507 "_arrayExpSliceAddass_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1508 "_arrayExpSliceAddass_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1509 "_arrayExpSliceAddass_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1510 "_arrayExpSliceAddass_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1511 "_arrayExpSliceAddass_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1512 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1513 "_arrayExpSliceDivass_d", // T[]/=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1514 "_arrayExpSliceDivass_f", // T[]/=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1515 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1516 "_arrayExpSliceMinSliceAssign_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1517 "_arrayExpSliceMinSliceAssign_d", // T[]=T-T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1518 "_arrayExpSliceMinSliceAssign_f", // T[]=T-T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1519 "_arrayExpSliceMinSliceAssign_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1520 "_arrayExpSliceMinSliceAssign_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1521 "_arrayExpSliceMinSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1522 "_arrayExpSliceMinSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1523 "_arrayExpSliceMinSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1524 "_arrayExpSliceMinSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1525 "_arrayExpSliceMinSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1526 "_arrayExpSliceMinSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1527 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1528 "_arrayExpSliceMinass_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1529 "_arrayExpSliceMinass_d", // T[]-=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1530 "_arrayExpSliceMinass_f", // T[]-=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1531 "_arrayExpSliceMinass_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1532 "_arrayExpSliceMinass_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1533 "_arrayExpSliceMinass_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1534 "_arrayExpSliceMinass_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1535 "_arrayExpSliceMinass_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1536 "_arrayExpSliceMinass_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1537 "_arrayExpSliceMinass_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1538 "_arrayExpSliceMinass_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1539 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1540 "_arrayExpSliceMulass_d", // T[]*=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1541 "_arrayExpSliceMulass_f", // T[]*=T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1542 "_arrayExpSliceMulass_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1543 "_arrayExpSliceMulass_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1544 "_arrayExpSliceMulass_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1545 "_arrayExpSliceMulass_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1546 "_arrayExpSliceMulass_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1547 "_arrayExpSliceMulass_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1548 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1549 "_arraySliceExpAddSliceAssign_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1550 "_arraySliceExpAddSliceAssign_d", // T[]=T[]+T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1551 "_arraySliceExpAddSliceAssign_f", // T[]=T[]+T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1552 "_arraySliceExpAddSliceAssign_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1553 "_arraySliceExpAddSliceAssign_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1554 "_arraySliceExpAddSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1555 "_arraySliceExpAddSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1556 "_arraySliceExpAddSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1557 "_arraySliceExpAddSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1558 "_arraySliceExpAddSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1559 "_arraySliceExpAddSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1560 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1561 "_arraySliceExpDivSliceAssign_d", // T[]=T[]/T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1562 "_arraySliceExpDivSliceAssign_f", // T[]=T[]/T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1563 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1564 "_arraySliceExpMinSliceAssign_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1565 "_arraySliceExpMinSliceAssign_d", // T[]=T[]-T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1566 "_arraySliceExpMinSliceAssign_f", // T[]=T[]-T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1567 "_arraySliceExpMinSliceAssign_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1568 "_arraySliceExpMinSliceAssign_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1569 "_arraySliceExpMinSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1570 "_arraySliceExpMinSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1571 "_arraySliceExpMinSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1572 "_arraySliceExpMinSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1573 "_arraySliceExpMinSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1574 "_arraySliceExpMinSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1575 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1576 "_arraySliceExpMulSliceAddass_d", // T[] += T[]*T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1577 "_arraySliceExpMulSliceAddass_f", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1578 "_arraySliceExpMulSliceAddass_r", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1579 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1580 "_arraySliceExpMulSliceAssign_d", // T[]=T[]*T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1581 "_arraySliceExpMulSliceAssign_f", // T[]=T[]*T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1582 "_arraySliceExpMulSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1583 "_arraySliceExpMulSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1584 "_arraySliceExpMulSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1585 "_arraySliceExpMulSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1586 "_arraySliceExpMulSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1587 "_arraySliceExpMulSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1588 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1589 "_arraySliceExpMulSliceMinass_d", // T[] -= T[]*T |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1590 "_arraySliceExpMulSliceMinass_f", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1591 "_arraySliceExpMulSliceMinass_r", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1592 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1593 "_arraySliceSliceAddSliceAssign_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1594 "_arraySliceSliceAddSliceAssign_d", // T[]=T[]+T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1595 "_arraySliceSliceAddSliceAssign_f", // T[]=T[]+T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1596 "_arraySliceSliceAddSliceAssign_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1597 "_arraySliceSliceAddSliceAssign_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1598 "_arraySliceSliceAddSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1599 "_arraySliceSliceAddSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1600 "_arraySliceSliceAddSliceAssign_r", // T[]=T[]+T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1601 "_arraySliceSliceAddSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1602 "_arraySliceSliceAddSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1603 "_arraySliceSliceAddSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1604 "_arraySliceSliceAddSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1605 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1606 "_arraySliceSliceAddass_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1607 "_arraySliceSliceAddass_d", // T[]+=T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1608 "_arraySliceSliceAddass_f", // T[]+=T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1609 "_arraySliceSliceAddass_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1610 "_arraySliceSliceAddass_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1611 "_arraySliceSliceAddass_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1612 "_arraySliceSliceAddass_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1613 "_arraySliceSliceAddass_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1614 "_arraySliceSliceAddass_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1615 "_arraySliceSliceAddass_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1616 "_arraySliceSliceAddass_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1617 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1618 "_arraySliceSliceMinSliceAssign_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1619 "_arraySliceSliceMinSliceAssign_d", // T[]=T[]-T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1620 "_arraySliceSliceMinSliceAssign_f", // T[]=T[]-T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1621 "_arraySliceSliceMinSliceAssign_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1622 "_arraySliceSliceMinSliceAssign_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1623 "_arraySliceSliceMinSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1624 "_arraySliceSliceMinSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1625 "_arraySliceSliceMinSliceAssign_r", // T[]=T[]-T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1626 "_arraySliceSliceMinSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1627 "_arraySliceSliceMinSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1628 "_arraySliceSliceMinSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1629 "_arraySliceSliceMinSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1630 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1631 "_arraySliceSliceMinass_a", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1632 "_arraySliceSliceMinass_d", // T[]-=T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1633 "_arraySliceSliceMinass_f", // T[]-=T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1634 "_arraySliceSliceMinass_g", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1635 "_arraySliceSliceMinass_h", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1636 "_arraySliceSliceMinass_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1637 "_arraySliceSliceMinass_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1638 "_arraySliceSliceMinass_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1639 "_arraySliceSliceMinass_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1640 "_arraySliceSliceMinass_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1641 "_arraySliceSliceMinass_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1642 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1643 "_arraySliceSliceMulSliceAssign_d", // T[]=T[]*T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1644 "_arraySliceSliceMulSliceAssign_f", // T[]=T[]*T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1645 "_arraySliceSliceMulSliceAssign_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1646 "_arraySliceSliceMulSliceAssign_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1647 "_arraySliceSliceMulSliceAssign_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1648 "_arraySliceSliceMulSliceAssign_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1649 "_arraySliceSliceMulSliceAssign_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1650 "_arraySliceSliceMulSliceAssign_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1651 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1652 "_arraySliceSliceMulass_d", // T[]*=T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1653 "_arraySliceSliceMulass_f", // T[]*=T[] |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1654 "_arraySliceSliceMulass_i", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1655 "_arraySliceSliceMulass_k", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1656 "_arraySliceSliceMulass_s", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1657 "_arraySliceSliceMulass_t", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1658 "_arraySliceSliceMulass_u", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1659 "_arraySliceSliceMulass_w", |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1660 ]; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1661 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1662 int i = binary(name, libArrayopFuncs.ptr, libArrayopFuncs.length); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1663 if (i == -1) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1664 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1665 debug { // Make sure our array is alphabetized |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1666 for (i = 0; i < libArrayopFuncs.length; i++) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1667 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1668 if (strcmp(name, libArrayopFuncs[i]) == 0) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1669 assert(false); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1670 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1671 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1672 /* Not in library, so generate it. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1673 * Construct the function body: |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1674 * foreach (i; 0 .. p.length) for (size_t i = 0; i < p.length; i++) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1675 * loopbody; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1676 * return p; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1677 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1678 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1679 auto fparams = new Parameters(); |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1680 Expression loopbody = buildArrayLoop(fparams); |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
1681 auto p = fparams[0 /*fparams.dim - 1*/]; |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1682 version (DMDV1) { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1683 // for (size_t i = 0; i < p.length; i++) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1684 Initializer init = new ExpInitializer(0, new IntegerExp(0, 0, Type.tsize_t)); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1685 Dsymbol d = new VarDeclaration(0, Type.tsize_t, Id.p, init); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1686 Statement s1 = new ForStatement(0, |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1687 new DeclarationStatement(0, d), |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1688 new CmpExp(TOKlt, 0, new IdentifierExp(0, Id.p), new ArrayLengthExp(0, new IdentifierExp(0, p.ident))), |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1689 new PostExp(TOKplusplus, 0, new IdentifierExp(0, Id.p)), |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1690 new ExpStatement(0, loopbody)); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1691 } else { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1692 // foreach (i; 0 .. p.length) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1693 Statement s1 = new ForeachRangeStatement(Loc(0), TOKforeach, |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
1694 new Parameter(STC.STCundefined, null, Id.p, null), |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1695 new IntegerExp(Loc(0), 0, Type.tint32), |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1696 new ArrayLengthExp(Loc(0), new IdentifierExp(Loc(0), p.ident)), |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1697 new ExpStatement(Loc(0), loopbody)); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1698 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1699 Statement s2 = new ReturnStatement(Loc(0), new IdentifierExp(Loc(0), p.ident)); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1700 //printf("s2: %s\n", s2.toChars()); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1701 Statement fbody = new CompoundStatement(Loc(0), s1, s2); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1702 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1703 /* Construct the function |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1704 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1705 TypeFunction ftype = new TypeFunction(fparams, type, 0, LINKc); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1706 //printf("ftype: %s\n", ftype.toChars()); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1707 fd = new FuncDeclaration(Loc(0), Loc(0), Lexer.idPool(name[0..namelen]), STCundefined, ftype); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1708 fd.fbody = fbody; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1709 fd.protection = PROT.PROTpublic; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1710 fd.linkage = LINKc; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1711 |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
1712 sc.module_.importedFrom.members.push(fd); |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1713 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1714 sc = sc.push(); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1715 sc.parent = sc.module_.importedFrom; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1716 sc.stc = STCundefined; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1717 sc.linkage = LINKc; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1718 fd.semantic(sc); |
79 | 1719 fd.semantic2(sc); |
1720 fd.semantic3(sc); | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1721 sc.pop(); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1722 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1723 else |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1724 { /* In library, refer to it. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1725 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1726 fd = FuncDeclaration.genCfunc(type, name[0..namelen]); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1727 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1728 sv.ptrvalue = cast(void*)fd; // cache symbol in hash table |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1729 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1730 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1731 /* Call the function fd(arguments) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1732 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1733 Expression ec = new VarExp(Loc(0), fd); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1734 Expression e = new CallExp(loc, ec, arguments); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1735 e.type = type; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
1736 return e; |
0 | 1737 } |
1738 | |
72 | 1739 override int inlineCost(InlineCostState* ics) |
0 | 1740 { |
1741 return 1 + e1.inlineCost(ics) + e2.inlineCost(ics); | |
1742 } | |
1743 | |
72 | 1744 override Expression doInline(InlineDoState ids) |
0 | 1745 { |
1746 BinExp be = cast(BinExp)copy(); | |
1747 | |
1748 be.e1 = e1.doInline(ids); | |
1749 be.e2 = e2.doInline(ids); | |
1750 return be; | |
1751 } | |
1752 | |
72 | 1753 override Expression inlineScan(InlineScanState* iss) |
0 | 1754 { |
1755 e1 = e1.inlineScan(iss); | |
1756 e2 = e2.inlineScan(iss); | |
1757 return this; | |
1758 } | |
1759 | |
1760 Expression op_overload(Scope sc) | |
1761 { | |
1762 //printf("BinExp.op_overload() (%s)\n", toChars()); | |
1763 | |
1764 AggregateDeclaration ad; | |
1765 Type t1 = e1.type.toBasetype(); | |
1766 Type t2 = e2.type.toBasetype(); | |
1767 Identifier id = opId(); | |
1768 Identifier id_r = opId_r(); | |
1769 | |
1770 Match m; | |
1771 scope Expressions args1 = new Expressions(); | |
1772 scope Expressions args2 = new Expressions(); | |
1773 int argsset = 0; | |
1774 | |
1775 AggregateDeclaration ad1; | |
1776 if (t1.ty == TY.Tclass) | |
1777 ad1 = (cast(TypeClass)t1).sym; | |
1778 else if (t1.ty == TY.Tstruct) | |
1779 ad1 = (cast(TypeStruct)t1).sym; | |
1780 else | |
1781 ad1 = null; | |
1782 | |
1783 AggregateDeclaration ad2; | |
1784 if (t2.ty == TY.Tclass) | |
1785 ad2 = (cast(TypeClass)t2).sym; | |
1786 else if (t2.ty == TY.Tstruct) | |
1787 ad2 = (cast(TypeStruct)t2).sym; | |
1788 else | |
1789 ad2 = null; | |
1790 | |
1791 Dsymbol s = null; | |
1792 Dsymbol s_r = null; | |
1793 FuncDeclaration fd = null; | |
1794 TemplateDeclaration td = null; | |
1795 if (ad1 && id) | |
1796 { | |
1797 s = search_function(ad1, id); | |
1798 } | |
1799 if (ad2 && id_r) | |
1800 { | |
1801 s_r = search_function(ad2, id_r); | |
1802 } | |
1803 | |
1804 if (s || s_r) | |
1805 { | |
1806 /* Try: | |
1807 * a.opfunc(b) | |
1808 * b.opfunc_r(a) | |
1809 * and see which is better. | |
1810 */ | |
1811 Expression e; | |
1812 FuncDeclaration lastf; | |
1813 | |
1814 args1.setDim(1); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1815 args1[0] = e1; |
0 | 1816 args2.setDim(1); |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1817 args2[0] = e2; |
0 | 1818 argsset = 1; |
1819 | |
1820 ///memset(&m, 0, sizeof(m)); | |
1821 m.last = MATCH.MATCHnomatch; | |
1822 | |
1823 if (s) | |
1824 { | |
1825 fd = s.isFuncDeclaration(); | |
1826 if (fd) | |
1827 { | |
1828 overloadResolveX(&m, fd, null, args2); | |
1829 } | |
1830 else | |
1831 { | |
1832 td = s.isTemplateDeclaration(); | |
1833 templateResolve(&m, td, sc, loc, null, null, args2); | |
1834 } | |
1835 } | |
1836 | |
1837 lastf = m.lastf; | |
1838 | |
1839 if (s_r) | |
1840 { | |
1841 fd = s_r.isFuncDeclaration(); | |
1842 if (fd) | |
1843 { | |
1844 overloadResolveX(&m, fd, null, args1); | |
1845 } | |
1846 else | |
1847 { | |
1848 td = s_r.isTemplateDeclaration(); | |
1849 templateResolve(&m, td, sc, loc, null, null, args1); | |
1850 } | |
1851 } | |
1852 | |
1853 if (m.count > 1) | |
1854 { | |
1855 // Error, ambiguous | |
1856 error("overloads %s and %s both match argument list for %s", | |
1857 m.lastf.type.toChars(), | |
1858 m.nextf.type.toChars(), | |
1859 m.lastf.toChars()); | |
1860 } | |
1861 else if (m.last == MATCH.MATCHnomatch) | |
1862 { | |
1863 m.lastf = m.anyf; | |
1864 } | |
1865 | |
1866 if (op == TOK.TOKplusplus || op == TOK.TOKminusminus) | |
1867 // Kludge because operator overloading regards e++ and e-- | |
1868 // as unary, but it's implemented as a binary. | |
1869 // Rewrite (e1 ++ e2) as e1.postinc() | |
1870 // Rewrite (e1 -- e2) as e1.postdec() | |
1871 e = build_overload(loc, sc, e1, null, id); | |
1872 else if (lastf && m.lastf == lastf || m.last == MATCH.MATCHnomatch) | |
1873 // Rewrite (e1 op e2) as e1.opfunc(e2) | |
1874 e = build_overload(loc, sc, e1, e2, id); | |
1875 else | |
1876 // Rewrite (e1 op e2) as e2.opfunc_r(e1) | |
1877 e = build_overload(loc, sc, e2, e1, id_r); | |
1878 return e; | |
1879 } | |
1880 | |
1881 if (isCommutative()) | |
1882 { | |
1883 s = null; | |
1884 s_r = null; | |
1885 if (ad1 && id_r) | |
1886 { | |
1887 s_r = search_function(ad1, id_r); | |
1888 } | |
1889 if (ad2 && id) | |
1890 { | |
1891 s = search_function(ad2, id); | |
1892 } | |
1893 | |
1894 if (s || s_r) | |
1895 { | |
1896 /* Try: | |
1897 * a.opfunc_r(b) | |
1898 * b.opfunc(a) | |
1899 * and see which is better. | |
1900 */ | |
1901 | |
1902 if (!argsset) | |
1903 { | |
1904 args1.setDim(1); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1905 args1[0] = e1; |
0 | 1906 args2.setDim(1); |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
79
diff
changeset
|
1907 args2[0] = e2; |
0 | 1908 } |
1909 | |
1910 ///memset(&m, 0, sizeof(m)); | |
1911 m.last = MATCH.MATCHnomatch; | |
1912 | |
1913 if (s_r) | |
1914 { | |
1915 fd = s_r.isFuncDeclaration(); | |
1916 if (fd) | |
1917 { | |
1918 overloadResolveX(&m, fd, null, args2); | |
1919 } | |
1920 else | |
1921 { td = s_r.isTemplateDeclaration(); | |
1922 templateResolve(&m, td, sc, loc, null, null, args2); | |
1923 } | |
1924 } | |
1925 FuncDeclaration lastf = m.lastf; | |
1926 | |
1927 if (s) | |
1928 { | |
1929 fd = s.isFuncDeclaration(); | |
1930 if (fd) | |
1931 { | |
1932 overloadResolveX(&m, fd, null, args1); | |
1933 } | |
1934 else | |
1935 { td = s.isTemplateDeclaration(); | |
1936 templateResolve(&m, td, sc, loc, null, null, args1); | |
1937 } | |
1938 } | |
1939 | |
1940 if (m.count > 1) | |
1941 { | |
1942 // Error, ambiguous | |
1943 error("overloads %s and %s both match argument list for %s", | |
1944 m.lastf.type.toChars(), | |
1945 m.nextf.type.toChars(), | |
1946 m.lastf.toChars()); | |
1947 } | |
1948 else if (m.last == MATCH.MATCHnomatch) | |
1949 { | |
1950 m.lastf = m.anyf; | |
1951 } | |
1952 | |
1953 Expression e; | |
1954 if (lastf && m.lastf == lastf || id_r && m.last == MATCH.MATCHnomatch) | |
1955 // Rewrite (e1 op e2) as e1.opfunc_r(e2) | |
1956 e = build_overload(loc, sc, e1, e2, id_r); | |
1957 else | |
1958 // Rewrite (e1 op e2) as e2.opfunc(e1) | |
1959 e = build_overload(loc, sc, e2, e1, id); | |
1960 | |
1961 // When reversing operands of comparison operators, | |
1962 // need to reverse the sense of the op | |
1963 switch (op) | |
1964 { | |
1965 case TOK.TOKlt: op = TOK.TOKgt; break; | |
1966 case TOK.TOKgt: op = TOK.TOKlt; break; | |
1967 case TOK.TOKle: op = TOK.TOKge; break; | |
1968 case TOK.TOKge: op = TOK.TOKle; break; | |
1969 | |
1970 // Floating point compares | |
1971 case TOK.TOKule: op = TOK.TOKuge; break; | |
1972 case TOK.TOKul: op = TOK.TOKug; break; | |
1973 case TOK.TOKuge: op = TOK.TOKule; break; | |
1974 case TOK.TOKug: op = TOK.TOKul; break; | |
1975 | |
1976 // These are symmetric | |
1977 case TOK.TOKunord: | |
1978 case TOK.TOKlg: | |
1979 case TOK.TOKleg: | |
1980 case TOK.TOKue: | |
1981 break; | |
123 | 1982 default: |
1983 break; /// | |
0 | 1984 } |
1985 | |
1986 return e; | |
1987 } | |
1988 } | |
1989 | |
1990 version (DMDV2) { | |
1991 // Try alias this on first operand | |
1992 if (ad1 && ad1.aliasthis) | |
1993 { | |
1994 /* Rewrite (e1 op e2) as: | |
1995 * (e1.aliasthis op e2) | |
1996 */ | |
1997 Expression e1 = new DotIdExp(loc, this.e1, ad1.aliasthis.ident); | |
1998 Expression e = copy(); | |
1999 (cast(BinExp)e).e1 = e1; | |
2000 e = e.semantic(sc); | |
2001 return e; | |
2002 } | |
2003 | |
2004 // Try alias this on second operand | |
2005 if (ad2 && ad2.aliasthis) | |
2006 { | |
2007 /* Rewrite (e1 op e2) as: | |
2008 * (e1 op e2.aliasthis) | |
2009 */ | |
2010 Expression e2 = new DotIdExp(loc, this.e2, ad2.aliasthis.ident); | |
2011 Expression e = copy(); | |
2012 (cast(BinExp)e).e2 = e2; | |
2013 e = e.semantic(sc); | |
2014 return e; | |
2015 } | |
2016 } | |
2017 return null; | |
2018 } | |
2019 | |
2020 elem* toElemBin(IRState* irs, int op) | |
2021 { | |
2022 //printf("toElemBin() '%s'\n", toChars()); | |
2023 | |
2024 tym_t tym = type.totym(); | |
2025 | |
2026 elem* el = e1.toElem(irs); | |
2027 elem* er = e2.toElem(irs); | |
2028 elem* e = el_bin(op,tym,el,er); | |
2029 el_setLoc(e,loc); | |
2030 | |
2031 return e; | |
2032 } | |
123 | 2033 final void AssignExp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str) |
2034 { | |
2035 /* Evaluate assign expressions right to left | |
2036 */ | |
2037 e2.buildArrayIdent(buf, arguments); | |
2038 e1.buildArrayIdent(buf, arguments); | |
2039 buf.writestring(Str); | |
2040 buf.writestring("ass"); | |
2041 } | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2042 |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2043 final void Exp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str) |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2044 { |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2045 /* Evaluate assign expressions left to right |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2046 */ |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2047 e1.buildArrayIdent(buf, arguments); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2048 e2.buildArrayIdent(buf, arguments); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2049 buf.writestring(Str); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2050 } |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2051 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2052 final Expression AssignExp_buildArrayLoop(AssignExpType)(Parameters fparams)// if (is (AssignExpType : AssignExp)) |
123 | 2053 { |
2054 /* Evaluate assign expressions right to left | |
2055 */ | |
2056 Expression ex2 = e2.buildArrayLoop(fparams); | |
2057 Expression ex1 = e1.buildArrayLoop(fparams); | |
126
1765f3ef917d
ClassDeclarations, Arguments -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
123
diff
changeset
|
2058 auto param = fparams[0]; |
123 | 2059 param.storageClass = STCundefined; |
2060 Expression e = new AssignExpType(Loc(0), ex1, ex2); | |
2061 return e; | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
2062 } |
123 | 2063 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
126
diff
changeset
|
2064 final Expression Exp_buildArrayLoop(ExpType)(Parameters fparams) if (is (ExpType : BinExp)) |
123 | 2065 { |
2066 /* Evaluate assign expressions left to right | |
2067 */ | |
2068 Expression ex1 = e1.buildArrayLoop(fparams); | |
2069 Expression ex2 = e2.buildArrayLoop(fparams); | |
2070 Expression e = new ExpType(Loc(0), ex1, ex2); | |
2071 return e; | |
2072 } | |
2073 } |