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