aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorTim Chevalier <[email protected]>2011-04-18 15:33:10 -0700
committerGraydon Hoare <[email protected]>2011-04-19 14:56:28 -0700
commitb7dd75c904277630675e432b3398a584d882b5ac (patch)
treefcc27a73698613ad6378a42e9cd28a809761b6e3 /src/lib
parentRemove half-baked 'opacity' layer qualifier. (diff)
downloadrust-b7dd75c904277630675e432b3398a584d882b5ac.tar.xz
rust-b7dd75c904277630675e432b3398a584d882b5ac.zip
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
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/_vec.rs2
-rw-r--r--src/lib/option.rs12
2 files changed, 9 insertions, 5 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs
index 6fc1d700..cc8fabca 100644
--- a/src/lib/_vec.rs
+++ b/src/lib/_vec.rs
@@ -266,7 +266,7 @@ fn unzip[T, U](&vec[tup(T, U)] v) -> tup(vec[T], vec[U]) {
fn or(&vec[bool] v) -> bool {
auto f = orb;
- be _vec.foldl[bool, bool](f, false, v);
+ ret _vec.foldl[bool, bool](f, false, v);
}
fn clone[T](&vec[T] v) -> vec[T] {
diff --git a/src/lib/option.rs b/src/lib/option.rs
index 66a41bca..e214c774 100644
--- a/src/lib/option.rs
+++ b/src/lib/option.rs
@@ -39,12 +39,16 @@ fn is_none[T](&t[T] opt) -> bool {
}
fn from_maybe[T](&T def, &t[T] opt) -> T {
- alt(opt) {
- case (none[T]) { ret def; }
- case (some[T](?t)) { ret t; }
- }
+ auto f = bind util.id[T](_);
+ ret maybe[T, T](def, f, opt);
}
+fn maybe[T, U](&U def, fn(&T) -> U f, &t[T] opt) -> U {
+ alt (opt) {
+ case (none[T]) { ret def; }
+ case (some[T](?t)) { ret f(t); }
+ }
+}
// Local Variables:
// mode: rust;
// fill-column: 78;