[breaking-change] remove the sign from integer literals in the ast

This commit is contained in:
Oliver Schneider
2016-02-11 09:52:55 +01:00
parent 625e78b700
commit bfa66bb389
10 changed files with 55 additions and 82 deletions

View File

@@ -683,8 +683,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us)))
}
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is,
ast::Sign::new(i))))
if i < 0 {
let i = (-i) as u64;
let lit = self.expr_lit(sp, ast::LitInt(i, ast::SignedIntLit(ast::IntTy::Is)));
self.expr_unary(sp, ast::UnOp::Neg, lit)
} else {
self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is)))
}
}
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32)))

View File

@@ -263,9 +263,27 @@ pub mod rt {
(signed, $t:ty, $tag:expr) => (
impl ToTokens for $t {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag,
ast::Sign::new(*self)));
dummy_spanned(lit).to_tokens(cx)
let val = if *self < 0 {
-self
} else {
*self
};
let lit = ast::LitInt(val as u64, ast::SignedIntLit($tag));
let lit = P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Lit(P(dummy_spanned(lit))),
span: DUMMY_SP,
attrs: None,
});
if *self >= 0 {
return lit.to_tokens(cx);
}
P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Unary(ast::UnOp::Neg, lit),
span: DUMMY_SP,
attrs: None,
}).to_tokens(cx)
}
}
);