Check for literals that are out of range for their type

This commit is contained in:
Marijn Haverbeke
2011-12-07 21:53:05 +01:00
parent e3eca9174b
commit 3d0610b072
4 changed files with 40 additions and 2 deletions

View File

@@ -132,6 +132,15 @@ fn int_ty_to_str(t: int_ty) -> str {
}
}
fn int_ty_max(t: int_ty) -> u64 {
alt t {
ty_i8. { 0x80u64 }
ty_i16. { 0x800u64 }
ty_char. | ty_i32. { 0x80000000u64 }
ty_i64. { 0x8000000000000000u64 }
}
}
fn uint_ty_to_str(t: uint_ty) -> str {
alt t {
ty_u. { "" } ty_u8. { "u8" } ty_u16. { "u16" }
@@ -139,6 +148,15 @@ fn uint_ty_to_str(t: uint_ty) -> str {
}
}
fn uint_ty_max(t: uint_ty) -> u64 {
alt t {
ty_u8. { 0xffu64 }
ty_u16. { 0xffffu64 }
ty_u32. { 0xffffffffu64 }
ty_u64. { 0xffffffffffffffffu64 }
}
}
fn float_ty_to_str(t: float_ty) -> str {
alt t { ty_f. { "" } ty_f32. { "f32" } ty_f64. { "f64" } }
}