0
|
1 module dmd.CommaExp;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Loc;
|
|
5 import dmd.BinExp;
|
|
6 import dmd.IRState;
|
|
7 import dmd.Scope;
|
|
8 import dmd.IntRange;
|
|
9 import dmd.Expression;
|
163
|
10 import dmd.GlobalExpressions;
|
0
|
11 import dmd.MATCH;
|
|
12 import dmd.WANT;
|
|
13 import dmd.TOK;
|
|
14 import dmd.Type;
|
|
15 import dmd.InterState;
|
|
16
|
|
17 import dmd.backend.elem;
|
|
18 import dmd.backend.Util;
|
|
19
|
|
20 class CommaExp : BinExp
|
|
21 {
|
|
22 this(Loc loc, Expression e1, Expression e2)
|
|
23 {
|
178
|
24 register();
|
|
25
|
0
|
26 super(loc, TOK.TOKcomma, CommaExp.sizeof, e1, e2);
|
|
27 }
|
|
28
|
72
|
29 override Expression semantic(Scope sc)
|
0
|
30 {
|
|
31 if (!type)
|
|
32 {
|
|
33 BinExp.semanticp(sc);
|
|
34 type = e2.type;
|
|
35 }
|
|
36 return this;
|
|
37 }
|
|
38
|
72
|
39 override void checkEscape()
|
0
|
40 {
|
|
41 e2.checkEscape();
|
|
42 }
|
|
43
|
135
|
44 override void checkEscapeRef()
|
|
45 {
|
|
46 e2.checkEscapeRef();
|
|
47 }
|
|
48
|
72
|
49 override IntRange getIntRange()
|
0
|
50 {
|
|
51 assert(false);
|
|
52 }
|
|
53
|
|
54 version (DMDV2) {
|
72
|
55 override int isLvalue()
|
0
|
56 {
|
|
57 return e2.isLvalue();
|
|
58 }
|
|
59 }
|
72
|
60 override Expression toLvalue(Scope sc, Expression e)
|
0
|
61 {
|
|
62 e2 = e2.toLvalue(sc, null);
|
|
63 return this;
|
|
64 }
|
|
65
|
72
|
66 override Expression modifiableLvalue(Scope sc, Expression e)
|
0
|
67 {
|
|
68 e2 = e2.modifiableLvalue(sc, e);
|
|
69 return this;
|
|
70 }
|
|
71
|
72
|
72 override bool isBool(bool result)
|
0
|
73 {
|
|
74 return e2.isBool(result);
|
|
75 }
|
|
76
|
72
|
77 override bool checkSideEffect(int flag)
|
0
|
78 {
|
|
79 if (flag == 2)
|
|
80 return e1.checkSideEffect(2) || e2.checkSideEffect(2);
|
|
81 else
|
|
82 {
|
|
83 // Don't check e1 until we cast(void) the a,b code generation
|
|
84 return e2.checkSideEffect(flag);
|
|
85 }
|
|
86 }
|
|
87
|
72
|
88 override MATCH implicitConvTo(Type t)
|
0
|
89 {
|
56
|
90 return e2.implicitConvTo(t);
|
0
|
91 }
|
|
92
|
72
|
93 override Expression castTo(Scope sc, Type t)
|
0
|
94 {
|
56
|
95 Expression e2c = e2.castTo(sc, t);
|
|
96 Expression e;
|
|
97
|
|
98 if (e2c != e2)
|
|
99 {
|
|
100 e = new CommaExp(loc, e1, e2c);
|
|
101 e.type = e2c.type;
|
|
102 }
|
|
103 else
|
|
104 {
|
|
105 e = this;
|
|
106 e.type = e2.type;
|
|
107 }
|
|
108 return e;
|
0
|
109 }
|
|
110
|
72
|
111 override Expression optimize(int result)
|
0
|
112 {
|
|
113 Expression e;
|
|
114
|
|
115 //printf("CommaExp.optimize(result = %d) %s\n", result, toChars());
|
|
116 e1 = e1.optimize(result & WANTinterpret);
|
|
117 e2 = e2.optimize(result);
|
|
118 if (!e1 || e1.op == TOKint64 || e1.op == TOKfloat64 || !e1.checkSideEffect(2))
|
|
119 {
|
|
120 e = e2;
|
|
121 if (e)
|
|
122 e.type = type;
|
|
123 }
|
|
124 else
|
|
125 e = this;
|
|
126 //printf("-CommaExp.optimize(result = %d) %s\n", result, e.toChars());
|
|
127 return e;
|
|
128 }
|
|
129
|
72
|
130 override Expression interpret(InterState istate)
|
0
|
131 {
|
163
|
132 version (LOG) {
|
|
133 printf("CommaExp.interpret() %.*s\n", toChars());
|
|
134 }
|
|
135 Expression e = e1.interpret(istate);
|
|
136 if (e !is EXP_CANT_INTERPRET)
|
|
137 e = e2.interpret(istate);
|
|
138 return e;
|
0
|
139 }
|
|
140
|
72
|
141 override elem* toElem(IRState* irs)
|
0
|
142 {
|
|
143 assert(e1 && e2);
|
|
144 elem* eleft = e1.toElem(irs);
|
|
145 elem* eright = e2.toElem(irs);
|
|
146 elem* e = el_combine(eleft, eright);
|
|
147 if (e)
|
|
148 el_setLoc(e, loc);
|
|
149 return e;
|
|
150 }
|
72
|
151 }
|