diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-12 11:27:30 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-12 12:04:14 +0200 |
| commit | fc6b7c8b381bcb506eab0f50c69b6cc18aafacb2 (patch) | |
| tree | c3511313bdb6c7cc8919426ce980e558396fe92c /src/comp/syntax | |
| parent | 64a6376da5ef6e40870af77410d3542ff7bab140 (diff) | |
| download | rust-fc6b7c8b381bcb506eab0f50c69b6cc18aafacb2.tar.gz rust-fc6b7c8b381bcb506eab0f50c69b6cc18aafacb2.zip | |
Reformat for new mode syntax, step 1
Long lines were fixed in a very crude way, as I'll be following up with another reformat in a bit.
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 24 | ||||
| -rw-r--r-- | src/comp/syntax/codemap.rs | 16 | ||||
| -rw-r--r-- | src/comp/syntax/ext/base.rs | 12 | ||||
| -rw-r--r-- | src/comp/syntax/ext/concat_idents.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ext/env.rs | 6 | ||||
| -rw-r--r-- | src/comp/syntax/ext/expand.rs | 7 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 61 | ||||
| -rw-r--r-- | src/comp/syntax/ext/ident_to_str.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ext/log_syntax.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 121 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 260 | ||||
| -rw-r--r-- | src/comp/syntax/parse/eval.rs | 10 | ||||
| -rw-r--r-- | src/comp/syntax/parse/lexer.rs | 58 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 329 | ||||
| -rw-r--r-- | src/comp/syntax/parse/token.rs | 3 | ||||
| -rw-r--r-- | src/comp/syntax/print/pp.rs | 12 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 261 | ||||
| -rw-r--r-- | src/comp/syntax/util/interner.rs | 6 | ||||
| -rw-r--r-- | src/comp/syntax/visit.rs | 166 |
20 files changed, 689 insertions, 679 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 67d0f6022f7..7ab627ec2b9 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -293,10 +293,11 @@ tag ty_ { for this type. */ + /* bot represents the value of functions that don't return a value locally to their context. in contrast, things like log that do return, but don't return a meaningful value, have result type nil. */ - ty_bool; + ty_bool; ty_int; ty_uint; ty_float; @@ -381,6 +382,7 @@ tag controlflow { // raise an error or exit (i.e. never return to the caller) + return; // everything else } diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index c5d769c1299..eaf6728838b 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -3,7 +3,7 @@ import std::option; import codemap::span; import ast::*; -fn respan<@T>(sp: &span, t: &T) -> spanned<T> { ret {node: t, span: sp}; } +fn respan<@T>(sp: span, t: T) -> spanned<T> { ret {node: t, span: sp}; } /* assuming that we're not in macro expansion */ fn mk_sp(lo: uint, hi: uint) -> span { @@ -13,13 +13,13 @@ fn mk_sp(lo: uint, hi: uint) -> span { // make this a const, once the compiler supports it fn dummy_sp() -> span { ret mk_sp(0u, 0u); } -fn path_name(p: &path) -> str { path_name_i(p.node.idents) } +fn path_name(p: path) -> str { path_name_i(p.node.idents) } -fn path_name_i(idents: &[ident]) -> str { str::connect(idents, "::") } +fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") } fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; } -fn variant_def_ids(d: &def) -> {tg: def_id, var: def_id} { +fn variant_def_ids(d: def) -> {tg: def_id, var: def_id} { alt d { def_variant(tag_id, var_id) { ret {tg: tag_id, var: var_id}; } } } @@ -47,7 +47,7 @@ type pat_id_map = std::map::hashmap<str, node_id>; // This is used because same-named variables in alternative patterns need to // use the node_id of their namesake in the first pattern. -fn pat_id_map(pat: &@pat) -> pat_id_map { +fn pat_id_map(pat: @pat) -> pat_id_map { let map = std::map::new_str_hash::<node_id>(); for each bound in pat_bindings(pat) { let name = alt bound.node { pat_bind(n) { n } }; @@ -57,7 +57,7 @@ fn pat_id_map(pat: &@pat) -> pat_id_map { } // FIXME: could return a constrained type -iter pat_bindings(pat: &@pat) -> @pat { +iter pat_bindings(pat: @pat) -> @pat { alt pat.node { pat_bind(_) { put pat; } pat_tag(_, sub) { @@ -74,7 +74,7 @@ iter pat_bindings(pat: &@pat) -> @pat { } } -fn pat_binding_ids(pat: &@pat) -> [node_id] { +fn pat_binding_ids(pat: @pat) -> [node_id] { let found = []; for each b in pat_bindings(pat) { found += [b.id]; } ret found; @@ -117,7 +117,7 @@ fn unop_to_str(op: unop) -> str { } } -fn is_path(e: &@expr) -> bool { +fn is_path(e: @expr) -> bool { ret alt e.node { expr_path(_) { true } _ { false } }; } @@ -179,9 +179,9 @@ fn is_constraint_arg(e: @expr) -> bool { } } -fn eq_ty(a: &@ty, b: &@ty) -> bool { ret std::box::ptr_eq(a, b); } +fn eq_ty(a: @ty, b: @ty) -> bool { ret std::box::ptr_eq(a, b); } -fn hash_ty(t: &@ty) -> uint { ret t.span.lo << 16u + t.span.hi; } +fn hash_ty(t: @ty) -> uint { ret t.span.lo << 16u + t.span.hi; } fn block_from_expr(e: @expr) -> blk { let blk_ = checked_blk([], option::some::<@expr>(e), e.id); @@ -193,13 +193,13 @@ fn checked_blk(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) -> ret {stmts: stmts1, expr: expr1, id: id1, rules: checked}; } -fn obj_field_from_anon_obj_field(f: &anon_obj_field) -> obj_field { +fn obj_field_from_anon_obj_field(f: anon_obj_field) -> obj_field { ret {mut: f.mut, ty: f.ty, ident: f.ident, id: f.id}; } // This is a convenience function to transfor ternary expressions to if // expressions so that they can be treated the same -fn ternary_to_if(e: &@expr) -> @expr { +fn ternary_to_if(e: @expr) -> @expr { alt e.node { expr_ternary(cond, then, els) { let then_blk = block_from_expr(then); diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index edb414b4e9b..b0f3bde73d9 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -73,7 +73,7 @@ tag opt_span { } type span = {lo: uint, hi: uint, expanded_from: opt_span}; -fn span_to_str(sp: &span, cm: &codemap) -> str { +fn span_to_str(sp: span, cm: codemap) -> str { let cur = sp; let res = ""; let prev_file = none; @@ -98,8 +98,8 @@ fn span_to_str(sp: &span, cm: &codemap) -> str { ret res; } -fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8, - cm: &codemap) { +fn emit_diagnostic(sp: option::t<span>, msg: str, kind: str, color: u8, + cm: codemap) { let ss = ""; let maybe_lines: option::t<@file_lines> = none; alt sp { @@ -120,7 +120,7 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8, maybe_highlight_lines(sp, cm, maybe_lines); } -fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, +fn maybe_highlight_lines(sp: option::t<span>, cm: codemap, maybe_lines: option::t<@file_lines>) { alt maybe_lines { @@ -188,13 +188,13 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, } } -fn emit_warning(sp: &option::t<span>, msg: &str, cm: &codemap) { +fn emit_warning(sp: option::t<span>, msg: str, cm: codemap) { emit_diagnostic(sp, msg, "warning", 11u8, cm); } -fn emit_error(sp: &option::t<span>, msg: &str, cm: &codemap) { +fn emit_error(sp: option::t<span>, msg: str, cm: codemap) { emit_diagnostic(sp, msg, "error", 9u8, cm); } -fn emit_note(sp: &option::t<span>, msg: &str, cm: &codemap) { +fn emit_note(sp: option::t<span>, msg: str, cm: codemap) { emit_diagnostic(sp, msg, "note", 10u8, cm); } @@ -210,7 +210,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { ret @{name: lo.filename, lines: lines}; } -fn get_line(fm: filemap, line: int, file: &str) -> str { +fn get_line(fm: filemap, line: int, file: str) -> str { let begin: uint = fm.lines[line].byte - fm.start_pos.byte; let end: uint; if line as uint < vec::len(fm.lines) - 1u { diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 298f90237bc..a77376edd6e 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -8,10 +8,10 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> @ast::expr; + fn(ext_ctxt, span, @ast::expr, option::t<str>) -> @ast::expr; type macro_def = {ident: str, ext: syntax_extension}; type macro_definer = - fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> macro_def; + fn(ext_ctxt, span, @ast::expr, option::t<str>) -> macro_def; tag syntax_extension { normal(syntax_expander); @@ -83,7 +83,7 @@ obj ext_ctxt(sess: @session, } -fn mk_ctxt(sess: &session) -> ext_ctxt { +fn mk_ctxt(sess: session) -> ext_ctxt { // FIXME: Some extensions work by building ASTs with paths to functions // they need to call at runtime. As those functions live in the std crate, // the paths are prefixed with "std::". Unfortunately, these paths can't @@ -96,7 +96,7 @@ fn mk_ctxt(sess: &session) -> ext_ctxt { ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none); } -fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str { +fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: str) -> str { alt expr.node { ast::expr_lit(l) { alt l.node { @@ -108,7 +108,7 @@ fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str { } } -fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident { +fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: str) -> ast::ident { alt expr.node { ast::expr_path(p) { if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { @@ -119,7 +119,7 @@ fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident { } } -fn make_new_lit(cx: &ext_ctxt, sp: codemap::span, lit: ast::lit_) -> +fn make_new_lit(cx: ext_ctxt, sp: codemap::span, lit: ast::lit_) -> @ast::expr { let sp_lit = @{node: lit, span: sp}; ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 53ee6cb0397..b2f019f233d 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -2,8 +2,8 @@ import std::option; import base::*; import syntax::ast; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 081bfd80c1d..2889487a6ae 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -11,8 +11,8 @@ import std::generic_os; import base::*; export expand_syntax_ext; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -33,7 +33,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, } } -fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: &str) -> @ast::expr { +fn make_new_str(cx: ext_ctxt, sp: codemap::span, s: str) -> @ast::expr { ret make_new_lit(cx, sp, ast::lit_str(s)); } // diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index 7037139bd93..05128fdd62b 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -15,9 +15,8 @@ import syntax::fold::*; import syntax::ext::base::*; -fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, - e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_) - -> expr_ { +fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt, e: expr_, + fld: ast_fold, orig: fn(expr_, ast_fold) -> expr_) -> expr_ { ret alt e { expr_mac(mac) { alt mac.node { @@ -53,7 +52,7 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, }; } -fn expand_crate(sess: &session::session, c: &@crate) -> @crate { +fn expand_crate(sess: session::session, c: @crate) -> @crate { let exts = syntax_expander_table(); let afp = default_ast_fold(); let cx: ext_ctxt = mk_ctxt(sess); diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index aef3cc46902..43a2cd03ec3 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -15,8 +15,8 @@ import base::*; import codemap::span; export expand_syntax_ext; -fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -33,7 +33,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, let fmtspan = args[0].span; log "Format string:"; log fmt; - fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: &str) -> ! { + fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: str) -> ! { cx.span_fatal(sp, msg); } let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _); @@ -44,49 +44,49 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, // FIXME: A lot of these functions for producing expressions can probably // be factored out in common with other code that builds expressions. // FIXME: Cleanup the naming of these functions -fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], - args: &[@ast::expr]) -> @ast::expr { - fn make_new_lit(cx: &ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { +fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr]) + -> @ast::expr { + fn make_new_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { let sp_lit = @{node: lit, span: sp}; ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; } - fn make_new_str(cx: &ext_ctxt, sp: span, s: &str) -> @ast::expr { + fn make_new_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr { let lit = ast::lit_str(s); ret make_new_lit(cx, sp, lit); } - fn make_new_int(cx: &ext_ctxt, sp: span, i: int) -> @ast::expr { + fn make_new_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr { let lit = ast::lit_int(i); ret make_new_lit(cx, sp, lit); } - fn make_new_uint(cx: &ext_ctxt, sp: span, u: uint) -> @ast::expr { + fn make_new_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr { let lit = ast::lit_uint(u); ret make_new_lit(cx, sp, lit); } - fn make_add_expr(cx: &ext_ctxt, sp: span, lhs: @ast::expr, - rhs: @ast::expr) -> @ast::expr { + fn make_add_expr(cx: ext_ctxt, sp: span, lhs: @ast::expr, rhs: @ast::expr) + -> @ast::expr { let binexpr = ast::expr_binary(ast::add, lhs, rhs); ret @{id: cx.next_id(), node: binexpr, span: sp}; } - fn make_path_expr(cx: &ext_ctxt, sp: span, idents: &[ast::ident]) -> + fn make_path_expr(cx: ext_ctxt, sp: span, idents: [ast::ident]) -> @ast::expr { let path = {global: false, idents: idents, types: []}; let sp_path = {node: path, span: sp}; let pathexpr = ast::expr_path(sp_path); ret @{id: cx.next_id(), node: pathexpr, span: sp}; } - fn make_vec_expr(cx: &ext_ctxt, sp: span, exprs: &[@ast::expr]) -> + fn make_vec_expr(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) -> @ast::expr { let vecexpr = ast::expr_vec(exprs, ast::imm); ret @{id: cx.next_id(), node: vecexpr, span: sp}; } - fn make_call(cx: &ext_ctxt, sp: span, fn_path: &[ast::ident], - args: &[@ast::expr]) -> @ast::expr { + fn make_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident], + args: [@ast::expr]) -> @ast::expr { let pathexpr = make_path_expr(cx, sp, fn_path); let callexpr = ast::expr_call(pathexpr, args); ret @{id: cx.next_id(), node: callexpr, span: sp}; } - fn make_rec_expr(cx: &ext_ctxt, sp: span, - fields: &[{ident: ast::ident, ex: @ast::expr}]) -> + fn make_rec_expr(cx: ext_ctxt, sp: span, + fields: [{ident: ast::ident, ex: @ast::expr}]) -> @ast::expr { let astfields: [ast::field] = []; for field: {ident: ast::ident, ex: @ast::expr} in fields { @@ -99,23 +99,23 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>); ret @{id: cx.next_id(), node: recexpr, span: sp}; } - fn make_path_vec(cx: &ext_ctxt, ident: &ast::ident) -> [ast::ident] { - fn compiling_std(cx: &ext_ctxt) -> bool { + fn make_path_vec(cx: ext_ctxt, ident: ast::ident) -> [ast::ident] { + fn compiling_std(cx: ext_ctxt) -> bool { ret str::find(cx.crate_file_name(), "std.rc") >= 0; } if compiling_std(cx) { ret ["extfmt", "rt", ident]; } else { ret ["std", "extfmt", "rt", ident]; } } - fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: &str) -> @ast::expr { + fn make_rt_path_expr(cx: ext_ctxt, sp: span, ident: str) -> @ast::expr { let path = make_path_vec(cx, ident); ret make_path_expr(cx, sp, path); } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion - fn make_rt_conv_expr(cx: &ext_ctxt, sp: span, cnv: &conv) -> @ast::expr { - fn make_flags(cx: &ext_ctxt, sp: span, flags: &[flag]) -> @ast::expr { + fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @ast::expr { + fn make_flags(cx: ext_ctxt, sp: span, flags: [flag]) -> @ast::expr { let flagexprs: [@ast::expr] = []; for f: flag in flags { let fstr; @@ -137,7 +137,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } ret make_vec_expr(cx, sp, flagexprs); } - fn make_count(cx: &ext_ctxt, sp: span, cnt: &count) -> @ast::expr { + fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr { alt cnt { count_implied. { ret make_rt_path_expr(cx, sp, "count_implied"); @@ -151,7 +151,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], _ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); } } } - fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr { + fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr { let rt_type; alt t { ty_hex(c) { @@ -166,7 +166,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } ret make_rt_path_expr(cx, sp, rt_type); } - fn make_conv_rec(cx: &ext_ctxt, sp: span, flags_expr: @ast::expr, + fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { ret make_rec_expr(cx, sp, @@ -182,7 +182,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width, rt_conv_precision, rt_conv_ty); } - fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: &str, cnv: &conv, + fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: str, cnv: conv, arg: @ast::expr) -> @ast::expr { let fname = "conv_" + conv_type; let path = make_path_vec(cx, fname); @@ -190,7 +190,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let args = [cnv_expr, arg]; ret make_call(cx, arg.span, path, args); } - fn make_new_conv(cx: &ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) -> + fn make_new_conv(cx: ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) -> @ast::expr { // FIXME: Extract all this validation into extfmt::ct @@ -334,10 +334,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let expected_nargs = n + 1u; // n conversions + the fmt string if expected_nargs < nargs { - cx.span_fatal( - sp, - #fmt["too many arguments to #fmt. found %u, expected %u", - nargs, expected_nargs]); + cx.span_fatal(sp, + #fmt["too many arguments to #fmt. found %u, expected %u", + nargs, expected_nargs]); } ret tmp_expr; } diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index 1cf015fcaf0..382e1ec3056 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -4,8 +4,8 @@ import std::option; import base::*; import syntax::ast; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index 50e7e307bdc..8f28e3b6c76 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -3,8 +3,8 @@ import base::*; import syntax::ast; import std::str; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { cx.print_backtrace(); std::io::stdout().write_line(print::pprust::expr_to_str(arg)); diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 4e76ec0d787..dc3b40645c2 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -33,7 +33,7 @@ import ast::mac_invoc; export add_new_extension; -fn path_to_ident(pth: &path) -> option::t<ident> { +fn path_to_ident(pth: path) -> option::t<ident> { if vec::len(pth.node.idents) == 1u && vec::len(pth.node.types) == 0u { ret some(pth.node.idents[0u]); } @@ -57,7 +57,7 @@ tag matchable { } /* for when given an incompatible bit of AST */ -fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! { +fn match_error(cx: ext_ctxt, m: matchable, expected: str) -> ! { alt m { match_expr(x) { cx.span_fatal(x.span, @@ -90,9 +90,9 @@ fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! { // we'll want to return something indicating amount of progress and location // of failure instead of `none`. type match_result = option::t<arb_depth<matchable>>; -type selector = fn(&matchable) -> match_result; +type selector = fn(matchable) -> match_result; -fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) -> +fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) -> {pre: [@expr], rep: option::t<@expr>, post: [@expr]} { let idx: uint = 0u; let res = none; @@ -122,7 +122,7 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) -> } } -fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) -> +fn option_flatten_map<T, U>(f: fn(T) -> option::t<U>, v: [T]) -> option::t<[U]> { let res = []; for elem: T in v { @@ -131,7 +131,7 @@ fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) -> ret some(res); } -fn a_d_map(ad: &arb_depth<matchable>, f: &selector) -> match_result { +fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result { alt ad { leaf(x) { ret f(x); } seq(ads, span) { @@ -144,7 +144,7 @@ fn a_d_map(ad: &arb_depth<matchable>, f: &selector) -> match_result { } fn compose_sels(s1: selector, s2: selector) -> selector { - fn scomp(s1: selector, s2: selector, m: &matchable) -> match_result { + fn scomp(s1: selector, s2: selector, m: matchable) -> match_result { ret alt s1(m) { none. { none } some(matches) { a_d_map(matches, s2) } @@ -160,19 +160,19 @@ type binders = mutable literal_ast_matchers: [selector]}; type bindings = hashmap<ident, arb_depth<matchable>>; -fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { } +fn acumm_bindings(_cx: ext_ctxt, _b_dest: bindings, _b_src: bindings) { } /* these three functions are the big moving parts */ /* create the selectors needed to bind and verify the pattern */ -fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders { +fn pattern_to_selectors(cx: ext_ctxt, e: @expr) -> binders { let res: binders = {real_binders: new_str_hash::<selector>(), mutable literal_ast_matchers: []}; //this oughta return binders instead, but macro args are a sequence of //expressions, rather than a single expression - fn trivial_selector(m: &matchable) -> match_result { ret some(leaf(m)); } + fn trivial_selector(m: matchable) -> match_result { ret some(leaf(m)); } p_t_s_rec(cx, match_expr(e), trivial_selector, res); ret res; } @@ -183,7 +183,7 @@ fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders { bindings. Most of the work is done in p_t_s, which generates the selectors. */ -fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { +fn use_selectors_to_bind(b: binders, e: @expr) -> option::t<bindings> { let res = new_str_hash::<arb_depth<matchable>>(); //need to do this first, to check vec lengths. for sel: selector in b.literal_ast_matchers { @@ -203,10 +203,10 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { /* use the bindings on the body to generate the expanded code */ -fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr { +fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr { let idx_path: @mutable [uint] = @mutable []; - fn new_id(_old: node_id, cx: &ext_ctxt) -> node_id { ret cx.next_id(); } - fn new_span(cx: &ext_ctxt, sp: &span) -> span { + fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { ret cx.next_id(); } + fn new_span(cx: ext_ctxt, sp: span) -> span { /* this discards information in the case of macro-defining macros */ ret {lo: sp.lo, hi: sp.hi, expanded_from: cx.backtrace()}; } @@ -231,7 +231,7 @@ fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr { /* helper: descend into a matcher */ -fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) -> +fn follow(m: arb_depth<matchable>, idx_path: @mutable [uint]) -> arb_depth<matchable> { let res: arb_depth<matchable> = m; for idx: uint in *idx_path { @@ -243,7 +243,7 @@ fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) -> ret res; } -fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>, +fn follow_for_trans(cx: ext_ctxt, mmaybe: option::t<arb_depth<matchable>>, idx_path: @mutable [uint]) -> option::t<matchable> { alt mmaybe { none. { ret none } @@ -262,10 +262,10 @@ fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>, } /* helper for transcribe_exprs: what vars from `b` occur in `e`? */ -iter free_vars(b: &bindings, e: @expr) -> ident { +iter free_vars(b: bindings, e: @expr) -> ident { let idents: hashmap<ident, ()> = new_str_hash::<()>(); - fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings, - idents: &hashmap<ident, ()>) -> ident { + fn mark_ident(i: ident, _fld: ast_fold, b: bindings, + idents: hashmap<ident, ()>) -> ident { if b.contains_key(i) { idents.insert(i, ()); } ret i; } @@ -282,8 +282,8 @@ iter free_vars(b: &bindings, e: @expr) -> ident { /* handle sequences (anywhere in the AST) of exprs, either real or ...ed */ -fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - recur: fn(&@expr) -> @expr, exprs: [@expr]) -> [@expr] { +fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + recur: fn(@expr) -> @expr, exprs: [@expr]) -> [@expr] { alt elts_to_ell(cx, exprs) { {pre: pre, rep: repeat_me_maybe, post: post} { let res = vec::map(recur, pre); @@ -344,8 +344,8 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], // substitute, in a position that's required to be an ident -fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - i: &ident, _fld: ast_fold) -> ident { +fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + i: ident, _fld: ast_fold) -> ident { ret alt follow_for_trans(cx, b.find(i), idx_path) { some(match_ident(a_id)) { a_id.node } some(m) { match_error(cx, m, "an identifier") } @@ -354,8 +354,8 @@ fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } -fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - p: &path_, _fld: ast_fold) -> path_ { +fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + p: path_, _fld: ast_fold) -> path_ { // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; } ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { @@ -369,9 +369,9 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } -fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - e: &ast::expr_, fld: ast_fold, - orig: fn(&ast::expr_, ast_fold) -> ast::expr_) -> +fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + e: ast::expr_, fld: ast_fold, + orig: fn(ast::expr_, ast_fold) -> ast::expr_) -> ast::expr_ { ret alt e { expr_path(p) { @@ -396,9 +396,9 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } } -fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - t: &ast::ty_, fld: ast_fold, - orig: fn(&ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ { +fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + t: ast::ty_, fld: ast_fold, + orig: fn(ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ { ret alt t { ast::ty_path(pth, _) { alt path_to_ident(pth) { @@ -420,9 +420,9 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], /* for parsing reasons, syntax variables bound to blocks must be used like `{v}` */ -fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - blk: &blk_, fld: ast_fold, - orig: fn(&blk_, ast_fold) -> blk_) -> blk_ { +fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + blk: blk_, fld: ast_fold, + orig: fn(blk_, ast_fold) -> blk_) -> blk_ { ret alt block_to_ident(blk) { some(id) { alt follow_for_trans(cx, b.find(id), idx_path) { @@ -430,6 +430,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], + // possibly allow promotion of ident/path/expr to blocks? some(m) { match_error(cx, m, "a block") @@ -444,7 +445,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], /* traverse the pattern, building instructions on how to bind the actual argument. ps accumulates instructions on navigating the tree.*/ -fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { +fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { //it might be possible to traverse only exprs, not matchables alt m { @@ -478,12 +479,13 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { + /* TODO: handle embedded types and blocks, at least */ expr_mac(mac) { p_t_s_r_mac(cx, mac, s, b); } _ { - fn select(cx: &ext_ctxt, m: &matchable, pat: @expr) -> + fn select(cx: ext_ctxt, m: matchable, pat: @expr) -> match_result { ret alt m { match_expr(e) { @@ -501,7 +503,7 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { /* make a match more precise */ -fn specialize_match(m: &matchable) -> matchable { +fn specialize_match(m: matchable) -> matchable { ret alt m { match_expr(e) { alt e.node { @@ -519,10 +521,10 @@ fn specialize_match(m: &matchable) -> matchable { } /* pattern_to_selectors helper functions */ -fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) { +fn p_t_s_r_path(cx: ext_ctxt, p: path, s: selector, b: binders) { alt path_to_ident(p) { some(p_id) { - fn select(cx: &ext_ctxt, m: &matchable) -> match_result { + fn select(cx: ext_ctxt, m: matchable) -> match_result { ret alt m { match_expr(e) { some(leaf(specialize_match(m))) } _ { cx.bug("broken traversal in p_t_s_r") } @@ -537,7 +539,7 @@ fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) { } } -fn block_to_ident(blk: &blk_) -> option::t<ident> { +fn block_to_ident(blk: blk_) -> option::t<ident> { if vec::len(blk.stmts) != 0u { ret none; } ret alt blk.expr { some(expr) { @@ -547,9 +549,9 @@ fn block_to_ident(blk: &blk_) -> option::t<ident> { } } -fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { - fn select_pt_1(cx: &ext_ctxt, m: &matchable, - fn_m: fn(&ast::mac) -> match_result) -> match_result { +fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) { + fn select_pt_1(cx: ext_ctxt, m: matchable, + fn_m: fn(ast::mac) -> match_result) -> match_result { ret alt m { match_expr(e) { alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } @@ -557,7 +559,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { _ { cx.bug("broken traversal in p_t_s_r") } } } - fn no_des(cx: &ext_ctxt, sp: &span, syn: &str) -> ! { + fn no_des(cx: ext_ctxt, sp: span, syn: str) -> ! { cx.span_fatal(sp, "destructuring " + syn + " is not yet supported"); } alt mac.node { @@ -569,7 +571,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { alt path_to_ident(pth) { some(id) { /* look for an embedded type */ - fn select_pt_2(m: &ast::mac) -> match_result { + fn select_pt_2(m: ast::mac) -> match_result { ret alt m.node { ast::mac_embed_type(t) { some(leaf(match_ty(t))) } _ { none } @@ -587,7 +589,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { ast::mac_embed_block(blk) { alt block_to_ident(blk.node) { some(id) { - fn select_pt_2(m: &ast::mac) -> match_result { + fn select_pt_2(m: ast::mac) -> match_result { ret alt m.node { ast::mac_embed_block(blk) { some(leaf(match_block(blk))) @@ -604,9 +606,9 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { } } -fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, - s: &selector, b: &binders) { - fn select(cx: &ext_ctxt, repeat_me: @expr, offset: uint, m: &matchable) -> +fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, + b: binders) { + fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) -> match_result { ret alt m { match_expr(e) { @@ -634,9 +636,9 @@ fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, } -fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector, - b: &binders) { - fn len_select(_cx: &ext_ctxt, m: &matchable, at_least: bool, len: uint) -> +fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector, + b: binders) { + fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) -> match_result { ret alt m { match_expr(e) { @@ -657,11 +659,11 @@ fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector, [compose_sels(s, bind len_select(cx, _, at_least, len))]; } -fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, - s: &selector, b: &binders) { +fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: [@expr], _repeat_after: bool, + s: selector, b: binders) { let idx: uint = 0u; while idx < vec::len(elts) { - fn select(cx: &ext_ctxt, m: &matchable, idx: uint) -> match_result { + fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result { ret alt m { match_expr(e) { alt e.node { @@ -680,8 +682,8 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, } } -fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: &option::t<str>) -> base::macro_def { +fn add_new_extension(cx: ext_ctxt, sp: span, arg: @expr, + _body: option::t<str>) -> base::macro_def { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -760,9 +762,8 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, }, ext: normal(ext)}; - fn generic_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: &option::t<str>, clauses: [@clause]) -> - @expr { + fn generic_extension(cx: ext_ctxt, sp: span, arg: @expr, + _body: option::t<str>, clauses: [@clause]) -> @expr { for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { some(bindings) { ret transcribe(cx, bindings, c.body) } diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 899d940b390..0a628214eda 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -21,92 +21,91 @@ type ast_fold = @mutable a_f; type ast_fold_precursor = //unlike the others, item_ is non-trivial - {fold_crate: fn(&crate_, ast_fold) -> crate_, - fold_crate_directive: - fn(&crate_directive_, ast_fold) -> crate_directive_, - fold_view_item: fn(&view_item_, ast_fold) -> view_item_, - fold_native_item: fn(&@native_item, ast_fold) -> @native_item, - fold_item: fn(&@item, ast_fold) -> @item, - fold_item_underscore: fn(&item_, ast_fold) -> item_, - fold_method: fn(&method_, ast_fold) -> method_, - fold_block: fn(&blk_, ast_fold) -> blk_, - fold_stmt: fn(&stmt_, ast_fold) -> stmt_, - fold_arm: fn(&arm, ast_fold) -> arm, - fold_pat: fn(&pat_, ast_fold) -> pat_, - fold_decl: fn(&decl_, ast_fold) -> decl_, - fold_expr: fn(&expr_, ast_fold) -> expr_, - fold_ty: fn(&ty_, ast_fold) -> ty_, - fold_constr: fn(&ast::constr_, ast_fold) -> constr_, - fold_fn: fn(&_fn, ast_fold) -> _fn, - fold_mod: fn(&_mod, ast_fold) -> _mod, - fold_native_mod: fn(&native_mod, ast_fold) -> native_mod, - fold_variant: fn(&variant_, ast_fold) -> variant_, - fold_ident: fn(&ident, ast_fold) -> ident, - fold_path: fn(&path_, ast_fold) -> path_, - fold_local: fn(&local_, ast_fold) -> local_, - map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr], + {fold_crate: fn(crate_, ast_fold) -> crate_, + fold_crate_directive: fn(crate_directive_, ast_fold) -> crate_directive_, + fold_view_item: fn(view_item_, ast_fold) -> view_item_, + fold_native_item: fn(@native_item, ast_fold) -> @native_item, + fold_item: fn(@item, ast_fold) -> @item, + fold_item_underscore: fn(item_, ast_fold) -> item_, + fold_method: fn(method_, ast_fold) -> method_, + fold_block: fn(blk_, ast_fold) -> blk_, + fold_stmt: fn(stmt_, ast_fold) -> stmt_, + fold_arm: fn(arm, ast_fold) -> arm, + fold_pat: fn(pat_, ast_fold) -> pat_, + fold_decl: fn(decl_, ast_fold) -> decl_, + fold_expr: fn(expr_, ast_fold) -> expr_, + fold_ty: fn(ty_, ast_fold) -> ty_, + fold_constr: fn(ast::constr_, ast_fold) -> constr_, + fold_fn: fn(_fn, ast_fold) -> _fn, + fold_mod: fn(_mod, ast_fold) -> _mod, + fold_native_mod: fn(native_mod, ast_fold) -> native_mod, + fold_variant: fn(variant_, ast_fold) -> variant_, + fold_ident: fn(ident, ast_fold) -> ident, + fold_path: fn(path_, ast_fold) -> path_, + fold_local: fn(local_, ast_fold) -> local_, + map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr], new_id: fn(node_id) -> node_id, - new_span: fn(&span) -> span}; + new_span: fn(span) -> span}; type a_f = - {fold_crate: fn(&crate) -> crate, - fold_crate_directive: fn(&@crate_directive) -> @crate_directive, - fold_view_item: fn(&@view_item) -> @view_item, - fold_native_item: fn(&@native_item) -> @native_item, - fold_item: fn(&@item) -> @item, - fold_item_underscore: fn(&item_) -> item_, - fold_method: fn(&@method) -> @method, - fold_block: fn(&blk) -> blk, - fold_stmt: fn(&@stmt) -> @stmt, - fold_arm: fn(&arm) -> arm, - fold_pat: fn(&@pat) -> @pat, - fold_decl: fn(&@decl) -> @decl, - fold_expr: fn(&@expr) -> @expr, - fold_ty: fn(&@ty) -> @ty, - fold_constr: fn(&@constr) -> @constr, - fold_fn: fn(&_fn) -> _fn, - fold_mod: fn(&_mod) -> _mod, - fold_native_mod: fn(&native_mod) -> native_mod, - fold_variant: fn(&variant) -> variant, - fold_ident: fn(&ident) -> ident, - fold_path: fn(&path) -> path, - fold_local: fn(&@local) -> @local, - map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr], + {fold_crate: fn(crate) -> crate, + fold_crate_directive: fn(@crate_directive) -> @crate_directive, + fold_view_item: fn(@view_item) -> @view_item, + fold_native_item: fn(@native_item) -> @native_item, + fold_item: fn(@item) -> @item, + fold_item_underscore: fn(item_) -> item_, + fold_method: fn(@method) -> @method, + fold_block: fn(blk) -> blk, + fold_stmt: fn(@stmt) -> @stmt, + fold_arm: fn(arm) -> arm, + fold_pat: fn(@pat) -> @pat, + fold_decl: fn(@decl) -> @decl, + fold_expr: fn(@expr) -> @expr, + fold_ty: fn(@ty) -> @ty, + fold_constr: fn(@constr) -> @constr, + fold_fn: fn(_fn) -> _fn, + fold_mod: fn(_mod) -> _mod, + fold_native_mod: fn(native_mod) -> native_mod, + fold_variant: fn(variant) -> variant, + fold_ident: fn(ident) -> ident, + fold_path: fn(path) -> path, + fold_local: fn(@local) -> @local, + map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr], new_id: fn(node_id) -> node_id, - new_span: fn(&span) -> span}; + new_span: fn(span) -> span}; //fn nf_dummy<T>(&T node) -> T { fail; } -fn nf_crate_dummy(_c: &crate) -> crate { fail; } -fn nf_crate_directive_dummy(_c: &@crate_directive) -> @crate_directive { +fn nf_crate_dummy(_c: crate) -> crate { fail; } +fn nf_crate_directive_dummy(_c: @crate_directive) -> @crate_directive { fail; } -fn nf_view_item_dummy(_v: &@view_item) -> @view_item { fail; } -fn nf_native_item_dummy(_n: &@native_item) -> @native_item { fail; } -fn nf_item_dummy(_i: &@item) -> @item { fail; } -fn nf_item_underscore_dummy(_i: &item_) -> item_ { fail; } -fn nf_method_dummy(_m: &@method) -> @method { fail; } -fn nf_blk_dummy(_b: &blk) -> blk { fail; } -fn nf_stmt_dummy(_s: &@stmt) -> @stmt { fail; } -fn nf_arm_dummy(_a: &arm) -> arm { fail; } -fn nf_pat_dummy(_p: &@pat) -> @pat { fail; } -fn nf_decl_dummy(_d: &@decl) -> @decl { fail; } -fn nf_expr_dummy(_e: &@expr) -> @expr { fail; } -fn nf_ty_dummy(_t: &@ty) -> @ty { fail; } -fn nf_constr_dummy(_c: &@constr) -> @constr { fail; } -fn nf_fn_dummy(_f: &_fn) -> _fn { fail; } -fn nf_mod_dummy(_m: &_mod) -> _mod { fail; } -fn nf_native_mod_dummy(_n: &native_mod) -> native_mod { fail; } -fn nf_variant_dummy(_v: &variant) -> variant { fail; } -fn nf_ident_dummy(_i: &ident) -> ident { fail; } -fn nf_path_dummy(_p: &path) -> path { fail; } -fn nf_obj_field_dummy(_o: &obj_field) -> obj_field { fail; } -fn nf_local_dummy(_o: &@local) -> @local { fail; } +fn nf_view_item_dummy(_v: @view_item) -> @view_item { fail; } +fn nf_native_item_dummy(_n: @native_item) -> @native_item { fail; } +fn nf_item_dummy(_i: @item) -> @item { fail; } +fn nf_item_underscore_dummy(_i: item_) -> item_ { fail; } +fn nf_method_dummy(_m: @method) -> @method { fail; } +fn nf_blk_dummy(_b: blk) -> blk { fail; } +fn nf_stmt_dummy(_s: @stmt) -> @stmt { fail; } +fn nf_arm_dummy(_a: arm) -> arm { fail; } +fn nf_pat_dummy(_p: @pat) -> @pat { fail; } +fn nf_decl_dummy(_d: @decl) -> @decl { fail; } +fn nf_expr_dummy(_e: @expr) -> @expr { fail; } +fn nf_ty_dummy(_t: @ty) -> @ty { fail; } +fn nf_constr_dummy(_c: @constr) -> @constr { fail; } +fn nf_fn_dummy(_f: _fn) -> _fn { fail; } +fn nf_mod_dummy(_m: _mod) -> _mod { fail; } +fn nf_native_mod_dummy(_n: native_mod) -> native_mod { fail; } +fn nf_variant_dummy(_v: variant) -> variant { fail; } +fn nf_ident_dummy(_i: ident) -> ident { fail; } +fn nf_path_dummy(_p: path) -> path { fail; } +fn nf_obj_field_dummy(_o: obj_field) -> obj_field { fail; } +fn nf_local_dummy(_o: @local) -> @local { fail; } /* some little folds that probably aren't useful to have in ast_fold itself*/ //used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive -fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item { +fn fold_meta_item_(mi: @meta_item, fld: ast_fold) -> @meta_item { ret @{node: alt mi.node { meta_word(id) { meta_word(fld.fold_ident(id)) } @@ -121,20 +120,20 @@ fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item { span: mi.span}; } //used in noop_fold_item and noop_fold_crate -fn fold_attribute_(at: &attribute, fmi: fn(&@meta_item) -> @meta_item) -> +fn fold_attribute_(at: attribute, fmi: fn(@meta_item) -> @meta_item) -> attribute { ret {node: {style: at.node.style, value: *fmi(@at.node.value)}, span: at.span}; } //used in noop_fold_native_item and noop_fold_fn -fn fold_arg_(a: &arg, fld: ast_fold) -> arg { +fn fold_arg_(a: arg, fld: ast_fold) -> arg { ret {mode: a.mode, ty: fld.fold_ty(a.ty), ident: fld.fold_ident(a.ident), id: a.id}; } //used in noop_fold_expr, and possibly elsewhere in the future -fn fold_mac_(m: &mac, fld: ast_fold) -> mac { +fn fold_mac_(m: mac, fld: ast_fold) -> mac { ret {node: alt m.node { mac_invoc(pth, arg, body) { @@ -151,7 +150,7 @@ fn fold_mac_(m: &mac, fld: ast_fold) -> mac { -fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ { +fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ { let fold_meta_item = bind fold_meta_item_(_, fld); let fold_attribute = bind fold_attribute_(_, fold_meta_item); @@ -161,7 +160,7 @@ fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ { config: vec::map(fold_meta_item, c.config)}; } -fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) -> +fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) -> crate_directive_ { ret alt cd { cdir_src_mod(id, fname, attrs) { @@ -177,12 +176,12 @@ fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) -> } } -fn noop_fold_view_item(vi: &view_item_, _fld: ast_fold) -> view_item_ { +fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ { ret vi; } -fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item { +fn noop_fold_native_item(ni: @native_item, fld: ast_fold) -> @native_item { let fold_arg = bind fold_arg_(_, fld); let fold_meta_item = bind fold_meta_item_(_, fld); let fold_attribute = bind fold_attribute_(_, fold_meta_item); @@ -208,7 +207,7 @@ fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item { span: ni.span}; } -fn noop_fold_item(i: &@item, fld: ast_fold) -> @item { +fn noop_fold_item(i: @item, fld: ast_fold) -> @item { let fold_meta_item = bind fold_meta_item_(_, fld); let fold_attribute = bind fold_attribute_(_, fold_meta_item); @@ -219,8 +218,8 @@ fn noop_fold_item(i: &@item, fld: ast_fold) -> @item { span: i.span}; } -fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { - fn fold_obj_field_(of: &obj_field, fld: ast_fold) -> obj_field { +fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { + fn fold_obj_field_(of: obj_field, fld: ast_fold) -> obj_field { ret {mut: of.mut, ty: fld.fold_ty(of.ty), ident: fld.fold_ident(of.ident), @@ -248,19 +247,19 @@ fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { }; } -fn noop_fold_method(m: &method_, fld: ast_fold) -> method_ { +fn noop_fold_method(m: method_, fld: ast_fold) -> method_ { ret {ident: fld.fold_ident(m.ident), meth: fld.fold_fn(m.meth), id: m.id}; } -fn noop_fold_block(b: &blk_, fld: ast_fold) -> blk_ { +fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ { ret {stmts: vec::map(fld.fold_stmt, b.stmts), expr: option::map(fld.fold_expr, b.expr), id: b.id, rules: b.rules}; } -fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ { +fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { ret alt s { stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) } stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) } @@ -270,13 +269,13 @@ fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ { }; } -fn noop_fold_arm(a: &arm, fld: ast_fold) -> arm { +fn noop_fold_arm(a: arm, fld: ast_fold) -> arm { ret {pats: vec::map(fld.fold_pat, a.pats), guard: option::map(fld.fold_expr, a.guard), body: fld.fold_block(a.body)}; } -fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { +fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { ret alt p { pat_wild. { p } pat_bind(ident) { pat_bind(fld.fold_ident(ident)) } @@ -296,15 +295,15 @@ fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { }; } -fn noop_fold_decl(d: &decl_, fld: ast_fold) -> decl_ { +fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ { ret alt d { decl_local(ls) { decl_local(vec::map(fld.fold_local, ls)) } decl_item(it) { decl_item(fld.fold_item(it)) } } } -fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { - fn fold_field_(field: &field, fld: ast_fold) -> field { +fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { + fn fold_field_(field: field, fld: ast_fold) -> field { ret {node: {mut: field.node.mut, ident: fld.fold_ident(field.node.ident), @@ -312,8 +311,8 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { span: field.span}; } let fold_field = bind fold_field_(_, fld); - fn fold_anon_obj_(ao: &anon_obj, fld: ast_fold) -> anon_obj { - fn fold_anon_obj_field_(aof: &anon_obj_field, fld: ast_fold) -> + fn fold_anon_obj_(ao: anon_obj, fld: ast_fold) -> anon_obj { + fn fold_anon_obj_field_(aof: anon_obj_field, fld: ast_fold) -> anon_obj_field { ret {mut: aof.mut, ty: fld.fold_ty(aof.ty), @@ -427,17 +426,17 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { } } -fn noop_fold_ty(t: &ty_, _fld: ast_fold) -> ty_ { +fn noop_fold_ty(t: ty_, _fld: ast_fold) -> ty_ { //drop in ty::fold_ty here if necessary ret t; } -fn noop_fold_constr(c: &constr_, fld: ast_fold) -> constr_ { +fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ { {path: fld.fold_path(c.path), args: c.args, id: c.id} } // functions just don't get spans, for some reason -fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn { +fn noop_fold_fn(f: _fn, fld: ast_fold) -> _fn { let fold_arg = bind fold_arg_(_, fld); ret {decl: @@ -452,35 +451,35 @@ fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn { } // ...nor do modules -fn noop_fold_mod(m: &_mod, fld: ast_fold) -> _mod { +fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod { ret {view_items: vec::map(fld.fold_view_item, m.view_items), items: vec::map(fld.fold_item, m.items)}; } -fn noop_fold_native_mod(nm: &native_mod, fld: ast_fold) -> native_mod { +fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod { ret {native_name: nm.native_name, abi: nm.abi, view_items: vec::map(fld.fold_view_item, nm.view_items), items: vec::map(fld.fold_native_item, nm.items)} } -fn noop_fold_variant(v: &variant_, fld: ast_fold) -> variant_ { - fn fold_variant_arg_(va: &variant_arg, fld: ast_fold) -> variant_arg { +fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { + fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg { ret {ty: fld.fold_ty(va.ty), id: va.id}; } let fold_variant_arg = bind fold_variant_arg_(_, fld); ret {name: v.name, args: vec::map(fold_variant_arg, v.args), id: v.id}; } -fn noop_fold_ident(i: &ident, _fld: ast_fold) -> ident { ret i; } +fn noop_fold_ident(i: ident, _fld: ast_fold) -> ident { ret i; } -fn noop_fold_path(p: &path_, fld: ast_fold) -> path_ { +fn noop_fold_path(p: path_, fld: ast_fold) -> path_ { ret {global: p.global, idents: vec::map(fld.fold_ident, p.idents), types: vec::map(fld.fold_ty, p.types)}; } -fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ { +fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { ret {ty: fld.fold_ty(l.ty), pat: fld.fold_pat(l.pat), init: @@ -496,13 +495,13 @@ fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ { /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a value */ -fn noop_map_exprs(f: fn(&@expr) -> @expr, es: [@expr]) -> [@expr] { +fn noop_map_exprs(f: fn(@expr) -> @expr, es: [@expr]) -> [@expr] { ret vec::map(f, es); } fn noop_id(i: node_id) -> node_id { ret i; } -fn noop_span(sp: &span) -> span { ret sp; } +fn noop_span(sp: span) -> span { ret sp; } fn default_ast_fold() -> @ast_fold_precursor { @@ -563,7 +562,7 @@ fn dummy_out(a: ast_fold) { } -fn make_fold(afp: &ast_fold_precursor) -> ast_fold { +fn make_fold(afp: ast_fold_precursor) -> ast_fold { let result: ast_fold = @mutable {fold_crate: nf_crate_dummy, fold_crate_directive: nf_crate_directive_dummy, @@ -592,84 +591,83 @@ fn make_fold(afp: &ast_fold_precursor) -> ast_fold { new_span: noop_span}; /* naturally, a macro to write these would be nice */ - fn f_crate(afp: &ast_fold_precursor, f: ast_fold, c: &crate) -> crate { + fn f_crate(afp: ast_fold_precursor, f: ast_fold, c: crate) -> crate { ret {node: afp.fold_crate(c.node, f), span: afp.new_span(c.span)}; } - fn f_crate_directive(afp: &ast_fold_precursor, f: ast_fold, - c: &@crate_directive) -> @crate_directive { + fn f_crate_directive(afp: ast_fold_precursor, f: ast_fold, + c: @crate_directive) -> @crate_directive { ret @{node: afp.fold_crate_directive(c.node, f), span: afp.new_span(c.span)}; } - fn f_view_item(afp: &ast_fold_precursor, f: ast_fold, x: &@view_item) -> + fn f_view_item(afp: ast_fold_precursor, f: ast_fold, x: @view_item) -> @view_item { ret @{node: afp.fold_view_item(x.node, f), span: afp.new_span(x.span)}; } - fn f_native_item(afp: &ast_fold_precursor, f: ast_fold, x: &@native_item) - -> @native_item { + fn f_native_item(afp: ast_fold_precursor, f: ast_fold, x: @native_item) -> + @native_item { ret afp.fold_native_item(x, f); } - fn f_item(afp: &ast_fold_precursor, f: ast_fold, i: &@item) -> @item { + fn f_item(afp: ast_fold_precursor, f: ast_fold, i: @item) -> @item { ret afp.fold_item(i, f); } - fn f_item_underscore(afp: &ast_fold_precursor, f: ast_fold, i: &item_) -> + fn f_item_underscore(afp: ast_fold_precursor, f: ast_fold, i: item_) -> item_ { ret afp.fold_item_underscore(i, f); } - fn f_method(afp: &ast_fold_precursor, f: ast_fold, x: &@method) -> - @method { + fn f_method(afp: ast_fold_precursor, f: ast_fold, x: @method) -> @method { ret @{node: afp.fold_method(x.node, f), span: afp.new_span(x.span)}; } - fn f_block(afp: &ast_fold_precursor, f: ast_fold, x: &blk) -> blk { + fn f_block(afp: ast_fold_precursor, f: ast_fold, x: blk) -> blk { ret {node: afp.fold_block(x.node, f), span: afp.new_span(x.span)}; } - fn f_stmt(afp: &ast_fold_precursor, f: ast_fold, x: &@stmt) -> @stmt { + fn f_stmt(afp: ast_fold_precursor, f: ast_fold, x: @stmt) -> @stmt { ret @{node: afp.fold_stmt(x.node, f), span: afp.new_span(x.span)}; } - fn f_arm(afp: &ast_fold_precursor, f: ast_fold, x: &arm) -> arm { + fn f_arm(afp: ast_fold_precursor, f: ast_fold, x: arm) -> arm { ret afp.fold_arm(x, f); } - fn f_pat(afp: &ast_fold_precursor, f: ast_fold, x: &@pat) -> @pat { + fn f_pat(afp: ast_fold_precursor, f: ast_fold, x: @pat) -> @pat { ret @{id: afp.new_id(x.id), node: afp.fold_pat(x.node, f), span: afp.new_span(x.span)}; } - fn f_decl(afp: &ast_fold_precursor, f: ast_fold, x: &@decl) -> @decl { + fn f_decl(afp: ast_fold_precursor, f: ast_fold, x: @decl) -> @decl { ret @{node: afp.fold_decl(x.node, f), span: afp.new_span(x.span)}; } - fn f_expr(afp: &ast_fold_precursor, f: ast_fold, x: &@expr) -> @expr { + fn f_expr(afp: ast_fold_precursor, f: ast_fold, x: @expr) -> @expr { ret @{id: afp.new_id(x.id), node: afp.fold_expr(x.node, f), span: afp.new_span(x.span)}; } - fn f_ty(afp: &ast_fold_precursor, f: ast_fold, x: &@ty) -> @ty { + fn f_ty(afp: ast_fold_precursor, f: ast_fold, x: @ty) -> @ty { ret @{node: afp.fold_ty(x.node, f), span: afp.new_span(x.span)}; } - fn f_constr(afp: &ast_fold_precursor, f: ast_fold, x: &@ast::constr) -> + fn f_constr(afp: ast_fold_precursor, f: ast_fold, x: @ast::constr) -> @ast::constr { ret @{node: afp.fold_constr(x.node, f), span: afp.new_span(x.span)}; } - fn f_fn(afp: &ast_fold_precursor, f: ast_fold, x: &_fn) -> _fn { + fn f_fn(afp: ast_fold_precursor, f: ast_fold, x: _fn) -> _fn { ret afp.fold_fn(x, f); } - fn f_mod(afp: &ast_fold_precursor, f: ast_fold, x: &_mod) -> _mod { + fn f_mod(afp: ast_fold_precursor, f: ast_fold, x: _mod) -> _mod { ret afp.fold_mod(x, f); } - fn f_native_mod(afp: &ast_fold_precursor, f: ast_fold, x: &native_mod) -> + fn f_native_mod(afp: ast_fold_precursor, f: ast_fold, x: native_mod) -> native_mod { ret afp.fold_native_mod(x, f); } - fn f_variant(afp: &ast_fold_precursor, f: ast_fold, x: &variant) -> + fn f_variant(afp: ast_fold_precursor, f: ast_fold, x: variant) -> variant { ret {node: afp.fold_variant(x.node, f), span: afp.new_span(x.span)}; } - fn f_ident(afp: &ast_fold_precursor, f: ast_fold, x: &ident) -> ident { + fn f_ident(afp: ast_fold_precursor, f: ast_fold, x: ident) -> ident { ret afp.fold_ident(x, f); } - fn f_path(afp: &ast_fold_precursor, f: ast_fold, x: &path) -> path { + fn f_path(afp: ast_fold_precursor, f: ast_fold, x: path) -> path { ret {node: afp.fold_path(x.node, f), span: afp.new_span(x.span)}; } - fn f_local(afp: &ast_fold_precursor, f: ast_fold, x: &@local) -> @local { + fn f_local(afp: ast_fold_precursor, f: ast_fold, x: @local) -> @local { ret @{node: afp.fold_local(x.node, f), span: afp.new_span(x.span)}; } diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index 6535ecfe586..147f1b9453e 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -25,23 +25,23 @@ type ctx = mutable byte_pos: uint, cfg: ast::crate_cfg}; -fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: &str, view_items: &mutable [@ast::view_item], +fn eval_crate_directives(cx: ctx, cdirs: [@ast::crate_directive], prefix: str, + view_items: &mutable [@ast::view_item], items: &mutable [@ast::item]) { for sub_cdir: @ast::crate_directive in cdirs { eval_crate_directive(cx, sub_cdir, prefix, view_items, items); } } -fn eval_crate_directives_to_mod(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: &str) -> ast::_mod { +fn eval_crate_directives_to_mod(cx: ctx, cdirs: [@ast::crate_directive], + prefix: str) -> ast::_mod { let view_items: [@ast::view_item] = []; let items: [@ast::item] = []; eval_crate_directives(cx, cdirs, prefix, view_items, items); ret {view_items: view_items, items: items}; } -fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &str, +fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str, view_items: &mutable [@ast::view_item], items: &mutable [@ast::item]) { alt cdir.node { diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index f0d5bfeb729..c5a9eefdec2 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -25,10 +25,10 @@ type reader = fn get_byte_pos() -> uint; fn get_col() -> uint; fn get_filemap() -> codemap::filemap; - fn err(&str); + fn err(str); }; -fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap, +fn new_reader(cm: codemap::codemap, src: str, filemap: codemap::filemap, itr: @interner::interner<str>) -> reader { obj reader(cm: codemap::codemap, src: str, @@ -77,7 +77,7 @@ fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap, fn get_interner() -> @interner::interner<str> { ret itr; } fn get_col() -> uint { ret col; } fn get_filemap() -> codemap::filemap { ret fm; } - fn err(m: &str) { + fn err(m: str) { codemap::emit_error(some(ast_util::mk_sp(chpos, chpos)), m, cm); } } @@ -123,12 +123,12 @@ fn is_hex_digit(c: char) -> bool { fn is_bin_digit(c: char) -> bool { ret c == '0' || c == '1'; } -fn consume_whitespace_and_comments(rdr: &reader) { +fn consume_whitespace_and_comments(rdr: reader) { while is_whitespace(rdr.curr()) { rdr.bump(); } be consume_any_line_comment(rdr); } -fn consume_any_line_comment(rdr: &reader) { +fn consume_any_line_comment(rdr: reader) { if rdr.curr() == '/' { alt rdr.next() { '/' { @@ -143,7 +143,7 @@ fn consume_any_line_comment(rdr: &reader) { } } -fn consume_block_comment(rdr: &reader) { +fn consume_block_comment(rdr: reader) { let level: int = 1; while level > 0 { if rdr.is_eof() { rdr.err("unterminated block comment"); fail; } @@ -164,13 +164,13 @@ fn consume_block_comment(rdr: &reader) { be consume_whitespace_and_comments(rdr); } -fn digits_to_string(s: &str) -> int { +fn digits_to_string(s: str) -> int { let accum_int: int = 0; for c: u8 in s { accum_int *= 10; accum_int += dec_digit_val(c as char); } ret accum_int; } -fn scan_exponent(rdr: &reader) -> option::t<str> { +fn scan_exponent(rdr: reader) -> option::t<str> { let c = rdr.curr(); let rslt = ""; if c == 'e' || c == 'E' { @@ -188,7 +188,7 @@ fn scan_exponent(rdr: &reader) -> option::t<str> { } else { ret none::<str>; } } -fn scan_dec_digits(rdr: &reader) -> str { +fn scan_dec_digits(rdr: reader) -> str { let c = rdr.curr(); let rslt: str = ""; while is_dec_digit(c) || c == '_' { @@ -199,7 +199,7 @@ fn scan_dec_digits(rdr: &reader) -> str { ret rslt; } -fn scan_number(c: char, rdr: &reader) -> token::token { +fn scan_number(c: char, rdr: reader) -> token::token { let accum_int = 0; let dec_str: str = ""; let is_dec_integer: bool = false; @@ -312,7 +312,7 @@ fn scan_number(c: char, rdr: &reader) -> token::token { } } -fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char { +fn scan_numeric_escape(rdr: reader, n_hex_digits: uint) -> char { let accum_int = 0; while n_hex_digits != 0u { let n = rdr.curr(); @@ -328,7 +328,7 @@ fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char { ret accum_int as char; } -fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} { +fn next_token(rdr: reader) -> {tok: token::token, chpos: uint, bpos: uint} { consume_whitespace_and_comments(rdr); let start_chpos = rdr.get_chpos(); let start_bpos = rdr.get_byte_pos(); @@ -336,7 +336,7 @@ fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} { ret {tok: tok, chpos: start_chpos, bpos: start_bpos}; } -fn next_token_inner(rdr: &reader) -> token::token { +fn next_token_inner(rdr: reader) -> token::token { let accum_str = ""; let c = rdr.curr(); if is_alpha(c) || c == '_' { @@ -351,7 +351,7 @@ fn next_token_inner(rdr: &reader) -> token::token { accum_str), is_mod_name); } if is_dec_digit(c) { ret scan_number(c, rdr); } - fn binop(rdr: &reader, op: token::binop) -> token::token { + fn binop(rdr: reader, op: token::binop) -> token::token { rdr.bump(); if rdr.curr() == '=' { rdr.bump(); @@ -362,6 +362,7 @@ fn next_token_inner(rdr: &reader) -> token::token { + // One-byte tokens. '?' { rdr.bump(); @@ -402,6 +403,7 @@ fn next_token_inner(rdr: &reader) -> token::token { + // Multi-byte tokens. '=' { rdr.bump(); @@ -551,7 +553,7 @@ tag cmnt_style { type cmnt = {style: cmnt_style, lines: [str], pos: uint}; -fn read_to_eol(rdr: &reader) -> str { +fn read_to_eol(rdr: reader) -> str { let val = ""; while rdr.curr() != '\n' && !rdr.is_eof() { str::push_char(val, rdr.curr()); @@ -561,29 +563,29 @@ fn read_to_eol(rdr: &reader) -> str { ret val; } -fn read_one_line_comment(rdr: &reader) -> str { +fn read_one_line_comment(rdr: reader) -> str { let val = read_to_eol(rdr); assert (val[0] == '/' as u8 && val[1] == '/' as u8); ret val; } -fn consume_whitespace(rdr: &reader) { +fn consume_whitespace(rdr: reader) { while is_whitespace(rdr.curr()) && !rdr.is_eof() { rdr.bump(); } } -fn consume_non_eol_whitespace(rdr: &reader) { +fn consume_non_eol_whitespace(rdr: reader) { while is_whitespace(rdr.curr()) && rdr.curr() != '\n' && !rdr.is_eof() { rdr.bump(); } } -fn push_blank_line_comment(rdr: &reader, comments: &mutable [cmnt]) { +fn push_blank_line_comment(rdr: reader, comments: &mutable [cmnt]) { log ">>> blank-line comment"; let v: [str] = []; comments += [{style: blank_line, lines: v, pos: rdr.get_chpos()}]; } -fn consume_whitespace_counting_blank_lines(rdr: &reader, +fn consume_whitespace_counting_blank_lines(rdr: reader, comments: &mutable [cmnt]) { while is_whitespace(rdr.curr()) && !rdr.is_eof() { if rdr.get_col() == 0u && rdr.curr() == '\n' { @@ -593,7 +595,7 @@ fn consume_whitespace_counting_blank_lines(rdr: &reader, } } -fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { +fn read_line_comments(rdr: reader, code_to_the_left: bool) -> cmnt { log ">>> line comments"; let p = rdr.get_chpos(); let lines: [str] = []; @@ -609,13 +611,13 @@ fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { pos: p}; } -fn all_whitespace(s: &str, begin: uint, end: uint) -> bool { +fn all_whitespace(s: str, begin: uint, end: uint) -> bool { let i: uint = begin; while i != end { if !is_whitespace(s[i] as char) { ret false; } i += 1u; } ret true; } -fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str, +fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: str, col: uint) { let s1; if all_whitespace(s, 0u, col) { @@ -627,7 +629,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str, lines += [s1]; } -fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt { +fn read_block_comment(rdr: reader, code_to_the_left: bool) -> cmnt { log ">>> block comment"; let p = rdr.get_chpos(); let lines: [str] = []; @@ -672,12 +674,12 @@ fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt { ret {style: style, lines: lines, pos: p}; } -fn peeking_at_comment(rdr: &reader) -> bool { +fn peeking_at_comment(rdr: reader) -> bool { ret rdr.curr() == '/' && rdr.next() == '/' || rdr.curr() == '/' && rdr.next() == '*'; } -fn consume_comment(rdr: &reader, code_to_the_left: bool, +fn consume_comment(rdr: reader, code_to_the_left: bool, comments: &mutable [cmnt]) { log ">>> consume comment"; if rdr.curr() == '/' && rdr.next() == '/' { @@ -688,7 +690,7 @@ fn consume_comment(rdr: &reader, code_to_the_left: bool, log "<<< consume comment"; } -fn is_lit(t: &token::token) -> bool { +fn is_lit(t: token::token) -> bool { ret alt t { token::LIT_INT(_) { true } token::LIT_UINT(_) { true } @@ -704,7 +706,7 @@ fn is_lit(t: &token::token) -> bool { type lit = {lit: str, pos: uint}; -fn gather_comments_and_literals(cm: &codemap::codemap, path: &str, +fn gather_comments_and_literals(cm: codemap::codemap, path: str, srdr: io::reader) -> {cmnts: [cmnt], lits: [lit]} { let src = str::unsafe_from_bytes(srdr.read_whole_stream()); diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index a6ffde02c55..3d115197794 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -25,7 +25,7 @@ tag ty_or_bang { a_ty(@ast::ty); a_bang; } type parse_sess = @{cm: codemap::codemap, mutable next_id: node_id}; -fn next_node_id(sess: &parse_sess) -> node_id { +fn next_node_id(sess: parse_sess) -> node_id { let rv = sess.next_id; sess.next_id += 1; ret rv; @@ -37,8 +37,8 @@ type parser = fn bump(); fn swap(token::token, uint, uint); fn look_ahead(uint) -> token::token; - fn fatal(&str) -> ! ; - fn warn(&str); + fn fatal(str) -> ! ; + fn warn(str); fn restrict(restriction); fn get_restriction() -> restriction; fn get_file_type() -> file_type; @@ -59,7 +59,7 @@ type parser = fn get_sess() -> parse_sess; }; -fn new_parser_from_file(sess: parse_sess, cfg: &ast::crate_cfg, path: &str, +fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str, chpos: uint, byte_pos: uint, ftype: file_type) -> parser { let src = io::read_whole_file_str(path); @@ -70,7 +70,7 @@ fn new_parser_from_file(sess: parse_sess, cfg: &ast::crate_cfg, path: &str, ret new_parser(sess, cfg, rdr, ftype); } -fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, +fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, ftype: file_type) -> parser { obj stdio_parser(sess: parse_sess, cfg: ast::crate_cfg, @@ -108,11 +108,11 @@ fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, } ret buffer[distance - 1u].tok; } - fn fatal(m: &str) -> ! { + fn fatal(m: str) -> ! { codemap::emit_error(some(self.get_span()), m, sess.cm); fail; } - fn warn(m: &str) { + fn warn(m: str) { codemap::emit_warning(some(self.get_span()), m, sess.cm); } fn restrict(r: restriction) { restr = r; } @@ -185,13 +185,13 @@ fn bad_expr_word_table() -> hashmap<str, ()> { ret words; } -fn unexpected(p: &parser, t: token::token) -> ! { +fn unexpected(p: parser, t: token::token) -> ! { let s: str = "unexpected token: "; s += token::to_str(p.get_reader(), t); p.fatal(s); } -fn expect(p: &parser, t: token::token) { +fn expect(p: parser, t: token::token) { if p.peek() == t { p.bump(); } else { @@ -203,7 +203,7 @@ fn expect(p: &parser, t: token::token) { } } -fn expect_gt(p: &parser) { +fn expect_gt(p: parser) { if p.peek() == token::GT { p.bump(); } else if p.peek() == token::BINOP(token::LSR) { @@ -219,34 +219,34 @@ fn expect_gt(p: &parser) { } } -fn spanned<@T>(lo: uint, hi: uint, node: &T) -> spanned<T> { +fn spanned<@T>(lo: uint, hi: uint, node: T) -> spanned<T> { ret {node: node, span: ast_util::mk_sp(lo, hi)}; } -fn parse_ident(p: &parser) -> ast::ident { +fn parse_ident(p: parser) -> ast::ident { alt p.peek() { token::IDENT(i, _) { p.bump(); ret p.get_str(i); } _ { p.fatal("expecting ident"); } } } -fn parse_value_ident(p: &parser) -> ast::ident { +fn parse_value_ident(p: parser) -> ast::ident { check_bad_word(p); ret parse_ident(p); } -fn eat(p: &parser, tok: &token::token) -> bool { +fn eat(p: parser, tok: token::token) -> bool { ret if p.peek() == tok { p.bump(); true } else { false }; } -fn is_word(p: &parser, word: &str) -> bool { +fn is_word(p: parser, word: str) -> bool { ret alt p.peek() { token::IDENT(sid, false) { str::eq(word, p.get_str(sid)) } _ { false } }; } -fn eat_word(p: &parser, word: &str) -> bool { +fn eat_word(p: parser, word: str) -> bool { alt p.peek() { token::IDENT(sid, false) { if str::eq(word, p.get_str(sid)) { @@ -258,14 +258,14 @@ fn eat_word(p: &parser, word: &str) -> bool { } } -fn expect_word(p: &parser, word: &str) { +fn expect_word(p: parser, word: str) { if !eat_word(p, word) { p.fatal("expecting " + word + ", found " + token::to_str(p.get_reader(), p.peek())); } } -fn check_bad_word(p: &parser) { +fn check_bad_word(p: parser) { alt p.peek() { token::IDENT(sid, false) { let w = p.get_str(sid); @@ -277,15 +277,16 @@ fn check_bad_word(p: &parser) { } } -fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { - fn parse_fn_input_ty(p: &parser) -> ast::ty_arg { +fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ { + fn parse_fn_input_ty(p: parser) -> ast::ty_arg { let lo = p.get_lo_pos(); + let mode = parse_arg_mode(p); // Ignore arg name, if present if is_plain_ident(p) && p.look_ahead(1u) == token::COLON { p.bump(); p.bump(); } - let mode = parse_arg_mode(p); + if mode == ast::by_ref { mode = parse_arg_mode(p); } let t = parse_ty(p, false); ret spanned(lo, t.span.hi, {mode: mode, ty: t}); } @@ -312,7 +313,7 @@ fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { ret ast::ty_fn(proto, inputs.node, output, cf, constrs); } -fn parse_proto(p: &parser) -> ast::proto { +fn parse_proto(p: parser) -> ast::proto { if eat_word(p, "iter") { ret ast::proto_iter; } else if eat_word(p, "fn") { @@ -322,8 +323,8 @@ fn parse_proto(p: &parser) -> ast::proto { } else { unexpected(p, p.peek()); } } -fn parse_ty_obj(p: &parser, hi: &mutable uint) -> ast::ty_ { - fn parse_method_sig(p: &parser) -> ast::ty_method { +fn parse_ty_obj(p: parser, hi: &mutable uint) -> ast::ty_ { + fn parse_method_sig(p: parser) -> ast::ty_method { let flo = p.get_lo_pos(); let proto: ast::proto = parse_proto(p); let ident = parse_value_ident(p); @@ -347,13 +348,13 @@ fn parse_ty_obj(p: &parser, hi: &mutable uint) -> ast::ty_ { ret ast::ty_obj(meths.node); } -fn parse_mt(p: &parser) -> ast::mt { +fn parse_mt(p: parser) -> ast::mt { let mut = parse_mutability(p); let t = parse_ty(p, false); ret {ty: t, mut: mut}; } -fn parse_ty_field(p: &parser) -> ast::ty_field { +fn parse_ty_field(p: parser) -> ast::ty_field { let lo = p.get_lo_pos(); let mut = parse_mutability(p); let id = parse_ident(p); @@ -364,13 +365,13 @@ fn parse_ty_field(p: &parser) -> ast::ty_field { // if i is the jth ident in args, return j // otherwise, fail -fn ident_index(p: &parser, args: &[ast::arg], i: &ast::ident) -> uint { +fn ident_index(p: parser, args: [ast::arg], i: ast::ident) -> uint { let j = 0u; for a: ast::arg in args { if a.ident == i { ret j; } j += 1u; } p.fatal("Unbound variable " + i + " in constraint arg"); } -fn parse_type_constr_arg(p: &parser) -> @ast::ty_constr_arg { +fn parse_type_constr_arg(p: parser) -> @ast::ty_constr_arg { let sp = p.get_span(); let carg = ast::carg_base; expect(p, token::BINOP(token::STAR)); @@ -384,7 +385,7 @@ fn parse_type_constr_arg(p: &parser) -> @ast::ty_constr_arg { ret @{node: carg, span: sp}; } -fn parse_constr_arg(args: &[ast::arg], p: &parser) -> @ast::constr_arg { +fn parse_constr_arg(args: [ast::arg], p: parser) -> @ast::constr_arg { let sp = p.get_span(); let carg = ast::carg_base; if p.peek() == token::BINOP(token::STAR) { @@ -396,7 +397,7 @@ fn parse_constr_arg(args: &[ast::arg], p: &parser) -> @ast::constr_arg { ret @{node: carg, span: sp}; } -fn parse_ty_constr(fn_args: &[ast::arg], p: &parser) -> @ast::constr { +fn parse_ty_constr(fn_args: [ast::arg], p: parser) -> @ast::constr { let lo = p.get_lo_pos(); let path = parse_path(p); let pf = bind parse_constr_arg(fn_args, _); @@ -406,7 +407,7 @@ fn parse_ty_constr(fn_args: &[ast::arg], p: &parser) -> @ast::constr { {path: path, args: args.node, id: p.get_id()}); } -fn parse_constr_in_type(p: &parser) -> @ast::ty_constr { +fn parse_constr_in_type(p: parser) -> @ast::ty_constr { let lo = p.get_lo_pos(); let path = parse_path(p); let args: [@ast::ty_constr_arg] = @@ -418,8 +419,8 @@ fn parse_constr_in_type(p: &parser) -> @ast::ty_constr { } -fn parse_constrs<T>(pser: fn(&parser) -> @ast::constr_general<T>, p: &parser) - -> [@ast::constr_general<T>] { +fn parse_constrs<T>(pser: fn(parser) -> @ast::constr_general<T>, p: parser) -> + [@ast::constr_general<T>] { let constrs: [@ast::constr_general<T>] = []; while true { let constr = pser(p); @@ -429,11 +430,11 @@ fn parse_constrs<T>(pser: fn(&parser) -> @ast::constr_general<T>, p: &parser) constrs } -fn parse_type_constraints(p: &parser) -> [@ast::ty_constr] { +fn parse_type_constraints(p: parser) -> [@ast::ty_constr] { ret parse_constrs(parse_constr_in_type, p); } -fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) +fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool) -> @ast::ty { let lo = p.get_lo_pos(); @@ -460,14 +461,14 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) } } -fn parse_ty_or_bang(p: &parser) -> ty_or_bang { +fn parse_ty_or_bang(p: parser) -> ty_or_bang { alt p.peek() { token::NOT. { p.bump(); ret a_bang; } _ { ret a_ty(parse_ty(p, false)); } } } -fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { +fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { let lo = p.get_lo_pos(); let hi = lo; let t: ast::ty_; @@ -578,33 +579,35 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { ret parse_ty_postfix(t, p, colons_before_params); } -fn parse_arg_mode(p: &parser) -> ast::mode { - let mode = ast::by_ref; +fn parse_arg_mode(p: parser) -> ast::mode { if eat(p, token::BINOP(token::AND)) { - if eat_word(p, "mutable") { mode = ast::by_mut_ref; } + eat_word(p, "mutable"); + ret ast::by_mut_ref; } else if eat(p, token::BINOP(token::MINUS)) { - mode = ast::by_move; + ret ast::by_move; + } else { + ret ast::by_ref; } - ret mode; } -fn parse_arg(p: &parser) -> ast::arg { +fn parse_arg(p: parser) -> ast::arg { + let m = parse_arg_mode(p); let i = parse_value_ident(p); expect(p, token::COLON); - let m = parse_arg_mode(p); + if m == ast::by_ref { m = parse_arg_mode(p); } let t = parse_ty(p, false); ret {mode: m, ty: t, ident: i, id: p.get_id()}; } -fn parse_fn_block_arg(p: &parser) -> ast::arg { +fn parse_fn_block_arg(p: parser) -> ast::arg { let m = parse_arg_mode(p); let i = parse_value_ident(p); let t = @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer); ret {mode: m, ty: t, ident: i, id: p.get_id()}; } -fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, - f: fn(&parser) -> T, p: &parser) -> [T] { +fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T, + p: parser) -> [T] { let first = true; let v = []; while p.peek() != token::GT && p.peek() != token::BINOP(token::LSR) && @@ -619,16 +622,16 @@ fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, ret v; } -fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, - p: &parser) -> [T] { +fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T, + p: parser) -> [T] { let v = parse_seq_to_before_gt(sep, f, p); expect_gt(p); ret v; } -fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, - p: &parser) -> spanned<[T]> { +fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T, + p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, token::LT); let result = parse_seq_to_before_gt::<T>(sep, f, p); @@ -638,14 +641,14 @@ fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, } fn parse_seq_to_end<T>(ket: token::token, sep: option::t<token::token>, - f: fn(&parser) -> T, p: &parser) -> [T] { + f: fn(parser) -> T, p: parser) -> [T] { let val = parse_seq_to_before_end(ket, sep, f, p); p.bump(); ret val; } fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>, - f: fn(&parser) -> T, p: &parser) -> [T] { + f: fn(parser) -> T, p: parser) -> [T] { let first: bool = true; let v: [T] = []; while p.peek() != ket { @@ -660,7 +663,7 @@ fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>, fn parse_seq<T>(bra: token::token, ket: token::token, - sep: option::t<token::token>, f: fn(&parser) -> T, p: &parser) + sep: option::t<token::token>, f: fn(parser) -> T, p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, bra); @@ -671,7 +674,7 @@ fn parse_seq<T>(bra: token::token, ket: token::token, } -fn parse_lit(p: &parser) -> ast::lit { +fn parse_lit(p: parser) -> ast::lit { let sp = p.get_span(); let lit: ast::lit_ = ast::lit_nil; if eat_word(p, "true") { @@ -712,11 +715,11 @@ fn is_ident(t: token::token) -> bool { ret false; } -fn is_plain_ident(p: &parser) -> bool { +fn is_plain_ident(p: parser) -> bool { ret alt p.peek() { token::IDENT(_, false) { true } _ { false } }; } -fn parse_path(p: &parser) -> ast::path { +fn parse_path(p: parser) -> ast::path { let lo = p.get_lo_pos(); let hi = lo; @@ -744,7 +747,7 @@ fn parse_path(p: &parser) -> ast::path { ret spanned(lo, hi, {global: global, idents: ids, types: []}); } -fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { +fn parse_path_and_ty_param_substs(p: parser) -> ast::path { let lo = p.get_lo_pos(); let path = parse_path(p); if p.peek() == token::MOD_SEP { @@ -762,7 +765,7 @@ fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { ret path; } -fn parse_mutability(p: &parser) -> ast::mutability { +fn parse_mutability(p: parser) -> ast::mutability { if eat_word(p, "mutable") { if p.peek() == token::QUES { p.bump(); ret ast::maybe_mut; } ret ast::mut; @@ -770,7 +773,7 @@ fn parse_mutability(p: &parser) -> ast::mutability { ret ast::imm; } -fn parse_field(p: &parser, sep: &token::token) -> ast::field { +fn parse_field(p: parser, sep: token::token) -> ast::field { let lo = p.get_lo_pos(); let m = parse_mutability(p); let i = parse_ident(p); @@ -779,17 +782,17 @@ fn parse_field(p: &parser, sep: &token::token) -> ast::field { ret spanned(lo, e.span.hi, {mut: m, ident: i, expr: e}); } -fn mk_expr(p: &parser, lo: uint, hi: uint, node: &ast::expr_) -> @ast::expr { +fn mk_expr(p: parser, lo: uint, hi: uint, node: ast::expr_) -> @ast::expr { ret @{id: p.get_id(), node: node, span: ast_util::mk_sp(lo, hi)}; } -fn mk_mac_expr(p: &parser, lo: uint, hi: uint, m: &ast::mac_) -> @ast::expr { +fn mk_mac_expr(p: parser, lo: uint, hi: uint, m: ast::mac_) -> @ast::expr { ret @{id: p.get_id(), node: ast::expr_mac({node: m, span: ast_util::mk_sp(lo, hi)}), span: ast_util::mk_sp(lo, hi)}; } -fn parse_bottom_expr(p: &parser) -> @ast::expr { +fn parse_bottom_expr(p: parser) -> @ast::expr { let lo = p.get_lo_pos(); let hi = p.get_hi_pos(); @@ -908,7 +911,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { ex = ast::expr_anon_obj(ob); } else if eat_word(p, "bind") { let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS); - fn parse_expr_opt(p: &parser) -> option::t<@ast::expr> { + fn parse_expr_opt(p: parser) -> option::t<@ast::expr> { alt p.peek() { token::UNDERSCORE. { p.bump(); ret none; } _ { ret some(parse_expr(p)); } @@ -1014,13 +1017,13 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ex); } -fn parse_syntax_ext(p: &parser) -> @ast::expr { +fn parse_syntax_ext(p: parser) -> @ast::expr { let lo = p.get_lo_pos(); expect(p, token::POUND); ret parse_syntax_ext_naked(p, lo); } -fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr { +fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr { let pth = parse_path(p); if vec::len(pth.node.idents) == 0u { p.fatal("expected a syntax expander name"); @@ -1039,17 +1042,17 @@ fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr { ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, e, none)); } -fn parse_self_method(p: &parser) -> @ast::expr { +fn parse_self_method(p: parser) -> @ast::expr { let sp = p.get_span(); let f_name: ast::ident = parse_ident(p); ret mk_expr(p, sp.lo, sp.hi, ast::expr_self_method(f_name)); } -fn parse_dot_or_call_expr(p: &parser) -> @ast::expr { +fn parse_dot_or_call_expr(p: parser) -> @ast::expr { ret parse_dot_or_call_expr_with(p, parse_bottom_expr(p)); } -fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr { +fn parse_dot_or_call_expr_with(p: parser, e: @ast::expr) -> @ast::expr { let lo = e.span.lo; let hi = e.span.hi; while true { @@ -1092,7 +1095,7 @@ fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr { ret e; } -fn parse_prefix_expr(p: &parser) -> @ast::expr { +fn parse_prefix_expr(p: parser) -> @ast::expr { if eat_word(p, "mutable") { p.warn("ignoring deprecated 'mutable' prefix operator"); } @@ -1136,7 +1139,7 @@ fn parse_prefix_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ex); } -fn parse_ternary(p: &parser) -> @ast::expr { +fn parse_ternary(p: parser) -> @ast::expr { let cond_expr = parse_binops(p); if p.peek() == token::QUES { p.bump(); @@ -1175,7 +1178,7 @@ fn prec_table() -> @[op_spec] { {tok: token::OROR, op: ast::or, prec: 1}]; } -fn parse_binops(p: &parser) -> @ast::expr { +fn parse_binops(p: parser) -> @ast::expr { ret parse_more_binops(p, parse_prefix_expr(p), 0); } @@ -1184,7 +1187,7 @@ const unop_prec: int = 100; const as_prec: int = 5; const ternary_prec: int = 0; -fn parse_more_binops(p: &parser, lhs: @ast::expr, min_prec: int) -> +fn parse_more_binops(p: parser, lhs: @ast::expr, min_prec: int) -> @ast::expr { let peeked = p.peek(); for cur: op_spec in *p.get_prec_table() { @@ -1206,7 +1209,7 @@ fn parse_more_binops(p: &parser, lhs: @ast::expr, min_prec: int) -> ret lhs; } -fn parse_assign_expr(p: &parser) -> @ast::expr { +fn parse_assign_expr(p: parser) -> @ast::expr { let lo = p.get_lo_pos(); let lhs = parse_ternary(p); alt p.peek() { @@ -1249,7 +1252,7 @@ fn parse_assign_expr(p: &parser) -> @ast::expr { ret lhs; } -fn parse_if_expr_1(p: &parser) -> +fn parse_if_expr_1(p: parser) -> {cond: @ast::expr, then: ast::blk, els: option::t<@ast::expr>, @@ -1268,7 +1271,7 @@ fn parse_if_expr_1(p: &parser) -> ret {cond: cond, then: thn, els: els, lo: lo, hi: hi}; } -fn parse_if_expr(p: &parser) -> @ast::expr { +fn parse_if_expr(p: parser) -> @ast::expr { if eat_word(p, "check") { let q = parse_if_expr_1(p); ret mk_expr(p, q.lo, q.hi, ast::expr_if_check(q.cond, q.then, q.els)); @@ -1278,7 +1281,7 @@ fn parse_if_expr(p: &parser) -> @ast::expr { } } -fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr { +fn parse_fn_expr(p: parser, proto: ast::proto) -> @ast::expr { let lo = p.get_last_lo_pos(); let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal); let body = parse_block(p); @@ -1286,7 +1289,7 @@ fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr { ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn)); } -fn parse_fn_block_expr(p: &parser) -> @ast::expr { +fn parse_fn_block_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let decl = parse_fn_block_decl(p); let body = parse_block_tail(p, lo, ast::checked); @@ -1294,7 +1297,7 @@ fn parse_fn_block_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn)); } -fn parse_else_expr(p: &parser) -> @ast::expr { +fn parse_else_expr(p: parser) -> @ast::expr { if eat_word(p, "if") { ret parse_if_expr(p); } else { @@ -1303,7 +1306,7 @@ fn parse_else_expr(p: &parser) -> @ast::expr { } } -fn parse_for_expr(p: &parser) -> @ast::expr { +fn parse_for_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let is_each = eat_word(p, "each"); let decl = parse_local(p, false); @@ -1316,7 +1319,7 @@ fn parse_for_expr(p: &parser) -> @ast::expr { } else { ret mk_expr(p, lo, hi, ast::expr_for(decl, seq, body)); } } -fn parse_while_expr(p: &parser) -> @ast::expr { +fn parse_while_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let cond = parse_expr(p); let body = parse_block(p); @@ -1324,7 +1327,7 @@ fn parse_while_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ast::expr_while(cond, body)); } -fn parse_do_while_expr(p: &parser) -> @ast::expr { +fn parse_do_while_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let body = parse_block(p); expect_word(p, "while"); @@ -1333,7 +1336,7 @@ fn parse_do_while_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond)); } -fn parse_alt_expr(p: &parser) -> @ast::expr { +fn parse_alt_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let discriminant = parse_expr(p); expect(p, token::LBRACE); @@ -1350,11 +1353,11 @@ fn parse_alt_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ast::expr_alt(discriminant, arms)); } -fn parse_expr(p: &parser) -> @ast::expr { +fn parse_expr(p: parser) -> @ast::expr { ret parse_expr_res(p, UNRESTRICTED); } -fn parse_expr_res(p: &parser, r: restriction) -> @ast::expr { +fn parse_expr_res(p: parser, r: restriction) -> @ast::expr { let old = p.get_restriction(); p.restrict(r); let e = parse_assign_expr(p); @@ -1362,7 +1365,7 @@ fn parse_expr_res(p: &parser, r: restriction) -> @ast::expr { ret e; } -fn parse_initializer(p: &parser) -> option::t<ast::initializer> { +fn parse_initializer(p: parser) -> option::t<ast::initializer> { alt p.peek() { token::EQ. { p.bump(); @@ -1375,6 +1378,7 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { + // Now that the the channel is the first argument to receive, // combining it with an initializer doesn't really make sense. // case (token::RECV) { @@ -1388,7 +1392,7 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { } } -fn parse_pats(p: &parser) -> [@ast::pat] { +fn parse_pats(p: parser) -> [@ast::pat] { let pats = []; while true { pats += [parse_pat(p)]; @@ -1397,7 +1401,7 @@ fn parse_pats(p: &parser) -> [@ast::pat] { ret pats; } -fn parse_pat(p: &parser) -> @ast::pat { +fn parse_pat(p: parser) -> @ast::pat { let lo = p.get_lo_pos(); let hi = p.get_hi_pos(); let pat; @@ -1503,7 +1507,7 @@ fn parse_pat(p: &parser) -> @ast::pat { ret @{id: p.get_id(), node: pat, span: ast_util::mk_sp(lo, hi)}; } -fn parse_local(p: &parser, allow_init: bool) -> @ast::local { +fn parse_local(p: parser, allow_init: bool) -> @ast::local { let lo = p.get_lo_pos(); let pat = parse_pat(p); let ty = @spanned(lo, lo, ast::ty_infer); @@ -1513,7 +1517,7 @@ fn parse_local(p: &parser, allow_init: bool) -> @ast::local { {ty: ty, pat: pat, init: init, id: p.get_id()}); } -fn parse_let(p: &parser) -> @ast::decl { +fn parse_let(p: parser) -> @ast::decl { let lo = p.get_lo_pos(); let locals = [parse_local(p, true)]; while p.peek() == token::COMMA { @@ -1523,19 +1527,19 @@ fn parse_let(p: &parser) -> @ast::decl { ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals)); } -fn parse_stmt(p: &parser) -> @ast::stmt { +fn parse_stmt(p: parser) -> @ast::stmt { if p.get_file_type() == SOURCE_FILE { ret parse_source_stmt(p); } else { ret parse_crate_stmt(p); } } -fn parse_crate_stmt(p: &parser) -> @ast::stmt { +fn parse_crate_stmt(p: parser) -> @ast::stmt { let cdir = parse_crate_directive(p, []); ret @spanned(cdir.span.lo, cdir.span.hi, ast::stmt_crate_directive(@cdir)); } -fn parse_source_stmt(p: &parser) -> @ast::stmt { +fn parse_source_stmt(p: parser) -> @ast::stmt { let lo = p.get_lo_pos(); if eat_word(p, "let") { let decl = parse_let(p); @@ -1582,7 +1586,7 @@ fn stmt_to_expr(stmt: @ast::stmt) -> option::t<@ast::expr> { ret alt stmt.node { ast::stmt_expr(e, _) { some(e) } _ { none } }; } -fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { +fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { alt stmt.node { ast::stmt_decl(d, _) { ret alt d.node { @@ -1636,6 +1640,7 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { + // We should not be calling this on a cdir. ast::stmt_crate_directive(cdir) { fail; @@ -1643,7 +1648,7 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { } } -fn parse_block(p: &parser) -> ast::blk { +fn parse_block(p: parser) -> ast::blk { let lo = p.get_lo_pos(); if eat_word(p, "unchecked") { be parse_block_tail(p, lo, ast::unchecked); @@ -1657,7 +1662,7 @@ fn parse_block(p: &parser) -> ast::blk { // I guess that also means "already parsed the 'impure'" if // necessary, and this should take a qualifier. // some blocks start with "#{"... -fn parse_block_tail(p: &parser, lo: uint, s: ast::check_mode) -> ast::blk { +fn parse_block_tail(p: parser, lo: uint, s: ast::check_mode) -> ast::blk { let stmts: [@ast::stmt] = []; let expr: option::t<@ast::expr> = none; while p.peek() != token::RBRACE { @@ -1702,7 +1707,7 @@ fn parse_block_tail(p: &parser, lo: uint, s: ast::check_mode) -> ast::blk { ret spanned(lo, hi, bloc); } -fn parse_ty_param(p: &parser) -> ast::ty_param { +fn parse_ty_param(p: parser) -> ast::ty_param { let k = alt p.peek() { token::TILDE. { p.bump(); ast::kind_unique } @@ -1712,7 +1717,7 @@ fn parse_ty_param(p: &parser) -> ast::ty_param { ret {ident: parse_ident(p), kind: k}; } -fn parse_ty_params(p: &parser) -> [ast::ty_param] { +fn parse_ty_params(p: parser) -> [ast::ty_param] { let ty_params: [ast::ty_param] = []; if p.peek() == token::LT { p.bump(); @@ -1726,7 +1731,7 @@ fn parse_ty_params(p: &parser) -> [ast::ty_param] { ret ty_params; } -fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) -> +fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) -> ast::fn_decl { let inputs: ast::spanned<[ast::arg]> = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg, @@ -1766,7 +1771,7 @@ fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) -> } } -fn parse_fn_block_decl(p: &parser) -> ast::fn_decl { +fn parse_fn_block_decl(p: parser) -> ast::fn_decl { let inputs: ast::spanned<[ast::arg]> = parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), some(token::COMMA), parse_fn_block_arg, p); @@ -1778,21 +1783,21 @@ fn parse_fn_block_decl(p: &parser) -> ast::fn_decl { constraints: []}; } -fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity, +fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity, il: ast::inlineness) -> ast::_fn { let decl = parse_fn_decl(p, purity, il); let body = parse_block(p); ret {decl: decl, proto: proto, body: body}; } -fn parse_fn_header(p: &parser) -> {ident: ast::ident, tps: [ast::ty_param]} { +fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} { let id = parse_value_ident(p); let ty_params = parse_ty_params(p); ret {ident: id, tps: ty_params}; } -fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident, - node: &ast::item_, attrs: &[ast::attribute]) -> @ast::item { +fn mk_item(p: parser, lo: uint, hi: uint, ident: ast::ident, node: ast::item_, + attrs: [ast::attribute]) -> @ast::item { ret @{ident: ident, attrs: attrs, id: p.get_id(), @@ -1800,8 +1805,8 @@ fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident, span: ast_util::mk_sp(lo, hi)}; } -fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto, - attrs: &[ast::attribute], il: ast::inlineness) -> +fn parse_item_fn_or_iter(p: parser, purity: ast::purity, proto: ast::proto, + attrs: [ast::attribute], il: ast::inlineness) -> @ast::item { let lo = p.get_last_lo_pos(); let t = parse_fn_header(p); @@ -1810,7 +1815,7 @@ fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto, attrs); } -fn parse_obj_field(p: &parser) -> ast::obj_field { +fn parse_obj_field(p: parser) -> ast::obj_field { let mut = parse_mutability(p); let ident = parse_value_ident(p); expect(p, token::COLON); @@ -1818,7 +1823,7 @@ fn parse_obj_field(p: &parser) -> ast::obj_field { ret {mut: mut, ty: ty, ident: ident, id: p.get_id()}; } -fn parse_anon_obj_field(p: &parser) -> ast::anon_obj_field { +fn parse_anon_obj_field(p: parser) -> ast::anon_obj_field { let mut = parse_mutability(p); let ident = parse_value_ident(p); expect(p, token::COLON); @@ -1828,7 +1833,7 @@ fn parse_anon_obj_field(p: &parser) -> ast::anon_obj_field { ret {mut: mut, ty: ty, expr: expr, ident: ident, id: p.get_id()}; } -fn parse_method(p: &parser) -> @ast::method { +fn parse_method(p: parser) -> @ast::method { let lo = p.get_lo_pos(); let proto = parse_proto(p); let ident = parse_value_ident(p); @@ -1837,7 +1842,7 @@ fn parse_method(p: &parser) -> @ast::method { ret @spanned(lo, f.body.span.hi, meth); } -fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); let ty_params = parse_ty_params(p); @@ -1854,7 +1859,7 @@ fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> @ast::item { attrs); } -fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); let ty_params = parse_ty_params(p); @@ -1866,10 +1871,7 @@ fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let dtor = parse_block(p); let decl = {inputs: - [{mode: ast::by_ref, - ty: t, - ident: arg_ident, - id: p.get_id()}], + [{mode: ast::by_ref, ty: t, ident: arg_ident, id: p.get_id()}], output: @spanned(lo, lo, ast::ty_nil), purity: ast::impure_fn, il: ast::il_normal, @@ -1880,8 +1882,8 @@ fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs); } -fn parse_mod_items(p: &parser, term: token::token, - first_item_attrs: &[ast::attribute]) -> ast::_mod { +fn parse_mod_items(p: parser, term: token::token, + first_item_attrs: [ast::attribute]) -> ast::_mod { // Shouldn't be any view items since we've already parsed an item attr let view_items = if vec::len(first_item_attrs) == 0u { parse_view(p) } else { [] }; @@ -1901,7 +1903,7 @@ fn parse_mod_items(p: &parser, term: token::token, ret {view_items: view_items, items: items}; } -fn parse_item_const(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_const(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_value_ident(p); expect(p, token::COLON); @@ -1913,7 +1915,7 @@ fn parse_item_const(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_const(ty, e), attrs); } -fn parse_item_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_mod(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); expect(p, token::LBRACE); @@ -1925,7 +1927,7 @@ fn parse_item_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_mod(m), attrs + inner_attrs.inner); } -fn parse_item_native_type(p: &parser, attrs: &[ast::attribute]) -> +fn parse_item_native_type(p: parser, attrs: [ast::attribute]) -> @ast::native_item { let t = parse_type_decl(p); let hi = p.get_hi_pos(); @@ -1937,7 +1939,7 @@ fn parse_item_native_type(p: &parser, attrs: &[ast::attribute]) -> span: ast_util::mk_sp(t.lo, hi)}; } -fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> +fn parse_item_native_fn(p: parser, attrs: [ast::attribute]) -> @ast::native_item { let lo = p.get_last_lo_pos(); let t = parse_fn_header(p); @@ -1953,7 +1955,7 @@ fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> span: ast_util::mk_sp(lo, hi)}; } -fn parse_native_item(p: &parser, attrs: &[ast::attribute]) -> +fn parse_native_item(p: parser, attrs: [ast::attribute]) -> @ast::native_item { if eat_word(p, "type") { ret parse_item_native_type(p, attrs); @@ -1962,8 +1964,8 @@ fn parse_native_item(p: &parser, attrs: &[ast::attribute]) -> } else { unexpected(p, p.peek()); } } -fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi, - first_item_attrs: &[ast::attribute]) -> +fn parse_native_mod_items(p: parser, native_name: str, abi: ast::native_abi, + first_item_attrs: [ast::attribute]) -> ast::native_mod { // Shouldn't be any view items since we've already parsed an item attr let view_items = @@ -1983,7 +1985,7 @@ fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi, items: items}; } -fn parse_item_native_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let abi = ast::native_abi_cdecl; if !is_word(p, "mod") { @@ -2017,13 +2019,13 @@ fn parse_item_native_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_native_mod(m), attrs + inner_attrs); } -fn parse_type_decl(p: &parser) -> {lo: uint, ident: ast::ident} { +fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} { let lo = p.get_last_lo_pos(); let id = parse_ident(p); ret {lo: lo, ident: id}; } -fn parse_item_type(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item { let t = parse_type_decl(p); let tps = parse_ty_params(p); expect(p, token::EQ); @@ -2033,7 +2035,7 @@ fn parse_item_type(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, t.lo, hi, t.ident, ast::item_ty(ty, tps), attrs); } -fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); let ty_params = parse_ty_params(p); @@ -2093,13 +2095,13 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs); } -fn parse_auth(p: &parser) -> ast::_auth { +fn parse_auth(p: parser) -> ast::_auth { if eat_word(p, "unsafe") { ret ast::auth_unsafe; } else { unexpected(p, p.peek()); } } -fn parse_item(p: &parser, attrs: &[ast::attribute]) -> option::t<@ast::item> { +fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> { if eat_word(p, "const") { ret some(parse_item_const(p, attrs)); } else if eat_word(p, "inline") { @@ -2138,7 +2140,7 @@ fn parse_item(p: &parser, attrs: &[ast::attribute]) -> option::t<@ast::item> { // extensions, which both begin with token.POUND type attr_or_ext = option::t<either::t<[ast::attribute], @ast::expr>>; -fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext { +fn parse_outer_attrs_or_ext(p: parser) -> attr_or_ext { if p.peek() == token::POUND { let lo = p.get_lo_pos(); p.bump(); @@ -2152,7 +2154,7 @@ fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext { } // Parse attributes that appear before an item -fn parse_outer_attributes(p: &parser) -> [ast::attribute] { +fn parse_outer_attributes(p: parser) -> [ast::attribute] { let attrs: [ast::attribute] = []; while p.peek() == token::POUND { attrs += [parse_attribute(p, ast::attr_outer)]; @@ -2160,13 +2162,13 @@ fn parse_outer_attributes(p: &parser) -> [ast::attribute] { ret attrs; } -fn parse_attribute(p: &parser, style: ast::attr_style) -> ast::attribute { +fn parse_attribute(p: parser, style: ast::attr_style) -> ast::attribute { let lo = p.get_lo_pos(); expect(p, token::POUND); ret parse_attribute_naked(p, style, lo); } -fn parse_attribute_naked(p: &parser, style: ast::attr_style, lo: uint) -> +fn parse_attribute_naked(p: parser, style: ast::attr_style, lo: uint) -> ast::attribute { expect(p, token::LBRACKET); let meta_item = parse_meta_item(p); @@ -2181,7 +2183,7 @@ fn parse_attribute_naked(p: &parser, style: ast::attr_style, lo: uint) -> // next item (since we can't know whether the attribute is an inner attribute // of the containing item or an outer attribute of the first contained item // until we see the semi). -fn parse_inner_attrs_and_next(p: &parser) -> +fn parse_inner_attrs_and_next(p: parser) -> {inner: [ast::attribute], next: [ast::attribute]} { let inner_attrs: [ast::attribute] = []; let next_outer_attrs: [ast::attribute] = []; @@ -2202,7 +2204,7 @@ fn parse_inner_attrs_and_next(p: &parser) -> ret {inner: inner_attrs, next: next_outer_attrs}; } -fn parse_meta_item(p: &parser) -> @ast::meta_item { +fn parse_meta_item(p: parser) -> @ast::meta_item { let lo = p.get_lo_pos(); let ident = parse_ident(p); alt p.peek() { @@ -2224,22 +2226,22 @@ fn parse_meta_item(p: &parser) -> @ast::meta_item { } } -fn parse_meta_seq(p: &parser) -> [@ast::meta_item] { +fn parse_meta_seq(p: parser) -> [@ast::meta_item] { ret parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_meta_item, p).node; } -fn parse_optional_meta(p: &parser) -> [@ast::meta_item] { +fn parse_optional_meta(p: parser) -> [@ast::meta_item] { alt p.peek() { token::LPAREN. { ret parse_meta_seq(p); } _ { ret []; } } } -fn parse_use(p: &parser) -> ast::view_item_ { +fn parse_use(p: parser) -> ast::view_item_ { let ident = parse_ident(p); let metadata = parse_optional_meta(p); ret ast::view_item_use(ident, metadata, p.get_id()); } -fn parse_rest_import_name(p: &parser, first: &ast::ident, +fn parse_rest_import_name(p: parser, first: ast::ident, def_ident: option::t<ast::ident>) -> ast::view_item_ { let identifiers: [ast::ident] = [first]; @@ -2262,6 +2264,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, + //the lexer can't tell the different kinds of stars apart ) : token::BINOP(token::STAR.) { glob = true; @@ -2270,8 +2273,9 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, + token::LBRACE. { - fn parse_import_ident(p: &parser) -> ast::import_ident { + fn parse_import_ident(p: parser) -> ast::import_ident { let lo = p.get_lo_pos(); let ident = parse_ident(p); let hi = p.get_hi_pos(); @@ -2288,6 +2292,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, + _ { p.fatal("expecting an identifier, or '*'"); } @@ -2317,7 +2322,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, } } -fn parse_full_import_name(p: &parser, def_ident: &ast::ident) -> +fn parse_full_import_name(p: parser, def_ident: ast::ident) -> ast::view_item_ { alt p.peek() { token::IDENT(i, _) { @@ -2328,7 +2333,7 @@ fn parse_full_import_name(p: &parser, def_ident: &ast::ident) -> } } -fn parse_import(p: &parser) -> ast::view_item_ { +fn parse_import(p: parser) -> ast::view_item_ { alt p.peek() { token::IDENT(i, _) { p.bump(); @@ -2344,14 +2349,14 @@ fn parse_import(p: &parser) -> ast::view_item_ { } } -fn parse_export(p: &parser) -> ast::view_item_ { +fn parse_export(p: parser) -> ast::view_item_ { let ids = parse_seq_to_before_end(token::SEMI, option::some(token::COMMA), parse_ident, p); ret ast::view_item_export(ids, p.get_id()); } -fn parse_view_item(p: &parser) -> @ast::view_item { +fn parse_view_item(p: parser) -> @ast::view_item { let lo = p.get_lo_pos(); let the_item = if eat_word(p, "use") { @@ -2364,7 +2369,7 @@ fn parse_view_item(p: &parser) -> @ast::view_item { ret @spanned(lo, hi, the_item); } -fn is_view_item(p: &parser) -> bool { +fn is_view_item(p: parser) -> bool { alt p.peek() { token::IDENT(sid, false) { let st = p.get_str(sid); @@ -2375,26 +2380,26 @@ fn is_view_item(p: &parser) -> bool { } } -fn parse_view(p: &parser) -> [@ast::view_item] { +fn parse_view(p: parser) -> [@ast::view_item] { let items: [@ast::view_item] = []; while is_view_item(p) { items += [parse_view_item(p)]; } ret items; } -fn parse_native_view(p: &parser) -> [@ast::view_item] { +fn parse_native_view(p: parser) -> [@ast::view_item] { let items: [@ast::view_item] = []; while is_view_item(p) { items += [parse_view_item(p)]; } ret items; } -fn parse_crate_from_source_file(input: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg, + sess: parse_sess) -> @ast::crate { let p = new_parser_from_file(sess, cfg, input, 0u, 0u, SOURCE_FILE); ret parse_crate_mod(p, cfg); } -fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_source_str(name: str, source: str, cfg: ast::crate_cfg, + sess: parse_sess) -> @ast::crate { let ftype = SOURCE_FILE; let filemap = codemap::new_filemap(name, 0u, 0u); sess.cm.files += [filemap]; @@ -2405,7 +2410,7 @@ fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg, } // Parses a source module as a crate -fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> @ast::crate { +fn parse_crate_mod(p: parser, _cfg: ast::crate_cfg) -> @ast::crate { let lo = p.get_lo_pos(); let crate_attrs = parse_inner_attrs_and_next(p); let first_item_outer_attrs = crate_attrs.next; @@ -2417,7 +2422,7 @@ fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> @ast::crate { config: p.get_cfg()}); } -fn parse_str(p: &parser) -> str { +fn parse_str(p: parser) -> str { alt p.peek() { token::LIT_STR(s) { p.bump(); ret p.get_str(s); } _ { fail; } @@ -2429,7 +2434,7 @@ fn parse_str(p: &parser) -> str { // Each crate file is a sequence of directives. // // Each directive imperatively extends its environment with 0 or more items. -fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> +fn parse_crate_directive(p: parser, first_outer_attr: [ast::attribute]) -> ast::crate_directive { // Collect the next attributes @@ -2450,6 +2455,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> + // mod x = "foo.rs"; token::SEMI. { let hi = p.get_hi_pos(); @@ -2459,6 +2465,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> + // mod x = "foo_dir" { ...directives... } token::LBRACE. { p.bump(); @@ -2487,8 +2494,8 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> } else { ret p.fatal("expected crate directive"); } } -fn parse_crate_directives(p: &parser, term: token::token, - first_outer_attr: &[ast::attribute]) -> +fn parse_crate_directives(p: parser, term: token::token, + first_outer_attr: [ast::attribute]) -> [@ast::crate_directive] { // This is pretty ugly. If we have an outer attribute then we can't accept @@ -2506,8 +2513,8 @@ fn parse_crate_directives(p: &parser, term: token::token, ret cdirs; } -fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_crate_file(input: str, cfg: ast::crate_cfg, + sess: parse_sess) -> @ast::crate { let p = new_parser_from_file(sess, cfg, input, 0u, 0u, CRATE_FILE); let lo = p.get_lo_pos(); let prefix = std::fs::dirname(p.get_filemap().name); @@ -2534,8 +2541,8 @@ fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, config: p.get_cfg()}); } -fn parse_crate_from_file(input: &str, cfg: &ast::crate_cfg, sess: &parse_sess) - -> @ast::crate { +fn parse_crate_from_file(input: str, cfg: ast::crate_cfg, sess: parse_sess) -> + @ast::crate { if str::ends_with(input, ".rc") { parse_crate_from_crate_file(input, cfg, sess) } else if str::ends_with(input, ".rs") { diff --git a/src/comp/syntax/parse/token.rs b/src/comp/syntax/parse/token.rs index 153f5236c4b..2846d3945dd 100644 --- a/src/comp/syntax/parse/token.rs +++ b/src/comp/syntax/parse/token.rs @@ -118,6 +118,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Structural symbols */ AT. { ret "@"; @@ -144,6 +145,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Literals */ LIT_INT(i) { ret int::to_str(i, 10u); @@ -171,6 +173,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Name components */ IDENT(s, _) { ret interner::get::<str>(*r.get_interner(), s); diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs index fad670fbefb..280a36a3ac7 100644 --- a/src/comp/syntax/print/pp.rs +++ b/src/comp/syntax/print/pp.rs @@ -73,8 +73,8 @@ fn tok_str(t: token) -> str { } } -fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint, - right: uint, lim: uint) -> str { +fn buf_str(toks: [mutable token], szs: [mutable int], left: uint, right: uint, + lim: uint) -> str { let n = vec::len(toks); assert (n == vec::len(szs)); let i = left; @@ -404,7 +404,7 @@ obj printer(out: io::writer, if n != 0u { top = print_stack[n - 1u]; } ret top; } - fn write_str(s: &str) { + fn write_str(s: str) { while pending_indentation > 0 { out.write_str(" "); pending_indentation -= 1; @@ -492,15 +492,15 @@ fn end(p: printer) { p.pretty_print(END); } fn eof(p: printer) { p.pretty_print(EOF); } -fn word(p: printer, wrd: &str) { +fn word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, str::char_len(wrd) as int)); } -fn huge_word(p: printer, wrd: &str) { +fn huge_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, size_infinity)); } -fn zero_word(p: printer, wrd: &str) { p.pretty_print(STRING(wrd, 0)); } +fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, 0)); } fn spaces(p: printer, n: uint) { break_offset(p, n, 0); } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 38e2dbed5b6..b1ecf450c5d 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -33,10 +33,10 @@ tag ann_node { node_expr(ps, @ast::expr); node_pat(ps, @ast::pat); } -type pp_ann = {pre: fn(&ann_node), post: fn(&ann_node)}; +type pp_ann = {pre: fn(ann_node), post: fn(ann_node)}; fn no_ann() -> pp_ann { - fn ignore(_node: &ann_node) { } + fn ignore(_node: ann_node) { } ret {pre: ignore, post: ignore}; } @@ -50,9 +50,9 @@ type ps = mutable boxes: [pp::breaks], ann: pp_ann}; -fn ibox(s: &ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); } +fn ibox(s: ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); } -fn end(s: &ps) { vec::pop(s.boxes); pp::end(s.s); } +fn end(s: ps) { vec::pop(s.boxes); pp::end(s.s); } fn rust_printer(writer: io::writer) -> ps { let boxes: [pp::breaks] = []; @@ -74,8 +74,8 @@ const default_columns: uint = 78u; // Requires you to pass an input filename and reader so that // it can scan the input text for comments and literals to // copy forward. -fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str, - in: io::reader, out: io::writer, ann: &pp_ann) { +fn print_crate(cm: codemap, crate: @ast::crate, filename: str, in: io::reader, + out: io::writer, ann: pp_ann) { let boxes: [pp::breaks] = []; let r = lexer::gather_comments_and_literals(cm, filename, in); let s = @@ -92,22 +92,21 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str, eof(s.s); } -fn ty_to_str(ty: &@ast::ty) -> str { be to_str(ty, print_type); } +fn ty_to_str(ty: @ast::ty) -> str { be to_str(ty, print_type); } -fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); } +fn pat_to_str(pat: @ast::pat) -> str { be to_str(pat, print_pat); } -fn expr_to_str(e: &@ast::expr) -> str { be to_str(e, print_expr); } +fn expr_to_str(e: @ast::expr) -> str { be to_str(e, print_expr); } -fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); } +fn stmt_to_str(s: ast::stmt) -> str { be to_str(s, print_stmt); } -fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); } +fn item_to_str(i: @ast::item) -> str { be to_str(i, print_item); } -fn path_to_str(p: &ast::path) -> str { +fn path_to_str(p: ast::path) -> str { be to_str(p, bind print_path(_, _, false)); } -fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) -> - str { +fn fun_to_str(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); print_fn(s, f.decl, f.proto, name, params, f.decl.constraints); @@ -115,7 +114,7 @@ fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) -> ret writer.get_str(); } -fn block_to_str(blk: &ast::blk) -> str { +fn block_to_str(blk: ast::blk) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); // containing cbox, will be closed by print-block at } @@ -129,29 +128,29 @@ fn block_to_str(blk: &ast::blk) -> str { ret writer.get_str(); } -fn meta_item_to_str(mi: &ast::meta_item) -> str { +fn meta_item_to_str(mi: ast::meta_item) -> str { ret to_str(@mi, print_meta_item); } -fn attribute_to_str(attr: &ast::attribute) -> str { +fn attribute_to_str(attr: ast::attribute) -> str { be to_str(attr, print_attribute); } -fn cbox(s: &ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); } +fn cbox(s: ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); } -fn box(s: &ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); } +fn box(s: ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); } -fn nbsp(s: &ps) { word(s.s, " "); } +fn nbsp(s: ps) { word(s.s, " "); } -fn word_nbsp(s: &ps, w: &str) { word(s.s, w); nbsp(s); } +fn word_nbsp(s: ps, w: str) { word(s.s, w); nbsp(s); } -fn word_space(s: &ps, w: &str) { word(s.s, w); space(s.s); } +fn word_space(s: ps, w: str) { word(s.s, w); space(s.s); } -fn popen(s: &ps) { word(s.s, "("); } +fn popen(s: ps) { word(s.s, "("); } -fn pclose(s: &ps) { word(s.s, ")"); } +fn pclose(s: ps) { word(s.s, ")"); } -fn head(s: &ps, w: &str) { +fn head(s: ps, w: str) { // outer-box is consistent cbox(s, indent_unit); // head-box is inconsistent @@ -160,35 +159,35 @@ fn head(s: &ps, w: &str) { word_nbsp(s, w); } -fn bopen(s: &ps) { +fn bopen(s: ps) { word(s.s, "{"); end(s); // close the head-box } -fn bclose_(s: &ps, span: codemap::span, indented: uint) { +fn bclose_(s: ps, span: codemap::span, indented: uint) { maybe_print_comment(s, span.hi); break_offset_if_not_bol(s, 1u, -(indented as int)); word(s.s, "}"); end(s); // close the outer-box } -fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); } +fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); } -fn is_begin(s: &ps) -> bool { +fn is_begin(s: ps) -> bool { alt s.s.last_token() { pp::BEGIN(_) { true } _ { false } } } -fn is_end(s: &ps) -> bool { +fn is_end(s: ps) -> bool { alt s.s.last_token() { pp::END. { true } _ { false } } } -fn is_bol(s: &ps) -> bool { +fn is_bol(s: ps) -> bool { ret s.s.last_token() == pp::EOF || s.s.last_token() == pp::hardbreak_tok(); } -fn hardbreak_if_not_bol(s: &ps) { if !is_bol(s) { hardbreak(s.s); } } -fn space_if_not_bol(s: &ps) { if !is_bol(s) { space(s.s); } } -fn break_offset_if_not_bol(s: &ps, n: uint, off: int) { +fn hardbreak_if_not_bol(s: ps) { if !is_bol(s) { hardbreak(s.s); } } +fn space_if_not_bol(s: ps) { if !is_bol(s) { space(s.s); } } +fn break_offset_if_not_bol(s: ps, n: uint, off: int) { if !is_bol(s) { break_offset(s.s, n, off); } else { @@ -203,7 +202,7 @@ fn break_offset_if_not_bol(s: &ps, n: uint, off: int) { // Synthesizes a comment that was not textually present in the original source // file. -fn synth_comment(s: &ps, text: &str) { +fn synth_comment(s: ps, text: str) { word(s.s, "/*"); space(s.s); word(s.s, text); @@ -211,7 +210,7 @@ fn synth_comment(s: &ps, text: &str) { word(s.s, "*/"); } -fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) { +fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN)) { box(s, 0u, b); let first = true; for elt: IN in elts { @@ -222,8 +221,8 @@ fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) { } -fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), - get_span: fn(&IN) -> codemap::span) { +fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN), + get_span: fn(IN) -> codemap::span) { box(s, 0u, b); let len = vec::len::<IN>(elts); let i = 0u; @@ -241,12 +240,12 @@ fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), end(s); } -fn commasep_exprs(s: &ps, b: breaks, exprs: &[@ast::expr]) { - fn expr_span(expr: &@ast::expr) -> codemap::span { ret expr.span; } +fn commasep_exprs(s: ps, b: breaks, exprs: [@ast::expr]) { + fn expr_span(expr: @ast::expr) -> codemap::span { ret expr.span; } commasep_cmnt(s, b, exprs, print_expr, expr_span); } -fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &[ast::attribute]) { +fn print_mod(s: ps, _mod: ast::_mod, attrs: [ast::attribute]) { print_inner_attributes(s, attrs); for vitem: @ast::view_item in _mod.view_items { print_view_item(s, vitem); @@ -254,8 +253,7 @@ fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &[ast::attribute]) { for item: @ast::item in _mod.items { print_item(s, item); } } -fn print_native_mod(s: &ps, nmod: &ast::native_mod, - attrs: &[ast::attribute]) { +fn print_native_mod(s: ps, nmod: ast::native_mod, attrs: [ast::attribute]) { print_inner_attributes(s, attrs); for vitem: @ast::view_item in nmod.view_items { print_view_item(s, vitem); @@ -263,7 +261,7 @@ fn print_native_mod(s: &ps, nmod: &ast::native_mod, for item: @ast::native_item in nmod.items { print_native_item(s, item); } } -fn print_type(s: &ps, ty: &@ast::ty) { +fn print_type(s: ps, ty: @ast::ty) { maybe_print_comment(s, ty.span.lo); ibox(s, 0u); alt ty.node { @@ -301,7 +299,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { } ast::ty_rec(fields) { word(s.s, "{"); - fn print_field(s: &ps, f: &ast::ty_field) { + fn print_field(s: ps, f: ast::ty_field) { cbox(s, indent_unit); print_mutability(s, f.node.mt.mut); word(s.s, f.node.ident); @@ -309,7 +307,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { print_type(s, f.node.mt.ty); end(s); } - fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; } + fn get_span(f: ast::ty_field) -> codemap::span { ret f.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); word(s.s, "}"); } @@ -346,7 +344,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { end(s); } -fn print_native_item(s: &ps, item: &@ast::native_item) { +fn print_native_item(s: ps, item: @ast::native_item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); @@ -365,6 +363,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { + ast::native_item_fn(lname, decl, typarams) { print_fn(s, decl, ast::proto_fn, item.ident, typarams, decl.constraints); @@ -379,7 +378,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { } } -fn print_item(s: &ps, item: &@ast::item) { +fn print_item(s: ps, item: @ast::item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); @@ -473,7 +472,7 @@ fn print_item(s: &ps, item: &@ast::item) { word(s.s, v.node.name); if vec::len(v.node.args) > 0u { popen(s); - fn print_variant_arg(s: &ps, arg: &ast::variant_arg) { + fn print_variant_arg(s: ps, arg: ast::variant_arg) { print_type(s, arg.ty); } commasep(s, consistent, v.node.args, print_variant_arg); @@ -490,14 +489,14 @@ fn print_item(s: &ps, item: &@ast::item) { word(s.s, item.ident); print_type_params(s, params); popen(s); - fn print_field(s: &ps, field: &ast::obj_field) { + fn print_field(s: ps, field: ast::obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); word_space(s, field.ident + ":"); print_type(s, field.ty); end(s); } - fn get_span(f: &ast::obj_field) -> codemap::span { ret f.ty.span; } + fn get_span(f: ast::obj_field) -> codemap::span { ret f.ty.span; } commasep_cmnt(s, consistent, _obj.fields, print_field, get_span); pclose(s); space(s.s); @@ -528,7 +527,7 @@ fn print_item(s: &ps, item: &@ast::item) { s.ann.post(ann_node); } -fn print_outer_attributes(s: &ps, attrs: &[ast::attribute]) { +fn print_outer_attributes(s: ps, attrs: [ast::attribute]) { let count = 0; for attr: ast::attribute in attrs { alt attr.node.style { @@ -539,7 +538,7 @@ fn print_outer_attributes(s: &ps, attrs: &[ast::attribute]) { if count > 0 { hardbreak_if_not_bol(s); } } -fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { +fn print_inner_attributes(s: ps, attrs: [ast::attribute]) { let count = 0; for attr: ast::attribute in attrs { alt attr.node.style { @@ -554,7 +553,7 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { if count > 0 { hardbreak_if_not_bol(s); } } -fn print_attribute(s: &ps, attr: &ast::attribute) { +fn print_attribute(s: ps, attr: ast::attribute) { hardbreak_if_not_bol(s); maybe_print_comment(s, attr.span.lo); word(s.s, "#["); @@ -562,7 +561,7 @@ fn print_attribute(s: &ps, attr: &ast::attribute) { word(s.s, "]"); } -fn print_stmt(s: &ps, st: &ast::stmt) { +fn print_stmt(s: ps, st: ast::stmt) { maybe_print_comment(s, st.span.lo); alt st.node { ast::stmt_decl(decl, _) { print_decl(s, decl); } @@ -572,13 +571,13 @@ fn print_stmt(s: &ps, st: &ast::stmt) { maybe_print_trailing_comment(s, st.span, none::<uint>); } -fn print_block(s: &ps, blk: &ast::blk) { +fn print_block(s: ps, blk: ast::blk) { print_possibly_embedded_block(s, blk, block_normal, indent_unit); } tag embed_type { block_macro; block_block_fn; block_normal; } -fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, +fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type, indented: uint) { alt blk.node.rules { ast::unchecked. { word(s.s, "unchecked"); } _ { } } @@ -615,8 +614,8 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, // followed by a unary op, square bracket, or paren. In those cases we // have to add an extra semi to make sure the output retains the same // meaning. - fn maybe_protect_block(s: &ps, last: &option::t<@ast::stmt>, - next: &expr_or_stmt) { + fn maybe_protect_block(s: ps, last: option::t<@ast::stmt>, + next: expr_or_stmt) { let last_expr_is_block = alt last { option::some(@{node: ast::stmt_expr(e, _), _}) { @@ -655,7 +654,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, visit_expr(ex, env, visitor); ret *env; - fn visit_expr(ex: &@ast::expr, e: &env, v: &visit::vt<env>) { + fn visit_expr(ex: @ast::expr, e: env, v: visit::vt<env>) { assert (*e == false); if expr_is_ambig(ex) { *e = true; ret; } @@ -695,7 +694,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, // ret and fail, without arguments cannot appear is the discriminant of if, // alt, do, & while unambiguously without being parenthesized -fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { +fn print_maybe_parens_discrim(s: ps, e: @ast::expr) { let disambig = alt e.node { ast::expr_ret(option::none.) { true } _ { false } }; if disambig { popen(s) } @@ -703,20 +702,21 @@ fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { if disambig { pclose(s) } } -fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, - elseopt: &option::t<@ast::expr>, chk: bool) { +fn print_if(s: ps, test: @ast::expr, blk: ast::blk, + elseopt: option::t<@ast::expr>, chk: bool) { head(s, "if"); if chk { word_nbsp(s, "check"); } print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); - fn do_else(s: &ps, els: option::t<@ast::expr>) { + fn do_else(s: ps, els: option::t<@ast::expr>) { alt els { some(_else) { alt _else.node { + // "another else-if" ast::expr_if(i, t, e) { cbox(s, indent_unit - 1u); @@ -730,6 +730,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, + // "final else" ast::expr_block(b) { cbox(s, indent_unit - 1u); @@ -745,7 +746,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, do_else(s, elseopt); } -fn print_mac(s: &ps, m: &ast::mac) { +fn print_mac(s: ps, m: ast::mac) { alt m.node { ast::mac_invoc(path, arg, body) { word(s.s, "#"); @@ -766,7 +767,7 @@ fn print_mac(s: &ps, m: &ast::mac) { } } -fn print_expr(s: &ps, expr: &@ast::expr) { +fn print_expr(s: ps, expr: @ast::expr) { maybe_print_comment(s, expr.span.lo); ibox(s, indent_unit); let ann_node = node_expr(s, expr); @@ -784,7 +785,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { end(s); } ast::expr_rec(fields, wth) { - fn print_field(s: &ps, field: &ast::field) { + fn print_field(s: ps, field: ast::field) { ibox(s, indent_unit); if field.node.mut == ast::mut { word_nbsp(s, "mutable"); } word(s.s, field.node.ident); @@ -792,7 +793,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { print_expr(s, field.node.expr); end(s); } - fn get_span(field: &ast::field) -> codemap::span { ret field.span; } + fn get_span(field: ast::field) -> codemap::span { ret field.span; } word(s.s, "{"); commasep_cmnt(s, consistent, fields, print_field, get_span); alt wth { @@ -823,7 +824,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { print_ident(s, ident); } ast::expr_bind(func, args) { - fn print_opt(s: &ps, expr: &option::t<@ast::expr>) { + fn print_opt(s: ps, expr: option::t<@ast::expr>) { alt expr { some(expr) { print_expr(s, expr); } _ { word(s.s, "_"); } @@ -1036,7 +1037,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { // Fields popen(s); - fn print_field(s: &ps, field: &ast::anon_obj_field) { + fn print_field(s: ps, field: ast::anon_obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); word_space(s, field.ident + ":"); @@ -1046,7 +1047,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { print_expr(s, field.expr); end(s); } - fn get_span(f: &ast::anon_obj_field) -> codemap::span { + fn get_span(f: ast::anon_obj_field) -> codemap::span { ret f.ty.span; } alt anon_obj.fields { @@ -1083,14 +1084,14 @@ fn print_expr(s: &ps, expr: &@ast::expr) { end(s); } -fn print_expr_parens_if_unary(s: &ps, ex: &@ast::expr) { +fn print_expr_parens_if_unary(s: ps, ex: @ast::expr) { let parens = alt ex.node { ast::expr_unary(_, _) { true } _ { false } }; if parens { popen(s); } print_expr(s, ex); if parens { pclose(s); } } -fn print_local_decl(s: &ps, loc: &@ast::local) { +fn print_local_decl(s: ps, loc: @ast::local) { print_pat(s, loc.node.pat); alt loc.node.ty.node { ast::ty_infer. { } @@ -1098,14 +1099,14 @@ fn print_local_decl(s: &ps, loc: &@ast::local) { } } -fn print_decl(s: &ps, decl: &@ast::decl) { +fn print_decl(s: ps, decl: @ast::decl) { maybe_print_comment(s, decl.span.lo); alt decl.node { ast::decl_local(locs) { space_if_not_bol(s); ibox(s, indent_unit); word_nbsp(s, "let"); - fn print_local(s: &ps, loc: &@ast::local) { + fn print_local(s: ps, loc: @ast::local) { ibox(s, indent_unit); print_local_decl(s, loc); end(s); @@ -1128,16 +1129,16 @@ fn print_decl(s: &ps, decl: &@ast::decl) { } } -fn print_ident(s: &ps, ident: &ast::ident) { word(s.s, ident); } +fn print_ident(s: ps, ident: ast::ident) { word(s.s, ident); } -fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) { +fn print_for_decl(s: ps, loc: @ast::local, coll: @ast::expr) { print_local_decl(s, loc); space(s.s); word_space(s, "in"); print_expr(s, coll); } -fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) { +fn print_path(s: ps, path: ast::path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); if path.node.global { word(s.s, "::"); } let first = true; @@ -1153,7 +1154,7 @@ fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) { } } -fn print_pat(s: &ps, pat: &@ast::pat) { +fn print_pat(s: ps, pat: @ast::pat) { maybe_print_comment(s, pat.span.lo); let ann_node = node_pat(s, pat); s.ann.pre(ann_node); @@ -1171,14 +1172,14 @@ fn print_pat(s: &ps, pat: &@ast::pat) { } ast::pat_rec(fields, etc) { word(s.s, "{"); - fn print_field(s: &ps, f: &ast::field_pat) { + fn print_field(s: ps, f: ast::field_pat) { cbox(s, indent_unit); word(s.s, f.ident); word_space(s, ":"); print_pat(s, f.pat); end(s); } - fn get_span(f: &ast::field_pat) -> codemap::span { ret f.pat.span; } + fn get_span(f: ast::field_pat) -> codemap::span { ret f.pat.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); if etc { if vec::len(fields) != 0u { word_space(s, ","); } @@ -1196,8 +1197,8 @@ fn print_pat(s: &ps, pat: &@ast::pat) { s.ann.post(ann_node); } -fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident, - typarams: &[ast::ty_param], constrs: [@ast::constr]) { +fn print_fn(s: ps, decl: ast::fn_decl, proto: ast::proto, name: ast::ident, + typarams: [ast::ty_param], constrs: [@ast::constr]) { alt decl.purity { ast::impure_fn. { head(s, proto_to_str(proto)); } _ { head(s, "pure fn"); } @@ -1207,10 +1208,9 @@ fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident, print_fn_args_and_ret(s, decl, constrs); } -fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, - constrs: [@ast::constr]) { +fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) { popen(s); - fn print_arg(s: &ps, x: &ast::arg) { + fn print_arg(s: ps, x: ast::arg) { ibox(s, indent_unit); word_space(s, x.ident + ":"); print_alias(s, x.mode); @@ -1228,9 +1228,9 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, } } -fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { +fn print_fn_block_args(s: ps, decl: ast::fn_decl) { word(s.s, "|"); - fn print_arg(s: &ps, x: &ast::arg) { + fn print_arg(s: ps, x: ast::arg) { ibox(s, indent_unit); print_alias(s, x.mode); word(s.s, x.ident); @@ -1241,7 +1241,7 @@ fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -fn print_alias(s: &ps, m: ast::mode) { +fn print_alias(s: ps, m: ast::mode) { alt m { ast::by_mut_ref. { word_space(s, "&mutable"); } ast::by_move. { word(s.s, "-"); } @@ -1249,7 +1249,7 @@ fn print_alias(s: &ps, m: ast::mode) { } } -fn print_kind(s: &ps, kind: ast::kind) { +fn print_kind(s: ps, kind: ast::kind) { alt kind { ast::kind_unique. { word(s.s, "~"); } ast::kind_shared. { word(s.s, "@"); } @@ -1257,10 +1257,10 @@ fn print_kind(s: &ps, kind: ast::kind) { } } -fn print_type_params(s: &ps, params: &[ast::ty_param]) { +fn print_type_params(s: ps, params: [ast::ty_param]) { if vec::len(params) > 0u { word(s.s, "<"); - fn printParam(s: &ps, param: &ast::ty_param) { + fn printParam(s: ps, param: ast::ty_param) { print_kind(s, param.kind); word(s.s, param.ident); } @@ -1269,7 +1269,7 @@ fn print_type_params(s: &ps, params: &[ast::ty_param]) { } } -fn print_meta_item(s: &ps, item: &@ast::meta_item) { +fn print_meta_item(s: ps, item: @ast::meta_item) { ibox(s, indent_unit); alt item.node { ast::meta_word(name) { word(s.s, name); } @@ -1288,7 +1288,7 @@ fn print_meta_item(s: &ps, item: &@ast::meta_item) { end(s); } -fn print_view_item(s: &ps, item: &@ast::view_item) { +fn print_view_item(s: ps, item: @ast::view_item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); alt item.node { @@ -1318,9 +1318,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { for elt: ast::ident in mod_path { word(s.s, elt); word(s.s, "::"); } word(s.s, "{"); commasep(s, inconsistent, idents, - fn (s: &ps, w: &ast::import_ident) { - word(s.s, w.node.name) - }); + fn (s: ps, w: ast::import_ident) { word(s.s, w.node.name) }); word(s.s, "}"); } ast::view_item_import_glob(ids, _) { @@ -1335,7 +1333,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { ast::view_item_export(ids, _) { head(s, "export"); commasep(s, inconsistent, ids, - fn (s: &ps, w: &ast::ident) { word(s.s, w) }); + fn (s: ps, w: ast::ident) { word(s.s, w) }); } } word(s.s, ";"); @@ -1355,7 +1353,7 @@ fn operator_prec(op: ast::binop) -> int { fail; } -fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { +fn need_parens(expr: @ast::expr, outer_prec: int) -> bool { alt expr.node { ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec } ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec } @@ -1363,6 +1361,7 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { + // This may be too conservative in some cases ast::expr_assign(_, _) { true @@ -1380,14 +1379,14 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { } } -fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) { +fn print_maybe_parens(s: ps, expr: @ast::expr, outer_prec: int) { let add_them = need_parens(expr, outer_prec); if add_them { popen(s); } print_expr(s, expr); if add_them { pclose(s); } } -fn print_mutability(s: &ps, mut: &ast::mutability) { +fn print_mutability(s: ps, mut: ast::mutability) { alt mut { ast::mut. { word_nbsp(s, "mutable"); } ast::maybe_mut. { word_nbsp(s, "mutable?"); } @@ -1395,20 +1394,20 @@ fn print_mutability(s: &ps, mut: &ast::mutability) { } } -fn print_mt(s: &ps, mt: &ast::mt) { +fn print_mt(s: ps, mt: ast::mt) { print_mutability(s, mt.mut); print_type(s, mt.ty); } -fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>, - inputs: &[ast::ty_arg], output: &@ast::ty, - cf: &ast::controlflow, constrs: &[@ast::constr]) { +fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>, + inputs: [ast::ty_arg], output: @ast::ty, cf: ast::controlflow, + constrs: [@ast::constr]) { ibox(s, indent_unit); word(s.s, proto_to_str(proto)); alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } } zerobreak(s.s); popen(s); - fn print_arg(s: &ps, input: &ast::ty_arg) { + fn print_arg(s: ps, input: ast::ty_arg) { print_alias(s, input.node.mode); print_type(s, input.node.ty); } @@ -1429,7 +1428,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>, end(s); } -fn maybe_print_trailing_comment(s: &ps, span: codemap::span, +fn maybe_print_trailing_comment(s: ps, span: codemap::span, next_pos: option::t<uint>) { let cm; alt s.cm { some(ccm) { cm = ccm; } _ { ret; } } @@ -1450,7 +1449,7 @@ fn maybe_print_trailing_comment(s: &ps, span: codemap::span, } } -fn print_remaining_comments(s: &ps) { +fn print_remaining_comments(s: ps) { // If there aren't any remaining comments, then we need to manually // make sure there is a line break at the end. if option::is_none(next_comment(s)) { hardbreak(s.s); } @@ -1462,13 +1461,13 @@ fn print_remaining_comments(s: &ps) { } } -fn in_cbox(s: &ps) -> bool { +fn in_cbox(s: ps) -> bool { let len = vec::len(s.boxes); if len == 0u { ret false; } ret s.boxes[len - 1u] == pp::consistent; } -fn print_literal(s: &ps, lit: &@ast::lit) { +fn print_literal(s: ps, lit: @ast::lit) { maybe_print_comment(s, lit.span.lo); alt next_lit(s) { some(lt) { @@ -1502,9 +1501,9 @@ fn print_literal(s: &ps, lit: &@ast::lit) { } } -fn lit_to_str(l: &@ast::lit) -> str { be to_str(l, print_literal); } +fn lit_to_str(l: @ast::lit) -> str { be to_str(l, print_literal); } -fn next_lit(s: &ps) -> option::t<lexer::lit> { +fn next_lit(s: ps) -> option::t<lexer::lit> { alt s.literals { some(lits) { if s.cur_lit < vec::len(lits) { @@ -1515,7 +1514,7 @@ fn next_lit(s: &ps) -> option::t<lexer::lit> { } } -fn maybe_print_comment(s: &ps, pos: uint) { +fn maybe_print_comment(s: ps, pos: uint) { while true { alt next_comment(s) { some(cmnt) { @@ -1529,7 +1528,7 @@ fn maybe_print_comment(s: &ps, pos: uint) { } } -fn print_comment(s: &ps, cmnt: lexer::cmnt) { +fn print_comment(s: ps, cmnt: lexer::cmnt) { alt cmnt.style { lexer::mixed. { assert (vec::len(cmnt.lines) == 1u); @@ -1573,13 +1572,13 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } } -fn print_string(s: &ps, st: &str) { +fn print_string(s: ps, st: str) { word(s.s, "\""); word(s.s, escape_str(st, '"')); word(s.s, "\""); } -fn escape_str(st: &str, to_escape: char) -> str { +fn escape_str(st: str, to_escape: char) -> str { let out: str = ""; let len = str::byte_len(st); let i = 0u; @@ -1601,7 +1600,7 @@ fn escape_str(st: &str, to_escape: char) -> str { ret out; } -fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str { +fn to_str<T>(t: T, f: fn(ps, T)) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); f(s, t); @@ -1609,7 +1608,7 @@ fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str { ret writer.get_str(); } -fn next_comment(s: &ps) -> option::t<lexer::cmnt> { +fn next_comment(s: ps) -> option::t<lexer::cmnt> { alt s.comments { some(cmnts) { if s.cur_cmnt < vec::len(cmnts) { @@ -1622,8 +1621,8 @@ fn next_comment(s: &ps) -> option::t<lexer::cmnt> { // Removing the aliases from the type of f in the next two functions // triggers memory corruption, but I haven't isolated the bug yet. FIXME -fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>]) - -> str { +fn constr_args_to_str<T>(f: fn(T) -> str, args: [@ast::sp_constr_arg<T>]) -> + str { let comma = false; let s = "("; for a: @ast::sp_constr_arg<T> in args { @@ -1634,7 +1633,7 @@ fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>]) ret s; } -fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) -> +fn constr_arg_to_str<T>(f: fn(T) -> str, c: ast::constr_arg_general_<T>) -> str { alt c { ast::carg_base. { ret "*"; } @@ -1646,15 +1645,15 @@ fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) -> // needed b/c constr_args_to_str needs // something that takes an alias // (argh) -fn uint_to_str(i: &uint) -> str { ret uint::str(i); } +fn uint_to_str(i: uint) -> str { ret uint::str(i); } -fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> str { +fn ast_ty_fn_constr_to_str(c: @ast::constr) -> str { ret path_to_str(c.node.path) + constr_args_to_str(uint_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { +fn ast_ty_fn_constrs_str(constrs: [@ast::constr]) -> str { let s = ""; let colon = true; for c: @ast::constr in constrs { @@ -1664,18 +1663,18 @@ fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { ret s; } -fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str { +fn fn_arg_idx_to_str(decl: ast::fn_decl, idx: uint) -> str { decl.inputs[idx].ident } -fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str { +fn ast_fn_constr_to_str(decl: ast::fn_decl, c: @ast::constr) -> str { let arg_to_str = bind fn_arg_idx_to_str(decl, _); ret path_to_str(c.node.path) + constr_args_to_str(arg_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { +fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str { let s = ""; let colon = true; for c: @ast::constr in constrs { @@ -1685,7 +1684,7 @@ fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { ret s; } -fn proto_to_str(p: &ast::proto) -> str { +fn proto_to_str(p: ast::proto) -> str { ret alt p { ast::proto_fn. { "fn" } ast::proto_iter. { "iter" } @@ -1694,8 +1693,8 @@ fn proto_to_str(p: &ast::proto) -> str { }; } -fn ty_constr_to_str(c: &@ast::ty_constr) -> str { - fn ty_constr_path_to_str(p: &ast::path) -> str { "*." + path_to_str(p) } +fn ty_constr_to_str(c: @ast::ty_constr) -> str { + fn ty_constr_path_to_str(p: ast::path) -> str { "*." + path_to_str(p) } ret path_to_str(c.node.path) + constr_args_to_str::<ast::path>(ty_constr_path_to_str, @@ -1703,7 +1702,7 @@ fn ty_constr_to_str(c: &@ast::ty_constr) -> str { } -fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> str { +fn ast_ty_constrs_str(constrs: [@ast::ty_constr]) -> str { let s = ""; let colon = true; for c: @ast::ty_constr in constrs { diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs index 3d1a495fb2e..7261c357940 100644 --- a/src/comp/syntax/util/interner.rs +++ b/src/comp/syntax/util/interner.rs @@ -21,7 +21,7 @@ fn mk<@T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> { ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer}; } -fn intern<@T>(itr: &interner<T>, val: &T) -> uint { +fn intern<@T>(itr: interner<T>, val: T) -> uint { alt itr.map.find(val) { some(idx) { ret idx; } none. { @@ -33,7 +33,7 @@ fn intern<@T>(itr: &interner<T>, val: &T) -> uint { } } -fn get<@T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect[idx]; } +fn get<@T>(itr: interner<T>, idx: uint) -> T { ret itr.vect[idx]; } -fn len<T>(itr: &interner<T>) -> uint { ret vec::len(itr.vect); } +fn len<T>(itr: interner<T>) -> uint { ret vec::len(itr.vect); } diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index e075b1d821c..e4d0abb8f19 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -19,20 +19,20 @@ tag vt<E> { mk_vt(visitor<E>); } type visitor<E> = // takes the components so that one function can be // generic over constr and ty_constr - @{visit_mod: fn(&_mod, &span, &E, &vt<E>), - visit_view_item: fn(&@view_item, &E, &vt<E>), - visit_native_item: fn(&@native_item, &E, &vt<E>), - visit_item: fn(&@item, &E, &vt<E>), - visit_local: fn(&@local, &E, &vt<E>), - visit_block: fn(&ast::blk, &E, &vt<E>), - visit_stmt: fn(&@stmt, &E, &vt<E>), - visit_arm: fn(&arm, &E, &vt<E>), - visit_pat: fn(&@pat, &E, &vt<E>), - visit_decl: fn(&@decl, &E, &vt<E>), - visit_expr: fn(&@expr, &E, &vt<E>), - visit_ty: fn(&@ty, &E, &vt<E>), - visit_constr: fn(&path, &span, node_id, &E, &vt<E>), - visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id, &E, &vt<E>)}; + @{visit_mod: fn(_mod, span, E, vt<E>), + visit_view_item: fn(@view_item, E, vt<E>), + visit_native_item: fn(@native_item, E, vt<E>), + visit_item: fn(@item, E, vt<E>), + visit_local: fn(@local, E, vt<E>), + visit_block: fn(ast::blk, E, vt<E>), + visit_stmt: fn(@stmt, E, vt<E>), + visit_arm: fn(arm, E, vt<E>), + visit_pat: fn(@pat, E, vt<E>), + visit_decl: fn(@decl, E, vt<E>), + visit_expr: fn(@expr, E, vt<E>), + visit_ty: fn(@ty, E, vt<E>), + visit_constr: fn(path, span, node_id, E, vt<E>), + visit_fn: fn(_fn, [ty_param], span, fn_ident, node_id, E, vt<E>)}; fn default_visitor<E>() -> visitor<E> { ret @{visit_mod: bind visit_mod::<E>(_, _, _, _), @@ -51,11 +51,11 @@ fn default_visitor<E>() -> visitor<E> { visit_fn: bind visit_fn::<E>(_, _, _, _, _, _, _)}; } -fn visit_crate<E>(c: &crate, e: &E, v: &vt<E>) { +fn visit_crate<E>(c: crate, e: E, v: vt<E>) { v.visit_mod(c.node.module, c.span, e, v); } -fn visit_crate_directive<E>(cd: &@crate_directive, e: &E, v: &vt<E>) { +fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { alt cd.node { cdir_src_mod(_, _, _) { } cdir_dir_mod(_, _, cdirs, _) { @@ -69,20 +69,20 @@ fn visit_crate_directive<E>(cd: &@crate_directive, e: &E, v: &vt<E>) { } } -fn visit_mod<E>(m: &_mod, _sp: &span, e: &E, v: &vt<E>) { +fn visit_mod<E>(m: _mod, _sp: span, e: E, v: vt<E>) { for vi: @view_item in m.view_items { v.visit_view_item(vi, e, v); } for i: @item in m.items { v.visit_item(i, e, v); } } -fn visit_view_item<E>(_vi: &@view_item, _e: &E, _v: &vt<E>) { } +fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { } -fn visit_local<E>(loc: &@local, e: &E, v: &vt<E>) { +fn visit_local<E>(loc: @local, e: E, v: vt<E>) { v.visit_pat(loc.node.pat, e, v); v.visit_ty(loc.node.ty, e, v); alt loc.node.init { none. { } some(i) { v.visit_expr(i.expr, e, v); } } } -fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) { +fn visit_item<E>(i: @item, e: E, v: vt<E>) { alt i.node { item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } item_fn(f, tp) { v.visit_fn(f, tp, i.span, some(i.ident), i.id, e, v); } @@ -110,7 +110,7 @@ fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) { } } -fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) { +fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { alt t.node { ty_nil. {/* no-op */ } ty_bot. {/* no-op */ } @@ -156,12 +156,12 @@ fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) { } } -fn visit_constr<E>(_operator: &path, _sp: &span, _id: node_id, _e: &E, - _v: &vt<E>) { +fn visit_constr<E>(_operator: path, _sp: span, _id: node_id, _e: E, + _v: vt<E>) { // default } -fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) { +fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { alt p.node { pat_tag(path, children) { for tp: @ty in path.node.types { v.visit_ty(tp, e, v); } @@ -176,14 +176,14 @@ fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) { } } -fn visit_native_item<E>(ni: &@native_item, e: &E, v: &vt<E>) { +fn visit_native_item<E>(ni: @native_item, e: E, v: vt<E>) { alt ni.node { native_item_fn(_, fd, _) { visit_fn_decl(fd, e, v); } native_item_ty. { } } } -fn visit_fn_decl<E>(fd: &fn_decl, e: &E, v: &vt<E>) { +fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { for a: arg in fd.inputs { v.visit_ty(a.ty, e, v); } for c: @constr in fd.constraints { v.visit_constr(c.node.path, c.span, c.node.id, e, v); @@ -191,18 +191,18 @@ fn visit_fn_decl<E>(fd: &fn_decl, e: &E, v: &vt<E>) { v.visit_ty(fd.output, e, v); } -fn visit_fn<E>(f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident, - _id: node_id, e: &E, v: &vt<E>) { +fn visit_fn<E>(f: _fn, _tp: [ty_param], _sp: span, _i: fn_ident, _id: node_id, + e: E, v: vt<E>) { visit_fn_decl(f.decl, e, v); v.visit_block(f.body, e, v); } -fn visit_block<E>(b: &ast::blk, e: &E, v: &vt<E>) { +fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { for s: @stmt in b.node.stmts { v.visit_stmt(s, e, v); } visit_expr_opt(b.node.expr, e, v); } -fn visit_stmt<E>(s: &@stmt, e: &E, v: &vt<E>) { +fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { alt s.node { stmt_decl(d, _) { v.visit_decl(d, e, v); } stmt_expr(ex, _) { v.visit_expr(ex, e, v); } @@ -210,7 +210,7 @@ fn visit_stmt<E>(s: &@stmt, e: &E, v: &vt<E>) { } } -fn visit_decl<E>(d: &@decl, e: &E, v: &vt<E>) { +fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { alt d.node { decl_local(locs) { for loc: @ast::local in locs { v.visit_local(loc, e, v); } @@ -219,15 +219,15 @@ fn visit_decl<E>(d: &@decl, e: &E, v: &vt<E>) { } } -fn visit_expr_opt<E>(eo: option::t<@expr>, e: &E, v: &vt<E>) { +fn visit_expr_opt<E>(eo: option::t<@expr>, e: E, v: vt<E>) { alt eo { none. { } some(ex) { v.visit_expr(ex, e, v); } } } -fn visit_exprs<E>(exprs: &[@expr], e: &E, v: &vt<E>) { +fn visit_exprs<E>(exprs: [@expr], e: E, v: vt<E>) { for ex: @expr in exprs { v.visit_expr(ex, e, v); } } -fn visit_mac<E>(m: mac, e: &E, v: &vt<E>) { +fn visit_mac<E>(m: mac, e: E, v: vt<E>) { alt m.node { ast::mac_invoc(pth, arg, body) { visit_expr(arg, e, v); } ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); } @@ -236,7 +236,7 @@ fn visit_mac<E>(m: mac, e: &E, v: &vt<E>) { } } -fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { +fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { alt ex.node { expr_vec(es, _) { visit_exprs(es, e, v); } expr_rec(flds, base) { @@ -329,7 +329,7 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { } } -fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) { +fn visit_arm<E>(a: arm, e: E, v: vt<E>) { for p: @pat in a.pats { v.visit_pat(p, e, v); } visit_expr_opt(a.guard, e, v); v.visit_block(a.body, e, v); @@ -341,99 +341,99 @@ fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) { type simple_visitor = // takes the components so that one function can be // generic over constr and ty_constr - @{visit_mod: fn(&_mod, &span), - visit_view_item: fn(&@view_item), - visit_native_item: fn(&@native_item), - visit_item: fn(&@item), - visit_local: fn(&@local), - visit_block: fn(&ast::blk), - visit_stmt: fn(&@stmt), - visit_arm: fn(&arm), - visit_pat: fn(&@pat), - visit_decl: fn(&@decl), - visit_expr: fn(&@expr), - visit_ty: fn(&@ty), - visit_constr: fn(&path, &span, node_id), - visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id)}; + @{visit_mod: fn(_mod, span), + visit_view_item: fn(@view_item), + visit_native_item: fn(@native_item), + visit_item: fn(@item), + visit_local: fn(@local), + visit_block: fn(ast::blk), + visit_stmt: fn(@stmt), + visit_arm: fn(arm), + visit_pat: fn(@pat), + visit_decl: fn(@decl), + visit_expr: fn(@expr), + visit_ty: fn(@ty), + visit_constr: fn(path, span, node_id), + visit_fn: fn(_fn, [ty_param], span, fn_ident, node_id)}; fn default_simple_visitor() -> simple_visitor { - ret @{visit_mod: fn (_m: &_mod, _sp: &span) { }, - visit_view_item: fn (_vi: &@view_item) { }, - visit_native_item: fn (_ni: &@native_item) { }, - visit_item: fn (_i: &@item) { }, - visit_local: fn (_l: &@local) { }, - visit_block: fn (_b: &ast::blk) { }, - visit_stmt: fn (_s: &@stmt) { }, - visit_arm: fn (_a: &arm) { }, - visit_pat: fn (_p: &@pat) { }, - visit_decl: fn (_d: &@decl) { }, - visit_expr: fn (_e: &@expr) { }, - visit_ty: fn (_t: &@ty) { }, - visit_constr: fn (_p: &path, _sp: &span, _id: node_id) { }, + ret @{visit_mod: fn (_m: _mod, _sp: span) { }, + visit_view_item: fn (_vi: @view_item) { }, + visit_native_item: fn (_ni: @native_item) { }, + visit_item: fn (_i: @item) { }, + visit_local: fn (_l: @local) { }, + visit_block: fn (_b: ast::blk) { }, + visit_stmt: fn (_s: @stmt) { }, + visit_arm: fn (_a: arm) { }, + visit_pat: fn (_p: @pat) { }, + visit_decl: fn (_d: @decl) { }, + visit_expr: fn (_e: @expr) { }, + visit_ty: fn (_t: @ty) { }, + visit_constr: fn (_p: path, _sp: span, _id: node_id) { }, visit_fn: - fn (_f: &_fn, _tps: &[ty_param], _sp: &span, _ident: &fn_ident, + fn (_f: _fn, _tps: [ty_param], _sp: span, _ident: fn_ident, _id: node_id) { }}; } -fn mk_simple_visitor(v: &simple_visitor) -> vt<()> { - fn v_mod(f: fn(&_mod, &span), m: &_mod, sp: &span, e: &(), v: &vt<()>) { +fn mk_simple_visitor(v: simple_visitor) -> vt<()> { + fn v_mod(f: fn(_mod, span), m: _mod, sp: span, e: (), v: vt<()>) { f(m, sp); visit_mod(m, sp, e, v); } - fn v_view_item(f: fn(&@view_item), vi: &@view_item, e: &(), v: &vt<()>) { + fn v_view_item(f: fn(@view_item), vi: @view_item, e: (), v: vt<()>) { f(vi); visit_view_item(vi, e, v); } - fn v_native_item(f: fn(&@native_item), ni: &@native_item, e: &(), - v: &vt<()>) { + fn v_native_item(f: fn(@native_item), ni: @native_item, e: (), + v: vt<()>) { f(ni); visit_native_item(ni, e, v); } - fn v_item(f: fn(&@item), i: &@item, e: &(), v: &vt<()>) { + fn v_item(f: fn(@item), i: @item, e: (), v: vt<()>) { f(i); visit_item(i, e, v); } - fn v_local(f: fn(&@local), l: &@local, e: &(), v: &vt<()>) { + fn v_local(f: fn(@local), l: @local, e: (), v: vt<()>) { f(l); visit_local(l, e, v); } - fn v_block(f: fn(&ast::blk), bl: &ast::blk, e: &(), v: &vt<()>) { + fn v_block(f: fn(ast::blk), bl: ast::blk, e: (), v: vt<()>) { f(bl); visit_block(bl, e, v); } - fn v_stmt(f: fn(&@stmt), st: &@stmt, e: &(), v: &vt<()>) { + fn v_stmt(f: fn(@stmt), st: @stmt, e: (), v: vt<()>) { f(st); visit_stmt(st, e, v); } - fn v_arm(f: fn(&arm), a: &arm, e: &(), v: &vt<()>) { + fn v_arm(f: fn(arm), a: arm, e: (), v: vt<()>) { f(a); visit_arm(a, e, v); } - fn v_pat(f: fn(&@pat), p: &@pat, e: &(), v: &vt<()>) { + fn v_pat(f: fn(@pat), p: @pat, e: (), v: vt<()>) { f(p); visit_pat(p, e, v); } - fn v_decl(f: fn(&@decl), d: &@decl, e: &(), v: &vt<()>) { + fn v_decl(f: fn(@decl), d: @decl, e: (), v: vt<()>) { f(d); visit_decl(d, e, v); } - fn v_expr(f: fn(&@expr), ex: &@expr, e: &(), v: &vt<()>) { + fn v_expr(f: fn(@expr), ex: @expr, e: (), v: vt<()>) { f(ex); visit_expr(ex, e, v); } - fn v_ty(f: fn(&@ty), ty: &@ty, e: &(), v: &vt<()>) { + fn v_ty(f: fn(@ty), ty: @ty, e: (), v: vt<()>) { f(ty); visit_ty(ty, e, v); } - fn v_constr(f: fn(&path, &span, node_id), pt: &path, sp: &span, - id: node_id, e: &(), v: &vt<()>) { + fn v_constr(f: fn(path, span, node_id), pt: path, sp: span, id: node_id, + e: (), v: vt<()>) { f(pt, sp, id); visit_constr(pt, sp, id, e, v); } - fn v_fn(f: fn(&_fn, &[ty_param], &span, &fn_ident, node_id), ff: &_fn, - tps: &[ty_param], sp: &span, ident: &fn_ident, id: node_id, - e: &(), v: &vt<()>) { + fn v_fn(f: fn(_fn, [ty_param], span, fn_ident, node_id), ff: _fn, + tps: [ty_param], sp: span, ident: fn_ident, id: node_id, e: (), + v: vt<()>) { f(ff, tps, sp, ident, id); visit_fn(ff, tps, sp, ident, id, e, v); } |
