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