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.
This commit is contained in:
parent
64a6376da5
commit
fc6b7c8b38
209 changed files with 3358 additions and 3353 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
//
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
|
|
|
|||
|
|
@ -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)};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue