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