diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-09-20 18:06:47 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-09-20 18:06:47 -0700 |
| commit | f809e2269779b5518e648cf63d9538399b00298e (patch) | |
| tree | c6cab9f354a64310b5274fb1e3e0aca9506fc5a0 /src/comp/syntax | |
| parent | 7ae251789ccd0a647e5abfc8085a8bd42359de65 (diff) | |
| download | rust-f809e2269779b5518e648cf63d9538399b00298e.tar.gz rust-f809e2269779b5518e648cf63d9538399b00298e.zip | |
Represent unique creation as a unop in the AST instead of its own expr
Like the box unop. Issue #409
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 7 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 1 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 10 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 5 | ||||
| -rw-r--r-- | src/comp/syntax/visit.rs | 1 |
6 files changed, 15 insertions, 10 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 6b64d373746..ad6aacb1549 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -124,7 +124,11 @@ tag binop { gt; } -tag unop { box(mutability); deref; not; neg; } +tag unop { + box(mutability); + uniq(mutability); + deref; not; neg; +} tag mode { by_ref; by_mut_ref; by_move; } @@ -215,7 +219,6 @@ tag expr_ { expr_if_check(@expr, blk, option::t<@expr>); expr_anon_obj(anon_obj); expr_mac(mac); - expr_uniq(@expr); } /* diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index aebf9b3e680..8350ce9a8bb 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -110,6 +110,7 @@ pure fn lazy_binop(b: binop) -> bool { fn unop_to_str(op: unop) -> str { alt op { box(mt) { if mt == mut { ret "@mutable "; } ret "@"; } + uniq(mt) { if mt == mut { ret "~mutable "; } ret "~"; } deref. { ret "*"; } not. { ret "!"; } neg. { ret "-"; } diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 23293adbd80..c53176e24fb 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -424,7 +424,6 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { } expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) } expr_mac(mac) { expr_mac(fold_mac(mac)) } - expr_uniq(e) { expr_uniq(fld.fold_expr(e)) } } } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 3e559e1a2a9..6869dc6501d 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -886,9 +886,6 @@ fn parse_bottom_expr(p: parser) -> @ast::expr { } else if p.peek() == token::ELLIPSIS { p.bump(); ret mk_mac_expr(p, lo, p.get_hi_pos(), ast::mac_ellipsis); - } else if p.peek() == token::TILDE { - p.bump(); - ex = ast::expr_uniq(parse_expr(p)); } else if eat_word(p, "obj") { // Anonymous object @@ -1145,6 +1142,13 @@ fn parse_prefix_expr(p: parser) -> @ast::expr { hi = e.span.hi; ex = ast::expr_unary(ast::box(m), e); } + token::TILDE. { + p.bump(); + let m = parse_mutability(p); + let e = parse_prefix_expr(p); + hi = e.span.hi; + ex = ast::expr_unary(ast::uniq(m), e); + } _ { ret parse_dot_or_call_expr(p); } } ret mk_expr(p, lo, hi, ex); diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 3a8e5f2b9be..48031a295db 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -988,7 +988,6 @@ fn print_expr(s: ps, expr: @ast::expr) { } bclose(s, expr.span); } - ast::expr_uniq(expr) { word(s.s, "~"); print_expr(s, expr); } } s.ann.post(ann_node); end(s); @@ -1001,7 +1000,7 @@ fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) { ast::expr_ternary(_, _, _) | ast::expr_move(_, _) | ast::expr_copy(_) | ast::expr_assign(_, _) | ast::expr_be(_) | ast::expr_assign_op(_, _, _) | ast::expr_swap(_, _) | - ast::expr_log(_, _) | ast::expr_assert(_) | ast::expr_uniq(_) | + ast::expr_log(_, _) | ast::expr_assert(_) | ast::expr_check(_, _) { true } _ { false } }; @@ -1658,7 +1657,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool { ast::expr_ternary(_, _, sub) | ast::expr_move(_, sub) | ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_be(sub) | ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) | - ast::expr_log(_, sub) | ast::expr_assert(sub) | ast::expr_uniq(sub) | + ast::expr_log(_, sub) | ast::expr_assert(sub) | ast::expr_check(_, sub) { ends_in_lit_int(sub) } ast::expr_fail(osub) | ast::expr_ret(osub) | ast::expr_put(osub) { alt osub { diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index d5b39bb7ca5..387434edf15 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -325,7 +325,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { } } expr_mac(mac) { visit_mac(mac, e, v); } - expr_uniq(x) { v.visit_expr(x, e, v); } } } |
