comparison sema/CheckTypes.d @ 195:4e1a7265d620

Made a BuildTypes pass, to give all exp's a type.
author Anders Johnsen <skabet@gmail.com>
date Tue, 29 Jul 2008 15:50:24 +0200
parents 08f68d684047
children
comparison
equal deleted inserted replaced
194:08f68d684047 195:4e1a7265d620
19 19
20 override void visitBinaryExp(BinaryExp exp) 20 override void visitBinaryExp(BinaryExp exp)
21 { 21 {
22 super.visitBinaryExp(exp); 22 super.visitBinaryExp(exp);
23 23
24 if(!(exp.left.type is exp.right.type)) 24 if(!exp.left.type.isSame(exp.right.type))
25 { 25 {
26 if (!exp.right.type.hasImplicitConversionTo(exp.left.type) && 26 if (!exp.right.type.hasImplicitConversionTo(exp.left.type) &&
27 !exp.left.type.hasImplicitConversionTo(exp.right.type)) 27 !exp.left.type.hasImplicitConversionTo(exp.right.type))
28 messages.report(InvalidImplicitCast, exp.loc) 28 messages.report(InvalidImplicitCast, exp.loc)
29 .arg(exp.right.type.toString) 29 .arg(exp.right.type.toString)
57 if(exp.left.type.byteSize > exp.right.type.byteSize) 57 if(exp.left.type.byteSize > exp.right.type.byteSize)
58 castExp = new CastExp( 58 castExp = new CastExp(
59 SLoc.Invalid, 59 SLoc.Invalid,
60 new Identifier(exp.left.type.name), 60 new Identifier(exp.left.type.name),
61 exp.right); 61 exp.right);
62 else if(exp.left.type.byteSize > exp.right.type.byteSize) 62 else if(exp.left.type.byteSize < exp.right.type.byteSize)
63 castExp = new CastExp( 63 castExp = new CastExp(
64 SLoc.Invalid, 64 SLoc.Invalid,
65 new Identifier(exp.right.type.name), 65 new Identifier(exp.right.type.name),
66 exp.left); 66 exp.left);
67 else 67 else
73 73
74 if(castExp) 74 if(castExp)
75 { 75 {
76 castExp.env = exp.env; 76 castExp.env = exp.env;
77 if(castExp.exp == exp.right) 77 if(castExp.exp == exp.right)
78 {
79 exp.type = castExp.type = exp.left.type;
78 exp.right = castExp; 80 exp.right = castExp;
81 }
79 else 82 else
83 {
84 exp.type = castExp.type = exp.right.type;
80 exp.left = castExp; 85 exp.left = castExp;
86 }
81 87
82 } 88 }
83 } 89 }
84 } 90 }
85 if (exp.op >= BinaryExp.Operator.LeftShift && 91 if (exp.op >= BinaryExp.Operator.LeftShift &&
96 messages.report(CanOnlyDerefPointers, 102 messages.report(CanOnlyDerefPointers,
97 [exp.exp.sourceRange][], 103 [exp.exp.sourceRange][],
98 [exp.loc]) 104 [exp.loc])
99 .arg(exp.exp.type.toString); 105 .arg(exp.exp.type.toString);
100 106
101 exp._type = DType.Int; 107 exp.type = DType.Int;
102 } 108 }
103 } 109 }
104 110
105 override void visitCallExp(CallExp exp) 111 override void visitCallExp(CallExp exp)
106 { 112 {
175 auto castExp = new CastExp( 181 auto castExp = new CastExp(
176 SLoc.Invalid, 182 SLoc.Invalid,
177 new Identifier(argType.name), 183 new Identifier(argType.name),
178 arg); 184 arg);
179 castExp.env = iden.env; 185 castExp.env = iden.env;
186 castExp.type = argType;
180 newArgs ~= castExp; 187 newArgs ~= castExp;
181 } 188 }
182 else 189 else
183 newArgs ~= arg; 190 newArgs ~= arg;
184 } 191 }
243 auto castExp = new CastExp( 250 auto castExp = new CastExp(
244 SLoc.Invalid, 251 SLoc.Invalid,
245 new Identifier(argType.name), 252 new Identifier(argType.name),
246 arg); 253 arg);
247 castExp.env = iden.env; 254 castExp.env = iden.env;
255 castExp.type = argType;
248 newArgs ~= castExp; 256 newArgs ~= castExp;
249 } 257 }
250 else 258 else
251 newArgs ~= arg; 259 newArgs ~= arg;
252 } 260 }
270 auto castExp = new CastExp( 278 auto castExp = new CastExp(
271 SLoc.Invalid, 279 SLoc.Invalid,
272 new Identifier(argType.name), 280 new Identifier(argType.name),
273 arg); 281 arg);
274 castExp.env = exp.exp.env; 282 castExp.env = exp.exp.env;
283 castExp.type = argType;
275 newArgs ~= castExp; 284 newArgs ~= castExp;
276 } 285 }
277 else 286 else
278 newArgs ~= arg; 287 newArgs ~= arg;
279 } 288 }
314 auto castExp = new CastExp( 323 auto castExp = new CastExp(
315 SLoc.Invalid, 324 SLoc.Invalid,
316 new Identifier(argType.name), 325 new Identifier(argType.name),
317 arg); 326 arg);
318 castExp.env = exp.newType.env; 327 castExp.env = exp.newType.env;
328 castExp.type = argType;
319 newArgs ~= castExp; 329 newArgs ~= castExp;
320 } 330 }
321 else 331 else
322 newArgs ~= arg; 332 newArgs ~= arg;
323 } 333 }
355 auto castExp = new CastExp( 365 auto castExp = new CastExp(
356 SLoc.Invalid, 366 SLoc.Invalid,
357 new Identifier(identifierType.name), 367 new Identifier(identifierType.name),
358 exp.exp); 368 exp.exp);
359 castExp.env = exp.exp.env; 369 castExp.env = exp.exp.env;
370 exp.type = castExp.type = identifierType;
360 exp.exp = castExp; 371 exp.exp = castExp;
361 } 372 }
362 373
363 if (expType.isStaticArray) 374 if (expType.isStaticArray)
364 messages.report(CannotReassignSArray, 375 messages.report(CannotReassignSArray,
386 auto castExp = new CastExp( 397 auto castExp = new CastExp(
387 SLoc.Invalid, 398 SLoc.Invalid,
388 new Identifier(returnType.name), 399 new Identifier(returnType.name),
389 stmt.exp); 400 stmt.exp);
390 castExp.env = stmt.exp.env; 401 castExp.env = stmt.exp.env;
402 castExp.type = returnType;
391 stmt.exp = castExp; 403 stmt.exp = castExp;
392 } 404 }
393 } 405 }
394 } 406 }
395 407
411 auto castExp = new CastExp( 423 auto castExp = new CastExp(
412 SLoc.Invalid, 424 SLoc.Invalid,
413 new Identifier(varType.name), 425 new Identifier(varType.name),
414 decl.init); 426 decl.init);
415 castExp.env = decl.init.env; 427 castExp.env = decl.init.env;
428 castExp.type = varType;
416 decl.init = castExp; 429 decl.init = castExp;
417 } 430 }
418 } 431 }
419 } 432 }
420 433