Store deprecated status of i/u-suffixed literals.

This commit is contained in:
Huon Wilson 2015-01-08 20:13:14 +11:00 committed by Niko Matsakis
parent 2f99a41fe1
commit e95779554e
18 changed files with 112 additions and 79 deletions

View file

@ -1075,15 +1075,29 @@ pub struct Typedef {
pub typ: P<Ty>,
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
pub enum IntTy {
TyIs,
TyIs(bool /* is this deprecated `int`? */),
TyI8,
TyI16,
TyI32,
TyI64,
}
impl PartialEq for IntTy {
fn eq(&self, other: &IntTy) -> bool {
match (*self, *other) {
// true/false need to compare the same, so this can't be derived
(TyIs(_), TyIs(_)) |
(TyI8, TyI8) |
(TyI16, TyI16) |
(TyI32, TyI32) |
(TyI64, TyI64) => true,
_ => false
}
}
}
impl fmt::Show for IntTy {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::String::fmt(self, f)
@ -1099,27 +1113,41 @@ impl fmt::String for IntTy {
impl IntTy {
pub fn suffix_len(&self) -> uint {
match *self {
TyIs => 1,
TyI8 => 2,
TyIs(true) /* i */ => 1,
TyIs(false) /* is */ | TyI8 => 2,
TyI16 | TyI32 | TyI64 => 3,
}
}
}
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
#[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Copy)]
pub enum UintTy {
TyUs,
TyUs(bool /* is this deprecated uint? */),
TyU8,
TyU16,
TyU32,
TyU64,
}
impl PartialEq for UintTy {
fn eq(&self, other: &UintTy) -> bool {
match (*self, *other) {
// true/false need to compare the same, so this can't be derived
(TyUs(_), TyUs(_)) |
(TyU8, TyU8) |
(TyU16, TyU16) |
(TyU32, TyU32) |
(TyU64, TyU64) => true,
_ => false
}
}
}
impl UintTy {
pub fn suffix_len(&self) -> uint {
match *self {
TyUs => 1,
TyU8 => 2,
TyUs(true) /* u */ => 1,
TyUs(false) /* us */ | TyU8 => 2,
TyU16 | TyU32 | TyU64 => 3,
}
}

View file

@ -127,8 +127,10 @@ pub fn is_path(e: P<Expr>) -> bool {
/// We want to avoid "45int" and "-3int" in favor of "45" and "-3"
pub fn int_ty_to_string(t: IntTy, val: Option<i64>) -> String {
let s = match t {
TyIs if val.is_some() => "is",
TyIs => "isize",
TyIs(true) if val.is_some() => "i",
TyIs(true) => "int",
TyIs(false) if val.is_some() => "is",
TyIs(false) => "isize",
TyI8 => "i8",
TyI16 => "i16",
TyI32 => "i32",
@ -148,7 +150,7 @@ pub fn int_ty_max(t: IntTy) -> u64 {
match t {
TyI8 => 0x80u64,
TyI16 => 0x8000u64,
TyIs | TyI32 => 0x80000000u64, // actually ni about TyIs
TyIs(_) | TyI32 => 0x80000000u64, // actually ni about TyIs
TyI64 => 0x8000000000000000u64
}
}
@ -157,8 +159,10 @@ pub fn int_ty_max(t: IntTy) -> u64 {
/// We want to avoid "42uint" in favor of "42u"
pub fn uint_ty_to_string(t: UintTy, val: Option<u64>) -> String {
let s = match t {
TyUs if val.is_some() => "us",
TyUs => "usize",
TyUs(true) if val.is_some() => "u",
TyUs(true) => "uint",
TyUs(false) if val.is_some() => "us",
TyUs(false) => "usize",
TyU8 => "u8",
TyU16 => "u16",
TyU32 => "u32",
@ -175,7 +179,7 @@ pub fn uint_ty_max(t: UintTy) -> u64 {
match t {
TyU8 => 0xffu64,
TyU16 => 0xffffu64,
TyUs | TyU32 => 0xffffffffu64, // actually ni about TyUs
TyUs(_) | TyU32 => 0xffffffffu64, // actually ni about TyUs
TyU64 => 0xffffffffffffffffu64
}
}

View file

@ -464,10 +464,10 @@ fn int_type_of_word(s: &str) -> Option<IntType> {
"u32" => Some(UnsignedInt(ast::TyU32)),
"i64" => Some(SignedInt(ast::TyI64)),
"u64" => Some(UnsignedInt(ast::TyU64)),
"int" => Some(SignedInt(ast::TyIs)),
"uint" => Some(UnsignedInt(ast::TyUs)),
"isize" => Some(SignedInt(ast::TyIs)),
"usize" => Some(UnsignedInt(ast::TyUs)),
"int" => Some(SignedInt(ast::TyIs(true))),
"uint" => Some(UnsignedInt(ast::TyUs(true))),
"isize" => Some(SignedInt(ast::TyIs(false))),
"usize" => Some(UnsignedInt(ast::TyUs(false))),
_ => None
}
}
@ -511,7 +511,7 @@ impl IntType {
SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) |
SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) |
SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true,
SignedInt(ast::TyIs) | UnsignedInt(ast::TyUs) => false
SignedInt(ast::TyIs(_)) | UnsignedInt(ast::TyUs(_)) => false
}
}
}

View file

@ -642,10 +642,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr(sp, ast::ExprLit(P(respan(sp, lit))))
}
fn expr_uint(&self, span: Span, i: uint) -> P<ast::Expr> {
self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs)))
self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs(false))))
}
fn expr_int(&self, sp: Span, i: int) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs, ast::Sign::new(i))))
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs(false),
ast::Sign::new(i))))
}
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8)))

