Revision 12
Added by over 7 years ago
OoaTypeCheckVisitor.java | ||
---|---|---|
49 | 49 |
import org.momut.ooas.ast.statements.KillStatement; |
50 | 50 |
import org.momut.ooas.ast.statements.Statement; |
51 | 51 |
import org.momut.ooas.ast.types.FunctionType; |
52 |
import org.momut.ooas.ast.types.ListType; |
|
52 | 53 |
import org.momut.ooas.ast.types.TypeKind; |
53 | 54 |
import org.momut.ooas.ast.types.Type; |
54 | 55 |
import org.momut.ooas.parser.ParserError; |
... | ... | |
390 | 391 |
Error(attributeIdentifier, String.format("Type mismatch in attribute initializer: %s ( %s := %s )", attributeIdentifier.toString(), idtype.toString(), acover.toString())); |
391 | 392 |
else |
392 | 393 |
{ |
393 |
final Expression constantvalue = attributeIdentifier.initializer().kind() == ExpressionKind.Value ? attributeIdentifier.initializer() : null; |
|
394 |
|
|
395 | 394 |
if (!Type.TypeEqual(atype, acover)) |
396 | 395 |
{ |
397 |
final UnaryOperator cast = new UnaryOperator(ExpressionKind.Cast, attributeIdentifier.initializer(), |
|
398 |
attributeIdentifier.initializer().line(), attributeIdentifier.initializer().pos()); |
|
399 |
cast.SetType(acover); |
|
400 |
attributeIdentifier.SetInitializer(cast); |
|
396 |
if(acover.kind() == TypeKind.ListType) |
|
397 |
{ |
|
398 |
attributeIdentifier.initializer().Accept(new OoaStaticListCastVisitor((ListType) acover)); |
|
399 |
|
|
400 |
// now check whether the list lengths are ok |
|
401 |
((ListType) atype).SetInnerType(((ListType) idtype).innerType()); |
|
402 |
final Type lengthCover = Type.CoverType(idtype, attributeIdentifier.initializer().type()); |
|
403 |
if (!Type.TypeEqual(atype, lengthCover)) { |
|
404 |
final UnaryOperator cast = new UnaryOperator(ExpressionKind.Cast, attributeIdentifier.initializer(), |
|
405 |
attributeIdentifier.initializer().line(), attributeIdentifier.initializer().pos()); |
|
406 |
cast.SetType(lengthCover); |
|
407 |
attributeIdentifier.SetInitializer(cast); |
|
408 |
} |
|
409 |
} |
|
410 |
else |
|
411 |
{ |
|
412 |
final UnaryOperator cast = new UnaryOperator(ExpressionKind.Cast, attributeIdentifier.initializer(), |
|
413 |
attributeIdentifier.initializer().line(), attributeIdentifier.initializer().pos()); |
|
414 |
cast.SetType(acover); |
|
415 |
attributeIdentifier.SetInitializer(cast); |
|
416 |
} |
|
401 | 417 |
} |
402 | 418 |
|
403 | 419 |
if (Type.FirstTypeLessRange(idtype, acover)) |
404 | 420 |
{ |
421 |
final Expression constantvalue = attributeIdentifier.initializer().kind() == ExpressionKind.Value ? attributeIdentifier.initializer() : null; |
|
405 | 422 |
if (constantvalue == null) |
406 | 423 |
{ |
407 | 424 |
Warning(attributeIdentifier, String.format("Assignment may over/underflow: %s := %s", idtype.toString(), acover.toString())); |
... | ... | |
416 | 433 |
} |
417 | 434 |
} |
418 | 435 |
} |
419 |
|
|
420 |
/* |
|
421 |
|
|
422 |
|
|
423 |
if (cover == null || !UlyssesType.TypeEqual(cover, idtype)) |
|
424 |
Error(attributeIdentifier, |
|
425 |
String.Format("Type mismatch in attribute initializer: expected '%s', found '%s'", |
|
426 |
idtype.ToString(), atype.ToString())); |
|
427 |
else |
|
428 |
attributeIdentifier.SetInitializer(UnaryOperator.CoerceUp(attributeIdentifier.initializer, idtype)); |
|
429 |
* */ |
|
430 | 436 |
} |
431 | 437 |
} |
432 | 438 |
} |
Also available in: Unified diff
latest version of the ooas compiler, with grammar version 1.10