annotate dmd/CondExp.d @ 191:52188e7e3fb5

Fixed deprecated features, now compiles with DMD2.058 Also changed Array allocation policy: Now doesn't reallocate but malloc's, followed by a memcpy (no free). (this fixes a crash while compiling druntime. Same bug in dmd)
author korDen@korDen-pc
date Sun, 25 Mar 2012 03:11:12 +0400
parents b0d41ff5e0df
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.CondExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.BinExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Loc;
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
6 import dmd.PtrExp;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Expression;
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
9 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.WANT;
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
22 import dmd.PREC;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.backend.mTY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
32 import dmd.expression.Util;
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
33
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
34 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
35
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 class CondExp : BinExp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
38 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
39
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 Expression econd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 this(Loc loc, Expression econd, Expression e1, Expression e2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 135
diff changeset
44 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 super(loc, TOK.TOKquestion, CondExp.sizeof, e1, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 this.econd = econd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
49 override Expression syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
43
a509c8688fbd CondExp.syntaxCopy
korDen
parents: 0
diff changeset
51 return new CondExp(loc, econd.syntaxCopy(), e1.syntaxCopy(), e2.syntaxCopy());
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
54 override Expression semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 Type t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 Type t2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 uint cs0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 uint cs1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 version (LOGSEMANTIC) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 printf("CondExp.semantic('%s')\n", toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 if (type)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 econd = econd.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 econd = resolveProperties(sc, econd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 econd = econd.checkToPointer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 econd = econd.checkToBoolean();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 /* this cannot work right because the types of e1 and e2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 * both contribute to the type of the result.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 if (sc.flags & SCOPEstaticif)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 /* If in static if, don't evaluate what we don't have to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 econd = econd.optimize(WANTflags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 if (econd.isBool(TRUE))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 return e1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 else if (econd.isBool(FALSE))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 return e2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 cs0 = sc.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 e1 = e1.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 e1 = resolveProperties(sc, e1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 cs1 = sc.callSuper;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 sc.callSuper = cs0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 e2 = e2.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e2 = resolveProperties(sc, e2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 sc.mergeCallSuper(loc, cs1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 // If either operand is void, the result is void
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 t1 = e1.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 t2 = e2.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 if (t1.ty == Tvoid || t2.ty == Tvoid)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 type = Type.tvoid;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 else if (t1 == t2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 type = t1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 typeCombine(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 switch (e1.type.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 case Tcomplex32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 case Tcomplex64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 case Tcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 e2 = e2.castTo(sc, e1.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 switch (e2.type.toBasetype().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 case Tcomplex32:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 case Tcomplex64:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 case Tcomplex80:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 e1 = e1.castTo(sc, e2.type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 if (type.toBasetype().ty == Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 e1 = e1.castTo(sc, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 e2 = e2.castTo(sc, type);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 static if (false) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 printf("res: %s\n", type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 printf("e1 : %s\n", e1.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 printf("e2 : %s\n", e2.type.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
149 override Expression optimize(int result)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 Expression e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 econd = econd.optimize(WANTflags | (result & WANTinterpret));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 if (econd.isBool(true))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 e = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 else if (econd.isBool(false))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 e = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 e1 = e1.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 e2 = e2.optimize(result);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
168 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 {
129
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
170 version (LOG) {
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
171 printf("CondExp.interpret() %.*s\n", toChars());
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
172 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
173 Expression e = econd.interpret(istate);
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
174 if (e !is EXP_CANT_INTERPRET)
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
175 {
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
176 if (e.isBool(true))
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
177 e = e1.interpret(istate);
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
178 else if (e.isBool(false))
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
179 e = e2.interpret(istate);
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
180 else
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
181 e = EXP_CANT_INTERPRET;
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
182 }
010eb8f0e18d further work on dmd test suite
korDen
parents: 123
diff changeset
183 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
186 override void checkEscape()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 e1.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 e2.checkEscape();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
192 override void checkEscapeRef()
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
193 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
194 e1.checkEscapeRef();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
195 e2.checkEscapeRef();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
196 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
197
191
52188e7e3fb5 Fixed deprecated features, now compiles with DMD2.058
korDen@korDen-pc
parents: 187
diff changeset
198 override bool isLvalue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
200 return e1.isLvalue() && e2.isLvalue();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
203 override Expression toLvalue(Scope sc, Expression ex)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
205 PtrExp e;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
206
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
207 // convert (econd ? e1 : e2) to *(econd ? &e1 : &e2)
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
208 e = new PtrExp(loc, this, type);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
209
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
210 e1 = e1.addressOf(sc);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
211 //e1 = e1.toLvalue(sc, null);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
212
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
213 e2 = e2.addressOf(sc);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
214 //e2 = e2.toLvalue(sc, null);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
215
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
216 typeCombine(sc);
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
217
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
218 type = e2.type;
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
219 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
222 override Expression modifiableLvalue(Scope sc, Expression e)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 {
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
224 //error("conditional expression %s is not a modifiable lvalue", toChars());
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
225 e1 = e1.modifiableLvalue(sc, e1);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
226 e2 = e2.modifiableLvalue(sc, e1);
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 129
diff changeset
227 return toLvalue(sc, this);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
230 override Expression checkToBoolean()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
232 e1 = e1.checkToBoolean();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
233 e2 = e2.checkToBoolean();
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
234 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
237 override bool checkSideEffect(int flag)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 {
64
4290d870944a More fixes
korDen
parents: 50
diff changeset
239 if (flag == 2)
4290d870944a More fixes
korDen
parents: 50
diff changeset
240 {
4290d870944a More fixes
korDen
parents: 50
diff changeset
241 return econd.checkSideEffect(2) || e1.checkSideEffect(2) || e2.checkSideEffect(2);
4290d870944a More fixes
korDen
parents: 50
diff changeset
242 }
4290d870944a More fixes
korDen
parents: 50
diff changeset
243 else
4290d870944a More fixes
korDen
parents: 50
diff changeset
244 {
4290d870944a More fixes
korDen
parents: 50
diff changeset
245 econd.checkSideEffect(1);
4290d870944a More fixes
korDen
parents: 50
diff changeset
246 e1.checkSideEffect(flag);
4290d870944a More fixes
korDen
parents: 50
diff changeset
247 return e2.checkSideEffect(flag);
4290d870944a More fixes
korDen
parents: 50
diff changeset
248 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
251 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 {
50
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
253 expToCBuffer(buf, hgs, econd, PREC_oror);
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
254 buf.writestring(" ? ");
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
255 expToCBuffer(buf, hgs, e1, PREC_expr);
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
256 buf.writestring(" : ");
adf6f7f216ea CondExp.toCBuffer
korDen
parents: 43
diff changeset
257 expToCBuffer(buf, hgs, e2, PREC_cond);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
260 override MATCH implicitConvTo(Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 MATCH m1 = e1.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 MATCH m2 = e2.implicitConvTo(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 //printf("CondExp: m1 %d m2 %d\n", m1, m2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 // Pick the worst match
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 return (m1 < m2) ? m1 : m2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
270 override Expression castTo(Scope sc, Type t)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 Expression e = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 if (type !is t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 if (1 || e1.op == TOKstring || e2.op == TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 e = new CondExp(loc, econd, e1.castTo(sc, t), e2.castTo(sc, t));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 e.type = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 e = Expression.castTo(sc, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
287 override void scanForNestedRef(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
292 override bool canThrow()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 return econd.canThrow() || e1.canThrow() || e2.canThrow();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
297 override int inlineCost(InlineCostState* ics)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 return 1 + e1.inlineCost(ics) + e2.inlineCost(ics) + econd.inlineCost(ics);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
302 override Expression doInline(InlineDoState ids)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 CondExp ce = cast(CondExp)copy();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 ce.econd = econd.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 ce.e1 = e1.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 ce.e2 = e2.doInline(ids);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 return ce;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
312 override Expression inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 econd = econd.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 e1 = e1.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 e2 = e2.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
320 override elem* toElem(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 elem* eleft;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 elem* eright;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 elem* ec = econd.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 eleft = e1.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 tym_t ty = eleft.Ety;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 if (global.params.cov && e1.loc.linnum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 eleft = el_combine(incUsageElem(irs, e1.loc), eleft);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 eright = e2.toElem(irs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (global.params.cov && e2.loc.linnum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 eright = el_combine(incUsageElem(irs, e2.loc), eright);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 elem* e = el_bin(OPcond, ty, ec, el_bin(OPcolon, ty, eleft, eright));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 if (tybasic(ty) == TYstruct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 e.Enumbytes = cast(uint)e1.type.size();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 el_setLoc(e, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 64
diff changeset
343 }