Make ast::ty_method hold a fn_decl, rather than duplicating its fields

This commit is contained in:
Marijn Haverbeke 2011-12-23 13:32:17 +01:00
parent f0dfbe7b1b
commit 970f5cc0e4
5 changed files with 20 additions and 39 deletions

View File

@ -356,21 +356,21 @@ 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::arg in m.node.inputs {
for ta: ast::arg in m.decl.inputs {
ins += [ast_arg_to_arg(tcx, mode, ta)];
}
let out = ast_ty_to_ty(tcx, mode, m.node.output);
let out = ast_ty_to_ty(tcx, mode, m.decl.output);
let out_constrs = [];
for constr: @ast::constr in m.node.constrs {
for constr: @ast::constr in m.decl.constraints {
out_constrs += [ty::ast_constr_to_constr(tcx, constr)];
}
let new_m: ty::method =
{proto: m.node.proto,
ident: m.node.ident,
{proto: m.decl.proto,
ident: m.ident,
inputs: ins,
output: out,
cf: m.node.cf,
cf: m.decl.cf,
constrs: out_constrs};
tmeths += [new_m];
}

View File

@ -307,17 +307,9 @@ type mt = {ty: @ty, mut: mutability};
type ty_field_ = {ident: ident, mt: mt};
type ty_method_ =
{proto: proto,
ident: ident,
inputs: [arg],
output: @ty,
cf: ret_style,
constrs: [@constr]};
type ty_field = spanned<ty_field_>;
type ty_method = spanned<ty_method_>;
type ty_method = {ident: ident, decl: fn_decl, span: span};
tag int_ty { ty_i; ty_char; ty_i8; ty_i16; ty_i32; ty_i64; }

View File

@ -294,14 +294,7 @@ fn parse_ty_obj(p: parser) -> ast::ty_ {
expect(p, token::SEMI);
alt f {
ast::ty_fn(d) {
// FIXME[fn_decl]
ret spanned(flo, fhi,
{proto: d.proto,
ident: ident,
inputs: d.inputs,
output: d.output,
cf: d.cf,
constrs: d.constraints});
{ident: ident, decl: d, span: ast_util::mk_sp(flo, fhi)}
}
}
}

View File

@ -306,8 +306,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
pclose(s);
}
ast::ty_fn(d) {
print_ty_fn(s, d.proto, none::<str>, d.inputs, d.output, d.cf,
d.constraints);
print_ty_fn(s, d, none::<str>);
}
ast::ty_obj(methods) {
head(s, "obj");
@ -316,8 +315,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
hardbreak_if_not_bol(s);
cbox(s, indent_unit);
maybe_print_comment(s, m.span.lo);
print_ty_fn(s, m.node.proto, some(m.node.ident), m.node.inputs,
m.node.output, m.node.cf, m.node.constrs);
print_ty_fn(s, m.decl, some(m.ident));
word(s.s, ";");
end(s);
}
@ -1338,11 +1336,9 @@ fn print_mt(s: ps, mt: ast::mt) {
print_type(s, mt.ty);
}
fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
inputs: [ast::arg], output: @ast::ty, cf: ast::ret_style,
constrs: [@ast::constr]) {
fn print_ty_fn(s: ps, decl: ast::fn_decl, id: option::t<ast::ident>) {
ibox(s, indent_unit);
word(s.s, proto_to_str(proto));
word(s.s, proto_to_str(decl.proto));
alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } }
zerobreak(s.s);
popen(s);
@ -1353,18 +1349,18 @@ fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>,
}
print_type(s, input.ty);
}
commasep(s, inconsistent, inputs, print_arg);
commasep(s, inconsistent, decl.inputs, print_arg);
pclose(s);
maybe_print_comment(s, output.span.lo);
if output.node != ast::ty_nil {
maybe_print_comment(s, decl.output.span.lo);
if decl.output.node != ast::ty_nil {
space_if_not_bol(s);
ibox(s, indent_unit);
word_space(s, "->");
if cf == ast::noreturn { word_nbsp(s, "!"); }
else { print_type(s, output); }
if decl.cf == ast::noreturn { word_nbsp(s, "!"); }
else { print_type(s, decl.output); }
end(s);
}
word(s.s, ast_ty_fn_constrs_str(constrs));
word(s.s, ast_ty_fn_constrs_str(decl.constraints));
end(s);
}

View File

@ -151,8 +151,8 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
}
ty_obj(tmeths) {
for m: ty_method in tmeths {
for a in m.node.inputs { v.visit_ty(a.ty, e, v); }
v.visit_ty(m.node.output, e, v);
for a in m.decl.inputs { v.visit_ty(a.ty, e, v); }
v.visit_ty(m.decl.output, e, v);
}
}
ty_path(p, _) { visit_path(p, e, v); }