From b7dd75c904277630675e432b3398a584d882b5ac Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 18 Apr 2011 15:33:10 -0700 Subject: 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 --- src/lib/_vec.rs | 2 +- src/lib/option.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/lib') 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; -- cgit v1.2.3