diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-04-24 01:29:46 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-04-29 14:30:55 -0700 |
| commit | f30f54e9d062bdb5b3cb10dd7185470280c1c278 (patch) | |
| tree | b641e10eb9ee445b023d9d9b69ea8330c41ca30b /src/libsyntax | |
| parent | a12a3db5b44d539f5512376a2e7bb40fbab63683 (diff) | |
| download | rust-f30f54e9d062bdb5b3cb10dd7185470280c1c278.tar.gz rust-f30f54e9d062bdb5b3cb10dd7185470280c1c278.zip | |
librustc: Remove the concept of modes from the compiler.
This commit does not remove `ty::arg`, although that should be possible to do now.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 40 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_encode.rs | 30 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 62 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 14 |
8 files changed, 52 insertions, 99 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 4137b3b8aa1..ba6fe1cda4f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -198,7 +198,7 @@ pub enum def { def_mod(def_id), def_foreign_mod(def_id), def_const(def_id), - def_arg(node_id, mode, bool /* is_mutbl */), + def_arg(node_id, bool /* is_mutbl */), def_local(node_id, bool /* is_mutbl */), def_variant(def_id /* enum */, def_id /* variant */), def_ty(def_id), @@ -417,43 +417,6 @@ pub enum unop { neg } -// Generally, after typeck you can get the inferred value -// using ty::resolved_T(...). -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum inferable<T> { - expl(T), - infer(node_id) -} - -impl<T:to_bytes::IterBytes> to_bytes::IterBytes for inferable<T> { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - match *self { - expl(ref t) => - to_bytes::iter_bytes_2(&0u8, t, lsb0, f), - - infer(ref n) => - to_bytes::iter_bytes_2(&1u8, n, lsb0, f), - } - } -} - -// "resolved" mode: the real modes. -#[auto_encode] -#[auto_decode] -#[deriving(Eq)] -pub enum rmode { by_ref, by_copy } - -impl to_bytes::IterBytes for rmode { - fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - (*self as u8).iter_bytes(lsb0, f) - } -} - -// inferable mode. -pub type mode = inferable<rmode>; - pub type stmt = spanned<stmt_>; #[auto_encode] @@ -941,7 +904,6 @@ pub struct inline_asm { #[auto_decode] #[deriving(Eq)] pub struct arg { - mode: mode, is_mutbl: bool, ty: @Ty, pat: @pat, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c28d369e7f8..148b713a4f5 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -58,7 +58,7 @@ pub fn def_id_of_def(d: def) -> def_id { def_use(id) | def_struct(id) | def_trait(id) => { id } - def_arg(id, _, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) + def_arg(id, _) | def_local(id, _) | def_self(id, _) | def_self_ty(id) | def_upvar(id, _, _, _) | def_binding(id, _) | def_region(id) | def_typaram_binder(id) | def_label(id) => { local_def(id) diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 0d451c66edb..da7b9570131 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -608,7 +608,6 @@ fn mk_ser_method( }; let ser_inputs = ~[ast::arg { - mode: ast::infer(cx.next_id()), is_mutbl: false, ty: ty_s, pat: @ast::pat { @@ -670,20 +669,22 @@ fn mk_deser_method( span: span, }; - let deser_inputs = ~[ast::arg { - mode: ast::infer(cx.next_id()), - is_mutbl: false, - ty: ty_d, - pat: @ast::pat { + let deser_inputs = ~[ + ast::arg { + is_mutbl: false, + ty: ty_d, + pat: @ast::pat { + id: cx.next_id(), + node: ast::pat_ident(ast::bind_by_copy, + ast_util::ident_to_path(span, + cx.ident_of( + ~"__d")), + None), + span: span, + }, id: cx.next_id(), - node: ast::pat_ident( - ast::bind_by_copy, - ast_util::ident_to_path(span, cx.ident_of(~"__d")), - None), - span: span, - }, - id: cx.next_id(), - }]; + } + ]; let deser_decl = ast::fn_decl { inputs: deser_inputs, @@ -1120,7 +1121,6 @@ fn mk_enum_deser_body( ast::expr_fn_block( ast::fn_decl { inputs: ~[ast::arg { - mode: ast::infer(ext_cx.next_id()), is_mutbl: false, ty: @ast::Ty { id: ext_cx.next_id(), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c4c2fed778f..4c876669f47 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -419,7 +419,6 @@ pub fn mk_arg(cx: @ext_ctxt, -> ast::arg { let arg_pat = mk_pat_ident(cx, span, ident); ast::arg { - mode: ast::infer(cx.next_id()), is_mutbl: false, ty: ty, pat: arg_pat, diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index ede3711b052..deaf1b1c754 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -196,7 +196,6 @@ impl ext_ctxt_ast_builder for @ext_ctxt { fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg { ast::arg { - mode: ast::infer(self.next_id()), is_mutbl: false, ty: ty, pat: @ast::pat { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index da6d0e8bf7b..cee1f531176 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -105,7 +105,6 @@ fn fold_attribute_(at: attribute, fld: @ast_fold) -> attribute { //used in noop_fold_foreign_item and noop_fold_fn_decl fn fold_arg_(a: arg, fld: @ast_fold) -> arg { ast::arg { - mode: a.mode, is_mutbl: a.is_mutbl, ty: fld.fold_ty(a.ty), pat: fld.fold_pat(a.pat), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 30275436c06..ae374808270 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -17,10 +17,10 @@ use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer}; use ast::{bind_by_copy, bitand, bitor, bitxor, blk}; -use ast::{blk_check_mode, box, by_copy, by_ref}; +use ast::{blk_check_mode, box}; use ast::{crate, crate_cfg, decl, decl_item}; use ast::{decl_local, default_blk, deref, quot, enum_def}; -use ast::{expl, expr, expr_, expr_addr_of, expr_match, expr_again}; +use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body}; use ast::{expr_field, expr_fn_block, expr_if, expr_index}; @@ -32,13 +32,13 @@ use ast::{expr_vstore_slice, expr_vstore_box}; use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; use ast::{expr_vstore_uniq, TyClosure, TyBareFn, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_const, foreign_item_fn, foreign_mod}; -use ast::{ident, impure_fn, infer, inherited, item, item_, item_const}; +use ast::{ident, impure_fn, inherited, item, item_, item_const}; use ast::{item_const, item_enum, item_fn, item_foreign_mod, item_impl}; use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_}; use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int}; use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const}; use ast::{m_imm, m_mutbl, mac_, mac_invoc_tt, matcher, match_nonterminal}; -use ast::{match_seq, match_tok, method, mode, mt, mul, mutability}; +use ast::{match_seq, match_tok, method, mt, mul, mutability}; use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; use ast::{pat_ident, pat_lit, pat_range, pat_region, pat_struct}; use ast::{pat_tup, pat_uniq, pat_wild, private}; @@ -765,22 +765,22 @@ pub impl Parser { } // parse an optional mode. - fn parse_arg_mode(&self) -> mode { + // XXX: Remove after snapshot. + fn parse_arg_mode(&self) { if self.eat(&token::BINOP(token::MINUS)) { self.obsolete(*self.span, ObsoleteMode); - expl(by_copy) } else if self.eat(&token::ANDAND) { - expl(by_ref) + // Ignore. } else if self.eat(&token::BINOP(token::PLUS)) { if self.eat(&token::BINOP(token::PLUS)) { // ++ mode is obsolete, but we need a snapshot // to stop parsing it. - expl(by_copy) + // Ignore. } else { - expl(by_copy) + // Ignore. } } else { - infer(self.get_id()) + // Ignore. } } @@ -810,16 +810,14 @@ pub impl Parser { // This version of parse arg doesn't necessarily require // identifier names. fn parse_arg_general(&self, require_name: bool) -> arg { - let m; let mut is_mutbl = false; let pat = if require_name || self.is_named_argument() { - m = self.parse_arg_mode(); + self.parse_arg_mode(); is_mutbl = self.eat_keyword(&~"mut"); let pat = self.parse_pat(false); self.expect(&token::COLON); pat } else { - m = infer(self.get_id()); ast_util::ident_to_pat(self.get_id(), *self.last_span, special_idents::invalid) @@ -827,8 +825,12 @@ pub impl Parser { let t = self.parse_ty(false); - ast::arg { mode: m, is_mutbl: is_mutbl, - ty: t, pat: pat, id: self.get_id() } + ast::arg { + is_mutbl: is_mutbl, + ty: t, + pat: pat, + id: self.get_id(), + } } // parse a single function argument @@ -838,7 +840,7 @@ pub impl Parser { // parse an argument in a lambda header e.g. |arg, arg| fn parse_fn_block_arg(&self) -> arg_or_capture_item { - let m = self.parse_arg_mode(); + self.parse_arg_mode(); let is_mutbl = self.eat_keyword(&~"mut"); let pat = self.parse_pat(false); let t = if self.eat(&token::COLON) { @@ -851,7 +853,6 @@ pub impl Parser { } }; either::Left(ast::arg { - mode: m, is_mutbl: is_mutbl, ty: t, pat: pat, @@ -2440,18 +2441,21 @@ pub impl Parser { // used by the copy foo and ref foo patterns to give a good // error message when parsing mistakes like ref foo(a,b) - fn parse_pat_ident(&self, refutable: bool, - binding_mode: ast::binding_mode) -> ast::pat_ { + fn parse_pat_ident(&self, + refutable: bool, + binding_mode: ast::binding_mode) + -> ast::pat_ { if !is_plain_ident(&*self.token) { - self.span_fatal( - *self.last_span, - ~"expected identifier, found path"); + self.span_fatal(*self.last_span, + ~"expected identifier, found path"); } // why a path here, and not just an identifier? let name = self.parse_path_without_tps(); let sub = if self.eat(&token::AT) { Some(self.parse_pat(refutable)) - } else { None }; + } else { + None + }; // just to be friendly, if they write something like // ref Some(i) @@ -4406,10 +4410,11 @@ pub impl Parser { // text that can't be parsed as an item // - mod_items uses extern_mod_allowed = true // - block_tail_ uses extern_mod_allowed = false - fn parse_items_and_view_items(&self, first_item_attrs: ~[attribute], + fn parse_items_and_view_items(&self, + first_item_attrs: ~[attribute], mut extern_mod_allowed: bool, macros_allowed: bool) - -> ParsedItemsAndViewItems { + -> ParsedItemsAndViewItems { let mut attrs = vec::append(first_item_attrs, self.parse_outer_attributes()); // First, parse view items. @@ -4539,8 +4544,11 @@ pub impl Parser { fn parse_str(&self) -> @~str { match *self.token { - token::LIT_STR(s) => { self.bump(); self.id_to_str(s) } - _ => self.fatal(~"expected string literal") + token::LIT_STR(s) => { + self.bump(); + self.id_to_str(s) + } + _ => self.fatal(~"expected string literal") } } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 918fc805194..337355304d4 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1718,19 +1718,6 @@ pub fn print_fn_block_args(s: @ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -pub fn mode_to_str(m: ast::mode) -> ~str { - match m { - ast::expl(ast::by_ref) => ~"&&", - ast::expl(ast::by_copy) => ~"+", - ast::infer(_) => ~"" - } -} - -pub fn print_arg_mode(s: @ps, m: ast::mode) { - let ms = mode_to_str(m); - if ms != ~"" { word(s.s, ms); } -} - pub fn print_bounds(s: @ps, bounds: @OptVec<ast::TyParamBound>) { if !bounds.is_empty() { word(s.s, ~":"); @@ -1879,7 +1866,6 @@ pub fn print_mt(s: @ps, mt: &ast::mt) { pub fn print_arg(s: @ps, input: ast::arg) { ibox(s, indent_unit); - print_arg_mode(s, input.mode); if input.is_mutbl { word_space(s, ~"mut"); } |
