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