comparison dmd/CommaExp.d @ 0:10317f0c89a5

Initial commit
author korDen
date Sat, 24 Oct 2009 08:42:06 +0400
parents
children 51605de93870
comparison
equal deleted inserted replaced
-1:000000000000 0:10317f0c89a5
1 module dmd.CommaExp;
2
3 import dmd.Loc;
4 import dmd.BinExp;
5 import dmd.IRState;
6 import dmd.Scope;
7 import dmd.IntRange;
8 import dmd.Expression;
9 import dmd.MATCH;
10 import dmd.WANT;
11 import dmd.TOK;
12 import dmd.Type;
13 import dmd.InterState;
14
15 import dmd.backend.elem;
16 import dmd.backend.Util;
17
18 class CommaExp : BinExp
19 {
20 this(Loc loc, Expression e1, Expression e2)
21 {
22 super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2);
23 }
24
25 Expression semantic(Scope sc)
26 {
27 if (!type)
28 {
29 BinExp.semanticp(sc);
30 type = e2.type;
31 }
32 return this;
33 }
34
35 void checkEscape()
36 {
37 e2.checkEscape();
38 }
39
40 IntRange getIntRange()
41 {
42 assert(false);
43 }
44
45 version (DMDV2) {
46 int isLvalue()
47 {
48 return e2.isLvalue();
49 }
50 }
51 Expression toLvalue(Scope sc, Expression e)
52 {
53 e2 = e2.toLvalue(sc, null);
54 return this;
55 }
56
57 Expression modifiableLvalue(Scope sc, Expression e)
58 {
59 e2 = e2.modifiableLvalue(sc, e);
60 return this;
61 }
62
63 bool isBool(bool result)
64 {
65 return e2.isBool(result);
66 }
67
68 bool checkSideEffect(int flag)
69 {
70 if (flag == 2)
71 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
72 else
73 {
74 // Don't check e1 until we cast(void) the a,b code generation
75 return e2.checkSideEffect(flag);
76 }
77 }
78
79 MATCH implicitConvTo(Type t)
80 {
81 assert(false);
82 }
83
84 Expression castTo(Scope sc, Type t)
85 {
86 assert(false);
87 }
88
89 Expression optimize(int result)
90 {
91 Expression e;
92
93 //printf("CommaExp.optimize(result = %d) %s\n", result, toChars());
94 e1 = e1.optimize(result & WANTinterpret);
95 e2 = e2.optimize(result);
96 if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2))
97 {
98 e = e2;
99 if (e)
100 e.type = type;
101 }
102 else
103 e = this;
104 //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars());
105 return e;
106 }
107
108 Expression interpret(InterState* istate)
109 {
110 assert(false);
111 }
112
113 elem* toElem(IRState* irs)
114 {
115 assert(e1 && e2);
116 elem* eleft = e1.toElem(irs);
117 elem* eright = e2.toElem(irs);
118 elem* e = el_combine(eleft, eright);
119 if (e)
120 el_setLoc(e, loc);
121 return e;
122 }
123 }