Mercurial > projects > ldc
annotate dmd/cast.c @ 711:eed2de0c67a0
Changed premake script to write target triple to a file, then read that, instead of using popen
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 20 Oct 2008 23:33:59 +0200 |
parents | eef8ac26c66c |
children | a26b0c5d5942 |
rev | line source |
---|---|
159 | 1 |
336 | 2 // Copyright (c) 1999-2008 by Digital Mars |
159 | 3 // All Rights Reserved |
4 // written by Walter Bright | |
5 // http://www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <stdio.h> | |
11 #include <assert.h> | |
12 | |
13 #if _WIN32 || IN_GCC || IN_LLVM | |
14 #include "mem.h" | |
15 #else | |
16 #include "../root/mem.h" | |
17 #endif | |
18 | |
19 #include "expression.h" | |
20 #include "mtype.h" | |
21 #include "utf.h" | |
22 #include "declaration.h" | |
23 #include "aggregate.h" | |
24 | |
25 /* ==================== implicitCast ====================== */ | |
26 | |
27 /************************************** | |
28 * Do an implicit cast. | |
29 * Issue error if it can't be done. | |
30 */ | |
31 | |
32 Expression *Expression::implicitCastTo(Scope *sc, Type *t) | |
33 { | |
34 //printf("implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); | |
35 if (implicitConvTo(t)) | |
36 { | |
37 if (global.params.warnings && | |
38 Type::impcnvWarn[type->toBasetype()->ty][t->toBasetype()->ty] && | |
39 op != TOKint64) | |
40 { | |
41 Expression *e = optimize(WANTflags | WANTvalue); | |
42 | |
43 if (e->op == TOKint64) | |
44 return e->implicitCastTo(sc, t); | |
45 | |
215
a58d8f4b84df
[svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents:
159
diff
changeset
|
46 warning("%s: implicit conversion of expression (%s) of type %s to %s can cause loss of data", |
a58d8f4b84df
[svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents:
159
diff
changeset
|
47 loc.toChars(), toChars(), type->toChars(), t->toChars()); |
159 | 48 } |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
49 #if DMDV2 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
50 if (match == MATCHconst && t == type->constOf()) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
51 { |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
52 Expression *e = copy(); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
53 e->type = t; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
54 return e; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
55 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
56 #endif |
159 | 57 return castTo(sc, t); |
58 } | |
59 | |
60 Expression *e = optimize(WANTflags | WANTvalue); | |
61 if (e != this) | |
62 return e->implicitCastTo(sc, t); | |
63 | |
64 #if 0 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
65 printf("ty = %d\n", type->ty); |
159 | 66 print(); |
67 type->print(); | |
68 printf("to:\n"); | |
69 t->print(); | |
70 printf("%p %p type: %s to: %s\n", type->deco, t->deco, type->deco, t->deco); | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
71 //printf("%p %p %p\n", type->nextOf()->arrayOf(), type, t); |
159 | 72 fflush(stdout); |
73 #endif | |
74 if (!t->deco) | |
75 { /* Can happen with: | |
76 * enum E { One } | |
77 * class A | |
78 * { static void fork(EDG dg) { dg(E.One); } | |
79 * alias void delegate(E) EDG; | |
80 * } | |
81 * Should eventually make it work. | |
82 */ | |
83 error("forward reference to type %s", t->toChars()); | |
84 } | |
85 else if (t->reliesOnTident()) | |
86 error("forward reference to type %s", t->reliesOnTident()->toChars()); | |
87 | |
88 error("cannot implicitly convert expression (%s) of type %s to %s", | |
89 toChars(), type->toChars(), t->toChars()); | |
90 return castTo(sc, t); | |
91 } | |
92 | |
93 /******************************************* | |
94 * Return !=0 if we can implicitly convert this to type t. | |
95 * Don't do the actual cast. | |
96 */ | |
97 | |
98 MATCH Expression::implicitConvTo(Type *t) | |
99 { | |
100 #if 0 | |
101 printf("Expression::implicitConvTo(this=%s, type=%s, t=%s)\n", | |
102 toChars(), type->toChars(), t->toChars()); | |
103 #endif | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
104 //static int nest; if (++nest == 10) halt(); |
159 | 105 if (!type) |
106 { error("%s is not an expression", toChars()); | |
107 type = Type::terror; | |
108 } | |
109 if (t->ty == Tbit && isBit()) | |
110 return MATCHconvert; | |
111 Expression *e = optimize(WANTvalue | WANTflags); | |
112 if (e != this) | |
113 { //printf("optimzed to %s\n", e->toChars()); | |
114 return e->implicitConvTo(t); | |
115 } | |
116 MATCH match = type->implicitConvTo(t); | |
117 if (match) | |
118 return match; | |
119 #if 0 | |
120 Type *tb = t->toBasetype(); | |
121 if (tb->ty == Tdelegate) | |
122 { TypeDelegate *td = (TypeDelegate *)tb; | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
123 TypeFunction *tf = (TypeFunction *)td->nextOf(); |
159 | 124 |
125 if (!tf->varargs && | |
126 !(tf->arguments && tf->arguments->dim) | |
127 ) | |
128 { | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
129 match = type->implicitConvTo(tf->nextOf()); |
159 | 130 if (match) |
131 return match; | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
132 if (tf->nextOf()->toBasetype()->ty == Tvoid) |
159 | 133 return MATCHconvert; |
134 } | |
135 } | |
136 #endif | |
137 return MATCHnomatch; | |
138 } | |
139 | |
140 | |
141 MATCH IntegerExp::implicitConvTo(Type *t) | |
142 { | |
143 #if 0 | |
144 printf("IntegerExp::implicitConvTo(this=%s, type=%s, t=%s)\n", | |
145 toChars(), type->toChars(), t->toChars()); | |
146 #endif | |
147 if (type->equals(t)) | |
148 return MATCHexact; | |
149 | |
150 enum TY ty = type->toBasetype()->ty; | |
151 enum TY toty = t->toBasetype()->ty; | |
152 | |
153 if (type->implicitConvTo(t) == MATCHnomatch && t->ty == Tenum) | |
154 { | |
155 return MATCHnomatch; | |
156 } | |
157 | |
158 switch (ty) | |
159 { | |
160 case Tbit: | |
161 case Tbool: | |
162 value &= 1; | |
163 ty = Tint32; | |
164 break; | |
165 | |
166 case Tint8: | |
167 value = (signed char)value; | |
168 ty = Tint32; | |
169 break; | |
170 | |
171 case Tchar: | |
172 case Tuns8: | |
173 value &= 0xFF; | |
174 ty = Tint32; | |
175 break; | |
176 | |
177 case Tint16: | |
178 value = (short)value; | |
179 ty = Tint32; | |
180 break; | |
181 | |
182 case Tuns16: | |
183 case Twchar: | |
184 value &= 0xFFFF; | |
185 ty = Tint32; | |
186 break; | |
187 | |
188 case Tint32: | |
189 value = (int)value; | |
190 break; | |
191 | |
192 case Tuns32: | |
193 case Tdchar: | |
194 value &= 0xFFFFFFFF; | |
195 ty = Tuns32; | |
196 break; | |
197 | |
198 default: | |
199 break; | |
200 } | |
201 | |
202 // Only allow conversion if no change in value | |
203 switch (toty) | |
204 { | |
205 case Tbit: | |
206 case Tbool: | |
207 if ((value & 1) != value) | |
208 goto Lno; | |
209 goto Lyes; | |
210 | |
211 case Tint8: | |
212 if ((signed char)value != value) | |
213 goto Lno; | |
214 goto Lyes; | |
215 | |
216 case Tchar: | |
217 case Tuns8: | |
218 //printf("value = %llu %llu\n", (integer_t)(unsigned char)value, value); | |
219 if ((unsigned char)value != value) | |
220 goto Lno; | |
221 goto Lyes; | |
222 | |
223 case Tint16: | |
224 if ((short)value != value) | |
225 goto Lno; | |
226 goto Lyes; | |
227 | |
228 case Tuns16: | |
229 if ((unsigned short)value != value) | |
230 goto Lno; | |
231 goto Lyes; | |
232 | |
233 case Tint32: | |
234 if (ty == Tuns32) | |
235 { | |
236 } | |
237 else if ((int)value != value) | |
238 goto Lno; | |
239 goto Lyes; | |
240 | |
241 case Tuns32: | |
242 if (ty == Tint32) | |
243 { | |
244 } | |
245 else if ((unsigned)value != value) | |
246 goto Lno; | |
247 goto Lyes; | |
248 | |
249 case Tdchar: | |
250 if (value > 0x10FFFFUL) | |
251 goto Lno; | |
252 goto Lyes; | |
253 | |
254 case Twchar: | |
255 if ((unsigned short)value != value) | |
256 goto Lno; | |
257 goto Lyes; | |
258 | |
259 case Tfloat32: | |
260 { | |
261 volatile float f; | |
262 if (type->isunsigned()) | |
263 { | |
264 f = (float)value; | |
265 if (f != value) | |
266 goto Lno; | |
267 } | |
268 else | |
269 { | |
270 f = (float)(long long)value; | |
271 if (f != (long long)value) | |
272 goto Lno; | |
273 } | |
274 goto Lyes; | |
275 } | |
276 | |
277 case Tfloat64: | |
278 { | |
279 volatile double f; | |
280 if (type->isunsigned()) | |
281 { | |
282 f = (double)value; | |
283 if (f != value) | |
284 goto Lno; | |
285 } | |
286 else | |
287 { | |
288 f = (double)(long long)value; | |
289 if (f != (long long)value) | |
290 goto Lno; | |
291 } | |
292 goto Lyes; | |
293 } | |
294 | |
295 case Tfloat80: | |
296 { | |
297 volatile long double f; | |
298 if (type->isunsigned()) | |
299 { | |
300 f = (long double)value; | |
301 if (f != value) | |
302 goto Lno; | |
303 } | |
304 else | |
305 { | |
306 f = (long double)(long long)value; | |
307 if (f != (long long)value) | |
308 goto Lno; | |
309 } | |
310 goto Lyes; | |
311 } | |
312 } | |
313 return Expression::implicitConvTo(t); | |
314 | |
315 Lyes: | |
316 //printf("MATCHconvert\n"); | |
317 return MATCHconvert; | |
318 | |
319 Lno: | |
320 //printf("MATCHnomatch\n"); | |
321 return MATCHnomatch; | |
322 } | |
323 | |
324 MATCH NullExp::implicitConvTo(Type *t) | |
325 { | |
326 #if 0 | |
327 printf("NullExp::implicitConvTo(this=%s, type=%s, t=%s)\n", | |
328 toChars(), type->toChars(), t->toChars()); | |
329 #endif | |
330 if (this->type->equals(t)) | |
331 return MATCHexact; | |
332 // NULL implicitly converts to any pointer type or dynamic array | |
333 if (type->ty == Tpointer && type->next->ty == Tvoid) | |
334 { | |
335 if (t->ty == Ttypedef) | |
336 t = ((TypeTypedef *)t)->sym->basetype; | |
337 if (t->ty == Tpointer || t->ty == Tarray || | |
338 t->ty == Taarray || t->ty == Tclass || | |
339 t->ty == Tdelegate) | |
340 return committed ? MATCHconvert : MATCHexact; | |
341 } | |
342 return Expression::implicitConvTo(t); | |
343 } | |
344 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
345 #if DMDV2 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
346 MATCH StructLiteralExp::implicitConvTo(Type *t) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
347 { |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
348 #if 0 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
349 printf("StructLiteralExp::implicitConvTo(this=%s, type=%s, t=%s)\n", |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
350 toChars(), type->toChars(), t->toChars()); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
351 #endif |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
352 MATCH m = Expression::implicitConvTo(t); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
353 if (m != MATCHnomatch) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
354 return m; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
355 if (type->ty == t->ty && type->ty == Tstruct && |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
356 ((TypeStruct *)type)->sym == ((TypeStruct *)t)->sym) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
357 { |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
358 m = MATCHconst; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
359 for (int i = 0; i < elements->dim; i++) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
360 { Expression *e = (Expression *)elements->data[i]; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
361 Type *te = e->type; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
362 if (t->mod == 0) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
363 te = te->mutableOf(); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
364 else |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
365 { assert(t->mod == MODinvariant); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
366 te = te->invariantOf(); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
367 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
368 MATCH m2 = e->implicitConvTo(te); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
369 //printf("\t%s => %s, match = %d\n", e->toChars(), te->toChars(), m2); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
370 if (m2 < m) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
371 m = m2; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
372 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
373 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
374 return m; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
375 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
376 #endif |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
377 |
159 | 378 MATCH StringExp::implicitConvTo(Type *t) |
379 { MATCH m; | |
380 | |
381 #if 0 | |
382 printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n", | |
383 toChars(), committed, type->toChars(), t->toChars()); | |
384 #endif | |
385 if (!committed) | |
386 { | |
387 if (!committed && t->ty == Tpointer && t->next->ty == Tvoid) | |
388 { | |
389 return MATCHnomatch; | |
390 } | |
391 if (type->ty == Tsarray || type->ty == Tarray || type->ty == Tpointer) | |
392 { | |
393 if (type->next->ty == Tchar) | |
394 { | |
395 switch (t->ty) | |
396 { | |
397 case Tsarray: | |
398 if (type->ty == Tsarray && | |
399 ((TypeSArray *)type)->dim->toInteger() != | |
400 ((TypeSArray *)t)->dim->toInteger()) | |
401 return MATCHnomatch; | |
402 goto L1; | |
403 case Tarray: | |
404 goto L1; | |
405 case Tpointer: | |
406 L1: | |
407 if (t->next->ty == Tchar) | |
408 return MATCHexact; | |
409 else if (t->next->ty == Twchar) | |
410 return MATCHexact; | |
411 else if (t->next->ty == Tdchar) | |
412 return MATCHexact; | |
413 break; | |
414 } | |
415 } | |
416 } | |
417 } | |
418 return Expression::implicitConvTo(t); | |
419 #if 0 | |
420 m = (MATCH)type->implicitConvTo(t); | |
421 if (m) | |
422 { | |
423 return m; | |
424 } | |
425 | |
426 return MATCHnomatch; | |
427 #endif | |
428 } | |
429 | |
430 MATCH ArrayLiteralExp::implicitConvTo(Type *t) | |
431 { MATCH result = MATCHexact; | |
432 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
433 #if 0 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
434 printf("ArrayLiteralExp::implicitConvTo(this=%s, type=%s, t=%s)\n", |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
435 toChars(), type->toChars(), t->toChars()); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
436 #endif |
159 | 437 Type *typeb = type->toBasetype(); |
438 Type *tb = t->toBasetype(); | |
439 if ((tb->ty == Tarray || tb->ty == Tsarray) && | |
440 (typeb->ty == Tarray || typeb->ty == Tsarray)) | |
441 { | |
442 if (tb->ty == Tsarray) | |
443 { TypeSArray *tsa = (TypeSArray *)tb; | |
444 if (elements->dim != tsa->dim->toInteger()) | |
445 result = MATCHnomatch; | |
446 } | |
447 | |
448 for (int i = 0; i < elements->dim; i++) | |
449 { Expression *e = (Expression *)elements->data[i]; | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
450 MATCH m = (MATCH)e->implicitConvTo(tb->nextOf()); |
159 | 451 if (m < result) |
452 result = m; // remember worst match | |
453 if (result == MATCHnomatch) | |
454 break; // no need to check for worse | |
455 } | |
456 return result; | |
457 } | |
458 else | |
459 return Expression::implicitConvTo(t); | |
460 } | |
461 | |
462 MATCH AssocArrayLiteralExp::implicitConvTo(Type *t) | |
463 { MATCH result = MATCHexact; | |
464 | |
465 Type *typeb = type->toBasetype(); | |
466 Type *tb = t->toBasetype(); | |
467 if (tb->ty == Taarray && typeb->ty == Taarray) | |
468 { | |
469 for (size_t i = 0; i < keys->dim; i++) | |
470 { Expression *e = (Expression *)keys->data[i]; | |
471 MATCH m = (MATCH)e->implicitConvTo(((TypeAArray *)tb)->key); | |
472 if (m < result) | |
473 result = m; // remember worst match | |
474 if (result == MATCHnomatch) | |
475 break; // no need to check for worse | |
476 e = (Expression *)values->data[i]; | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
477 m = (MATCH)e->implicitConvTo(tb->nextOf()); |
159 | 478 if (m < result) |
479 result = m; // remember worst match | |
480 if (result == MATCHnomatch) | |
481 break; // no need to check for worse | |
482 } | |
483 return result; | |
484 } | |
485 else | |
486 return Expression::implicitConvTo(t); | |
487 } | |
488 | |
489 MATCH AddrExp::implicitConvTo(Type *t) | |
490 { | |
491 #if 0 | |
492 printf("AddrExp::implicitConvTo(this=%s, type=%s, t=%s)\n", | |
493 toChars(), type->toChars(), t->toChars()); | |
494 #endif | |
495 MATCH result; | |
496 | |
497 result = type->implicitConvTo(t); | |
498 //printf("\tresult = %d\n", result); | |
499 | |
500 if (result == MATCHnomatch) | |
501 { | |
502 // Look for pointers to functions where the functions are overloaded. | |
503 VarExp *ve; | |
504 FuncDeclaration *f; | |
505 | |
506 t = t->toBasetype(); | |
507 if (type->ty == Tpointer && type->next->ty == Tfunction && | |
508 t->ty == Tpointer && t->next->ty == Tfunction && | |
509 e1->op == TOKvar) | |
510 { | |
511 ve = (VarExp *)e1; | |
512 f = ve->var->isFuncDeclaration(); | |
513 if (f && f->overloadExactMatch(t->next)) | |
514 result = MATCHexact; | |
515 } | |
516 } | |
517 //printf("\tresult = %d\n", result); | |
518 return result; | |
519 } | |
520 | |
521 MATCH SymOffExp::implicitConvTo(Type *t) | |
522 { | |
523 #if 0 | |
524 printf("SymOffExp::implicitConvTo(this=%s, type=%s, t=%s)\n", | |
525 toChars(), type->toChars(), t->toChars()); | |
526 #endif | |
527 MATCH result; | |
528 | |
529 result = type->implicitConvTo(t); | |
530 //printf("\tresult = %d\n", result); | |
531 | |
532 if (result == MATCHnomatch) | |
533 { | |
534 // Look for pointers to functions where the functions are overloaded. | |
535 FuncDeclaration *f; | |
536 | |
537 t = t->toBasetype(); | |
538 if (type->ty == Tpointer && type->next->ty == Tfunction && | |
539 t->ty == Tpointer && t->next->ty == Tfunction) | |
540 { | |
541 f = var->isFuncDeclaration(); | |
542 if (f && f->overloadExactMatch(t->next)) | |
543 result = MATCHexact; | |
544 } | |
545 } | |
546 //printf("\tresult = %d\n", result); | |
547 return result; | |
548 } | |
549 | |
550 MATCH DelegateExp::implicitConvTo(Type *t) | |
551 { | |
552 #if 0 | |
553 printf("DelegateExp::implicitConvTo(this=%s, type=%s, t=%s)\n", | |
554 toChars(), type->toChars(), t->toChars()); | |
555 #endif | |
556 MATCH result; | |
557 | |
558 result = type->implicitConvTo(t); | |
559 | |
560 if (result == 0) | |
561 { | |
562 // Look for pointers to functions where the functions are overloaded. | |
563 FuncDeclaration *f; | |
564 | |
565 t = t->toBasetype(); | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
566 if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction && |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
567 t->ty == Tdelegate && t->nextOf()->ty == Tfunction) |
159 | 568 { |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
569 if (func && func->overloadExactMatch(t->nextOf())) |
159 | 570 result = MATCHexact; |
571 } | |
572 } | |
573 return result; | |
574 } | |
575 | |
576 MATCH CondExp::implicitConvTo(Type *t) | |
577 { | |
578 MATCH m1; | |
579 MATCH m2; | |
580 | |
581 m1 = e1->implicitConvTo(t); | |
582 m2 = e2->implicitConvTo(t); | |
583 | |
584 // Pick the worst match | |
585 return (m1 < m2) ? m1 : m2; | |
586 } | |
587 | |
588 | |
589 /* ==================== castTo ====================== */ | |
590 | |
591 /************************************** | |
592 * Do an explicit cast. | |
593 */ | |
594 | |
595 Expression *Expression::castTo(Scope *sc, Type *t) | |
596 { | |
597 //printf("Expression::castTo(this=%s, t=%s)\n", toChars(), t->toChars()); | |
598 #if 0 | |
599 printf("Expression::castTo(this=%s, type=%s, t=%s)\n", | |
600 toChars(), type->toChars(), t->toChars()); | |
601 #endif | |
602 if (type == t) | |
603 return this; | |
604 Expression *e = this; | |
605 Type *tb = t->toBasetype(); | |
606 Type *typeb = type->toBasetype(); | |
607 if (tb != typeb) | |
608 { | |
609 // Do (type *) cast of (type [dim]) | |
610 if (tb->ty == Tpointer && | |
611 typeb->ty == Tsarray | |
612 ) | |
613 { | |
614 //printf("Converting [dim] to *\n"); | |
615 | |
616 if (typeb->size(loc) == 0) | |
617 e = new NullExp(loc); | |
618 else | |
619 e = new AddrExp(loc, e); | |
620 } | |
621 #if 0 | |
622 else if (tb->ty == Tdelegate && type->ty != Tdelegate) | |
623 { | |
624 TypeDelegate *td = (TypeDelegate *)tb; | |
625 TypeFunction *tf = (TypeFunction *)td->nextOf(); | |
626 return toDelegate(sc, tf->nextOf()); | |
627 } | |
628 #endif | |
629 else | |
630 { | |
631 e = new CastExp(loc, e, tb); | |
632 } | |
633 } | |
634 else | |
635 { | |
636 e = e->copy(); // because of COW for assignment to e->type | |
637 } | |
638 assert(e != this); | |
639 e->type = t; | |
640 //printf("Returning: %s\n", e->toChars()); | |
641 return e; | |
642 } | |
643 | |
644 | |
645 Expression *RealExp::castTo(Scope *sc, Type *t) | |
646 { Expression *e = this; | |
647 if (type != t) | |
648 { | |
649 if ((type->isreal() && t->isreal()) || | |
650 (type->isimaginary() && t->isimaginary()) | |
651 ) | |
652 { e = copy(); | |
653 e->type = t; | |
654 } | |
655 else | |
656 e = Expression::castTo(sc, t); | |
657 } | |
658 return e; | |
659 } | |
660 | |
661 | |
662 Expression *ComplexExp::castTo(Scope *sc, Type *t) | |
663 { Expression *e = this; | |
664 if (type != t) | |
665 { | |
666 if (type->iscomplex() && t->iscomplex()) | |
667 { e = copy(); | |
668 e->type = t; | |
669 } | |
670 else | |
671 e = Expression::castTo(sc, t); | |
672 } | |
673 return e; | |
674 } | |
675 | |
676 | |
677 Expression *NullExp::castTo(Scope *sc, Type *t) | |
678 { NullExp *e; | |
679 Type *tb; | |
680 | |
681 //printf("NullExp::castTo(t = %p)\n", t); | |
682 if (type == t) | |
683 { | |
684 committed = 1; | |
685 return this; | |
686 } | |
687 e = (NullExp *)copy(); | |
688 e->committed = 1; | |
689 tb = t->toBasetype(); | |
690 e->type = type->toBasetype(); | |
691 if (tb != e->type) | |
692 { | |
693 // NULL implicitly converts to any pointer type or dynamic array | |
694 if (e->type->ty == Tpointer && e->type->nextOf()->ty == Tvoid && | |
695 (tb->ty == Tpointer || tb->ty == Tarray || tb->ty == Taarray || | |
696 tb->ty == Tdelegate)) | |
697 { | |
698 #if 0 | |
699 if (tb->ty == Tdelegate) | |
700 { TypeDelegate *td = (TypeDelegate *)tb; | |
701 TypeFunction *tf = (TypeFunction *)td->nextOf(); | |
702 | |
703 if (!tf->varargs && | |
704 !(tf->arguments && tf->arguments->dim) | |
705 ) | |
706 { | |
707 return Expression::castTo(sc, t); | |
708 } | |
709 } | |
710 #endif | |
711 } | |
712 else | |
713 { | |
714 return e->Expression::castTo(sc, t); | |
715 } | |
716 } | |
717 e->type = t; | |
718 return e; | |
719 } | |
720 | |
721 Expression *StringExp::castTo(Scope *sc, Type *t) | |
722 { | |
723 /* This follows copy-on-write; any changes to 'this' | |
724 * will result in a copy. | |
725 * The this->string member is considered immutable. | |
726 */ | |
727 StringExp *se; | |
728 Type *tb; | |
729 int copied = 0; | |
730 | |
731 //printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed); | |
732 | |
733 if (!committed && t->ty == Tpointer && t->nextOf()->ty == Tvoid) | |
734 { | |
735 error("cannot convert string literal to void*"); | |
736 } | |
737 | |
738 se = this; | |
739 if (!committed) | |
740 { se = (StringExp *)copy(); | |
741 se->committed = 1; | |
742 copied = 1; | |
743 } | |
744 | |
745 if (type == t) | |
746 { | |
747 return se; | |
748 } | |
749 | |
750 tb = t->toBasetype(); | |
751 //printf("\ttype = %s\n", type->toChars()); | |
752 if (tb->ty == Tdelegate && type->toBasetype()->ty != Tdelegate) | |
753 return Expression::castTo(sc, t); | |
754 | |
755 Type *typeb = type->toBasetype(); | |
756 if (typeb == tb) | |
757 { | |
758 if (!copied) | |
759 { se = (StringExp *)copy(); | |
760 copied = 1; | |
761 } | |
762 se->type = t; | |
763 return se; | |
764 } | |
765 | |
766 if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) | |
767 { if (!copied) | |
768 { se = (StringExp *)copy(); | |
769 copied = 1; | |
770 } | |
771 goto Lcast; | |
772 } | |
773 if (typeb->ty != Tsarray && typeb->ty != Tarray && typeb->ty != Tpointer) | |
774 { if (!copied) | |
775 { se = (StringExp *)copy(); | |
776 copied = 1; | |
777 } | |
778 goto Lcast; | |
779 } | |
780 | |
781 if (typeb->nextOf()->size() == tb->nextOf()->size()) | |
782 { | |
783 if (!copied) | |
784 { se = (StringExp *)copy(); | |
785 copied = 1; | |
786 } | |
787 if (tb->ty == Tsarray) | |
788 goto L2; // handle possible change in static array dimension | |
789 se->type = t; | |
790 return se; | |
791 } | |
792 | |
793 if (committed) | |
794 goto Lcast; | |
795 | |
796 #define X(tf,tt) ((tf) * 256 + (tt)) | |
797 { | |
798 OutBuffer buffer; | |
799 size_t newlen = 0; | |
800 int tfty = typeb->nextOf()->toBasetype()->ty; | |
801 int ttty = tb->nextOf()->toBasetype()->ty; | |
802 switch (X(tfty, ttty)) | |
803 { | |
804 case X(Tchar, Tchar): | |
805 case X(Twchar,Twchar): | |
806 case X(Tdchar,Tdchar): | |
807 break; | |
808 | |
809 case X(Tchar, Twchar): | |
810 for (size_t u = 0; u < len;) | |
811 { unsigned c; | |
812 char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); | |
813 if (p) | |
814 error("%s", p); | |
815 else | |
816 buffer.writeUTF16(c); | |
817 } | |
818 newlen = buffer.offset / 2; | |
819 buffer.writeUTF16(0); | |
820 goto L1; | |
821 | |
822 case X(Tchar, Tdchar): | |
823 for (size_t u = 0; u < len;) | |
824 { unsigned c; | |
825 char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); | |
826 if (p) | |
827 error("%s", p); | |
828 buffer.write4(c); | |
829 newlen++; | |
830 } | |
831 buffer.write4(0); | |
832 goto L1; | |
833 | |
834 case X(Twchar,Tchar): | |
835 for (size_t u = 0; u < len;) | |
836 { unsigned c; | |
837 char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); | |
838 if (p) | |
839 error("%s", p); | |
840 else | |
841 buffer.writeUTF8(c); | |
842 } | |
843 newlen = buffer.offset; | |
844 buffer.writeUTF8(0); | |
845 goto L1; | |
846 | |
847 case X(Twchar,Tdchar): | |
848 for (size_t u = 0; u < len;) | |
849 { unsigned c; | |
850 char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); | |
851 if (p) | |
852 error("%s", p); | |
853 buffer.write4(c); | |
854 newlen++; | |
855 } | |
856 buffer.write4(0); | |
857 goto L1; | |
858 | |
859 case X(Tdchar,Tchar): | |
860 for (size_t u = 0; u < len; u++) | |
861 { | |
862 unsigned c = ((unsigned *)se->string)[u]; | |
863 if (!utf_isValidDchar(c)) | |
864 error("invalid UCS-32 char \\U%08x", c); | |
865 else | |
866 buffer.writeUTF8(c); | |
867 newlen++; | |
868 } | |
869 newlen = buffer.offset; | |
870 buffer.writeUTF8(0); | |
871 goto L1; | |
872 | |
873 case X(Tdchar,Twchar): | |
874 for (size_t u = 0; u < len; u++) | |
875 { | |
876 unsigned c = ((unsigned *)se->string)[u]; | |
877 if (!utf_isValidDchar(c)) | |
878 error("invalid UCS-32 char \\U%08x", c); | |
879 else | |
880 buffer.writeUTF16(c); | |
881 newlen++; | |
882 } | |
883 newlen = buffer.offset / 2; | |
884 buffer.writeUTF16(0); | |
885 goto L1; | |
886 | |
887 L1: | |
888 if (!copied) | |
889 { se = (StringExp *)copy(); | |
890 copied = 1; | |
891 } | |
892 se->string = buffer.extractData(); | |
893 se->len = newlen; | |
894 se->sz = tb->nextOf()->size(); | |
895 break; | |
896 | |
897 default: | |
898 assert(typeb->nextOf()->size() != tb->nextOf()->size()); | |
899 goto Lcast; | |
900 } | |
901 } | |
902 #undef X | |
903 L2: | |
904 assert(copied); | |
905 | |
906 // See if need to truncate or extend the literal | |
907 if (tb->ty == Tsarray) | |
908 { | |
909 int dim2 = ((TypeSArray *)tb)->dim->toInteger(); | |
910 | |
911 //printf("dim from = %d, to = %d\n", se->len, dim2); | |
912 | |
913 // Changing dimensions | |
914 if (dim2 != se->len) | |
915 { | |
916 // Copy when changing the string literal | |
917 unsigned newsz = se->sz; | |
918 void *s; | |
919 int d; | |
920 | |
921 d = (dim2 < se->len) ? dim2 : se->len; | |
922 s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); | |
923 memcpy(s, se->string, d * newsz); | |
924 // Extend with 0, add terminating 0 | |
925 memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); | |
926 se->string = s; | |
927 se->len = dim2; | |
928 } | |
929 } | |
930 se->type = t; | |
931 return se; | |
932 | |
933 Lcast: | |
934 Expression *e = new CastExp(loc, se, t); | |
935 e->type = t; // so semantic() won't be run on e | |
936 return e; | |
937 } | |
938 | |
939 Expression *AddrExp::castTo(Scope *sc, Type *t) | |
940 { | |
941 Type *tb; | |
942 | |
943 #if 0 | |
944 printf("AddrExp::castTo(this=%s, type=%s, t=%s)\n", | |
945 toChars(), type->toChars(), t->toChars()); | |
946 #endif | |
947 Expression *e = this; | |
948 | |
949 tb = t->toBasetype(); | |
950 type = type->toBasetype(); | |
951 if (tb != type) | |
952 { | |
953 // Look for pointers to functions where the functions are overloaded. | |
954 VarExp *ve; | |
955 FuncDeclaration *f; | |
956 | |
957 if (type->ty == Tpointer && type->next->ty == Tfunction && | |
958 tb->ty == Tpointer && tb->next->ty == Tfunction && | |
959 e1->op == TOKvar) | |
960 { | |
961 ve = (VarExp *)e1; | |
962 f = ve->var->isFuncDeclaration(); | |
963 if (f) | |
964 { | |
965 f = f->overloadExactMatch(tb->next); | |
966 if (f) | |
967 { | |
968 e = new VarExp(loc, f); | |
969 e->type = f->type; | |
970 e = new AddrExp(loc, e); | |
971 e->type = t; | |
972 return e; | |
973 } | |
974 } | |
975 } | |
976 e = Expression::castTo(sc, t); | |
977 } | |
978 e->type = t; | |
979 return e; | |
980 } | |
981 | |
982 | |
983 Expression *TupleExp::castTo(Scope *sc, Type *t) | |
984 { TupleExp *e = (TupleExp *)copy(); | |
985 e->exps = (Expressions *)exps->copy(); | |
986 for (size_t i = 0; i < e->exps->dim; i++) | |
987 { Expression *ex = (Expression *)e->exps->data[i]; | |
988 ex = ex->castTo(sc, t); | |
989 e->exps->data[i] = (void *)ex; | |
990 } | |
991 return e; | |
992 } | |
993 | |
994 | |
995 Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t) | |
996 { | |
997 #if 0 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
998 printf("ArrayLiteralExp::castTo(this=%s, type=%s, => %s)\n", |
159 | 999 toChars(), type->toChars(), t->toChars()); |
1000 #endif | |
1001 if (type == t) | |
1002 return this; | |
1003 ArrayLiteralExp *e = this; | |
1004 Type *typeb = type->toBasetype(); | |
1005 Type *tb = t->toBasetype(); | |
1006 if ((tb->ty == Tarray || tb->ty == Tsarray) && | |
1007 (typeb->ty == Tarray || typeb->ty == Tsarray) && | |
1008 // Not trying to convert non-void[] to void[] | |
1009 !(tb->nextOf()->toBasetype()->ty == Tvoid && typeb->nextOf()->toBasetype()->ty != Tvoid)) | |
1010 { | |
1011 if (tb->ty == Tsarray) | |
1012 { TypeSArray *tsa = (TypeSArray *)tb; | |
1013 if (elements->dim != tsa->dim->toInteger()) | |
1014 goto L1; | |
1015 } | |
1016 | |
1017 e = (ArrayLiteralExp *)copy(); | |
1018 e->elements = (Expressions *)elements->copy(); | |
1019 for (int i = 0; i < elements->dim; i++) | |
1020 { Expression *ex = (Expression *)elements->data[i]; | |
1021 ex = ex->castTo(sc, tb->nextOf()); | |
1022 e->elements->data[i] = (void *)ex; | |
1023 } | |
1024 e->type = t; | |
1025 return e; | |
1026 } | |
1027 if (tb->ty == Tpointer && typeb->ty == Tsarray) | |
1028 { | |
1029 e = (ArrayLiteralExp *)copy(); | |
1030 e->type = typeb->nextOf()->pointerTo(); | |
1031 } | |
1032 L1: | |
1033 return e->Expression::castTo(sc, t); | |
1034 } | |
1035 | |
1036 Expression *AssocArrayLiteralExp::castTo(Scope *sc, Type *t) | |
1037 { | |
1038 if (type == t) | |
1039 return this; | |
1040 AssocArrayLiteralExp *e = this; | |
1041 Type *typeb = type->toBasetype(); | |
1042 Type *tb = t->toBasetype(); | |
1043 if (tb->ty == Taarray && typeb->ty == Taarray && | |
1044 tb->nextOf()->toBasetype()->ty != Tvoid) | |
1045 { | |
1046 e = (AssocArrayLiteralExp *)copy(); | |
1047 e->keys = (Expressions *)keys->copy(); | |
1048 e->values = (Expressions *)values->copy(); | |
1049 assert(keys->dim == values->dim); | |
1050 for (size_t i = 0; i < keys->dim; i++) | |
1051 { Expression *ex = (Expression *)values->data[i]; | |
1052 ex = ex->castTo(sc, tb->nextOf()); | |
1053 e->values->data[i] = (void *)ex; | |
1054 | |
1055 ex = (Expression *)keys->data[i]; | |
1056 ex = ex->castTo(sc, ((TypeAArray *)tb)->index); | |
1057 e->keys->data[i] = (void *)ex; | |
1058 } | |
1059 e->type = t; | |
1060 return e; | |
1061 } | |
1062 L1: | |
1063 return e->Expression::castTo(sc, t); | |
1064 } | |
1065 | |
1066 Expression *SymOffExp::castTo(Scope *sc, Type *t) | |
1067 { | |
1068 Type *tb; | |
1069 | |
1070 #if 0 | |
1071 printf("SymOffExp::castTo(this=%s, type=%s, t=%s)\n", | |
1072 toChars(), type->toChars(), t->toChars()); | |
1073 #endif | |
1074 Expression *e = this; | |
1075 | |
1076 tb = t->toBasetype(); | |
1077 type = type->toBasetype(); | |
1078 if (tb != type) | |
1079 { | |
1080 // Look for pointers to functions where the functions are overloaded. | |
1081 FuncDeclaration *f; | |
1082 | |
1083 if (type->ty == Tpointer && type->next->ty == Tfunction && | |
1084 tb->ty == Tpointer && tb->next->ty == Tfunction) | |
1085 { | |
1086 f = var->isFuncDeclaration(); | |
1087 if (f) | |
1088 { | |
1089 f = f->overloadExactMatch(tb->next); | |
1090 if (f) | |
1091 { | |
1092 e = new SymOffExp(loc, f, 0); | |
1093 e->type = t; | |
1094 return e; | |
1095 } | |
1096 } | |
1097 } | |
1098 e = Expression::castTo(sc, t); | |
1099 } | |
1100 e->type = t; | |
1101 return e; | |
1102 } | |
1103 | |
1104 Expression *DelegateExp::castTo(Scope *sc, Type *t) | |
1105 { | |
1106 Type *tb; | |
1107 #if 0 | |
1108 printf("DelegateExp::castTo(this=%s, type=%s, t=%s)\n", | |
1109 toChars(), type->toChars(), t->toChars()); | |
1110 #endif | |
1111 Expression *e = this; | |
1112 static char msg[] = "cannot form delegate due to covariant return type"; | |
1113 | |
1114 tb = t->toBasetype(); | |
1115 type = type->toBasetype(); | |
1116 if (tb != type) | |
1117 { | |
1118 // Look for delegates to functions where the functions are overloaded. | |
1119 FuncDeclaration *f; | |
1120 | |
1121 if (type->ty == Tdelegate && type->next->ty == Tfunction && | |
1122 tb->ty == Tdelegate && tb->next->ty == Tfunction) | |
1123 { | |
1124 if (func) | |
1125 { | |
1126 f = func->overloadExactMatch(tb->next); | |
1127 if (f) | |
1128 { int offset; | |
1129 if (f->tintro && f->tintro->next->isBaseOf(f->type->next, &offset) && offset) | |
1130 error("%s", msg); | |
1131 e = new DelegateExp(loc, e1, f); | |
1132 e->type = t; | |
1133 return e; | |
1134 } | |
1135 if (func->tintro) | |
1136 error("%s", msg); | |
1137 } | |
1138 } | |
1139 e = Expression::castTo(sc, t); | |
1140 } | |
1141 else | |
1142 { int offset; | |
1143 | |
1144 if (func->tintro && func->tintro->next->isBaseOf(func->type->next, &offset) && offset) | |
1145 error("%s", msg); | |
1146 } | |
1147 e->type = t; | |
1148 return e; | |
1149 } | |
1150 | |
1151 Expression *CondExp::castTo(Scope *sc, Type *t) | |
1152 { | |
1153 Expression *e = this; | |
1154 | |
1155 if (type != t) | |
1156 { | |
1157 if (1 || e1->op == TOKstring || e2->op == TOKstring) | |
1158 { e = new CondExp(loc, econd, e1->castTo(sc, t), e2->castTo(sc, t)); | |
1159 e->type = t; | |
1160 } | |
1161 else | |
1162 e = Expression::castTo(sc, t); | |
1163 } | |
1164 return e; | |
1165 } | |
1166 | |
1167 /* ==================== ====================== */ | |
1168 | |
1169 /**************************************** | |
1170 * Scale addition/subtraction to/from pointer. | |
1171 */ | |
1172 | |
1173 Expression *BinExp::scaleFactor(Scope *sc) | |
1174 { d_uns64 stride; | |
1175 Type *t1b = e1->type->toBasetype(); | |
1176 Type *t2b = e2->type->toBasetype(); | |
1177 | |
1178 if (t1b->ty == Tpointer && t2b->isintegral()) | |
1179 { // Need to adjust operator by the stride | |
1180 // Replace (ptr + int) with (ptr + (int * stride)) | |
1181 Type *t = Type::tptrdiff_t; | |
1182 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1183 stride = t1b->nextOf()->size(loc); |
159 | 1184 if (!t->equals(t2b)) |
1185 e2 = e2->castTo(sc, t); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
510
diff
changeset
|
1186 // LDC: llvm uses typesafe pointer arithmetic |
159 | 1187 #if !IN_LLVM |
1188 if (t1b->next->isbit()) | |
1189 // BUG: should add runtime check for misaligned offsets | |
1190 // This perhaps should be done by rewriting as &p[i] | |
1191 // and letting back end do it. | |
1192 e2 = new UshrExp(loc, e2, new IntegerExp(0, 3, t)); | |
1193 else | |
1194 e2 = new MulExp(loc, e2, new IntegerExp(0, stride, t)); | |
1195 #endif | |
1196 e2->type = t; | |
1197 type = e1->type; | |
1198 } | |
1199 else if (t2b->ty == Tpointer && t1b->isintegral()) | |
1200 { // Need to adjust operator by the stride | |
1201 // Replace (int + ptr) with (ptr + (int * stride)) | |
1202 Type *t = Type::tptrdiff_t; | |
1203 Expression *e; | |
1204 | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1205 stride = t2b->nextOf()->size(loc); |
159 | 1206 if (!t->equals(t1b)) |
1207 e = e1->castTo(sc, t); | |
1208 else | |
1209 e = e1; | |
1210 #if !IN_LLVM | |
1211 if (t2b->next->isbit()) | |
1212 // BUG: should add runtime check for misaligned offsets | |
1213 e = new UshrExp(loc, e, new IntegerExp(0, 3, t)); | |
1214 else | |
1215 e = new MulExp(loc, e, new IntegerExp(0, stride, t)); | |
1216 #endif | |
1217 e->type = t; | |
1218 type = e2->type; | |
1219 e1 = e2; | |
1220 e2 = e; | |
1221 } | |
1222 return this; | |
1223 } | |
1224 | |
1225 /************************************ | |
1226 * Bring leaves to common type. | |
1227 */ | |
1228 | |
1229 Expression *BinExp::typeCombine(Scope *sc) | |
1230 { | |
1231 Type *t1; | |
1232 Type *t2; | |
1233 Type *t; | |
1234 TY ty; | |
1235 | |
1236 //printf("BinExp::typeCombine()\n"); | |
1237 //dump(0); | |
1238 | |
1239 e1 = e1->integralPromotions(sc); | |
1240 e2 = e2->integralPromotions(sc); | |
1241 | |
1242 // BUG: do toBasetype() | |
1243 t1 = e1->type; | |
1244 t2 = e2->type; | |
1245 assert(t1); | |
1246 | |
1247 //if (t1) printf("\tt1 = %s\n", t1->toChars()); | |
1248 //if (t2) printf("\tt2 = %s\n", t2->toChars()); | |
1249 #ifdef DEBUG | |
1250 if (!t2) printf("\te2 = '%s'\n", e2->toChars()); | |
1251 #endif | |
1252 assert(t2); | |
1253 | |
1254 Type *t1b = t1->toBasetype(); | |
1255 Type *t2b = t2->toBasetype(); | |
1256 | |
1257 ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty]; | |
1258 if (ty != Terror) | |
1259 { TY ty1; | |
1260 TY ty2; | |
1261 | |
1262 ty1 = (TY)Type::impcnvType1[t1b->ty][t2b->ty]; | |
1263 ty2 = (TY)Type::impcnvType2[t1b->ty][t2b->ty]; | |
1264 | |
1265 if (t1b->ty == ty1) // if no promotions | |
1266 { | |
1267 if (t1 == t2) | |
1268 { | |
1269 if (!type) | |
1270 type = t1; | |
1271 return this; | |
1272 } | |
1273 | |
1274 if (t1b == t2b) | |
1275 { | |
1276 if (!type) | |
1277 type = t1b; | |
1278 return this; | |
1279 } | |
1280 } | |
1281 | |
1282 if (!type) | |
1283 type = Type::basic[ty]; | |
1284 | |
1285 t1 = Type::basic[ty1]; | |
1286 t2 = Type::basic[ty2]; | |
1287 e1 = e1->castTo(sc, t1); | |
1288 e2 = e2->castTo(sc, t2); | |
1289 #if 0 | |
1290 if (type != Type::basic[ty]) | |
1291 { t = type; | |
1292 type = Type::basic[ty]; | |
1293 return castTo(sc, t); | |
1294 } | |
1295 #endif | |
1296 //printf("after typeCombine():\n"); | |
1297 //dump(0); | |
1298 //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2); | |
1299 return this; | |
1300 } | |
1301 | |
1302 t = t1; | |
1303 if (t1 == t2) | |
1304 { | |
1305 if ((t1->ty == Tstruct || t1->ty == Tclass) && | |
1306 (op == TOKmin || op == TOKadd)) | |
1307 goto Lincompatible; | |
1308 } | |
1309 else if (t1->isintegral() && t2->isintegral()) | |
1310 { | |
1311 printf("t1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); | |
1312 int sz1 = t1->size(); | |
1313 int sz2 = t2->size(); | |
1314 int sign1 = t1->isunsigned() == 0; | |
1315 int sign2 = t2->isunsigned() == 0; | |
1316 | |
1317 if (sign1 == sign2) | |
1318 { | |
1319 if (sz1 < sz2) | |
1320 goto Lt2; | |
1321 else | |
1322 goto Lt1; | |
1323 } | |
1324 if (!sign1) | |
1325 { | |
1326 if (sz1 >= sz2) | |
1327 goto Lt1; | |
1328 else | |
1329 goto Lt2; | |
1330 } | |
1331 else | |
1332 { | |
1333 if (sz2 >= sz1) | |
1334 goto Lt2; | |
1335 else | |
1336 goto Lt1; | |
1337 } | |
1338 } | |
1339 else if (t1->ty == Tpointer && t2->ty == Tpointer) | |
1340 { | |
1341 // Bring pointers to compatible type | |
1342 Type *t1n = t1->next; | |
1343 Type *t2n = t2->next; | |
1344 | |
1345 //t1->print(); | |
1346 //t2->print(); | |
1347 //if (t1n == t2n) *(char *)0 = 0; | |
1348 assert(t1n != t2n); | |
1349 if (t1n->ty == Tvoid) // pointers to void are always compatible | |
1350 t = t2; | |
1351 else if (t2n->ty == Tvoid) | |
1352 ; | |
1353 else if (t1n->ty == Tclass && t2n->ty == Tclass) | |
1354 { ClassDeclaration *cd1 = t1n->isClassHandle(); | |
1355 ClassDeclaration *cd2 = t2n->isClassHandle(); | |
1356 int offset; | |
1357 | |
1358 if (cd1->isBaseOf(cd2, &offset)) | |
1359 { | |
1360 if (offset) | |
1361 e2 = e2->castTo(sc, t); | |
1362 } | |
1363 else if (cd2->isBaseOf(cd1, &offset)) | |
1364 { | |
1365 t = t2; | |
1366 if (offset) | |
1367 e1 = e1->castTo(sc, t); | |
1368 } | |
1369 else | |
1370 goto Lincompatible; | |
1371 } | |
1372 else | |
1373 goto Lincompatible; | |
1374 } | |
1375 else if ((t1->ty == Tsarray || t1->ty == Tarray) && | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1376 e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1377 { /* (T[n] op void*) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1378 * (T[] op void*) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1379 */ |
159 | 1380 goto Lx1; |
1381 } | |
1382 else if ((t2->ty == Tsarray || t2->ty == Tarray) && | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1383 e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1384 { /* (void* op T[n]) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1385 * (void* op T[]) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1386 */ |
159 | 1387 goto Lx2; |
1388 } | |
1389 else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) | |
1390 { | |
1391 goto Lt2; | |
1392 } | |
1393 else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) | |
1394 { | |
1395 goto Lt1; | |
1396 } | |
1397 else if (t1->ty == Tclass || t2->ty == Tclass) | |
336 | 1398 { |
1399 while (1) | |
159 | 1400 { |
336 | 1401 int i1 = e2->implicitConvTo(t1); |
1402 int i2 = e1->implicitConvTo(t2); | |
1403 | |
1404 if (i1 && i2) | |
1405 { | |
1406 // We have the case of class vs. void*, so pick class | |
1407 if (t1->ty == Tpointer) | |
1408 i1 = 0; | |
1409 else if (t2->ty == Tpointer) | |
1410 i2 = 0; | |
1411 } | |
159 | 1412 |
336 | 1413 if (i2) |
1414 { | |
1415 goto Lt2; | |
1416 } | |
1417 else if (i1) | |
1418 { | |
1419 goto Lt1; | |
1420 } | |
1421 else if (t1->ty == Tclass && t2->ty == Tclass) | |
1422 { TypeClass *tc1 = (TypeClass *)t1; | |
1423 TypeClass *tc2 = (TypeClass *)t2; | |
1424 | |
1425 /* Pick 'tightest' type | |
1426 */ | |
1427 ClassDeclaration *cd1 = tc1->sym->baseClass; | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1428 ClassDeclaration *cd2 = tc2->sym->baseClass; |
336 | 1429 |
1430 if (cd1 && cd2) | |
1431 { t1 = cd1->type; | |
1432 t2 = cd2->type; | |
1433 } | |
1434 else if (cd1) | |
1435 t1 = cd1->type; | |
1436 else if (cd2) | |
1437 t2 = cd2->type; | |
1438 else | |
1439 goto Lincompatible; | |
1440 } | |
1441 else | |
1442 goto Lincompatible; | |
159 | 1443 } |
1444 } | |
1445 else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) | |
1446 { | |
1447 goto Lt2; | |
1448 } | |
1449 //else if (e2->op == TOKstring) { printf("test2\n"); } | |
1450 else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) | |
1451 { | |
1452 goto Lt1; | |
1453 } | |
1454 else if (t1->ty == Tsarray && t2->ty == Tsarray && | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1455 e2->implicitConvTo(t1->nextOf()->arrayOf())) |
159 | 1456 { |
1457 Lx1: | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1458 t = t1->nextOf()->arrayOf(); |
159 | 1459 e1 = e1->castTo(sc, t); |
1460 e2 = e2->castTo(sc, t); | |
1461 } | |
1462 else if (t1->ty == Tsarray && t2->ty == Tsarray && | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1463 e1->implicitConvTo(t2->nextOf()->arrayOf())) |
159 | 1464 { |
1465 Lx2: | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1466 t = t2->nextOf()->arrayOf(); |
159 | 1467 e1 = e1->castTo(sc, t); |
1468 e2 = e2->castTo(sc, t); | |
1469 } | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1470 else if (t1->isintegral() && t2->isintegral()) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1471 { |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1472 assert(0); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1473 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1474 else if (e1->op == TOKslice && t1->ty == Tarray && |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1475 e2->implicitConvTo(t1->nextOf())) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1476 { // T[] op T |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1477 e2 = e2->castTo(sc, t1->nextOf()); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1478 t = t1->nextOf()->arrayOf(); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1479 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1480 else if (e2->op == TOKslice && t2->ty == Tarray && |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1481 e1->implicitConvTo(t2->nextOf())) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1482 { // T op T[] |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1483 e1 = e1->castTo(sc, t2->nextOf()); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1484 t = t2->nextOf()->arrayOf(); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1485 |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1486 //printf("test %s\n", e->toChars()); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1487 e1 = e1->optimize(WANTvalue); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1488 if (isCommutative() && e1->isConst()) |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1489 { /* Swap operands to minimize number of functions generated |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1490 */ |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1491 //printf("swap %s\n", e->toChars()); |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1492 Expression *tmp = e1; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1493 e1 = e2; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1494 e2 = tmp; |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1495 } |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1496 } |
159 | 1497 else |
1498 { | |
1499 Lincompatible: | |
1500 incompatibleTypes(); | |
1501 } | |
1502 Lret: | |
1503 if (!type) | |
1504 type = t; | |
1505 //dump(0); | |
1506 return this; | |
1507 | |
1508 | |
1509 Lt1: | |
1510 e2 = e2->castTo(sc, t1); | |
1511 t = t1; | |
1512 goto Lret; | |
1513 | |
1514 Lt2: | |
1515 e1 = e1->castTo(sc, t2); | |
1516 t = t2; | |
1517 goto Lret; | |
1518 } | |
1519 | |
1520 /*********************************** | |
1521 * Do integral promotions (convertchk). | |
1522 * Don't convert <array of> to <pointer to> | |
1523 */ | |
1524 | |
1525 Expression *Expression::integralPromotions(Scope *sc) | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1526 { |
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1527 Expression *e = this; |
159 | 1528 |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
336
diff
changeset
|
1529 //printf("integralPromotions %s %s\n", e->toChars(), e->type->toChars()); |
159 | 1530 switch (type->toBasetype()->ty) |
1531 { | |
1532 case Tvoid: | |
1533 error("void has no value"); | |
1534 break; | |
1535 | |
1536 case Tint8: | |
1537 case Tuns8: | |
1538 case Tint16: | |
1539 case Tuns16: | |
1540 case Tbit: | |
1541 case Tbool: | |
1542 case Tchar: | |
1543 case Twchar: | |
1544 e = e->castTo(sc, Type::tint32); | |
1545 break; | |
1546 | |
1547 case Tdchar: | |
1548 e = e->castTo(sc, Type::tuns32); | |
1549 break; | |
1550 } | |
1551 return e; | |
1552 } | |
1553 |