Mercurial > projects > ddmd
annotate dmd/Expression.d @ 23:460959608115
Branch merge.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Mon, 12 Apr 2010 17:00:08 +0100 |
parents | 832f71e6f96c 5c9b78899f5d |
children | ccbc1e0bb3f0 |
rev | line source |
---|---|
0 | 1 module dmd.Expression; |
2 | |
3 import dmd.Loc; | |
4 import dmd.TOK; | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
5 import dmd.Argument; |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
6 import dmd.IdentifierExp; |
0 | 7 import dmd.Type; |
8 import dmd.WANT; | |
9 import dmd.Scope; | |
10 import dmd.ArrayTypes; | |
11 import dmd.OutBuffer; | |
12 import dmd.HdrGenState; | |
13 import dmd.MATCH; | |
14 import dmd.IntRange; | |
15 import dmd.Dsymbol; | |
16 import dmd.FuncDeclaration; | |
17 import dmd.InterState; | |
18 import dmd.InlineCostState; | |
19 import dmd.InlineDoState; | |
20 import dmd.InlineScanState; | |
21 import dmd.Identifier; | |
22 import dmd.IRState; | |
23 import dmd.DotIdExp; | |
24 import dmd.TypeExp; | |
25 import dmd.DYNCAST; | |
26 import dmd.TY; | |
27 import dmd.CallExp; | |
28 import dmd.VarExp; | |
29 import dmd.STC; | |
30 import dmd.TemplateInstance; | |
31 import dmd.CommaExp; | |
32 import dmd.NullExp; | |
33 import dmd.AddrExp; | |
34 import dmd.ErrorExp; | |
35 import dmd.TypeStruct; | |
36 import dmd.CastExp; | |
37 import dmd.Global; | |
38 import dmd.Token; | |
39 import dmd.TypeClass; | |
40 import dmd.PtrExp; | |
41 import dmd.TypeSArray; | |
42 import dmd.TypeReference; | |
43 import dmd.Util; | |
44 import dmd.Complex; | |
45 | |
46 import dmd.backend.elem; | |
47 import dmd.backend.dt_t; | |
48 | |
4 | 49 import core.memory; |
2 | 50 |
0 | 51 import std.stdio : writef; |
52 | |
53 import std.conv; | |
54 | |
55 /* Things like: | |
56 * int.size | |
57 * foo.size | |
58 * (foo).size | |
59 * cast(foo).size | |
60 */ | |
61 | |
62 Expression typeDotIdExp(Loc loc, Type type, Identifier ident) | |
63 { | |
64 return new DotIdExp(loc, new TypeExp(loc, type), ident); | |
65 } | |
66 | |
67 /***************************************** | |
68 * Determine if 'this' is available. | |
69 * If it is, return the FuncDeclaration that has it. | |
70 */ | |
71 | |
72 FuncDeclaration hasThis(Scope sc) | |
73 { | |
74 FuncDeclaration fd; | |
75 FuncDeclaration fdthis; | |
76 | |
77 //printf("hasThis()\n"); | |
78 fdthis = sc.parent.isFuncDeclaration(); | |
79 //printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis.toChars() : ""); | |
80 | |
81 // Go upwards until we find the enclosing member function | |
82 fd = fdthis; | |
83 while (1) | |
84 { | |
85 if (!fd) | |
86 { | |
87 goto Lno; | |
88 } | |
89 if (!fd.isNested()) | |
90 break; | |
91 | |
92 Dsymbol parent = fd.parent; | |
93 while (parent) | |
94 { | |
95 TemplateInstance ti = parent.isTemplateInstance(); | |
96 if (ti) | |
97 parent = ti.parent; | |
98 else | |
99 break; | |
100 } | |
101 | |
102 fd = fd.parent.isFuncDeclaration(); | |
103 } | |
104 | |
105 if (!fd.isThis()) | |
106 { | |
107 //printf("test '%s'\n", fd.toChars()); | |
108 goto Lno; | |
109 } | |
110 | |
111 assert(fd.vthis); | |
112 return fd; | |
113 | |
114 Lno: | |
115 return null; // don't have 'this' available | |
116 } | |
117 | |
118 /*************************************** | |
119 * Pull out any properties. | |
120 */ | |
121 | |
122 Expression resolveProperties(Scope sc, Expression e) | |
123 { | |
124 //printf("resolveProperties(%s)\n", e.toChars()); | |
125 if (e.type) | |
126 { | |
127 Type t = e.type.toBasetype(); | |
128 | |
129 if (t.ty == TY.Tfunction || e.op == TOK.TOKoverloadset) | |
130 { | |
131 e = new CallExp(e.loc, e); | |
132 e = e.semantic(sc); | |
133 } | |
134 | |
135 /* Look for e being a lazy parameter; rewrite as delegate call | |
136 */ | |
137 else if (e.op == TOK.TOKvar) | |
138 { VarExp ve = cast(VarExp)e; | |
139 | |
140 if (ve.var.storage_class & STC.STClazy) | |
141 { | |
142 e = new CallExp(e.loc, e); | |
143 e = e.semantic(sc); | |
144 } | |
145 } | |
146 | |
147 else if (e.op == TOK.TOKdotexp) | |
148 { | |
149 e.error("expression has no value"); | |
150 } | |
151 } | |
152 else if (e.op == TOK.TOKdottd) | |
153 { | |
154 e = new CallExp(e.loc, e); | |
155 e = e.semantic(sc); | |
156 } | |
157 | |
158 return e; | |
159 } | |
160 | |
161 class Expression | |
162 { | |
163 Loc loc; // file location | |
164 TOK op; // handy to minimize use of dynamic_cast | |
165 Type type; // !=null means that semantic() has been run | |
166 int size; // # of bytes in Expression so we can copy() it | |
167 | |
168 this(Loc loc, TOK op, int size) | |
169 { | |
170 this.loc = loc; | |
171 //writef("Expression.Expression(op = %d %s) this = %p\n", op, to!(string)(op), this); | |
172 this.op = op; | |
173 this.size = size; | |
174 type = null; | |
175 } | |
176 | |
177 int equals(Object o) | |
178 { | |
179 return this is o; | |
180 } | |
181 | |
182 /********************************* | |
183 * Does *not* do a deep copy. | |
184 */ | |
185 Expression copy() /// bad bad bad | |
186 { | |
187 Expression e; | |
188 if (!size) | |
189 { | |
190 debug { | |
191 writef("No expression copy for: %s\n", toChars()); | |
192 writef("op = %d\n", op); | |
193 dump(0); | |
194 } | |
195 assert(0); | |
196 } | |
197 auto size = this.classinfo.init.length; | |
2 | 198 auto ptr = GC.malloc(size); |
0 | 199 memcpy(ptr, cast(void*)this, size); |
200 | |
201 return cast(Expression)ptr; | |
202 } | |
203 | |
204 Expression syntaxCopy() | |
205 { | |
206 //printf("Expression::syntaxCopy()\n"); | |
207 //dump(0); | |
208 return copy(); | |
209 } | |
210 | |
211 Expression semantic(Scope sc) | |
212 { | |
213 version (LOGSEMANTIC) { | |
214 printf("Expression.semantic() %s\n", toChars()); | |
215 } | |
216 if (type) | |
217 type = type.semantic(loc, sc); | |
218 else | |
219 type = Type.tvoid; | |
220 return this; | |
221 } | |
222 | |
223 Expression trySemantic(Scope sc) | |
224 { | |
225 uint errors = global.errors; | |
226 global.gag++; | |
227 Expression e = semantic(sc); | |
228 global.gag--; | |
229 if (errors != global.errors) | |
230 { | |
231 global.errors = errors; | |
232 e = null; | |
233 } | |
234 return e; | |
235 } | |
236 | |
237 DYNCAST dyncast() { return DYNCAST.DYNCAST_EXPRESSION; } // kludge for template.isExpression() | |
238 | |
239 void print() | |
240 { | |
241 assert(false); | |
242 } | |
243 | |
244 string toChars() | |
245 { | |
246 scope OutBuffer buf = new OutBuffer(); | |
247 HdrGenState hgs; | |
248 | |
249 toCBuffer(buf, &hgs); | |
250 return buf.toChars(); | |
251 } | |
252 | |
253 void dump(int indent) | |
254 { | |
255 assert(false); | |
256 } | |
257 | |
258 void error(T...)(string format, T t) | |
259 { | |
260 .error(loc, format, t); | |
261 } | |
262 | |
263 void warning(T...)(string formar, T t) | |
264 { | |
265 .warning(loc, format, t); | |
266 } | |
267 | |
268 void rvalue() | |
269 { | |
270 if (type && type.toBasetype().ty == TY.Tvoid) | |
271 { | |
272 error("expression %s is void and has no value", toChars()); | |
273 static if (false) { | |
274 dump(0); | |
275 halt(); | |
276 } | |
277 type = Type.terror; | |
278 } | |
279 } | |
280 | |
281 static Expression combine(Expression e1, Expression e2) | |
282 { | |
283 if (e1) | |
284 { | |
285 if (e2) | |
286 { | |
287 e1 = new CommaExp(e1.loc, e1, e2); | |
288 e1.type = e2.type; | |
289 } | |
290 } | |
291 else | |
292 { | |
293 e1 = e2; | |
294 } | |
295 | |
296 return e1; | |
297 } | |
298 | |
299 static Expressions arraySyntaxCopy(Expressions exps) | |
300 { | |
301 Expressions a = null; | |
302 | |
303 if (exps) | |
304 { | |
305 a = new Expressions(); | |
306 a.setDim(exps.dim); | |
307 for (int i = 0; i < a.dim; i++) | |
308 { | |
309 Expression e = cast(Expression)exps.data[i]; | |
310 | |
311 e = e.syntaxCopy(); | |
312 a.data[i] = cast(void*)e; | |
313 } | |
314 } | |
315 return a; | |
316 } | |
317 | |
318 ulong toInteger() | |
319 { | |
320 assert(false); | |
321 } | |
322 | |
323 ulong toUInteger() | |
324 { | |
325 //printf("Expression %s\n", Token.toChars(op)); | |
326 return cast(ulong)toInteger(); | |
327 } | |
328 | |
329 real toReal() | |
330 { | |
331 assert(false); | |
332 } | |
333 | |
334 real toImaginary() | |
335 { | |
336 assert(false); | |
337 } | |
338 | |
339 Complex!(real) toComplex() | |
340 { | |
341 assert(false); | |
342 } | |
343 | |
344 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
345 { | |
346 buf.writestring(Token.toChars(op)); | |
347 } | |
348 | |
349 void toMangleBuffer(OutBuffer buf) | |
350 { | |
351 assert(false); | |
352 } | |
353 | |
354 int isLvalue() | |
355 { | |
356 assert(false); | |
357 } | |
358 | |
359 Expression toLvalue(Scope sc, Expression e) | |
360 { | |
361 assert(false); | |
362 } | |
363 | |
364 Expression modifiableLvalue(Scope sc, Expression e) | |
365 { | |
366 //printf("Expression::modifiableLvalue() %s, type = %s\n", toChars(), type.toChars()); | |
367 | |
368 // See if this expression is a modifiable lvalue (i.e. not const) | |
369 version (DMDV2) { | |
370 if (type && (!type.isMutable() || !type.isAssignable())) | |
371 error("%s is not mutable", e.toChars()); | |
372 } | |
373 return toLvalue(sc, e); | |
374 } | |
375 | |
376 /************************************** | |
377 * Do an implicit cast. | |
378 * Issue error if it can't be done. | |
379 */ | |
380 Expression implicitCastTo(Scope sc, Type t) | |
381 { | |
382 //printf("Expression.implicitCastTo(%s of type %s) => %s\n", toChars(), type.toChars(), t.toChars()); | |
383 | |
384 MATCH match = implicitConvTo(t); | |
385 if (match) | |
386 { | |
387 TY tyfrom = type.toBasetype().ty; | |
388 TY tyto = t.toBasetype().ty; | |
389 | |
390 version (DMDV1) { | |
391 if (global.params.warnings && | |
392 Type.impcnvWarn[tyfrom][tyto] && | |
393 op != TOKint64) | |
394 { | |
395 Expression e = optimize(WANT.WANTflags | WANT.WANTvalue); | |
396 | |
397 if (e.op == TOK.TOKint64) | |
398 return e.implicitCastTo(sc, t); | |
399 if (tyfrom == Tint32 && (op == TOKadd || op == TOKmin || op == TOKand || op == TOKor || op == TOKxor)) | |
400 { | |
401 /* This is really only a semi-kludge fix, | |
402 * we really should look at the operands of op | |
403 * and see if they are narrower types. | |
404 * For example, b=b|b and b=b|7 and s=b+b should be allowed, | |
405 * but b=b|i should be an error. | |
406 */ | |
407 ; | |
408 } | |
409 else | |
410 { | |
411 warning("implicit conversion of expression (%s) of type %s to %s can cause loss of data", toChars(), type.toChars(), t.toChars()); | |
412 } | |
413 } | |
414 } | |
415 version (DMDV2) { | |
416 if (match == MATCH.MATCHconst && t == type.constOf()) | |
417 { | |
418 Expression e = copy(); | |
419 e.type = t; | |
420 return e; | |
421 } | |
422 } | |
423 return castTo(sc, t); | |
424 } | |
425 | |
426 Expression e = optimize(WANT.WANTflags | WANT.WANTvalue); | |
427 if (e != this) | |
428 return e.implicitCastTo(sc, t); | |
429 | |
430 static if (false) { | |
431 printf("ty = %d\n", type.ty); | |
432 print(); | |
433 type.print(); | |
434 printf("to:\n"); | |
435 t.print(); | |
436 printf("%p %p type: %s to: %s\n", type.deco, t.deco, type.deco, t.deco); | |
437 //printf("%p %p %p\n", type.nextOf().arrayOf(), type, t); | |
438 fflush(stdout); | |
439 } | |
440 if (!t.deco) { | |
441 /* Can happen with: | |
442 * enum E { One } | |
443 * class A | |
444 * { static void fork(EDG dg) { dg(E.One); } | |
445 * alias void delegate(E) EDG; | |
446 * } | |
447 * Should eventually make it work. | |
448 */ | |
449 error("forward reference to type %s", t.toChars()); | |
450 } else if (t.reliesOnTident()) { | |
451 error("forward reference to type %s", t.reliesOnTident().toChars()); | |
452 } | |
453 | |
454 error("cannot implicitly convert expression (%s) of type %s to %s", toChars(), type.toChars(), t.toChars()); | |
455 return castTo(sc, t); | |
456 } | |
457 | |
458 /******************************************* | |
459 * Return !=0 if we can implicitly convert this to type t. | |
460 * Don't do the actual cast. | |
461 */ | |
462 MATCH implicitConvTo(Type t) | |
463 { | |
464 static if (false) { | |
465 printf("Expression.implicitConvTo(this=%s, type=%s, t=%s)\n", | |
466 toChars(), type.toChars(), t.toChars()); | |
467 } | |
468 //static int nest; if (++nest == 10) halt(); | |
469 if (!type) | |
470 { | |
471 error("%s is not an expression", toChars()); | |
472 type = Type.terror; | |
473 } | |
474 Expression e = optimize(WANT.WANTvalue | WANT.WANTflags); | |
475 if (e.type == t) | |
476 return MATCH.MATCHexact; | |
477 if (e != this) | |
478 { | |
479 //printf("\toptimized to %s of type %s\n", e.toChars(), e.type.toChars()); | |
480 return e.implicitConvTo(t); | |
481 } | |
482 MATCH match = type.implicitConvTo(t); | |
483 if (match != MATCH.MATCHnomatch) | |
484 return match; | |
485 | |
486 /* See if we can do integral narrowing conversions | |
487 */ | |
488 if (type.isintegral() && t.isintegral() && | |
489 type.isTypeBasic() && t.isTypeBasic()) | |
490 { | |
491 IntRange ir = getIntRange(); | |
492 if (ir.imax <= t.sizemask()) | |
493 return MATCH.MATCHconvert; | |
494 } | |
495 | |
496 static if (false) { | |
497 Type tb = t.toBasetype(); | |
498 if (tb.ty == Tdelegate) | |
499 { | |
500 TypeDelegate td = cast(TypeDelegate)tb; | |
501 TypeFunction tf = cast(TypeFunction)td.nextOf(); | |
502 | |
503 if (!tf.varargs && !(tf.arguments && tf.arguments.dim)) | |
504 { | |
505 match = type.implicitConvTo(tf.nextOf()); | |
506 if (match) | |
507 return match; | |
508 if (tf.nextOf().toBasetype().ty == Tvoid) | |
509 return MATCH.MATCHconvert; | |
510 } | |
511 } | |
512 } | |
513 return MATCH.MATCHnomatch; | |
514 } | |
515 | |
516 IntRange getIntRange() | |
517 { | |
518 assert(false); | |
519 } | |
520 | |
521 /************************************** | |
522 * Do an explicit cast. | |
523 */ | |
524 Expression castTo(Scope sc, Type t) | |
525 { | |
526 //printf("Expression.castTo(this=%s, t=%s)\n", toChars(), t.toChars()); | |
527 static if (false) { | |
528 writef("Expression.castTo(this=%s, type=%s, t=%s)\n", | |
529 toChars(), type.toChars(), t.toChars()); | |
530 } | |
531 if (type is t) | |
532 return this; | |
533 Expression e = this; | |
534 Type tb = t.toBasetype(); | |
535 Type typeb = type.toBasetype(); | |
536 if (tb != typeb) | |
537 { | |
538 // Do (type *) cast of (type [dim]) | |
539 if (tb.ty == TY.Tpointer && typeb.ty == TY.Tsarray | |
540 ) | |
541 { | |
542 //printf("Converting [dim] to *\n"); | |
543 | |
544 if (typeb.size(loc) == 0) | |
545 e = new NullExp(loc); | |
546 else | |
547 e = new AddrExp(loc, e); | |
548 } | |
549 else { | |
550 static if (false) { | |
551 if (tb.ty == Tdelegate && type.ty != Tdelegate) | |
552 { | |
553 TypeDelegate td = cast(TypeDelegate)tb; | |
554 TypeFunction tf = cast(TypeFunction)td.nextOf(); | |
555 return toDelegate(sc, tf.nextOf()); | |
556 } | |
557 } | |
558 if (typeb.ty == TY.Tstruct) | |
559 { | |
560 TypeStruct ts = cast(TypeStruct)typeb; | |
561 if (!(tb.ty == TY.Tstruct && ts.sym == (cast(TypeStruct)tb).sym) && | |
562 ts.sym.aliasthis) | |
563 { /* Forward the cast to our alias this member, rewrite to: | |
564 * cast(to)e1.aliasthis | |
565 */ | |
566 Expression e1 = new DotIdExp(loc, this, ts.sym.aliasthis.ident); | |
567 Expression e2 = new CastExp(loc, e1, tb); | |
568 e2 = e2.semantic(sc); | |
569 return e2; | |
570 } | |
571 } | |
572 else if (typeb.ty == TY.Tclass) | |
573 { | |
574 TypeClass ts = cast(TypeClass)typeb; | |
575 if (tb.ty != TY.Tclass && ts.sym.aliasthis) | |
576 { /* Forward the cast to our alias this member, rewrite to: | |
577 * cast(to)e1.aliasthis | |
578 */ | |
579 Expression e1 = new DotIdExp(loc, this, ts.sym.aliasthis.ident); | |
580 Expression e2 = new CastExp(loc, e1, tb); | |
581 e2 = e2.semantic(sc); | |
582 return e2; | |
583 } | |
584 } | |
585 e = new CastExp(loc, e, tb); | |
586 } | |
587 } | |
588 else | |
589 { | |
590 e = e.copy(); // because of COW for assignment to e.type | |
591 } | |
592 | |
593 assert(e != this); | |
594 e.type = t; | |
595 //printf("Returning: %s\n", e.toChars()); | |
596 return e; | |
597 } | |
598 | |
599 /************************************ | |
600 * Detect cases where pointers to the stack can 'escape' the | |
601 * lifetime of the stack frame. | |
602 */ | |
603 void checkEscape() | |
604 { | |
605 } | |
606 | |
607 void checkScalar() | |
608 { | |
609 if (!type.isscalar()) | |
610 error("'%s' is not a scalar, it is a %s", toChars(), type.toChars()); | |
611 | |
612 rvalue(); | |
613 } | |
614 | |
615 void checkNoBool() | |
616 { | |
617 if (type.toBasetype().ty == TY.Tbool) | |
618 error("operation not allowed on bool '%s'", toChars()); | |
619 } | |
620 | |
621 Expression checkIntegral() | |
622 { | |
623 if (!type.isintegral()) | |
624 { | |
625 error("'%s' is not of integral type, it is a %s", toChars(), type.toChars()); | |
626 return new ErrorExp(); | |
627 } | |
628 | |
629 rvalue(); | |
630 return this; | |
631 } | |
632 | |
633 Expression checkArithmetic() | |
634 { | |
635 if (!type.isintegral() && !type.isfloating()) | |
636 { | |
637 error("'%s' is not of arithmetic type, it is a %s", toChars(), type.toChars()); | |
638 return new ErrorExp(); | |
639 } | |
640 | |
641 rvalue(); | |
642 return this; | |
643 } | |
644 | |
645 void checkDeprecated(Scope sc, Dsymbol s) | |
646 { | |
647 s.checkDeprecated(loc, sc); | |
648 } | |
649 | |
650 void checkPurity(Scope sc, FuncDeclaration f) | |
651 { | |
652 static if (true) { | |
653 if (sc.func) | |
654 { | |
655 FuncDeclaration outerfunc = sc.func; | |
656 while (outerfunc.toParent2() && outerfunc.toParent2().isFuncDeclaration()) | |
657 { | |
658 outerfunc = outerfunc.toParent2().isFuncDeclaration(); | |
659 } | |
660 if (outerfunc.isPure() && !sc.intypeof && (!f.isNested() && !f.isPure())) | |
661 error("pure function '%s' cannot call impure function '%s'\n", | |
662 sc.func.toChars(), f.toChars()); | |
663 } | |
664 } else { | |
665 if (sc.func && sc.func.isPure() && !sc.intypeof && !f.isPure()) | |
666 error("pure function '%s' cannot call impure function '%s'\n", | |
667 sc.func.toChars(), .toChars()); | |
668 } | |
669 } | |
670 | |
671 /***************************** | |
672 * Check that expression can be tested for true or false. | |
673 */ | |
674 Expression checkToBoolean() | |
675 { | |
676 // Default is 'yes' - do nothing | |
677 | |
678 debug { | |
679 if (!type) | |
680 dump(0); | |
681 } | |
682 | |
683 if (!type.checkBoolean()) | |
684 { | |
685 error("expression %s of type %s does not have a boolean value", toChars(), type.toChars()); | |
686 } | |
687 | |
688 return this; | |
689 } | |
690 | |
691 Expression checkToPointer() | |
692 { | |
693 Expression e; | |
694 Type tb; | |
695 | |
696 //printf("Expression::checkToPointer()\n"); | |
697 e = this; | |
698 | |
699 // If C static array, convert to pointer | |
700 tb = type.toBasetype(); | |
701 if (tb.ty == Tsarray) | |
702 { | |
703 TypeSArray ts = cast(TypeSArray)tb; | |
704 if (ts.size(loc) == 0) | |
705 e = new NullExp(loc); | |
706 else | |
707 e = new AddrExp(loc, this); | |
708 e.type = ts.next.pointerTo(); | |
709 } | |
710 return e; | |
711 } | |
712 | |
713 Expression addressOf(Scope sc) | |
714 { | |
715 //printf("Expression::addressOf()\n"); | |
716 Expression e = toLvalue(sc, null); | |
717 e = new AddrExp(loc, e); | |
718 e.type = type.pointerTo(); | |
719 return e; | |
720 } | |
721 | |
722 /****************************** | |
723 * If this is a reference, dereference it. | |
724 */ | |
725 Expression deref() | |
726 { | |
727 //printf("Expression::deref()\n"); | |
728 if (type.ty == TY.Treference) | |
729 { | |
730 Expression e = new PtrExp(loc, this); | |
731 e.type = (cast(TypeReference)type).next; | |
732 return e; | |
733 } | |
734 return this; | |
735 } | |
736 | |
737 /*********************************** | |
738 * Do integral promotions (convertchk). | |
739 * Don't convert <array of> to <pointer to> | |
740 */ | |
741 Expression integralPromotions(Scope sc) | |
742 { | |
743 Expression e = this; | |
744 | |
745 //printf("integralPromotions %s %s\n", e.toChars(), e.type.toChars()); | |
746 switch (type.toBasetype().ty) | |
747 { | |
748 case TY.Tvoid: | |
749 error("void has no value"); | |
750 break; | |
751 | |
752 case TY.Tint8: | |
753 case TY.Tuns8: | |
754 case TY.Tint16: | |
755 case TY.Tuns16: | |
756 case TY.Tbit: | |
757 case TY.Tbool: | |
758 case TY.Tchar: | |
759 case TY.Twchar: | |
760 e = e.castTo(sc, Type.tint32); | |
761 break; | |
762 | |
763 case TY.Tdchar: | |
764 e = e.castTo(sc, Type.tuns32); | |
765 break; | |
766 default: | |
767 break; /// | |
768 } | |
769 return e; | |
770 } | |
771 | |
772 Expression toDelegate(Scope sc, Type t) | |
773 { | |
774 assert(false); | |
775 } | |
776 | |
777 void scanForNestedRef(Scope sc) | |
778 { | |
779 assert(false); | |
780 } | |
781 | |
782 Expression optimize(int result) | |
783 { | |
784 //printf("Expression.optimize(result = x%x) %s\n", result, toChars()); | |
785 return this; | |
786 } | |
787 | |
788 Expression interpret(InterState istate) | |
789 { | |
790 assert(false); | |
791 } | |
792 | |
793 int isConst() | |
794 { | |
795 //printf("Expression::isConst(): %s\n", toChars()); | |
796 return 0; | |
797 } | |
798 | |
799 /******************************** | |
800 * Does this expression statically evaluate to a boolean TRUE or FALSE? | |
801 */ | |
802 bool isBool(bool result) | |
803 { | |
804 return false; | |
805 } | |
806 | |
807 int isBit() | |
808 { | |
809 assert(false); | |
810 } | |
811 | |
812 /******************************** | |
813 * Check for expressions that have no use. | |
814 * Input: | |
815 * flag 0 not going to use the result, so issue error message if no | |
816 * side effects | |
817 * 1 the result of the expression is used, but still check | |
818 * for useless subexpressions | |
819 * 2 do not issue error messages, just return !=0 if expression | |
820 * has side effects | |
821 */ | |
822 bool checkSideEffect(int flag) | |
823 { | |
824 if (flag == 0) | |
825 { | |
826 if (op == TOKimport) | |
827 error("%s has no effect", toChars()); | |
828 else | |
829 error("%s has no effect in expression (%s)", | |
830 | |
831 Token.toChars(op), toChars()); | |
832 } | |
833 | |
834 return false; | |
835 } | |
836 | |
837 bool canThrow() | |
838 { | |
839 version (DMDV2) { | |
840 return false; | |
841 } else { | |
842 return true; | |
843 } | |
844 } | |
845 | |
846 int inlineCost(InlineCostState* ics) | |
847 { | |
848 return 1; | |
849 } | |
850 | |
851 Expression doInline(InlineDoState ids) | |
852 { | |
853 //printf("Expression.doInline(%s): %s\n", Token.toChars(op), toChars()); | |
854 return copy(); | |
855 } | |
856 | |
857 Expression inlineScan(InlineScanState* iss) | |
858 { | |
859 return this; | |
860 } | |
861 | |
862 /*********************************** | |
863 * Determine if operands of binary op can be reversed | |
864 * to fit operator overload. | |
865 */ | |
866 | |
867 // For operator overloading | |
868 bool isCommutative() | |
869 { | |
870 return false; // default is no reverse | |
871 } | |
872 | |
873 /*********************************** | |
874 * Get Identifier for operator overload. | |
875 */ | |
876 Identifier opId() | |
877 { | |
878 assert(false); | |
879 } | |
880 | |
881 /*********************************** | |
882 * Get Identifier for reverse operator overload, | |
883 * null if not supported for this operator. | |
884 */ | |
885 Identifier opId_r() | |
886 { | |
887 return null; | |
888 } | |
889 | |
890 // For array ops | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
891 /****************************************** |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
892 * Construct the identifier for the array operation function, |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
893 * and build the argument list to pass to it. |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
894 */ |
0 | 895 void buildArrayIdent(OutBuffer buf, Expressions arguments) |
896 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
897 buf.writestring("Exp"); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
898 arguments.shift(cast(void*)this); |
0 | 899 } |
900 | |
901 Expression buildArrayLoop(Arguments fparams) | |
902 { | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
903 Identifier id = Identifier.generateId("c", fparams.dim); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
904 Argument param = new Argument(STC.STCundefined, type, id, null); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
905 fparams.shift(cast(void*)param); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
906 Expression e = new IdentifierExp(Loc(0), id); |
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
907 return e; |
0 | 908 } |
909 | |
910 // Back end | |
911 elem* toElem(IRState* irs) | |
912 { | |
913 assert(false); | |
914 } | |
915 | |
916 dt_t** toDt(dt_t** pdt) | |
917 { | |
918 assert(false); | |
919 } | |
16
5c9b78899f5d
Implemented methods for Tuples, fixed some linking issues.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
920 } |