Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Commit

Permalink
No i128 or u128
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 6, 2017
1 parent fbedee1 commit 8759cfe
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
14 changes: 6 additions & 8 deletions syntex_syntax/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ use std::u32;

use serialize::{self, Encodable, Decodable, Encoder, Decoder};

use rustc_i128::{u128, i128};

/// An identifier contains a Name (index into the interner
/// table) and a SyntaxContext to track renaming and
/// macro expansion per Flatt et al., "Macros That Work Together"
Expand Down Expand Up @@ -1064,7 +1062,7 @@ pub enum LitKind {
/// A character literal (`'a'`)
Char(char),
/// An integer literal (`1`)
Int(u128, LitIntType),
Int(u64, LitIntType),
/// A float literal (`1f64` or `1E10f64`)
Float(Symbol, FloatTy),
/// A float literal without a suffix (`1.0 or 1.0E10`)
Expand Down Expand Up @@ -1200,11 +1198,11 @@ impl IntTy {
}
}

pub fn val_to_string(&self, val: i128) -> String {
// cast to a u128 so we can correctly print INT128_MIN. All integral types
// are parsed as u128, so we wouldn't want to print an extra negative
pub fn val_to_string(&self, val: i64) -> String {
// cast to a u64 so we can correctly print INT64_MIN. All integral types
// are parsed as u64, so we wouldn't want to print an extra negative
// sign.
format!("{}{}", val as u128, self.ty_to_string())
format!("{}{}", val as u64, self.ty_to_string())
}

pub fn bit_width(&self) -> Option<usize> {
Expand Down Expand Up @@ -1241,7 +1239,7 @@ impl UintTy {
}
}

pub fn val_to_string(&self, val: u128) -> String {
pub fn val_to_string(&self, val: u64) -> String {
format!("{}{}", val, self.ty_to_string())
}

Expand Down
11 changes: 5 additions & 6 deletions syntex_syntax/src/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use codemap::{dummy_spanned, respan, Spanned};
use ext::base::ExtCtxt;
use ptr::P;
use symbol::{Symbol, keywords};
use rustc_i128::u128;

// Transitional reexports so qquote can find the paths it is looking for
mod syntax {
Expand Down Expand Up @@ -713,26 +712,26 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit))))
}
fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> {
self.expr_lit(span, ast::LitKind::Int(i as u128,
self.expr_lit(span, ast::LitKind::Int(i as u64,
ast::LitIntType::Unsigned(ast::UintTy::Us)))
}
fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> {
if i < 0 {
let i = (-i) as u128;
let i = (-i) as u64;
let lit_ty = ast::LitIntType::Signed(ast::IntTy::Is);
let lit = self.expr_lit(sp, ast::LitKind::Int(i, lit_ty));
self.expr_unary(sp, ast::UnOp::Neg, lit)
} else {
self.expr_lit(sp, ast::LitKind::Int(i as u128,
self.expr_lit(sp, ast::LitKind::Int(i as u64,
ast::LitIntType::Signed(ast::IntTy::Is)))
}
}
fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitKind::Int(u as u128,
self.expr_lit(sp, ast::LitKind::Int(u as u64,
ast::LitIntType::Unsigned(ast::UintTy::U32)))
}
fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitKind::Int(u as u128, ast::LitIntType::Unsigned(ast::UintTy::U8)))
self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::LitIntType::Unsigned(ast::UintTy::U8)))
}
fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> {
self.expr_lit(sp, ast::LitKind::Bool(value))
Expand Down
5 changes: 2 additions & 3 deletions syntex_syntax/src/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub mod rt {
pub use parse::new_parser_from_tts;
pub use syntax_pos::{BytePos, Span, DUMMY_SP};
pub use codemap::{dummy_spanned};
use rustc_i128::{u128};

pub trait ToTokens {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree>;
Expand Down Expand Up @@ -290,7 +289,7 @@ pub mod rt {
} else {
*self
};
let lit = ast::LitKind::Int(val as u128, ast::LitIntType::Signed($tag));
let lit = ast::LitKind::Int(val as u64, ast::LitIntType::Signed($tag));
let lit = P(ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Lit(P(dummy_spanned(lit))),
Expand All @@ -312,7 +311,7 @@ pub mod rt {
(unsigned, $t:ty, $tag:expr) => (
impl ToTokens for $t {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
let lit = ast::LitKind::Int(*self as u128, ast::LitIntType::Unsigned($tag));
let lit = ast::LitKind::Int(*self as u64, ast::LitIntType::Unsigned($tag));
dummy_spanned(lit).to_tokens(cx)
}
}
Expand Down
4 changes: 1 addition & 3 deletions syntex_syntax/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str;

use rustc_i128::u128;

pub type PResult<'a, T> = Result<T, DiagnosticBuilder<'a>>;

#[macro_use]
Expand Down Expand Up @@ -591,7 +589,7 @@ pub fn integer_lit(s: &str, suffix: Option<Symbol>, sd: &Handler, sp: Span) -> a
debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \
string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix);

match u128::from_str_radix(s, base) {
match u64::from_str_radix(s, base) {
Ok(r) => ast::LitKind::Int(r, ty),
Err(_) => {
// small bases are lexed as if they were base 10, e.g, the string
Expand Down
4 changes: 1 addition & 3 deletions syntex_syntax/src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::slice;

use rustc_i128::u128;

bitflags! {
pub flags Restrictions: u8 {
const RESTRICTION_STMT_EXPR = 1 << 0,
Expand Down Expand Up @@ -2056,7 +2054,7 @@ impl<'a> Parser<'a> {
pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinVec<Attribute>) -> P<Expr> {
let span = &self.span;
let lv_lit = P(codemap::Spanned {
node: LitKind::Int(i as u128, ast::LitIntType::Unsigned(UintTy::U32)),
node: LitKind::Int(i as u64, ast::LitIntType::Unsigned(UintTy::U32)),
span: *span
});

Expand Down
4 changes: 1 addition & 3 deletions syntex_syntax/src/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use std_inject;
use symbol::{Symbol, keywords};
use tokenstream::{self, TokenTree};

use rustc_i128::i128;

use std::ascii;
use std::io::{self, Write, Read};
use std::iter;
Expand Down Expand Up @@ -649,7 +647,7 @@ pub trait PrintState<'a> {
ast::LitKind::Int(i, t) => {
match t {
ast::LitIntType::Signed(st) => {
word(self.writer(), &st.val_to_string(i as i128))
word(self.writer(), &st.val_to_string(i as i64))
}
ast::LitIntType::Unsigned(ut) => {
word(self.writer(), &ut.val_to_string(i))
Expand Down

0 comments on commit 8759cfe

Please sign in to comment.