diff options
| author | Lindsey Kuper <lindsey@rockstargirl.org> | 2012-06-11 16:31:03 -0700 |
|---|---|---|
| committer | Lindsey Kuper <lindsey@rockstargirl.org> | 2012-06-11 16:34:56 -0700 |
| commit | 8467279faccc3837cddf854e30eafb3a086c3c9e (patch) | |
| tree | 6980e71b1a286ecd2a093a96205bbe8971cb450d /src/rustc | |
| parent | baf58a764b4cc5ffc3de7bf43b549a4cc59a57a4 (diff) | |
| download | rust-8467279faccc3837cddf854e30eafb3a086c3c9e.tar.gz rust-8467279faccc3837cddf854e30eafb3a086c3c9e.zip | |
Add a new AST node for unsuffixed integer types.
Diffstat (limited to 'src/rustc')
| -rw-r--r-- | src/rustc/middle/const_eval.rs | 1 | ||||
| -rw-r--r-- | src/rustc/middle/trans/base.rs | 5 | ||||
| -rw-r--r-- | src/rustc/middle/typeck/check.rs | 54 |
3 files changed, 29 insertions, 31 deletions
diff --git a/src/rustc/middle/const_eval.rs b/src/rustc/middle/const_eval.rs index 3fb75900faf..d0e4b715988 100644 --- a/src/rustc/middle/const_eval.rs +++ b/src/rustc/middle/const_eval.rs @@ -111,6 +111,7 @@ fn lit_to_const(lit: @lit) -> const_val { lit_str(s) { const_str(s) } lit_int(n, _) { const_int(n) } lit_uint(n, _) { const_uint(n) } + lit_int_unsuffixed(n, _) { const_int(n) } lit_float(n, _) { const_float(option::get(float::from_str(n)) as f64) } lit_nil { const_int(0i64) } lit_bool(b) { const_int(b as i64) } diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index a6806d97559..07216030767 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -1483,6 +1483,11 @@ fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef { alt lit.node { ast::lit_int(i, t) { C_integral(T_int_ty(cx, t), i as u64, True) } ast::lit_uint(u, t) { C_integral(T_uint_ty(cx, t), u, False) } + ast::lit_int_unsuffixed(i, t) { + // FIXME (#1425): should we be using cx.fcx.infcx to figure out what + // to actually generate from this? + C_integral(T_int_ty(cx, t), i as u64, True) + } ast::lit_float(fs, t) { C_floating(fs, T_float_ty(cx, t)) } ast::lit_bool(b) { C_bool(b) } ast::lit_nil { C_nil() } diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 50123559f02..bc7f46703e0 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -629,40 +629,32 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t { alt lit.node { ast::lit_str(_) { ty::mk_str(tcx) } - ast::lit_int(v, t) { - alt t { - ty_char | ty_i8 | ty_i16 | ty_i32 | ty_i64 { - // If it's a char or has an explicit suffix, give it the - // appropriate integral type. - ty::mk_mach_int(tcx, t) - } - ty_i { - // Otherwise, an unsuffixed integer literal parses to a - // `ty_i`. In that case, it could have any integral type, - // so create an integral type variable for it. - let vid = fcx.infcx.next_ty_var_integral_id(); - - // We need to sniff at the value `v` provided and figure - // out how big of an int it is; that determines the set of - // possibly types it could take on. - let possible_types = alt v { - 0i64 to 127i64 { min_8bit_tys() } - 128i64 to 65535i64 { min_16bit_tys() } - 65536i64 to 4294967295i64 { min_32bit_tys() } - _ { min_64bit_tys() } - }; + ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) } + ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) } + ast::lit_int_unsuffixed(v, t) { + // An unsuffixed integer literal could have any integral type, + // so we create an integral type variable for it. + let vid = fcx.infcx.next_ty_var_integral_id(); + + // We need to sniff at the value `v` and figure out how big of + // an int it is; that determines the range of possible types + // that the integral type variable could take on. + let possible_types = alt v { + 0i64 to 127i64 { min_8bit_tys() } + 128i64 to 65535i64 { min_16bit_tys() } + 65536i64 to 4294967295i64 { min_32bit_tys() } + _ { min_64bit_tys() } + }; - // Store the set of possible types - fcx.infcx.set(fcx.infcx.tvib, vid, - root(possible_types)); - ty::mk_var_integral(tcx, vid); + // Store the set of possible types and return the integral + // type variable. + fcx.infcx.set(fcx.infcx.tvib, vid, + root(possible_types)); + ty::mk_var_integral(tcx, vid); - // FIXME: remove me when #1425 is finished. - ty::mk_mach_int(tcx, t) - } - } + // FIXME: remove me when #1425 is finished. + ty::mk_mach_int(tcx, t) } - ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) } ast::lit_float(_, t) { ty::mk_mach_float(tcx, t) } ast::lit_nil { ty::mk_nil(tcx) } ast::lit_bool(_) { ty::mk_bool(tcx) } |
