aboutsummaryrefslogtreecommitdiff
path: root/src/comp/util/common.rs
diff options
context:
space:
mode:
authorTim Chevalier <[email protected]>2011-04-12 12:16:21 -0700
committerGraydon Hoare <[email protected]>2011-04-12 14:31:46 -0700
commitd7e881841438cfe0797b71ff35ea96c8f2477a76 (patch)
tree727e73ccf9138df34a1ad3585ef00559e526b2c6 /src/comp/util/common.rs
parentAdd LLVMAddLoopIdiomPass. (diff)
downloadrust-d7e881841438cfe0797b71ff35ea96c8f2477a76.tar.xz
rust-d7e881841438cfe0797b71ff35ea96c8f2477a76.zip
Further work on typestate. Handles expr_rec and expr_assign now.
Also changed the ts_ann field on statements to be an ann instead, which explains most of the changes. As well, got rid of the "warning: no type for expression" error by filling in annotations for local decls in typeck (not sure whether this was my fault or not). Finally, in bitv, added a clone() function to copy a bit vector, and fixed is_true, is_false, and to_str to not be nonsense.
Diffstat (limited to 'src/comp/util/common.rs')
-rw-r--r--src/comp/util/common.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs
index 68d518da..58109126 100644
--- a/src/comp/util/common.rs
+++ b/src/comp/util/common.rs
@@ -1,8 +1,17 @@
import std._uint;
import std._int;
import std._vec;
+import std.option.none;
import front.ast;
+import util.typestate_ann.ts_ann;
+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;
type filename = str;
type span = rec(uint lo, uint hi);
@@ -94,6 +103,40 @@ fn elt_exprs(vec[ast.elt] elts) -> vec[@ast.expr] {
be _vec.map[ast.elt, @ast.expr](f, elts);
}
+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);
+}
+
+fn plain_ann() -> ast.ann {
+ ret ast.ann_type(middle.ty.plain_ty(middle.ty.ty_nil),
+ none[vec[@middle.ty.t]], none[@ts_ann]);
+}
+
+fn log_expr(@ast.expr e) -> () {
+ 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_expr(out, e);
+ log(s.get_str());
+}
+
+fn log_block(&ast.block b) -> () {
+ 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);
+ log(s.get_str());
+}
+
//
// Local Variables:
// mode: rust