Merge branch 'master' of github.com:graydon/rust

This commit is contained in:
Graydon Hoare 2011-12-22 14:50:52 -08:00
commit dcd771cd48
23 changed files with 334 additions and 404 deletions

View File

@ -51,7 +51,7 @@ fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
// we want to be main.
fn nomain(&&item: @ast::item) -> option::t<@ast::item> {
alt item.node {
ast::item_fn(f, _) {
ast::item_fn(_, _, _) {
if item.ident == "main" {
option::none
} else { option::some(item) }
@ -83,7 +83,7 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) ->
if is_test_fn(i) {
alt i.node {
ast::item_fn(f, _) when f.decl.purity == ast::unsafe_fn {
ast::item_fn(decl, _, _) when decl.purity == ast::unsafe_fn {
cx.sess.span_fatal(
i.span,
"unsafe functions cannot be used for tests");
@ -110,9 +110,9 @@ fn is_test_fn(i: @ast::item) -> bool {
fn has_test_signature(i: @ast::item) -> bool {
alt i.node {
ast::item_fn(f, tps) {
let input_cnt = vec::len(f.decl.inputs);
let no_output = f.decl.output.node == ast::ty_nil;
ast::item_fn(decl, tps, _) {
let input_cnt = vec::len(decl.inputs);
let no_output = decl.output.node == ast::ty_nil;
let tparm_cnt = vec::len(tps);
input_cnt == 0u && no_output && tparm_cnt == 0u
}
@ -190,13 +190,12 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
let ret_ty = mk_test_desc_vec_ty(cx);
let decl: ast::fn_decl =
{inputs: [],
{proto: ast::proto_bare,
inputs: [],
output: ret_ty,
purity: ast::impure_fn,
il: ast::il_normal,
cf: ast::return_val,
constraints: []};
let proto = ast::proto_bare;
// The vector of test_descs for this crate
let test_descs = mk_test_desc_vec(cx);
@ -205,9 +204,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
default_block([], option::some(test_descs), cx.sess.next_node_id());
let body = nospan(body_);
let fn_ = {decl: decl, proto: proto, body: body};
let item_ = ast::item_fn(fn_, []);
let item_ = ast::item_fn(decl, [], body);
let item: ast::item =
{ident: "tests",
attrs: [],
@ -325,10 +322,10 @@ fn mk_test_wrapper(cx: test_ctxt,
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
let wrapper_decl: ast::fn_decl = {
proto: ast::proto_bare,
inputs: [],
output: @nospan(ast::ty_nil),
purity: ast::impure_fn,
il: ast::il_normal,
cf: ast::return_val,
constraints: []
};
@ -341,12 +338,6 @@ fn mk_test_wrapper(cx: test_ctxt,
rules: ast::default_blk
});
let wrapper_fn: ast::_fn = {
decl: wrapper_decl,
proto: ast::proto_bare,
body: wrapper_body
};
let wrapper_capture: @ast::capture_clause = @{
copies: [],
moves: []
@ -354,7 +345,7 @@ fn mk_test_wrapper(cx: test_ctxt,
let wrapper_expr: ast::expr = {
id: cx.sess.next_node_id(),
node: ast::expr_fn(wrapper_fn, wrapper_capture),
node: ast::expr_fn(wrapper_decl, wrapper_body, wrapper_capture),
span: span
};
@ -375,13 +366,12 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
let ret_ty = nospan(ast::ty_nil);
let decl: ast::fn_decl =
{inputs: [args_arg],
{proto: ast::proto_bare,
inputs: [args_arg],
output: @ret_ty,
purity: ast::impure_fn,
il: ast::il_normal,
cf: ast::return_val,
constraints: []};
let proto = ast::proto_bare;
let test_main_call_expr = mk_test_main_call(cx);
@ -390,9 +380,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
cx.sess.next_node_id());
let body = {node: body_, span: dummy_sp()};
let fn_ = {decl: decl, proto: proto, body: body};
let item_ = ast::item_fn(fn_, []);
let item_ = ast::item_fn(decl, [], body);
let item: ast::item =
{ident: "main",
attrs: [],

View File

@ -62,8 +62,6 @@ const tag_crate_deps: uint = 0x25u;
// A single crate dependency
const tag_crate_dep: uint = 0x26u;
const tag_items_data_item_inlineness: uint = 0x27u;
const tag_crate_hash: uint = 0x28u;
const tag_mod_impl: uint = 0x30u;

View File

@ -74,7 +74,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
}
item_fn(_, tps) {
item_fn(_, tps, _) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
@ -105,7 +105,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
encode_def_id(ebml_w, local_def(it.id));
ebml::end_tag(ebml_w);
}
item_res(_, _, tps, ctor_id) {
item_res(_, tps, _, _, ctor_id) {
add_to_index(ebml_w, path, index, it.ident);
ebml::start_tag(ebml_w, tag_paths_data_item);
encode_name(ebml_w, it.ident);
@ -173,12 +173,6 @@ fn encode_family(ebml_w: ebml::writer, c: u8) {
ebml::end_tag(ebml_w);
}
fn encode_inlineness(ebml_w: ebml::writer, c: u8) {
ebml::start_tag(ebml_w, tag_items_data_item_inlineness);
ebml_w.writer.write([c]);
ebml::end_tag(ebml_w);
}
fn def_to_str(did: def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
fn encode_type_param_kinds(ebml_w: ebml::writer, tps: [ty_param]) {
@ -282,20 +276,15 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_symbol(ecx, ebml_w, item.id);
ebml::end_tag(ebml_w);
}
item_fn(fd, tps) {
item_fn(decl, tps, _) {
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
encode_family(ebml_w,
alt fd.decl.purity {
alt decl.purity {
unsafe_fn. { 'u' }
pure_fn. { 'p' }
impure_fn. { 'f' }
} as u8);
encode_inlineness(ebml_w,
alt fd.decl.il {
il_normal. { 'n' }
il_inline. { 'i' }
} as u8);
encode_type_param_kinds(ebml_w, tps);
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
encode_symbol(ecx, ebml_w, item.id);
@ -333,7 +322,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
ebml::end_tag(ebml_w);
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
}
item_res(_, _, tps, ctor_id) {
item_res(_, tps, _, _, ctor_id) {
let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
ebml::start_tag(ebml_w, tag_items_data_item);
@ -383,22 +372,21 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_name(ebml_w, item.ident);
for m in methods {
ebml::start_tag(ebml_w, tag_impl_method);
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.node.id))));
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
ebml::end_tag(ebml_w);
}
ebml::end_tag(ebml_w);
for m in methods {
index += [{val: m.node.id, pos: ebml_w.writer.tell()}];
index += [{val: m.id, pos: ebml_w.writer.tell()}];
ebml::start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, local_def(m.node.id));
encode_def_id(ebml_w, local_def(m.id));
encode_family(ebml_w, 'f' as u8);
encode_inlineness(ebml_w, 'n' as u8);
encode_type_param_kinds(ebml_w, tps + m.node.tps);
encode_type_param_kinds(ebml_w, tps + m.tps);
encode_type(ecx, ebml_w,
node_id_to_monotype(ecx.ccx.tcx, m.node.id));
encode_name(ebml_w, m.node.ident);
encode_symbol(ecx, ebml_w, m.node.id);
node_id_to_monotype(ecx.ccx.tcx, m.id));
encode_name(ebml_w, m.ident);
encode_symbol(ecx, ebml_w, m.id);
ebml::end_tag(ebml_w);
}
}

View File

@ -68,13 +68,13 @@ fn map_item(cx: ctx, i: @item) {
item_obj(ob, _, ctor_id) {
cx.map.insert(ctor_id, node_obj_ctor(i));
for m in ob.methods {
cx.map.insert(m.node.id, node_obj_method(m));
cx.map.insert(m.id, node_obj_method(m));
}
}
item_impl(_, _, ms) {
for m in ms { cx.map.insert(m.node.id, node_method(m)); }
for m in ms { cx.map.insert(m.id, node_method(m)); }
}
item_res(_, dtor_id, _, ctor_id) {
item_res(_, _, _, dtor_id, ctor_id) {
cx.map.insert(ctor_id, node_res_ctor(i));
cx.map.insert(dtor_id, node_item(i));
}

View File

@ -721,23 +721,23 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
let (ident, ret_ty, id) = alt cx.ast_map.get(fcx.id) {
ast_map::node_item(item) {
alt item.node {
ast::item_fn(f, _) | ast::item_res(f, _, _, _) {
(item.ident, f.decl.output, item.id)
ast::item_fn(decl, _, _) | ast::item_res(decl, _, _, _, _) {
(item.ident, decl.output, item.id)
}
}
}
ast_map::node_obj_method(method) {
(method.node.ident, method.node.meth.decl.output, method.node.id)
(method.ident, method.decl.output, method.id)
}
ast_map::node_res_ctor(item) {
alt item.node { ast::item_res(f, _, _, ctor_id) {
(item.ident, f.decl.output, ctor_id)
alt item.node { ast::item_res(decl, _, _, _, ctor_id) {
(item.ident, decl.output, ctor_id)
}}
}
ast_map::node_expr(expr) {
alt expr.node {
ast::expr_fn(f, _) {
(dbg_cx.names.next("fn"), f.decl.output, expr.id)
ast::expr_fn(decl, _, _) {
(dbg_cx.names.next("fn"), decl.output, expr.id)
}
ast::expr_fn_block(decl, _) {
(dbg_cx.names.next("fn"), decl.output, expr.id)

View File

@ -38,8 +38,8 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
let walk_expr =
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
alt expr.node {
ast::expr_fn(f, captures) {
if f.proto != ast::proto_bare {
ast::expr_fn(decl, _, captures) {
if decl.proto != ast::proto_bare {
visit::visit_expr(expr, depth + 1, v);
}
}

View File

@ -178,8 +178,9 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
}
}
expr_ternary(_, a, b) { maybe_copy(cx, a); maybe_copy(cx, b); }
expr_fn(_, cap_clause) { check_fn_cap_clause(cx, e.id, *cap_clause); }
expr_fn(_, _, cap_clause) {
check_fn_cap_clause(cx, e.id, *cap_clause);
}
_ { }
}
visit::visit_expr(e, cx, v);

View File

@ -136,7 +136,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
for arg in args {
alt arg.node {
//NDM--register captured as uses
expr_fn(_, captured) { fns += [arg]; }
expr_fn(_, _, captured) { fns += [arg]; }
expr_fn_block(_, _) { fns += [arg]; }
_ {
alt arg_ts[i].mode {

View File

@ -337,7 +337,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
visit_ty: bind walk_ty(e, _, _, _),
visit_constr: bind walk_constr(e, _, _, _, _, _),
visit_fn_proto:
bind visit_fn_proto_with_scope(e, _, _, _, _, _, _, _),
bind visit_fn_proto_with_scope(e, _, _, _, _, _, _, _, _),
visit_fn_block:
bind visit_fn_block_with_scope(e, _, _, _, _, _, _)
with *visit::default_visitor()};
@ -353,7 +353,7 @@ fn resolve_names(e: @env, c: @ast::crate) {
lookup_path_strict(*e, sc, exp.span, p.node,
ns_value));
}
ast::expr_fn(_, cap_clause) {
ast::expr_fn(_, _, cap_clause) {
let rci = bind resolve_capture_item(e, sc, _);
vec::iter(cap_clause.copies, rci);
vec::iter(cap_clause.moves, rci);
@ -404,8 +404,8 @@ fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) {
ast::item_impl(tps, sty, methods) {
visit::visit_ty(sty, sc, v);
for m in methods {
v.visit_fn_proto(m.node.meth, tps + m.node.tps, m.span,
some(m.node.ident), m.node.id, sc, v);
v.visit_fn_proto(m.decl, tps + m.tps, m.body, m.span,
some(m.ident), m.id, sc, v);
}
}
_ { visit::visit_item(i, sc, v); }
@ -417,9 +417,9 @@ fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes,
visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v);
}
fn visit_fn_proto_with_scope(e: @env, f: ast::_fn, tp: [ast::ty_param],
sp: span, name: fn_ident, id: node_id,
sc: scopes, v: vt<scopes>) {
fn visit_fn_proto_with_scope(e: @env, decl: ast::fn_decl, tp: [ast::ty_param],
body: ast::blk, sp: span, name: fn_ident,
id: node_id, sc: scopes, v: vt<scopes>) {
// is this a main fn declaration?
alt name {
some(nm) {
@ -434,13 +434,13 @@ fn visit_fn_proto_with_scope(e: @env, f: ast::_fn, tp: [ast::ty_param],
// here's where we need to set up the mapping
// for f's constrs in the table.
for c: @ast::constr in f.decl.constraints { resolve_constr(e, c, sc, v); }
let scope = alt f.proto {
ast::proto_bare. { scope_bare_fn(f.decl, id, tp) }
_ { scope_fn_expr(f.decl, id, tp) }
for c: @ast::constr in decl.constraints { resolve_constr(e, c, sc, v); }
let scope = alt decl.proto {
ast::proto_bare. { scope_bare_fn(decl, id, tp) }
_ { scope_fn_expr(decl, id, tp) }
};
visit::visit_fn_proto(f, tp, sp, name, id, cons(scope, @sc), v);
visit::visit_fn_proto(decl, tp, body, sp, name, id, cons(scope, @sc), v);
}
fn visit_fn_block_with_scope(_e: @env, decl: fn_decl, blk: ast::blk,
@ -1053,9 +1053,9 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> {
ast::item_const(_, _) {
if ns == ns_value { ret some(ast::def_const(local_def(i.id))); }
}
ast::item_fn(f, _) {
ast::item_fn(decl, _, _) {
if ns == ns_value {
ret some(ast::def_fn(local_def(i.id), f.decl.purity));
ret some(ast::def_fn(local_def(i.id), decl.purity));
}
}
ast::item_mod(_) {
@ -1067,7 +1067,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> {
ast::item_ty(_, _) {
if ns == ns_type { ret some(ast::def_ty(local_def(i.id))); }
}
ast::item_res(_, _, _, ctor_id) {
ast::item_res(_, _, _, _, ctor_id) {
alt ns {
ns_value. {
ret some(ast::def_fn(local_def(ctor_id), ast::impure_fn));
@ -1319,9 +1319,9 @@ fn index_mod(md: ast::_mod) -> mod_index {
}
for it: @ast::item in md.items {
alt it.node {
ast::item_const(_, _) | ast::item_fn(_, _) | ast::item_mod(_) |
ast::item_const(_, _) | ast::item_fn(_, _, _) | ast::item_mod(_) |
ast::item_native_mod(_) | ast::item_ty(_, _) |
ast::item_res(_, _, _, _) | ast::item_obj(_, _, _) |
ast::item_res(_, _, _, _, _) | ast::item_obj(_, _, _) |
ast::item_impl(_, _, _) {
add_to_index(index, it.ident, mie_item(it));
}
@ -1479,8 +1479,8 @@ fn check_item(e: @env, i: @ast::item, &&x: (), v: vt<()>) {
}
visit::visit_item(i, x, v);
alt i.node {
ast::item_fn(f, ty_params) {
check_fn(*e, i.span, f);
ast::item_fn(decl, ty_params, _) {
check_fn(*e, i.span, decl);
ensure_unique(*e, i.span, typaram_names(ty_params), ident_id,
"type parameter");
}
@ -1488,7 +1488,7 @@ fn check_item(e: @env, i: @ast::item, &&x: (), v: vt<()>) {
fn field_name(field: ast::obj_field) -> ident { ret field.ident; }
ensure_unique(*e, i.span, ob.fields, field_name, "object field");
for m: @ast::method in ob.methods {
check_fn(*e, m.span, m.node.meth);
check_fn(*e, m.span, m.decl);
}
ensure_unique(*e, i.span, typaram_names(ty_params), ident_id,
"type parameter");
@ -1568,11 +1568,11 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
ast::item_mod(_) | ast::item_native_mod(_) {
add_name(mods, it.span, it.ident);
}
ast::item_const(_, _) | ast::item_fn(_, _) {
ast::item_const(_, _) | ast::item_fn(_, _, _) {
add_name(values, it.span, it.ident);
}
ast::item_ty(_, _) { add_name(types, it.span, it.ident); }
ast::item_res(_, _, _, _) | ast::item_obj(_, _, _) {
ast::item_res(_, _, _, _, _) | ast::item_obj(_, _, _) {
add_name(types, it.span, it.ident);
add_name(values, it.span, it.ident);
}
@ -1586,9 +1586,9 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
}
}
fn check_fn(e: env, sp: span, f: ast::_fn) {
fn check_fn(e: env, sp: span, decl: ast::fn_decl) {
fn arg_name(a: ast::arg) -> ident { ret a.ident; }
ensure_unique(e, sp, f.decl.inputs, arg_name, "argument");
ensure_unique(e, sp, decl.inputs, arg_name, "argument");
}
fn check_expr(e: @env, ex: @ast::expr, &&x: (), v: vt<()>) {
@ -1775,9 +1775,9 @@ fn find_impls_in_item(i: @ast::item, &impls: [@_impl],
impls += [@{did: local_def(i.id),
ident: i.ident,
methods: vec::map(mthds, {|m|
@{did: local_def(m.node.id),
n_tps: vec::len(m.node.tps),
ident: m.node.ident}
@{did: local_def(m.id),
n_tps: vec::len(m.tps),
ident: m.ident}
})}];
}
}

View File

@ -3554,17 +3554,16 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
assert op != ast::deref; // lvals are handled above
ret trans_unary(bcx, op, x, e.id, dest);
}
ast::expr_fn(f, cap_clause) {
ast::expr_fn(decl, body, cap_clause) {
ret trans_closure::trans_expr_fn(
bcx, f, e.span, e.id, *cap_clause, dest);
bcx, decl, body, e.span, e.id, *cap_clause, dest);
}
ast::expr_fn_block(decl, body) {
alt ty::struct(tcx, ty::expr_ty(tcx, e)) {
ty::ty_fn(proto, _, _, _, _) {
let f: ast::_fn = { decl: decl, proto: proto, body: body };
let cap_clause = { copies: [], moves: [] };
ret trans_closure::trans_expr_fn(
bcx, f, e.span, e.id, cap_clause, dest);
bcx, decl, body, e.span, e.id, cap_clause, dest);
}
_ {
fail "Type of fn block is not a function!";
@ -4516,14 +4515,15 @@ tag self_arg { obj_self(ty::t); impl_self(ty::t); no_self; }
// trans_closure: Builds an LLVM function out of a source function.
// If the function closes over its environment a closure will be
// returned.
fn trans_closure(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
fn trans_closure(cx: @local_ctxt, sp: span, decl: ast::fn_decl,
body: ast::blk, llfndecl: ValueRef,
ty_self: self_arg, ty_params: [ast::ty_param],
id: ast::node_id, maybe_load_env: block(@fn_ctxt)) {
set_uwtable(llfndecl);
// Set up arguments to the function.
let fcx = new_fn_ctxt_w_id(cx, sp, llfndecl, id, f.decl.cf);
create_llargs_for_fn_args(fcx, ty_self, f.decl.inputs, ty_params);
let fcx = new_fn_ctxt_w_id(cx, sp, llfndecl, id, decl.cf);
create_llargs_for_fn_args(fcx, ty_self, decl.inputs, ty_params);
alt ty_self {
obj_self(_) {
populate_fn_ctxt_from_llself(fcx, option::get(fcx.llself));
@ -4535,10 +4535,10 @@ fn trans_closure(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
// pass to finish_fn later.
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let block_ty = node_id_type(cx.ccx, f.body.node.id);
let block_ty = node_id_type(cx.ccx, body.node.id);
let arg_tys = arg_tys_of_fn(fcx.lcx.ccx, id);
bcx = copy_args_to_allocas(fcx, bcx, f.decl.inputs, arg_tys);
bcx = copy_args_to_allocas(fcx, bcx, decl.inputs, arg_tys);
maybe_load_env(fcx);
@ -4548,14 +4548,14 @@ fn trans_closure(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
// (trans_block, trans_expr, et cetera).
if ty::type_is_bot(cx.ccx.tcx, block_ty) ||
ty::type_is_nil(cx.ccx.tcx, block_ty) ||
option::is_none(f.body.node.expr) {
bcx = trans_block_dps(bcx, f.body, ignore);
option::is_none(body.node.expr) {
bcx = trans_block_dps(bcx, body, ignore);
} else if ty::type_is_immediate(cx.ccx.tcx, block_ty) {
let cell = empty_dest_cell();
bcx = trans_block_dps(bcx, f.body, by_val(cell));
bcx = trans_block_dps(bcx, body, by_val(cell));
Store(bcx, *cell, fcx.llretptr);
} else {
bcx = trans_block_dps(bcx, f.body, save_in(fcx.llretptr));
bcx = trans_block_dps(bcx, body, save_in(fcx.llretptr));
}
// FIXME: until LLVM has a unit type, we are moving around
@ -4567,13 +4567,13 @@ fn trans_closure(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
// trans_fn: creates an LLVM function corresponding to a source language
// function.
fn trans_fn(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
ty_self: self_arg, ty_params: [ast::ty_param],
fn trans_fn(cx: @local_ctxt, sp: span, decl: ast::fn_decl, body: ast::blk,
llfndecl: ValueRef, ty_self: self_arg, ty_params: [ast::ty_param],
id: ast::node_id) {
let do_time = cx.ccx.sess.get_opts().stats;
let start = do_time ? time::get_time() : {sec: 0u32, usec: 0u32};
let fcx = option::none;
trans_closure(cx, sp, f, llfndecl, ty_self, ty_params, id,
trans_closure(cx, sp, decl, body, llfndecl, ty_self, ty_params, id,
{|new_fcx| fcx = option::some(new_fcx);});
if cx.ccx.sess.get_opts().extra_debuginfo {
debuginfo::create_function(option::get(fcx));
@ -4584,7 +4584,7 @@ fn trans_fn(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef,
}
}
fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn,
fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::fn_decl,
ctor_id: ast::node_id, ty_params: [ast::ty_param]) {
let ccx = cx.ccx;
@ -4596,12 +4596,12 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn,
}
let fcx = new_fn_ctxt(cx, sp, llctor_decl);
let ret_t = ty::ret_ty_of_fn(cx.ccx.tcx, ctor_id);
create_llargs_for_fn_args(fcx, no_self, dtor.decl.inputs, ty_params);
create_llargs_for_fn_args(fcx, no_self, dtor.inputs, ty_params);
let bcx = new_top_block_ctxt(fcx);
let lltop = bcx.llbb;
let arg_t = arg_tys_of_fn(ccx, ctor_id)[0].ty;
let tup_t = ty::mk_tup(ccx.tcx, [ty::mk_int(ccx.tcx), arg_t]);
let arg = alt fcx.llargs.find(dtor.decl.inputs[0].id) {
let arg = alt fcx.llargs.find(dtor.inputs[0].id) {
some(local_mem(x)) { x }
};
let llretptr = fcx.llretptr;
@ -4706,11 +4706,11 @@ fn trans_impl(cx: @local_ctxt, name: ast::ident, methods: [@ast::method],
id: ast::node_id, tps: [ast::ty_param]) {
let sub_cx = extend_path(cx, name);
for m in methods {
alt cx.ccx.item_ids.find(m.node.id) {
alt cx.ccx.item_ids.find(m.id) {
some(llfn) {
trans_fn(extend_path(sub_cx, m.node.ident), m.span, m.node.meth,
trans_fn(extend_path(sub_cx, m.ident), m.span, m.decl, m.body,
llfn, impl_self(ty::node_id_to_monotype(cx.ccx.tcx, id)),
tps + m.node.tps, m.node.id);
tps + m.tps, m.id);
}
}
}
@ -4996,11 +4996,12 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
fn trans_item(cx: @local_ctxt, item: ast::item) {
alt item.node {
ast::item_fn(f, tps) {
ast::item_fn(decl, tps, body) {
let sub_cx = extend_path(cx, item.ident);
alt cx.ccx.item_ids.find(item.id) {
some(llfndecl) {
trans_fn(sub_cx, item.span, f, llfndecl, no_self, tps, item.id);
trans_fn(sub_cx, item.span, decl, body, llfndecl, no_self, tps,
item.id);
}
_ {
cx.ccx.sess.span_fatal(item.span,
@ -5017,13 +5018,14 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
ast::item_impl(tps, _, ms) {
trans_impl(cx, item.ident, ms, item.id, tps);
}
ast::item_res(dtor, dtor_id, tps, ctor_id) {
trans_res_ctor(cx, item.span, dtor, ctor_id, tps);
ast::item_res(decl, tps, body, dtor_id, ctor_id) {
trans_res_ctor(cx, item.span, decl, ctor_id, tps);
// Create a function for the destructor
alt cx.ccx.item_ids.find(item.id) {
some(lldtor_decl) {
trans_fn(cx, item.span, dtor, lldtor_decl, no_self, tps, dtor_id);
trans_fn(cx, item.span, decl, body, lldtor_decl, no_self,
tps, dtor_id);
}
_ {
cx.ccx.sess.span_fatal(item.span, "unbound dtor in trans_item");
@ -5329,7 +5331,7 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
let new_pt = pt + [i.ident];
visit::visit_item(i, new_pt, v);
alt i.node {
ast::item_fn(f, tps) {
ast::item_fn(_, tps, _) {
if !ccx.obj_methods.contains_key(i.id) {
register_fn(ccx, i.span, new_pt, "fn", tps, i.id);
}
@ -5337,17 +5339,17 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
ast::item_obj(ob, tps, ctor_id) {
register_fn(ccx, i.span, new_pt, "obj_ctor", tps, ctor_id);
for m: @ast::method in ob.methods {
ccx.obj_methods.insert(m.node.id, ());
ccx.obj_methods.insert(m.id, ());
}
}
ast::item_impl(tps, _, methods) {
let name = ccx.names.next(i.ident);
for m in methods {
register_fn(ccx, i.span, pt + [name, m.node.ident],
"impl_method", tps + m.node.tps, m.node.id);
register_fn(ccx, i.span, pt + [name, m.ident],
"impl_method", tps + m.tps, m.id);
}
}
ast::item_res(_, dtor_id, tps, ctor_id) {
ast::item_res(_, tps, _, dtor_id, ctor_id) {
register_fn(ccx, i.span, new_pt, "res_ctor", tps, ctor_id);
// Note that the destructor is associated with the item's id, not
// the dtor_id. This is a bit counter-intuitive, but simplifies

View File

@ -372,7 +372,8 @@ fn load_environment(enclosing_cx: @block_ctxt,
}
fn trans_expr_fn(bcx: @block_ctxt,
f: ast::_fn,
decl: ast::fn_decl,
body: ast::blk,
sp: span,
id: ast::node_id,
cap_clause: ast::capture_clause,
@ -389,21 +390,22 @@ fn trans_expr_fn(bcx: @block_ctxt,
let trans_closure_env = lambda(ck: ty::closure_kind) -> ValueRef {
let cap_vars = capture::compute_capture_vars(
ccx.tcx, id, f.proto, cap_clause);
ccx.tcx, id, decl.proto, cap_clause);
let {llbox, box_ty, bcx} = build_closure(bcx, cap_vars, ck);
trans_closure(sub_cx, sp, f, llfn, no_self, [], id, {|fcx|
trans_closure(sub_cx, sp, decl, body, llfn, no_self, [], id, {|fcx|
load_environment(bcx, fcx, box_ty, cap_vars, ck);
});
llbox
};
let closure = alt f.proto {
let closure = alt decl.proto {
ast::proto_block. { trans_closure_env(ty::closure_block) }
ast::proto_shared(_) { trans_closure_env(ty::closure_shared) }
ast::proto_send. { trans_closure_env(ty::closure_send) }
ast::proto_bare. {
let closure = C_null(T_opaque_boxed_closure_ptr(ccx));
trans_closure(sub_cx, sp, f, llfn, no_self, [], id, {|_fcx|});
trans_closure(sub_cx, sp, decl, body, llfn, no_self, [],
id, {|_fcx|});
closure
}
};

View File

@ -386,7 +386,7 @@ tag vtbl_mthd {
// Alphabetize ast::methods by ident. A helper for create_vtbl.
fn ast_mthd_lteq(&&a: @ast::method, &&b: @ast::method) -> bool {
ret str::lteq(a.node.ident, b.node.ident);
ret str::lteq(a.ident, b.ident);
}
// Alphabetize vtbl_mthds by ident. A helper for create_vtbl.
@ -394,13 +394,13 @@ fn vtbl_mthd_lteq(a: vtbl_mthd, b: vtbl_mthd) -> bool {
alt a {
normal_mthd(ma) {
alt b {
normal_mthd(mb) { ret str::lteq(ma.node.ident, mb.node.ident); }
fwding_mthd(mb) { ret str::lteq(ma.node.ident, mb.ident); }
normal_mthd(mb) { ret str::lteq(ma.ident, mb.ident); }
fwding_mthd(mb) { ret str::lteq(ma.ident, mb.ident); }
}
}
fwding_mthd(ma) {
alt b {
normal_mthd(mb) { ret str::lteq(ma.ident, mb.node.ident); }
normal_mthd(mb) { ret str::lteq(ma.ident, mb.ident); }
fwding_mthd(mb) { ret str::lteq(ma.ident, mb.ident); }
}
}
@ -420,7 +420,7 @@ fn filtering_fn(cx: @local_ctxt, m: vtbl_mthd, addtl_meths: [@ast::method]) ->
alt m {
fwding_mthd(fm) {
for am: @ast::method in addtl_meths {
if str::eq(am.node.ident, fm.ident) { ret none; }
if str::eq(am.ident, fm.ident) { ret none; }
}
ret some(fwding_mthd(fm));
}
@ -876,7 +876,7 @@ fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t,
let llfnty = T_nil();
let ccx = cx.ccx;
alt ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id)) {
alt ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.id)) {
ty::ty_fn(_, inputs, output, rs, _) {
check non_ty_var(ccx, output);
llfnty = type_of_fn(ccx, m.span, true, inputs, output,
@ -884,17 +884,17 @@ fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t,
}
}
let mcx: @local_ctxt =
@{path: cx.path + ["method", m.node.ident] with *cx};
@{path: cx.path + ["method", m.ident] with *cx};
let s: str = mangle_internal_name_by_path(mcx.ccx, mcx.path);
let llfn: ValueRef = decl_internal_cdecl_fn(ccx.llmod, s, llfnty);
// Every method on an object gets its node_id inserted into the crate-wide
// item_ids map, together with the ValueRef that points to where that
// method's definition will be in the executable.
ccx.item_ids.insert(m.node.id, llfn);
ccx.item_symbols.insert(m.node.id, s);
trans_fn(mcx, m.span, m.node.meth, llfn, obj_self(self_ty), ty_params,
m.node.id);
ccx.item_ids.insert(m.id, llfn);
ccx.item_symbols.insert(m.id, s);
trans_fn(mcx, m.span, m.decl, m.body, llfn, obj_self(self_ty), ty_params,
m.id);
ret llfn;
}

View File

@ -1,8 +1,6 @@
import syntax::ast;
import ast::{_fn, stmt,
fn_ident, node_id, crate, return_val, noreturn,
expr};
import ast::{stmt, fn_ident, node_id, crate, return_val, noreturn, expr};
import syntax::{visit, print};
import syntax::codemap::span;
import middle::ty::{type_is_nil, ret_ty_of_fn};

View File

@ -27,13 +27,13 @@ fn find_pre_post_native_mod(_m: native_mod) -> native_mod {
}
fn find_pre_post_method(ccx: crate_ctxt, m: @method) {
assert (ccx.fm.contains_key(m.node.id));
assert (ccx.fm.contains_key(m.id));
let fcx: fn_ctxt =
{enclosing: ccx.fm.get(m.node.id),
id: m.node.id,
name: m.node.ident,
{enclosing: ccx.fm.get(m.id),
id: m.id,
name: m.ident,
ccx: ccx};
find_pre_post_fn(fcx, m.node.meth.body);
find_pre_post_fn(fcx, m.body);
}
fn find_pre_post_item(ccx: crate_ctxt, i: item) {
@ -56,23 +56,23 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
ccx: ccx};
find_pre_post_expr(fake_fcx, e);
}
item_fn(f, _) {
item_fn(_, _, body) {
assert (ccx.fm.contains_key(i.id));
let fcx =
{enclosing: ccx.fm.get(i.id), id: i.id, name: i.ident, ccx: ccx};
find_pre_post_fn(fcx, f.body);
find_pre_post_fn(fcx, body);
}
item_mod(m) { find_pre_post_mod(m); }
item_native_mod(nm) { find_pre_post_native_mod(nm); }
item_ty(_, _) { ret; }
item_tag(_, _) { ret; }
item_res(dtor, dtor_id, _, _) {
item_res(_, _, body, dtor_id, _) {
let fcx =
{enclosing: ccx.fm.get(dtor_id),
id: dtor_id,
name: i.ident,
ccx: ccx};
find_pre_post_fn(fcx, dtor.body);
find_pre_post_fn(fcx, body);
}
item_obj(o, _, _) {for m in o.methods { find_pre_post_method(ccx, m); }}
item_impl(_, _, ms) { for m in ms { find_pre_post_method(ccx, m); } }
@ -347,7 +347,7 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
expr_log(_, lvl, arg) {
find_pre_post_exprs(fcx, [lvl, arg], e.id);
}
expr_fn(f, cap_clause) {
expr_fn(_, _, cap_clause) {
find_pre_post_expr_fn_upvars(fcx, e);
let use_cap_item = lambda(&&cap_item: @capture_item) {

View File

@ -371,7 +371,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
}
expr_mac(_) { fcx.ccx.tcx.sess.bug("unexpanded macro"); }
expr_lit(l) { ret pure_exp(fcx.ccx, e.id, pres); }
expr_fn(_, cap_clause) {
expr_fn(_, _, cap_clause) {
ret find_pre_post_state_cap_clause(fcx, e.id, pres, *cap_clause);
}
expr_fn_block(_, _) { ret pure_exp(fcx.ccx, e.id, pres); }

View File

@ -256,10 +256,10 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
}
}
}
fn ast_arg_to_arg(tcx: ty::ctxt, mode: mode, arg: ast::ty_arg)
fn ast_arg_to_arg(tcx: ty::ctxt, mode: mode, arg: ast::arg)
-> {mode: ty::mode, ty: ty::t} {
let ty = ast_ty_to_ty(tcx, mode, arg.node.ty);
ret {mode: default_arg_mode_for_ty(tcx, arg.node.mode, ty), ty: ty};
let ty = ast_ty_to_ty(tcx, mode, arg.ty);
ret {mode: default_arg_mode_for_ty(tcx, arg.mode, ty), ty: ty};
}
alt tcx.ast_ty_to_ty_cache.find(ast_ty) {
some(some(ty)) { ret ty; }
@ -333,18 +333,8 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
}
typ = ty::mk_rec(tcx, flds);
}
ast::ty_fn(proto, inputs, output, cf, constrs) {
let i = [];
for ta: ast::ty_arg in inputs {
i += [ast_arg_to_arg(tcx, mode, ta)];
}
let out_ty = ast_ty_to_ty(tcx, mode, output);
let out_constrs = [];
for constr: @ast::constr in constrs {
out_constrs += [ty::ast_constr_to_constr(tcx, constr)];
}
typ = ty::mk_fn(tcx, proto, i, out_ty, cf, out_constrs);
ast::ty_fn(decl) {
typ = ty_of_fn_decl(tcx, mode, decl);
}
ast::ty_path(path, id) {
alt tcx.def_map.find(id) {
@ -366,7 +356,7 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
let tmeths: [ty::method] = [];
for m: ast::ty_method in meths {
let ins = [];
for ta: ast::ty_arg in m.node.inputs {
for ta: ast::arg in m.node.inputs {
ins += [ast_arg_to_arg(tcx, mode, ta)];
}
let out = ast_ty_to_ty(tcx, mode, m.node.output);
@ -414,9 +404,8 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
tcx.tcache.insert(local_def(it.id), tpt);
ret tpt;
}
ast::item_fn(fn_info, tps) {
ret ty_of_fn_decl(tcx, mode, fn_info.decl, fn_info.proto,
tps, some(local_def(it.id)));
ast::item_fn(decl, tps, _) {
ret ty_of_fn(tcx, mode, decl, tps, local_def(it.id));
}
ast::item_obj(ob, tps, _) {
let t_obj = ty_of_obj(tcx, mode, it.ident, ob, tps);
@ -435,8 +424,8 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
tcx.tcache.insert(local_def(it.id), tpt);
ret tpt;
}
ast::item_res(f, _, tps, _) {
let t_arg = ty_of_arg(tcx, mode, f.decl.inputs[0]);
ast::item_res(decl, tps, _, _, _) {
let t_arg = ty_of_arg(tcx, mode, decl.inputs[0]);
let t = ty::mk_named(tcx, ty::mk_res(tcx, local_def(it.id), t_arg.ty,
mk_ty_params(tcx, tps)),
@it.ident);
@ -480,9 +469,7 @@ fn ty_of_arg(tcx: ty::ctxt, mode: mode, a: ast::arg) -> ty::arg {
let ty = ast_ty_to_ty(tcx, mode, a.ty);
{mode: default_arg_mode_for_ty(tcx, a.mode, ty), ty: ty}
}
fn ty_of_fn_decl(tcx: ty::ctxt, mode: mode, 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 {
fn ty_of_fn_decl(tcx: ty::ctxt, mode: mode, decl: ast::fn_decl) -> ty::t {
let input_tys = [];
for a: ast::arg in decl.inputs { input_tys += [ty_of_arg(tcx, mode, a)]; }
let output_ty = ast_ty_to_ty(tcx, mode, decl.output);
@ -491,10 +478,14 @@ fn ty_of_fn_decl(tcx: ty::ctxt, mode: mode, decl: ast::fn_decl,
for constr: @ast::constr in decl.constraints {
out_constrs += [ty::ast_constr_to_constr(tcx, constr)];
}
let t_fn = ty::mk_fn(tcx, proto, input_tys, output_ty,
decl.cf, out_constrs);
let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn};
alt def_id { some(did) { tcx.tcache.insert(did, tpt); } _ { } }
ty::mk_fn(tcx, decl.proto, input_tys, output_ty, decl.cf, out_constrs)
}
fn ty_of_fn(tcx: ty::ctxt, mode: mode, decl: ast::fn_decl,
ty_params: [ast::ty_param], def_id: ast::def_id)
-> ty::ty_param_kinds_and_ty {
let tpt = {kinds: ty_param_kinds(ty_params),
ty: ty_of_fn_decl(tcx, mode, decl)};
tcx.tcache.insert(def_id, tpt);
ret tpt;
}
fn ty_of_native_fn_decl(tcx: ty::ctxt, mode: mode, decl: ast::fn_decl,
@ -510,19 +501,19 @@ fn ty_of_native_fn_decl(tcx: ty::ctxt, mode: mode, decl: ast::fn_decl,
ret tpt;
}
fn ty_of_method(tcx: ty::ctxt, mode: mode, m: @ast::method) -> ty::method {
let inputs = vec::map(m.node.meth.decl.inputs,
let inputs = vec::map(m.decl.inputs,
{|i| ty_of_arg(tcx, mode, i)});
let output = ast_ty_to_ty(tcx, mode, m.node.meth.decl.output);
let output = ast_ty_to_ty(tcx, mode, m.decl.output);
let out_constrs = [];
for constr: @ast::constr in m.node.meth.decl.constraints {
for constr: @ast::constr in m.decl.constraints {
out_constrs += [ty::ast_constr_to_constr(tcx, constr)];
}
ret {proto: m.node.meth.proto,
ident: m.node.ident,
ret {proto: m.decl.proto,
ident: m.ident,
inputs: inputs,
output: output,
cf: m.node.meth.decl.cf,
cf: m.decl.cf,
constrs: out_constrs};
}
fn ty_of_obj(tcx: ty::ctxt, mode: mode, id: ast::ident, ob: ast::_obj,
@ -691,10 +682,10 @@ mod collect {
for m in ms {
let ty = ty::method_ty_to_fn_ty(
cx.tcx, ty_of_method(cx.tcx, m_collect, m));
cx.tcx.tcache.insert(local_def(m.node.id),
{kinds: ty_param_kinds(m.node.tps),
cx.tcx.tcache.insert(local_def(m.id),
{kinds: ty_param_kinds(m.tps),
ty: ty});
write::ty_only(cx.tcx, m.node.id, ty);
write::ty_only(cx.tcx, m.id, ty);
}
write::ty_only(cx.tcx, it.id, ast_ty_to_ty(cx.tcx, m_collect,
selfty));
@ -714,7 +705,7 @@ mod collect {
let method_types = ty_of_obj_methods(cx.tcx, m_collect, object);
let i = 0u;
for m in object.methods {
write::ty_only(cx.tcx, m.node.id,
write::ty_only(cx.tcx, m.id,
ty::method_ty_to_fn_ty(cx.tcx,
method_types[i]));
i += 1u;
@ -731,8 +722,8 @@ mod collect {
i += 1u;
}
}
ast::item_res(f, dtor_id, tps, ctor_id) {
let t_arg = ty_of_arg(cx.tcx, m_collect, f.decl.inputs[0]);
ast::item_res(decl, tps, _, dtor_id, ctor_id) {
let t_arg = ty_of_arg(cx.tcx, m_collect, decl.inputs[0]);
let t_res =
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
mk_ty_params(cx.tcx, tps));
@ -1000,7 +991,7 @@ mod writeback {
if !wbcx.success { ret; }
resolve_type_vars_for_node(wbcx, e.span, e.id);
alt e.node {
ast::expr_fn({decl: decl, _}, _) |
ast::expr_fn(decl, _, _) |
ast::expr_fn_block(decl, _) {
for input in decl.inputs {
resolve_type_vars_for_node(wbcx, e.span, input.id);
@ -1504,14 +1495,12 @@ fn lookup_method(fcx: @fn_ctxt, isc: resolve::iscopes,
fn check_expr_fn_with_unifier(fcx: @fn_ctxt,
expr: @ast::expr,
decl: ast::fn_decl,
proto: ast::proto,
body: ast::blk,
unify: unifier,
expected: ty::t) {
let tcx = fcx.ccx.tcx;
let fty = ty_of_fn_decl(tcx, m_check_tyvar(fcx), decl,
proto, [], none).ty;
let fty = ty_of_fn_decl(tcx, m_check_tyvar(fcx), decl);
log #fmt("check_expr_fn_with_unifier %s fty=%s",
expr_to_str(expr),
@ -1525,7 +1514,7 @@ fn check_expr_fn_with_unifier(fcx: @fn_ctxt,
// record projection work on type inferred arguments.
unify(fcx, expr.span, expected, fty);
check_fn1(fcx.ccx, decl, proto, body, expr.id, some(fcx));
check_fn1(fcx.ccx, decl, body, expr.id, some(fcx));
}
fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
@ -1960,11 +1949,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
if !arm_non_bot { result_ty = ty::mk_bot(tcx); }
write::ty_only_fixup(fcx, id, result_ty);
}
ast::expr_fn(f, captures) {
check_expr_fn_with_unifier(fcx, expr, f.decl,
f.proto, f.body,
ast::expr_fn(decl, body, captures) {
check_expr_fn_with_unifier(fcx, expr, decl, body,
unify, expected);
capture::check_capture_clause(tcx, expr.id, f.proto, *captures);
capture::check_capture_clause(tcx, expr.id, decl.proto, *captures);
}
ast::expr_fn_block(decl, body) {
// Take the prototype from the expected type, but default to block:
@ -1980,8 +1968,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
log #fmt("checking expr_fn_block %s expected=%s",
expr_to_str(expr),
ty_to_str(tcx, expected));
check_expr_fn_with_unifier(fcx, expr, decl,
proto, body,
check_expr_fn_with_unifier(fcx, expr, {proto: proto with decl}, body,
unify, expected);
write::ty_only_fixup(fcx, id, expected);
}
@ -2322,7 +2309,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
option::t<ty::method> {
for om: @ast::method in outer_obj_methods {
if str::eq(om.node.ident, m.ident) {
if str::eq(om.ident, m.ident) {
// We'd better be overriding with one of the same
// type. Check to make sure.
let new_type = ty_of_method(ccx.tcx, m_check, om);
@ -2351,7 +2338,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
// collect::convert for regular objects.)
let i = 0u;
while i < vec::len(ao.methods) {
write::ty_only(tcx, ao.methods[i].node.id,
write::ty_only(tcx, ao.methods[i].id,
ty::method_ty_to_fn_ty(tcx, method_types[i]));
i += 1u;
}
@ -2604,15 +2591,15 @@ fn check_constraints(fcx: @fn_ctxt, cs: [@ast::constr], args: [ast::arg]) {
}
fn check_fn(ccx: @crate_ctxt,
f: ast::_fn,
decl: ast::fn_decl,
body: ast::blk,
id: ast::node_id,
old_fcx: option::t<@fn_ctxt>) {
check_fn1(ccx, f.decl, f.proto, f.body, id, old_fcx);
check_fn1(ccx, decl, body, id, old_fcx);
}
fn check_fn1(ccx: @crate_ctxt,
decl: ast::fn_decl,
proto: ast::proto,
body: ast::blk,
id: ast::node_id,
old_fcx: option::t<@fn_ctxt>) {
@ -2628,7 +2615,7 @@ fn check_fn1(ccx: @crate_ctxt,
let fcx: @fn_ctxt =
@{ret_ty: ty::ty_fn_ret(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)),
purity: purity,
proto: proto,
proto: decl.proto,
var_bindings: gather_result.var_bindings,
locals: gather_result.locals,
next_var_id: gather_result.next_var_id,
@ -2665,14 +2652,16 @@ fn check_fn1(ccx: @crate_ctxt,
}
fn check_method(ccx: @crate_ctxt, method: @ast::method) {
check_fn(ccx, method.node.meth, method.node.id, none);
check_fn(ccx, method.decl, method.body, method.id, none);
}
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
alt it.node {
ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); }
ast::item_fn(f, _) { check_fn(ccx, f, it.id, none); }
ast::item_res(f, dtor_id, _, _) { check_fn(ccx, f, dtor_id, none); }
ast::item_fn(decl, _, body) { check_fn(ccx, decl, body, it.id, none); }
ast::item_res(decl, _, body, dtor_id, _) {
check_fn(ccx, decl, body, dtor_id, none);
}
ast::item_obj(ob, _, _) {
// We're entering an object, so gather up the info we need.
ccx.self_infos += [self_obj(ob.fields,

View File

@ -226,7 +226,7 @@ tag expr_ {
expr_for(@local, @expr, blk);
expr_do_while(blk, @expr);
expr_alt(@expr, [arm]);
expr_fn(_fn, @capture_clause);
expr_fn(fn_decl, blk, @capture_clause);
expr_fn_block(fn_decl, blk);
expr_block(blk);
@ -307,20 +307,16 @@ type mt = {ty: @ty, mut: mutability};
type ty_field_ = {ident: ident, mt: mt};
type ty_arg_ = {mode: mode, ty: @ty};
type ty_method_ =
{proto: proto,
ident: ident,
inputs: [ty_arg],
inputs: [arg],
output: @ty,
cf: ret_style,
constrs: [@constr]};
type ty_field = spanned<ty_field_>;
type ty_arg = spanned<ty_arg_>;
type ty_method = spanned<ty_method_>;
tag int_ty { ty_i; ty_char; ty_i8; ty_i16; ty_i32; ty_i64; }
@ -353,7 +349,7 @@ tag ty_ {
ty_port(@ty);
ty_chan(@ty);
ty_rec([ty_field]);
ty_fn(proto, [ty_arg], @ty, ret_style, [@constr]);
ty_fn(fn_decl);
ty_obj([ty_method]);
ty_tup([@ty]);
ty_path(@path, node_id);
@ -403,13 +399,11 @@ type ty_constr = spanned<ty_constr_>;
corresponding to these. */
type arg = {mode: mode, ty: @ty, ident: ident, id: node_id};
tag inlineness { il_normal; il_inline; }
type fn_decl =
{inputs: [arg],
{proto: proto,
inputs: [arg],
output: @ty,
purity: purity,
il: inlineness,
cf: ret_style,
constraints: [@constr]};
@ -425,11 +419,8 @@ tag ret_style {
return_val; // everything else
}
type _fn = {decl: fn_decl, proto: proto, body: blk};
type method_ = {ident: ident, meth: _fn, id: node_id, tps: [ty_param]};
type method = spanned<method_>;
type method = {ident: ident, tps: [ty_param], decl: fn_decl, body: blk,
id: node_id, span: span};
type obj_field = {mut: mutability, ty: @ty, ident: ident, id: node_id};
type anon_obj_field =
@ -499,16 +490,14 @@ type item = // For objs and resources, this is the type def_id
tag item_ {
item_const(@ty, @expr);
item_fn(_fn, [ty_param]);
item_fn(fn_decl, [ty_param], blk);
item_mod(_mod);
item_native_mod(native_mod);
item_ty(@ty, [ty_param]);
item_tag([variant], [ty_param]);
item_obj(_obj, [ty_param], /* constructor id */node_id);
item_res(_fn /* dtor */,
node_id /* dtor id */,
[ty_param],
node_id /* ctor id */);
item_res(fn_decl /* dtor */, [ty_param], blk,
node_id /* dtor id */, node_id /* ctor id */);
item_impl([ty_param], @ty /* self */, [@method]);
}

View File

@ -26,7 +26,7 @@ type ast_fold_precursor =
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_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,
@ -35,7 +35,6 @@ type ast_fold_precursor =
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_,
@ -62,7 +61,6 @@ type a_f =
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,
@ -92,7 +90,6 @@ 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; }
@ -124,7 +121,7 @@ fn fold_attribute_(at: attribute, fmi: fn@(&&@meta_item) -> @meta_item) ->
ret {node: {style: at.node.style, value: *fmi(@at.node.value)},
span: at.span};
}
//used in noop_fold_native_item and noop_fold_fn
//used in noop_fold_native_item and noop_fold_fn_decl
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
ret {mode: a.mode,
ty: fld.fold_ty(a.ty),
@ -146,10 +143,10 @@ fn fold_mac_(m: mac, fld: ast_fold) -> mac {
}
fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
ret {inputs: vec::map(decl.inputs, bind fold_arg_(_, fld)),
ret {proto: decl.proto,
inputs: vec::map(decl.inputs, bind fold_arg_(_, fld)),
output: fld.fold_ty(decl.output),
purity: decl.purity,
il: decl.il,
cf: decl.cf,
constraints: vec::map(decl.constraints, fld.fold_constr)}
}
@ -195,10 +192,10 @@ fn noop_fold_native_item(&&ni: @native_item, fld: ast_fold) -> @native_item {
alt ni.node {
native_item_ty. { native_item_ty }
native_item_fn(fdec, typms) {
native_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
native_item_fn({proto: fdec.proto,
inputs: vec::map(fdec.inputs, fold_arg),
output: fld.fold_ty(fdec.output),
purity: fdec.purity,
il: fdec.il,
cf: fdec.cf,
constraints:
vec::map(fdec.constraints,
@ -231,7 +228,10 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
ret alt i {
item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) }
item_fn(f, typms) { item_fn(fld.fold_fn(f), typms) }
item_fn(decl, typms, body) {
let body = fld.fold_block(body);
item_fn(fold_fn_decl(decl, fld), typms, body)
}
item_mod(m) { item_mod(fld.fold_mod(m)) }
item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) }
item_ty(t, typms) { item_ty(fld.fold_ty(t), typms) }
@ -247,15 +247,17 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
item_impl(tps, fld.fold_ty(ty),
vec::map(methods, fld.fold_method))
}
item_res(dtor, did, typms, cid) {
item_res(fld.fold_fn(dtor), did, typms, cid)
item_res(decl, typms, body, did, cid) {
item_res(fold_fn_decl(decl, fld), typms, fld.fold_block(body),
did, cid)
}
};
}
fn noop_fold_method(m: method_, fld: ast_fold) -> method_ {
ret {ident: fld.fold_ident(m.ident), meth: fld.fold_fn(m.meth)
with m};
fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
ret @{ident: fld.fold_ident(m.ident),
decl: fold_fn_decl(m.decl, fld),
body: fld.fold_block(m.body) with *m};
}
@ -393,7 +395,9 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
expr_alt(expr, arms) {
expr_alt(fld.fold_expr(expr), vec::map(arms, fld.fold_arm))
}
expr_fn(f, captures) { expr_fn(fld.fold_fn(f), captures) }
expr_fn(decl, body, captures) {
expr_fn(fold_fn_decl(decl, fld), fld.fold_block(body), captures)
}
expr_fn_block(decl, body) {
expr_fn_block(fold_fn_decl(decl, fld), fld.fold_block(body))
}
@ -446,13 +450,6 @@ 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 {
ret {decl: fold_fn_decl(f.decl, fld),
proto: f.proto,
body: fld.fold_block(f.body)};
}
// ...nor do modules
fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
ret {view_items: vec::map(m.view_items, fld.fold_view_item),
@ -521,7 +518,6 @@ fn default_ast_fold() -> @ast_fold_precursor {
fold_expr: noop_fold_expr,
fold_ty: noop_fold_ty,
fold_constr: noop_fold_constr,
fold_fn: noop_fold_fn,
fold_mod: noop_fold_mod,
fold_native_mod: noop_fold_native_mod,
fold_variant: noop_fold_variant,
@ -552,7 +548,6 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
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(_),
@ -590,7 +585,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
}
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)};
ret afp.fold_method(x, f);
}
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)};
@ -621,9 +616,6 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
@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 {
ret afp.fold_fn(x, f);
}
fn f_mod(afp: ast_fold_precursor, f: ast_fold, x: _mod) -> _mod {
ret afp.fold_mod(x, f);
}
@ -661,7 +653,6 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
fold_expr: bind f_expr(afp, result, _),
fold_ty: bind f_ty(afp, result, _),
fold_constr: bind f_constr(afp, result, _),
fold_fn: bind f_fn(afp, result, _),
fold_mod: bind f_mod(afp, result, _),
fold_native_mod: bind f_native_mod(afp, result, _),
fold_variant: bind f_variant(afp, result, _),

View File

@ -265,16 +265,14 @@ fn check_bad_word(p: parser) {
}
fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ {
fn parse_fn_input_ty(p: parser) -> ast::ty_arg {
let lo = p.get_lo_pos();
fn parse_fn_input_ty(p: parser) -> ast::arg {
let mode = parse_arg_mode(p);
// Ignore arg name, if present
if is_plain_ident(p) && p.look_ahead(1u) == token::COLON {
let name = if is_plain_ident(p) && p.look_ahead(1u) == token::COLON {
let name = parse_value_ident(p);
p.bump();
p.bump();
}
let t = parse_ty(p, false);
ret spanned(lo, t.span.hi, {mode: mode, ty: t});
name
} else { "" };
ret {mode: mode, ty: parse_ty(p, false), ident: name, id: p.get_id()};
}
let inputs =
parse_seq(token::LPAREN, token::RPAREN, seq_sep(token::COMMA),
@ -283,7 +281,9 @@ fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ {
// auto constrs = parse_constrs(~[], p);
let constrs: [@ast::constr] = [];
let (ret_style, ret_ty) = parse_ret_ty(p);
ret ast::ty_fn(proto, inputs.node, ret_ty, ret_style, constrs);
ret ast::ty_fn({proto: proto, inputs: inputs.node, output: ret_ty,
purity: ast::impure_fn, cf: ret_style,
constraints: constrs});
}
fn parse_ty_obj(p: parser) -> ast::ty_ {
@ -291,17 +291,18 @@ fn parse_ty_obj(p: parser) -> ast::ty_ {
let flo = p.get_lo_pos();
let proto: ast::proto = parse_method_proto(p);
let ident = parse_value_ident(p);
let f = parse_ty_fn(proto, p);
let f = parse_ty_fn(proto, p), fhi = p.get_last_hi_pos();
expect(p, token::SEMI);
alt f {
ast::ty_fn(proto, inputs, output, cf, constrs) {
ret spanned(flo, output.span.hi,
{proto: proto,
ast::ty_fn(d) {
// FIXME[fn_decl]
ret spanned(flo, fhi,
{proto: d.proto,
ident: ident,
inputs: inputs,
output: output,
cf: cf,
constrs: constrs});
inputs: d.inputs,
output: d.output,
cf: d.cf,
constrs: d.constraints});
}
}
}
@ -1325,10 +1326,10 @@ fn parse_capture_clause(p: parser) -> @ast::capture_clause {
fn parse_fn_expr(p: parser, proto: ast::proto) -> @ast::expr {
let lo = p.get_last_lo_pos();
let capture_clause = parse_capture_clause(p);
let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
let decl = parse_fn_decl(p, proto, ast::impure_fn);
let body = parse_block(p);
let _fn = {decl: decl, proto: proto, body: body};
ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn, capture_clause));
ret mk_expr(p, lo, body.span.hi,
ast::expr_fn(decl, body, capture_clause));
}
fn parse_fn_block_expr(p: parser) -> @ast::expr {
@ -1774,8 +1775,8 @@ fn parse_ty_params(p: parser) -> [ast::ty_param] {
ret ty_params;
}
fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) ->
ast::fn_decl {
fn parse_fn_decl(p: parser, proto: ast::proto, purity: ast::purity)
-> ast::fn_decl {
let inputs: ast::spanned<[ast::arg]> =
parse_seq(token::LPAREN, token::RPAREN, seq_sep(token::COMMA),
parse_arg, p);
@ -1788,10 +1789,10 @@ fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) ->
constrs = parse_constrs({|x| parse_ty_constr(inputs.node, x) }, p);
}
let (ret_style, ret_ty) = parse_ret_ty(p);
ret {inputs: inputs.node,
ret {proto: proto,
inputs: inputs.node,
output: ret_ty,
purity: purity,
il: il,
cf: ret_style,
constraints: constrs};
}
@ -1802,21 +1803,14 @@ fn parse_fn_block_decl(p: parser) -> ast::fn_decl {
seq_sep(token::COMMA), parse_fn_block_arg, p).node;
let output = eat(p, token::RARROW) ? parse_ty(p, false) :
@spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer);
ret {inputs: inputs,
ret {proto: ast::proto_block,
inputs: inputs,
output: output,
purity: ast::impure_fn,
il: ast::il_normal,
cf: ast::return_val,
constraints: []};
}
fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity,
il: ast::inlineness) -> ast::_fn {
let decl = parse_fn_decl(p, purity, il);
let body = parse_block(p);
ret {decl: decl, proto: proto, body: body};
}
fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} {
let id = parse_value_ident(p);
let ty_params = parse_ty_params(p);
@ -1833,13 +1827,13 @@ fn mk_item(p: parser, lo: uint, hi: uint, ident: ast::ident, node: ast::item_,
}
fn parse_item_fn(p: parser, purity: ast::purity, proto: ast::proto,
attrs: [ast::attribute], il: ast::inlineness) ->
@ast::item {
attrs: [ast::attribute]) -> @ast::item {
let lo = p.get_last_lo_pos();
let t = parse_fn_header(p);
let f = parse_fn(p, proto, purity, il);
ret mk_item(p, lo, f.body.span.hi, t.ident, ast::item_fn(f, t.tps),
attrs);
let decl = parse_fn_decl(p, proto, purity);
let body = parse_block(p);
ret mk_item(p, lo, body.span.hi, t.ident,
ast::item_fn(decl, t.tps, body), attrs);
}
fn parse_obj_field(p: parser) -> ast::obj_field {
@ -1865,9 +1859,10 @@ fn parse_method(p: parser, allow_tps: bool) -> @ast::method {
let proto = parse_method_proto(p);
let ident = parse_value_ident(p);
let tps = allow_tps ? parse_ty_params(p) : [];
let f = parse_fn(p, proto, ast::impure_fn, ast::il_normal);
let meth = {ident: ident, meth: f, id: p.get_id(), tps: tps};
ret @spanned(lo, f.body.span.hi, meth);
let decl = parse_fn_decl(p, proto, ast::impure_fn);
let body = parse_block(p);
@{ident: ident, tps: tps, decl: decl, body: body,
id: p.get_id(), span: ast_util::mk_sp(lo, body.span.hi)}
}
fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item {
@ -1909,18 +1904,17 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
expect(p, token::RPAREN);
let dtor = parse_block_no_value(p);
let decl =
{inputs:
{proto: ast::proto_bare,
inputs:
[{mode: ast::by_ref, ty: t, ident: arg_ident,
id: p.get_id()}],
output: @spanned(lo, lo, ast::ty_nil),
purity: ast::impure_fn,
il: ast::il_normal,
cf: ast::return_val,
constraints: []};
let f = {decl: decl, proto: ast::proto_shared(ast::sugar_normal),
body: dtor};
ret mk_item(p, lo, dtor.span.hi, ident,
ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs);
ast::item_res(decl, ty_params, dtor, p.get_id(), p.get_id()),
attrs);
}
fn parse_mod_items(p: parser, term: token::token,
@ -1984,7 +1978,7 @@ fn parse_item_native_fn(p: parser, attrs: [ast::attribute],
purity: ast::purity) -> @ast::native_item {
let lo = p.get_last_lo_pos();
let t = parse_fn_header(p);
let decl = parse_fn_decl(p, purity, ast::il_normal);
let decl = parse_fn_decl(p, ast::proto_bare, purity);
let hi = p.get_hi_pos();
expect(p, token::SEMI);
ret @{ident: t.ident,
@ -2142,24 +2136,20 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
} else if eat_word(p, "inline") {
expect_word(p, "fn");
let proto = parse_fn_item_proto(p);
ret some(parse_item_fn(p, ast::impure_fn, proto,
attrs, ast::il_inline));
ret some(parse_item_fn(p, ast::impure_fn, proto, attrs));
} else if is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN {
p.bump();
let proto = parse_fn_item_proto(p);
ret some(parse_item_fn(p, ast::impure_fn, proto,
attrs, ast::il_normal));
ret some(parse_item_fn(p, ast::impure_fn, proto, attrs));
} else if eat_word(p, "pure") {
expect_word(p, "fn");
let proto = parse_fn_item_proto(p);
ret some(parse_item_fn(p, ast::pure_fn, proto, attrs,
ast::il_normal));
ret some(parse_item_fn(p, ast::pure_fn, proto, attrs));
} else if is_word(p, "unsafe") && p.look_ahead(1u) != token::LBRACE {
p.bump();
expect_word(p, "fn");
let proto = parse_fn_item_proto(p);
ret some(parse_item_fn(p, ast::unsafe_fn, proto,
attrs, ast::il_normal));
ret some(parse_item_fn(p, ast::unsafe_fn, proto, attrs));
} else if eat_word(p, "mod") {
ret some(parse_item_mod(p, attrs));
} else if eat_word(p, "native") {

View File

@ -91,10 +91,11 @@ 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(decl: ast::fn_decl, 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);
print_fn(s, decl, name, params);
eof(s.s);
ret writer.get_str();
}
@ -304,8 +305,9 @@ fn print_type(s: ps, &&ty: @ast::ty) {
commasep(s, inconsistent, elts, print_type);
pclose(s);
}
ast::ty_fn(proto, inputs, output, cf, constrs) {
print_ty_fn(s, proto, none::<str>, inputs, output, cf, constrs);
ast::ty_fn(d) {
print_ty_fn(s, d.proto, none::<str>, d.inputs, d.output, d.cf,
d.constraints);
}
ast::ty_obj(methods) {
head(s, "obj");
@ -348,8 +350,7 @@ fn print_native_item(s: ps, item: @ast::native_item) {
}
ast::native_item_fn(decl, typarams) {
print_fn(s, decl, ast::proto_bare, item.ident, typarams,
decl.constraints);
print_fn(s, decl, item.ident, typarams);
end(s); // end head-ibox
word(s.s, ";");
end(s); // end the outer fn box
@ -377,11 +378,10 @@ fn print_item(s: ps, &&item: @ast::item) {
end(s); // end the outer cbox
}
ast::item_fn(_fn, typarams) {
print_fn(s, _fn.decl, _fn.proto, item.ident, typarams,
_fn.decl.constraints);
ast::item_fn(decl, typarams, body) {
print_fn(s, decl, item.ident, typarams);
word(s.s, " ");
print_block(s, _fn.body);
print_block(s, body);
}
ast::item_mod(_mod) {
head(s, "mod");
@ -469,10 +469,9 @@ fn print_item(s: ps, &&item: @ast::item) {
for meth: @ast::method in _obj.methods {
hardbreak_if_not_bol(s);
maybe_print_comment(s, meth.span.lo);
print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
meth.node.ident, meth.node.tps, []);
print_fn(s, meth.decl, meth.ident, meth.tps);
word(s.s, " ");
print_block(s, meth.node.meth.body);
print_block(s, meth.body);
}
bclose(s, item.span);
}
@ -488,23 +487,22 @@ fn print_item(s: ps, &&item: @ast::item) {
for meth in methods {
hardbreak_if_not_bol(s);
maybe_print_comment(s, meth.span.lo);
print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
meth.node.ident, meth.node.tps, []);
print_fn(s, meth.decl, meth.ident, meth.tps);
word(s.s, " ");
print_block(s, meth.node.meth.body);
print_block(s, meth.body);
}
bclose(s, item.span);
}
ast::item_res(dt, dt_id, tps, ct_id) {
ast::item_res(decl, tps, body, dt_id, ct_id) {
head(s, "resource");
word(s.s, item.ident);
print_type_params(s, tps);
popen(s);
word_space(s, dt.decl.inputs[0].ident + ":");
print_type(s, dt.decl.inputs[0].ty);
word_space(s, decl.inputs[0].ident + ":");
print_type(s, decl.inputs[0].ty);
pclose(s);
space(s.s);
print_block(s, dt.body);
print_block(s, body);
}
}
s.ann.post(ann_node);
@ -826,11 +824,11 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
}
bclose_(s, expr.span, alt_indent_unit);
}
ast::expr_fn(f, captures) { // NDM captures
head(s, proto_to_str(f.proto));
print_fn_args_and_ret(s, f.decl, []);
ast::expr_fn(decl, body, captures) { // NDM captures
head(s, proto_to_str(decl.proto));
print_fn_args_and_ret(s, decl);
space(s.s);
print_block(s, f.body);
print_block(s, body);
}
ast::expr_fn_block(decl, body) {
// containing cbox, will be closed by print-block at }
@ -976,10 +974,9 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
for meth: @ast::method in anon_obj.methods {
hardbreak_if_not_bol(s);
maybe_print_comment(s, meth.span.lo);
print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
meth.node.ident, meth.node.tps, []);
print_fn(s, meth.decl, meth.ident, meth.tps);
word(s.s, " ");
print_block(s, meth.node.meth.body);
print_block(s, meth.body);
}
// With object
@ -1131,18 +1128,18 @@ 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, name: ast::ident,
typarams: [ast::ty_param]) {
alt decl.purity {
ast::impure_fn. { head(s, proto_to_str(proto)); }
ast::impure_fn. { head(s, proto_to_str(decl.proto)); }
_ { head(s, "pure fn"); }
}
word(s.s, name);
print_type_params(s, typarams);
print_fn_args_and_ret(s, decl, constrs);
print_fn_args_and_ret(s, decl);
}
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) {
popen(s);
fn print_arg(s: ps, x: ast::arg) {
ibox(s, indent_unit);
@ -1153,7 +1150,7 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) {
}
commasep(s, inconsistent, decl.inputs, print_arg);
pclose(s);
word(s.s, ast_fn_constrs_str(decl, constrs));
word(s.s, ast_fn_constrs_str(decl, decl.constraints));
maybe_print_comment(s, decl.output.span.lo);
if decl.output.node != ast::ty_nil {
space_if_not_bol(s);
@ -1342,16 +1339,19 @@ fn print_mt(s: ps, mt: ast::mt) {
}
fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
inputs: [ast::ty_arg], output: @ast::ty, cf: ast::ret_style,
inputs: [ast::arg], output: @ast::ty, cf: ast::ret_style,
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) {
print_arg_mode(s, input.node.mode);
print_type(s, input.node.ty);
fn print_arg(s: ps, input: ast::arg) {
print_arg_mode(s, input.mode);
if str::byte_len(input.ident) > 0u {
word_space(s, input.ident + ":");
}
print_type(s, input.ty);
}
commasep(s, inconsistent, inputs, print_arg);
pclose(s);

View File

@ -33,7 +33,8 @@ type visitor<E> =
visit_constr: fn@(@path, span, node_id, E, vt<E>),
// A function with a fully specified prototype:
visit_fn_proto: fn@(_fn, [ty_param], span, fn_ident, node_id, E, vt<E>),
visit_fn_proto: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id,
E, vt<E>),
// Function sugar like { || ... }:
visit_fn_block: fn@(fn_decl, blk, span, node_id, E, vt<E>),
@ -56,7 +57,7 @@ fn default_visitor<E>() -> visitor<E> {
visit_expr: bind visit_expr::<E>(_, _, _),
visit_ty: bind skip_ty::<E>(_, _, _),
visit_constr: bind visit_constr::<E>(_, _, _, _, _),
visit_fn_proto: bind visit_fn_proto::<E>(_, _, _, _, _, _, _),
visit_fn_proto: bind visit_fn_proto::<E>(_, _, _, _, _, _, _, _),
visit_fn_block: bind visit_fn_block::<E>(_, _, _, _, _, _),
visit_fn_body: bind visit_fn_body::<E>(_, _, _, _, _, _, _)};
}
@ -94,16 +95,18 @@ fn visit_local<E>(loc: @local, 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_proto(f, tp, i.span,
some(i.ident), i.id, e, v); }
item_fn(decl, tp, body) {
v.visit_fn_proto(decl, tp, body, i.span, some(i.ident), i.id, e, v);
}
item_mod(m) { v.visit_mod(m, i.span, e, v); }
item_native_mod(nm) {
for vi: @view_item in nm.view_items { v.visit_view_item(vi, e, v); }
for ni: @native_item in nm.items { v.visit_native_item(ni, e, v); }
}
item_ty(t, _) { v.visit_ty(t, e, v); }
item_res(f, dtor_id, tps, _) {
v.visit_fn_proto(f, tps, i.span, some(i.ident), dtor_id, e, v);
item_res(decl, tps, body, dtor_id, _) {
v.visit_fn_proto(decl, tps, body, i.span, some(i.ident), dtor_id,
e, v);
}
item_tag(variants, _) {
for vr: variant in variants {
@ -113,15 +116,15 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
item_obj(ob, _, _) {
for f: obj_field in ob.fields { v.visit_ty(f.ty, e, v); }
for m: @method in ob.methods {
v.visit_fn_proto(m.node.meth, m.node.tps, m.span,
some(m.node.ident), m.node.id, e, v);
v.visit_fn_proto(m.decl, m.tps, m.body, m.span,
some(m.ident), m.id, e, v);
}
}
item_impl(_, ty, methods) {
visit_ty(ty, e, v);
for m in methods {
v.visit_fn_proto(m.node.meth, m.node.tps, m.span,
some(m.node.ident), m.node.id, e, v);
v.visit_fn_proto(m.decl, m.tps, m.body, m.span,
some(m.ident), m.id, e, v);
}
}
}
@ -139,16 +142,16 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
for f: ty_field in flds { v.visit_ty(f.node.mt.ty, e, v); }
}
ty_tup(ts) { for tt in ts { v.visit_ty(tt, e, v); } }
ty_fn(_, args, out, _, constrs) {
for a: ty_arg in args { v.visit_ty(a.node.ty, e, v); }
for c: @constr in constrs {
ty_fn(decl) {
for a in decl.inputs { v.visit_ty(a.ty, e, v); }
for c: @constr in decl.constraints {
v.visit_constr(c.node.path, c.span, c.node.id, e, v);
}
v.visit_ty(out, e, v);
v.visit_ty(decl.output, e, v);
}
ty_obj(tmeths) {
for m: ty_method in tmeths {
for a: ty_arg in m.node.inputs { v.visit_ty(a.node.ty, e, v); }
for a in m.node.inputs { v.visit_ty(a.ty, e, v); }
v.visit_ty(m.node.output, e, v);
}
}
@ -205,9 +208,9 @@ fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) {
v.visit_ty(fd.output, e, v);
}
fn visit_fn_proto<E>(f: _fn, _tp: [ty_param], sp: span, i: fn_ident,
id: node_id, e: E, v: vt<E>) {
v.visit_fn_body(f.decl, f.body, sp, i, id, e, v);
fn visit_fn_proto<E>(decl: fn_decl, _tp: [ty_param], body: blk, sp: span,
i: fn_ident, id: node_id, e: E, v: vt<E>) {
v.visit_fn_body(decl, body, sp, i, id, e, v);
}
fn visit_fn_block<E>(decl: fn_decl, body: blk, sp: span, id: node_id,
@ -307,8 +310,8 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
v.visit_expr(x, e, v);
for a: arm in arms { v.visit_arm(a, e, v); }
}
expr_fn(f, captures) {
v.visit_fn_proto(f, [], ex.span, none, ex.id, e, v);
expr_fn(decl, body, _) {
v.visit_fn_proto(decl, [], body, ex.span, none, ex.id, e, v);
}
expr_fn_block(decl, body) {
v.visit_fn_block(decl, body, ex.span, ex.id, e, v);
@ -354,8 +357,8 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
some(ex) { v.visit_expr(ex, e, v); }
}
for m: @method in anon_obj.methods {
v.visit_fn_proto(m.node.meth, m.node.tps, m.span,
some(m.node.ident), m.node.id, e, v);
v.visit_fn_proto(m.decl, m.tps, m.body, m.span,
some(m.ident), m.id, e, v);
}
}
expr_mac(mac) { visit_mac(mac, e, v); }
@ -387,7 +390,7 @@ type simple_visitor =
visit_expr: fn@(@expr),
visit_ty: fn@(@ty),
visit_constr: fn@(@path, span, node_id),
visit_fn_proto: fn@(_fn, [ty_param], span, fn_ident, node_id),
visit_fn_proto: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id),
visit_fn_block: fn@(fn_decl, blk, span, node_id),
visit_fn_body: fn@(fn_decl, blk, span, fn_ident, node_id)};
@ -408,8 +411,8 @@ fn default_simple_visitor() -> simple_visitor {
visit_ty: simple_ignore_ty,
visit_constr: fn(_p: @path, _sp: span, _id: node_id) { },
visit_fn_proto:
fn(_f: _fn, _tps: [ty_param], _sp: span, _ident: fn_ident,
_id: node_id) { },
fn(_d: fn_decl, _tps: [ty_param], _b: blk, _sp: span,
_ident: fn_ident, _id: node_id) { },
visit_fn_block:
fn(_f: fn_decl, _b: blk, _sp: span, _node_id: node_id) { },
visit_fn_body:
@ -473,11 +476,11 @@ fn mk_simple_visitor(v: simple_visitor) -> 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<()>) {
f(ff, tps, sp, ident, id);
visit_fn_proto(ff, tps, sp, ident, id, e, v);
fn v_fn(f: fn@(fn_decl, [ty_param], blk, span, fn_ident, node_id),
decl: fn_decl, tps: [ty_param], body: blk, sp: span,
ident: fn_ident, id: node_id, &&e: (), v: vt<()>) {
f(decl, tps, body, sp, ident, id);
visit_fn_proto(decl, tps, body, sp, ident, id, e, v);
}
fn v_fn_block(f: fn@(fn_decl, blk, span, node_id),
fn_decl: fn_decl, blk: blk,
@ -513,7 +516,7 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
visit_ty: visit_ty,
visit_constr: bind v_constr(v.visit_constr, _, _, _, _, _),
visit_fn_proto:
bind v_fn(v.visit_fn_proto, _, _, _, _, _, _, _),
bind v_fn(v.visit_fn_proto, _, _, _, _, _, _, _, _),
visit_fn_block:
bind v_fn_block(v.visit_fn_block, _, _, _, _, _, _),
visit_fn_body:

View File

@ -62,15 +62,6 @@ fn log_block_err(b: ast::blk) {
fn log_item_err(i: @ast::item) {
log_full(core::error, print::pprust::item_to_str(i));
}
fn log_fn(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) {
log_full(core::debug, print::pprust::fun_to_str(f, name, params));
}
fn log_fn_err(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) {
log_full(core::error, print::pprust::fun_to_str(f, name, params));
}
fn log_stmt(st: ast::stmt) {
log_full(core::debug, print::pprust::stmt_to_str(st));
}

View File

@ -34,7 +34,7 @@ type fndoc = {
doc = "Function docs extracted from attributes",
_fn = "AST object representing this function")
)]
fn doc_fn(rd: rustdoc, ident: str, doc: fndoc, _fn: ast::_fn) {
fn doc_fn(rd: rustdoc, ident: str, doc: fndoc, decl: ast::fn_decl) {
rd.w.write_line("## Function `" + ident + "`");
rd.w.write_line(doc.brief);
alt doc.desc {
@ -45,7 +45,7 @@ fn doc_fn(rd: rustdoc, ident: str, doc: fndoc, _fn: ast::_fn) {
}
none. { }
}
for arg: ast::arg in _fn.decl.inputs {
for arg: ast::arg in decl.inputs {
rd.w.write_str("### Argument `" + arg.ident + "`: ");
rd.w.write_line("`" + pprust::ty_to_str(arg.ty) + "`");
alt doc.args.find(arg.ident) {
@ -55,7 +55,7 @@ fn doc_fn(rd: rustdoc, ident: str, doc: fndoc, _fn: ast::_fn) {
none. { }
};
}
rd.w.write_line("### Returns `" + pprust::ty_to_str(_fn.decl.output) + "`");
rd.w.write_line("### Returns `" + pprust::ty_to_str(decl.output) + "`");
alt doc.return {
some(_r) { rd.w.write_line(_r); }
none. { }
@ -152,14 +152,14 @@ fn doc_item(rd: rustdoc, item: @ast::item) {
alt item.node {
ast::item_const(ty, expr) { }
ast::item_fn(_fn, _) {
doc_fn(rd, item.ident, _fndoc0, _fn);
ast::item_fn(decl, _, _) {
doc_fn(rd, item.ident, _fndoc0, decl);
}
ast::item_mod(_mod) { }
ast::item_ty(ty, typarams) { }
ast::item_tag(variant, typarams) { }
ast::item_obj(_obj, typarams, node_id) { }
ast::item_res(dtor, dtorid, typarams, ctorid) { }
ast::item_res(_, _, _, _, _) { }
};
}