2011-06-15 11:19:50 -07:00
|
|
|
|
2011-12-13 16:25:51 -08:00
|
|
|
import core::{int, uint};
|
2011-07-05 11:48:19 +02:00
|
|
|
import syntax::ast::*;
|
2011-08-21 21:44:41 -07:00
|
|
|
import syntax::ast_util::pat_binding_ids;
|
2011-07-26 16:47:13 +02:00
|
|
|
import syntax::visit;
|
2011-07-05 11:48:19 +02:00
|
|
|
import syntax::codemap::span;
|
2011-11-11 00:41:42 +08:00
|
|
|
import util::common::{log_stmt};
|
|
|
|
import aux::{num_constraints, get_fn_info, crate_ctxt, 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-09-12 11:27:30 +02:00
|
|
|
fn collect_ids_expr(e: @expr, rs: @mutable [node_id]) { *rs += [e.id]; }
|
2011-06-15 11:19:50 -07:00
|
|
|
|
2011-09-12 11:27:30 +02:00
|
|
|
fn collect_ids_block(b: blk, rs: @mutable [node_id]) { *rs += [b.node.id]; }
|
2011-05-14 19:02:30 -07:00
|
|
|
|
2011-09-12 11:27:30 +02: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) {
|
2011-12-22 17:53:53 -08:00
|
|
|
log(debug, "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) {
|
2011-12-22 17:53:53 -08:00
|
|
|
log(debug, "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-09-12 11:27:30 +02: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-12-20 11:03:21 -08:00
|
|
|
fn node_ids_in_fn(body: blk, 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-12-20 11:03:21 -08:00
|
|
|
collect_ids.visit_block(body, (), collect_ids);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-09-12 11:27:30 +02: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-12-22 17:53:53 -08:00
|
|
|
log(debug, 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-12-20 11:03:21 -08:00
|
|
|
fn visit_fn(ccx: crate_ctxt, num_constraints: uint, body: blk) {
|
2011-08-19 15:16:48 -07:00
|
|
|
let node_ids: @mutable [node_id] = @mutable [];
|
2011-12-20 11:03:21 -08:00
|
|
|
node_ids_in_fn(body, 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-12-29 20:07:55 -08:00
|
|
|
fn annotate_in_fn(ccx: crate_ctxt, _fk: visit::fn_kind, _decl: fn_decl,
|
|
|
|
body: blk, _sp: span, id: node_id) {
|
2011-07-27 14:19:39 +02:00
|
|
|
let f_info = get_fn_info(ccx, id);
|
2011-12-20 11:03:21 -08:00
|
|
|
visit_fn(ccx, num_constraints(f_info), body);
|
2011-05-14 19:02:30 -07:00
|
|
|
}
|
|
|
|
|
2011-09-12 11:27:30 +02:00
|
|
|
fn annotate_crate(ccx: crate_ctxt, crate: crate) {
|
2011-07-27 14:19:39 +02:00
|
|
|
let do_ann =
|
2011-12-20 11:03:21 -08:00
|
|
|
visit::mk_simple_visitor(
|
2011-12-29 20:07:55 -08:00
|
|
|
@{visit_fn: bind annotate_in_fn(ccx, _, _, _, _, _)
|
2011-12-20 11:03:21 -08:00
|
|
|
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
|
|
|
|
// End:
|
|
|
|
//
|