diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-07-13 18:43:52 -0700 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-07-14 17:37:20 -0700 |
| commit | 41a21f053ced3df8fe9acc66cb30fb6005339b3e (patch) | |
| tree | 12cf2e5e9ba0405e31a0a6abd509b6a5d3f477c4 /src/libsyntax/parse | |
| parent | 1fbb9d035ddd0c9ae56a91167fda2f100c3987ad (diff) | |
| download | rust-41a21f053ced3df8fe9acc66cb30fb6005339b3e.tar.gz rust-41a21f053ced3df8fe9acc66cb30fb6005339b3e.zip | |
remove typestate from code, tests, and docs
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 153 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 |
3 files changed, 17 insertions, 147 deletions
diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 9b36b77407e..20fb7772d08 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -6,8 +6,7 @@ import ast_util::operator_prec; fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { alt e.node { - ast::expr_if(_, _, _) | ast::expr_if_check(_, _, _) - | ast::expr_alt(_, _, _) | ast::expr_block(_) + ast::expr_if(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_) | ast::expr_while(_, _) | ast::expr_loop(_) | ast::expr_call(_, _, true) { false @@ -44,7 +43,6 @@ fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool { ast::expr_assign_op(_, _, _) { true } ast::expr_ret(_) { true } ast::expr_assert(_) { true } - ast::expr_check(_, _) { true } ast::expr_log(_, _, _) { true } _ { !parse::classify::expr_requires_semi_to_be_stmt(expr) } } @@ -64,8 +62,9 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool { ast::expr_move(_, sub) | ast::expr_copy(sub) | ast::expr_assign(_, sub) | ast::expr_assign_op(_, _, sub) | ast::expr_swap(_, sub) | - ast::expr_log(_, _, sub) | ast::expr_assert(sub) | - ast::expr_check(_, sub) { ends_in_lit_int(sub) } + ast::expr_log(_, _, sub) | ast::expr_assert(sub) { + ends_in_lit_int(sub) + } ast::expr_fail(osub) | ast::expr_ret(osub) { alt osub { some(ex) { ends_in_lit_int(ex) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b67fd88ab61..fa0361e797b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -20,14 +20,14 @@ import ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute, by_mutbl_ref, by_ref, by_val, capture_clause, capture_item, carg_base, carg_ident, cdir_dir_mod, cdir_src_mod, cdir_view_item, checked_expr, claimed_expr, class_immutable, - class_member, class_method, class_mutable, constr, constr_arg, - constr_general, crate, crate_cfg, crate_directive, decl, + class_member, class_method, class_mutable, + crate, crate_cfg, crate_directive, decl, decl_item, decl_local, default_blk, deref, div, expl, expr, expr_, expr_addr_of, expr_alt, expr_again, expr_assert, expr_assign, expr_assign_op, expr_binary, expr_block, expr_break, - expr_call, expr_cast, expr_check, expr_copy, expr_do_body, + expr_call, expr_cast, expr_copy, expr_do_body, expr_fail, expr_field, expr_fn, expr_fn_block, expr_if, - expr_if_check, expr_index, expr_lit, expr_log, expr_loop, + expr_index, expr_lit, expr_log, expr_loop, expr_loop_body, expr_mac, expr_move, expr_new, expr_path, expr_rec, expr_ret, expr_swap, expr_tup, expr_unary, expr_vec, expr_vstore, expr_while, extern_fn, field, fn_decl, foreign_item, @@ -265,15 +265,9 @@ class parser { {mode: mode, ty: p.parse_ty(false), ident: name, id: p.get_id()} }; - // FIXME (#34): constrs is empty because right now, higher-order - // functions can't have constrained types. Not sure whether - // that would be desirable anyway. See bug for the story on - // constrained types. - let constrs: ~[@constr] = ~[]; let (ret_style, ret_ty) = self.parse_ret_ty(); ret {inputs: inputs, output: ret_ty, - purity: purity, cf: ret_style, - constraints: constrs}; + purity: purity, cf: ret_style}; } fn parse_trait_methods() -> ~[trait_method] { @@ -341,79 +335,6 @@ class parser { ret spanned(lo, ty.span.hi, {ident: id, mt: {ty: ty, mutbl: mutbl}}); } - // if i is the jth ident in args, return j - // otherwise, fail - fn ident_index(args: ~[arg], i: ident) -> uint { - let mut j = 0u; - for args.each |a| { if a.ident == i { ret j; } j += 1u; } - self.fatal(~"unbound variable `" + *i + ~"` in constraint arg"); - } - - fn parse_type_constr_arg() -> @ty_constr_arg { - let sp = self.span; - let mut carg = carg_base; - self.expect(token::BINOP(token::STAR)); - if self.token == token::DOT { - // "*..." notation for record fields - self.bump(); - let pth = self.parse_path_without_tps(); - carg = carg_ident(pth); - } - // No literals yet, I guess? - ret @{node: carg, span: sp}; - } - - fn parse_constr_arg(args: ~[arg]) -> @constr_arg { - let sp = self.span; - let mut carg = carg_base; - if self.token == token::BINOP(token::STAR) { - self.bump(); - } else { - let i: ident = self.parse_value_ident(); - carg = carg_ident(self.ident_index(args, i)); - } - ret @{node: carg, span: sp}; - } - - fn parse_ty_constr(fn_args: ~[arg]) -> @constr { - let lo = self.span.lo; - let path = self.parse_path_without_tps(); - let args = self.parse_unspanned_seq( - token::LPAREN, token::RPAREN, - seq_sep_trailing_disallowed(token::COMMA), - |p| p.parse_constr_arg(fn_args)); - ret @spanned(lo, self.span.hi, - {path: path, args: args, id: self.get_id()}); - } - - fn parse_constr_in_type() -> @ty_constr { - let lo = self.span.lo; - let path = self.parse_path_without_tps(); - let args: ~[@ty_constr_arg] = self.parse_unspanned_seq( - token::LPAREN, token::RPAREN, - seq_sep_trailing_disallowed(token::COMMA), - |p| p.parse_type_constr_arg()); - let hi = self.span.lo; - let tc: ty_constr_ = {path: path, args: args, id: self.get_id()}; - ret @spanned(lo, hi, tc); - } - - - fn parse_constrs<T: copy>(pser: fn(parser) -> @constr_general<T>) -> - ~[@constr_general<T>] { - let mut constrs: ~[@constr_general<T>] = ~[]; - loop { - let constr = pser(self); - vec::push(constrs, constr); - if self.token == token::COMMA { self.bump(); } - else { ret constrs; } - }; - } - - fn parse_type_constraints() -> ~[@ty_constr] { - ret self.parse_constrs(|p| p.parse_constr_in_type()); - } - fn parse_ret_ty() -> (ret_style, @ty) { ret if self.eat(token::RARROW) { let lo = self.span.lo; @@ -519,16 +440,7 @@ class parser { if vec::len(elems) == 0u { self.unexpected_last(token::RBRACE); } - let hi = self.span.hi; - - let t = ty_rec(elems); - if self.token == token::COLON { - self.bump(); - ty_constr(@{id: self.get_id(), - node: t, - span: mk_sp(lo, hi)}, - self.parse_type_constraints()) - } else { t } + ty_rec(elems) } else if self.token == token::LBRACKET { self.expect(token::LBRACKET); let t = ty_vec(self.parse_mt()); @@ -970,21 +882,6 @@ class parser { let e = self.parse_expr(); ex = expr_assert(e); hi = e.span.hi; - } else if self.eat_keyword(~"check") { - /* Should be a predicate (pure boolean function) applied to - arguments that are all either slot variables or literals. - but the typechecker enforces that. */ - let e = self.parse_expr(); - hi = e.span.hi; - ex = expr_check(checked_expr, e); - } else if self.eat_keyword(~"claim") { - /* Same rules as check, except that if check-claims - is enabled (a command-line flag), then the parser turns - claims into check */ - - let e = self.parse_expr(); - hi = e.span.hi; - ex = expr_check(claimed_expr, e); } else if self.eat_keyword(~"ret") { if can_begin_expr(self.token) { let e = self.parse_expr(); @@ -1457,12 +1354,7 @@ class parser { ret lhs; } - fn parse_if_expr_1() -> - {cond: @expr, - then: blk, - els: option<@expr>, - lo: uint, - hi: uint} { + fn parse_if_expr() -> @expr { let lo = self.last_span.lo; let cond = self.parse_expr(); let thn = self.parse_block(); @@ -1473,18 +1365,8 @@ class parser { els = some(elexpr); hi = elexpr.span.hi; } - ret {cond: cond, then: thn, els: els, lo: lo, hi: hi}; - } - - fn parse_if_expr() -> @expr { - if self.eat_keyword(~"check") { - let q = self.parse_if_expr_1(); - ret self.mk_expr(q.lo, q.hi, - expr_if_check(q.cond, q.then, q.els)); - } else { - let q = self.parse_if_expr_1(); - ret self.mk_expr(q.lo, q.hi, expr_if(q.cond, q.then, q.els)); - } + let q = {cond: cond, then: thn, els: els, lo: lo, hi: hi}; + ret self.mk_expr(q.lo, q.hi, expr_if(q.cond, q.then, q.els)); } fn parse_fn_expr(proto: proto) -> @expr { @@ -1520,8 +1402,7 @@ class parser { span: self.span }, purity: impure_fn, - cf: return_val, - constraints: ~[] + cf: return_val } }, @~[]) @@ -2083,20 +1964,11 @@ class parser { let inputs = either::lefts(args_or_capture_items); let capture_clause = @either::rights(args_or_capture_items); - // Use the args list to translate each bound variable - // mentioned in a constraint to an arg index. - // Seems weird to do this in the parser, but I'm not sure how else to. - let mut constrs = ~[]; - if self.token == token::COLON { - self.bump(); - constrs = self.parse_constrs(|p| p.parse_ty_constr(inputs)); - } let (ret_style, ret_ty) = self.parse_ret_ty(); ret ({inputs: inputs, output: ret_ty, purity: purity, - cf: ret_style, - constraints: constrs}, capture_clause); + cf: ret_style}, capture_clause); } fn parse_fn_block_decl() -> (fn_decl, capture_clause) { @@ -2118,8 +1990,7 @@ class parser { ret ({inputs: either::lefts(inputs_captures), output: output, purity: impure_fn, - cf: return_val, - constraints: ~[]}, + cf: return_val}, @either::rights(inputs_captures)); } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 7db5af23266..eb8c5b65fa5 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -306,7 +306,7 @@ fn restricted_keyword_table() -> hashmap<~str, ()> { let keys = ~[ ~"alt", ~"again", ~"assert", ~"break", - ~"check", ~"claim", ~"class", ~"const", ~"copy", + ~"check", ~"class", ~"const", ~"copy", ~"do", ~"drop", ~"else", ~"enum", ~"export", ~"extern", ~"fail", ~"false", ~"fn", ~"for", |
