2011-06-15 11:19:50 -07:00
|
|
|
|
2011-05-14 19:02:30 -07:00
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2011-07-06 16:46:17 +02:00
|
|
|
import std::int;
|
|
|
|
import std::uint;
|
2011-07-05 11:48:19 +02:00
|
|
|
import syntax::ast::*;
|
2011-07-26 16:47:13 +02:00
|
|
|
import syntax::visit;
|
2011-07-05 11:48:19 +02:00
|
|
|
import syntax::codemap::span;
|
2011-07-06 16:46:17 +02:00
|
|
|
import std::map::new_str_hash;
|
2011-05-18 15:43:05 -07:00
|
|
|
import util::common::log_expr_err;
|
|
|
|
import util::common::log_block_err;
|
|
|
|
import util::common::log_item_err;
|
|
|
|
import util::common::log_stmt_err;
|
|
|
|
import util::common::log_expr;
|
|
|
|
import util::common::log_block;
|
|
|
|
import util::common::log_stmt;
|
2011-05-20 16:53:24 -07:00
|
|
|
import aux::fn_info;
|
|
|
|
import aux::fn_info_map;
|
2011-06-01 18:10:10 -07:00
|
|
|
import aux::num_constraints;
|
2011-05-20 16:53:24 -07:00
|
|
|
import aux::get_fn_info;
|
|
|
|
import aux::crate_ctxt;
|
|
|
|
import aux::add_node;
|
2011-05-18 15:43:05 -07:00
|
|
|
import middle::tstate::ann::empty_ann;
|
2011-05-14 19:02:30 -07:00
|
|
|
|
2011-08-19 15:16:48 -07:00
|
|
|
fn collect_ids_expr(e: &@expr, rs: @mutable [node_id]) { *rs += [e.id]; }
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-08-19 15:16:48 -07:00
|
|
|
fn collect_ids_block(b: &blk, rs: @mutable [node_id]) { *rs += [b.node.id]; }
|
2011-05-14 19:02:30 -07:00
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) {
|
2011-07-27 14:19:39 +02:00
|
|
|
alt s.node {
|
|
|
|
stmt_decl(_, id) {
|
|
|
|
log "node_id " + int::str(id);
|
2011-08-19 15:16:48 -07:00
|
|
|
log_stmt(*s);;
|
|
|
|
*rs += [id];
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
|
|
|
stmt_expr(_, id) {
|
|
|
|
log "node_id " + int::str(id);
|
2011-08-19 15:16:48 -07:00
|
|
|
log_stmt(*s);;
|
|
|
|
*rs += [id];
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
|
|
|
_ { }
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
fn collect_ids_local(l: &@local, rs: @mutable [node_id]) {
|
2011-08-03 10:19:36 +02:00
|
|
|
*rs += pat_binding_ids(l.node.pat);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
fn node_ids_in_fn(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident,
|
|
|
|
id: node_id, rs: @mutable [node_id]) {
|
2011-07-27 14:19:39 +02:00
|
|
|
let collect_ids =
|
|
|
|
visit::mk_simple_visitor(@{visit_expr: bind collect_ids_expr(_, rs),
|
|
|
|
visit_block: bind collect_ids_block(_, rs),
|
|
|
|
visit_stmt: bind collect_ids_stmt(_, rs),
|
|
|
|
visit_local: bind collect_ids_local(_, rs)
|
|
|
|
with *visit::default_simple_visitor()});
|
2011-07-26 16:47:13 +02:00
|
|
|
visit::visit_fn(f, tps, sp, i, id, (), collect_ids);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
fn init_vecs(ccx: &crate_ctxt, node_ids: &[node_id], len: uint) {
|
2011-08-15 21:54:52 -07:00
|
|
|
for i: node_id in node_ids {
|
2011-07-06 16:46:17 +02:00
|
|
|
log int::str(i) + " |-> " + uint::str(len);
|
2011-05-20 16:53:24 -07:00
|
|
|
add_node(ccx, i, empty_ann(len));
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn visit_fn(ccx: &crate_ctxt, num_constraints: uint, f: &_fn,
|
2011-08-04 16:20:09 -07:00
|
|
|
tps: &[ty_param], sp: &span, i: &fn_ident, id: node_id) {
|
2011-08-19 15:16:48 -07:00
|
|
|
let node_ids: @mutable [node_id] = @mutable [];
|
2011-06-30 00:18:41 -07:00
|
|
|
node_ids_in_fn(f, tps, sp, i, id, node_ids);
|
2011-07-27 14:19:39 +02:00
|
|
|
let node_id_vec = *node_ids;
|
2011-06-10 16:39:09 +02:00
|
|
|
init_vecs(ccx, node_id_vec, num_constraints);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-08-04 16:20:09 -07:00
|
|
|
fn annotate_in_fn(ccx: &crate_ctxt, f: &_fn, tps: &[ty_param], sp: &span,
|
2011-07-27 14:19:39 +02:00
|
|
|
i: &fn_ident, id: node_id) {
|
|
|
|
let f_info = get_fn_info(ccx, id);
|
2011-06-30 00:18:41 -07:00
|
|
|
visit_fn(ccx, num_constraints(f_info), f, tps, sp, i, id);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-07-27 14:19:39 +02:00
|
|
|
fn annotate_crate(ccx: &crate_ctxt, crate: &crate) {
|
|
|
|
let do_ann =
|
|
|
|
visit::mk_simple_visitor(@{visit_fn:
|
|
|
|
bind annotate_in_fn(ccx, _, _, _, _, _)
|
|
|
|
with *visit::default_simple_visitor()});
|
2011-07-26 16:47:13 +02:00
|
|
|
visit::visit_crate(crate, (), do_ann);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
2011-05-18 15:43:05 -07:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|