From aa25f22f197682de3b18fc4c8ba068d1feda220f Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 2 May 2011 11:23:07 -0700 Subject: Use different syntax for checks that matter to typestate This giant commit changes the syntax of Rust to use "assert" for "check" expressions that didn't mean anything to the typestate system, and continue using "check" for checks that are used as part of typestate checking. Most of the changes are just replacing "check" with "assert" in test cases and rustc. --- src/comp/front/parser.rs | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'src/comp/front/parser.rs') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index fdd41cf0..3e8ca85a 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -621,7 +621,7 @@ fn parse_path(parser p, greed g) -> ast.path { if (p.peek() == token.DOT) { if (g == GREEDY) { p.bump(); - check (is_ident(p.peek())); + assert (is_ident(p.peek())); } else { more = false; } @@ -816,20 +816,23 @@ fn parse_bottom_expr(parser p) -> @ast.expr { ex = ast.expr_log(0, e, ast.ann_none); } - case (token.CHECK) { + case (token.ASSERT) { p.bump(); - alt (p.peek()) { - case (token.LPAREN) { - auto e = parse_expr(p); - auto hi = e.span.hi; - ex = ast.expr_check_expr(e, ast.ann_none); - } - case (_) { - p.get_session().unimpl("constraint-check stmt"); - } - } + auto e = parse_expr(p); + auto hi = e.span.hi; + ex = ast.expr_assert(e, ast.ann_none); } + case (token.CHECK) { + p.bump(); + /* Should be a predicate (pure boolean function) applied to + arguments that are all either slot variables or literals. + but the typechecker enforces that. */ + auto e = parse_expr(p); + auto hi = e.span.hi; + ex = ast.expr_check(e, ast.ann_none); + } + case (token.RET) { p.bump(); alt (p.peek()) { @@ -937,7 +940,7 @@ fn expand_syntax_ext(parser p, ast.span sp, &ast.path path, vec[@ast.expr] args, option.t[str] body) -> ast.expr_ { - check (_vec.len[ast.ident](path.node.idents) > 0u); + assert (_vec.len[ast.ident](path.node.idents) > 0u); auto extname = path.node.idents.(0); if (_str.eq(extname, "fmt")) { auto expanded = extfmt.expand_syntax_ext(args, body); @@ -1673,7 +1676,8 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool { case (ast.expr_put(_,_)) { ret true; } case (ast.expr_be(_,_)) { ret true; } case (ast.expr_log(_,_,_)) { ret true; } - case (ast.expr_check_expr(_,_)) { ret true; } + case (ast.expr_check(_,_)) { ret true; } + case (ast.expr_assert(_,_)) { ret true; } } } // We should not be calling this on a cdir. @@ -2157,24 +2161,24 @@ fn parse_item(parser p) -> @ast.item { alt (p.peek()) { case (token.CONST) { - check (lyr == ast.layer_value); + assert (lyr == ast.layer_value); ret parse_item_const(p); } case (token.FN) { - check (lyr == ast.layer_value); + assert (lyr == ast.layer_value); ret parse_item_fn_or_iter(p); } case (token.ITER) { - check (lyr == ast.layer_value); + assert (lyr == ast.layer_value); ret parse_item_fn_or_iter(p); } case (token.MOD) { - check (lyr == ast.layer_value); + assert (lyr == ast.layer_value); ret parse_item_mod(p); } case (token.NATIVE) { - check (lyr == ast.layer_value); + assert (lyr == ast.layer_value); ret parse_item_native_mod(p); } case (token.TYPE) { -- cgit v1.2.3