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