1
Fork 0

libsyntax: Make float literals not use @str

This commit is contained in:
Patrick Walton 2014-01-15 17:15:39 -08:00 committed by Huon Wilson
parent 8d6ef2e1b1
commit b496d7bec2
7 changed files with 24 additions and 20 deletions

View file

@ -515,9 +515,9 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
LitInt(n, _) => const_int(n),
LitUint(n, _) => const_uint(n),
LitIntUnsuffixed(n) => const_int(n),
LitFloat(n, _) => const_float(from_str::<f64>(n).unwrap() as f64),
LitFloatUnsuffixed(n) =>
const_float(from_str::<f64>(n).unwrap() as f64),
LitFloat(ref n, _) | LitFloatUnsuffixed(ref n) => {
const_float(from_str::<f64>(n.get()).unwrap() as f64)
}
LitNil => const_int(0i64),
LitBool(b) => const_bool(b)
}

View file

@ -57,12 +57,14 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
ty_to_str(cx.tcx, lit_int_ty)))
}
}
ast::LitFloat(fs, t) => C_floating(fs, Type::float_from_ty(t)),
ast::LitFloatUnsuffixed(fs) => {
ast::LitFloat(ref fs, t) => {
C_floating(fs.get(), Type::float_from_ty(t))
}
ast::LitFloatUnsuffixed(ref fs) => {
let lit_float_ty = ty::node_id_to_type(cx.tcx, e.id);
match ty::get(lit_float_ty).sty {
ty::ty_float(t) => {
C_floating(fs, Type::float_from_ty(t))
C_floating(fs.get(), Type::float_from_ty(t))
}
_ => {
cx.sess.span_bug(lit.span,

View file

@ -1152,8 +1152,8 @@ fn lit_to_str(lit: &ast::Lit) -> ~str {
ast::LitInt(i, _t) => i.to_str(),
ast::LitUint(u, _t) => u.to_str(),
ast::LitIntUnsuffixed(i) => i.to_str(),
ast::LitFloat(f, _t) => f.to_str(),
ast::LitFloatUnsuffixed(f) => f.to_str(),
ast::LitFloat(ref f, _t) => f.get().to_str(),
ast::LitFloatUnsuffixed(ref f) => f.get().to_str(),
ast::LitBool(b) => b.to_str(),
ast::LitNil => ~"",
}

View file

@ -728,8 +728,8 @@ pub enum Lit_ {
LitInt(i64, IntTy),
LitUint(u64, UintTy),
LitIntUnsuffixed(i64),
LitFloat(@str, FloatTy),
LitFloatUnsuffixed(@str),
LitFloat(InternedString, FloatTy),
LitFloatUnsuffixed(InternedString),
LitNil,
LitBool(bool),
}

View file

@ -29,12 +29,11 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
match e.node {
ast::ExprLit(lit) => {
match lit.node {
ast::LitStr(ref s, _) => {
ast::LitStr(ref s, _) |
ast::LitFloat(ref s, _) |
ast::LitFloatUnsuffixed(ref s) => {
accumulator.push_str(s.get());
}
ast::LitFloat(s, _) | ast::LitFloatUnsuffixed(s) => {
accumulator.push_str(s);
}
ast::LitChar(c) => {
accumulator.push_char(char::from_u32(c).unwrap());
}

View file

@ -1405,9 +1405,12 @@ impl Parser {
token::LIT_INT(i, it) => LitInt(i, it),
token::LIT_UINT(u, ut) => LitUint(u, ut),
token::LIT_INT_UNSUFFIXED(i) => LitIntUnsuffixed(i),
token::LIT_FLOAT(s, ft) => LitFloat(self.id_to_str(s), ft),
token::LIT_FLOAT_UNSUFFIXED(s) =>
LitFloatUnsuffixed(self.id_to_str(s)),
token::LIT_FLOAT(s, ft) => {
LitFloat(self.id_to_interned_str(s), ft)
}
token::LIT_FLOAT_UNSUFFIXED(s) => {
LitFloatUnsuffixed(self.id_to_interned_str(s))
}
token::LIT_STR(s) => {
LitStr(self.id_to_interned_str(s), ast::CookedStr)
}

View file

@ -2202,10 +2202,10 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) {
word(&mut s.s, (i as u64).to_str_radix(10u));
}
}
ast::LitFloat(f, t) => {
word(&mut s.s, f.to_owned() + ast_util::float_ty_to_str(t));
ast::LitFloat(ref f, t) => {
word(&mut s.s, f.get() + ast_util::float_ty_to_str(t));
}
ast::LitFloatUnsuffixed(f) => word(&mut s.s, f),
ast::LitFloatUnsuffixed(ref f) => word(&mut s.s, f.get()),
ast::LitNil => word(&mut s.s, "()"),
ast::LitBool(val) => {
if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); }