convert ast::expr into a struct
This commit is contained in:
parent
1280a64089
commit
8a3a1fc148
15 changed files with 222 additions and 148 deletions
|
|
@ -696,8 +696,14 @@ impl blk_check_mode : cmp::Eq {
|
|||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
type expr = {id: node_id, callee_id: node_id, node: expr_, span: span};
|
||||
// Extra node ID is only used for index, assign_op, unary, binary, method call
|
||||
struct expr {
|
||||
id: node_id,
|
||||
// Extra node ID is only used for index, assign_op, unary, binary, method
|
||||
// call
|
||||
callee_id: node_id,
|
||||
node: expr_,
|
||||
span: span,
|
||||
}
|
||||
|
||||
#[auto_encode]
|
||||
#[auto_decode]
|
||||
|
|
|
|||
|
|
@ -263,8 +263,12 @@ priv impl ext_ctxt {
|
|||
}
|
||||
|
||||
fn expr(span: span, node: ast::expr_) -> @ast::expr {
|
||||
@{id: self.next_id(), callee_id: self.next_id(),
|
||||
node: node, span: span}
|
||||
@ast::expr {
|
||||
id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: node,
|
||||
span: span,
|
||||
}
|
||||
}
|
||||
|
||||
fn path(span: span, strs: ~[ast::ident]) -> @ast::path {
|
||||
|
|
|
|||
|
|
@ -19,10 +19,13 @@ use ext::build;
|
|||
use core::dvec;
|
||||
use core::option;
|
||||
|
||||
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) ->
|
||||
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) -> @ast::expr {
|
||||
@ast::expr {
|
||||
return @{id: cx.next_id(), callee_id: cx.next_id(),
|
||||
node: expr, span: sp};
|
||||
id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: expr,
|
||||
span: sp,
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
|
||||
|
|
|
|||
|
|
@ -34,13 +34,19 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, tts: ~[ast::token_tree])
|
|||
}
|
||||
let res = cx.parse_sess().interner.intern(@res_str);
|
||||
|
||||
let e = @{id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: ast::expr_path(@ast::path { span: sp,
|
||||
global: false,
|
||||
idents: ~[res],
|
||||
rp: None,
|
||||
types: ~[] }),
|
||||
span: sp};
|
||||
let e = @ast::expr {
|
||||
id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: ast::expr_path(
|
||||
@ast::path {
|
||||
span: sp,
|
||||
global: false,
|
||||
idents: ~[res],
|
||||
rp: None,
|
||||
types: ~[],
|
||||
}
|
||||
),
|
||||
span: sp,
|
||||
};
|
||||
mr_expr(e)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, tt: ~[ast::token_tree])
|
|||
print::pprust::tt_to_str(ast::tt_delim(tt),cx.parse_sess().interner));
|
||||
|
||||
//trivial expression
|
||||
return mr_expr(@{id: cx.next_id(), callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::None), span: sp});
|
||||
mr_expr(@ast::expr {
|
||||
id: cx.next_id(),
|
||||
callee_id: cx.next_id(),
|
||||
node: ast::expr_rec(~[], option::None),
|
||||
span: sp,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,17 +122,21 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
}
|
||||
|
||||
fn block_expr(b: ast::blk) -> @ast::expr {
|
||||
@{id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_block(b),
|
||||
span: dummy_sp()}
|
||||
@expr {
|
||||
id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_block(b),
|
||||
span: dummy_sp(),
|
||||
}
|
||||
}
|
||||
|
||||
fn move_expr(e: @ast::expr) -> @ast::expr {
|
||||
@{id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_unary_move(e),
|
||||
span: e.span}
|
||||
@expr {
|
||||
id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_unary_move(e),
|
||||
span: e.span,
|
||||
}
|
||||
}
|
||||
|
||||
fn stmt_expr(e: @ast::expr) -> @ast::stmt {
|
||||
|
|
@ -153,10 +157,12 @@ impl ext_ctxt: ext_ctxt_ast_builder {
|
|||
}
|
||||
|
||||
fn rec(+fields: ~[ast::field]) -> @ast::expr {
|
||||
@{id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_rec(fields, None),
|
||||
span: dummy_sp()}
|
||||
@expr {
|
||||
id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
node: ast::expr_rec(fields, None),
|
||||
span: dummy_sp(),
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
|
||||
|
|
|
|||
|
|
@ -761,10 +761,12 @@ impl ast_fold_fns: ast_fold {
|
|||
}
|
||||
fn fold_expr(&&x: @expr) -> @expr {
|
||||
let (n, s) = (self.fold_expr)(x.node, x.span, self as ast_fold);
|
||||
return @{id: (self.new_id)(x.id),
|
||||
callee_id: (self.new_id)(x.callee_id),
|
||||
node: n,
|
||||
span: (self.new_span)(s)};
|
||||
@expr {
|
||||
id: (self.new_id)(x.id),
|
||||
callee_id: (self.new_id)(x.callee_id),
|
||||
node: n,
|
||||
span: (self.new_span)(s),
|
||||
}
|
||||
}
|
||||
fn fold_ty(&&x: @Ty) -> @Ty {
|
||||
let (n, s) = (self.fold_ty)(x.node, x.span, self as ast_fold);
|
||||
|
|
|
|||
|
|
@ -888,15 +888,21 @@ impl Parser {
|
|||
}
|
||||
|
||||
fn mk_expr(+lo: BytePos, +hi: BytePos, +node: expr_) -> @expr {
|
||||
return @{id: self.get_id(), callee_id: self.get_id(),
|
||||
node: node, span: mk_sp(lo, hi)};
|
||||
@expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: node,
|
||||
span: mk_sp(lo, hi),
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_mac_expr(+lo: BytePos, +hi: BytePos, m: mac_) -> @expr {
|
||||
return @{id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: expr_mac(spanned {node: m, span: mk_sp(lo, hi)}),
|
||||
span: mk_sp(lo, hi)};
|
||||
@expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: expr_mac(spanned {node: m, span: mk_sp(lo, hi)}),
|
||||
span: mk_sp(lo, hi),
|
||||
}
|
||||
}
|
||||
|
||||
fn mk_lit_u32(i: u32) -> @expr {
|
||||
|
|
@ -904,8 +910,12 @@ impl Parser {
|
|||
let lv_lit = @spanned { node: lit_uint(i as u64, ty_u32),
|
||||
span: span };
|
||||
|
||||
return @{id: self.get_id(), callee_id: self.get_id(),
|
||||
node: expr_lit(lv_lit), span: span};
|
||||
@expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: expr_lit(lv_lit),
|
||||
span: span,
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_bottom_expr() -> @expr {
|
||||
|
|
@ -1625,23 +1635,21 @@ impl Parser {
|
|||
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
|
||||
ctor(block));
|
||||
let args = vec::append(args, ~[last_arg]);
|
||||
@{node: expr_call(f, args, true),
|
||||
.. *e}
|
||||
@expr {node: expr_call(f, args, true), .. *e}
|
||||
}
|
||||
expr_method_call(f, i, tps, args, false) => {
|
||||
let block = self.parse_lambda_block_expr();
|
||||
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
|
||||
ctor(block));
|
||||
let args = vec::append(args, ~[last_arg]);
|
||||
@{node: expr_method_call(f, i, tps, args, true),
|
||||
.. *e}
|
||||
@expr {node: expr_method_call(f, i, tps, args, true), .. *e}
|
||||
}
|
||||
expr_field(f, i, tps) => {
|
||||
let block = self.parse_lambda_block_expr();
|
||||
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
|
||||
ctor(block));
|
||||
@{node: expr_method_call(f, i, tps, ~[last_arg], true),
|
||||
.. *e}
|
||||
@expr {node: expr_method_call(f, i, tps, ~[last_arg], true),
|
||||
.. *e}
|
||||
}
|
||||
expr_path(*) | expr_call(*) | expr_method_call(*) |
|
||||
expr_paren(*) => {
|
||||
|
|
@ -1916,12 +1924,15 @@ impl Parser {
|
|||
hi = sub.span.hi;
|
||||
// HACK: parse @"..." as a literal of a vstore @str
|
||||
pat = match sub.node {
|
||||
pat_lit(e@@{
|
||||
pat_lit(e@@expr {
|
||||
node: expr_lit(@spanned {node: lit_str(_), span: _}), _
|
||||
}) => {
|
||||
let vst = @{id: self.get_id(), callee_id: self.get_id(),
|
||||
node: expr_vstore(e, expr_vstore_box),
|
||||
span: mk_sp(lo, hi)};
|
||||
let vst = @expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: expr_vstore(e, expr_vstore_box),
|
||||
span: mk_sp(lo, hi),
|
||||
};
|
||||
pat_lit(vst)
|
||||
}
|
||||
_ => pat_box(sub)
|
||||
|
|
@ -1933,12 +1944,15 @@ impl Parser {
|
|||
hi = sub.span.hi;
|
||||
// HACK: parse ~"..." as a literal of a vstore ~str
|
||||
pat = match sub.node {
|
||||
pat_lit(e@@{
|
||||
pat_lit(e@@expr {
|
||||
node: expr_lit(@spanned {node: lit_str(_), span: _}), _
|
||||
}) => {
|
||||
let vst = @{id: self.get_id(), callee_id: self.get_id(),
|
||||
node: expr_vstore(e, expr_vstore_uniq),
|
||||
span: mk_sp(lo, hi)};
|
||||
let vst = @expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: expr_vstore(e, expr_vstore_uniq),
|
||||
span: mk_sp(lo, hi),
|
||||
};
|
||||
pat_lit(vst)
|
||||
}
|
||||
_ => pat_uniq(sub)
|
||||
|
|
@ -1952,10 +1966,10 @@ impl Parser {
|
|||
hi = sub.span.hi;
|
||||
// HACK: parse &"..." as a literal of a borrowed str
|
||||
pat = match sub.node {
|
||||
pat_lit(e@@{
|
||||
pat_lit(e@@expr {
|
||||
node: expr_lit(@spanned {node: lit_str(_), span: _}), _
|
||||
}) => {
|
||||
let vst = @{
|
||||
let vst = @expr {
|
||||
id: self.get_id(),
|
||||
callee_id: self.get_id(),
|
||||
node: expr_vstore(e, expr_vstore_slice),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue