2011-06-15 11:19:50 -07:00
|
|
|
|
2011-05-17 20:41:41 +02:00
|
|
|
import std::vec;
|
2011-05-14 19:02:30 -07:00
|
|
|
import std::option;
|
|
|
|
import std::option::some;
|
|
|
|
import std::option::none;
|
2011-06-13 17:04:15 -07:00
|
|
|
import front::ast::*;
|
2011-06-19 22:41:21 +02:00
|
|
|
import util::common::istr;
|
2011-05-14 19:02:30 -07:00
|
|
|
import util::common::uistr;
|
|
|
|
import util::common::span;
|
|
|
|
import util::common::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-06-24 19:04:08 +02:00
|
|
|
fn collect_ids_expr(&@expr e, @mutable vec[node_id] rs) {
|
|
|
|
vec::push(*rs, e.id);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-06-24 19:04:08 +02:00
|
|
|
fn collect_ids_block(&block b, @mutable vec[node_id] rs) {
|
|
|
|
vec::push(*rs, b.node.id);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-06-24 19:04:08 +02:00
|
|
|
fn collect_ids_stmt(&@stmt s, @mutable vec[node_id] rs) {
|
2011-05-18 15:43:05 -07:00
|
|
|
alt (s.node) {
|
2011-06-19 22:41:21 +02:00
|
|
|
case (stmt_decl(_, ?id)) {
|
|
|
|
log "node_id " + istr(id);
|
2011-05-18 15:43:05 -07:00
|
|
|
log_stmt(*s);
|
2011-06-24 19:04:08 +02:00
|
|
|
vec::push(*rs, id);
|
2011-05-18 15:43:05 -07:00
|
|
|
}
|
2011-06-19 22:41:21 +02:00
|
|
|
case (stmt_expr(_, ?id)) {
|
|
|
|
log "node_id " + istr(id);
|
2011-05-18 15:43:05 -07:00
|
|
|
log_stmt(*s);
|
2011-06-24 19:04:08 +02:00
|
|
|
vec::push(*rs, id);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
2011-06-15 11:19:50 -07:00
|
|
|
case (_) { }
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 19:04:08 +02:00
|
|
|
fn collect_ids_local(&@local l, @mutable vec[node_id] rs) {
|
|
|
|
vec::push(*rs, l.node.id);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:18:41 -07:00
|
|
|
fn node_ids_in_fn(&_fn f, &vec[ty_param] tps, &span sp, &fn_ident i,
|
|
|
|
node_id id, @mutable vec[node_id] rs) {
|
2011-05-18 15:43:05 -07:00
|
|
|
auto collect_ids = walk::default_visitor();
|
2011-06-15 11:19:50 -07:00
|
|
|
collect_ids =
|
2011-06-24 19:04:08 +02:00
|
|
|
rec(visit_expr_pre=bind collect_ids_expr(_, rs),
|
|
|
|
visit_block_pre=bind collect_ids_block(_, rs),
|
|
|
|
visit_stmt_pre=bind collect_ids_stmt(_, rs),
|
|
|
|
visit_local_pre=bind collect_ids_local(_, rs) with collect_ids);
|
2011-06-30 00:18:41 -07:00
|
|
|
walk::walk_fn(collect_ids, f, tps, sp, i, id);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-06-19 22:41:21 +02:00
|
|
|
fn init_vecs(&crate_ctxt ccx, &vec[node_id] node_ids, uint len) {
|
|
|
|
for (node_id i in node_ids) {
|
|
|
|
log istr(i) + " |-> " + uistr(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-06-30 00:18:41 -07:00
|
|
|
fn visit_fn(&crate_ctxt ccx, uint num_constraints, &_fn f, &vec[ty_param] tps,
|
|
|
|
&span sp, &fn_ident i, node_id id) {
|
2011-06-19 22:41:21 +02:00
|
|
|
let @mutable vec[node_id] node_ids = @mutable [];
|
2011-06-30 00:18:41 -07:00
|
|
|
node_ids_in_fn(f, tps, sp, i, id, node_ids);
|
2011-06-10 16:39:09 +02:00
|
|
|
auto node_id_vec = *node_ids;
|
|
|
|
init_vecs(ccx, node_id_vec, num_constraints);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-06-30 00:18:41 -07:00
|
|
|
fn annotate_in_fn(&crate_ctxt ccx, &_fn f, &vec[ty_param] tps,
|
|
|
|
&span sp, &fn_ident i, node_id id) {
|
2011-06-19 22:41:21 +02:00
|
|
|
auto 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-06-15 11:19:50 -07:00
|
|
|
fn annotate_crate(&crate_ctxt ccx, &crate crate) {
|
2011-05-18 15:43:05 -07:00
|
|
|
auto do_ann = walk::default_visitor();
|
2011-06-15 11:19:50 -07:00
|
|
|
do_ann =
|
2011-06-30 00:18:41 -07:00
|
|
|
rec(visit_fn_pre=bind annotate_in_fn(ccx, _, _, _, _, _) with do_ann);
|
2011-05-18 15:43:05 -07:00
|
|
|
walk::walk_crate(do_ann, crate);
|
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:
|
|
|
|
//
|