Unify some data structures in syntax::ast that were doing the same thing
As a preparation to removing some duplication in typeck.
This commit is contained in:
parent
3b61064631
commit
0490c36143
22 changed files with 327 additions and 397 deletions
|
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,9 @@ 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) {
|
||||
item_fn(fold_fn_decl(decl, fld), typms, fld.fold_block(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 +246,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 +394,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 +449,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 +517,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 +547,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 +584,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 +615,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 +652,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, _),
|
||||
|
|
|
|||
|
|
@ -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") {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue