convert ast::ty into a struct
This commit is contained in:
parent
8a3a1fc148
commit
8cdc3fda11
10 changed files with 149 additions and 80 deletions
|
@ -329,19 +329,25 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::Ty {
|
|||
mk_path(cx, ~[cx.sess.ident_of(~"test"),
|
||||
cx.sess.ident_of(~"TestDesc")]);
|
||||
|
||||
let test_desc_ty: ast::Ty =
|
||||
{id: cx.sess.next_node_id(),
|
||||
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
|
||||
span: dummy_sp()};
|
||||
let test_desc_ty = ast::Ty {
|
||||
id: cx.sess.next_node_id(),
|
||||
node: ast::ty_path(test_desc_ty_path, cx.sess.next_node_id()),
|
||||
span: dummy_sp(),
|
||||
};
|
||||
|
||||
let vec_mt = ast::mt {ty: @test_desc_ty, mutbl: ast::m_imm};
|
||||
|
||||
let inner_ty = @{id: cx.sess.next_node_id(),
|
||||
node: ast::ty_vec(vec_mt),
|
||||
span: dummy_sp()};
|
||||
return @{id: cx.sess.next_node_id(),
|
||||
node: ast::ty_uniq(ast::mt {ty: inner_ty, mutbl: ast::m_imm}),
|
||||
span: dummy_sp()};
|
||||
let inner_ty = @ast::Ty {
|
||||
id: cx.sess.next_node_id(),
|
||||
node: ast::ty_vec(vec_mt),
|
||||
span: dummy_sp(),
|
||||
};
|
||||
|
||||
@ast::Ty {
|
||||
id: cx.sess.next_node_id(),
|
||||
node: ast::ty_uniq(ast::mt { ty: inner_ty, mutbl: ast::m_imm }),
|
||||
span: dummy_sp(),
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
|
||||
|
@ -482,7 +488,11 @@ fn mk_test_wrapper(cx: test_ctxt,
|
|||
|
||||
let wrapper_decl: ast::fn_decl = {
|
||||
inputs: ~[],
|
||||
output: @{id: cx.sess.next_node_id(), node: ast::ty_nil, span: span},
|
||||
output: @ast::Ty {
|
||||
id: cx.sess.next_node_id(),
|
||||
node: ast::ty_nil,
|
||||
span: span,
|
||||
},
|
||||
cf: ast::return_val
|
||||
};
|
||||
|
||||
|
@ -505,9 +515,11 @@ fn mk_test_wrapper(cx: test_ctxt,
|
|||
}
|
||||
|
||||
fn mk_main(cx: test_ctxt) -> @ast::item {
|
||||
let ret_ty = {id: cx.sess.next_node_id(),
|
||||
node: ast::ty_nil,
|
||||
span: dummy_sp()};
|
||||
let ret_ty = ast::Ty {
|
||||
id: cx.sess.next_node_id(),
|
||||
node: ast::ty_nil,
|
||||
span: dummy_sp(),
|
||||
};
|
||||
|
||||
let decl: ast::fn_decl =
|
||||
{inputs: ~[],
|
||||
|
|
|
@ -1281,7 +1281,7 @@ impl Resolver {
|
|||
// If there are static methods, then create the module
|
||||
// and add them.
|
||||
match (trait_ref_opt, ty) {
|
||||
(None, @{ id: _, node: ty_path(path, _), span: _ }) if
|
||||
(None, @Ty { node: ty_path(path, _), _ }) if
|
||||
has_static_methods && path.idents.len() == 1 => {
|
||||
// Create the module.
|
||||
let name = path_to_ident(path);
|
||||
|
|
|
@ -1040,7 +1040,11 @@ impl float_ty : cmp::Eq {
|
|||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type Ty = {id: node_id, node: ty_, span: span};
|
||||
struct Ty {
|
||||
id: node_id,
|
||||
node: ty_,
|
||||
span: span,
|
||||
}
|
||||
|
||||
// Not represented directly in the AST, referred to by name through a ty_path.
|
||||
#[auto_encode]
|
||||
|
|
|
@ -435,7 +435,7 @@ fn operator_prec(op: ast::binop) -> uint {
|
|||
}
|
||||
|
||||
fn dtor_dec() -> fn_decl {
|
||||
let nil_t = @{id: 0, node: ty_nil, span: dummy_sp()};
|
||||
let nil_t = @ast::Ty { id: 0, node: ty_nil, span: dummy_sp() };
|
||||
// dtor has no args
|
||||
{inputs: ~[],
|
||||
output: nil_t, cf: return_val}
|
||||
|
|
|
@ -130,7 +130,10 @@ fn expand_auto_encode(
|
|||
do vec::flat_map(in_items) |item| {
|
||||
if item.attrs.any(is_auto_encode) {
|
||||
match item.node {
|
||||
ast::item_ty(@{node: ast::ty_rec(ref fields), _}, tps) => {
|
||||
ast::item_ty(
|
||||
@ast::Ty {node: ast::ty_rec(ref fields), _},
|
||||
tps
|
||||
) => {
|
||||
let ser_impl = mk_rec_ser_impl(
|
||||
cx,
|
||||
item.span,
|
||||
|
@ -196,7 +199,10 @@ fn expand_auto_decode(
|
|||
do vec::flat_map(in_items) |item| {
|
||||
if item.attrs.any(is_auto_decode) {
|
||||
match item.node {
|
||||
ast::item_ty(@{node: ast::ty_rec(ref fields), _}, tps) => {
|
||||
ast::item_ty(
|
||||
@ast::Ty {node: ast::ty_rec(ref fields), _},
|
||||
tps
|
||||
) => {
|
||||
let deser_impl = mk_rec_deser_impl(
|
||||
cx,
|
||||
item.span,
|
||||
|
@ -249,7 +255,7 @@ priv impl ext_ctxt {
|
|||
path: @ast::path,
|
||||
bounds: @~[ast::ty_param_bound]
|
||||
) -> ast::ty_param {
|
||||
let bound = ast::TraitTyParamBound(@{
|
||||
let bound = ast::TraitTyParamBound(@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_path(path, self.next_id()),
|
||||
span: span,
|
||||
|
@ -315,9 +321,13 @@ priv impl ext_ctxt {
|
|||
|
||||
fn ty_path(span: span, strs: ~[ast::ident],
|
||||
tps: ~[@ast::Ty]) -> @ast::Ty {
|
||||
@{id: self.next_id(),
|
||||
node: ast::ty_path(self.path_tps(span, strs, tps), self.next_id()),
|
||||
span: span}
|
||||
@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_path(
|
||||
self.path_tps(span, strs, tps),
|
||||
self.next_id()),
|
||||
span: span,
|
||||
}
|
||||
}
|
||||
|
||||
fn binder_pat(span: span, nm: ast::ident) -> @ast::pat {
|
||||
|
@ -438,7 +448,7 @@ fn mk_impl(
|
|||
let mut trait_tps = vec::append(
|
||||
~[ty_param],
|
||||
do tps.map |tp| {
|
||||
let t_bound = ast::TraitTyParamBound(@{
|
||||
let t_bound = ast::TraitTyParamBound(@ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: ast::ty_path(path, cx.next_id()),
|
||||
span: span,
|
||||
|
@ -568,7 +578,7 @@ fn mk_ser_method(
|
|||
span: span,
|
||||
ser_body: ast::blk
|
||||
) -> @ast::method {
|
||||
let ty_s = @{
|
||||
let ty_s = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: ast::ty_rptr(
|
||||
@{
|
||||
|
@ -597,7 +607,7 @@ fn mk_ser_method(
|
|||
id: cx.next_id(),
|
||||
}];
|
||||
|
||||
let ser_output = @{
|
||||
let ser_output = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: ast::ty_nil,
|
||||
span: span,
|
||||
|
@ -631,7 +641,7 @@ fn mk_deser_method(
|
|||
ty: @ast::Ty,
|
||||
deser_body: ast::blk
|
||||
) -> @ast::method {
|
||||
let ty_d = @{
|
||||
let ty_d = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: ast::ty_rptr(
|
||||
@{
|
||||
|
@ -670,8 +680,7 @@ fn mk_deser_method(
|
|||
ident: cx.ident_of(~"decode"),
|
||||
attrs: ~[],
|
||||
tps: ~[],
|
||||
self_ty: ast::spanned { node: ast::sty_static,
|
||||
span: span },
|
||||
self_ty: ast::spanned { node: ast::sty_static, span: span },
|
||||
purity: ast::impure_fn,
|
||||
decl: deser_decl,
|
||||
body: deser_body,
|
||||
|
@ -1181,7 +1190,7 @@ fn mk_enum_deser_body(
|
|||
{
|
||||
inputs: ~[{
|
||||
mode: ast::infer(cx.next_id()),
|
||||
ty: @{
|
||||
ty: @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: ast::ty_infer,
|
||||
span: span
|
||||
|
@ -1196,7 +1205,7 @@ fn mk_enum_deser_body(
|
|||
},
|
||||
id: cx.next_id(),
|
||||
}],
|
||||
output: @{
|
||||
output: @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: ast::ty_infer,
|
||||
span: span,
|
||||
|
|
|
@ -194,7 +194,7 @@ fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
|
|||
None),
|
||||
span: sp,
|
||||
};
|
||||
let ty : @ast::Ty = @{ id: cx.next_id(), node: ast::ty_infer, span: sp };
|
||||
let ty = @ast::Ty { id: cx.next_id(), node: ast::ty_infer, span: sp };
|
||||
let local = @ast::spanned {
|
||||
node: ast::local_ {
|
||||
is_mutbl: mutbl,
|
||||
|
@ -293,7 +293,7 @@ fn mk_ty_path(cx: ext_ctxt,
|
|||
-> @ast::Ty {
|
||||
let ty = build::mk_raw_path(span, idents);
|
||||
let ty = ast::ty_path(ty, cx.next_id());
|
||||
let ty = @{ id: cx.next_id(), node: move ty, span: span };
|
||||
let ty = @ast::Ty { id: cx.next_id(), node: move ty, span: span };
|
||||
ty
|
||||
}
|
||||
fn mk_ty_path_global(cx: ext_ctxt,
|
||||
|
@ -302,7 +302,7 @@ fn mk_ty_path_global(cx: ext_ctxt,
|
|||
-> @ast::Ty {
|
||||
let ty = build::mk_raw_path_global(span, idents);
|
||||
let ty = ast::ty_path(ty, cx.next_id());
|
||||
let ty = @{ id: cx.next_id(), node: move ty, span: span };
|
||||
let ty = @ast::Ty { id: cx.next_id(), node: move ty, span: span };
|
||||
ty
|
||||
}
|
||||
fn mk_simple_ty_path(cx: ext_ctxt,
|
||||
|
|
|
@ -140,7 +140,11 @@ fn create_eq_method(cx: ext_ctxt,
|
|||
arg_region,
|
||||
ast::mt { ty: arg_path_type, mutbl: m_imm }
|
||||
);
|
||||
let arg_type = @{ id: cx.next_id(), node: move arg_type, span: span };
|
||||
let arg_type = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: arg_type,
|
||||
span: span,
|
||||
};
|
||||
|
||||
// Create the `other` parameter.
|
||||
let other_ident = cx.ident_of(~"__other");
|
||||
|
@ -150,10 +154,10 @@ fn create_eq_method(cx: ext_ctxt,
|
|||
let bool_ident = cx.ident_of(~"bool");
|
||||
let output_type = build::mk_raw_path(span, ~[ bool_ident ]);
|
||||
let output_type = ty_path(output_type, cx.next_id());
|
||||
let output_type = @{
|
||||
let output_type = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
node: move output_type,
|
||||
span: span
|
||||
node: output_type,
|
||||
span: span,
|
||||
};
|
||||
|
||||
// Create the function declaration.
|
||||
|
@ -199,7 +203,7 @@ fn create_self_type_with_params(cx: ext_ctxt,
|
|||
~[ type_ident ],
|
||||
move self_ty_params);
|
||||
let self_type = ty_path(self_type, cx.next_id());
|
||||
@{ id: cx.next_id(), node: move self_type, span: span }
|
||||
@ast::Ty { id: cx.next_id(), node: self_type, span: span }
|
||||
}
|
||||
|
||||
fn create_derived_impl(cx: ext_ctxt,
|
||||
|
@ -303,7 +307,7 @@ fn create_iter_bytes_method(cx: ext_ctxt,
|
|||
let f_arg = build::mk_arg(cx, span, f_ident, f_arg_type);
|
||||
|
||||
// Create the type of the return value.
|
||||
let output_type = @{ id: cx.next_id(), node: ty_nil, span: span };
|
||||
let output_type = @ast::Ty { id: cx.next_id(), node: ty_nil, span: span };
|
||||
|
||||
// Create the function declaration.
|
||||
let inputs = ~[ move lsb0_arg, move f_arg ];
|
||||
|
|
|
@ -176,15 +176,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
}
|
||||
|
||||
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
|
||||
@{id: self.next_id(),
|
||||
node: ast::ty_rec(fields),
|
||||
span: dummy_sp()}
|
||||
@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_rec(fields),
|
||||
span: dummy_sp(),
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_infer() -> @ast::Ty {
|
||||
@{id: self.next_id(),
|
||||
node: ast::ty_infer,
|
||||
span: dummy_sp()}
|
||||
@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_infer,
|
||||
span: dummy_sp(),
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
|
||||
|
@ -340,15 +344,19 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
}
|
||||
|
||||
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty {
|
||||
@{id: self.next_id(),
|
||||
node: ast::ty_path(path, self.next_id()),
|
||||
span: path.span}
|
||||
@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_path(path, self.next_id()),
|
||||
span: path.span,
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_nil_ast_builder() -> @ast::Ty {
|
||||
@{id: self.next_id(),
|
||||
node: ast::ty_nil,
|
||||
span: dummy_sp()}
|
||||
@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_nil,
|
||||
span: dummy_sp(),
|
||||
}
|
||||
}
|
||||
|
||||
fn item_ty_poly(name: ident,
|
||||
|
|
|
@ -770,7 +770,11 @@ impl ast_fold_fns: ast_fold {
|
|||
}
|
||||
fn fold_ty(&&x: @Ty) -> @Ty {
|
||||
let (n, s) = (self.fold_ty)(x.node, x.span, self as ast_fold);
|
||||
return @{id: (self.new_id)(x.id), node: n, span: (self.new_span)(s)};
|
||||
@Ty {
|
||||
id: (self.new_id)(x.id),
|
||||
node: n,
|
||||
span: (self.new_span)(s),
|
||||
}
|
||||
}
|
||||
fn fold_mod(x: _mod) -> _mod {
|
||||
return (self.fold_mod)(x, self as ast_fold);
|
||||
|
|
|
@ -478,17 +478,27 @@ impl Parser {
|
|||
return if self.eat(token::RARROW) {
|
||||
let lo = self.span.lo;
|
||||
if self.eat(token::NOT) {
|
||||
(noreturn, @{id: self.get_id(),
|
||||
node: ty_bot,
|
||||
span: mk_sp(lo, self.last_span.hi)})
|
||||
(
|
||||
noreturn,
|
||||
@Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_bot,
|
||||
span: mk_sp(lo, self.last_span.hi)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
(return_val, self.parse_ty(false))
|
||||
}
|
||||
} else {
|
||||
let pos = self.span.lo;
|
||||
(return_val, @{id: self.get_id(),
|
||||
node: ty_nil,
|
||||
span: mk_sp(pos, pos)})
|
||||
(
|
||||
return_val,
|
||||
@Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_nil,
|
||||
span: mk_sp(pos, pos),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -580,7 +590,7 @@ impl Parser {
|
|||
} else { self.fatal(~"expected type"); };
|
||||
|
||||
let sp = mk_sp(lo, self.last_span.hi);
|
||||
return @{id: self.get_id(), node: t, span: sp};
|
||||
@Ty {id: self.get_id(), node: t, span: sp}
|
||||
}
|
||||
|
||||
fn parse_box_or_uniq_pointee(
|
||||
|
@ -731,9 +741,11 @@ impl Parser {
|
|||
let t = if p.eat(token::COLON) {
|
||||
p.parse_ty(false)
|
||||
} else {
|
||||
@{id: p.get_id(),
|
||||
node: ty_infer,
|
||||
span: mk_sp(p.span.lo, p.span.hi)}
|
||||
@Ty {
|
||||
id: p.get_id(),
|
||||
node: ty_infer,
|
||||
span: mk_sp(p.span.lo, p.span.hi),
|
||||
}
|
||||
};
|
||||
either::Left({mode: m, ty: t, pat: pat, id: p.get_id()})
|
||||
}
|
||||
|
@ -1565,7 +1577,7 @@ impl Parser {
|
|||
({
|
||||
{
|
||||
inputs: ~[],
|
||||
output: @{
|
||||
output: @Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_infer,
|
||||
span: self.span
|
||||
|
@ -2150,9 +2162,11 @@ impl Parser {
|
|||
allow_init: bool) -> @local {
|
||||
let lo = self.span.lo;
|
||||
let pat = self.parse_pat(false);
|
||||
let mut ty = @{id: self.get_id(),
|
||||
node: ty_infer,
|
||||
span: mk_sp(lo, lo)};
|
||||
let mut ty = @Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_infer,
|
||||
span: mk_sp(lo, lo),
|
||||
};
|
||||
if self.eat(token::COLON) { ty = self.parse_ty(false); }
|
||||
let init = if allow_init { self.parse_initializer() } else { None };
|
||||
@spanned(
|
||||
|
@ -2430,9 +2444,13 @@ impl Parser {
|
|||
}
|
||||
|
||||
fn mk_ty_path(i: ident) -> @Ty {
|
||||
@{id: self.get_id(), node: ty_path(
|
||||
ident_to_path(copy self.last_span, i),
|
||||
self.get_id()), span: self.last_span}
|
||||
@Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_path(
|
||||
ident_to_path(copy self.last_span, i),
|
||||
self.get_id()),
|
||||
span: self.last_span,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_optional_purity() -> ast::purity {
|
||||
|
@ -2650,7 +2668,7 @@ impl Parser {
|
|||
let output = if self.eat(token::RARROW) {
|
||||
self.parse_ty(false)
|
||||
} else {
|
||||
@{id: self.get_id(), node: ty_infer, span: self.span}
|
||||
@Ty { id: self.get_id(), node: ty_infer, span: self.span }
|
||||
};
|
||||
return ({inputs: either::lefts(inputs_captures),
|
||||
output: output,
|
||||
|
@ -2733,7 +2751,11 @@ impl Parser {
|
|||
// impl<T> ~[T] : to_str { ... }
|
||||
fn parse_item_impl() -> item_info {
|
||||
fn wrap_path(p: Parser, pt: @path) -> @Ty {
|
||||
@{id: p.get_id(), node: ty_path(pt, p.get_id()), span: pt.span}
|
||||
@Ty {
|
||||
id: p.get_id(),
|
||||
node: ty_path(pt, p.get_id()),
|
||||
span: pt.span,
|
||||
}
|
||||
}
|
||||
|
||||
// We do two separate paths here: old-style impls and new-style impls.
|
||||
|
@ -2786,7 +2808,7 @@ impl Parser {
|
|||
idents: ~[i],
|
||||
rp: None,
|
||||
types: do typarams.map |tp| {
|
||||
@{
|
||||
@Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_path(ident_to_path(s, tp.ident), self.get_id()),
|
||||
span: s
|
||||
|
@ -2938,13 +2960,19 @@ impl Parser {
|
|||
self.obsolete(copy self.span, ObsoleteClassMethod);
|
||||
self.parse_method();
|
||||
// bogus value
|
||||
@spanned(self.span.lo, self.span.hi,
|
||||
ast::struct_field_ {
|
||||
kind: unnamed_field,
|
||||
id: self.get_id(),
|
||||
ty: @{id: self.get_id(),
|
||||
node: ty_nil,
|
||||
span: copy self.span} })
|
||||
@spanned(
|
||||
self.span.lo,
|
||||
self.span.hi,
|
||||
ast::struct_field_ {
|
||||
kind: unnamed_field,
|
||||
id: self.get_id(),
|
||||
ty: @ast::Ty {
|
||||
id: self.get_id(),
|
||||
node: ty_nil,
|
||||
span: copy self.span,
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue