diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-09-11 21:25:01 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-09-11 21:25:01 -0700 |
| commit | 8a8f200d102294cf1bd90cdacad995abccda7934 (patch) | |
| tree | 31e99a460697349c403fc5cf4809427303e14804 /src/libsyntax | |
| parent | 02b41097e42082a306ca6dbbd79ee9a1d7d35348 (diff) | |
| download | rust-8a8f200d102294cf1bd90cdacad995abccda7934.tar.gz rust-8a8f200d102294cf1bd90cdacad995abccda7934.zip | |
Introduce auto adjustment table to subsume autoderef/autoref/borrowings.
Fixes #3261 Fixes #3443
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_serialize.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 27 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 32 |
5 files changed, 54 insertions, 28 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3d3fd5bfd11..af7d8d83b6b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -421,6 +421,15 @@ enum vstore { vstore_slice(@region) // &[1,2,3,4](foo)? } +#[auto_serialize] +enum expr_vstore { + // FIXME (#2112): Change uint to @expr (actually only constant exprs) + expr_vstore_fixed(Option<uint>), // [1,2,3,4]/_ or 4 + expr_vstore_uniq, // ~[1,2,3,4] + expr_vstore_box, // @[1,2,3,4] + expr_vstore_slice // &[1,2,3,4] +} + pure fn is_blockish(p: ast::proto) -> bool { match p { proto_block => true, @@ -662,7 +671,7 @@ enum alt_mode { alt_check, alt_exhaustive, } #[auto_serialize] enum expr_ { - expr_vstore(@expr, vstore), + expr_vstore(@expr, expr_vstore), expr_vec(~[@expr], mutability), expr_rec(~[field], Option<@expr>), expr_call(@expr, ~[@expr], bool), // True iff last argument is a block diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 6a31dac2e8f..52357ca4752 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -260,7 +260,7 @@ impl ext_ctxt: ext_ctxt_helpers { ast::expr_lit( @{node: ast::lit_str(s), span: span})), - ast::vstore_uniq)) + ast::expr_vstore_uniq)) } fn lit_uint(span: span, i: uint) -> @ast::expr { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 12fbb00e6c6..8574c0c9082 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -65,24 +65,26 @@ fn mk_base_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) -> let vecexpr = ast::expr_vec(exprs, ast::m_imm); mk_expr(cx, sp, vecexpr) } -fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr, vst: ast::vstore) -> +fn mk_vstore_e(cx: ext_ctxt, sp: span, expr: @ast::expr, + vst: ast::expr_vstore) -> @ast::expr { mk_expr(cx, sp, ast::expr_vstore(expr, vst)) } fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_uniq) + mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::expr_vstore_uniq) } fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(None)) + mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), + ast::expr_vstore_fixed(None)) } fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr { let lit = ast::lit_str(@s); return mk_lit(cx, sp, lit); } fn mk_uniq_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr { - mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::vstore_uniq) + mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::expr_vstore_uniq) } fn mk_rec_e(cx: ext_ctxt, sp: span, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ea824ea2fb6..b8d55fb1055 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -64,7 +64,9 @@ use ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute, variant, view_item, view_item_, view_item_export, view_item_import, view_item_use, view_path, view_path_glob, view_path_list, view_path_simple, visibility, vstore, vstore_box, - vstore_fixed, vstore_slice, vstore_uniq}; + vstore_fixed, vstore_slice, vstore_uniq, + expr_vstore_fixed, expr_vstore_slice, expr_vstore_box, + expr_vstore_uniq}; export file_type; export parser; @@ -1071,7 +1073,8 @@ impl parser { None => (), Some(v) => { hi = self.span.hi; - ex = expr_vstore(self.mk_expr(lo, hi, ex), vstore_fixed(v)); + ex = expr_vstore(self.mk_expr(lo, hi, ex), + expr_vstore_fixed(v)); } }, _ => () @@ -1370,7 +1373,7 @@ impl parser { ex = match e.node { expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) if m == m_imm => { - expr_vstore(e, vstore_slice(self.region_from_name(None))) + expr_vstore(e, expr_vstore_slice) } _ => expr_addr_of(m, e) }; @@ -1386,7 +1389,7 @@ impl parser { // HACK: turn @[...] into a @-evec ex = match e.node { expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) - if m == m_imm => expr_vstore(e, vstore_box), + if m == m_imm => expr_vstore(e, expr_vstore_box), _ => expr_unary(box(m), e) }; } @@ -1398,7 +1401,7 @@ impl parser { // HACK: turn ~[...] into a ~-evec ex = match e.node { expr_vec(*) | expr_lit(@{node: lit_str(_), span: _}) - if m == m_imm => expr_vstore(e, vstore_uniq), + if m == m_imm => expr_vstore(e, expr_vstore_uniq), _ => expr_unary(uniq(m), e) }; } @@ -1849,7 +1852,7 @@ impl parser { node: expr_lit(@{node: lit_str(_), span: _}), _ }) => { let vst = @{id: self.get_id(), callee_id: self.get_id(), - node: expr_vstore(e, vstore_box), + node: expr_vstore(e, expr_vstore_box), span: mk_sp(lo, hi)}; pat_lit(vst) } @@ -1866,7 +1869,7 @@ impl parser { node: expr_lit(@{node: lit_str(_), span: _}), _ }) => { let vst = @{id: self.get_id(), callee_id: self.get_id(), - node: expr_vstore(e, vstore_uniq), + node: expr_vstore(e, expr_vstore_uniq), span: mk_sp(lo, hi)}; pat_lit(vst) } @@ -1884,10 +1887,12 @@ impl parser { pat_lit(e@@{ node: expr_lit(@{node: lit_str(_), span: _}), _ }) => { - let vst = @{id: self.get_id(), callee_id: self.get_id(), - node: expr_vstore(e, - vstore_slice(self.region_from_name(None))), - span: mk_sp(lo, hi)}; + let vst = @{ + id: self.get_id(), + callee_id: self.get_id(), + node: expr_vstore(e, expr_vstore_slice), + span: mk_sp(lo, hi) + }; pat_lit(vst) } _ => pat_region(sub) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 46fbaed8b5d..49133242d54 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -976,6 +976,16 @@ fn print_vstore(s: ps, t: ast::vstore) { } } +fn print_expr_vstore(s: ps, t: ast::expr_vstore) { + match t { + ast::expr_vstore_fixed(Some(i)) => word(s.s, fmt!("%u", i)), + ast::expr_vstore_fixed(None) => word(s.s, ~"_"), + ast::expr_vstore_uniq => word(s.s, ~"~"), + ast::expr_vstore_box => word(s.s, ~"@"), + ast::expr_vstore_slice => word(s.s, ~"&"), + } +} + fn print_expr(s: ps, &&expr: @ast::expr) { fn print_field(s: ps, field: ast::field) { ibox(s, indent_unit); @@ -992,17 +1002,17 @@ fn print_expr(s: ps, &&expr: @ast::expr) { let ann_node = node_expr(s, expr); s.ann.pre(ann_node); match expr.node { - ast::expr_vstore(e, v) => match v { - ast::vstore_fixed(_) => { - print_expr(s, e); - word(s.s, ~"/"); - print_vstore(s, v); - } - _ => { - print_vstore(s, v); - print_expr(s, e); - } - }, + ast::expr_vstore(e, v) => match v { + ast::expr_vstore_fixed(_) => { + print_expr(s, e); + word(s.s, ~"/"); + print_expr_vstore(s, v); + } + _ => { + print_expr_vstore(s, v); + print_expr(s, e); + } + }, ast::expr_vec(exprs, mutbl) => { ibox(s, indent_unit); word(s.s, ~"["); |
