convert ast::{ty_field_,ty_method} into a struct

This commit is contained in:
Erick Tryzelaar 2013-01-15 15:03:49 -08:00 committed by Tim Chevalier
parent 8cdc3fda11
commit 5ba7e55a4c
5 changed files with 47 additions and 21 deletions

View File

@ -940,15 +940,25 @@ struct mt {
#[auto_encode]
#[auto_decode]
type ty_field_ = {ident: ident, mt: mt};
struct ty_field_ {
ident: ident,
mt: mt,
}
type ty_field = spanned<ty_field_>;
#[auto_encode]
#[auto_decode]
type ty_method = {ident: ident, attrs: ~[attribute], purity: purity,
decl: fn_decl, tps: ~[ty_param], self_ty: self_ty,
id: node_id, span: span};
struct ty_method {
ident: ident,
attrs: ~[attribute],
purity: purity,
decl: fn_decl,
tps: ~[ty_param],
self_ty: self_ty,
id: node_id,
span: span,
}
#[auto_encode]
#[auto_decode]

View File

@ -341,13 +341,19 @@ fn public_methods(ms: ~[@method]) -> ~[@method] {
// a default, pull out the useful fields to make a ty_method
fn trait_method_to_ty_method(method: trait_method) -> ty_method {
match method {
required(ref m) => (*m),
provided(m) => {
{ident: m.ident, attrs: m.attrs,
purity: m.purity, decl: m.decl,
tps: m.tps, self_ty: m.self_ty,
id: m.id, span: m.span}
}
required(ref m) => (*m),
provided(m) => {
ty_method {
ident: m.ident,
attrs: m.attrs,
purity: m.purity,
decl: m.decl,
tps: m.tps,
self_ty: m.self_ty,
id: m.id,
span: m.span,
}
}
}
}

View File

@ -167,7 +167,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
spanned {
node: {
node: ast::ty_field_ {
ident: name,
mt: ast::mt { ty: ty, mutbl: ast::m_imm },
},

View File

@ -541,9 +541,13 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
mt { ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl }
}
fn fold_field(f: ty_field, fld: ast_fold) -> ty_field {
spanned { node: { ident: fld.fold_ident(f.node.ident),
mt: fold_mt(f.node.mt, fld) },
span: fld.new_span(f.span) }
spanned {
node: ast::ty_field_ {
ident: fld.fold_ident(f.node.ident),
mt: fold_mt(f.node.mt, fld),
},
span: fld.new_span(f.span),
}
}
match t {
ty_nil | ty_bot | ty_infer => copy t,

View File

@ -421,10 +421,16 @@ impl Parser {
debug!("parse_trait_methods(): parsing required method");
// NB: at the moment, visibility annotations on required
// methods are ignored; this could change.
required({ident: ident, attrs: attrs,
purity: pur, decl: d, tps: tps,
self_ty: self_ty,
id: p.get_id(), span: mk_sp(lo, hi)})
required(ty_method {
ident: ident,
attrs: attrs,
purity: pur,
decl: d,
tps: tps,
self_ty: self_ty,
id: p.get_id(),
span: mk_sp(lo, hi)
})
}
token::LBRACE => {
debug!("parse_trait_methods(): parsing provided method");
@ -467,9 +473,9 @@ impl Parser {
spanned(
lo,
ty.span.hi,
{
ast::ty_field_ {
ident: id,
mt: ast::mt { ty: ty, mutbl: mutbl }
mt: ast::mt { ty: ty, mutbl: mutbl },
}
)
}