2010-09-01 15:24:14 -05:00
|
|
|
import std._uint;
|
2010-09-23 19:16:34 -05:00
|
|
|
import std._int;
|
2011-04-07 20:15:56 -05:00
|
|
|
import std._vec;
|
2011-04-12 14:16:21 -05:00
|
|
|
import std.option.none;
|
2010-10-19 16:54:10 -05:00
|
|
|
import front.ast;
|
2011-04-12 14:16:21 -05:00
|
|
|
import util.typestate_ann.ts_ann;
|
2010-09-01 15:24:14 -05:00
|
|
|
|
2011-04-12 14:16:21 -05:00
|
|
|
import std.io.stdout;
|
|
|
|
import std.io.str_writer;
|
|
|
|
import std.io.string_writer;
|
|
|
|
import pretty.pprust.print_block;
|
|
|
|
import pretty.pprust.print_expr;
|
|
|
|
import pretty.pprust.print_decl;
|
|
|
|
import pretty.pp.mkstate;
|
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);
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-21 18:22:32 -05:00
|
|
|
fn new_str_hash[V]() -> std.map.hashmap[str,V] {
|
|
|
|
let std.map.hashfn[str] hasher = std._str.hash;
|
|
|
|
let std.map.eqfn[str] eqer = std._str.eq;
|
|
|
|
ret std.map.mk_hashmap[str,V](hasher, eqer);
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:59:38 -06:00
|
|
|
fn def_eq(&ast.def_id a, &ast.def_id b) -> bool {
|
|
|
|
ret a._0 == b._0 && a._1 == b._1;
|
|
|
|
}
|
|
|
|
|
2011-03-31 13:55:28 -05:00
|
|
|
fn hash_def(&ast.def_id d) -> uint {
|
|
|
|
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-03-31 13:55:28 -05:00
|
|
|
fn new_def_hash[V]() -> std.map.hashmap[ast.def_id,V] {
|
|
|
|
let std.map.hashfn[ast.def_id] hasher = hash_def;
|
2011-03-08 13:59:38 -06:00
|
|
|
let std.map.eqfn[ast.def_id] eqer = def_eq;
|
2010-10-19 16:54:10 -05:00
|
|
|
ret std.map.mk_hashmap[ast.def_id,V](hasher, eqer);
|
|
|
|
}
|
|
|
|
|
2011-03-25 12:42:57 -05:00
|
|
|
fn new_int_hash[V]() -> std.map.hashmap[int,V] {
|
|
|
|
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;
|
|
|
|
ret std.map.mk_hashmap[int,V](hasher, eqer);
|
|
|
|
}
|
|
|
|
|
2011-04-11 18:54:05 -05:00
|
|
|
fn new_uint_hash[V]() -> std.map.hashmap[uint,V] {
|
|
|
|
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;
|
|
|
|
ret std.map.mk_hashmap[uint,V](hasher, eqer);
|
|
|
|
}
|
|
|
|
|
2010-09-23 19:16:34 -05:00
|
|
|
fn istr(int i) -> str {
|
|
|
|
ret _int.to_str(i, 10u);
|
|
|
|
}
|
|
|
|
|
2011-04-07 20:15:56 -05:00
|
|
|
fn uistr(uint i) -> str {
|
|
|
|
ret _uint.to_str(i, 10u);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn elt_expr(&ast.elt e) -> @ast.expr { ret e.expr; }
|
|
|
|
|
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
|
|
|
fn elt_exprs(&vec[ast.elt] elts) -> vec[@ast.expr] {
|
2011-04-07 20:15:56 -05:00
|
|
|
auto f = elt_expr;
|
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 _vec.map[ast.elt, @ast.expr](f, elts);
|
2011-04-07 20:15:56 -05:00
|
|
|
}
|
|
|
|
|
2011-04-12 14:16:21 -05:00
|
|
|
fn field_expr(&ast.field f) -> @ast.expr { ret f.expr; }
|
|
|
|
|
|
|
|
fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
|
|
|
|
auto f = field_expr;
|
|
|
|
ret _vec.map[ast.field, @ast.expr](f, fields);
|
|
|
|
}
|
|
|
|
|
2011-04-25 14:15:55 -05:00
|
|
|
fn plain_ann(middle.ty.ctxt tcx) -> ast.ann {
|
|
|
|
ret ast.ann_type(middle.ty.mk_nil(tcx),
|
2011-04-22 14:27:28 -05:00
|
|
|
none[vec[middle.ty.t]], none[@ts_ann]);
|
2011-04-12 14:16:21 -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
|
|
|
fn expr_to_str(&ast.expr e) -> str {
|
2011-04-12 14:16:21 -05:00
|
|
|
let str_writer s = string_writer();
|
|
|
|
auto out_ = mkstate(s.get_writer(), 80u);
|
|
|
|
auto out = @rec(s=out_,
|
|
|
|
comments=none[vec[front.lexer.cmnt]],
|
|
|
|
mutable cur_cmnt=0u);
|
2011-04-13 17:34:10 -05:00
|
|
|
print_expr(out, @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
|
|
|
ret s.get_str();
|
2011-04-12 14:16:21 -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
|
|
|
fn log_expr(&ast.expr e) -> () {
|
|
|
|
log(expr_to_str(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_expr_err(&ast.expr e) -> () {
|
|
|
|
log_err(expr_to_str(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn block_to_str(&ast.block b) -> str {
|
2011-04-12 14:16:21 -05:00
|
|
|
let str_writer s = string_writer();
|
|
|
|
auto out_ = mkstate(s.get_writer(), 80u);
|
|
|
|
auto out = @rec(s=out_,
|
|
|
|
comments=none[vec[front.lexer.cmnt]],
|
|
|
|
mutable cur_cmnt=0u);
|
|
|
|
|
|
|
|
print_block(out, 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
|
|
|
ret s.get_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_block(&ast.block b) -> () {
|
|
|
|
log(block_to_str(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_block_err(&ast.block b) -> () {
|
|
|
|
log_err(block_to_str(b));
|
2011-04-12 14:16:21 -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
|
|
|
fn log_ann(&ast.ann a) -> () {
|
|
|
|
alt (a) {
|
|
|
|
case (ast.ann_none) {
|
|
|
|
log("ann_none");
|
|
|
|
}
|
|
|
|
case (ast.ann_type(_,_,_)) {
|
|
|
|
log("ann_type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
fn stmt_to_str(&ast.stmt st) -> str {
|
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
|
|
|
let str_writer s = string_writer();
|
|
|
|
auto out_ = mkstate(s.get_writer(), 80u);
|
|
|
|
auto out = @rec(s=out_,
|
|
|
|
comments=none[vec[front.lexer.cmnt]],
|
|
|
|
mutable cur_cmnt=0u);
|
|
|
|
alt (st.node) {
|
|
|
|
case (ast.stmt_decl(?decl,_)) {
|
|
|
|
print_decl(out, decl);
|
|
|
|
}
|
|
|
|
case (ast.stmt_expr(?ex,_)) {
|
|
|
|
print_expr(out, ex);
|
|
|
|
}
|
|
|
|
case (_) { /* do nothing */ }
|
|
|
|
}
|
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 s.get_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_stmt(&ast.stmt st) -> () {
|
|
|
|
log(stmt_to_str(st));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn log_stmt_err(&ast.stmt st) -> () {
|
|
|
|
log_err(stmt_to_str(st));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn decl_lhs(@ast.decl d) -> ast.def_id {
|
|
|
|
alt (d.node) {
|
|
|
|
case (ast.decl_local(?l)) {
|
|
|
|
ret l.id;
|
|
|
|
}
|
|
|
|
case (ast.decl_item(?an_item)) {
|
|
|
|
alt (an_item.node) {
|
|
|
|
case (ast.item_const(_,_,_,?d,_)) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
case (ast.item_fn(_,_,_,?d,_)) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
case (ast.item_mod(_,_,?d)) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
case (ast.item_native_mod(_,_,?d)) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
case (ast.item_ty(_,_,_,?d,_)) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
case (ast.item_tag(_,_,_,?d,_)) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
case (ast.item_obj(_,_,_,?d,_)) {
|
|
|
|
ret d.ctor; /* This doesn't really make sense */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
//
|