diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2013-01-15 13:51:43 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2013-01-20 14:08:18 -0800 |
| commit | 8a3a1fc1489fb1f313fdd75af4e73a6a3b271ce2 (patch) | |
| tree | 3971b94fa8dea80685cce5c2894763b9f350a5d4 /src/libsyntax | |
| parent | 1280a64089358d679e010e48dcd18a3d6657d52e (diff) | |
| download | rust-8a3a1fc1489fb1f313fdd75af4e73a6a3b271ce2.tar.gz rust-8a3a1fc1489fb1f313fdd75af4e73a6a3b271ce2.zip | |
convert ast::expr into a struct
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ext/log_syntax.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 62 |
8 files changed, 102 insertions, 57 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6f2ffe00849..4b3962efc7f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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] diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index e241f6435d3..625c04a6463 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -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 { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index cc4c58f3504..a4184bdfda7 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -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 { diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 32e77afab93..8e94ed19021 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -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) } diff --git a/src/libsyntax/ext/log_syntax.rs b/src/libsyntax/ext/log_syntax.rs index 563c56e02b5..5308f4c3486 100644 --- a/src/libsyntax/ext/log_syntax.rs +++ b/src/libsyntax/ext/log_syntax.rs @@ -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, + }) } diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 19cbf833c0f..8472e61c196 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -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 { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 23915ea189b..60430b51f0a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -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); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6fba59d6a84..486ec56523b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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), |
