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.
|
|
|
|
#debug[">>"];
|
|
|
|
let r <- op();
|
|
|
|
#debug["<< (Result = %?)", r];
|
|
|
|
ret r;
|
|
|
|
}
|
|
|
|
|
|
|
|
resource _indenter(_i: ()) {
|
|
|
|
#debug["<<"];
|
|
|
|
}
|
|
|
|
|
|
|
|
fn indenter() -> _indenter {
|
|
|
|
#debug[">>"];
|
|
|
|
_indenter(())
|
|
|
|
}
|
|
|
|
|
2011-08-12 09:15:18 -05:00
|
|
|
type flag = hashmap<str, ()>;
|
2010-08-18 13:34:47 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn field_expr(f: ast::field) -> @ast::expr { ret f.node.expr; }
|
2011-04-12 14:16:21 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn field_exprs(fields: [ast::field]) -> [@ast::expr] {
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut es = [];
|
2012-04-06 13:01:43 -05:00
|
|
|
for fields.each {|f| es += [f.node.expr]; }
|
2011-07-06 21:00:00 -05:00
|
|
|
ret 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
|
|
|
|
// of b
|
|
|
|
fn block_expr_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
|
|
|
|
let rs = @mut false;
|
|
|
|
let visit_expr = {|flag: @mut bool, e: @ast::expr| *flag |= p(e.node)};
|
2011-07-27 07:19:39 -05:00
|
|
|
let v =
|
2012-06-19 21:34:01 -05:00
|
|
|
visit::mk_simple_visitor(@{visit_expr: {|a|visit_expr(rs, a)}
|
2011-07-27 07:19:39 -05:00
|
|
|
with *visit::default_simple_visitor()});
|
2011-07-26 09:47:13 -05:00
|
|
|
visit::visit_block(b, (), v);
|
2012-06-14 14:24:56 -05:00
|
|
|
ret *rs;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn has_nonlocal_exits(b: ast::blk) -> bool {
|
|
|
|
block_expr_query(b) {|e| alt e {
|
|
|
|
ast::expr_break | ast::expr_cont { true }
|
|
|
|
_ { 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-06-14 14:24:56 -05:00
|
|
|
block_expr_query(b) {|e| alt e {
|
|
|
|
ast::expr_break { true }
|
|
|
|
_ { 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 {
|
2011-07-27 07:19:39 -05:00
|
|
|
alt l.node.init { some(i) { ret i.expr.span; } _ { ret 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-03-08 17:24:27 -06:00
|
|
|
// FIXME: path should be a constrained type, so we know
|
2012-06-14 14:24:56 -05:00
|
|
|
// the call to last doesn't fail (#34)
|
2012-06-10 02:49:59 -05:00
|
|
|
vec::last(path) == syntax::ast_map::path_name(@"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:
|
|
|
|
//
|