diff options
| author | Marijn Haverbeke <[email protected]> | 2011-05-12 17:24:54 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <[email protected]> | 2011-05-12 21:30:44 +0200 |
| commit | 3816e57fd2a8ab19e4ac6d4b3ddd5b49d5973ff2 (patch) | |
| tree | 508982ed2f789aedd89eebd529343d9dc88b8e01 /src/comp/util | |
| parent | Transitional change to make extfmt output lowercase module name (diff) | |
| download | rust-3816e57fd2a8ab19e4ac6d4b3ddd5b49d5973ff2.tar.xz rust-3816e57fd2a8ab19e4ac6d4b3ddd5b49d5973ff2.zip | |
Downcase std modules again, move to :: for module dereferencing
This should be a snapshot transition.
Diffstat (limited to 'src/comp/util')
| -rw-r--r-- | src/comp/util/common.rs | 166 | ||||
| -rw-r--r-- | src/comp/util/typestate_ann.rs | 62 |
2 files changed, 114 insertions, 114 deletions
diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index 83223d75..dc5e6d08 100644 --- a/src/comp/util/common.rs +++ b/src/comp/util/common.rs @@ -1,23 +1,23 @@ -import std.Map; -import std.Map.hashmap; -import std.UInt; -import std.Int; -import std.Vec; -import std.Option.none; -import front.ast; -import util.typestate_ann.ts_ann; - -import middle.fold; -import middle.fold.respan; - -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.pprust.print_fn; -import pretty.pp.mkstate; +import std::map; +import std::map::hashmap; +import std::_uint; +import std::_int; +import std::_vec; +import std::option::none; +import front::ast; +import util::typestate_ann::ts_ann; + +import middle::fold; +import middle::fold::respan; + +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::pprust::print_fn; +import pretty::pp::mkstate; type filename = str; type span = rec(uint lo, uint hi); @@ -56,150 +56,150 @@ fn ty_mach_to_str(ty_mach tm) -> str { } } -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); +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); } -fn def_eq(&ast.def_id a, &ast.def_id b) -> bool { +fn def_eq(&ast::def_id a, &ast::def_id b) -> bool { ret a._0 == b._0 && a._1 == b._1; } -fn hash_def(&ast.def_id d) -> uint { +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; } -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); +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); } -fn new_int_hash[V]() -> std.Map.hashmap[int,V] { +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); + ret std::map::mk_hashmap[int,V](hasher, eqer); } -fn new_uint_hash[V]() -> std.Map.hashmap[uint,V] { +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); + ret std::map::mk_hashmap[uint,V](hasher, eqer); } fn istr(int i) -> str { - ret Int.to_str(i, 10u); + ret _int::to_str(i, 10u); } fn uistr(uint i) -> str { - ret UInt.to_str(i, 10u); + ret _uint::to_str(i, 10u); } -fn elt_expr(&ast.elt e) -> @ast.expr { ret e.expr; } +fn elt_expr(&ast::elt e) -> @ast::expr { ret e.expr; } -fn elt_exprs(&vec[ast.elt] elts) -> vec[@ast.expr] { +fn elt_exprs(&vec[ast::elt] elts) -> vec[@ast::expr] { auto f = elt_expr; - ret Vec.map[ast.elt, @ast.expr](f, elts); + ret _vec::map[ast::elt, @ast::expr](f, elts); } -fn field_expr(&ast.field f) -> @ast.expr { ret f.expr; } +fn field_expr(&ast::field f) -> @ast::expr { ret f.expr; } -fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] { +fn field_exprs(vec[ast::field] fields) -> vec [@ast::expr] { auto f = field_expr; - ret Vec.map[ast.field, @ast.expr](f, fields); + ret _vec::map[ast::field, @ast::expr](f, fields); } -fn plain_ann(&ast.ann old, middle.ty.ctxt tcx) -> ast.ann { - ret ast.ann_type(ast.ann_tag(old), middle.ty.mk_nil(tcx), - none[vec[middle.ty.t]], none[@ts_ann]); +fn plain_ann(&ast::ann old, middle::ty::ctxt tcx) -> ast::ann { + ret ast::ann_type(ast::ann_tag(old), middle::ty::mk_nil(tcx), + none[vec[middle::ty::t]], none[@ts_ann]); } -fn expr_to_str(&@ast.expr e) -> str { +fn expr_to_str(&@ast::expr e) -> str { let str_writer s = string_writer(); auto out_ = mkstate(s.get_writer(), 80u); auto out = @rec(s=out_, - comments=none[vec[front.lexer.cmnt]], + comments=none[vec[front::lexer::cmnt]], mutable cur_cmnt=0u); print_expr(out, e); ret s.get_str(); } -fn log_expr(&ast.expr e) -> () { +fn log_expr(&ast::expr e) -> () { log(expr_to_str(@e)); } -fn log_expr_err(&ast.expr e) -> () { +fn log_expr_err(&ast::expr e) -> () { log_err(expr_to_str(@e)); } -fn block_to_str(&ast.block b) -> str { +fn block_to_str(&ast::block b) -> str { let str_writer s = string_writer(); auto out_ = mkstate(s.get_writer(), 80u); auto out = @rec(s=out_, - comments=none[vec[front.lexer.cmnt]], + comments=none[vec[front::lexer::cmnt]], mutable cur_cmnt=0u); print_block(out, b); ret s.get_str(); } -fn log_block(&ast.block b) -> () { +fn log_block(&ast::block b) -> () { log(block_to_str(b)); } -fn log_block_err(&ast.block b) -> () { +fn log_block_err(&ast::block b) -> () { log_err(block_to_str(b)); } -fn log_ann(&ast.ann a) -> () { +fn log_ann(&ast::ann a) -> () { alt (a) { - case (ast.ann_none(_)) { + case (ast::ann_none(_)) { log("ann_none"); } - case (ast.ann_type(_,_,_,_)) { + case (ast::ann_type(_,_,_,_)) { log("ann_type"); } } } -fn fun_to_str(&ast._fn f, str name, vec[ast.ty_param] params) -> str { +fn fun_to_str(&ast::_fn f, str name, vec[ast::ty_param] params) -> str { let str_writer s = string_writer(); auto out_ = mkstate(s.get_writer(), 80u); auto out = @rec(s=out_, - comments=none[vec[front.lexer.cmnt]], + comments=none[vec[front::lexer::cmnt]], mutable cur_cmnt=0u); print_fn(out, f.decl, name, params); ret s.get_str(); } -fn log_fn(&ast._fn f, str name, vec[ast.ty_param] params) -> () { +fn log_fn(&ast::_fn f, str name, vec[ast::ty_param] params) -> () { log(fun_to_str(f, name, params)); } -fn log_fn_err(&ast._fn f, str name, vec[ast.ty_param] params) -> () { +fn log_fn_err(&ast::_fn f, str name, vec[ast::ty_param] params) -> () { log_err(fun_to_str(f, name, params)); } -fn stmt_to_str(&ast.stmt st) -> str { +fn stmt_to_str(&ast::stmt st) -> str { let str_writer s = string_writer(); auto out_ = mkstate(s.get_writer(), 80u); auto out = @rec(s=out_, - comments=none[vec[front.lexer.cmnt]], + comments=none[vec[front::lexer::cmnt]], mutable cur_cmnt=0u); alt (st.node) { - case (ast.stmt_decl(?decl,_)) { + case (ast::stmt_decl(?decl,_)) { print_decl(out, decl); } - case (ast.stmt_expr(?ex,_)) { + case (ast::stmt_expr(?ex,_)) { print_expr(out, ex); } case (_) { /* do nothing */ } @@ -207,40 +207,40 @@ fn stmt_to_str(&ast.stmt st) -> str { ret s.get_str(); } -fn log_stmt(&ast.stmt st) -> () { +fn log_stmt(&ast::stmt st) -> () { log(stmt_to_str(st)); } -fn log_stmt_err(&ast.stmt st) -> () { +fn log_stmt_err(&ast::stmt st) -> () { log_err(stmt_to_str(st)); } -fn decl_lhs(@ast.decl d) -> ast.def_id { +fn decl_lhs(@ast::decl d) -> ast::def_id { alt (d.node) { - case (ast.decl_local(?l)) { + case (ast::decl_local(?l)) { ret l.id; } - case (ast.decl_item(?an_item)) { + case (ast::decl_item(?an_item)) { alt (an_item.node) { - case (ast.item_const(_,_,_,?d,_)) { + case (ast::item_const(_,_,_,?d,_)) { ret d; } - case (ast.item_fn(_,_,_,?d,_)) { + case (ast::item_fn(_,_,_,?d,_)) { ret d; } - case (ast.item_mod(_,_,?d)) { + case (ast::item_mod(_,_,?d)) { ret d; } - case (ast.item_native_mod(_,_,?d)) { + case (ast::item_native_mod(_,_,?d)) { ret d; } - case (ast.item_ty(_,_,_,?d,_)) { + case (ast::item_ty(_,_,_,?d,_)) { ret d; } - case (ast.item_tag(_,_,_,?d,_)) { + case (ast::item_tag(_,_,_,?d,_)) { ret d; } - case (ast.item_obj(_,_,_,?d,_)) { + case (ast::item_obj(_,_,_,?d,_)) { ret d.ctor; /* This doesn't really make sense */ } } @@ -248,29 +248,29 @@ fn decl_lhs(@ast.decl d) -> ast.def_id { } } -fn has_nonlocal_exits(&ast.block b) -> bool { +fn has_nonlocal_exits(&ast::block b) -> bool { /* overkill, but just passing around a mutable bool doesn't seem to work in rustboot */ auto has_exits = new_str_hash[()](); - fn set_break(&flag f, &span sp, &ast.ann a) -> @ast.expr { + fn set_break(&flag f, &span sp, &ast::ann a) -> @ast::expr { f.insert("foo", ()); - ret @respan(sp, ast.expr_break(a)); + ret @respan(sp, ast::expr_break(a)); } - fn set_cont(&flag f, &span sp, &ast.ann a) -> @ast.expr { + fn set_cont(&flag f, &span sp, &ast::ann a) -> @ast::expr { f.insert("foo", ()); - ret @respan(sp, ast.expr_cont(a)); + ret @respan(sp, ast::expr_cont(a)); } fn check_b(&flag f) -> bool { ret (f.size() == 0u); } - auto fld0 = fold.new_identity_fold[flag](); + auto fld0 = fold::new_identity_fold[flag](); fld0 = @rec(fold_expr_break = bind set_break(_,_,_), fold_expr_cont = bind set_cont(_,_,_), keep_going = bind check_b(_) with *fld0); - fold.fold_block[flag](has_exits, fld0, b); + fold::fold_block[flag](has_exits, fld0, b); ret (has_exits.size() > 0u); } diff --git a/src/comp/util/typestate_ann.rs b/src/comp/util/typestate_ann.rs index 949eaeb2..249dc5ca 100644 --- a/src/comp/util/typestate_ann.rs +++ b/src/comp/util/typestate_ann.rs @@ -1,21 +1,21 @@ -import front.ast.ident; -import std.Vec; -import std.BitV; +import front::ast::ident; +import std::_vec; +import std::bitv; /* This says: this expression requires the idents in <pre> to be initialized, and given the precondition, it guarantees that the idents in <post> are initialized. */ -type precond = BitV.t; /* 1 means "this variable must be initialized" +type precond = bitv::t; /* 1 means "this variable must be initialized" 0 means "don't care about this variable" */ -type postcond = BitV.t; /* 1 means "this variable is initialized" +type postcond = bitv::t; /* 1 means "this variable is initialized" 0 means "don't know about this variable */ -type prestate = BitV.t; /* 1 means "this variable is definitely initialized" +type prestate = bitv::t; /* 1 means "this variable is definitely initialized" 0 means "don't know whether this variable is initialized" */ -type poststate = BitV.t; /* 1 means "this variable is definitely initialized" +type poststate = bitv::t; /* 1 means "this variable is definitely initialized" 0 means "don't know whether this variable is initialized" */ @@ -29,7 +29,7 @@ type pre_and_post_state = rec(prestate prestate, poststate poststate); type ts_ann = rec(pre_and_post conditions, pre_and_post_state states); fn true_precond(uint num_vars) -> precond { - be BitV.create(num_vars, false); + be bitv::create(num_vars, false); } fn true_postcond(uint num_vars) -> postcond { @@ -45,7 +45,7 @@ fn empty_poststate(uint num_vars) -> poststate { } fn false_postcond(uint num_vars) -> postcond { - be BitV.create(num_vars, true); + be bitv::create(num_vars, true); } fn empty_pre_post(uint num_vars) -> pre_and_post { @@ -72,15 +72,15 @@ fn get_post(&pre_and_post p) -> postcond { } fn difference(&precond p1, &precond p2) -> bool { - be BitV.difference(p1, p2); + be bitv::difference(p1, p2); } fn union(&precond p1, &precond p2) -> bool { - be BitV.union(p1, p2); + be bitv::union(p1, p2); } fn intersect(&precond p1, &precond p2) -> bool { - be BitV.intersect(p1, p2); + be bitv::intersect(p1, p2); } fn pps_len(&pre_and_post p) -> uint { @@ -91,62 +91,62 @@ fn pps_len(&pre_and_post p) -> uint { fn require_and_preserve(uint i, &pre_and_post p) -> () { // sets the ith bit in p's pre and post - BitV.set(p.precondition, i, true); - BitV.set(p.postcondition, i, true); + bitv::set(p.precondition, i, true); + bitv::set(p.postcondition, i, true); } fn set_in_postcond(uint i, &pre_and_post p) -> bool { // sets the ith bit in p's post - auto was_set = BitV.get(p.postcondition, i); - BitV.set(p.postcondition, i, true); + auto was_set = bitv::get(p.postcondition, i); + bitv::set(p.postcondition, i, true); ret !was_set; } fn set_in_poststate(uint i, &pre_and_post_state s) -> bool { // sets the ith bit in p's post - auto was_set = BitV.get(s.poststate, i); - BitV.set(s.poststate, i, true); + auto was_set = bitv::get(s.poststate, i); + bitv::set(s.poststate, i, true); ret !was_set; } // Sets all the bits in a's precondition to equal the // corresponding bit in p's precondition. fn set_precondition(&ts_ann a, &precond p) -> () { - BitV.copy(a.conditions.precondition, p); + bitv::copy(a.conditions.precondition, p); } // Sets all the bits in a's postcondition to equal the // corresponding bit in p's postcondition. fn set_postcondition(&ts_ann a, &postcond p) -> () { - BitV.copy(a.conditions.postcondition, p); + bitv::copy(a.conditions.postcondition, p); } // Sets all the bits in a's prestate to equal the // corresponding bit in p's prestate. fn set_prestate(@ts_ann a, &prestate p) -> bool { - ret BitV.copy(a.states.prestate, p); + ret bitv::copy(a.states.prestate, p); } // Sets all the bits in a's postcondition to equal the // corresponding bit in p's postcondition. fn set_poststate(@ts_ann a, &poststate p) -> bool { - ret BitV.copy(a.states.poststate, p); + ret bitv::copy(a.states.poststate, p); } // Set all the bits in p that are set in new fn extend_prestate(&prestate p, &poststate new) -> bool { - ret BitV.union(p, new); + ret bitv::union(p, new); } // Set all the bits in p that are set in new fn extend_poststate(&poststate p, &poststate new) -> bool { - ret BitV.union(p, new); + ret bitv::union(p, new); } // Clears the given bit in p fn relax_prestate(uint i, &prestate p) -> bool { - auto was_set = BitV.get(p, i); - BitV.set(p, i, false); + auto was_set = bitv::get(p, i); + bitv::set(p, i, false); ret was_set; } @@ -164,16 +164,16 @@ fn pp_clone(&pre_and_post p) -> pre_and_post { } fn clone(prestate p) -> prestate { - ret BitV.clone(p); + ret bitv::clone(p); } // returns true if a implies b // that is, returns true except if for some bits c and d, // c = 1 and d = 0 -fn implies(BitV.t a, BitV.t b) -> bool { - auto tmp = BitV.clone(b); - BitV.difference(tmp, a); - ret BitV.is_false(tmp); +fn implies(bitv::t a, bitv::t b) -> bool { + auto tmp = bitv::clone(b); + bitv::difference(tmp, a); + ret bitv::is_false(tmp); } // |