View file

@ -1031,7 +1031,7 @@ impl<'a> MethodDef<'a> {
let arms: Vec<ast::Arm> = variants.iter().enumerate()
.map(|(index, variant)| {
let pat = variant_to_pat(cx, sp, type_ident, &**variant);
let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs));
let lit = ast::LitInt(index as u64, ast::UnsignedIntLit(ast::TyUs(false)));
cx.arm(sp, vec![pat], cx.expr_lit(sp, lit))
}).collect();

View file

@ -244,10 +244,10 @@ pub mod rt {
}
macro_rules! impl_to_source_int {
(signed, $t:ty, $tag:ident) => (
(signed, $t:ty, $tag:expr) => (
impl ToSource for $t {
fn to_source(&self) -> String {
let lit = ast::LitInt(*self as u64, ast::SignedIntLit(ast::$tag,
let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag,
ast::Sign::new(*self)));
pprust::lit_to_string(&dummy_spanned(lit))
}
@ -258,10 +258,10 @@ pub mod rt {
}
}
);
(unsigned, $t:ty, $tag:ident) => (
(unsigned, $t:ty, $tag:expr) => (
impl ToSource for $t {
fn to_source(&self) -> String {
let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit(ast::$tag));
let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag));
pprust::lit_to_string(&dummy_spanned(lit))
}
}
@ -273,17 +273,17 @@ pub mod rt {
);
}
impl_to_source_int! { signed, int, TyIs }
impl_to_source_int! { signed, i8, TyI8 }
impl_to_source_int! { signed, i16, TyI16 }
impl_to_source_int! { signed, i32, TyI32 }
impl_to_source_int! { signed, i64, TyI64 }
impl_to_source_int! { signed, int, ast::TyIs(false) }
impl_to_source_int! { signed, i8, ast::TyI8 }
impl_to_source_int! { signed, i16, ast::TyI16 }
impl_to_source_int! { signed, i32, ast::TyI32 }
impl_to_source_int! { signed, i64, ast::TyI64 }
impl_to_source_int! { unsigned, uint, TyUs }
impl_to_source_int! { unsigned, u8, TyU8 }
impl_to_source_int! { unsigned, u16, TyU16 }
impl_to_source_int! { unsigned, u32, TyU32 }
impl_to_source_int! { unsigned, u64, TyU64 }
impl_to_source_int! { unsigned, uint, ast::TyUs(false) }
impl_to_source_int! { unsigned, u8, ast::TyU8 }
impl_to_source_int! { unsigned, u16, ast::TyU16 }
impl_to_source_int! { unsigned, u32, ast::TyU32 }
impl_to_source_int! { unsigned, u64, ast::TyU64 }
// Alas ... we write these out instead. All redundant.

View file

@ -702,14 +702,14 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
if let Some(suf) = suffix {
if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")}
ty = match suf {
"i" => ast::SignedIntLit(ast::TyIs, ast::Plus),
"is" => ast::SignedIntLit(ast::TyIs, ast::Plus),
"i" => ast::SignedIntLit(ast::TyIs(true), ast::Plus),
"is" => ast::SignedIntLit(ast::TyIs(false), ast::Plus),
"i8" => ast::SignedIntLit(ast::TyI8, ast::Plus),
"i16" => ast::SignedIntLit(ast::TyI16, ast::Plus),
"i32" => ast::SignedIntLit(ast::TyI32, ast::Plus),
"i64" => ast::SignedIntLit(ast::TyI64, ast::Plus),
"u" => ast::UnsignedIntLit(ast::TyUs),
"us" => ast::UnsignedIntLit(ast::TyUs),
"u" => ast::UnsignedIntLit(ast::TyUs(true)),
"us" => ast::UnsignedIntLit(ast::TyUs(false)),
"u8" => ast::UnsignedIntLit(ast::TyU8),
"u16" => ast::UnsignedIntLit(ast::TyU16),
"u32" => ast::UnsignedIntLit(ast::TyU32),