diff options
| author | bors <bors@rust-lang.org> | 2014-06-25 02:02:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-06-25 02:02:00 +0000 |
| commit | 91be86af0952aebb1f7c1811a6abcccd7bd1c26e (patch) | |
| tree | 45fd08bfce0007e8e32453b94fd3229d1a13fba3 /src/libsyntax | |
| parent | 05ca9f747d62c9385cc142daa3c24a32d32a3f16 (diff) | |
| parent | cdccecb24f5c467282b73413494343d3848b4e5a (diff) | |
| download | rust-91be86af0952aebb1f7c1811a6abcccd7bd1c26e.tar.gz rust-91be86af0952aebb1f7c1811a6abcccd7bd1c26e.zip | |
auto merge of #15163 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/abi.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 215 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/print/pp.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/util/small_vector.rs | 16 |
9 files changed, 114 insertions, 166 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 3d6266fd4c0..9771bc9386b 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -150,7 +150,7 @@ impl Abi { impl Architecture { fn bit(&self) -> u32 { - 1 << (*self as u32) + 1 << (*self as uint) } } @@ -198,11 +198,11 @@ fn indices_are_correct() { assert_eq!(i, abi_data.abi.index()); } - let bits = 1 << (X86 as u32); - let bits = bits | 1 << (X86_64 as u32); + let bits = 1 << (X86 as uint); + let bits = bits | 1 << (X86_64 as uint); assert_eq!(IntelBits, bits); - let bits = 1 << (Arm as u32); + let bits = 1 << (Arm as uint); assert_eq!(ArmBits, bits); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index aeafc0e306c..64d381d2b12 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -675,8 +675,7 @@ pub enum IntTy { impl fmt::Show for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", - ast_util::int_ty_to_str(*self, None, ast_util::AutoSuffix)) + write!(f, "{}", ast_util::int_ty_to_str(*self, None)) } } @@ -691,8 +690,7 @@ pub enum UintTy { impl fmt::Show for UintTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", - ast_util::uint_ty_to_str(*self, None, ast_util::AutoSuffix)) + write!(f, "{}", ast_util::uint_ty_to_str(*self, None)) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d28553da691..95bd35764e7 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -107,19 +107,11 @@ pub fn is_path(e: Gc<Expr>) -> bool { return match e.node { ExprPath(_) => true, _ => false }; } -pub enum SuffixMode { - ForceSuffix, - AutoSuffix, -} - // Get a string representation of a signed int type, with its value. // We want to avoid "45int" and "-3int" in favor of "45" and "-3" -pub fn int_ty_to_str(t: IntTy, val: Option<i64>, mode: SuffixMode) -> String { +pub fn int_ty_to_str(t: IntTy, val: Option<i64>) -> String { let s = match t { - TyI if val.is_some() => match mode { - AutoSuffix => "", - ForceSuffix => "i", - }, + TyI if val.is_some() => "i", TyI => "int", TyI8 => "i8", TyI16 => "i16", @@ -147,12 +139,9 @@ pub fn int_ty_max(t: IntTy) -> u64 { // Get a string representation of an unsigned int type, with its value. // We want to avoid "42uint" in favor of "42u" -pub fn uint_ty_to_str(t: UintTy, val: Option<u64>, mode: SuffixMode) -> String { +pub fn uint_ty_to_str(t: UintTy, val: Option<u64>) -> String { let s = match t { - TyU if val.is_some() => match mode { - AutoSuffix => "", - ForceSuffix => "u", - }, + TyU if val.is_some() => "u", TyU => "uint", TyU8 => "u8", TyU16 => "u16", diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 407715ab4da..9174bb65b24 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -32,6 +32,7 @@ use std::gc::Gc; pub mod rt { use ast; + use codemap::Spanned; use ext::base::ExtCtxt; use parse::token; use parse; @@ -48,12 +49,25 @@ pub mod rt { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> ; } + impl ToTokens for TokenTree { + fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { + vec!(self.clone()) + } + } + impl ToTokens for Vec<TokenTree> { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { (*self).clone() } } + impl<T: ToTokens> ToTokens for Spanned<T> { + fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { + // FIXME: use the span? + self.node.to_tokens(cx) + } + } + /* Should be (when bugs in default methods are fixed): trait ToSource : ToTokens { @@ -68,72 +82,62 @@ pub mod rt { */ + // FIXME: Move this trait to pprust and get rid of *_to_str? pub trait ToSource { // Takes a thing and generates a string containing rust code for it. fn to_source(&self) -> String; } - impl ToSource for ast::Ident { - fn to_source(&self) -> String { - token::get_ident(*self).get().to_string() - } - } - - impl ToSource for Gc<ast::Item> { - fn to_source(&self) -> String { - pprust::item_to_str(&**self) - } - } - - impl<'a> ToSource for &'a [Gc<ast::Item>] { - fn to_source(&self) -> String { - self.iter() - .map(|i| i.to_source()) - .collect::<Vec<String>>() - .connect("\n\n") - .to_string() - } - } - - impl ToSource for ast::Ty { - fn to_source(&self) -> String { - pprust::ty_to_str(self) - } - } - - impl<'a> ToSource for &'a [ast::Ty] { - fn to_source(&self) -> String { - self.iter() - .map(|i| i.to_source()) - .collect::<Vec<String>>() - .connect(", ") - .to_string() - } - } + macro_rules! impl_to_source( + (Gc<$t:ty>, $pp:ident) => ( + impl ToSource for Gc<$t> { + fn to_source(&self) -> String { + pprust::$pp(&**self) + } + } + ); + ($t:ty, $pp:ident) => ( + impl ToSource for $t { + fn to_source(&self) -> String { + pprust::$pp(self) + } + } + ); + ) - impl ToSource for Generics { - fn to_source(&self) -> String { - pprust::generics_to_str(self) - } + fn slice_to_source<'a, T: ToSource>(sep: &'static str, xs: &'a [T]) -> String { + xs.iter() + .map(|i| i.to_source()) + .collect::<Vec<String>>() + .connect(sep) + .to_string() } - impl ToSource for Gc<ast::Expr> { - fn to_source(&self) -> String { - pprust::expr_to_str(&**self) - } - } + macro_rules! impl_to_source_slice( + ($t:ty, $sep:expr) => ( + impl<'a> ToSource for &'a [$t] { + fn to_source(&self) -> String { + slice_to_source($sep, *self) + } + } + ) + ) - impl ToSource for ast::Block { + impl ToSource for ast::Ident { fn to_source(&self) -> String { - pprust::block_to_str(self) + token::get_ident(*self).get().to_string() } } - impl ToSource for ast::Arg { - fn to_source(&self) -> String { - pprust::arg_to_str(self) - } - } + impl_to_source!(ast::Ty, ty_to_str) + impl_to_source!(ast::Block, block_to_str) + impl_to_source!(ast::Arg, arg_to_str) + impl_to_source!(Generics, generics_to_str) + impl_to_source!(Gc<ast::Item>, item_to_str) + impl_to_source!(Gc<ast::Expr>, expr_to_str) + impl_to_source!(Gc<ast::Pat>, pat_to_str) + impl_to_source_slice!(ast::Ty, ", ") + impl_to_source_slice!(Gc<ast::Item>, "\n\n") impl<'a> ToSource for &'a str { fn to_source(&self) -> String { @@ -163,76 +167,36 @@ pub mod rt { } } - impl ToSource for int { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI)); - pprust::lit_to_str(&lit) - } - } - - impl ToSource for i8 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI8)); - pprust::lit_to_str(&lit) - } - } - - impl ToSource for i16 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI16)); - pprust::lit_to_str(&lit) - } - } - - - impl ToSource for i32 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI32)); - pprust::lit_to_str(&lit) - } - } - - impl ToSource for i64 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI64)); - pprust::lit_to_str(&lit) - } - } - - impl ToSource for uint { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU)); - pprust::lit_to_str(&lit) - } - } - - impl ToSource for u8 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU8)); - pprust::lit_to_str(&lit) - } - } - - impl ToSource for u16 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU16)); - pprust::lit_to_str(&lit) - } - } + macro_rules! impl_to_source_int( + (signed, $t:ty, $tag:ident) => ( + impl ToSource for $t { + fn to_source(&self) -> String { + let lit = dummy_spanned(ast::LitInt(*self as i64, ast::$tag)); + pprust::lit_to_str(&lit) + } + } + ); + (unsigned, $t:ty, $tag:ident) => ( + impl ToSource for $t { + fn to_source(&self) -> String { + let lit = dummy_spanned(ast::LitUint(*self as u64, ast::$tag)); + pprust::lit_to_str(&lit) + } + } + ); + ) - impl ToSource for u32 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU32)); - pprust::lit_to_str(&lit) - } - } + impl_to_source_int!(signed, int, TyI) + 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 ToSource for u64 { - fn to_source(&self) -> String { - let lit = dummy_spanned(ast::LitUint(*self as u64, ast::TyU64)); - pprust::lit_to_str(&lit) - } - } + impl_to_source_int!(unsigned, uint, TyU) + 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) // Alas ... we write these out instead. All redundant. @@ -246,7 +210,7 @@ pub mod rt { ) ) - macro_rules! impl_to_tokens_self( + macro_rules! impl_to_tokens_lifetime( ($t:ty) => ( impl<'a> ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { @@ -258,14 +222,15 @@ pub mod rt { impl_to_tokens!(ast::Ident) impl_to_tokens!(Gc<ast::Item>) - impl_to_tokens_self!(&'a [Gc<ast::Item>]) + impl_to_tokens!(Gc<ast::Pat>) + impl_to_tokens_lifetime!(&'a [Gc<ast::Item>]) impl_to_tokens!(ast::Ty) - impl_to_tokens_self!(&'a [ast::Ty]) + impl_to_tokens_lifetime!(&'a [ast::Ty]) impl_to_tokens!(Generics) impl_to_tokens!(Gc<ast::Expr>) impl_to_tokens!(ast::Block) impl_to_tokens!(ast::Arg) - impl_to_tokens_self!(&'a str) + impl_to_tokens_lifetime!(&'a str) impl_to_tokens!(()) impl_to_tokens!(char) impl_to_tokens!(bool) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e1319304e04..1cb09bb8d89 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2721,7 +2721,7 @@ impl<'a> Parser<'a> { } // parse an expression, subject to the given restriction - fn parse_expr_res(&mut self, r: restriction) -> Gc<Expr> { + pub fn parse_expr_res(&mut self, r: restriction) -> Gc<Expr> { let old = self.restriction; self.restriction = r; let e = self.parse_assign_expr(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 8e36339b0e5..9549d5b8389 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -212,10 +212,8 @@ pub fn to_str(t: &Token) -> String { res.push_char('\''); res } - LIT_INT(i, t) => ast_util::int_ty_to_str(t, Some(i), - ast_util::ForceSuffix), - LIT_UINT(u, t) => ast_util::uint_ty_to_str(t, Some(u), - ast_util::ForceSuffix), + LIT_INT(i, t) => ast_util::int_ty_to_str(t, Some(i)), + LIT_UINT(u, t) => ast_util::uint_ty_to_str(t, Some(u)), LIT_INT_UNSUFFIXED(i) => { (i as u64).to_str() } LIT_FLOAT(s, t) => { let mut body = String::from_str(get_ident(s).get()); diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 672e08af2d8..854aa80ca34 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -163,7 +163,7 @@ pub fn mk_printer(out: Box<io::Writer>, linewidth: uint) -> Printer { let n: uint = 3 * linewidth; debug!("mk_printer {}", linewidth); let token: Vec<Token> = Vec::from_elem(n, Eof); - let size: Vec<int> = Vec::from_elem(n, 0); + let size: Vec<int> = Vec::from_elem(n, 0i); let scan_stack: Vec<uint> = Vec::from_elem(n, 0u); Printer { out: out, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index fafebd3c5dc..97e99ca692d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2319,13 +2319,11 @@ impl<'a> State<'a> { } ast::LitInt(i, t) => { word(&mut self.s, - ast_util::int_ty_to_str(t, Some(i), - ast_util::AutoSuffix).as_slice()) + ast_util::int_ty_to_str(t, Some(i)).as_slice()) } ast::LitUint(u, t) => { word(&mut self.s, - ast_util::uint_ty_to_str(t, Some(u), - ast_util::ForceSuffix).as_slice()) + ast_util::uint_ty_to_str(t, Some(u)).as_slice()) } ast::LitIntUnsuffixed(i) => { word(&mut self.s, format!("{}", i).as_slice()) diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index a3b2c23dfdf..d5cc2c7f304 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -173,7 +173,7 @@ mod test { #[test] fn test_push_get() { let mut v = SmallVector::zero(); - v.push(1); + v.push(1i); assert_eq!(1, v.len()); assert_eq!(&1, v.get(0)); v.push(2); @@ -186,7 +186,7 @@ mod test { #[test] fn test_from_iter() { - let v: SmallVector<int> = (vec!(1, 2, 3)).move_iter().collect(); + let v: SmallVector<int> = (vec!(1i, 2, 3)).move_iter().collect(); assert_eq!(3, v.len()); assert_eq!(&1, v.get(0)); assert_eq!(&2, v.get(1)); @@ -199,11 +199,11 @@ mod test { let v: Vec<int> = v.move_iter().collect(); assert_eq!(Vec::new(), v); - let v = SmallVector::one(1); - assert_eq!(vec!(1), v.move_iter().collect()); + let v = SmallVector::one(1i); + assert_eq!(vec!(1i), v.move_iter().collect()); - let v = SmallVector::many(vec!(1, 2, 3)); - assert_eq!(vec!(1, 2, 3), v.move_iter().collect()); + let v = SmallVector::many(vec!(1i, 2i, 3i)); + assert_eq!(vec!(1i, 2i, 3i), v.move_iter().collect()); } #[test] @@ -220,7 +220,7 @@ mod test { #[test] fn test_expect_one_one() { - assert_eq!(1, SmallVector::one(1).expect_one("")); - assert_eq!(1, SmallVector::many(vec!(1)).expect_one("")); + assert_eq!(1i, SmallVector::one(1i).expect_one("")); + assert_eq!(1i, SmallVector::many(vec!(1i)).expect_one("")); } } |
