diff options
Diffstat (limited to 'src/libsyntax')
25 files changed, 229 insertions, 91 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 94bd9a18589..f77d00ce9b1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -17,6 +17,7 @@ use opt_vec::OptVec; use core::cast; use core::option::{None, Option, Some}; use core::to_bytes; +use core::to_bytes::IterBytes; use core::to_str::ToStr; use std::serialize::{Encodable, Decodable, Encoder, Decoder}; @@ -98,12 +99,14 @@ impl<D:Decoder> Decodable<D> for ident { #[cfg(stage0)] impl to_bytes::IterBytes for ident { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { self.repr.iter_bytes(lsb0, f) } } #[cfg(not(stage0))] impl to_bytes::IterBytes for ident { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { self.repr.iter_bytes(lsb0, f) } @@ -121,6 +124,20 @@ pub struct Lifetime { ident: ident } +#[cfg(stage0)] +impl to_bytes::IterBytes for Lifetime { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f) + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for Lifetime { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f) + } +} + // a "Path" is essentially Rust's notion of a name; // for instance: core::cmp::Eq . It's represented // as a sequence of identifiers, along with a bunch @@ -752,7 +769,7 @@ pub struct ty_method { purity: purity, decl: fn_decl, generics: Generics, - self_ty: self_ty, + explicit_self: explicit_self, id: node_id, span: span, } @@ -1049,7 +1066,7 @@ impl to_bytes::IterBytes for ret_style { #[auto_encode] #[auto_decode] #[deriving(Eq)] -pub enum self_ty_ { +pub enum explicit_self_ { sty_static, // no self sty_value, // `self` sty_region(Option<@Lifetime>, mutability), // `&'lt self` @@ -1057,7 +1074,33 @@ pub enum self_ty_ { sty_uniq(mutability) // `~self` } -pub type self_ty = spanned<self_ty_>; +#[cfg(stage0)] +impl to_bytes::IterBytes for explicit_self_ { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + match *self { + sty_static => 0u8.iter_bytes(lsb0, f), + sty_value => 1u8.iter_bytes(lsb0, f), + sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f), + sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f), + sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f), + } + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for explicit_self_ { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + match *self { + sty_static => 0u8.iter_bytes(lsb0, f), + sty_value => 1u8.iter_bytes(lsb0, f), + sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f), + sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f), + sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f), + } + } +} + +pub type explicit_self = spanned<explicit_self_>; #[auto_encode] #[auto_decode] @@ -1066,7 +1109,7 @@ pub struct method { ident: ident, attrs: ~[attribute], generics: Generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: purity, decl: fn_decl, body: blk, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 212ceadf912..a98e3002dcf 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -272,7 +272,7 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method { purity: m.purity, decl: copy m.decl, generics: copy m.generics, - self_ty: m.self_ty, + explicit_self: m.explicit_self, id: m.id, span: m.span, } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index e0392b476e4..cd0b29f2a1e 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -152,6 +152,20 @@ impl<D:Decoder> Decodable<D> for span { } } +#[cfg(stage0)] +impl to_bytes::IterBytes for span { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f); + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for span { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f) + } +} + pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> { respan(mk_sp(lo, hi), t) } @@ -199,16 +213,62 @@ pub struct FileMapAndLine {fm: @FileMap, line: uint} pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos} pub struct NameAndSpan {name: ~str, span: Option<span>} +#[cfg(stage0)] +impl to_bytes::IterBytes for NameAndSpan { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f) + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for NameAndSpan { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f) + } +} + pub struct CallInfo { call_site: span, callee: NameAndSpan } +#[cfg(stage0)] +impl to_bytes::IterBytes for CallInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f) + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for CallInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f) + } +} + /// Extra information for tracking macro expansion of spans pub enum ExpnInfo { ExpandedFrom(CallInfo) } +#[cfg(stage0)] +impl to_bytes::IterBytes for ExpnInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { + match *self { + ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f) + } + } +} + +#[cfg(not(stage0))] +impl to_bytes::IterBytes for ExpnInfo { + fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { + match *self { + ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f) + } + } +} + pub type FileName = ~str; pub struct FileLines diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 6b2aa2416f8..993fa612a27 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -232,7 +232,7 @@ fn highlight_lines(cm: @codemap::CodeMap, let max_lines = 6u; let mut elided = false; let mut display_lines = /* FIXME (#2543) */ copy lines.lines; - if vec::len(display_lines) > max_lines { + if display_lines.len() > max_lines { display_lines = vec::slice(display_lines, 0u, max_lines).to_vec(); elided = true; } @@ -243,7 +243,7 @@ fn highlight_lines(cm: @codemap::CodeMap, io::stderr().write_str(s); } if elided { - let last_line = display_lines[vec::len(display_lines) - 1u]; + let last_line = display_lines[display_lines.len() - 1u]; let s = fmt!("%s:%u ", fm.name, last_line + 1u); let mut indent = str::len(s); let mut out = ~""; @@ -254,7 +254,7 @@ fn highlight_lines(cm: @codemap::CodeMap, // FIXME (#3260) // If there's one line at fault we can easily point to the problem - if vec::len(lines.lines) == 1u { + if lines.lines.len() == 1u { let lo = cm.lookup_char_pos(sp.lo); let mut digits = 0u; let mut num = (lines.lines[0] + 1u) / 10u; diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index ac86d266d73..5c306aefc6a 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -713,7 +713,7 @@ fn mk_ser_method( ident: cx.ident_of("encode"), attrs: ~[], generics: ast_util::empty_generics(), - self_ty: codemap::spanned { + explicit_self: codemap::spanned { node: ast::sty_region(None, ast::m_imm), span: span }, @@ -772,7 +772,7 @@ fn mk_deser_method( ident: cx.ident_of("decode"), attrs: ~[], generics: ast_util::empty_generics(), - self_ty: codemap::spanned { node: ast::sty_static, span: span }, + explicit_self: codemap::spanned { node: ast::sty_static, span: span }, purity: ast::impure_fn, decl: deser_decl, body: deser_body, @@ -824,7 +824,7 @@ fn mk_struct_ser_impl( cx.ident_of("emit_struct"), ~[ cx.lit_str(span, @cx.str_of(ident)), - cx.lit_uint(span, vec::len(fields)), + cx.lit_uint(span, fields.len()), cx.lambda_stmts_1(span, fields, cx.ident_of("__s")), ] ); @@ -886,7 +886,7 @@ fn mk_struct_deser_impl( cx.ident_of("read_struct"), ~[ cx.lit_str(span, @cx.str_of(ident)), - cx.lit_uint(span, vec::len(fields)), + cx.lit_uint(span, fields.len()), cx.lambda_expr_1( cx.expr( span, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 20bf01c0dc1..30470d2ebe7 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -351,7 +351,7 @@ pub fn expr_to_ident(cx: @ext_ctxt, err_msg: &str) -> ast::ident { match expr.node { ast::expr_path(p) => { - if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { + if p.types.len() > 0u || p.idents.len() != 1u { cx.span_fatal(expr.span, err_msg); } return p.idents[0]; diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index 2151e9529c4..1a45107c267 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -28,7 +28,7 @@ pub fn expand_deriving_clone(cx: @ext_ctxt, MethodDef { name: ~"clone", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Self, const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index e431e1f78bf..7fc2fdc7963 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -34,7 +34,7 @@ pub fn expand_deriving_eq(cx: @ext_ctxt, MethodDef { name: $name, generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"bool"])), const_nonmatching: true, diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index cdb9f620301..5445aef4491 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -24,7 +24,7 @@ pub fn expand_deriving_ord(cx: @ext_ctxt, MethodDef { name: $name, generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"bool"])), const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index 068a7bc06b1..4541569b829 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -33,7 +33,7 @@ pub fn expand_deriving_totaleq(cx: @ext_ctxt, MethodDef { name: ~"equals", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"bool"])), const_nonmatching: true, diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 5ec4e028454..8f156e6a9e3 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_totalord(cx: @ext_ctxt, MethodDef { name: ~"cmp", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[borrowed_self()], ret_ty: Literal(Path::new(~[~"core", ~"cmp", ~"Ordering"])), const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index fd5d26a1787..3be65ecd8db 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -119,13 +119,13 @@ fn create_decode_method( let body_block = build::mk_simple_block(cx, span, expr); // Create the method. - let self_ty = spanned { node: sty_static, span: span }; + let explicit_self = spanned { node: sty_static, span: span }; let method_ident = cx.ident_of("decode"); @ast::method { ident: method_ident, attrs: ~[], generics: ast_util::empty_generics(), - self_ty: self_ty, + explicit_self: explicit_self, purity: impure_fn, decl: fn_decl, body: body_block, diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index a5edd92022f..2078ec9d45c 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -111,13 +111,13 @@ fn create_encode_method( let body_block = build::mk_block_(cx, span, statements); // Create the method. - let self_ty = spanned { node: sty_region(None, m_imm), span: span }; + let explicit_self = spanned { node: sty_region(None, m_imm), span: span }; let method_ident = cx.ident_of("encode"); @ast::method { ident: method_ident, attrs: ~[], generics: ast_util::empty_generics(), - self_ty: self_ty, + explicit_self: explicit_self, purity: impure_fn, decl: fn_decl, body: body_block, diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index be2cc6dd25e..fc14e3c3f73 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -216,7 +216,7 @@ pub struct MethodDef<'self> { /// Whether there is a self argument (outer Option) i.e. whether /// this is a static function, and whether it is a pointer (inner /// Option) - self_ty: Option<Option<PtrTy>>, + explicit_self: Option<Option<PtrTy>>, /// Arguments other than the self argument args: ~[Ty], @@ -321,7 +321,7 @@ impl<'self> TraitDef<'self> { type_ident: ident, generics: &Generics) -> @ast::item { let methods = do self.methods.map |method_def| { - let (self_ty, self_args, nonself_args, tys) = + let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(cx, span, type_ident, generics); let body = if method_def.is_static() { @@ -339,7 +339,7 @@ impl<'self> TraitDef<'self> { method_def.create_method(cx, span, type_ident, generics, - self_ty, tys, + explicit_self, tys, body) }; @@ -352,7 +352,7 @@ impl<'self> TraitDef<'self> { type_ident: ident, generics: &Generics) -> @ast::item { let methods = do self.methods.map |method_def| { - let (self_ty, self_args, nonself_args, tys) = + let (explicit_self, self_args, nonself_args, tys) = method_def.split_self_nonself_args(cx, span, type_ident, generics); let body = if method_def.is_static() { @@ -370,7 +370,7 @@ impl<'self> TraitDef<'self> { method_def.create_method(cx, span, type_ident, generics, - self_ty, tys, + explicit_self, tys, body) }; @@ -404,28 +404,27 @@ impl<'self> MethodDef<'self> { } fn is_static(&self) -> bool { - self.self_ty.is_none() + self.explicit_self.is_none() } fn split_self_nonself_args(&self, cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics) - -> (ast::self_ty, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) { + -> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) { let mut self_args = ~[], nonself_args = ~[], arg_tys = ~[]; - let mut ast_self_ty = respan(span, ast::sty_static); let mut nonstatic = false; - match self.self_ty { + let ast_explicit_self = match self.explicit_self { Some(ref self_ptr) => { - let (self_expr, self_ty) = ty::get_explicit_self(cx, span, - self_ptr); + let (self_expr, explicit_self) = ty::get_explicit_self(cx, span, self_ptr); - ast_self_ty = self_ty; self_args.push(self_expr); nonstatic = true; + + explicit_self } - _ => {} - } + None => respan(span, ast::sty_static), + }; for self.args.eachi |i, ty| { let ast_ty = ty.to_ty(cx, span, type_ident, generics); @@ -449,13 +448,13 @@ impl<'self> MethodDef<'self> { } } - (ast_self_ty, self_args, nonself_args, arg_tys) + (ast_explicit_self, self_args, nonself_args, arg_tys) } fn create_method(&self, cx: @ext_ctxt, span: span, type_ident: ident, generics: &Generics, - self_ty: ast::self_ty, + explicit_self: ast::explicit_self, arg_types: ~[(ident, @ast::Ty)], body: @expr) -> @ast::method { // create the generics that aren't for Self @@ -477,7 +476,7 @@ impl<'self> MethodDef<'self> { ident: method_ident, attrs: ~[], generics: fn_generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: ast::impure_fn, decl: fn_decl, body: body_block, diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 9eb246ffe22..27e3a54add5 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -26,7 +26,7 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt, MethodDef { name: ~"iter_bytes", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[ Literal(Path::new(~[~"bool"])), Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"])) diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 9030be86f39..2d91fcd346a 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -32,7 +32,7 @@ pub fn expand_deriving_rand(cx: @ext_ctxt, bounds: ~[(~"R", ~[ Path::new(~[~"core", ~"rand", ~"Rng"]) ])] }, - self_ty: None, + explicit_self: None, args: ~[ Ptr(~Literal(Path::new_local(~"R")), Borrowed(None, ast::m_mutbl)) diff --git a/src/libsyntax/ext/deriving/to_str.rs b/src/libsyntax/ext/deriving/to_str.rs index 6010354349e..13cb09e970d 100644 --- a/src/libsyntax/ext/deriving/to_str.rs +++ b/src/libsyntax/ext/deriving/to_str.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_to_str(cx: @ext_ctxt, MethodDef { name: ~"to_str", generics: LifetimeBounds::empty(), - self_ty: borrowed_explicit_self(), + explicit_self: borrowed_explicit_self(), args: ~[], ret_ty: Ptr(~Literal(Path::new_local(~"str")), Owned), const_nonmatching: false, diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index 768ac7458d6..8fd372e4792 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -217,7 +217,7 @@ pub impl LifetimeBounds { pub fn get_explicit_self(cx: @ext_ctxt, span: span, self_ptr: &Option<PtrTy>) - -> (@expr, ast::self_ty) { + -> (@expr, ast::explicit_self) { let self_path = build::make_self(cx, span); match *self_ptr { None => { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9afbe1e479d..f9ca84473fb 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -542,7 +542,41 @@ pub fn core_macros() -> ~str { } ) - + // + // A scheme-style conditional that helps to improve code clarity in some instances when + // the `if`, `else if`, and `else` keywords obscure predicates undesirably. + // + // # Example + // + // ~~~ + // let clamped = + // if x > mx { mx } + // else if x < mn { mn } + // else { x }; + // ~~~ + // + // Using `cond!`, the above could be written as: + // + // ~~~ + // let clamped = cond!( + // (x > mx) { mx } + // (x < mn) { mn } + // _ { x } + // ); + // ~~~ + // + // The optional default case is denoted by `_`. + // + macro_rules! cond ( + ( $(($pred:expr) $body:block)+ _ $default:block ) => ( + $(if $pred $body else)+ + $default + ); + // for if the default case was ommitted + ( $(($pred:expr) $body:block)+ ) => ( + $(if $pred $body)else+ + ); + ) }"; } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6ed8994ed33..f6dbbbf420d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -323,7 +323,7 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method { ident: fld.fold_ident(m.ident), attrs: /* FIXME (#2543) */ copy m.attrs, generics: fold_generics(&m.generics, fld), - self_ty: m.self_ty, + explicit_self: m.explicit_self, purity: m.purity, decl: fold_fn_decl(&m.decl, fld), body: fld.fold_block(&m.body), diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index fa91b968f69..89873b27935 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -276,7 +276,7 @@ fn read_block_comment(rdr: @mut StringReader, let mut style = if code_to_the_left { trailing } else { isolated }; consume_non_eol_whitespace(rdr); - if !is_eof(rdr) && rdr.curr != '\n' && vec::len(lines) == 1u { + if !is_eof(rdr) && rdr.curr != '\n' && lines.len() == 1u { style = mixed; } debug!("<<< block comment"); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e1fe20695c7..b76098858cb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -19,7 +19,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; use ast::{blk_check_mode, box}; use ast::{crate, crate_cfg, decl, decl_item}; -use ast::{decl_local, default_blk, deref, div, enum_def}; +use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self}; use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body}; @@ -43,7 +43,7 @@ use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; use ast::{pat_ident, pat_lit, pat_range, pat_region, pat_struct}; use ast::{pat_tup, pat_uniq, pat_wild, private}; use ast::{rem, required}; -use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl}; +use ast::{ret_style, return_val, shl, shr, stmt, stmt_decl}; use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field}; use ast::{struct_variant_kind, subtract}; use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value}; @@ -504,7 +504,7 @@ pub impl Parser { let generics = p.parse_generics(); - let (self_ty, d) = do self.parse_fn_decl_with_self() |p| { + let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| { // This is somewhat dubious; We don't want to allow argument // names to be left off if there is a definition... either::Left(p.parse_arg_general(false)) @@ -526,7 +526,7 @@ pub impl Parser { purity: pur, decl: d, generics: generics, - self_ty: self_ty, + explicit_self: explicit_self, id: p.get_id(), span: mk_sp(lo, hi) }) @@ -540,7 +540,7 @@ pub impl Parser { ident: ident, attrs: attrs, generics: generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: pur, decl: d, body: body, @@ -2471,7 +2471,7 @@ pub impl Parser { } }, _ => { - if vec::len(enum_path.idents)==1u { + if enum_path.idents.len()==1u { // it could still be either an enum // or an identifier pattern, resolve // will sort it out: @@ -3002,11 +3002,11 @@ pub impl Parser { &self, parse_arg_fn: &fn(&Parser) -> arg_or_capture_item - ) -> (self_ty, fn_decl) { - fn maybe_parse_self_ty( - cnstr: &fn(v: mutability) -> ast::self_ty_, + ) -> (explicit_self, fn_decl) { + fn maybe_parse_explicit_self( + cnstr: &fn(v: mutability) -> ast::explicit_self_, p: &Parser - ) -> ast::self_ty_ { + ) -> ast::explicit_self_ { // We need to make sure it isn't a mode or a type if p.token_is_keyword(&~"self", &p.look_ahead(1)) || ((p.token_is_keyword(&~"const", &p.look_ahead(1)) || @@ -3022,7 +3022,7 @@ pub impl Parser { } } - fn maybe_parse_borrowed_self_ty(this: &Parser) -> ast::self_ty_ { + fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ { // The following things are possible to see here: // // fn(&self) @@ -3066,15 +3066,15 @@ pub impl Parser { // A bit of complexity and lookahead is needed here in order to to be // backwards compatible. let lo = self.span.lo; - let self_ty = match *self.token { + let explicit_self = match *self.token { token::BINOP(token::AND) => { - maybe_parse_borrowed_self_ty(self) + maybe_parse_borrowed_explicit_self(self) } token::AT => { - maybe_parse_self_ty(sty_box, self) + maybe_parse_explicit_self(sty_box, self) } token::TILDE => { - maybe_parse_self_ty(sty_uniq, self) + maybe_parse_explicit_self(sty_uniq, self) } token::IDENT(*) if self.is_self_ident() => { self.bump(); @@ -3087,7 +3087,7 @@ pub impl Parser { // If we parsed a self type, expect a comma before the argument list. let args_or_capture_items; - if self_ty != sty_static { + if explicit_self != sty_static { match *self.token { token::COMMA => { self.bump(); @@ -3132,7 +3132,7 @@ pub impl Parser { cf: ret_style }; - (spanned(lo, hi, self_ty), fn_decl) + (spanned(lo, hi, explicit_self), fn_decl) } // parse the |arg, arg| header on a lambda @@ -3199,7 +3199,7 @@ pub impl Parser { let pur = self.parse_fn_purity(); let ident = self.parse_ident(); let generics = self.parse_generics(); - let (self_ty, decl) = do self.parse_fn_decl_with_self() |p| { + let (explicit_self, decl) = do self.parse_fn_decl_with_self() |p| { p.parse_arg() }; @@ -3210,7 +3210,7 @@ pub impl Parser { ident: ident, attrs: attrs, generics: generics, - self_ty: self_ty, + explicit_self: explicit_self, purity: pur, decl: decl, body: body, @@ -4337,7 +4337,7 @@ pub impl Parser { } _ => () } - let last = path[vec::len(path) - 1u]; + let last = path[path.len() - 1u]; let path = @ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 27686c4e4aa..fe479ab81f7 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -357,12 +357,14 @@ impl<'self> Equiv<@~str> for StringRef<'self> { #[cfg(stage0)] impl<'self> to_bytes::IterBytes for StringRef<'self> { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f); } } #[cfg(not(stage0))] impl<'self> to_bytes::IterBytes for StringRef<'self> { + #[inline(always)] fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool { (**self).iter_bytes(lsb0, f) } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 7944469cb96..38c58612f43 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -110,8 +110,8 @@ pub fn tok_str(t: token) -> ~str { pub fn buf_str(toks: ~[token], szs: ~[int], left: uint, right: uint, lim: uint) -> ~str { - let n = vec::len(toks); - assert!(n == vec::len(szs)); + let n = toks.len(); + assert!(n == szs.len()); let mut i = left; let mut L = lim; let mut s = ~"["; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1e94c16f87a..ea1682978a4 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -181,12 +181,12 @@ pub fn path_to_str(p: @ast::Path, intr: @ident_interner) -> ~str { } pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::ident, - opt_self_ty: Option<ast::self_ty_>, + opt_explicit_self: Option<ast::explicit_self_>, generics: &ast::Generics, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); print_fn(s, decl, Some(purity), AbiSet::Rust(), - name, generics, opt_self_ty, ast::inherited); + name, generics, opt_explicit_self, ast::inherited); end(s); // Close the head box end(s); // Close the outer box eof(s.s); @@ -797,7 +797,7 @@ pub fn print_ty_method(s: @ps, m: &ast::ty_method) { print_outer_attributes(s, m.attrs); print_ty_fn(s, None, None, None, m.purity, ast::Many, &m.decl, Some(m.ident), Some(&m.generics), - Some(/*bad*/ copy m.self_ty.node)); + Some(/*bad*/ copy m.explicit_self.node)); word(s.s, ~";"); } @@ -813,7 +813,7 @@ pub fn print_method(s: @ps, meth: @ast::method) { maybe_print_comment(s, meth.span.lo); print_outer_attributes(s, meth.attrs); print_fn(s, &meth.decl, Some(meth.purity), AbiSet::Rust(), - meth.ident, &meth.generics, Some(meth.self_ty.node), + meth.ident, &meth.generics, Some(meth.explicit_self.node), meth.vis); word(s.s, ~" "); print_block_with_attrs(s, &meth.body, meth.attrs); @@ -1626,13 +1626,13 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) { (s.ann.post)(ann_node); } -pub fn self_ty_to_str(self_ty: ast::self_ty_, intr: @ident_interner) -> ~str { - to_str(self_ty, |a, b| { print_self_ty(a, b); () }, intr) +pub fn explicit_self_to_str(explicit_self: ast::explicit_self_, intr: @ident_interner) -> ~str { + to_str(explicit_self, |a, b| { print_explicit_self(a, b); () }, intr) } // Returns whether it printed anything -pub fn print_self_ty(s: @ps, self_ty: ast::self_ty_) -> bool { - match self_ty { +pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool { + match explicit_self { ast::sty_static => { return false; } ast::sty_value => { word(s.s, ~"self"); } ast::sty_region(lt, m) => { @@ -1657,24 +1657,24 @@ pub fn print_fn(s: @ps, abis: AbiSet, name: ast::ident, generics: &ast::Generics, - opt_self_ty: Option<ast::self_ty_>, + opt_explicit_self: Option<ast::explicit_self_>, vis: ast::visibility) { head(s, ~""); - print_fn_header_info(s, opt_self_ty, purity, abis, ast::Many, None, vis); + print_fn_header_info(s, opt_explicit_self, purity, abis, ast::Many, None, vis); nbsp(s); print_ident(s, name); print_generics(s, generics); - print_fn_args_and_ret(s, decl, opt_self_ty); + print_fn_args_and_ret(s, decl, opt_explicit_self); } pub fn print_fn_args(s: @ps, decl: &ast::fn_decl, - opt_self_ty: Option<ast::self_ty_>) { + opt_explicit_self: Option<ast::explicit_self_>) { // It is unfortunate to duplicate the commasep logic, but we we want the // self type and the args all in the same box. box(s, 0u, inconsistent); let mut first = true; - for opt_self_ty.each |self_ty| { - first = !print_self_ty(s, *self_ty); + for opt_explicit_self.each |explicit_self| { + first = !print_explicit_self(s, *explicit_self); } for decl.inputs.each |arg| { @@ -1686,9 +1686,9 @@ pub fn print_fn_args(s: @ps, decl: &ast::fn_decl, } pub fn print_fn_args_and_ret(s: @ps, decl: &ast::fn_decl, - opt_self_ty: Option<ast::self_ty_>) { + opt_explicit_self: Option<ast::explicit_self_>) { popen(s); - print_fn_args(s, decl, opt_self_ty); + print_fn_args(s, decl, opt_explicit_self); pclose(s); maybe_print_comment(s, decl.output.span.lo); @@ -1798,7 +1798,7 @@ pub fn print_meta_item(s: @ps, item: @ast::meta_item) { pub fn print_view_path(s: @ps, vp: @ast::view_path) { match vp.node { ast::view_path_simple(ident, path, _) => { - if path.idents[vec::len(path.idents)-1u] != ident { + if path.idents[path.idents.len()-1u] != ident { print_ident(s, ident); space(s.s); word_space(s, ~"="); @@ -1900,7 +1900,7 @@ pub fn print_ty_fn(s: @ps, decl: &ast::fn_decl, id: Option<ast::ident>, generics: Option<&ast::Generics>, - opt_self_ty: Option<ast::self_ty_>) { + opt_explicit_self: Option<ast::explicit_self_>) { ibox(s, indent_unit); // Duplicates the logic in `print_fn_header_info()`. This is because that @@ -1920,8 +1920,8 @@ pub fn print_ty_fn(s: @ps, // self type and the args all in the same box. box(s, 0u, inconsistent); let mut first = true; - for opt_self_ty.each |self_ty| { - first = !print_self_ty(s, *self_ty); + for opt_explicit_self.each |explicit_self| { + first = !print_explicit_self(s, *explicit_self); } for decl.inputs.each |arg| { if first { first = false; } else { word_space(s, ~","); } @@ -2067,7 +2067,7 @@ pub fn maybe_print_comment(s: @ps, pos: BytePos) { pub fn print_comment(s: @ps, cmnt: &comments::cmnt) { match cmnt.style { comments::mixed => { - assert!((vec::len(cmnt.lines) == 1u)); + assert!(cmnt.lines.len() == 1u); zerobreak(s.s); word(s.s, cmnt.lines[0]); zerobreak(s.s); @@ -2083,7 +2083,7 @@ pub fn print_comment(s: @ps, cmnt: &comments::cmnt) { } comments::trailing => { word(s.s, ~" "); - if vec::len(cmnt.lines) == 1u { + if cmnt.lines.len() == 1u { word(s.s, cmnt.lines[0]); hardbreak(s.s); } else { @@ -2163,7 +2163,7 @@ pub fn print_opt_sigil(s: @ps, opt_sigil: Option<ast::Sigil>) { } pub fn print_fn_header_info(s: @ps, - _opt_sty: Option<ast::self_ty_>, + _opt_explicit_self: Option<ast::explicit_self_>, opt_purity: Option<ast::purity>, abis: AbiSet, onceness: ast::Onceness, |
