2011-05-12 10:24:54 -05:00
|
|
|
import std::map::hashmap;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::ast;
|
2011-11-10 10:41:42 -06:00
|
|
|
import ast::{ty, pat};
|
|
|
|
import syntax::codemap::{span};
|
2011-07-26 09:47:13 -05:00
|
|
|
import syntax::visit;
|
2011-07-05 04:48:19 -05:00
|
|
|
import syntax::print;
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2012-04-05 22:59:07 -05:00
|
|
|
fn indent<R>(op: fn() -> R) -> R {
|
|
|
|
// Use in conjunction with the log post-processor like `src/etc/indenter`
|
|
|
|
// to make debug output more readable.
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!(">>");
|
2012-04-05 22:59:07 -05:00
|
|
|
let r <- op();
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!("<< (Result = %?)", r);
|
2012-08-01 19:30:05 -05:00
|
|
|
return r;
|
2012-04-05 22:59:07 -05:00
|
|
|
}
|
|
|
|
|
2012-08-15 20:46:55 -05:00
|
|
|
struct _indenter {
|
2012-06-22 13:53:25 -05:00
|
|
|
let _i: ();
|
|
|
|
new(_i: ()) { self._i = (); }
|
2012-08-22 19:24:52 -05:00
|
|
|
drop { debug!("<<"); }
|
2012-04-05 22:59:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn indenter() -> _indenter {
|
2012-08-22 19:24:52 -05:00
|
|
|
debug!(">>");
|
2012-04-05 22:59:07 -05:00
|
|
|
_indenter(())
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
type flag = hashmap<~str, ()>;
|
2010-08-18 13:34:47 -05:00
|
|
|
|
2012-08-01 19:30:05 -05:00
|
|
|
fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; }
|
2011-04-12 14:16:21 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
|
|
|
|
let mut es = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for fields.each |f| { vec::push(es, f.node.expr); }
|
2012-08-01 19:30:05 -05:00
|
|
|
return es;
|
2011-04-12 14:16:21 -05:00
|
|
|
}
|
|
|
|
|
2012-06-14 14:24:56 -05:00
|
|
|
// Takes a predicate p, returns true iff p is true for any subexpressions
|
2012-06-20 20:50:44 -05:00
|
|
|
// of b -- skipping any inner loops (loop, while, loop_body)
|
|
|
|
fn loop_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
|
2012-06-14 14:24:56 -05:00
|
|
|
let rs = @mut false;
|
2012-06-30 18:19:07 -05:00
|
|
|
let visit_expr =
|
|
|
|
|e: @ast::expr, &&flag: @mut bool, v: visit::vt<@mut bool>| {
|
2012-06-20 20:50:44 -05:00
|
|
|
*flag |= p(e.node);
|
2012-08-06 14:34:08 -05:00
|
|
|
match e.node {
|
2012-06-20 20:50:44 -05:00
|
|
|
// Skip inner loops, since a break in the inner loop isn't a
|
|
|
|
// break inside the outer loop
|
2012-08-03 21:59:04 -05:00
|
|
|
ast::expr_loop(*) | ast::expr_while(*)
|
|
|
|
| ast::expr_loop_body(*) => {}
|
|
|
|
_ => visit::visit_expr(e, flag, v)
|
2012-06-20 20:50:44 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
let v = visit::mk_vt(@{visit_expr: visit_expr
|
|
|
|
with *visit::default_visitor()});
|
|
|
|
visit::visit_block(b, rs, v);
|
2012-08-01 19:30:05 -05:00
|
|
|
return *rs;
|
2012-06-14 14:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn has_nonlocal_exits(b: ast::blk) -> bool {
|
2012-08-03 21:59:04 -05:00
|
|
|
do loop_query(b) |e| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match e {
|
2012-08-14 21:20:56 -05:00
|
|
|
ast::expr_break(_) | ast::expr_again(_) => true,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
Support all expression forms in typestate
Added support for self_method, cont, chan, port, recv, send, be,
do_while, spawn, and ext; handled break and cont correctly.
(However, there are no non-xfailed test cases for ext or spawn in
stage0 currently.)
Although the standard library compiles and all test cases pass with
typestate enabled, I left typestate checking disabled as rustc
terminates abnormally when building the standard library if so,
even though it does generate code correctly.
2011-04-21 19:39:04 -05:00
|
|
|
}
|
2011-05-14 21:02:30 -05:00
|
|
|
|
2012-03-10 22:34:57 -06:00
|
|
|
fn may_break(b: ast::blk) -> bool {
|
2012-08-03 21:59:04 -05:00
|
|
|
do loop_query(b) |e| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match e {
|
2012-08-14 21:20:56 -05:00
|
|
|
ast::expr_break(_) => true,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 22:34:57 -06:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn local_rhs_span(l: @ast::local, def: span) -> span {
|
2012-08-06 14:34:08 -05:00
|
|
|
match l.node.init {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(i) => return i.expr.span,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => return def
|
|
|
|
}
|
2011-05-18 17:38:38 -05:00
|
|
|
}
|
|
|
|
|
2012-05-22 01:34:34 -05:00
|
|
|
fn is_main_name(path: syntax::ast_map::path) -> bool {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#34): path should be a constrained type, so we know
|
|
|
|
// the call to last doesn't fail.
|
2012-07-18 18:18:02 -05:00
|
|
|
vec::last(path) == syntax::ast_map::path_name(
|
|
|
|
syntax::parse::token::special_idents::main
|
|
|
|
)
|
2011-07-13 19:26:06 -05:00
|
|
|
}
|
2011-07-22 05:03:10 -05:00
|
|
|
|
2010-08-18 13:34:47 -05:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|