2011-05-12 10:24:54 -05:00
|
|
|
import std::map;
|
|
|
|
import std::map::hashmap;
|
2011-05-17 13:41:41 -05:00
|
|
|
import std::uint;
|
|
|
|
import std::int;
|
|
|
|
import std::vec;
|
2011-05-12 10:24:54 -05:00
|
|
|
import std::option::none;
|
2011-05-18 17:38:38 -05:00
|
|
|
import std::option::some;
|
2011-05-12 10:24:54 -05:00
|
|
|
import front::ast;
|
2011-05-14 21:02:30 -05:00
|
|
|
import front::ast::ty;
|
|
|
|
import front::ast::pat;
|
2011-05-30 18:22:58 -05:00
|
|
|
import front::codemap::codemap;
|
2011-06-01 20:10:10 -05:00
|
|
|
import front::ast::lit;
|
|
|
|
import front::ast::path;
|
2011-05-26 19:16:54 -05:00
|
|
|
import middle::walk;
|
2011-05-12 10:24:54 -05:00
|
|
|
|
|
|
|
import std::io::stdout;
|
|
|
|
import std::io::str_writer;
|
|
|
|
import std::io::string_writer;
|
|
|
|
import pretty::pprust::print_block;
|
2011-05-18 17:38:38 -05:00
|
|
|
import pretty::pprust::print_item;
|
2011-05-12 10:24:54 -05:00
|
|
|
import pretty::pprust::print_expr;
|
2011-06-01 20:10:10 -05:00
|
|
|
import pretty::pprust::print_path;
|
2011-05-12 10:24:54 -05:00
|
|
|
import pretty::pprust::print_decl;
|
|
|
|
import pretty::pprust::print_fn;
|
2011-05-14 21:02:30 -05:00
|
|
|
import pretty::pprust::print_type;
|
2011-06-09 11:48:16 -05:00
|
|
|
import pretty::ppaux::print_literal;
|
|
|
|
import pretty::ppaux::mo_untyped;
|
2011-05-28 21:16:18 -05:00
|
|
|
import pretty::pp::mk_printer;
|
2011-02-23 16:37:39 -06:00
|
|
|
|
|
|
|
type filename = str;
|
2011-04-08 11:44:20 -05:00
|
|
|
type span = rec(uint lo, uint hi);
|
2010-10-05 20:21:44 -05:00
|
|
|
type spanned[T] = rec(T node, span span);
|
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
|
|
|
type flag = hashmap[str, ()];
|
2010-08-18 13:34:47 -05:00
|
|
|
|
2010-09-09 17:59:29 -05:00
|
|
|
tag ty_mach {
|
2010-09-21 01:56:43 -05:00
|
|
|
ty_i8;
|
|
|
|
ty_i16;
|
|
|
|
ty_i32;
|
|
|
|
ty_i64;
|
|
|
|
|
|
|
|
ty_u8;
|
|
|
|
ty_u16;
|
|
|
|
ty_u32;
|
|
|
|
ty_u64;
|
|
|
|
|
|
|
|
ty_f32;
|
|
|
|
ty_f64;
|
2010-09-09 17:59:29 -05:00
|
|
|
}
|
2010-08-18 13:34:47 -05:00
|
|
|
|
2011-05-20 16:15:39 -05:00
|
|
|
tag ty_or_bang[T] {
|
|
|
|
a_ty(T);
|
|
|
|
a_bang;
|
|
|
|
}
|
|
|
|
|
2010-08-20 13:41:34 -05:00
|
|
|
fn ty_mach_to_str(ty_mach tm) -> str {
|
|
|
|
alt (tm) {
|
2010-09-21 01:56:43 -05:00
|
|
|
case (ty_u8) { ret "u8"; }
|
|
|
|
case (ty_u16) { ret "u16"; }
|
|
|
|
case (ty_u32) { ret "u32"; }
|
|
|
|
case (ty_u64) { ret "u64"; }
|
|
|
|
|
|
|
|
case (ty_i8) { ret "i8"; }
|
|
|
|
case (ty_i16) { ret "i16"; }
|
|
|
|
case (ty_i32) { ret "i32"; }
|
|
|
|
case (ty_i64) { ret "i64"; }
|
|
|
|
|
|
|
|
case (ty_f32) { ret "f32"; }
|
|
|
|
case (ty_f64) { ret "f64"; }
|
2010-08-20 13:41:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn new_str_hash[V]() -> std::map::hashmap[str,V] {
|
2011-05-17 13:41:41 -05:00
|
|
|
let std::map::hashfn[str] hasher = std::str::hash;
|
|
|
|
let std::map::eqfn[str] eqer = std::str::eq;
|
2011-05-12 10:24:54 -05:00
|
|
|
ret std::map::mk_hashmap[str,V](hasher, eqer);
|
2010-09-21 18:22:32 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn def_eq(&ast::def_id a, &ast::def_id b) -> bool {
|
2011-03-08 13:59:38 -06:00
|
|
|
ret a._0 == b._0 && a._1 == b._1;
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn hash_def(&ast::def_id d) -> uint {
|
2011-03-31 13:55:28 -05:00
|
|
|
auto h = 5381u;
|
|
|
|
h = ((h << 5u) + h) ^ (d._0 as uint);
|
|
|
|
h = ((h << 5u) + h) ^ (d._1 as uint);
|
|
|
|
ret h;
|
|
|
|
}
|
2010-10-19 16:54:10 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn new_def_hash[V]() -> std::map::hashmap[ast::def_id,V] {
|
|
|
|
let std::map::hashfn[ast::def_id] hasher = hash_def;
|
|
|
|
let std::map::eqfn[ast::def_id] eqer = def_eq;
|
|
|
|
ret std::map::mk_hashmap[ast::def_id,V](hasher, eqer);
|
2010-10-19 16:54:10 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn new_int_hash[V]() -> std::map::hashmap[int,V] {
|
2011-03-25 12:42:57 -05:00
|
|
|
fn hash_int(&int x) -> uint { ret x as uint; }
|
|
|
|
fn eq_int(&int a, &int b) -> bool { ret a == b; }
|
|
|
|
auto hasher = hash_int;
|
|
|
|
auto eqer = eq_int;
|
2011-05-12 10:24:54 -05:00
|
|
|
ret std::map::mk_hashmap[int,V](hasher, eqer);
|
2011-03-25 12:42:57 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn new_uint_hash[V]() -> std::map::hashmap[uint,V] {
|
2011-04-11 18:54:05 -05:00
|
|
|
fn hash_uint(&uint x) -> uint { ret x; }
|
|
|
|
fn eq_uint(&uint a, &uint b) -> bool { ret a == b; }
|
|
|
|
auto hasher = hash_uint;
|
|
|
|
auto eqer = eq_uint;
|
2011-05-12 10:24:54 -05:00
|
|
|
ret std::map::mk_hashmap[uint,V](hasher, eqer);
|
2011-04-11 18:54:05 -05:00
|
|
|
}
|
|
|
|
|
2010-09-23 19:16:34 -05:00
|
|
|
fn istr(int i) -> str {
|
2011-05-17 13:41:41 -05:00
|
|
|
ret int::to_str(i, 10u);
|
2010-09-23 19:16:34 -05:00
|
|
|
}
|
|
|
|
|
2011-04-07 20:15:56 -05:00
|
|
|
fn uistr(uint i) -> str {
|
2011-05-17 13:41:41 -05:00
|
|
|
ret uint::to_str(i, 10u);
|
2011-04-07 20:15:56 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn elt_expr(&ast::elt e) -> @ast::expr { ret e.expr; }
|
2011-04-07 20:15:56 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn elt_exprs(&vec[ast::elt] elts) -> vec[@ast::expr] {
|
2011-04-07 20:15:56 -05:00
|
|
|
auto f = elt_expr;
|
2011-05-17 13:41:41 -05:00
|
|
|
ret vec::map[ast::elt, @ast::expr](f, elts);
|
2011-04-07 20:15:56 -05:00
|
|
|
}
|
|
|
|
|
2011-05-30 17:56:01 -05:00
|
|
|
fn field_expr(&ast::field f) -> @ast::expr { ret f.node.expr; }
|
2011-04-12 14:16:21 -05:00
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn field_exprs(vec[ast::field] fields) -> vec [@ast::expr] {
|
2011-04-12 14:16:21 -05:00
|
|
|
auto f = field_expr;
|
2011-05-17 13:41:41 -05:00
|
|
|
ret vec::map[ast::field, @ast::expr](f, fields);
|
2011-04-12 14:16:21 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_expr(&ast::expr e) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log(pretty::pprust::expr_to_str(@e));
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_expr_err(&ast::expr e) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log_err(pretty::pprust::expr_to_str(@e));
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
|
|
|
|
2011-05-14 21:02:30 -05:00
|
|
|
fn log_ty_err(&ty t) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log_err(pretty::pprust::ty_to_str(t));
|
2011-05-14 21:02:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn log_pat_err(&@pat p) -> () {
|
|
|
|
log_err(pretty::pprust::pat_to_str(p));
|
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_block(&ast::block b) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log(pretty::pprust::block_to_str(b));
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_block_err(&ast::block b) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log_err(pretty::pprust::block_to_str(b));
|
2011-04-12 14:16:21 -05:00
|
|
|
}
|
|
|
|
|
2011-05-18 17:38:38 -05:00
|
|
|
fn log_item_err(&@ast::item i) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log_err(pretty::pprust::item_to_str(i));
|
2011-04-22 13:08:47 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_fn(&ast::_fn f, str name, vec[ast::ty_param] params) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log(pretty::pprust::fun_to_str(f, name, params));
|
2011-04-22 13:08:47 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_fn_err(&ast::_fn f, str name, vec[ast::ty_param] params) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log_err(pretty::pprust::fun_to_str(f, name, params));
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_stmt(&ast::stmt st) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log(pretty::pprust::stmt_to_str(st));
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn log_stmt_err(&ast::stmt st) -> () {
|
2011-05-31 12:58:30 -05:00
|
|
|
log_err(pretty::pprust::stmt_to_str(st));
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn decl_lhs(@ast::decl d) -> ast::def_id {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
alt (d.node) {
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::decl_local(?l)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret l.id;
|
|
|
|
}
|
2011-05-12 10:24:54 -05:00
|
|
|
case (ast::decl_item(?an_item)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
alt (an_item.node) {
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_const(_,_,_,_,?d,_)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d;
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_fn(_,_,_,_,?d,_)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d;
|
|
|
|
}
|
2011-06-14 16:39:28 -05:00
|
|
|
case (ast::item_mod(_,_,_,?d)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d;
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_native_mod(_,_,_,?d)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d;
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_ty(_,_,_,_,?d,_)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d;
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_tag(_,_,_,_,?d,_)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d;
|
|
|
|
}
|
2011-06-14 19:06:06 -05:00
|
|
|
case (ast::item_obj(_,_,_,_,?d,_)) {
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
ret d.ctor; /* This doesn't really make sense */
|
|
|
|
}
|
|
|
|
}
|
2011-05-26 19:16:54 -05:00
|
|
|
}
|
Further work on typestate_check
Lots of work on typestate_check, seems to get a lot of the way
through checking the standard library.
* Added for, for_each, assign_op, bind, cast, put, check, break,
and cont. (I'm not sure break and cont are actually handled correctly.)
* Fixed side-effect bug in seq_preconds so that unioning the
preconditions of a sequence of statements or expressions
is handled correctly.
* Pass poststate correctly through a stmt_decl.
* Handle expr_ret and expr_fail properly (after execution of a ret
or fail, everything is true -- this is needed to handle ifs and alts
where one branch is a ret or fail)
* Fixed bug in set_prestate_ann where a thing that needed to be
mutated wasn't getting passed as an alias
* Fixed bug in how expr_alt was treated (zero is not the identity
for intersect, who knew, right?)
* Update logging to reflect log_err vs. log
* Fixed find_locals so as to return all local decls and exclude
function arguments.
* Make union_postconds work on an empty vector (needed to handle
empty blocks correctly)
* Added _vec.cat_options, which takes a list of option[T] to a list
of T, ignoring any Nones
* Added two test cases.
2011-04-20 14:11:01 -05:00
|
|
|
}
|
Handle nested items correctly in typestate_check
Summary says it all. Actually, only nested objects and functions
are handled, but that's better than before. The fold that I was using
before to traverse a crate wasn't working correctly, because annotations
have to reflect the number of local variables of the nearest enclosing
function (in turn, because annotations are represented as bit vectors).
The fold was traversing the AST in the wrong order, first filling in
the annotations correctly, but then re-traversing them with the bit
vector length for any outer nested functions, and so on.
Remedying this required writing a lot of tedious boilerplate code
because I scrapped the idea of using a fold altogether.
I also made typestate_check handle unary, field, alt, and fail.
Also, some miscellaneous changes:
* added annotations to blocks in typeck
* fix pprust so it can handle spawn
* added more logging functions in util.common
* fixed _vec.or
* added maybe and from_maybe in option
* removed fold_block field from ast_fold, since it was never used
2011-04-18 17:33:10 -05:00
|
|
|
}
|
|
|
|
|
2011-05-12 10:24:54 -05:00
|
|
|
fn has_nonlocal_exits(&ast::block b) -> bool {
|
2011-05-26 19:16:54 -05:00
|
|
|
auto has_exits = @mutable false;
|
2011-05-09 19:49:19 -05:00
|
|
|
|
2011-05-26 19:16:54 -05:00
|
|
|
fn visit_expr(@mutable bool flag, &@ast::expr e) {
|
|
|
|
alt (e.node) {
|
|
|
|
case (ast::expr_break(_)) { *flag = true; }
|
|
|
|
case (ast::expr_cont(_)) { *flag = true; }
|
|
|
|
case (_) { }
|
|
|
|
}
|
|
|
|
}
|
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-26 19:16:54 -05:00
|
|
|
auto v = rec(visit_expr_pre=bind visit_expr(has_exits, _)
|
|
|
|
with walk::default_visitor());
|
|
|
|
walk::walk_block(v, b);
|
|
|
|
ret *has_exits;
|
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
|
|
|
|
2011-06-13 19:04:15 -05:00
|
|
|
fn local_rhs_span(&@ast::local_ l, &span def) -> span {
|
2011-05-18 17:38:38 -05:00
|
|
|
alt (l.init) {
|
2011-05-30 23:39:19 -05:00
|
|
|
case (some(?i)) { ret i.expr.span; }
|
2011-05-18 17:38:38 -05:00
|
|
|
case (_) { ret def; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 20:10:10 -05:00
|
|
|
fn lit_eq(&@ast::lit l, &@ast::lit m) -> bool {
|
|
|
|
alt (l.node) {
|
2011-06-09 19:11:21 -05:00
|
|
|
case (ast::lit_str(?s,?kind_s)) {
|
2011-06-01 20:10:10 -05:00
|
|
|
alt (m.node) {
|
2011-06-09 19:11:21 -05:00
|
|
|
case (ast::lit_str(?t,?kind_t)) {
|
|
|
|
ret s == t && kind_s == kind_t;
|
|
|
|
}
|
2011-06-01 20:10:10 -05:00
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_char(?c)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_char(?d)) { ret c == d; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_int(?i)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_int(?j)) { ret i == j; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_uint(?i)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_uint(?j)) { ret i == j; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_mach_int(_, ?i)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_mach_int(_, ?j)) { ret i == j; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_float(?s)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_float(?t)) { ret s == t; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_mach_float(_,?s)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_mach_float(_,?t)) { ret s == t; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_nil) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_nil) { ret true; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (ast::lit_bool(?b)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast::lit_bool(?c)) { ret b == c; }
|
|
|
|
case (_) { ret false; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-26 19:16:54 -05:00
|
|
|
fn respan[T](&span sp, &T t) -> spanned[T] {
|
|
|
|
ret rec(node=t, span=sp);
|
|
|
|
}
|
|
|
|
|
2011-06-09 11:48:16 -05:00
|
|
|
fn may_begin_ident(char c) -> bool {
|
|
|
|
ret (is_alpha(c) || c == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
fn in_range(char c, char lo, char hi) -> bool {
|
|
|
|
ret lo <= c && c <= hi;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_alpha(char c) -> bool {
|
|
|
|
ret in_range(c, 'a', 'z') ||
|
|
|
|
in_range(c, 'A', 'Z');
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_dec_digit(char c) -> bool {
|
|
|
|
ret in_range(c, '0', '9');
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_alnum(char c) -> bool {
|
|
|
|
ret is_alpha(c) || is_dec_digit(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_hex_digit(char c) -> bool {
|
|
|
|
ret in_range(c, '0', '9') ||
|
|
|
|
in_range(c, 'a', 'f') ||
|
|
|
|
in_range(c, 'A', 'F');
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_bin_digit(char c) -> bool {
|
|
|
|
ret c == '0' || c == '1';
|
|
|
|
}
|
|
|
|
|
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
|
2011-03-25 17:07:27 -05:00
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
2010-08-18 13:34:47 -05:00
|
|
|
// End:
|
|
|
|
//
|