diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-02-15 11:25:39 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-02-15 13:26:11 -0800 |
| commit | bfff2a8d55f8d96df77c7e496dc7713fe7faf5f9 (patch) | |
| tree | 23c1e0515c6894f15bbd9c5b473f7f4e2653965d /src/comp/syntax | |
| parent | dddd9908d537ce2858f37783779c3b88005ff0a8 (diff) | |
| download | rust-bfff2a8d55f8d96df77c7e496dc7713fe7faf5f9.tar.gz rust-bfff2a8d55f8d96df77c7e496dc7713fe7faf5f9.zip | |
make mut a keyword synonymous with mutable
first step towards issue #1273
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ext/build.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/ext/qquote.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 41 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 30 |
8 files changed, 50 insertions, 45 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index deaf70c41fb..3a365e58bbd 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -121,7 +121,7 @@ enum pat_ { pat_range(@expr, @expr), } -enum mutability { mut, imm, maybe_mut, } +enum mutability { m_mutbl, m_imm, m_const, } enum proto { proto_bare, // native fn @@ -173,7 +173,7 @@ enum inferable<T> { } // "resolved" mode: the real modes. -enum rmode { by_ref, by_val, by_mut_ref, by_move, by_copy } +enum rmode { by_ref, by_val, by_mutbl_ref, by_move, by_copy } // inferable mode. type mode = inferable<rmode>; @@ -205,7 +205,7 @@ enum decl_ { decl_local([@local]), decl_item(@item), } type arm = {pats: [@pat], guard: option<@expr>, body: blk}; -type field_ = {mut: mutability, ident: ident, expr: @expr}; +type field_ = {mutbl: mutability, ident: ident, expr: @expr}; type field = spanned<field_>; @@ -316,7 +316,7 @@ enum lit_ { // NB: If you change this, you'll probably want to change the corresponding // type structure in middle/ty.rs as well. -type mt = {ty: @ty, mut: mutability}; +type mt = {ty: @ty, mutbl: mutability}; type ty_field_ = {ident: ident, mt: mt}; diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 3511cd91853..cd508aae90b 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -66,8 +66,8 @@ 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 "~"; } + box(mt) { if mt == m_mutbl { ret "@mut "; } ret "@"; } + uniq(mt) { if mt == m_mutbl { ret "~mut "; } ret "~"; } deref { ret "*"; } not { ret "!"; } neg { ret "-"; } diff --git a/src/comp/syntax/ext/build.rs b/src/comp/syntax/ext/build.rs index 4d0cfa75a14..5d615c4305d 100644 --- a/src/comp/syntax/ext/build.rs +++ b/src/comp/syntax/ext/build.rs @@ -61,7 +61,7 @@ fn mk_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident], // e = expr, t = type fn mk_vec_e(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) -> @ast::expr { - let vecexpr = ast::expr_vec(exprs, ast::imm); + let vecexpr = ast::expr_vec(exprs, ast::m_imm); ret @{id: cx.next_id(), node: vecexpr, span: sp}; } fn mk_rec_e(cx: ext_ctxt, sp: span, @@ -72,7 +72,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span, let ident = field.ident; let val = field.ex; let astfield = - {node: {mut: ast::imm, ident: ident, expr: val}, span: sp}; + {node: {mutbl: ast::m_imm, ident: ident, expr: val}, span: sp}; astfields += [astfield]; } let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>); diff --git a/src/comp/syntax/ext/qquote.rs b/src/comp/syntax/ext/qquote.rs index 6afb3fa3f75..6d2a9e04d72 100644 --- a/src/comp/syntax/ext/qquote.rs +++ b/src/comp/syntax/ext/qquote.rs @@ -231,7 +231,7 @@ fn finish<T: qq_helper> [mk_str(cx,sp, loc.file.name), mk_uint(cx,sp, loc.line), mk_uint(cx,sp, loc.col)]), - mk_unary(cx,sp, ast::box(ast::imm), + mk_unary(cx,sp, ast::box(ast::m_imm), mk_str(cx,sp, str2)), mk_access_(cx,sp, mk_access_(cx,sp, session_call(), "opts"), diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index df281640210..b8f9dd2c140 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -682,7 +682,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg, let clauses: [@clause] = []; for arg: @expr in args { alt arg.node { - expr_vec(elts, mut) { + expr_vec(elts, mutbl) { if vec::len(elts) != 2u { cx.span_fatal((*arg).span, "extension clause must consist of [" + diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 878b26fa84c..d161d27c020 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -337,7 +337,7 @@ fn wrap<T>(f: fn@(T, ast_fold) -> T) fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { fn fold_field_(field: field, fld: ast_fold) -> field { ret {node: - {mut: field.node.mut, + {mutbl: field.node.mutbl, ident: fld.fold_ident(field.node.ident), expr: fld.fold_expr(field.node.expr)}, span: field.span}; @@ -434,7 +434,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ { let fold_mac = bind fold_mac_(_, fld); fn fold_mt(mt: mt, fld: ast_fold) -> mt { - {ty: fld.fold_ty(mt.ty), mut: mt.mut} + {ty: fld.fold_ty(mt.ty), mutbl: mt.mutbl} } fn fold_field(f: ty_field, fld: ast_fold) -> ty_field { {node: {ident: fld.fold_ident(f.node.ident), diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 01f04433908..1e21dff0b34 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -150,7 +150,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> { "export", "fail", "fn", "for", "if", "iface", "impl", "import", "let", "log", "mod", "mutable", "native", "pure", "resource", "ret", "trait", "type", "unchecked", "unsafe", - "while, crust"] { + "while", "crust", "mut"] { words.insert(word, ()); } words @@ -293,18 +293,18 @@ fn parse_ty_methods(p: parser) -> [ast::ty_method] { } fn parse_mt(p: parser) -> ast::mt { - let mut = parse_mutability(p); + let mutbl = parse_mutability(p); let t = parse_ty(p, false); - ret {ty: t, mut: mut}; + ret {ty: t, mutbl: mutbl}; } fn parse_ty_field(p: parser) -> ast::ty_field { let lo = p.span.lo; - let mut = parse_mutability(p); + let mutbl = parse_mutability(p); let id = parse_ident(p); expect(p, token::COLON); let ty = parse_ty(p, false); - ret spanned(lo, ty.span.hi, {ident: id, mt: {ty: ty, mut: mut}}); + ret spanned(lo, ty.span.hi, {ident: id, mt: {ty: ty, mutbl: mutbl}}); } // if i is the jth ident in args, return j @@ -486,7 +486,7 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { fn parse_arg_mode(p: parser) -> ast::mode { if eat(p, token::BINOP(token::AND)) { - ast::expl(ast::by_mut_ref) + ast::expl(ast::by_mutbl_ref) } else if eat(p, token::BINOP(token::MINUS)) { ast::expl(ast::by_move) } else if eat(p, token::ANDAND) { @@ -693,11 +693,13 @@ fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path { fn parse_mutability(p: parser) -> ast::mutability { if eat_word(p, "mutable") { - ast::mut + ast::m_mutbl + } else if eat_word(p, "mut") { + ast::m_mutbl } else if eat_word(p, "const") { - ast::maybe_mut + ast::m_const } else { - ast::imm + ast::m_imm } } @@ -707,7 +709,7 @@ fn parse_field(p: parser, sep: token::token) -> ast::field { let i = parse_ident(p); expect(p, sep); let e = parse_expr(p); - ret spanned(lo, e.span.hi, {mut: m, ident: i, expr: e}); + ret spanned(lo, e.span.hi, {mutbl: m, ident: i, expr: e}); } fn mk_expr(p: parser, lo: uint, hi: uint, node: ast::expr_) -> @ast::expr { @@ -786,7 +788,7 @@ fn parse_bottom_expr(p: parser) -> pexpr { ret mk_pexpr(p, lo, hi, ast::expr_tup(es)); } else if p.token == token::LBRACE { p.bump(); - if is_word(p, "mutable") || + if is_word(p, "mut") || is_word(p, "mutable") || is_plain_ident(p) && p.look_ahead(1u) == token::COLON { let fields = [parse_field(p, token::COLON)]; let base = none; @@ -832,11 +834,11 @@ fn parse_bottom_expr(p: parser) -> pexpr { ret pexpr(parse_block_expr(p, lo, ast::unsafe_blk)); } else if p.token == token::LBRACKET { p.bump(); - let mut = parse_mutability(p); + let mutbl = parse_mutability(p); let es = parse_seq_to_end(token::RBRACKET, seq_sep(token::COMMA), parse_expr, p); - ex = ast::expr_vec(es, mut); + ex = ast::expr_vec(es, mutbl); } else if p.token == token::POUND_LT { p.bump(); let ty = parse_ty(p, false); @@ -971,7 +973,7 @@ fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr { }; let hi = es.span.hi; e = some(mk_expr(p, es.span.lo, hi, - ast::expr_vec(es.node, ast::imm))); + ast::expr_vec(es.node, ast::m_imm))); } let b = none; if p.token == token::LBRACE { @@ -1578,6 +1580,9 @@ fn parse_local(p: parser, allow_init: bool) -> @ast::local { } fn parse_let(p: parser) -> @ast::decl { + if eat_word(p, "mut") { + /* TODO */ + } let lo = p.span.lo; let locals = [parse_local(p, true)]; while eat(p, token::COMMA) { @@ -1587,10 +1592,10 @@ fn parse_let(p: parser) -> @ast::decl { } fn parse_instance_var(p:parser) -> ast::class_member { - let is_mut = ast::class_immutable; + let is_mutbl = ast::class_immutable; expect_word(p, "let"); - if eat_word(p, "mutable") { - is_mut = ast::class_mutable; + if eat_word(p, "mut") || eat_word(p, "mutable") { + is_mutbl = ast::class_mutable; } if !is_plain_ident(p) { p.fatal("expecting ident"); @@ -1598,7 +1603,7 @@ fn parse_instance_var(p:parser) -> ast::class_member { let name = parse_ident(p); expect(p, token::COLON); let ty = parse_ty(p, false); - ret ast::instance_var(name, ty, is_mut, p.get_id()); + ret ast::instance_var(name, ty, is_mutbl, p.get_id()); } fn parse_stmt(p: parser, first_item_attrs: [ast::attribute]) -> @ast::stmt { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 23cea66e8db..343b4500a3d 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -318,10 +318,10 @@ fn print_type(s: ps, &&ty: @ast::ty) { ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); } ast::ty_vec(mt) { word(s.s, "["); - alt mt.mut { - ast::mut { word_space(s, "mutable"); } - ast::maybe_mut { word_space(s, "const"); } - ast::imm { } + alt mt.mutbl { + ast::m_mutbl { word_space(s, "mut"); } + ast::m_const { word_space(s, "const"); } + ast::m_imm { } } print_type(s, mt.ty); word(s.s, "]"); @@ -331,7 +331,7 @@ fn print_type(s: ps, &&ty: @ast::ty) { word(s.s, "{"); fn print_field(s: ps, f: ast::ty_field) { cbox(s, indent_unit); - print_mutability(s, f.node.mt.mut); + print_mutability(s, f.node.mt.mutbl); word(s.s, f.node.ident); word_space(s, ":"); print_type(s, f.node.mt.ty); @@ -785,10 +785,10 @@ fn print_expr(s: ps, &&expr: @ast::expr) { let ann_node = node_expr(s, expr); s.ann.pre(ann_node); alt expr.node { - ast::expr_vec(exprs, mut) { + ast::expr_vec(exprs, mutbl) { ibox(s, indent_unit); word(s.s, "["); - if mut == ast::mut { + if mutbl == ast::m_mutbl { word(s.s, "mutable"); if vec::len(exprs) > 0u { nbsp(s); } } @@ -799,7 +799,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) { ast::expr_rec(fields, wth) { fn print_field(s: ps, field: ast::field) { ibox(s, indent_unit); - if field.node.mut == ast::mut { word_nbsp(s, "mutable"); } + if field.node.mutbl == ast::m_mutbl { word_nbsp(s, "mutable"); } word(s.s, field.node.ident); word_space(s, ":"); print_expr(s, field.node.expr); @@ -1274,7 +1274,7 @@ fn print_fn_block_args(s: ps, decl: ast::fn_decl) { fn mode_to_str(m: ast::mode) -> str { alt m { - ast::expl(ast::by_mut_ref) { "&" } + ast::expl(ast::by_mutbl_ref) { "&" } ast::expl(ast::by_move) { "-" } ast::expl(ast::by_ref) { "&&" } ast::expl(ast::by_val) { "++" } @@ -1436,16 +1436,16 @@ fn print_op_maybe_parens(s: ps, expr: @ast::expr, outer_prec: int) { if add_them { pclose(s); } } -fn print_mutability(s: ps, mut: ast::mutability) { - alt mut { - ast::mut { word_nbsp(s, "mutable"); } - ast::maybe_mut { word_nbsp(s, "const"); } - ast::imm {/* nothing */ } +fn print_mutability(s: ps, mutbl: ast::mutability) { + alt mutbl { + ast::m_mutbl { word_nbsp(s, "mutable"); } + ast::m_const { word_nbsp(s, "const"); } + ast::m_imm {/* nothing */ } } } fn print_mt(s: ps, mt: ast::mt) { - print_mutability(s, mt.mut); + print_mutability(s, mt.mutbl); print_type(s, mt.ty); } |
