Make fn denote a bare function. Convert fn to fn@ as needed

This commit is contained in:
Brian Anderson 2011-10-18 15:07:40 -07:00
parent f324704c0a
commit 29ad3bdb10
64 changed files with 263 additions and 248 deletions

View file

@ -88,7 +88,7 @@ fn parse_input_src(sess: session::session, cfg: ast::crate_cfg, infile: str)
ret {crate: crate, src: src};
}
fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
fn time<@T>(do_it: bool, what: str, thunk: fn@() -> T) -> T {
if !do_it { ret thunk(); }
let start = std::time::precise_time_s();
let rv = thunk();

View file

@ -12,7 +12,7 @@ import front::attr;
export modify_for_testing;
type node_id_gen = fn() -> ast::node_id;
type node_id_gen = fn@() -> ast::node_id;
type test = {span: span, path: [ast::ident], ignore: bool};
@ -369,7 +369,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
il: ast::il_normal,
cf: ast::return_val,
constraints: []};
let proto = ast::proto_fn;
let proto = ast::proto_bare;
let test_main_call_expr = mk_test_main_call(cx);

View file

@ -28,9 +28,9 @@ export external_resolver;
// def_id for an item defined in another crate, somebody needs to figure out
// what crate that's in and give us a def_id that makes sense for the current
// build.
type external_resolver = fn(ast::def_id) -> ast::def_id;
type external_resolver = fn@(ast::def_id) -> ast::def_id;
fn lookup_hash(d: ebml::doc, eq_fn: fn([u8]) -> bool, hash: uint) ->
fn lookup_hash(d: ebml::doc, eq_fn: fn@([u8]) -> bool, hash: uint) ->
[ebml::doc] {
let index = ebml::get_doc(d, tag_index);
let table = ebml::get_doc(index, tag_index_table);

View file

@ -16,7 +16,7 @@ export parse_ty_data;
// data buffer. Whatever format you choose should not contain pipe characters.
// Callback to translate defs to strs or back:
type str_def = fn(str) -> ast::def_id;
type str_def = fn@(str) -> ast::def_id;
type pstate =
{data: @[u8], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt};
@ -34,7 +34,7 @@ fn parse_ident(st: @pstate, sd: str_def, last: char) -> ast::ident {
ret parse_ident_(st, sd, bind is_last(last, _));
}
fn parse_ident_(st: @pstate, _sd: str_def, is_last: fn(char) -> bool) ->
fn parse_ident_(st: @pstate, _sd: str_def, is_last: fn@(char) -> bool) ->
ast::ident {
let rslt = "";
while !is_last(peek(st) as char) {

View file

@ -24,7 +24,7 @@ type freevar_map = hashmap<ast::node_id, freevar_info>;
// Since we want to be able to collect upvars in some arbitrary piece
// of the AST, we take a walker function that we invoke with a visitor
// in order to start the search.
fn collect_freevars(def_map: resolve::def_map, walker: fn(visit::vt<int>)) ->
fn collect_freevars(def_map: resolve::def_map, walker: fn@(visit::vt<int>)) ->
freevar_info {
let seen = new_int_hash();
let refs = @mutable [];

View file

@ -595,6 +595,7 @@ fn lookup_in_scope_strict(e: env, sc: scopes, sp: span, name: ident,
fn scope_is_fn(sc: scope) -> bool {
ret alt sc {
scope_fn(_, ast::proto_iter., _) | scope_fn(_, ast::proto_fn., _) |
scope_fn(_, ast::proto_bare., _) |
scope_native_item(_) {
true
}

View file

@ -109,7 +109,7 @@ fn matches_always(p: @ast::pat) -> bool {
};
}
type enter_pat = fn(@ast::pat) -> option::t<[@ast::pat]>;
type enter_pat = fn@(@ast::pat) -> option::t<[@ast::pat]>;
fn enter_match(m: match, col: uint, val: ValueRef, e: enter_pat) -> match {
let result = [];
@ -314,7 +314,7 @@ fn any_tup_pat(m: match, col: uint) -> bool {
}
type exit_node = {bound: bind_map, from: BasicBlockRef, to: BasicBlockRef};
type mk_fail = fn() -> BasicBlockRef;
type mk_fail = fn@() -> BasicBlockRef;
fn pick_col(m: match) -> uint {
let scores = vec::init_elt_mut(0u, vec::len(m[0].pats));

View file

@ -259,8 +259,8 @@ type fn_ctxt =
lcx: @local_ctxt};
tag cleanup {
clean(fn(@block_ctxt) -> @block_ctxt);
clean_temp(ValueRef, fn(@block_ctxt) -> @block_ctxt);
clean(fn@(@block_ctxt) -> @block_ctxt);
clean_temp(ValueRef, fn@(@block_ctxt) -> @block_ctxt);
}
fn add_clean(cx: @block_ctxt, val: ValueRef, ty: ty::t) {

View file

@ -151,7 +151,7 @@ fn relax_precond_block(fcx: fn_ctxt, i: node_id, b: blk) {
visit_stmt: relax_precond_stmt,
visit_item:
fn (_i: @item, _cx: relax_ctxt, _vt: visit::vt<relax_ctxt>) { },
visit_fn: do_nothing
visit_fn: bind do_nothing(_, _, _, _, _, _, _)
with *visitor};
let v1 = visit::mk_vt(visitor);
v1.visit_block(b, cx, v1);

View file

@ -111,7 +111,8 @@ fn check_states_against_conditions(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param],
visitor =
@{visit_stmt: check_states_stmt,
visit_expr: check_states_expr,
visit_fn: do_nothing with *visitor};
visit_fn: bind do_nothing(_, _, _, _, _, _, _)
with *visitor};
visit::visit_fn(f, tps, sp, i, id, fcx, visit::mk_vt(visitor));
/* Check that the return value is initialized */

View file

@ -54,7 +54,8 @@ fn find_locals(tcx: ty::ctxt, f: _fn, tps: [ty_param], sp: span, i: fn_ident,
visitor =
@{visit_local: collect_local,
visit_expr: collect_pred,
visit_fn: do_nothing with *visitor};
visit_fn: bind do_nothing(_, _, _, _, _, _, _)
with *visitor};
visit::visit_fn(f, tps, sp, i, id, cx, visit::mk_vt(visitor));
ret cx;
}

View file

@ -603,7 +603,7 @@ fn cname(cx: ctxt, typ: t) -> option::t<str> {
// Type folds
type ty_walk = fn(t);
type ty_walk = fn@(t);
fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
alt struct(cx, ty) {
@ -655,9 +655,9 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
}
tag fold_mode {
fm_var(fn(int) -> t);
fm_param(fn(uint, ast::kind) -> t);
fm_general(fn(t) -> t);
fm_var(fn@(int) -> t);
fm_param(fn@(uint, ast::kind) -> t);
fm_general(fn@(t) -> t);
}
fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
@ -2712,13 +2712,14 @@ fn type_err_to_str(err: ty::type_err) -> str {
// Converts type parameters in a type to type variables and returns the
// resulting type along with a list of type variable IDs.
fn bind_params_in_type(sp: span, cx: ctxt, next_ty_var: fn() -> int, typ: t,
fn bind_params_in_type(sp: span, cx: ctxt, next_ty_var: fn@() -> int, typ: t,
ty_param_count: uint) -> {ids: [int], ty: t} {
let param_var_ids: @mutable [int] = @mutable [];
let i = 0u;
while i < ty_param_count { *param_var_ids += [next_ty_var()]; i += 1u; }
fn binder(sp: span, cx: ctxt, param_var_ids: @mutable [int],
_next_ty_var: fn() -> int, index: uint, _kind: ast::kind) -> t {
_next_ty_var: fn@() -> int, index: uint,
_kind: ast::kind) -> t {
if index < vec::len(*param_var_ids) {
ret mk_var(cx, param_var_ids[index]);
} else {

View file

@ -53,7 +53,7 @@ type fn_ctxt =
// Used for ast_ty_to_ty() below.
type ty_getter = fn(ast::def_id) -> ty::ty_param_kinds_and_ty;
type ty_getter = fn@(ast::def_id) -> ty::ty_param_kinds_and_ty;
fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> int {
alt fcx.locals.find(id) {
@ -516,8 +516,8 @@ mod collect {
ret k;
}
fn ty_of_fn_decl(cx: @ctxt, convert: fn(&&@ast::ty) -> ty::t,
ty_of_arg: fn(ast::arg) -> arg, decl: ast::fn_decl,
fn ty_of_fn_decl(cx: @ctxt, convert: fn@(&&@ast::ty) -> ty::t,
ty_of_arg: fn@(ast::arg) -> arg, decl: ast::fn_decl,
proto: ast::proto, ty_params: [ast::ty_param],
def_id: option::t<ast::def_id>) ->
ty::ty_param_kinds_and_ty {
@ -536,8 +536,8 @@ mod collect {
alt def_id { some(did) { cx.tcx.tcache.insert(did, tpt); } _ { } }
ret tpt;
}
fn ty_of_native_fn_decl(cx: @ctxt, convert: fn(&&@ast::ty) -> ty::t,
ty_of_arg: fn(ast::arg) -> arg,
fn ty_of_native_fn_decl(cx: @ctxt, convert: fn@(&&@ast::ty) -> ty::t,
ty_of_arg: fn@(ast::arg) -> arg,
decl: ast::fn_decl, abi: ast::native_abi,
ty_params: [ast::ty_param], def_id: ast::def_id)
-> ty::ty_param_kinds_and_ty {
@ -1227,8 +1227,10 @@ fn gather_locals(ccx: @crate_ctxt, f: ast::_fn, id: ast::node_id,
let visit =
@{visit_local: visit_local,
visit_pat: visit_pat,
visit_fn: visit_fn,
visit_item: visit_item with *visit::default_visitor()};
visit_fn: bind visit_fn(_, _, _, _, _, _, _),
visit_item: bind visit_item(_, _, _)
with *visit::default_visitor()};
visit::visit_block(f.body, (), visit::mk_vt(visit));
ret {var_bindings: vb,
locals: locals,
@ -2787,7 +2789,7 @@ fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool {
fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id) {
let main_t = ty::node_id_to_monotype(tcx, main_id);
alt ty::struct(tcx, main_t) {
ty::ty_fn(ast::proto_fn., args, rs, ast::return_val., constrs) {
ty::ty_fn(ast::proto_bare., args, rs, ast::return_val., constrs) {
let ok = vec::len(constrs) == 0u;
ok &= ty::type_is_nil(tcx, rs);
let num_args = vec::len(args);

View file

@ -6,10 +6,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);

View file

@ -11,7 +11,7 @@ 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_ {
fld: ast_fold, orig: fn@(expr_, ast_fold) -> expr_) -> expr_ {
ret alt e {
expr_mac(mac) {
alt mac.node {

View file

@ -72,7 +72,7 @@ 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]) ->
{pre: [@expr], rep: option::t<@expr>, post: [@expr]} {
@ -104,7 +104,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 {
@ -263,7 +263,7 @@ 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] {
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);
@ -351,7 +351,7 @@ 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_) ->
orig: fn@(ast::expr_, ast_fold) -> ast::expr_) ->
ast::expr_ {
ret alt e {
expr_path(p) {
@ -378,7 +378,7 @@ 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_ {
orig: fn@(ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ {
ret alt t {
ast::ty_path(pth, _) {
alt path_to_ident(pth) {
@ -402,7 +402,7 @@ fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
blk: blk_, fld: ast_fold,
orig: fn(blk_, ast_fold) -> blk_) -> blk_ {
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) {

View file

@ -20,58 +20,59 @@ 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],
new_id: fn(node_id) -> node_id,
new_span: fn(span) -> span};
{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};
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],
new_id: fn(node_id) -> node_id,
new_span: fn(span) -> span};
{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};
//fn nf_dummy<T>(&T node) -> T { fail; }
@ -119,7 +120,7 @@ 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};
@ -495,7 +496,7 @@ 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);
}
@ -568,32 +569,34 @@ resource foldres(f: ast_fold) {
}
fn make_fold(afp: ast_fold_precursor) -> @foldres {
// FIXME: Have to bind all the bare functions into shared functions
// because @mutable is invariant with respect to its contents
let result: ast_fold =
@mutable {fold_crate: nf_crate_dummy,
fold_crate_directive: nf_crate_directive_dummy,
fold_view_item: nf_view_item_dummy,
fold_native_item: nf_native_item_dummy,
fold_item: nf_item_dummy,
fold_item_underscore: nf_item_underscore_dummy,
fold_method: nf_method_dummy,
fold_block: nf_blk_dummy,
fold_stmt: nf_stmt_dummy,
fold_arm: nf_arm_dummy,
fold_pat: nf_pat_dummy,
fold_decl: nf_decl_dummy,
fold_expr: nf_expr_dummy,
fold_ty: nf_ty_dummy,
fold_constr: nf_constr_dummy,
fold_fn: nf_fn_dummy,
fold_mod: nf_mod_dummy,
fold_native_mod: nf_native_mod_dummy,
fold_variant: nf_variant_dummy,
fold_ident: nf_ident_dummy,
fold_path: nf_path_dummy,
fold_local: nf_local_dummy,
map_exprs: noop_map_exprs,
new_id: noop_id,
new_span: noop_span};
@mutable {fold_crate: bind nf_crate_dummy(_),
fold_crate_directive: bind nf_crate_directive_dummy(_),
fold_view_item: bind nf_view_item_dummy(_),
fold_native_item: bind nf_native_item_dummy(_),
fold_item: bind nf_item_dummy(_),
fold_item_underscore: bind nf_item_underscore_dummy(_),
fold_method: bind nf_method_dummy(_),
fold_block: bind nf_blk_dummy(_),
fold_stmt: bind nf_stmt_dummy(_),
fold_arm: bind nf_arm_dummy(_),
fold_pat: bind nf_pat_dummy(_),
fold_decl: bind nf_decl_dummy(_),
fold_expr: bind nf_expr_dummy(_),
fold_ty: bind nf_ty_dummy(_),
fold_constr: bind nf_constr_dummy(_),
fold_fn: bind nf_fn_dummy(_),
fold_mod: bind nf_mod_dummy(_),
fold_native_mod: bind nf_native_mod_dummy(_),
fold_variant: bind nf_variant_dummy(_),
fold_ident: bind nf_ident_dummy(_),
fold_path: bind nf_path_dummy(_),
fold_local: bind nf_local_dummy(_),
map_exprs: bind noop_map_exprs(_, _),
new_id: bind noop_id(_),
new_span: bind noop_span(_)};
/* naturally, a macro to write these would be nice */
fn f_crate(afp: ast_fold_precursor, f: ast_fold, c: crate) -> crate {

View file

@ -390,7 +390,8 @@ fn parse_constr_in_type(p: parser) -> @ast::ty_constr {
}
fn parse_constrs<T>(pser: fn(parser) -> @ast::constr_general<T>, p: parser) ->
fn parse_constrs<T>(pser: fn@(parser) -> @ast::constr_general<T>,
p: parser) ->
[@ast::constr_general<T>] {
let constrs: [@ast::constr_general<T>] = [];
while true {
@ -602,7 +603,7 @@ fn parse_fn_block_arg(p: parser) -> ast::arg {
}
fn parse_seq_to_before_gt<@T>(sep: option::t<token::token>,
f: fn(parser) -> T,
f: fn@(parser) -> T,
p: parser) -> [T] {
let first = true;
let v = [];
@ -618,7 +619,7 @@ fn parse_seq_to_before_gt<@T>(sep: option::t<token::token>,
ret v;
}
fn parse_seq_to_gt<@T>(sep: option::t<token::token>, f: fn(parser) -> T,
fn parse_seq_to_gt<@T>(sep: option::t<token::token>, f: fn@(parser) -> T,
p: parser) -> [T] {
let v = parse_seq_to_before_gt(sep, f, p);
expect_gt(p);
@ -626,7 +627,7 @@ fn parse_seq_to_gt<@T>(sep: option::t<token::token>, f: fn(parser) -> T,
ret v;
}
fn parse_seq_lt_gt<@T>(sep: option::t<token::token>, f: fn(parser) -> T,
fn parse_seq_lt_gt<@T>(sep: option::t<token::token>, f: fn@(parser) -> T,
p: parser) -> spanned<[T]> {
let lo = p.get_lo_pos();
expect(p, token::LT);
@ -645,7 +646,7 @@ fn parse_seq_to_end<@T>(ket: token::token, sep: option::t<token::token>,
fn parse_seq_to_before_end<@T>(ket: token::token,
sep: option::t<token::token>,
f: fn(parser) -> T, p: parser) -> [T] {
f: fn@(parser) -> T, p: parser) -> [T] {
let first: bool = true;
let v: [T] = [];
while p.peek() != ket {
@ -660,7 +661,7 @@ fn parse_seq_to_before_end<@T>(ket: token::token,
fn parse_seq<@T>(bra: token::token, ket: token::token,
sep: option::t<token::token>, f: fn(parser) -> T, p: parser)
sep: option::t<token::token>, f: fn@(parser) -> T, p: parser)
-> spanned<[T]> {
let lo = p.get_lo_pos();
expect(p, bra);
@ -2141,7 +2142,7 @@ fn parse_fn_item_proto(p: parser) -> ast::proto {
p.bump();
ast::proto_fn
} else {
ast::proto_fn
ast::proto_bare
}
}
@ -2153,7 +2154,7 @@ fn parse_fn_ty_proto(p: parser) -> ast::proto {
p.bump();
ast::proto_fn
} else {
ast::proto_fn
ast::proto_bare
}
}
@ -2165,7 +2166,7 @@ fn parse_fn_anon_proto(p: parser) -> ast::proto {
p.bump();
ast::proto_fn
} else {
ast::proto_fn
ast::proto_bare
}
}
@ -2198,7 +2199,8 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
} else if is_word(p, "unsafe") && p.look_ahead(1u) != token::LBRACE {
p.bump();
expect_word(p, "fn");
ret some(parse_item_fn_or_iter(p, ast::unsafe_fn, ast::proto_fn,
let proto = parse_fn_item_proto(p);
ret some(parse_item_fn_or_iter(p, ast::unsafe_fn, proto,
attrs, ast::il_normal));
} else if eat_word(p, "iter") {
ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_iter,

View file

@ -18,7 +18,7 @@ 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) { }
@ -352,7 +352,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,
print_fn(s, decl, ast::proto_bare, item.ident, typarams,
decl.constraints);
alt lname {
none. { }
@ -1557,7 +1557,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);
@ -1578,7 +1578,7 @@ 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>]) ->
fn constr_args_to_str<T>(f: fn@(T) -> str, args: [@ast::sp_constr_arg<T>]) ->
str {
let comma = false;
let s = "(";
@ -1590,7 +1590,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 "*"; }
@ -1643,11 +1643,11 @@ fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str {
fn proto_to_str(p: ast::proto) -> str {
ret alt p {
ast::proto_fn. { "fn" }
ast::proto_fn. { "fn@" }
ast::proto_iter. { "iter" }
ast::proto_block. { "block" }
ast::proto_closure. { "lambda" }
ast::proto_bare. { "fn#" }
ast::proto_bare. { "fn" }
};
}

View file

@ -18,20 +18,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>(_, _, _, _),
@ -341,97 +341,97 @@ 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 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: (),
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,
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,
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);