Get rid of def_ids and anns in AST nodes, use single node_id
This reduces some redundancy in the AST data structures and cruft in the code that works with them. To get a def_id from a node_id, apply ast::local_def, which adds the local crate_num to the given node_id. Most code only deals with crate-local node_ids, and won't have to create def_ids at all.
This commit is contained in:
parent
3d8a5cb9e6
commit
75681f9ad7
25 changed files with 1537 additions and 1472 deletions
|
@ -76,8 +76,7 @@ fn time[T](bool do_it, str what, fn() -> T thunk) -> T {
|
|||
fn compile_input(session::session sess, eval::env env, str input,
|
||||
str output) {
|
||||
auto time_passes = sess.get_opts().time_passes;
|
||||
auto def = tup(ast::local_crate, 0);
|
||||
auto p = parser::new_parser(sess, env, def, input, 0u, 0u);
|
||||
auto p = parser::new_parser(sess, env, input, 0u, 0);
|
||||
auto crate =
|
||||
time(time_passes, "parsing", bind parse_input(sess, p, input));
|
||||
if (sess.get_opts().output_type == link::output_type_none) { ret; }
|
||||
|
@ -103,8 +102,7 @@ fn compile_input(session::session sess, eval::env env, str input,
|
|||
|
||||
fn pretty_print_input(session::session sess, eval::env env, str input,
|
||||
pp_mode ppm) {
|
||||
auto def = tup(ast::local_crate, 0);
|
||||
auto p = front::parser::new_parser(sess, env, def, input, 0u, 0u);
|
||||
auto p = front::parser::new_parser(sess, env, input, 0u, 0);
|
||||
auto crate = parse_input(sess, p, input);
|
||||
auto mode;
|
||||
alt (ppm) {
|
||||
|
|
|
@ -16,17 +16,16 @@ type path = spanned[path_];
|
|||
fn path_name(&path p) -> str { ret str::connect(p.node.idents, "::"); }
|
||||
|
||||
type crate_num = int;
|
||||
type node_id = int;
|
||||
type def_id = tup(crate_num, node_id);
|
||||
|
||||
const crate_num local_crate = 0;
|
||||
|
||||
type def_num = int;
|
||||
|
||||
type def_id = tup(crate_num, def_num);
|
||||
fn local_def(node_id id) -> def_id {
|
||||
ret tup(local_crate, id);
|
||||
}
|
||||
|
||||
type ty_param = ident;
|
||||
|
||||
type ann = rec(uint id);
|
||||
|
||||
tag def {
|
||||
def_fn(def_id);
|
||||
def_obj(def_id);
|
||||
|
@ -102,15 +101,15 @@ type meta_item_ = rec(ident key, str value);
|
|||
|
||||
type block = spanned[block_];
|
||||
|
||||
type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, ann a);
|
||||
type block_ = rec(vec[@stmt] stmts, option::t[@expr] expr, node_id id);
|
||||
|
||||
type pat = spanned[pat_];
|
||||
|
||||
tag pat_ {
|
||||
pat_wild(ann);
|
||||
pat_bind(ident, def_id, ann);
|
||||
pat_lit(@lit, ann);
|
||||
pat_tag(path, vec[@pat], ann);
|
||||
pat_wild(node_id);
|
||||
pat_bind(ident, node_id);
|
||||
pat_lit(@lit, node_id);
|
||||
pat_tag(path, vec[@pat], node_id);
|
||||
}
|
||||
|
||||
tag mutability { mut; imm; maybe_mut; }
|
||||
|
@ -183,8 +182,8 @@ tag mode { val; alias(bool); }
|
|||
type stmt = spanned[stmt_];
|
||||
|
||||
tag stmt_ {
|
||||
stmt_decl(@decl, ann);
|
||||
stmt_expr(@expr, ann);
|
||||
stmt_decl(@decl, node_id);
|
||||
stmt_expr(@expr, node_id);
|
||||
|
||||
// These only exist in crate-level blocks.
|
||||
stmt_crate_directive(@crate_directive);
|
||||
|
@ -199,8 +198,7 @@ type local_ =
|
|||
bool infer,
|
||||
ident ident,
|
||||
option::t[initializer] init,
|
||||
def_id id,
|
||||
ann ann);
|
||||
node_id id);
|
||||
|
||||
type local = spanned[local_];
|
||||
|
||||
|
@ -225,58 +223,58 @@ tag seq_kind { sk_unique; sk_rc; }
|
|||
type expr = spanned[expr_];
|
||||
|
||||
tag expr_ {
|
||||
expr_vec(vec[@expr], mutability, seq_kind, ann);
|
||||
expr_tup(vec[elt], ann);
|
||||
expr_rec(vec[field], option::t[@expr], ann);
|
||||
expr_call(@expr, vec[@expr], ann);
|
||||
expr_self_method(ident, ann);
|
||||
expr_bind(@expr, vec[option::t[@expr]], ann);
|
||||
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], ann);
|
||||
expr_binary(binop, @expr, @expr, ann);
|
||||
expr_unary(unop, @expr, ann);
|
||||
expr_lit(@lit, ann);
|
||||
expr_cast(@expr, @ty, ann);
|
||||
expr_if(@expr, block, option::t[@expr], ann);
|
||||
expr_while(@expr, block, ann);
|
||||
expr_for(@local, @expr, block, ann);
|
||||
expr_for_each(@local, @expr, block, ann);
|
||||
expr_do_while(block, @expr, ann);
|
||||
expr_alt(@expr, vec[arm], ann);
|
||||
expr_fn(_fn, ann);
|
||||
expr_block(block, ann);
|
||||
expr_vec(vec[@expr], mutability, seq_kind, node_id);
|
||||
expr_tup(vec[elt], node_id);
|
||||
expr_rec(vec[field], option::t[@expr], node_id);
|
||||
expr_call(@expr, vec[@expr], node_id);
|
||||
expr_self_method(ident, node_id);
|
||||
expr_bind(@expr, vec[option::t[@expr]], node_id);
|
||||
expr_spawn(spawn_dom, option::t[str], @expr, vec[@expr], node_id);
|
||||
expr_binary(binop, @expr, @expr, node_id);
|
||||
expr_unary(unop, @expr, node_id);
|
||||
expr_lit(@lit, node_id);
|
||||
expr_cast(@expr, @ty, node_id);
|
||||
expr_if(@expr, block, option::t[@expr], node_id);
|
||||
expr_while(@expr, block, node_id);
|
||||
expr_for(@local, @expr, block, node_id);
|
||||
expr_for_each(@local, @expr, block, node_id);
|
||||
expr_do_while(block, @expr, node_id);
|
||||
expr_alt(@expr, vec[arm], node_id);
|
||||
expr_fn(_fn, node_id);
|
||||
expr_block(block, node_id);
|
||||
/*
|
||||
* FIXME: many of these @exprs should be constrained with
|
||||
* is_lval once we have constrained types working.
|
||||
*/
|
||||
expr_move(@expr, @expr, ann);
|
||||
expr_assign(@expr,@expr, ann);
|
||||
expr_swap(@expr, @expr, ann);
|
||||
expr_assign_op(binop, @expr, @expr, ann);
|
||||
expr_send(@expr, @expr, ann);
|
||||
expr_recv(@expr, @expr, ann);
|
||||
expr_field(@expr, ident, ann);
|
||||
expr_index(@expr, @expr, ann);
|
||||
expr_path(path, ann);
|
||||
expr_ext(path, vec[@expr], option::t[str], @expr, ann);
|
||||
expr_fail(ann, option::t[str]);
|
||||
expr_break(ann);
|
||||
expr_cont(ann);
|
||||
expr_ret(option::t[@expr], ann);
|
||||
expr_put(option::t[@expr], ann);
|
||||
expr_be(@expr, ann);
|
||||
expr_log(int, @expr, ann);
|
||||
expr_move(@expr, @expr, node_id);
|
||||
expr_assign(@expr,@expr, node_id);
|
||||
expr_swap(@expr, @expr, node_id);
|
||||
expr_assign_op(binop, @expr, @expr, node_id);
|
||||
expr_send(@expr, @expr, node_id);
|
||||
expr_recv(@expr, @expr, node_id);
|
||||
expr_field(@expr, ident, node_id);
|
||||
expr_index(@expr, @expr, node_id);
|
||||
expr_path(path, node_id);
|
||||
expr_ext(path, vec[@expr], option::t[str], @expr, node_id);
|
||||
expr_fail(node_id, option::t[str]);
|
||||
expr_break(node_id);
|
||||
expr_cont(node_id);
|
||||
expr_ret(option::t[@expr], node_id);
|
||||
expr_put(option::t[@expr], node_id);
|
||||
expr_be(@expr, node_id);
|
||||
expr_log(int, @expr, node_id);
|
||||
|
||||
/* just an assert, no significance to typestate */
|
||||
expr_assert(@expr, ann);
|
||||
expr_assert(@expr, node_id);
|
||||
|
||||
/* preds that typestate is aware of */
|
||||
expr_check(@expr, ann);
|
||||
expr_check(@expr, node_id);
|
||||
/* FIXME Would be nice if expr_check desugared
|
||||
to expr_if_check. */
|
||||
expr_if_check(@expr, block, option::t[@expr], ann);
|
||||
expr_port(ann);
|
||||
expr_chan(@expr, ann);
|
||||
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, ann);
|
||||
expr_if_check(@expr, block, option::t[@expr], node_id);
|
||||
expr_port(node_id);
|
||||
expr_chan(@expr, node_id);
|
||||
expr_anon_obj(anon_obj, vec[ty_param], obj_def_ids, node_id);
|
||||
}
|
||||
|
||||
type lit = spanned[lit_];
|
||||
|
@ -348,7 +346,7 @@ tag ty_ {
|
|||
ty_rec(vec[ty_field]);
|
||||
ty_fn(proto, vec[ty_arg], @ty, controlflow, vec[@constr]);
|
||||
ty_obj(vec[ty_method]);
|
||||
ty_path(path, ann);
|
||||
ty_path(path, node_id);
|
||||
ty_type;
|
||||
ty_constr(@ty, vec[@constr]);
|
||||
}
|
||||
|
@ -368,7 +366,9 @@ type constr_arg = constr_arg_general[uint];
|
|||
|
||||
type constr_arg_general[T] = spanned[constr_arg_general_[T]];
|
||||
|
||||
type constr_ = rec(path path, vec[@constr_arg_general[uint]] args, ann ann);
|
||||
type constr_ = rec(path path,
|
||||
vec[@constr_arg_general[uint]] args,
|
||||
node_id id);
|
||||
|
||||
type constr = spanned[constr_];
|
||||
|
||||
|
@ -376,7 +376,7 @@ type constr = spanned[constr_];
|
|||
/* The parser generates ast::constrs; resolve generates
|
||||
a mapping from each function to a list of ty::constr_defs,
|
||||
corresponding to these. */
|
||||
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
|
||||
type arg = rec(mode mode, @ty ty, ident ident, node_id id);
|
||||
|
||||
type fn_decl =
|
||||
rec(vec[arg] inputs,
|
||||
|
@ -402,11 +402,11 @@ tag controlflow {
|
|||
|
||||
type _fn = rec(fn_decl decl, proto proto, block body);
|
||||
|
||||
type method_ = rec(ident ident, _fn meth, def_id id, ann ann);
|
||||
type method_ = rec(ident ident, _fn meth, node_id id);
|
||||
|
||||
type method = spanned[method_];
|
||||
|
||||
type obj_field = rec(mutability mut, @ty ty, ident ident, def_id id, ann ann);
|
||||
type obj_field = rec(mutability mut, @ty ty, ident ident, node_id id);
|
||||
|
||||
type _obj =
|
||||
rec(vec[obj_field] fields, vec[@method] methods, option::t[@method] dtor);
|
||||
|
@ -435,22 +435,22 @@ type native_mod =
|
|||
vec[@view_item] view_items,
|
||||
vec[@native_item] items);
|
||||
|
||||
type variant_arg = rec(@ty ty, def_id id);
|
||||
type variant_arg = rec(@ty ty, node_id id);
|
||||
|
||||
type variant_ = rec(str name, vec[variant_arg] args, def_id id, ann ann);
|
||||
type variant_ = rec(str name, vec[variant_arg] args, node_id id);
|
||||
|
||||
type variant = spanned[variant_];
|
||||
|
||||
type view_item = spanned[view_item_];
|
||||
|
||||
tag view_item_ {
|
||||
view_item_use(ident, vec[@meta_item], def_id, ann);
|
||||
view_item_import(ident, vec[ident], def_id);
|
||||
view_item_import_glob(vec[ident], def_id);
|
||||
view_item_export(ident);
|
||||
view_item_use(ident, vec[@meta_item], node_id);
|
||||
view_item_import(ident, vec[ident], node_id);
|
||||
view_item_import_glob(vec[ident], node_id);
|
||||
view_item_export(ident, node_id);
|
||||
}
|
||||
|
||||
type obj_def_ids = rec(def_id ty, def_id ctor);
|
||||
type obj_def_ids = rec(node_id ty, node_id ctor);
|
||||
|
||||
|
||||
// Meta-data associated with an item
|
||||
|
@ -464,12 +464,9 @@ tag attr_style { attr_outer; attr_inner; }
|
|||
|
||||
type attribute_ = rec(attr_style style, meta_item value);
|
||||
|
||||
type item =
|
||||
rec(ident ident,
|
||||
type item = rec(ident ident,
|
||||
vec[attribute] attrs,
|
||||
def_id id, // For objs, this is the type def_id
|
||||
|
||||
ann ann,
|
||||
node_id id, // For objs, this is the type's def_id
|
||||
item_ node,
|
||||
span span);
|
||||
|
||||
|
@ -480,21 +477,18 @@ tag item_ {
|
|||
item_native_mod(native_mod);
|
||||
item_ty(@ty, vec[ty_param]);
|
||||
item_tag(vec[variant], vec[ty_param]);
|
||||
item_obj(_obj, vec[ty_param], def_id);
|
||||
/* constructor id */
|
||||
|
||||
item_obj(_obj, vec[ty_param], node_id /* constructor id */);
|
||||
}
|
||||
|
||||
type native_item = spanned[native_item_];
|
||||
|
||||
tag native_item_ {
|
||||
native_item_ty(ident, def_id);
|
||||
native_item_ty(ident, node_id);
|
||||
native_item_fn(ident,
|
||||
option::t[str],
|
||||
fn_decl,
|
||||
vec[ty_param],
|
||||
def_id,
|
||||
ann);
|
||||
node_id);
|
||||
}
|
||||
|
||||
fn is_exported(ident i, _mod m) -> bool {
|
||||
|
@ -514,7 +508,7 @@ fn is_exported(ident i, _mod m) -> bool {
|
|||
auto count = 0u;
|
||||
for (@ast::view_item vi in m.view_items) {
|
||||
alt (vi.node) {
|
||||
case (ast::view_item_export(?id)) {
|
||||
case (ast::view_item_export(?id, _)) {
|
||||
if (str::eq(i, id)) {
|
||||
// even if it's nonlocal (since it's explicit)
|
||||
|
||||
|
|
|
@ -359,8 +359,8 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id {
|
|||
auto crate_part = vec::slice[u8](buf, 0u, colon_idx);
|
||||
auto def_part = vec::slice[u8](buf, colon_idx + 1u, len);
|
||||
auto crate_num = uint::parse_buf(crate_part, 10u) as int;
|
||||
auto def_num = uint::parse_buf(def_part, 10u) as int;
|
||||
ret tup(crate_num, def_num);
|
||||
auto def_id = uint::parse_buf(def_part, 10u) as int;
|
||||
ret tup(crate_num, def_id);
|
||||
}
|
||||
|
||||
fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash) ->
|
||||
|
@ -407,7 +407,7 @@ fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
|
|||
ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
|
||||
}
|
||||
auto eqer = bind eq_item(_, item_id);
|
||||
auto found = lookup_hash(items, eqer, metadata::hash_def_num(item_id));
|
||||
auto found = lookup_hash(items, eqer, metadata::hash_def_id(item_id));
|
||||
if (vec::len(found) == 0u) {
|
||||
ret option::none[ebml::doc];
|
||||
} else { ret option::some[ebml::doc](found.(0)); }
|
||||
|
@ -606,7 +606,7 @@ type env =
|
|||
|
||||
fn visit_view_item(env e, &@ast::view_item i) {
|
||||
alt (i.node) {
|
||||
case (ast::view_item_use(?ident, ?meta_items, ?id, ?ann)) {
|
||||
case (ast::view_item_use(?ident, ?meta_items, ?id)) {
|
||||
auto cnum;
|
||||
if (!e.crate_cache.contains_key(ident)) {
|
||||
cnum = e.next_crate_num;
|
||||
|
@ -615,7 +615,7 @@ fn visit_view_item(env e, &@ast::view_item i) {
|
|||
e.crate_cache.insert(ident, e.next_crate_num);
|
||||
e.next_crate_num += 1;
|
||||
} else { cnum = e.crate_cache.get(ident); }
|
||||
e.crate_map.insert(ann.id, cnum);
|
||||
e.crate_map.insert(id, cnum);
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ type ctx =
|
|||
mutable vec[str] deps,
|
||||
session::session sess,
|
||||
mutable uint chpos,
|
||||
mutable uint next_ann);
|
||||
mutable int next_id);
|
||||
|
||||
fn mk_env() -> env { ret []; }
|
||||
|
||||
|
@ -287,23 +287,18 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix,
|
|||
}
|
||||
auto full_path = prefix + std::fs::path_sep() + file_path;
|
||||
if (cx.mode == mode_depend) { cx.deps += [full_path]; ret; }
|
||||
auto start_id = cx.p.next_def_id();
|
||||
auto p0 =
|
||||
new_parser(cx.sess, e, start_id, full_path, cx.chpos,
|
||||
cx.next_ann);
|
||||
new_parser(cx.sess, e, full_path, cx.chpos,
|
||||
cx.next_id);
|
||||
auto inner_attrs = parse_inner_attrs_and_next(p0);
|
||||
auto first_item_outer_attrs = inner_attrs._1;
|
||||
auto m0 = parse_mod_items(p0, token::EOF,
|
||||
first_item_outer_attrs);
|
||||
auto next_id = p0.next_def_id();
|
||||
// Thread defids and chpos through the parsers
|
||||
auto m0 = parse_mod_items(p0, token::EOF, first_item_outer_attrs);
|
||||
|
||||
cx.p.set_def(next_id._1);
|
||||
auto i = front::parser::mk_item(p0, cdir.span.lo, cdir.span.hi,
|
||||
id, ast::item_mod(m0), []);
|
||||
// Thread defids and chpos through the parsers
|
||||
cx.chpos = p0.get_chpos();
|
||||
cx.next_ann = p0.next_ann_num();
|
||||
auto i = front::parser::mk_item(cx.p, cdir.span.lo, cdir.span.hi,
|
||||
id, ast::item_mod(m0),
|
||||
inner_attrs._0);
|
||||
cx.next_id = p0.next_id();
|
||||
vec::push[@ast::item](items, i);
|
||||
}
|
||||
case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs)) {
|
||||
|
@ -311,9 +306,12 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix,
|
|||
alt (dir_opt) { case (some(?d)) { path = d; } case (none) { } }
|
||||
auto full_path = prefix + std::fs::path_sep() + path;
|
||||
auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path);
|
||||
auto i =
|
||||
front::parser::mk_item(cx.p, cdir.span.lo, cdir.span.hi, id,
|
||||
ast::item_mod(m0), []);
|
||||
auto i = @rec(ident=id,
|
||||
attrs=[],
|
||||
id=cx.next_id,
|
||||
node=ast::item_mod(m0),
|
||||
span=cdir.span);
|
||||
cx.next_id += 1;
|
||||
vec::push[@ast::item](items, i);
|
||||
}
|
||||
case (ast::cdir_view_item(?vi)) {
|
||||
|
|
|
@ -25,7 +25,7 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
|
|||
|
||||
type span_msg_fn = fn(span, str) -> ! ;
|
||||
|
||||
type next_ann_fn = fn() -> ast::ann ;
|
||||
type next_id_fn = fn() -> ast::node_id ;
|
||||
|
||||
|
||||
// Provides a limited set of services necessary for syntax extensions
|
||||
|
@ -33,7 +33,7 @@ type next_ann_fn = fn() -> ast::ann ;
|
|||
type ext_ctxt =
|
||||
rec(span_msg_fn span_fatal,
|
||||
span_msg_fn span_unimpl,
|
||||
next_ann_fn next_ann);
|
||||
next_id_fn next_id);
|
||||
|
||||
fn mk_ctxt(parser parser) -> ext_ctxt {
|
||||
auto sess = parser.get_session();
|
||||
|
@ -45,11 +45,11 @@ fn mk_ctxt(parser parser) -> ext_ctxt {
|
|||
sess.span_unimpl(sp, msg);
|
||||
}
|
||||
auto ext_span_unimpl = bind ext_span_unimpl_(sess, _, _);
|
||||
fn ext_next_ann_(parser parser) -> ast::ann { parser.get_ann() }
|
||||
auto ext_next_ann = bind ext_next_ann_(parser);
|
||||
fn ext_next_id_(parser parser) -> ast::node_id { parser.get_id() }
|
||||
auto ext_next_id = bind ext_next_id_(parser);
|
||||
ret rec(span_fatal=ext_span_fatal,
|
||||
span_unimpl=ext_span_unimpl,
|
||||
next_ann=ext_next_ann);
|
||||
next_id=ext_next_id);
|
||||
}
|
||||
//
|
||||
// Local Variables:
|
||||
|
|
|
@ -44,7 +44,7 @@ fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str {
|
|||
|
||||
fn make_new_lit(&ext_ctxt cx, common::span sp, ast::lit_ lit) -> @ast::expr {
|
||||
auto sp_lit = @rec(node=lit, span=sp);
|
||||
auto expr = ast::expr_lit(sp_lit, cx.next_ann());
|
||||
auto expr = ast::expr_lit(sp_lit, cx.next_id());
|
||||
ret @rec(node=expr, span=sp);
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
fn make_new_lit(&ext_ctxt cx, common::span sp, ast::lit_ lit) ->
|
||||
@ast::expr {
|
||||
auto sp_lit = @rec(node=lit, span=sp);
|
||||
auto expr = ast::expr_lit(sp_lit, cx.next_ann());
|
||||
auto expr = ast::expr_lit(sp_lit, cx.next_id());
|
||||
ret @rec(node=expr, span=sp);
|
||||
}
|
||||
fn make_new_str(&ext_ctxt cx, common::span sp, str s) -> @ast::expr {
|
||||
|
@ -73,7 +73,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
}
|
||||
fn make_add_expr(&ext_ctxt cx, common::span sp, @ast::expr lhs,
|
||||
@ast::expr rhs) -> @ast::expr {
|
||||
auto binexpr = ast::expr_binary(ast::add, lhs, rhs, cx.next_ann());
|
||||
auto binexpr = ast::expr_binary(ast::add, lhs, rhs, cx.next_id());
|
||||
ret @rec(node=binexpr, span=sp);
|
||||
}
|
||||
fn make_path_expr(&ext_ctxt cx, common::span sp, vec[ast::ident] idents)
|
||||
|
@ -81,21 +81,21 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
let vec[@ast::ty] types = [];
|
||||
auto path = rec(idents=idents, types=types);
|
||||
auto sp_path = rec(node=path, span=sp);
|
||||
auto pathexpr = ast::expr_path(sp_path, cx.next_ann());
|
||||
auto pathexpr = ast::expr_path(sp_path, cx.next_id());
|
||||
auto sp_pathexpr = @rec(node=pathexpr, span=sp);
|
||||
ret sp_pathexpr;
|
||||
}
|
||||
fn make_vec_expr(&ext_ctxt cx, common::span sp, vec[@ast::expr] exprs) ->
|
||||
@ast::expr {
|
||||
auto vecexpr =
|
||||
ast::expr_vec(exprs, ast::imm, ast::sk_rc, cx.next_ann());
|
||||
ast::expr_vec(exprs, ast::imm, ast::sk_rc, cx.next_id());
|
||||
auto sp_vecexpr = @rec(node=vecexpr, span=sp);
|
||||
ret sp_vecexpr;
|
||||
}
|
||||
fn make_call(&ext_ctxt cx, common::span sp, vec[ast::ident] fn_path,
|
||||
vec[@ast::expr] args) -> @ast::expr {
|
||||
auto pathexpr = make_path_expr(cx, sp, fn_path);
|
||||
auto callexpr = ast::expr_call(pathexpr, args, cx.next_ann());
|
||||
auto callexpr = ast::expr_call(pathexpr, args, cx.next_id());
|
||||
auto sp_callexpr = @rec(node=callexpr, span=sp);
|
||||
ret sp_callexpr;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
|
|||
astfields += [astfield];
|
||||
}
|
||||
auto recexpr =
|
||||
ast::expr_rec(astfields, option::none[@ast::expr], cx.next_ann());
|
||||
ast::expr_rec(astfields, option::none[@ast::expr], cx.next_id());
|
||||
auto sp_recexpr = @rec(node=recexpr, span=sp);
|
||||
ret sp_recexpr;
|
||||
}
|
||||
|
|
|
@ -38,8 +38,6 @@ type parser =
|
|||
fn get_lo_pos() -> uint ;
|
||||
fn get_hi_pos() -> uint ;
|
||||
fn get_last_lo_pos() -> uint ;
|
||||
fn next_def_id() -> ast::def_id ;
|
||||
fn set_def(ast::def_num) ;
|
||||
fn get_prec_table() -> vec[op_spec] ;
|
||||
fn get_str(token::str_num) -> str ;
|
||||
fn get_reader() -> lexer::reader ;
|
||||
|
@ -47,12 +45,12 @@ type parser =
|
|||
fn get_bad_expr_words() -> hashmap[str, ()] ;
|
||||
fn get_syntax_expanders() -> hashmap[str, ext::syntax_extension] ;
|
||||
fn get_chpos() -> uint ;
|
||||
fn get_ann() -> ast::ann ;
|
||||
fn next_ann_num() -> uint ;
|
||||
fn get_id() -> ast::node_id ;
|
||||
fn next_id() -> ast::node_id ;
|
||||
};
|
||||
|
||||
fn new_parser(session::session sess, eval::env env, ast::def_id initial_def,
|
||||
str path, uint pos, uint next_ann) -> parser {
|
||||
fn new_parser(session::session sess, eval::env env,
|
||||
str path, uint pos, ast::node_id next_id) -> parser {
|
||||
obj stdio_parser(session::session sess,
|
||||
eval::env env,
|
||||
file_type ftype,
|
||||
|
@ -60,12 +58,10 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def,
|
|||
mutable uint lo,
|
||||
mutable uint hi,
|
||||
mutable uint last_lo,
|
||||
mutable ast::def_num def,
|
||||
mutable restriction res,
|
||||
ast::crate_num crate,
|
||||
lexer::reader rdr,
|
||||
vec[op_spec] precs,
|
||||
mutable uint next_ann_var,
|
||||
mutable ast::node_id next_id_var,
|
||||
hashmap[str, ()] bad_words,
|
||||
hashmap[str, ext::syntax_extension] syntax_expanders) {
|
||||
fn peek() -> token::token { ret tok; }
|
||||
|
@ -86,8 +82,6 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def,
|
|||
fn get_lo_pos() -> uint { ret lo; }
|
||||
fn get_hi_pos() -> uint { ret hi; }
|
||||
fn get_last_lo_pos() -> uint { ret last_lo; }
|
||||
fn next_def_id() -> ast::def_id { def += 1; ret tup(crate, def); }
|
||||
fn set_def(ast::def_num d) { def = d; }
|
||||
fn get_file_type() -> file_type { ret ftype; }
|
||||
fn get_env() -> eval::env { ret env; }
|
||||
fn get_prec_table() -> vec[op_spec] { ret precs; }
|
||||
|
@ -101,12 +95,12 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def,
|
|||
ret syntax_expanders;
|
||||
}
|
||||
fn get_chpos() -> uint { ret rdr.get_chpos(); }
|
||||
fn get_ann() -> ast::ann {
|
||||
auto rv = rec(id=next_ann_var);
|
||||
next_ann_var += 1u;
|
||||
fn get_id() -> ast::node_id {
|
||||
auto rv = next_id_var;
|
||||
next_id_var += 1;
|
||||
ret rv;
|
||||
}
|
||||
fn next_ann_num() -> uint { ret next_ann_var; }
|
||||
fn next_id() -> ast::node_id { ret next_id_var; }
|
||||
}
|
||||
auto ftype = SOURCE_FILE;
|
||||
if (str::ends_with(path, ".rc")) { ftype = CRATE_FILE; }
|
||||
|
@ -120,8 +114,8 @@ fn new_parser(session::session sess, eval::env env, ast::def_id initial_def,
|
|||
lexer::consume_whitespace_and_comments(rdr);
|
||||
auto npos = rdr.get_chpos();
|
||||
ret stdio_parser(sess, env, ftype, lexer::next_token(rdr), npos, npos,
|
||||
npos, initial_def._1, UNRESTRICTED, initial_def._0, rdr,
|
||||
prec_table(), next_ann, bad_expr_word_table(),
|
||||
npos, UNRESTRICTED, rdr,
|
||||
prec_table(), next_id, bad_expr_word_table(),
|
||||
ext::syntax_expander_table());
|
||||
}
|
||||
|
||||
|
@ -378,7 +372,7 @@ fn parse_ty_constr(&vec[ast::arg] fn_args, &parser p) -> @ast::constr {
|
|||
// FIXME fix the def_id
|
||||
|
||||
ret @spanned(lo, args.span.hi,
|
||||
rec(path=path, args=args.node, ann=p.get_ann()));
|
||||
rec(path=path, args=args.node, id=p.get_id()));
|
||||
}
|
||||
|
||||
|
||||
|
@ -576,7 +570,7 @@ fn parse_ty(&parser p) -> @ast::ty {
|
|||
hi = typ.span.hi;
|
||||
} else if (is_ident(p.peek())) {
|
||||
auto path = parse_path(p);
|
||||
t = ast::ty_path(path, p.get_ann());
|
||||
t = ast::ty_path(path, p.get_id());
|
||||
hi = path.span.hi;
|
||||
} else { p.err("expecting type"); t = ast::ty_nil; fail; }
|
||||
ret parse_ty_postfix(@spanned(lo, hi, t), p);
|
||||
|
@ -590,7 +584,7 @@ fn parse_arg(&parser p) -> ast::arg {
|
|||
}
|
||||
let @ast::ty t = parse_ty(p);
|
||||
let ast::ident i = parse_value_ident(p);
|
||||
ret rec(mode=m, ty=t, ident=i, id=p.next_def_id());
|
||||
ret rec(mode=m, ty=t, ident=i, id=p.get_id());
|
||||
}
|
||||
|
||||
fn parse_seq_to_end[T](token::token ket, option::t[token::token] sep,
|
||||
|
@ -714,7 +708,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
// alt-exhaustive-match checking are co-operating.
|
||||
|
||||
auto lit = @spanned(lo, hi, ast::lit_nil);
|
||||
let ast::expr_ ex = ast::expr_lit(lit, p.get_ann());
|
||||
let ast::expr_ ex = ast::expr_lit(lit, p.get_id());
|
||||
if (p.peek() == token::LPAREN) {
|
||||
p.bump();
|
||||
alt (p.peek()) {
|
||||
|
@ -722,7 +716,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto lit = @spanned(lo, hi, ast::lit_nil);
|
||||
ret @spanned(lo, hi, ast::expr_lit(lit, p.get_ann()));
|
||||
ret @spanned(lo, hi, ast::expr_lit(lit, p.get_id()));
|
||||
}
|
||||
case (_) {/* fall through */ }
|
||||
}
|
||||
|
@ -733,7 +727,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
} else if (p.peek() == token::LBRACE) {
|
||||
auto blk = parse_block(p);
|
||||
ret @spanned(blk.span.lo, blk.span.hi,
|
||||
ast::expr_block(blk, p.get_ann()));
|
||||
ast::expr_block(blk, p.get_id()));
|
||||
} else if (eat_word(p, "if")) {
|
||||
ret parse_if_expr(p);
|
||||
} else if (eat_word(p, "for")) {
|
||||
|
@ -758,14 +752,14 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_elt, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_tup(es.node, p.get_ann());
|
||||
ex = ast::expr_tup(es.node, p.get_id());
|
||||
} else if (p.peek() == token::LBRACKET) {
|
||||
p.bump();
|
||||
auto mut = parse_mutability(p);
|
||||
auto es =
|
||||
parse_seq_to_end(token::RBRACKET, some(token::COMMA), parse_expr,
|
||||
p);
|
||||
ex = ast::expr_vec(es, mut, ast::sk_rc, p.get_ann());
|
||||
ex = ast::expr_vec(es, mut, ast::sk_rc, p.get_id());
|
||||
} else if (p.peek() == token::TILDE) {
|
||||
p.bump();
|
||||
alt (p.peek()) {
|
||||
|
@ -776,14 +770,14 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
auto es =
|
||||
parse_seq_to_end(token::RBRACKET, some(token::COMMA),
|
||||
parse_expr, p);
|
||||
ex = ast::expr_vec(es, mut, ast::sk_unique, p.get_ann());
|
||||
ex = ast::expr_vec(es, mut, ast::sk_unique, p.get_id());
|
||||
}
|
||||
case (token::LIT_STR(?s)) {
|
||||
p.bump();
|
||||
auto lit =
|
||||
@rec(node=ast::lit_str(p.get_str(s), ast::sk_unique),
|
||||
span=p.get_span());
|
||||
ex = ast::expr_lit(lit, p.get_ann());
|
||||
ex = ast::expr_lit(lit, p.get_id());
|
||||
}
|
||||
case (_) {
|
||||
p.get_session().span_unimpl(p.get_span(),
|
||||
|
@ -824,8 +818,8 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
|
||||
let ast::anon_obj ob =
|
||||
rec(fields=fields, methods=meths, with_obj=with_obj);
|
||||
auto odid = rec(ty=p.next_def_id(), ctor=p.next_def_id());
|
||||
ex = ast::expr_anon_obj(ob, ty_params, odid, p.get_ann());
|
||||
auto odid = rec(ty=p.get_id(), ctor=p.get_id());
|
||||
ex = ast::expr_anon_obj(ob, ty_params, odid, p.get_id());
|
||||
} else if (eat_word(p, "rec")) {
|
||||
expect(p, token::LPAREN);
|
||||
auto fields = [parse_field(p)];
|
||||
|
@ -846,7 +840,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
fields += [parse_field(p)];
|
||||
} else { unexpected(p, p.peek()); }
|
||||
}
|
||||
ex = ast::expr_rec(fields, base, p.get_ann());
|
||||
ex = ast::expr_rec(fields, base, p.get_id());
|
||||
} else if (eat_word(p, "bind")) {
|
||||
auto e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS);
|
||||
fn parse_expr_opt(&parser p) -> option::t[@ast::expr] {
|
||||
|
@ -859,7 +853,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_expr_opt, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_bind(e, es.node, p.get_ann());
|
||||
ex = ast::expr_bind(e, es.node, p.get_id());
|
||||
} else if (p.peek() == token::POUND) {
|
||||
auto ex_ext = parse_syntax_ext(p);
|
||||
lo = ex_ext.span.lo;
|
||||
|
@ -870,19 +864,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
case (token::LIT_STR(?s)) { msg = some(p.get_str(s)); p.bump(); }
|
||||
case (_) { msg = none; }
|
||||
}
|
||||
ex = ast::expr_fail(p.get_ann(), msg);
|
||||
ex = ast::expr_fail(p.get_id(), msg);
|
||||
} else if (eat_word(p, "log")) {
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_log(1, e, p.get_ann());
|
||||
ex = ast::expr_log(1, e, p.get_id());
|
||||
} else if (eat_word(p, "log_err")) {
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_log(0, e, p.get_ann());
|
||||
ex = ast::expr_log(0, e, p.get_id());
|
||||
} else if (eat_word(p, "assert")) {
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_assert(e, p.get_ann());
|
||||
ex = ast::expr_assert(e, p.get_id());
|
||||
} else if (eat_word(p, "check")) {
|
||||
/* Should be a predicate (pure boolean function) applied to
|
||||
arguments that are all either slot variables or literals.
|
||||
|
@ -890,27 +884,27 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
|
||||
auto e = parse_expr(p);
|
||||
auto hi = e.span.hi;
|
||||
ex = ast::expr_check(e, p.get_ann());
|
||||
ex = ast::expr_check(e, p.get_id());
|
||||
} else if (eat_word(p, "ret")) {
|
||||
alt (p.peek()) {
|
||||
case (token::SEMI) { ex = ast::expr_ret(none, p.get_ann()); }
|
||||
case (token::SEMI) { ex = ast::expr_ret(none, p.get_id()); }
|
||||
case (_) {
|
||||
auto e = parse_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_ret(some(e), p.get_ann());
|
||||
ex = ast::expr_ret(some(e), p.get_id());
|
||||
}
|
||||
}
|
||||
} else if (eat_word(p, "break")) {
|
||||
ex = ast::expr_break(p.get_ann());
|
||||
ex = ast::expr_break(p.get_id());
|
||||
} else if (eat_word(p, "cont")) {
|
||||
ex = ast::expr_cont(p.get_ann());
|
||||
ex = ast::expr_cont(p.get_id());
|
||||
} else if (eat_word(p, "put")) {
|
||||
alt (p.peek()) {
|
||||
case (token::SEMI) { ex = ast::expr_put(none, p.get_ann()); }
|
||||
case (token::SEMI) { ex = ast::expr_put(none, p.get_id()); }
|
||||
case (_) {
|
||||
auto e = parse_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_put(some(e), p.get_ann());
|
||||
ex = ast::expr_put(some(e), p.get_id());
|
||||
}
|
||||
}
|
||||
} else if (eat_word(p, "be")) {
|
||||
|
@ -919,19 +913,19 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
// FIXME: Is this the right place for this check?
|
||||
if (/*check*/ast::is_call_expr(e)) {
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_be(e, p.get_ann());
|
||||
ex = ast::expr_be(e, p.get_id());
|
||||
} else { p.err("Non-call expression in tail call"); }
|
||||
} else if (eat_word(p, "port")) {
|
||||
expect(p, token::LPAREN);
|
||||
expect(p, token::RPAREN);
|
||||
hi = p.get_hi_pos();
|
||||
ex = ast::expr_port(p.get_ann());
|
||||
ex = ast::expr_port(p.get_id());
|
||||
} else if (eat_word(p, "chan")) {
|
||||
expect(p, token::LPAREN);
|
||||
auto e = parse_expr(p);
|
||||
hi = e.span.hi;
|
||||
expect(p, token::RPAREN);
|
||||
ex = ast::expr_chan(e, p.get_ann());
|
||||
ex = ast::expr_chan(e, p.get_id());
|
||||
} else if (eat_word(p, "self")) {
|
||||
log "parsing a self-call...";
|
||||
expect(p, token::DOT);
|
||||
|
@ -942,17 +936,17 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_expr, p);
|
||||
hi = es.span.hi;
|
||||
ex = ast::expr_call(f, es.node, p.get_ann());
|
||||
ex = ast::expr_call(f, es.node, p.get_id());
|
||||
} else if (is_ident(p.peek()) && !is_word(p, "true") &&
|
||||
!is_word(p, "false")) {
|
||||
check_bad_word(p);
|
||||
auto pth = parse_path_and_ty_param_substs(p);
|
||||
hi = pth.span.hi;
|
||||
ex = ast::expr_path(pth, p.get_ann());
|
||||
ex = ast::expr_path(pth, p.get_id());
|
||||
} else {
|
||||
auto lit = parse_lit(p);
|
||||
hi = lit.span.hi;
|
||||
ex = ast::expr_lit(@lit, p.get_ann());
|
||||
ex = ast::expr_lit(@lit, p.get_id());
|
||||
}
|
||||
ret @spanned(lo, hi, ex);
|
||||
}
|
||||
|
@ -989,7 +983,7 @@ fn expand_syntax_ext(&parser p, common::span sp, &ast::path path,
|
|||
case (some(ext::x(?ext))) {
|
||||
auto ext_cx = ext::mk_ctxt(p);
|
||||
ret ast::expr_ext(path, args, body, ext(ext_cx, sp, args, body),
|
||||
p.get_ann());
|
||||
p.get_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -998,7 +992,7 @@ fn parse_self_method(&parser p) -> @ast::expr {
|
|||
auto sp = p.get_span();
|
||||
let ast::ident f_name = parse_ident(p);
|
||||
auto hi = p.get_span();
|
||||
ret @rec(node=ast::expr_self_method(f_name, p.get_ann()), span=sp);
|
||||
ret @rec(node=ast::expr_self_method(f_name, p.get_id()), span=sp);
|
||||
}
|
||||
|
||||
fn parse_dot_or_call_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1020,7 +1014,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
|
|||
parse_seq(token::LPAREN, token::RPAREN,
|
||||
some(token::COMMA), parse_expr, p);
|
||||
hi = es.span.hi;
|
||||
auto e_ = ast::expr_call(e, es.node, p.get_ann());
|
||||
auto e_ = ast::expr_call(e, es.node, p.get_id());
|
||||
e = @spanned(lo, hi, e_);
|
||||
}
|
||||
}
|
||||
|
@ -1031,7 +1025,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
|
|||
hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto e_ =
|
||||
ast::expr_field(e, p.get_str(i), p.get_ann());
|
||||
ast::expr_field(e, p.get_str(i), p.get_id());
|
||||
e = @spanned(lo, hi, e_);
|
||||
}
|
||||
case (token::LPAREN) {
|
||||
|
@ -1039,7 +1033,7 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
|
|||
auto ix = parse_expr(p);
|
||||
hi = ix.span.hi;
|
||||
expect(p, token::RPAREN);
|
||||
auto e_ = ast::expr_index(e, ix, p.get_ann());
|
||||
auto e_ = ast::expr_index(e, ix, p.get_id());
|
||||
e = @spanned(lo, hi, e_);
|
||||
}
|
||||
case (?t) { unexpected(p, t); }
|
||||
|
@ -1063,13 +1057,13 @@ fn parse_prefix_expr(&parser p) -> @ast::expr {
|
|||
// alt-exhaustive-match checking are co-operating.
|
||||
|
||||
auto lit = @spanned(lo, lo, ast::lit_nil);
|
||||
let ast::expr_ ex = ast::expr_lit(lit, p.get_ann());
|
||||
let ast::expr_ ex = ast::expr_lit(lit, p.get_id());
|
||||
alt (p.peek()) {
|
||||
case (token::NOT) {
|
||||
p.bump();
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::not, e, p.get_ann());
|
||||
ex = ast::expr_unary(ast::not, e, p.get_id());
|
||||
}
|
||||
case (token::BINOP(?b)) {
|
||||
alt (b) {
|
||||
|
@ -1077,13 +1071,13 @@ fn parse_prefix_expr(&parser p) -> @ast::expr {
|
|||
p.bump();
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::neg, e, p.get_ann());
|
||||
ex = ast::expr_unary(ast::neg, e, p.get_id());
|
||||
}
|
||||
case (token::STAR) {
|
||||
p.bump();
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::deref, e, p.get_ann());
|
||||
ex = ast::expr_unary(ast::deref, e, p.get_id());
|
||||
}
|
||||
case (_) { ret parse_dot_or_call_expr(p); }
|
||||
}
|
||||
|
@ -1093,7 +1087,7 @@ fn parse_prefix_expr(&parser p) -> @ast::expr {
|
|||
auto m = parse_mutability(p);
|
||||
auto e = parse_prefix_expr(p);
|
||||
hi = e.span.hi;
|
||||
ex = ast::expr_unary(ast::box(m), e, p.get_ann());
|
||||
ex = ast::expr_unary(ast::box(m), e, p.get_id());
|
||||
}
|
||||
case (_) { ret parse_dot_or_call_expr(p); }
|
||||
}
|
||||
|
@ -1141,14 +1135,14 @@ fn parse_more_binops(&parser p, @ast::expr lhs, int min_prec) -> @ast::expr {
|
|||
if (cur.prec > min_prec && cur.tok == peeked) {
|
||||
p.bump();
|
||||
auto rhs = parse_more_binops(p, parse_prefix_expr(p), cur.prec);
|
||||
auto bin = ast::expr_binary(cur.op, lhs, rhs, p.get_ann());
|
||||
auto bin = ast::expr_binary(cur.op, lhs, rhs, p.get_id());
|
||||
auto span = @spanned(lhs.span.lo, rhs.span.hi, bin);
|
||||
ret parse_more_binops(p, span, min_prec);
|
||||
}
|
||||
}
|
||||
if (as_prec > min_prec && eat_word(p, "as")) {
|
||||
auto rhs = parse_ty(p);
|
||||
auto _as = ast::expr_cast(lhs, rhs, p.get_ann());
|
||||
auto _as = ast::expr_cast(lhs, rhs, p.get_id());
|
||||
auto span = @spanned(lhs.span.lo, rhs.span.hi, _as);
|
||||
ret parse_more_binops(p, span, min_prec);
|
||||
}
|
||||
|
@ -1163,7 +1157,7 @@ fn parse_assign_expr(&parser p) -> @ast::expr {
|
|||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_assign(lhs, rhs, p.get_ann()));
|
||||
ast::expr_assign(lhs, rhs, p.get_id()));
|
||||
}
|
||||
case (token::BINOPEQ(?op)) {
|
||||
p.bump();
|
||||
|
@ -1183,31 +1177,31 @@ fn parse_assign_expr(&parser p) -> @ast::expr {
|
|||
case (token::ASR) { aop = ast::asr; }
|
||||
}
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_assign_op(aop, lhs, rhs, p.get_ann()));
|
||||
ast::expr_assign_op(aop, lhs, rhs, p.get_id()));
|
||||
}
|
||||
case (token::LARROW) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_move(lhs, rhs, p.get_ann()));
|
||||
ast::expr_move(lhs, rhs, p.get_id()));
|
||||
}
|
||||
case (token::SEND) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_send(lhs, rhs, p.get_ann()));
|
||||
ast::expr_send(lhs, rhs, p.get_id()));
|
||||
}
|
||||
case (token::RECV) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_recv(lhs, rhs, p.get_ann()));
|
||||
ast::expr_recv(lhs, rhs, p.get_id()));
|
||||
}
|
||||
case (token::DARROW) {
|
||||
p.bump();
|
||||
auto rhs = parse_expr(p);
|
||||
ret @spanned(lo, rhs.span.hi,
|
||||
ast::expr_swap(lhs, rhs, p.get_ann()));
|
||||
ast::expr_swap(lhs, rhs, p.get_id()));
|
||||
}
|
||||
case (_) {/* fall through */ }
|
||||
}
|
||||
|
@ -1216,7 +1210,7 @@ fn parse_assign_expr(&parser p) -> @ast::expr {
|
|||
|
||||
fn parse_if_expr_1(&parser p) -> tup(@ast::expr,
|
||||
ast::block, option::t[@ast::expr],
|
||||
ast::ann, uint, uint) {
|
||||
ast::node_id, uint, uint) {
|
||||
auto lo = p.get_last_lo_pos();
|
||||
expect(p, token::LPAREN);
|
||||
auto cond = parse_expr(p);
|
||||
|
@ -1229,7 +1223,7 @@ fn parse_if_expr_1(&parser p) -> tup(@ast::expr,
|
|||
els = some(elexpr);
|
||||
hi = elexpr.span.hi;
|
||||
}
|
||||
ret tup(cond, thn, els, p.get_ann(), lo, hi);
|
||||
ret tup(cond, thn, els, p.get_id(), lo, hi);
|
||||
}
|
||||
|
||||
fn parse_if_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1250,7 +1244,7 @@ fn parse_fn_expr(&parser p) -> @ast::expr {
|
|||
auto decl = parse_fn_decl(p, ast::impure_fn);
|
||||
auto body = parse_block(p);
|
||||
auto _fn = rec(decl=decl, proto=ast::proto_fn, body=body);
|
||||
ret @spanned(lo, body.span.hi, ast::expr_fn(_fn, p.get_ann()));
|
||||
ret @spanned(lo, body.span.hi, ast::expr_fn(_fn, p.get_id()));
|
||||
}
|
||||
|
||||
fn parse_else_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1259,7 +1253,7 @@ fn parse_else_expr(&parser p) -> @ast::expr {
|
|||
} else {
|
||||
auto blk = parse_block(p);
|
||||
ret @spanned(blk.span.lo, blk.span.hi,
|
||||
ast::expr_block(blk, p.get_ann()));
|
||||
ast::expr_block(blk, p.get_id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1284,9 +1278,9 @@ fn parse_for_expr(&parser p) -> @ast::expr {
|
|||
auto hi = body.span.hi;
|
||||
if (is_each) {
|
||||
ret @spanned(lo, hi,
|
||||
ast::expr_for_each(decl, seq, body, p.get_ann()));
|
||||
ast::expr_for_each(decl, seq, body, p.get_id()));
|
||||
} else {
|
||||
ret @spanned(lo, hi, ast::expr_for(decl, seq, body, p.get_ann()));
|
||||
ret @spanned(lo, hi, ast::expr_for(decl, seq, body, p.get_id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1297,7 +1291,7 @@ fn parse_while_expr(&parser p) -> @ast::expr {
|
|||
expect(p, token::RPAREN);
|
||||
auto body = parse_block(p);
|
||||
auto hi = body.span.hi;
|
||||
ret @spanned(lo, hi, ast::expr_while(cond, body, p.get_ann()));
|
||||
ret @spanned(lo, hi, ast::expr_while(cond, body, p.get_id()));
|
||||
}
|
||||
|
||||
fn parse_do_while_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1308,7 +1302,7 @@ fn parse_do_while_expr(&parser p) -> @ast::expr {
|
|||
auto cond = parse_expr(p);
|
||||
expect(p, token::RPAREN);
|
||||
auto hi = cond.span.hi;
|
||||
ret @spanned(lo, hi, ast::expr_do_while(body, cond, p.get_ann()));
|
||||
ret @spanned(lo, hi, ast::expr_do_while(body, cond, p.get_id()));
|
||||
}
|
||||
|
||||
fn parse_alt_expr(&parser p) -> @ast::expr {
|
||||
|
@ -1335,7 +1329,7 @@ fn parse_alt_expr(&parser p) -> @ast::expr {
|
|||
}
|
||||
auto hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto expr = ast::expr_alt(discriminant, arms, p.get_ann());
|
||||
auto expr = ast::expr_alt(discriminant, arms, p.get_id());
|
||||
ret @spanned(lo, hi, expr);
|
||||
}
|
||||
|
||||
|
@ -1351,7 +1345,7 @@ fn parse_spawn_expr(&parser p) -> @ast::expr {
|
|||
auto hi = es.span.hi;
|
||||
auto spawn_expr =
|
||||
ast::expr_spawn(ast::dom_implicit, option::none, fn_expr, es.node,
|
||||
p.get_ann());
|
||||
p.get_id());
|
||||
ret @spanned(lo, hi, spawn_expr);
|
||||
}
|
||||
|
||||
|
@ -1398,7 +1392,7 @@ fn parse_pat(&parser p) -> @ast::pat {
|
|||
alt (p.peek()) {
|
||||
case (token::UNDERSCORE) {
|
||||
p.bump();
|
||||
pat = ast::pat_wild(p.get_ann());
|
||||
pat = ast::pat_wild(p.get_id());
|
||||
}
|
||||
case (token::QUES) {
|
||||
p.bump();
|
||||
|
@ -1407,8 +1401,7 @@ fn parse_pat(&parser p) -> @ast::pat {
|
|||
hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
pat =
|
||||
ast::pat_bind(p.get_str(id), p.next_def_id(),
|
||||
p.get_ann());
|
||||
ast::pat_bind(p.get_str(id), p.get_id());
|
||||
}
|
||||
case (?tok) {
|
||||
p.err("expected identifier after '?' in pattern but " +
|
||||
|
@ -1421,7 +1414,7 @@ fn parse_pat(&parser p) -> @ast::pat {
|
|||
if (!is_ident(tok) || is_word(p, "true") || is_word(p, "false")) {
|
||||
auto lit = parse_lit(p);
|
||||
hi = lit.span.hi;
|
||||
pat = ast::pat_lit(@lit, p.get_ann());
|
||||
pat = ast::pat_lit(@lit, p.get_id());
|
||||
} else {
|
||||
auto tag_path = parse_path_and_ty_param_substs(p);
|
||||
hi = tag_path.span.hi;
|
||||
|
@ -1437,7 +1430,7 @@ fn parse_pat(&parser p) -> @ast::pat {
|
|||
}
|
||||
case (_) { args = []; }
|
||||
}
|
||||
pat = ast::pat_tag(tag_path, args, p.get_ann());
|
||||
pat = ast::pat_tag(tag_path, args, p.get_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1454,9 +1447,7 @@ fn parse_local_full(&option::t[@ast::ty] tyopt, &parser p)
|
|||
infer=false,
|
||||
ident=ident,
|
||||
init=init,
|
||||
id=p.next_def_id(),
|
||||
ann=p.get_ann()));
|
||||
|
||||
id=p.get_id()));
|
||||
}
|
||||
|
||||
fn parse_typed_local(&parser p) -> @ast::local {
|
||||
|
@ -1497,11 +1488,11 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
|
|||
if (eat_word(p, "let")) {
|
||||
auto decl = parse_let(p);
|
||||
auto hi = p.get_span();
|
||||
ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann()));
|
||||
ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id()));
|
||||
} else if (eat_word(p, "auto")) {
|
||||
auto decl = parse_auto(p);
|
||||
auto hi = p.get_span();
|
||||
ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_ann()));
|
||||
ret @spanned(lo, decl.span.hi, ast::stmt_decl(decl, p.get_id()));
|
||||
} else {
|
||||
|
||||
auto item_attrs;
|
||||
|
@ -1514,7 +1505,7 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
|
|||
}
|
||||
case (some(right(?ext))) {
|
||||
ret @spanned(lo, ext.span.hi,
|
||||
ast::stmt_expr(ext, p.get_ann()));
|
||||
ast::stmt_expr(ext, p.get_id()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1534,19 +1525,19 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
|
|||
case (got_item(?i)) {
|
||||
auto hi = i.span.hi;
|
||||
auto decl = @spanned(lo, hi, ast::decl_item(i));
|
||||
ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_ann()));
|
||||
ret @spanned(lo, hi, ast::stmt_decl(decl, p.get_id()));
|
||||
}
|
||||
case (fn_no_item) { // parse_item will have already skipped "fn"
|
||||
|
||||
auto e = parse_fn_expr(p);
|
||||
e = parse_dot_or_call_expr_with(p, e);
|
||||
ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_ann()));
|
||||
ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id()));
|
||||
}
|
||||
case (no_item) {
|
||||
// Remainder are line-expr stmts.
|
||||
|
||||
auto e = parse_expr(p);
|
||||
ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_ann()));
|
||||
ret @spanned(lo, e.span.hi, ast::stmt_expr(e, p.get_id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1667,7 +1658,7 @@ fn parse_block(&parser p) -> ast::block {
|
|||
}
|
||||
auto hi = p.get_hi_pos();
|
||||
p.bump();
|
||||
auto bloc = rec(stmts=stmts, expr=expr, a=p.get_ann());
|
||||
auto bloc = rec(stmts=stmts, expr=expr, id=p.get_id());
|
||||
ret spanned(lo, hi, bloc);
|
||||
}
|
||||
|
||||
|
@ -1731,8 +1722,7 @@ fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node,
|
|||
&vec[ast::attribute] attrs) -> @ast::item {
|
||||
ret @rec(ident=ident,
|
||||
attrs=attrs,
|
||||
id=p.next_def_id(),
|
||||
ann=p.get_ann(),
|
||||
id=p.get_id(),
|
||||
node=node,
|
||||
span=rec(lo=lo, hi=hi));
|
||||
}
|
||||
|
@ -1749,7 +1739,7 @@ fn parse_obj_field(&parser p) -> ast::obj_field {
|
|||
auto mut = parse_mutability(p);
|
||||
auto ty = parse_ty(p);
|
||||
auto ident = parse_value_ident(p);
|
||||
ret rec(mut=mut, ty=ty, ident=ident, id=p.next_def_id(), ann=p.get_ann());
|
||||
ret rec(mut=mut, ty=ty, ident=ident, id=p.get_id());
|
||||
}
|
||||
|
||||
fn parse_method(&parser p) -> @ast::method {
|
||||
|
@ -1757,7 +1747,7 @@ fn parse_method(&parser p) -> @ast::method {
|
|||
auto proto = parse_proto(p);
|
||||
auto ident = parse_value_ident(p);
|
||||
auto f = parse_fn(p, proto, ast::impure_fn);
|
||||
auto meth = rec(ident=ident, meth=f, id=p.next_def_id(), ann=p.get_ann());
|
||||
auto meth = rec(ident=ident, meth=f, id=p.get_id());
|
||||
ret @spanned(lo, f.body.span.hi, meth);
|
||||
}
|
||||
|
||||
|
@ -1776,7 +1766,7 @@ fn parse_dtor(&parser p) -> @ast::method {
|
|||
constraints=[]);
|
||||
let ast::_fn f = rec(decl=d, proto=ast::proto_fn, body=b);
|
||||
let ast::method_ m =
|
||||
rec(ident="drop", meth=f, id=p.next_def_id(), ann=p.get_ann());
|
||||
rec(ident="drop", meth=f, id=p.get_id());
|
||||
ret @spanned(lo, f.body.span.hi, m);
|
||||
}
|
||||
|
||||
|
@ -1801,7 +1791,7 @@ fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
|
|||
expect(p, token::RBRACE);
|
||||
let ast::_obj ob = rec(fields=fields.node, methods=meths, dtor=dtor);
|
||||
ret mk_item(p, lo, hi, ident, ast::item_obj(ob, ty_params,
|
||||
p.next_def_id()), attrs);
|
||||
p.get_id()), attrs);
|
||||
}
|
||||
|
||||
fn parse_mod_items(&parser p, token::token term,
|
||||
|
@ -1856,7 +1846,7 @@ fn parse_item_native_type(&parser p) -> @ast::native_item {
|
|||
auto t = parse_type_decl(p);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto item = ast::native_item_ty(t._1, p.next_def_id());
|
||||
auto item = ast::native_item_ty(t._1, p.get_id());
|
||||
ret @spanned(t._0, hi, item);
|
||||
}
|
||||
|
||||
|
@ -1872,8 +1862,7 @@ fn parse_item_native_fn(&parser p) -> @ast::native_item {
|
|||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto item =
|
||||
ast::native_item_fn(t._0, link_name, decl, t._1, p.next_def_id(),
|
||||
p.get_ann());
|
||||
ast::native_item_fn(t._0, link_name, decl, t._1, p.get_id());
|
||||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
|
@ -1975,19 +1964,18 @@ fn parse_item_tag(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
|||
parse_seq(token::LPAREN, token::RPAREN,
|
||||
some(token::COMMA), parse_ty, p);
|
||||
for (@ast::ty ty in arg_tys.node) {
|
||||
args += [rec(ty=ty, id=p.next_def_id())];
|
||||
args += [rec(ty=ty, id=p.get_id())];
|
||||
}
|
||||
}
|
||||
case (_) {/* empty */ }
|
||||
}
|
||||
auto vhi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto id = p.next_def_id();
|
||||
auto id = p.get_id();
|
||||
auto vr =
|
||||
rec(name=p.get_str(name),
|
||||
args=args,
|
||||
id=id,
|
||||
ann=p.get_ann());
|
||||
id=p.get_id());
|
||||
variants += [spanned(vlo, vhi, vr)];
|
||||
}
|
||||
case (token::RBRACE) {/* empty */ }
|
||||
|
@ -2165,7 +2153,7 @@ fn parse_use(&parser p) -> @ast::view_item {
|
|||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto use_decl =
|
||||
ast::view_item_use(ident, metadata, p.next_def_id(), p.get_ann());
|
||||
ast::view_item_use(ident, metadata, p.get_id());
|
||||
ret @spanned(lo, hi, use_decl);
|
||||
}
|
||||
|
||||
|
@ -2201,17 +2189,17 @@ fn parse_rest_import_name(&parser p, ast::ident first,
|
|||
case (some(?i)) {
|
||||
if (glob) { p.err("globbed imports can't be renamed"); }
|
||||
import_decl =
|
||||
ast::view_item_import(i, identifiers, p.next_def_id());
|
||||
ast::view_item_import(i, identifiers, p.get_id());
|
||||
}
|
||||
case (_) {
|
||||
if (glob) {
|
||||
import_decl =
|
||||
ast::view_item_import_glob(identifiers, p.next_def_id());
|
||||
ast::view_item_import_glob(identifiers, p.get_id());
|
||||
} else {
|
||||
auto len = vec::len(identifiers);
|
||||
import_decl =
|
||||
ast::view_item_import(identifiers.(len - 1u), identifiers,
|
||||
p.next_def_id());
|
||||
p.get_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2254,7 +2242,7 @@ fn parse_export(&parser p) -> @ast::view_item {
|
|||
auto id = parse_ident(p);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
ret @spanned(lo, hi, ast::view_item_export(id));
|
||||
ret @spanned(lo, hi, ast::view_item_export(id, p.get_id()));
|
||||
}
|
||||
|
||||
fn parse_view_item(&parser p) -> @ast::view_item {
|
||||
|
@ -2390,7 +2378,7 @@ fn parse_crate_from_crate_file(&parser p) -> @ast::crate {
|
|||
mutable deps=deps,
|
||||
sess=p.get_session(),
|
||||
mutable chpos=p.get_chpos(),
|
||||
mutable next_ann=p.next_ann_num());
|
||||
mutable next_id=p.next_id());
|
||||
auto m =
|
||||
eval::eval_crate_directives_to_mod(cx, p.get_env(), cdirs, prefix);
|
||||
auto hi = p.get_hi_pos();
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
|
||||
import front::ast;
|
||||
import front::ast::ident;
|
||||
import front::ast::def_num;
|
||||
import front::ast::node_id;
|
||||
import front::ast::def_id;
|
||||
import util::common::span;
|
||||
import visit::vt;
|
||||
import std::vec;
|
||||
|
@ -22,9 +23,9 @@ import std::option::is_none;
|
|||
tag valid { valid; overwritten(span, ast::path); val_taken(span, ast::path); }
|
||||
|
||||
type restrict =
|
||||
@rec(vec[def_num] root_vars,
|
||||
def_num block_defnum,
|
||||
vec[def_num] bindings,
|
||||
@rec(vec[node_id] root_vars,
|
||||
node_id block_defnum,
|
||||
vec[node_id] bindings,
|
||||
vec[ty::t] tys,
|
||||
vec[uint] depends_on,
|
||||
mutable valid ok);
|
||||
|
@ -33,8 +34,8 @@ type scope = vec[restrict];
|
|||
|
||||
tag local_info { arg(ast::mode); objfield(ast::mutability); }
|
||||
|
||||
type ctx =
|
||||
rec(@ty::ctxt tcx, std::map::hashmap[def_num, local_info] local_map);
|
||||
type ctx = rec(@ty::ctxt tcx,
|
||||
std::map::hashmap[node_id, local_info] local_map);
|
||||
|
||||
fn check_crate(@ty::ctxt tcx, &@ast::crate crate) {
|
||||
auto cx =
|
||||
|
@ -44,7 +45,7 @@ fn check_crate(@ty::ctxt tcx, &@ast::crate crate) {
|
|||
// arguments that's otherwise not easily available.
|
||||
local_map=util::common::new_int_hash());
|
||||
auto v =
|
||||
@rec(visit_fn=bind visit_fn(cx, _, _, _, _, _, _, _, _),
|
||||
@rec(visit_fn=bind visit_fn(cx, _, _, _, _, _, _, _),
|
||||
visit_item=bind visit_item(cx, _, _, _),
|
||||
visit_expr=bind visit_expr(cx, _, _, _)
|
||||
with *visit::default_visitor[scope]());
|
||||
|
@ -52,11 +53,10 @@ fn check_crate(@ty::ctxt tcx, &@ast::crate crate) {
|
|||
}
|
||||
|
||||
fn visit_fn(@ctx cx, &ast::_fn f, &vec[ast::ty_param] tp, &span sp,
|
||||
&ident name, &ast::def_id d_id, &ast::ann a, &scope sc,
|
||||
&vt[scope] v) {
|
||||
&ident name, ast::node_id id, &scope sc, &vt[scope] v) {
|
||||
visit::visit_fn_decl(f.decl, sc, v);
|
||||
for (ast::arg arg_ in f.decl.inputs) {
|
||||
cx.local_map.insert(arg_.id._1, arg(arg_.mode));
|
||||
cx.local_map.insert(arg_.id, arg(arg_.mode));
|
||||
}
|
||||
vt(v).visit_block(f.body, [], v);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ fn visit_item(@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) {
|
|||
alt (i.node) {
|
||||
case (ast::item_obj(?o, _, _)) {
|
||||
for (ast::obj_field f in o.fields) {
|
||||
cx.local_map.insert(f.id._1, objfield(f.mut));
|
||||
cx.local_map.insert(f.id, objfield(f.mut));
|
||||
}
|
||||
}
|
||||
case (_) { }
|
||||
|
@ -107,8 +107,8 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
|
|||
case (ast::expr_for(?decl, ?seq, ?block, _)) {
|
||||
check_for(*cx, decl, seq, block, sc, v);
|
||||
}
|
||||
case (ast::expr_path(?pt, ?ann)) {
|
||||
check_var(*cx, ex, pt, ann, false, sc);
|
||||
case (ast::expr_path(?pt, ?id)) {
|
||||
check_var(*cx, ex, pt, id, false, sc);
|
||||
handled = false;
|
||||
}
|
||||
case (ast::expr_move(?dest, ?src, _)) {
|
||||
|
@ -126,11 +126,11 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
|
|||
}
|
||||
|
||||
fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) ->
|
||||
rec(vec[def_num] root_vars, vec[ty::t] unsafe_ts) {
|
||||
rec(vec[node_id] root_vars, vec[ty::t] unsafe_ts) {
|
||||
auto fty = ty::expr_ty(*cx.tcx, f);
|
||||
auto arg_ts = fty_args(cx, fty);
|
||||
let vec[def_num] roots = [];
|
||||
let vec[tup(uint, def_num)] mut_roots = [];
|
||||
let vec[node_id] roots = [];
|
||||
let vec[tup(uint, node_id)] mut_roots = [];
|
||||
let vec[ty::t] unsafe_ts = [];
|
||||
let vec[uint] unsafe_t_offsets = [];
|
||||
auto i = 0u;
|
||||
|
@ -169,8 +169,8 @@ fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) ->
|
|||
}
|
||||
if (vec::len(unsafe_ts) > 0u) {
|
||||
alt (f.node) {
|
||||
case (ast::expr_path(_, ?ann)) {
|
||||
if (def_is_local(cx.tcx.def_map.get(ann.id), true)) {
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
if (def_is_local(cx.tcx.def_map.get(id), true)) {
|
||||
cx.tcx.sess.span_fatal(f.span,
|
||||
#fmt("function may alias with \
|
||||
argument %u, which is not immutably rooted",
|
||||
|
@ -200,7 +200,7 @@ fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) ->
|
|||
}
|
||||
// Ensure we're not passing a root by mutable alias.
|
||||
|
||||
for (tup(uint, def_num) root in mut_roots) {
|
||||
for (tup(uint, node_id) root in mut_roots) {
|
||||
auto mut_alias_to_root = vec::count(root._1, roots) > 1u;
|
||||
for (restrict r in sc) {
|
||||
if (vec::member(root._1, r.root_vars)) {
|
||||
|
@ -228,8 +228,8 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
|
|||
auto mut_a = arg_t.mode == ty::mo_alias(true);
|
||||
auto ok = true;
|
||||
alt (args.(i).node) {
|
||||
case (ast::expr_path(_, ?ann)) {
|
||||
auto def = cx.tcx.def_map.get(ann.id);
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
auto def = cx.tcx.def_map.get(id);
|
||||
auto dnum = ast::def_id_of_def(def)._1;
|
||||
alt (cx.local_map.find(dnum)) {
|
||||
case (some(arg(ast::alias(?mut)))) {
|
||||
|
@ -282,11 +282,11 @@ fn check_alt(&ctx cx, &@ast::expr input, &vec[ast::arm] arms, &scope sc,
|
|||
}
|
||||
}
|
||||
|
||||
fn arm_defnums(&ast::arm arm) -> vec[def_num] {
|
||||
fn arm_defnums(&ast::arm arm) -> vec[node_id] {
|
||||
auto dnums = [];
|
||||
fn walk_pat(&mutable vec[def_num] found, &@ast::pat p) {
|
||||
fn walk_pat(&mutable vec[node_id] found, &@ast::pat p) {
|
||||
alt (p.node) {
|
||||
case (ast::pat_bind(_, ?did, _)) { vec::push(found, did._1); }
|
||||
case (ast::pat_bind(_, ?id)) { vec::push(found, id); }
|
||||
case (ast::pat_tag(_, ?children, _)) {
|
||||
for (@ast::pat child in children) { walk_pat(found, child); }
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call,
|
|||
alt (call.node) {
|
||||
case (ast::expr_call(?f, ?args, _)) {
|
||||
auto data = check_call(cx, f, args, sc);
|
||||
auto defnum = local.node.id._1;
|
||||
auto defnum = local.node.id;
|
||||
auto new_sc =
|
||||
@rec(root_vars=data.root_vars,
|
||||
block_defnum=defnum,
|
||||
|
@ -319,7 +319,7 @@ fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call,
|
|||
fn check_for(&ctx cx, &@ast::local local, &@ast::expr seq, &ast::block block,
|
||||
&scope sc, &vt[scope] v) {
|
||||
visit::visit_expr(seq, sc, v);
|
||||
auto defnum = local.node.id._1;
|
||||
auto defnum = local.node.id;
|
||||
auto root = expr_root(cx, seq, false);
|
||||
auto root_def =
|
||||
alt (path_def_id(cx, root.ex)) {
|
||||
|
@ -347,9 +347,9 @@ fn check_for(&ctx cx, &@ast::local local, &@ast::expr seq, &ast::block block,
|
|||
visit::visit_block(block, sc + [new_sc], v);
|
||||
}
|
||||
|
||||
fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::ann ann, bool assign,
|
||||
&scope sc) {
|
||||
auto def = cx.tcx.def_map.get(ann.id);
|
||||
fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::node_id id,
|
||||
bool assign, &scope sc) {
|
||||
auto def = cx.tcx.def_map.get(id);
|
||||
if (!def_is_local(def, true)) { ret; }
|
||||
auto my_defnum = ast::def_id_of_def(def)._1;
|
||||
auto var_t = ty::expr_ty(*cx.tcx, ex);
|
||||
|
@ -374,8 +374,8 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
|
|||
&vt[scope] v) {
|
||||
visit_expr(cx, src, sc, v);
|
||||
alt (dest.node) {
|
||||
case (ast::expr_path(?p, ?ann)) {
|
||||
auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(ann.id))._1;
|
||||
case (ast::expr_path(?p, ?id)) {
|
||||
auto dnum = ast::def_id_of_def(cx.tcx.def_map.get(id))._1;
|
||||
if (is_immutable_alias(cx, sc, dnum)) {
|
||||
cx.tcx.sess.span_fatal(dest.span,
|
||||
"assigning to immutable alias");
|
||||
|
@ -389,7 +389,7 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
|
|||
r.ok = overwritten(dest.span, p);
|
||||
}
|
||||
}
|
||||
check_var(*cx, dest, p, ann, true, sc);
|
||||
check_var(*cx, dest, p, id, true, sc);
|
||||
}
|
||||
case (_) {
|
||||
auto root = expr_root(*cx, dest, false);
|
||||
|
@ -410,7 +410,7 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
|
|||
}
|
||||
}
|
||||
|
||||
fn is_immutable_alias(&@ctx cx, &scope sc, def_num dnum) -> bool {
|
||||
fn is_immutable_alias(&@ctx cx, &scope sc, node_id dnum) -> bool {
|
||||
alt (cx.local_map.find(dnum)) {
|
||||
case (some(arg(ast::alias(false)))) { ret true; }
|
||||
case (_) { }
|
||||
|
@ -421,7 +421,7 @@ fn is_immutable_alias(&@ctx cx, &scope sc, def_num dnum) -> bool {
|
|||
ret false;
|
||||
}
|
||||
|
||||
fn is_immutable_objfield(&@ctx cx, def_num dnum) -> bool {
|
||||
fn is_immutable_objfield(&@ctx cx, node_id dnum) -> bool {
|
||||
ret cx.local_map.find(dnum) == some(objfield(ast::imm));
|
||||
}
|
||||
|
||||
|
@ -447,11 +447,11 @@ fn test_scope(&ctx cx, &scope sc, &restrict r, &ast::path p) {
|
|||
}
|
||||
}
|
||||
|
||||
fn deps(&scope sc, vec[def_num] roots) -> vec[uint] {
|
||||
fn deps(&scope sc, vec[node_id] roots) -> vec[uint] {
|
||||
auto i = 0u;
|
||||
auto result = [];
|
||||
for (restrict r in sc) {
|
||||
for (def_num dn in roots) {
|
||||
for (node_id dn in roots) {
|
||||
if (vec::member(dn, r.bindings)) { vec::push(result, i); }
|
||||
}
|
||||
i += 1u;
|
||||
|
@ -567,8 +567,8 @@ fn inner_mut(&vec[deref] ds) -> option::t[ty::t] {
|
|||
|
||||
fn path_def_id(&ctx cx, &@ast::expr ex) -> option::t[ast::def_id] {
|
||||
alt (ex.node) {
|
||||
case (ast::expr_path(_, ?ann)) {
|
||||
ret some(ast::def_id_of_def(cx.tcx.def_map.get(ann.id)));
|
||||
case (ast::expr_path(_, ?id)) {
|
||||
ret some(ast::def_id_of_def(cx.tcx.def_map.get(id)));
|
||||
}
|
||||
case (_) { ret none; }
|
||||
}
|
||||
|
|
56
src/comp/middle/ast_map.rs
Normal file
56
src/comp/middle/ast_map.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
import front::ast::*;
|
||||
import visit::vt;
|
||||
|
||||
tag ast_node {
|
||||
node_item(@item);
|
||||
node_obj_ctor(@item);
|
||||
node_native_item(@native_item);
|
||||
node_expr(@expr);
|
||||
}
|
||||
|
||||
type map = std::map::hashmap[node_id, ast_node];
|
||||
|
||||
fn map_crate(&crate c) -> map {
|
||||
auto map = util::common::new_int_hash[ast_node]();
|
||||
|
||||
auto v_map = @rec(visit_item=bind map_item(map, _, _, _),
|
||||
visit_native_item=bind map_native_item(map, _, _, _),
|
||||
visit_expr=bind map_expr(map, _, _, _)
|
||||
with *visit::default_visitor[()]());
|
||||
visit::visit_crate(c, (), visit::vtor(v_map));
|
||||
ret map;
|
||||
}
|
||||
|
||||
fn map_item(&map map, &@item i, &() e, &vt[()] v) {
|
||||
map.insert(i.id, node_item(i));
|
||||
alt (i.node) {
|
||||
case (item_obj(_, _, ?ctor_id)) {
|
||||
map.insert(ctor_id, node_obj_ctor(i));
|
||||
}
|
||||
case (_) {}
|
||||
}
|
||||
visit::visit_item(i, e, v);
|
||||
}
|
||||
|
||||
fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) {
|
||||
auto id = alt (i.node) {
|
||||
case (native_item_ty(_, ?id)) { id }
|
||||
case (native_item_fn(_, _, _, _, ?id)) { id }
|
||||
};
|
||||
map.insert(id, node_native_item(i));
|
||||
visit::visit_native_item(i, e, v);
|
||||
}
|
||||
|
||||
fn map_expr(&map map, &@expr ex, &() e, &vt[()] v) {
|
||||
map.insert(ty::expr_node_id(ex), node_expr(ex));
|
||||
visit::visit_expr(ex, e, v);
|
||||
}
|
||||
|
||||
// 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:
|
|
@ -8,7 +8,6 @@ import std::io;
|
|||
import std::option;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
import front::ast;
|
||||
import front::ast::*;
|
||||
import middle::trans;
|
||||
import middle::ty;
|
||||
|
@ -83,7 +82,7 @@ tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap[ty::t, ty_abbrev]); }
|
|||
|
||||
mod Encode {
|
||||
type ctxt =
|
||||
rec(fn(&ast::def_id) -> str ds, // Def -> str Callback:
|
||||
rec(fn(&def_id) -> str ds, // Def -> str Callback:
|
||||
|
||||
ty::ctxt tcx, // The type context.
|
||||
|
||||
|
@ -149,9 +148,9 @@ mod Encode {
|
|||
}
|
||||
fn enc_mt(&io::writer w, &@ctxt cx, &ty::mt mt) {
|
||||
alt (mt.mut) {
|
||||
case (ast::imm) { }
|
||||
case (ast::mut) { w.write_char('m'); }
|
||||
case (ast::maybe_mut) { w.write_char('?'); }
|
||||
case (imm) { }
|
||||
case (mut) { w.write_char('m'); }
|
||||
case (maybe_mut) { w.write_char('?'); }
|
||||
}
|
||||
enc_ty(w, cx, mt.ty);
|
||||
}
|
||||
|
@ -214,14 +213,14 @@ mod Encode {
|
|||
case (ty::ty_native_fn(?abi, ?args, ?out)) {
|
||||
w.write_char('N');
|
||||
alt (abi) {
|
||||
case (ast::native_abi_rust) { w.write_char('r'); }
|
||||
case (ast::native_abi_rust_intrinsic) {
|
||||
case (native_abi_rust) { w.write_char('r'); }
|
||||
case (native_abi_rust_intrinsic) {
|
||||
w.write_char('i');
|
||||
}
|
||||
case (ast::native_abi_cdecl) { w.write_char('c'); }
|
||||
case (ast::native_abi_llvm) { w.write_char('l'); }
|
||||
case (native_abi_cdecl) { w.write_char('c'); }
|
||||
case (native_abi_llvm) { w.write_char('l'); }
|
||||
}
|
||||
enc_ty_fn(w, cx, args, out, ast::return, []);
|
||||
enc_ty_fn(w, cx, args, out, return, []);
|
||||
}
|
||||
case (ty::ty_obj(?methods)) {
|
||||
w.write_str("O[");
|
||||
|
@ -245,14 +244,14 @@ mod Encode {
|
|||
case (ty::ty_task) { w.write_char('a'); }
|
||||
}
|
||||
}
|
||||
fn enc_proto(&io::writer w, ast::proto proto) {
|
||||
fn enc_proto(&io::writer w, proto proto) {
|
||||
alt (proto) {
|
||||
case (ast::proto_iter) { w.write_char('W'); }
|
||||
case (ast::proto_fn) { w.write_char('F'); }
|
||||
case (proto_iter) { w.write_char('W'); }
|
||||
case (proto_fn) { w.write_char('F'); }
|
||||
}
|
||||
}
|
||||
fn enc_ty_fn(&io::writer w, &@ctxt cx, &vec[ty::arg] args, &ty::t out,
|
||||
&ast::controlflow cf, &vec[@ty::constr_def] constrs) {
|
||||
&controlflow cf, &vec[@ty::constr_def] constrs) {
|
||||
w.write_char('[');
|
||||
for (ty::arg arg in args) {
|
||||
alt (arg.mode) {
|
||||
|
@ -266,7 +265,7 @@ mod Encode {
|
|||
}
|
||||
w.write_char(']');
|
||||
alt (cf) {
|
||||
case (ast::noreturn) { w.write_char('!'); }
|
||||
case (noreturn) { w.write_char('!'); }
|
||||
case (_) { enc_ty(w, cx, out); }
|
||||
}
|
||||
auto colon = true;
|
||||
|
@ -310,20 +309,20 @@ fn encode_name(&ebml::writer ebml_w, &str name) {
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_def_id(&ebml::writer ebml_w, &ast::def_id id) {
|
||||
fn encode_def_id(&ebml::writer ebml_w, &def_id id) {
|
||||
ebml::start_tag(ebml_w, tag_def_id);
|
||||
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_tag_variant_paths(&ebml::writer ebml_w, &vec[ast::variant] variants,
|
||||
fn encode_tag_variant_paths(&ebml::writer ebml_w, &vec[variant] variants,
|
||||
&vec[str] path,
|
||||
&mutable vec[tup(str, uint)] index) {
|
||||
for (ast::variant variant in variants) {
|
||||
for (variant variant in variants) {
|
||||
add_to_index(ebml_w, path, index, variant.node.name);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, variant.node.name);
|
||||
encode_def_id(ebml_w, variant.node.id);
|
||||
encode_def_id(ebml_w, local_def(variant.node.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
|
@ -335,98 +334,98 @@ fn add_to_index(&ebml::writer ebml_w, &vec[str] path,
|
|||
}
|
||||
|
||||
fn encode_native_module_item_paths(&ebml::writer ebml_w,
|
||||
&ast::native_mod nmod, &vec[str] path,
|
||||
&native_mod nmod, &vec[str] path,
|
||||
&mutable vec[tup(str, uint)] index) {
|
||||
for (@ast::native_item nitem in nmod.items) {
|
||||
for (@native_item nitem in nmod.items) {
|
||||
alt (nitem.node) {
|
||||
case (ast::native_item_ty(?id, ?did)) {
|
||||
add_to_index(ebml_w, path, index, id);
|
||||
case (native_item_ty(?ident, ?id)) {
|
||||
add_to_index(ebml_w, path, index, ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, id);
|
||||
encode_def_id(ebml_w, did);
|
||||
encode_name(ebml_w, ident);
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::native_item_fn(?id, _, _, _, ?did, _)) {
|
||||
add_to_index(ebml_w, path, index, id);
|
||||
case (native_item_fn(?ident, _, _, _, ?id)) {
|
||||
add_to_index(ebml_w, path, index, ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, id);
|
||||
encode_def_id(ebml_w, did);
|
||||
encode_name(ebml_w, ident);
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_module_item_paths(&ebml::writer ebml_w, &ast::_mod module,
|
||||
fn encode_module_item_paths(&ebml::writer ebml_w, &_mod module,
|
||||
&vec[str] path,
|
||||
&mutable vec[tup(str, uint)] index) {
|
||||
for (@ast::item it in module.items) {
|
||||
if (!ast::is_exported(it.ident, module)) { cont; }
|
||||
for (@item it in module.items) {
|
||||
if (!is_exported(it.ident, module)) { cont; }
|
||||
alt (it.node) {
|
||||
case (ast::item_const(_, _)) {
|
||||
case (item_const(_, _)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_fn(_, ?tps)) {
|
||||
case (item_fn(_, ?tps)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_mod(?_mod)) {
|
||||
case (item_mod(?_mod)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_mod);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
encode_module_item_paths(ebml_w, _mod, path + [it.ident],
|
||||
index);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_native_mod(?nmod)) {
|
||||
case (item_native_mod(?nmod)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_mod);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
encode_native_module_item_paths(ebml_w, nmod,
|
||||
path + [it.ident], index);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_ty(_, ?tps)) {
|
||||
case (item_ty(_, ?tps)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_tag(?variants, ?tps)) {
|
||||
case (item_tag(?variants, ?tps)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
encode_tag_variant_paths(ebml_w, variants, path, index);
|
||||
}
|
||||
case (ast::item_obj(_, ?tps, ?ctor_id)) {
|
||||
case (item_obj(_, ?tps, ?ctor_id)) {
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, ctor_id);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
ebml::end_tag(ebml_w);
|
||||
add_to_index(ebml_w, path, index, it.ident);
|
||||
ebml::start_tag(ebml_w, tag_paths_data_item);
|
||||
encode_name(ebml_w, it.ident);
|
||||
encode_def_id(ebml_w, it.id);
|
||||
encode_def_id(ebml_w, local_def(it.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_item_paths(&ebml::writer ebml_w, &@ast::crate crate) ->
|
||||
fn encode_item_paths(&ebml::writer ebml_w, &@crate crate) ->
|
||||
vec[tup(str, uint)] {
|
||||
let vec[tup(str, uint)] index = [];
|
||||
let vec[str] path = [];
|
||||
|
@ -444,15 +443,15 @@ fn encode_kind(&ebml::writer ebml_w, u8 c) {
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn def_to_str(&ast::def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); }
|
||||
fn def_to_str(&def_id did) -> str { ret #fmt("%d:%d", did._0, did._1); }
|
||||
|
||||
fn encode_type_param_count(&ebml::writer ebml_w, &vec[ast::ty_param] tps) {
|
||||
fn encode_type_param_count(&ebml::writer ebml_w, &vec[ty_param] tps) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_ty_param_count);
|
||||
ebml::write_vint(ebml_w.writer, vec::len[ast::ty_param](tps));
|
||||
ebml::write_vint(ebml_w.writer, vec::len[ty_param](tps));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_variant_id(&ebml::writer ebml_w, &ast::def_id vid) {
|
||||
fn encode_variant_id(&ebml::writer ebml_w, &def_id vid) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_variant);
|
||||
ebml_w.writer.write(str::bytes(def_to_str(vid)));
|
||||
ebml::end_tag(ebml_w);
|
||||
|
@ -468,37 +467,37 @@ fn encode_type(&@trans::crate_ctxt cx, &ebml::writer ebml_w, &ty::t typ) {
|
|||
}
|
||||
|
||||
fn encode_symbol(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
||||
&ast::def_id did) {
|
||||
node_id id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::bytes(cx.item_symbols.get(did)));
|
||||
ebml_w.writer.write(str::bytes(cx.item_symbols.get(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_discriminant(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
||||
&ast::def_id did) {
|
||||
node_id id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_symbol);
|
||||
ebml_w.writer.write(str::bytes(cx.discrim_symbols.get(did)));
|
||||
ebml_w.writer.write(str::bytes(cx.discrim_symbols.get(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_tag_id(&ebml::writer ebml_w, &ast::def_id id) {
|
||||
fn encode_tag_id(&ebml::writer ebml_w, &def_id id) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item_tag_id);
|
||||
ebml_w.writer.write(str::bytes(def_to_str(id)));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
||||
&ast::def_id did, &vec[ast::variant] variants,
|
||||
node_id id, &vec[variant] variants,
|
||||
&mutable vec[tup(int, uint)] index,
|
||||
&vec[ast::ty_param] ty_params) {
|
||||
for (ast::variant variant in variants) {
|
||||
index += [tup(variant.node.id._1, ebml_w.writer.tell())];
|
||||
&vec[ty_param] ty_params) {
|
||||
for (variant variant in variants) {
|
||||
index += [tup(variant.node.id, ebml_w.writer.tell())];
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, variant.node.id);
|
||||
encode_def_id(ebml_w, local_def(variant.node.id));
|
||||
encode_kind(ebml_w, 'v' as u8);
|
||||
encode_tag_id(ebml_w, did);
|
||||
encode_type(cx, ebml_w, trans::node_ann_type(cx, variant.node.ann));
|
||||
if (vec::len[ast::variant_arg](variant.node.args) > 0u) {
|
||||
encode_tag_id(ebml_w, local_def(id));
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, variant.node.id));
|
||||
if (vec::len[variant_arg](variant.node.args) > 0u) {
|
||||
encode_symbol(cx, ebml_w, variant.node.id);
|
||||
}
|
||||
encode_discriminant(cx, ebml_w, variant.node.id);
|
||||
|
@ -508,70 +507,70 @@ fn encode_tag_variant_info(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
|||
}
|
||||
|
||||
fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
||||
@ast::item item, &mutable vec[tup(int, uint)] index) {
|
||||
@item item, &mutable vec[tup(int, uint)] index) {
|
||||
alt (item.node) {
|
||||
case (ast::item_const(_, _)) {
|
||||
case (item_const(_, _)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'c' as u8);
|
||||
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, item.id));
|
||||
encode_symbol(cx, ebml_w, item.id);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_fn(_, ?tps)) {
|
||||
case (item_fn(_, ?tps)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'f' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, item.id));
|
||||
encode_symbol(cx, ebml_w, item.id);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_mod(_)) {
|
||||
case (item_mod(_)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'm' as u8);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_native_mod(_)) {
|
||||
case (item_native_mod(_)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'n' as u8);
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_ty(_, ?tps)) {
|
||||
case (item_ty(_, ?tps)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'y' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, item.id));
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
case (ast::item_tag(?variants, ?tps)) {
|
||||
case (item_tag(?variants, ?tps)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 't' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type(cx, ebml_w, trans::node_ann_type(cx, item.ann));
|
||||
for (ast::variant v in variants) {
|
||||
encode_variant_id(ebml_w, v.node.id);
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, item.id));
|
||||
for (variant v in variants) {
|
||||
encode_variant_id(ebml_w, local_def(v.node.id));
|
||||
}
|
||||
ebml::end_tag(ebml_w);
|
||||
encode_tag_variant_info(cx, ebml_w, item.id, variants, index,
|
||||
tps);
|
||||
}
|
||||
case (ast::item_obj(_, ?tps, ?ctor_id)) {
|
||||
case (item_obj(_, ?tps, ?ctor_id)) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, ctor_id);
|
||||
encode_def_id(ebml_w, local_def(ctor_id));
|
||||
encode_kind(ebml_w, 'o' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
auto fn_ty = trans::node_ann_type(cx, item.ann);
|
||||
auto fn_ty = trans::node_id_type(cx, item.id);
|
||||
encode_type(cx, ebml_w, fn_ty);
|
||||
encode_symbol(cx, ebml_w, ctor_id);
|
||||
ebml::end_tag(ebml_w);
|
||||
index += [tup(item.id._1, ebml_w.writer.tell())];
|
||||
index += [tup(item.id, ebml_w.writer.tell())];
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
encode_def_id(ebml_w, item.id);
|
||||
encode_def_id(ebml_w, local_def(item.id));
|
||||
encode_kind(ebml_w, 'y' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type(cx, ebml_w, ty::ty_fn_ret(cx.tcx, fn_ty));
|
||||
|
@ -581,20 +580,20 @@ fn encode_info_for_item(@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
|||
}
|
||||
|
||||
fn encode_info_for_native_item(&@trans::crate_ctxt cx, &ebml::writer ebml_w,
|
||||
&@ast::native_item nitem) {
|
||||
&@native_item nitem) {
|
||||
ebml::start_tag(ebml_w, tag_items_data_item);
|
||||
alt (nitem.node) {
|
||||
case (ast::native_item_ty(_, ?did)) {
|
||||
encode_def_id(ebml_w, did);
|
||||
case (native_item_ty(_, ?id)) {
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
encode_kind(ebml_w, 'T' as u8);
|
||||
encode_type(cx, ebml_w, ty::mk_native(cx.tcx));
|
||||
}
|
||||
case (ast::native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
|
||||
encode_def_id(ebml_w, did);
|
||||
case (native_item_fn(_, _, _, ?tps, ?id)) {
|
||||
encode_def_id(ebml_w, local_def(id));
|
||||
encode_kind(ebml_w, 'F' as u8);
|
||||
encode_type_param_count(ebml_w, tps);
|
||||
encode_type(cx, ebml_w, trans::node_ann_type(cx, ann));
|
||||
encode_symbol(cx, ebml_w, did);
|
||||
encode_type(cx, ebml_w, trans::node_id_type(cx, id));
|
||||
encode_symbol(cx, ebml_w, id);
|
||||
}
|
||||
}
|
||||
ebml::end_tag(ebml_w);
|
||||
|
@ -604,13 +603,13 @@ fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w) ->
|
|||
vec[tup(int, uint)] {
|
||||
let vec[tup(int, uint)] index = [];
|
||||
ebml::start_tag(ebml_w, tag_items_data);
|
||||
for each (@tup(ast::def_id, @ast::item) kvp in cx.items.items()) {
|
||||
index += [tup(kvp._0._1, ebml_w.writer.tell())];
|
||||
for each (@tup(node_id, @item) kvp in cx.items.items()) {
|
||||
index += [tup(kvp._0, ebml_w.writer.tell())];
|
||||
encode_info_for_item(cx, ebml_w, kvp._1, index);
|
||||
}
|
||||
for each (@tup(ast::def_id, @ast::native_item) kvp in
|
||||
for each (@tup(node_id, @native_item) kvp in
|
||||
cx.native_items.items()) {
|
||||
index += [tup(kvp._0._1, ebml_w.writer.tell())];
|
||||
index += [tup(kvp._0, ebml_w.writer.tell())];
|
||||
encode_info_for_native_item(cx, ebml_w, kvp._1);
|
||||
}
|
||||
ebml::end_tag(ebml_w);
|
||||
|
@ -621,7 +620,7 @@ fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w) ->
|
|||
// Path and definition ID indexing
|
||||
|
||||
// djb's cdb hashes.
|
||||
fn hash_def_num(&int def_num) -> uint { ret 177573u ^ (def_num as uint); }
|
||||
fn hash_def_id(&int def_id) -> uint { ret 177573u ^ (def_id as uint); }
|
||||
|
||||
fn hash_path(&str s) -> uint {
|
||||
auto h = 5381u;
|
||||
|
@ -670,8 +669,8 @@ fn write_int(&io::writer writer, &int n) {
|
|||
writer.write_be_uint(n as uint, 4u);
|
||||
}
|
||||
|
||||
fn encode_meta_items(&ebml::writer ebml_w, &ast::crate crate) {
|
||||
fn encode_meta_item(&ebml::writer ebml_w, &ast::meta_item mi) {
|
||||
fn encode_meta_items(&ebml::writer ebml_w, &crate crate) {
|
||||
fn encode_meta_item(&ebml::writer ebml_w, &meta_item mi) {
|
||||
ebml::start_tag(ebml_w, tag_meta_item);
|
||||
ebml::start_tag(ebml_w, tag_meta_item_key);
|
||||
ebml_w.writer.write(str::bytes(mi.node.key));
|
||||
|
@ -682,18 +681,18 @@ fn encode_meta_items(&ebml::writer ebml_w, &ast::crate crate) {
|
|||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
ebml::start_tag(ebml_w, tag_meta_export);
|
||||
for each (@ast::meta_item mi in link::crate_export_metas(crate)) {
|
||||
for each (@meta_item mi in link::crate_export_metas(crate)) {
|
||||
encode_meta_item(ebml_w, *mi);
|
||||
}
|
||||
ebml::end_tag(ebml_w);
|
||||
ebml::start_tag(ebml_w, tag_meta_local);
|
||||
for each (@ast::meta_item mi in link::crate_local_metas(crate)) {
|
||||
for each (@meta_item mi in link::crate_local_metas(crate)) {
|
||||
encode_meta_item(ebml_w, *mi);
|
||||
}
|
||||
ebml::end_tag(ebml_w);
|
||||
}
|
||||
|
||||
fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) -> ValueRef {
|
||||
fn encode_metadata(&@trans::crate_ctxt cx, &@crate crate) -> ValueRef {
|
||||
auto string_w = io::string_writer();
|
||||
auto buf_w = string_w.get_writer().get_buf_writer();
|
||||
auto ebml_w = ebml::create_writer(buf_w);
|
||||
|
@ -714,7 +713,7 @@ fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) -> ValueRef {
|
|||
ebml::start_tag(ebml_w, tag_items);
|
||||
auto items_index = encode_info_for_items(cx, ebml_w);
|
||||
auto int_writer = write_int;
|
||||
auto item_hasher = hash_def_num;
|
||||
auto item_hasher = hash_def_id;
|
||||
auto items_buckets = create_index[int](items_index, item_hasher);
|
||||
encode_index[int](ebml_w, items_buckets, int_writer);
|
||||
ebml::end_tag(ebml_w);
|
||||
|
@ -725,7 +724,7 @@ fn encode_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) -> ValueRef {
|
|||
ret C_postr(string_w.get_str());
|
||||
}
|
||||
|
||||
fn write_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) {
|
||||
fn write_metadata(&@trans::crate_ctxt cx, &@crate crate) {
|
||||
if (!cx.sess.get_opts().shared) { ret; }
|
||||
auto llmeta = encode_metadata(cx, crate);
|
||||
auto llconst = trans::C_struct([llmeta]);
|
||||
|
|
|
@ -3,12 +3,13 @@ import front::ast;
|
|||
import front::ast::ident;
|
||||
import front::ast::def;
|
||||
import front::ast::def_id;
|
||||
import front::ast::ann;
|
||||
import front::ast::node_id;
|
||||
import front::ast::local_def;
|
||||
|
||||
import front::creader;
|
||||
import driver::session::session;
|
||||
import util::common::new_def_hash;
|
||||
import util::common::new_int_hash;
|
||||
import util::common::new_uint_hash;
|
||||
import util::common::new_str_hash;
|
||||
import util::common::span;
|
||||
import util::common::respan;
|
||||
|
@ -107,17 +108,17 @@ type indexed_mod =
|
|||
only need to look at them to determine exports, which they can't control.*/
|
||||
|
||||
// It should be safe to use index to memoize lookups of globbed names.
|
||||
type crate_map = hashmap[uint, ast::crate_num];
|
||||
type crate_map = hashmap[node_id, ast::crate_num];
|
||||
|
||||
type def_map = hashmap[uint, def];
|
||||
type def_map = hashmap[node_id, def];
|
||||
|
||||
type env =
|
||||
rec(crate_map crate_map,
|
||||
def_map def_map,
|
||||
constr_table fn_constrs,
|
||||
hashmap[def_id, @ast::item] ast_map,
|
||||
hashmap[ast::def_num, import_state] imports,
|
||||
hashmap[ast::def_num, @indexed_mod] mod_map,
|
||||
hashmap[ast::node_id, @ast::item] ast_map,
|
||||
hashmap[ast::node_id, import_state] imports,
|
||||
hashmap[ast::node_id, @indexed_mod] mod_map,
|
||||
hashmap[def_id, vec[ident]] ext_map,
|
||||
ext_hash ext_cache,
|
||||
session sess);
|
||||
|
@ -132,10 +133,10 @@ tag namespace { ns_value; ns_type; ns_module; }
|
|||
fn resolve_crate(session sess, @ast::crate crate) ->
|
||||
tup(def_map, constr_table) {
|
||||
auto e =
|
||||
@rec(crate_map=new_uint_hash[ast::crate_num](),
|
||||
def_map=new_uint_hash[def](),
|
||||
fn_constrs=new_def_hash[vec[ty::constr_def]](),
|
||||
ast_map=new_def_hash[@ast::item](),
|
||||
@rec(crate_map=new_int_hash[ast::crate_num](),
|
||||
def_map=new_int_hash[def](),
|
||||
fn_constrs = new_int_hash[vec[ty::constr_def]](),
|
||||
ast_map=new_int_hash[@ast::item](),
|
||||
imports=new_int_hash[import_state](),
|
||||
mod_map=new_int_hash[@indexed_mod](),
|
||||
ext_map=new_def_hash[vec[ident]](),
|
||||
|
@ -170,8 +171,8 @@ fn map_crate(&@env e, &@ast::crate c) {
|
|||
glob_imported_names=new_str_hash[import_state]()));
|
||||
fn index_vi(@env e, &@ast::view_item i, &scopes sc, &vt[scopes] v) {
|
||||
alt (i.node) {
|
||||
case (ast::view_item_import(_, ?ids, ?defid)) {
|
||||
e.imports.insert(defid._1, todo(i, sc));
|
||||
case (ast::view_item_import(_, ?ids, ?id)) {
|
||||
e.imports.insert(id, todo(i, sc));
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
|
@ -181,7 +182,7 @@ fn map_crate(&@env e, &@ast::crate c) {
|
|||
alt (i.node) {
|
||||
case (ast::item_mod(?md)) {
|
||||
auto s = new_str_hash[import_state]();
|
||||
e.mod_map.insert(i.id._1,
|
||||
e.mod_map.insert(i.id,
|
||||
@rec(m=some(md),
|
||||
index=index_mod(md),
|
||||
mutable glob_imports=vec::empty[def](),
|
||||
|
@ -190,7 +191,7 @@ fn map_crate(&@env e, &@ast::crate c) {
|
|||
}
|
||||
case (ast::item_native_mod(?nmd)) {
|
||||
auto s = new_str_hash[import_state]();
|
||||
e.mod_map.insert(i.id._1,
|
||||
e.mod_map.insert(i.id,
|
||||
@rec(m=none[ast::_mod],
|
||||
index=index_nmod(nmd),
|
||||
mutable glob_imports=vec::empty[def](),
|
||||
|
@ -218,10 +219,10 @@ fn map_crate(&@env e, &@ast::crate c) {
|
|||
case (cons(scope_item(?i), ?tl)) {
|
||||
alt (i.node) {
|
||||
case (ast::item_mod(_)) {
|
||||
ret e.mod_map.get(i.id._1);
|
||||
ret e.mod_map.get(i.id);
|
||||
}
|
||||
case (ast::item_native_mod(_)) {
|
||||
ret e.mod_map.get(i.id._1);
|
||||
ret e.mod_map.get(i.id);
|
||||
}
|
||||
case (_) { be find_mod(e, *tl); }
|
||||
}
|
||||
|
@ -248,7 +249,7 @@ fn map_crate(&@env e, &@ast::crate c) {
|
|||
}
|
||||
|
||||
fn resolve_imports(&env e) {
|
||||
for each (@tup(ast::def_num, import_state) it in e.imports.items()) {
|
||||
for each (@tup(ast::node_id, import_state) it in e.imports.items()) {
|
||||
alt (it._1) {
|
||||
case (todo(?item, ?sc)) { resolve_import(e, item, sc); }
|
||||
case (resolved(_, _, _)) { }
|
||||
|
@ -266,7 +267,7 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
visit_expr=bind walk_expr(e, _, _, _),
|
||||
visit_ty=bind walk_ty(e, _, _, _),
|
||||
visit_constr=bind walk_constr(e, _, _, _),
|
||||
visit_fn=bind visit_fn_with_scope(e, _, _, _, _, _, _, _, _)
|
||||
visit_fn=bind visit_fn_with_scope(e, _, _, _, _, _, _, _)
|
||||
with *visit::default_visitor());
|
||||
visit::visit_crate(*c, cons(scope_crate(c), @nil), visit::vtor(v));
|
||||
e.sess.abort_if_errors();
|
||||
|
@ -274,8 +275,8 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
fn walk_expr(@env e, &@ast::expr exp, &scopes sc, &vt[scopes] v) {
|
||||
visit_expr_with_scope(exp, sc, v);
|
||||
alt (exp.node) {
|
||||
case (ast::expr_path(?p, ?a)) {
|
||||
maybe_insert(e, a.id,
|
||||
case (ast::expr_path(?p, ?id)) {
|
||||
maybe_insert(e, id,
|
||||
lookup_path_strict(*e, sc, exp.span,
|
||||
p.node.idents, ns_value));
|
||||
}
|
||||
|
@ -285,8 +286,8 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
fn walk_ty(@env e, &@ast::ty t, &scopes sc, &vt[scopes] v) {
|
||||
visit::visit_ty(t, sc, v);
|
||||
alt (t.node) {
|
||||
case (ast::ty_path(?p, ?a)) {
|
||||
maybe_insert(e, a.id,
|
||||
case (ast::ty_path(?p, ?id)) {
|
||||
maybe_insert(e, id,
|
||||
lookup_path_strict(*e, sc, t.span,
|
||||
p.node.idents, ns_type));
|
||||
}
|
||||
|
@ -294,7 +295,7 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
}
|
||||
}
|
||||
fn walk_constr(@env e, &@ast::constr c, &scopes sc, &vt[scopes] v) {
|
||||
maybe_insert(e, c.node.ann.id,
|
||||
maybe_insert(e, c.node.id,
|
||||
lookup_path_strict(*e, sc, c.span,
|
||||
c.node.path.node.idents, ns_value));
|
||||
}
|
||||
|
@ -304,14 +305,14 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
}
|
||||
fn walk_pat(&env e, &scopes sc, &@ast::pat pat) {
|
||||
alt (pat.node) {
|
||||
case (ast::pat_tag(?p, ?children, ?a)) {
|
||||
case (ast::pat_tag(?p, ?children, ?id)) {
|
||||
auto fnd =
|
||||
lookup_path_strict(e, sc, p.span, p.node.idents,
|
||||
ns_value);
|
||||
if (option::is_some(fnd)) {
|
||||
alt (option::get(fnd)) {
|
||||
case (ast::def_variant(?did, ?vid)) {
|
||||
e.def_map.insert(a.id, option::get(fnd));
|
||||
e.def_map.insert(id, option::get(fnd));
|
||||
for (@ast::pat child in children) {
|
||||
walk_pat(e, sc, child);
|
||||
}
|
||||
|
@ -328,7 +329,7 @@ fn resolve_names(&@env e, &@ast::crate c) {
|
|||
}
|
||||
}
|
||||
|
||||
fn maybe_insert(@env e, uint id,
|
||||
fn maybe_insert(@env e, node_id id,
|
||||
option::t[def] def) {
|
||||
if (option::is_some(def)) {
|
||||
e.def_map.insert(id, option::get(def));
|
||||
|
@ -348,16 +349,16 @@ fn visit_native_item_with_scope(&@ast::native_item ni, &scopes sc,
|
|||
}
|
||||
|
||||
fn visit_fn_with_scope(&@env e, &ast::_fn f, &vec[ast::ty_param] tp, &span sp,
|
||||
&ident name, &def_id d_id, &ann a, &scopes sc,
|
||||
&ident name, node_id id, &scopes sc,
|
||||
&vt[scopes] v) {
|
||||
// here's where we need to set up the mapping
|
||||
// for f's constrs in the table.
|
||||
|
||||
for (@ast::constr c in f.decl.constraints) {
|
||||
resolve_constr(e, d_id, c, sc, v);
|
||||
resolve_constr(e, id, c, sc, v);
|
||||
}
|
||||
visit::visit_fn(f, tp, sp, name, d_id, a, cons(scope_fn(f.decl, tp), @sc),
|
||||
v);
|
||||
visit::visit_fn(f, tp, sp, name, id,
|
||||
cons(scope_fn(f.decl, tp), @sc), v);
|
||||
}
|
||||
|
||||
fn visit_block_with_scope(&ast::block b, &scopes sc, &vt[scopes] v) {
|
||||
|
@ -411,7 +412,7 @@ fn follow_import(&env e, &scopes sc,
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_constr(@env e, &def_id d_id, &@ast::constr c, &scopes sc,
|
||||
fn resolve_constr(@env e, node_id id, &@ast::constr c, &scopes sc,
|
||||
&vt[scopes] v) {
|
||||
auto new_def =
|
||||
lookup_path_strict(*e, sc, c.span, c.node.path.node.idents, ns_value);
|
||||
|
@ -421,7 +422,7 @@ fn resolve_constr(@env e, &def_id d_id, &@ast::constr c, &scopes sc,
|
|||
let ty::constr_general[uint] c_ =
|
||||
rec(path=c.node.path, args=c.node.args, id=pred_id);
|
||||
let ty::constr_def new_constr = respan(c.span, c_);
|
||||
add_constr(e, d_id, new_constr);
|
||||
add_constr(e, id, new_constr);
|
||||
}
|
||||
case (_) {
|
||||
e.sess.span_err(c.span,
|
||||
|
@ -432,9 +433,9 @@ fn resolve_constr(@env e, &def_id d_id, &@ast::constr c, &scopes sc,
|
|||
}
|
||||
}
|
||||
|
||||
fn add_constr(&@env e, &def_id d_id, &ty::constr_def c) {
|
||||
e.fn_constrs.insert(d_id,
|
||||
alt (e.fn_constrs.find(d_id)) {
|
||||
fn add_constr(&@env e, node_id id, &ty::constr_def c) {
|
||||
e.fn_constrs.insert(id,
|
||||
alt (e.fn_constrs.find(id)) {
|
||||
case (none) { [c] }
|
||||
case (some(?cs)) { cs + [c] }
|
||||
});
|
||||
|
@ -446,8 +447,8 @@ fn resolve_import(&env e, &@ast::view_item it, &scopes sc) {
|
|||
auto defid;
|
||||
auto ids;
|
||||
alt (it.node) {
|
||||
case (ast::view_item_import(_, ?_ids, ?_defid)) {
|
||||
defid = _defid;
|
||||
case (ast::view_item_import(_, ?_ids, ?_id)) {
|
||||
defid = local_def(_id);
|
||||
ids = _ids;
|
||||
}
|
||||
}
|
||||
|
@ -511,15 +512,15 @@ fn resolve_import(&env e, &@ast::view_item it, &scopes sc) {
|
|||
e.imports.insert(defid._1, resolved(val, typ, md));
|
||||
}
|
||||
}
|
||||
fn remove_if_unresolved(hashmap[ast::def_num, import_state] imports,
|
||||
ast::def_num def_num) {
|
||||
fn remove_if_unresolved(hashmap[ast::node_id, import_state] imports,
|
||||
ast::node_id node_id) {
|
||||
// If we couldn't resolve the import, don't leave it in a partially
|
||||
// resolved state, to avoid having it reported later as a cyclic
|
||||
// import
|
||||
if (imports.contains_key(def_num)) {
|
||||
alt (imports.get(def_num)) {
|
||||
if (imports.contains_key(node_id)) {
|
||||
alt (imports.get(node_id)) {
|
||||
case (resolving(_)) {
|
||||
imports.remove(def_num);
|
||||
imports.remove(node_id);
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
|
@ -605,8 +606,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) ->
|
|||
|
||||
alt (s) {
|
||||
case (scope_crate(?c)) {
|
||||
auto defid = tup(ast::local_crate, -1);
|
||||
ret lookup_in_local_mod(e, defid, sp, id, ns, inside);
|
||||
ret lookup_in_local_mod(e, -1, sp, id, ns, inside);
|
||||
}
|
||||
case (scope_item(?it)) {
|
||||
alt (it.node) {
|
||||
|
@ -634,7 +634,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) ->
|
|||
}
|
||||
case (scope_native_item(?it)) {
|
||||
alt (it.node) {
|
||||
case (ast::native_item_fn(_, _, ?decl, ?ty_params, _, _))
|
||||
case (ast::native_item_fn(_, _, ?decl, ?ty_params, _))
|
||||
{
|
||||
ret lookup_in_fn(id, decl, ty_params, ns);
|
||||
}
|
||||
|
@ -646,7 +646,7 @@ fn lookup_in_scope(&env e, scopes sc, &span sp, &ident id, namespace ns) ->
|
|||
case (scope_loop(?local)) {
|
||||
if (ns == ns_value) {
|
||||
if (str::eq(local.node.ident, id)) {
|
||||
ret some(ast::def_local(local.node.id));
|
||||
ret some(ast::def_local(local_def(local.node.id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -696,16 +696,18 @@ fn lookup_in_ty_params(&ident id, &vec[ast::ty_param] ty_params) ->
|
|||
ret none[def];
|
||||
}
|
||||
|
||||
fn lookup_in_pat(&ident id, &ast::pat pat) -> option::t[def] {
|
||||
fn lookup_in_pat(&ident ident, &ast::pat pat) -> option::t[def] {
|
||||
alt (pat.node) {
|
||||
case (ast::pat_bind(?name, ?defid, _)) {
|
||||
if (str::eq(name, id)) { ret some(ast::def_binding(defid)); }
|
||||
case (ast::pat_bind(?name, ?id)) {
|
||||
if (str::eq(name, ident)) {
|
||||
ret some(ast::def_binding(local_def(id)));
|
||||
}
|
||||
}
|
||||
case (ast::pat_wild(_)) { }
|
||||
case (ast::pat_lit(_, _)) { }
|
||||
case (ast::pat_tag(_, ?pats, _)) {
|
||||
for (@ast::pat p in pats) {
|
||||
auto found = lookup_in_pat(id, *p);
|
||||
auto found = lookup_in_pat(ident, *p);
|
||||
if (!option::is_none(found)) { ret found; }
|
||||
}
|
||||
}
|
||||
|
@ -718,7 +720,9 @@ fn lookup_in_fn(&ident id, &ast::fn_decl decl, &vec[ast::ty_param] ty_params,
|
|||
alt (ns) {
|
||||
case (ns_value) {
|
||||
for (ast::arg a in decl.inputs) {
|
||||
if (str::eq(a.ident, id)) { ret some(ast::def_arg(a.id)); }
|
||||
if (str::eq(a.ident, id)) {
|
||||
ret some(ast::def_arg(local_def(a.id)));
|
||||
}
|
||||
}
|
||||
ret none[def];
|
||||
}
|
||||
|
@ -733,7 +737,7 @@ fn lookup_in_obj(&ident id, &ast::_obj ob, &vec[ast::ty_param] ty_params,
|
|||
case (ns_value) {
|
||||
for (ast::obj_field f in ob.fields) {
|
||||
if (str::eq(f.ident, id)) {
|
||||
ret some(ast::def_obj_field(f.id));
|
||||
ret some(ast::def_obj_field(local_def(f.id)));
|
||||
}
|
||||
}
|
||||
ret none[def];
|
||||
|
@ -751,7 +755,7 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) ->
|
|||
alt (d.node) {
|
||||
case (ast::decl_local(?loc)) {
|
||||
if (ns == ns_value && str::eq(id, loc.node.ident)) {
|
||||
ret some(ast::def_local(loc.node.id));
|
||||
ret some(ast::def_local(local_def(loc.node.id)));
|
||||
}
|
||||
}
|
||||
case (ast::decl_item(?it)) {
|
||||
|
@ -759,14 +763,16 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) ->
|
|||
case (ast::item_tag(?variants, _)) {
|
||||
if (ns == ns_type) {
|
||||
if (str::eq(it.ident, id)) {
|
||||
ret some(ast::def_ty(it.id));
|
||||
ret some(ast::def_ty
|
||||
(local_def(it.id)));
|
||||
}
|
||||
} else if (ns == ns_value) {
|
||||
for (ast::variant v in variants) {
|
||||
if (str::eq(v.node.name, id)) {
|
||||
auto i = v.node.id;
|
||||
ret some(ast::def_variant(it.id,
|
||||
i));
|
||||
ret some(ast::def_variant
|
||||
(local_def(it.id),
|
||||
local_def(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -792,27 +798,39 @@ fn lookup_in_block(&ident id, &ast::block_ b, namespace ns) ->
|
|||
fn found_def_item(&@ast::item i, namespace ns) -> option::t[def] {
|
||||
alt (i.node) {
|
||||
case (ast::item_const(_, _)) {
|
||||
if (ns == ns_value) { ret some(ast::def_const(i.id)); }
|
||||
if (ns == ns_value) {
|
||||
ret some(ast::def_const(local_def(i.id)));
|
||||
}
|
||||
}
|
||||
case (ast::item_fn(_, _)) {
|
||||
if (ns == ns_value) { ret some(ast::def_fn(i.id)); }
|
||||
if (ns == ns_value) {
|
||||
ret some(ast::def_fn(local_def(i.id)));
|
||||
}
|
||||
}
|
||||
case (ast::item_mod(_)) {
|
||||
if (ns == ns_module) { ret some(ast::def_mod(i.id)); }
|
||||
if (ns == ns_module) {
|
||||
ret some(ast::def_mod(local_def(i.id)));
|
||||
}
|
||||
}
|
||||
case (ast::item_native_mod(_)) {
|
||||
if (ns == ns_module) { ret some(ast::def_native_mod(i.id)); }
|
||||
if (ns == ns_module) {
|
||||
ret some(ast::def_native_mod(local_def(i.id)));
|
||||
}
|
||||
}
|
||||
case (ast::item_ty(_, _)) {
|
||||
if (ns == ns_type) { ret some(ast::def_ty(i.id)); }
|
||||
if (ns == ns_type) {
|
||||
ret some(ast::def_ty(local_def(i.id)));
|
||||
}
|
||||
}
|
||||
case (ast::item_tag(_, _)) {
|
||||
if (ns == ns_type) { ret some(ast::def_ty(i.id)); }
|
||||
if (ns == ns_type) {
|
||||
ret some(ast::def_ty(local_def(i.id)));
|
||||
}
|
||||
}
|
||||
case (ast::item_obj(_, _, ?ctor_id)) {
|
||||
alt (ns) {
|
||||
case (ns_value) { ret some(ast::def_obj(ctor_id)); }
|
||||
case (ns_type) { ret some(ast::def_obj(i.id)); }
|
||||
case (ns_value) { ret some(ast::def_obj(local_def(ctor_id)));}
|
||||
case (ns_type) { ret some(ast::def_obj(local_def(i.id))); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
|
@ -850,10 +868,10 @@ fn lookup_in_mod(&env e, def m, &span sp, &ident id, namespace ns, dir dr) ->
|
|||
}
|
||||
alt (m) {
|
||||
case (ast::def_mod(?defid)) {
|
||||
ret lookup_in_local_mod(e, defid, sp, id, ns, dr);
|
||||
ret lookup_in_local_mod(e, defid._1, sp, id, ns, dr);
|
||||
}
|
||||
case (ast::def_native_mod(?defid)) {
|
||||
ret lookup_in_local_native_mod(e, defid, sp, id, ns);
|
||||
ret lookup_in_local_native_mod(e, defid._1, sp, id, ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -861,11 +879,11 @@ fn lookup_in_mod(&env e, def m, &span sp, &ident id, namespace ns, dir dr) ->
|
|||
fn found_view_item(&env e, @ast::view_item vi, namespace ns) ->
|
||||
option::t[def] {
|
||||
alt (vi.node) {
|
||||
case (ast::view_item_use(_, _, _, ?ann)) {
|
||||
ret some(ast::def_mod(tup(e.crate_map.get(ann.id), -1)));
|
||||
case (ast::view_item_use(_, _, ?id)) {
|
||||
ret some(ast::def_mod(tup(e.crate_map.get(id), -1)));
|
||||
}
|
||||
case (ast::view_item_import(_, _, ?defid)) {
|
||||
ret lookup_import(e, defid, ns);
|
||||
case (ast::view_item_import(_, _, ?id)) {
|
||||
ret lookup_import(e, local_def(id), ns);
|
||||
}
|
||||
case (ast::view_item_import_glob(_, ?defid)) {
|
||||
ret none[def]; //will be handled in the fallback glob pass
|
||||
|
@ -894,14 +912,14 @@ fn lookup_import(&env e, def_id defid, namespace ns) -> option::t[def] {
|
|||
}
|
||||
}
|
||||
|
||||
fn lookup_in_local_native_mod(&env e, def_id defid, &span sp, &ident id,
|
||||
fn lookup_in_local_native_mod(&env e, node_id node_id, &span sp, &ident id,
|
||||
namespace ns) -> option::t[def] {
|
||||
ret lookup_in_local_mod(e, defid, sp, id, ns, inside);
|
||||
ret lookup_in_local_mod(e, node_id, sp, id, ns, inside);
|
||||
}
|
||||
|
||||
fn lookup_in_local_mod(&env e, def_id defid, &span sp, &ident id,
|
||||
fn lookup_in_local_mod(&env e, node_id node_id, &span sp, &ident id,
|
||||
namespace ns, dir dr) -> option::t[def] {
|
||||
auto info = e.mod_map.get(defid._1);
|
||||
auto info = e.mod_map.get(node_id);
|
||||
if (dr == outside && !ast::is_exported(id, option::get(info.m))) {
|
||||
// if we're in a native mod, then dr==inside, so info.m is some _mod
|
||||
|
||||
|
@ -947,7 +965,7 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id,
|
|||
ret some[def](matches.(0));
|
||||
} else {
|
||||
for (def match in matches) {
|
||||
alt (e.ast_map.find(ast::def_id_of_def(match))) {
|
||||
alt (e.ast_map.find(ast::def_id_of_def(match)._1)) {
|
||||
case (some(?it)) {
|
||||
e.sess.span_note(it.span,
|
||||
"'" + id + "' is defined here.");
|
||||
|
@ -1001,7 +1019,8 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) ->
|
|||
case (ast::item_tag(?variants, _)) {
|
||||
if (ns == ns_value) {
|
||||
auto vid = variants.(variant_idx).node.id;
|
||||
ret some(ast::def_variant(item.id, vid));
|
||||
ret some(ast::def_variant(local_def(item.id),
|
||||
local_def(vid)));
|
||||
} else { ret none[def]; }
|
||||
}
|
||||
}
|
||||
|
@ -1009,10 +1028,14 @@ fn lookup_in_mie(&env e, &mod_index_entry mie, namespace ns) ->
|
|||
case (mie_native_item(?native_item)) {
|
||||
alt (native_item.node) {
|
||||
case (ast::native_item_ty(_, ?id)) {
|
||||
if (ns == ns_type) { ret some(ast::def_native_ty(id)); }
|
||||
if (ns == ns_type) {
|
||||
ret some(ast::def_native_ty(local_def(id)));
|
||||
}
|
||||
}
|
||||
case (ast::native_item_fn(_, _, _, _, ?id)) {
|
||||
if (ns == ns_value) {
|
||||
ret some(ast::def_native_fn(local_def(id)));
|
||||
}
|
||||
case (ast::native_item_fn(_, _, _, _, ?id, _)) {
|
||||
if (ns == ns_value) { ret some(ast::def_native_fn(id)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1035,8 +1058,8 @@ fn index_mod(&ast::_mod md) -> mod_index {
|
|||
auto index = new_str_hash[list[mod_index_entry]]();
|
||||
for (@ast::view_item it in md.view_items) {
|
||||
alt (it.node) {
|
||||
case (ast::view_item_use(?id, _, _, _)) {
|
||||
add_to_index(index, id, mie_view_item(it));
|
||||
case (ast::view_item_use(?ident, _, _)) {
|
||||
add_to_index(index, ident, mie_view_item(it));
|
||||
}
|
||||
case (ast::view_item_import(?def_ident, _, _)) {
|
||||
add_to_index(index, def_ident, mie_view_item(it));
|
||||
|
@ -1045,7 +1068,7 @@ fn index_mod(&ast::_mod md) -> mod_index {
|
|||
//globbed imports have to be resolved lazily.
|
||||
ast::view_item_import_glob(_, _)) {
|
||||
}
|
||||
case (ast::view_item_export(_)) { }
|
||||
case (ast::view_item_export(_, _)) { }
|
||||
}
|
||||
}
|
||||
for (@ast::item it in md.items) {
|
||||
|
@ -1090,16 +1113,16 @@ fn index_nmod(&ast::native_mod md) -> mod_index {
|
|||
add_to_index(index, def_ident, mie_view_item(it));
|
||||
}
|
||||
case (ast::view_item_import_glob(_, _)) { }
|
||||
case (ast::view_item_export(_)) { }
|
||||
case (ast::view_item_export(_, _)) { }
|
||||
}
|
||||
}
|
||||
for (@ast::native_item it in md.items) {
|
||||
alt (it.node) {
|
||||
case (ast::native_item_ty(?id, _)) {
|
||||
add_to_index(index, id, mie_native_item(it));
|
||||
case (ast::native_item_ty(?ident, _)) {
|
||||
add_to_index(index, ident, mie_native_item(it));
|
||||
}
|
||||
case (ast::native_item_fn(?id, _, _, _, _, _)) {
|
||||
add_to_index(index, id, mie_native_item(it));
|
||||
case (ast::native_item_fn(?ident, _, _, _, _)) {
|
||||
add_to_index(index, ident, mie_native_item(it));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1142,7 +1165,7 @@ fn check_for_collisions(&@env e, &ast::crate c) {
|
|||
// Module indices make checking those relatively simple -- just check each
|
||||
// name for multiple entities in the same namespace.
|
||||
|
||||
for each (@tup(ast::def_num, @indexed_mod) m in e.mod_map.items()) {
|
||||
for each (@tup(ast::node_id, @indexed_mod) m in e.mod_map.items()) {
|
||||
for each (@tup(ident, list[mod_index_entry]) name in
|
||||
m._1.index.items()) {
|
||||
check_mod_name(*e, name._0, name._1);
|
||||
|
@ -1225,7 +1248,7 @@ fn check_arm(@env e, &ast::arm a, &() x, &vt[()] v) {
|
|||
visit::visit_arm(a, x, v);
|
||||
fn walk_pat(checker ch, &@ast::pat p) {
|
||||
alt (p.node) {
|
||||
case (ast::pat_bind(?name, _, _)) { add_name(ch, p.span, name); }
|
||||
case (ast::pat_bind(?name, _)) { add_name(ch, p.span, name); }
|
||||
case (ast::pat_tag(_, ?children, _)) {
|
||||
for (@ast::pat child in children) { walk_pat(ch, child); }
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,7 +4,8 @@ import std::option;
|
|||
import std::option::some;
|
||||
import std::option::none;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_ann;
|
||||
import middle::ty::expr_node_id;
|
||||
import util::common::istr;
|
||||
import util::common::uistr;
|
||||
import util::common::span;
|
||||
import util::common::new_str_hash;
|
||||
|
@ -23,70 +24,69 @@ import aux::crate_ctxt;
|
|||
import aux::add_node;
|
||||
import middle::tstate::ann::empty_ann;
|
||||
|
||||
fn collect_ids_expr(&@expr e, @mutable vec[uint] res) {
|
||||
vec::push(*res, expr_ann(e).id);
|
||||
fn collect_ids_expr(&@expr e, @mutable vec[node_id] res) {
|
||||
vec::push(*res, expr_node_id(e));
|
||||
}
|
||||
|
||||
fn collect_ids_block(&block b, @mutable vec[uint] res) {
|
||||
vec::push(*res, b.node.a.id);
|
||||
fn collect_ids_block(&block b, @mutable vec[node_id] res) {
|
||||
vec::push(*res, b.node.id);
|
||||
}
|
||||
|
||||
fn collect_ids_stmt(&@stmt s, @mutable vec[uint] res) {
|
||||
fn collect_ids_stmt(&@stmt s, @mutable vec[node_id] res) {
|
||||
alt (s.node) {
|
||||
case (stmt_decl(_, ?a)) {
|
||||
log "node_id " + uistr(a.id);
|
||||
case (stmt_decl(_, ?id)) {
|
||||
log "node_id " + istr(id);
|
||||
log_stmt(*s);
|
||||
vec::push(*res, a.id);
|
||||
vec::push(*res, id);
|
||||
}
|
||||
case (stmt_expr(_, ?a)) {
|
||||
log "node_id " + uistr(a.id);
|
||||
case (stmt_expr(_, ?id)) {
|
||||
log "node_id " + istr(id);
|
||||
log_stmt(*s);
|
||||
vec::push(*res, a.id);
|
||||
vec::push(*res, id);
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_ids_local(&@local l, @mutable vec[uint] res) {
|
||||
vec::push(*res, l.node.ann.id);
|
||||
fn collect_ids_local(&@local l, @mutable vec[node_id] res) {
|
||||
vec::push(*res, l.node.id);
|
||||
}
|
||||
|
||||
fn node_ids_in_fn(&_fn f, &span sp, &ident i, &def_id d, &ann a,
|
||||
@mutable vec[uint] res) {
|
||||
fn node_ids_in_fn(&_fn f, &span sp, &ident i, node_id id,
|
||||
@mutable vec[node_id] res) {
|
||||
auto collect_ids = walk::default_visitor();
|
||||
collect_ids =
|
||||
rec(visit_expr_pre=bind collect_ids_expr(_, res),
|
||||
visit_block_pre=bind collect_ids_block(_, res),
|
||||
visit_stmt_pre=bind collect_ids_stmt(_, res),
|
||||
visit_local_pre=bind collect_ids_local(_, res) with collect_ids);
|
||||
walk::walk_fn(collect_ids, f, sp, i, d, a);
|
||||
walk::walk_fn(collect_ids, f, sp, i, id);
|
||||
}
|
||||
|
||||
fn init_vecs(&crate_ctxt ccx, &vec[uint] node_ids, uint len) {
|
||||
for (uint i in node_ids) {
|
||||
log uistr(i) + " |-> " + uistr(len);
|
||||
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);
|
||||
add_node(ccx, i, empty_ann(len));
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_fn(&crate_ctxt ccx, uint num_constraints, &_fn f, &span sp, &ident i,
|
||||
&def_id d, &ann a) {
|
||||
let @mutable vec[uint] node_ids = @mutable [];
|
||||
node_ids_in_fn(f, sp, i, d, a, node_ids);
|
||||
node_id id) {
|
||||
let @mutable vec[node_id] node_ids = @mutable [];
|
||||
node_ids_in_fn(f, sp, i, id, node_ids);
|
||||
auto node_id_vec = *node_ids;
|
||||
init_vecs(ccx, node_id_vec, num_constraints);
|
||||
}
|
||||
|
||||
fn annotate_in_fn(&crate_ctxt ccx, &_fn f, &span sp, &ident i, &def_id f_id,
|
||||
&ann a) {
|
||||
auto f_info = get_fn_info(ccx, f_id);
|
||||
visit_fn(ccx, num_constraints(f_info), f, sp, i, f_id, a);
|
||||
fn annotate_in_fn(&crate_ctxt ccx, &_fn f, &span sp, &ident i, node_id id) {
|
||||
auto f_info = get_fn_info(ccx, id);
|
||||
visit_fn(ccx, num_constraints(f_info), f, sp, i, id);
|
||||
}
|
||||
|
||||
fn annotate_crate(&crate_ctxt ccx, &crate crate) {
|
||||
auto do_ann = walk::default_visitor();
|
||||
do_ann =
|
||||
rec(visit_fn_pre=bind annotate_in_fn(ccx, _, _, _, _, _) with do_ann);
|
||||
rec(visit_fn_pre=bind annotate_in_fn(ccx, _, _, _, _) with do_ann);
|
||||
walk::walk_crate(do_ann, crate);
|
||||
}
|
||||
//
|
||||
|
|
|
@ -10,14 +10,15 @@ import std::option::some;
|
|||
import std::option::maybe;
|
||||
import front::ast;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_ann;
|
||||
import middle::ty::expr_node_id;
|
||||
import util::common;
|
||||
import util::common::span;
|
||||
import util::common::respan;
|
||||
import util::common::log_block;
|
||||
import util::common::new_def_hash;
|
||||
import util::common::new_int_hash;
|
||||
import util::common::new_uint_hash;
|
||||
import util::common::log_expr_err;
|
||||
import util::common::istr;
|
||||
import util::common::uistr;
|
||||
import util::common::lit_eq;
|
||||
import pretty::pprust::path_to_str;
|
||||
|
@ -37,7 +38,6 @@ import tstate::ann::extend_poststate;
|
|||
import tstate::ann::set_precondition;
|
||||
import tstate::ann::set_postcondition;
|
||||
import tstate::ann::ts_ann;
|
||||
import util::common::istr;
|
||||
import pretty::ppaux::constr_args_to_str;
|
||||
import pretty::ppaux::lit_to_str;
|
||||
|
||||
|
@ -210,13 +210,13 @@ tag constraint {
|
|||
|
||||
tag constr__ { ninit(ident); npred(path, vec[@constr_arg_use]); }
|
||||
|
||||
type constr_ = rec(def_id id, constr__ c);
|
||||
type constr_ = rec(node_id id, constr__ c);
|
||||
|
||||
type constr = spanned[constr_];
|
||||
|
||||
type norm_constraint = rec(uint bit_num, constr c);
|
||||
|
||||
type constr_map = @std::map::hashmap[def_id, constraint];
|
||||
type constr_map = @std::map::hashmap[node_id, constraint];
|
||||
|
||||
type fn_info = rec(constr_map constrs, uint num_constraints, controlflow cf);
|
||||
|
||||
|
@ -226,51 +226,53 @@ type node_ann_table = @mutable vec[mutable ts_ann];
|
|||
|
||||
|
||||
/* mapping from function name to fn_info map */
|
||||
type fn_info_map = @std::map::hashmap[def_id, fn_info];
|
||||
type fn_info_map = @std::map::hashmap[node_id, fn_info];
|
||||
|
||||
type fn_ctxt = rec(fn_info enclosing, def_id id, ident name, crate_ctxt ccx);
|
||||
type fn_ctxt = rec(fn_info enclosing, node_id id, ident name, crate_ctxt ccx);
|
||||
|
||||
type crate_ctxt = rec(ty::ctxt tcx, node_ann_table node_anns, fn_info_map fm);
|
||||
|
||||
fn get_fn_info(&crate_ctxt ccx, def_id did) -> fn_info {
|
||||
assert (ccx.fm.contains_key(did));
|
||||
ret ccx.fm.get(did);
|
||||
fn get_fn_info(&crate_ctxt ccx, node_id id) -> fn_info {
|
||||
assert (ccx.fm.contains_key(id));
|
||||
ret ccx.fm.get(id);
|
||||
}
|
||||
|
||||
fn add_node(&crate_ctxt ccx, uint i, &ts_ann a) {
|
||||
fn add_node(&crate_ctxt ccx, node_id i, &ts_ann a) {
|
||||
auto sz = len(*ccx.node_anns);
|
||||
if (sz <= i) { grow(*ccx.node_anns, i - sz + 1u, empty_ann(0u)); }
|
||||
if (sz <= i as uint) {
|
||||
grow(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u));
|
||||
}
|
||||
ccx.node_anns.(i) = a;
|
||||
}
|
||||
|
||||
fn get_ts_ann(&crate_ctxt ccx, uint i) -> option::t[ts_ann] {
|
||||
if (i < len(*ccx.node_anns)) {
|
||||
fn get_ts_ann(&crate_ctxt ccx, node_id i) -> option::t[ts_ann] {
|
||||
if (i as uint < len(*ccx.node_anns)) {
|
||||
ret some[ts_ann](ccx.node_anns.(i));
|
||||
} else { ret none[ts_ann]; }
|
||||
}
|
||||
|
||||
|
||||
/********* utils ********/
|
||||
fn ann_to_ts_ann(&crate_ctxt ccx, &ann a) -> ts_ann {
|
||||
alt (get_ts_ann(ccx, a.id)) {
|
||||
fn node_id_to_ts_ann(&crate_ctxt ccx, node_id id) -> ts_ann {
|
||||
alt (get_ts_ann(ccx, id)) {
|
||||
case (none) {
|
||||
log_err "ann_to_ts_ann: no ts_ann for node_id " + uistr(a.id);
|
||||
log_err "node_id_to_ts_ann: no ts_ann for node_id " + istr(id);
|
||||
fail;
|
||||
}
|
||||
case (some(?t)) { ret t; }
|
||||
}
|
||||
}
|
||||
|
||||
fn ann_to_poststate(&crate_ctxt ccx, ann a) -> poststate {
|
||||
log "ann_to_poststate";
|
||||
ret ann_to_ts_ann(ccx, a).states.poststate;
|
||||
fn node_id_to_poststate(&crate_ctxt ccx, node_id id) -> poststate {
|
||||
log "node_id_to_poststate";
|
||||
ret node_id_to_ts_ann(ccx, id).states.poststate;
|
||||
}
|
||||
|
||||
fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann {
|
||||
log "stmt_to_ann";
|
||||
alt (s.node) {
|
||||
case (stmt_decl(_, ?a)) { ret ann_to_ts_ann(ccx, a); }
|
||||
case (stmt_expr(_, ?a)) { ret ann_to_ts_ann(ccx, a); }
|
||||
case (stmt_decl(_, ?id)) { ret node_id_to_ts_ann(ccx, id); }
|
||||
case (stmt_expr(_, ?id)) { ret node_id_to_ts_ann(ccx, id); }
|
||||
case (stmt_crate_directive(_)) {
|
||||
log_err "expecting an annotated statement here";
|
||||
fail;
|
||||
|
@ -282,14 +284,14 @@ fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann {
|
|||
/* fails if e has no annotation */
|
||||
fn expr_states(&crate_ctxt ccx, @expr e) -> pre_and_post_state {
|
||||
log "expr_states";
|
||||
ret ann_to_ts_ann(ccx, expr_ann(e)).states;
|
||||
ret node_id_to_ts_ann(ccx, expr_node_id(e)).states;
|
||||
}
|
||||
|
||||
|
||||
/* fails if e has no annotation */
|
||||
fn expr_pp(&crate_ctxt ccx, @expr e) -> pre_and_post {
|
||||
log "expr_pp";
|
||||
ret ann_to_ts_ann(ccx, expr_ann(e)).conditions;
|
||||
ret node_id_to_ts_ann(ccx, expr_node_id(e)).conditions;
|
||||
}
|
||||
|
||||
fn stmt_pp(&crate_ctxt ccx, &stmt s) -> pre_and_post {
|
||||
|
@ -300,7 +302,7 @@ fn stmt_pp(&crate_ctxt ccx, &stmt s) -> pre_and_post {
|
|||
/* fails if b has no annotation */
|
||||
fn block_pp(&crate_ctxt ccx, &block b) -> pre_and_post {
|
||||
log "block_pp";
|
||||
ret ann_to_ts_ann(ccx, b.node.a).conditions;
|
||||
ret node_id_to_ts_ann(ccx, b.node.id).conditions;
|
||||
}
|
||||
|
||||
fn clear_pp(pre_and_post pp) {
|
||||
|
@ -308,14 +310,14 @@ fn clear_pp(pre_and_post pp) {
|
|||
ann::clear(pp.postcondition);
|
||||
}
|
||||
|
||||
fn clear_precond(&crate_ctxt ccx, &ann a) {
|
||||
auto pp = ann_to_ts_ann(ccx, a);
|
||||
fn clear_precond(&crate_ctxt ccx, node_id id) {
|
||||
auto pp = node_id_to_ts_ann(ccx, id);
|
||||
ann::clear(pp.conditions.precondition);
|
||||
}
|
||||
|
||||
fn block_states(&crate_ctxt ccx, &block b) -> pre_and_post_state {
|
||||
log "block_states";
|
||||
ret ann_to_ts_ann(ccx, b.node.a).states;
|
||||
ret node_id_to_ts_ann(ccx, b.node.id).states;
|
||||
}
|
||||
|
||||
fn stmt_states(&crate_ctxt ccx, &stmt s) -> pre_and_post_state {
|
||||
|
@ -376,60 +378,63 @@ fn block_poststate(&crate_ctxt ccx, &block b) -> poststate {
|
|||
|
||||
|
||||
/* sets the pre_and_post for an ann */
|
||||
fn with_pp(&crate_ctxt ccx, &ann a, pre_and_post p) {
|
||||
add_node(ccx, a.id, @rec(conditions=p, states=empty_states(pps_len(p))));
|
||||
fn with_pp(&crate_ctxt ccx, node_id id, pre_and_post p) {
|
||||
add_node(ccx, id, @rec(conditions=p, states=empty_states(pps_len(p))));
|
||||
}
|
||||
|
||||
fn set_prestate_ann(&crate_ctxt ccx, &ann a, &prestate pre) -> bool {
|
||||
fn set_prestate_ann(&crate_ctxt ccx, node_id id, &prestate pre) -> bool {
|
||||
log "set_prestate_ann";
|
||||
ret set_prestate(ann_to_ts_ann(ccx, a), pre);
|
||||
ret set_prestate(node_id_to_ts_ann(ccx, id), pre);
|
||||
}
|
||||
|
||||
fn extend_prestate_ann(&crate_ctxt ccx, &ann a, &prestate pre) -> bool {
|
||||
fn extend_prestate_ann(&crate_ctxt ccx, node_id id, &prestate pre) -> bool {
|
||||
log "extend_prestate_ann";
|
||||
ret extend_prestate(ann_to_ts_ann(ccx, a).states.prestate, pre);
|
||||
ret extend_prestate(node_id_to_ts_ann(ccx, id).states.prestate, pre);
|
||||
}
|
||||
|
||||
fn set_poststate_ann(&crate_ctxt ccx, &ann a, &poststate post) -> bool {
|
||||
fn set_poststate_ann(&crate_ctxt ccx, node_id id, &poststate post) -> bool {
|
||||
log "set_poststate_ann";
|
||||
ret set_poststate(ann_to_ts_ann(ccx, a), post);
|
||||
ret set_poststate(node_id_to_ts_ann(ccx, id), post);
|
||||
}
|
||||
|
||||
fn extend_poststate_ann(&crate_ctxt ccx, &ann a, &poststate post) -> bool {
|
||||
fn extend_poststate_ann(&crate_ctxt ccx, node_id id, &poststate post)
|
||||
-> bool {
|
||||
log "extend_poststate_ann";
|
||||
ret extend_poststate(ann_to_ts_ann(ccx, a).states.poststate, post);
|
||||
ret extend_poststate(node_id_to_ts_ann(ccx, id).states.poststate, post);
|
||||
}
|
||||
|
||||
fn set_pre_and_post(&crate_ctxt ccx, &ann a, &precond pre, &postcond post) {
|
||||
fn set_pre_and_post(&crate_ctxt ccx, node_id id, &precond pre,
|
||||
&postcond post) {
|
||||
log "set_pre_and_post";
|
||||
auto t = ann_to_ts_ann(ccx, a);
|
||||
auto t = node_id_to_ts_ann(ccx, id);
|
||||
set_precondition(t, pre);
|
||||
set_postcondition(t, post);
|
||||
}
|
||||
|
||||
fn copy_pre_post(&crate_ctxt ccx, &ann a, &@expr sub) {
|
||||
fn copy_pre_post(&crate_ctxt ccx, node_id id, &@expr sub) {
|
||||
log "set_pre_and_post";
|
||||
auto p = expr_pp(ccx, sub);
|
||||
copy_pre_post_(ccx, a, p.precondition, p.postcondition);
|
||||
copy_pre_post_(ccx, id, p.precondition, p.postcondition);
|
||||
}
|
||||
|
||||
fn copy_pre_post_(&crate_ctxt ccx, &ann a, &prestate pre, &poststate post) {
|
||||
fn copy_pre_post_(&crate_ctxt ccx, node_id id, &prestate pre,
|
||||
&poststate post) {
|
||||
log "set_pre_and_post";
|
||||
auto t = ann_to_ts_ann(ccx, a);
|
||||
auto t = node_id_to_ts_ann(ccx, id);
|
||||
set_precondition(t, pre);
|
||||
set_postcondition(t, post);
|
||||
}
|
||||
|
||||
/* sets all bits to *1* */
|
||||
fn set_postcond_false(&crate_ctxt ccx, &ann a) {
|
||||
auto p = ann_to_ts_ann(ccx, a);
|
||||
fn set_postcond_false(&crate_ctxt ccx, node_id id) {
|
||||
auto p = node_id_to_ts_ann(ccx, id);
|
||||
ann::set(p.conditions.postcondition);
|
||||
}
|
||||
|
||||
fn pure_exp(&crate_ctxt ccx, &ann a, &prestate p) -> bool {
|
||||
fn pure_exp(&crate_ctxt ccx, node_id id, &prestate p) -> bool {
|
||||
auto changed = false;
|
||||
changed = extend_prestate_ann(ccx, a, p) || changed;
|
||||
changed = extend_poststate_ann(ccx, a, p) || changed;
|
||||
changed = extend_prestate_ann(ccx, id, p) || changed;
|
||||
changed = extend_poststate_ann(ccx, id, p) || changed;
|
||||
ret changed;
|
||||
}
|
||||
|
||||
|
@ -449,49 +454,41 @@ fn num_constraints(fn_info m) -> uint { ret m.num_constraints; }
|
|||
|
||||
fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
|
||||
let vec[mutable ts_ann] na = vec::empty_mut();
|
||||
ret rec(tcx=cx, node_anns=@mutable na, fm=@new_def_hash[fn_info]());
|
||||
ret rec(tcx=cx, node_anns=@mutable na, fm=@new_int_hash[fn_info]());
|
||||
}
|
||||
|
||||
fn controlflow_def_id(&crate_ctxt ccx, &def_id d) -> controlflow {
|
||||
alt (ccx.fm.find(d)) {
|
||||
case (some(?fi)) { ret fi.cf; }
|
||||
case (none) { ret return; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Use e's type to determine whether it returns.
|
||||
If it has a function type with a ! annotation,
|
||||
the answer is noreturn. */
|
||||
fn controlflow_expr(&crate_ctxt ccx, @expr e) -> controlflow {
|
||||
alt (ty::struct(ccx.tcx, ty::ann_to_type(ccx.tcx, expr_ann(e)))) {
|
||||
alt (ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, expr_node_id(e)))) {
|
||||
case (ty::ty_fn(_, _, _, ?cf, _)) { ret cf; }
|
||||
case (_) { ret return; }
|
||||
}
|
||||
}
|
||||
|
||||
fn constraints_expr(&ty::ctxt cx, @expr e) -> vec[@ty::constr_def] {
|
||||
alt (ty::struct(cx, ty::ann_to_type(cx, expr_ann(e)))) {
|
||||
alt (ty::struct(cx, ty::node_id_to_type(cx, expr_node_id(e)))) {
|
||||
case (ty::ty_fn(_, _, _, _, ?cs)) { ret cs; }
|
||||
case (_) { ret []; }
|
||||
}
|
||||
}
|
||||
|
||||
fn ann_to_def_strict(&ty::ctxt cx, &ann a) -> def {
|
||||
alt (cx.def_map.find(a.id)) {
|
||||
fn node_id_to_def_strict(&ty::ctxt cx, node_id id) -> def {
|
||||
alt (cx.def_map.find(id)) {
|
||||
case (none) {
|
||||
log_err "ann_to_def: node_id " + uistr(a.id) + " has no def";
|
||||
log_err "node_id_to_def: node_id " + istr(id) + " has no def";
|
||||
fail;
|
||||
}
|
||||
case (some(?d)) { ret d; }
|
||||
}
|
||||
}
|
||||
|
||||
fn ann_to_def(&crate_ctxt ccx, &ann a) -> option::t[def] {
|
||||
ret ccx.tcx.def_map.find(a.id);
|
||||
fn node_id_to_def(&crate_ctxt ccx, node_id id) -> option::t[def] {
|
||||
ret ccx.tcx.def_map.find(id);
|
||||
}
|
||||
|
||||
fn norm_a_constraint(&def_id id, &constraint c) -> vec[norm_constraint] {
|
||||
fn norm_a_constraint(node_id id, &constraint c) -> vec[norm_constraint] {
|
||||
alt (c) {
|
||||
case (cinit(?n, ?sp, ?i)) {
|
||||
ret [rec(bit_num=n, c=respan(sp, rec(id=id, c=ninit(i))))];
|
||||
|
@ -515,7 +512,7 @@ fn norm_a_constraint(&def_id id, &constraint c) -> vec[norm_constraint] {
|
|||
// non-exhaustive match in trans.
|
||||
fn constraints(&fn_ctxt fcx) -> vec[norm_constraint] {
|
||||
let vec[norm_constraint] res = [];
|
||||
for each (@tup(def_id, constraint) p in fcx.enclosing.constrs.items()) {
|
||||
for each (@tup(node_id, constraint) p in fcx.enclosing.constrs.items()) {
|
||||
res += norm_a_constraint(p._0, p._1);
|
||||
}
|
||||
ret res;
|
||||
|
@ -536,14 +533,14 @@ fn match_args(&fn_ctxt fcx, vec[pred_desc] occs, vec[@constr_arg_use] occ) ->
|
|||
fcx.ccx.tcx.sess.bug("match_args: no match for occurring args");
|
||||
}
|
||||
|
||||
fn def_id_for_constr(ty::ctxt tcx, uint t) -> def_id {
|
||||
fn node_id_for_constr(ty::ctxt tcx, node_id t) -> node_id {
|
||||
alt (tcx.def_map.find(t)) {
|
||||
case (none) {
|
||||
tcx.sess.bug("def_id_for_constr: bad node_id " + uistr(t));
|
||||
tcx.sess.bug("node_id_for_constr: bad node_id " + istr(t));
|
||||
}
|
||||
case (some(def_fn(?i))) { ret i; }
|
||||
case (some(def_fn(?i))) { ret i._1; }
|
||||
case (_) {
|
||||
tcx.sess.bug("def_id_for_constr: pred is not a function");
|
||||
tcx.sess.bug("node_id_for_constr: pred is not a function");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -580,9 +577,9 @@ fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr {
|
|||
// typechecker bug
|
||||
expr_call(?operator, ?args, _)) {
|
||||
alt (operator.node) {
|
||||
case (expr_path(?p, ?a)) {
|
||||
case (expr_path(?p, ?id)) {
|
||||
ret respan(e.span,
|
||||
rec(id=def_id_for_constr(tcx, a.id),
|
||||
rec(id=node_id_for_constr(tcx, id),
|
||||
c=npred(p,
|
||||
exprs_to_constr_args(tcx, args))));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import aux::expr_precond;
|
|||
import aux::block_prestate;
|
||||
import aux::expr_prestate;
|
||||
import aux::stmt_prestate;
|
||||
import tstate::aux::ann_to_ts_ann;
|
||||
import tstate::aux::node_id_to_ts_ann;
|
||||
import tstate::ann::pre_and_post;
|
||||
import tstate::ann::precond;
|
||||
import tstate::ann::postcond;
|
||||
|
@ -136,9 +136,9 @@ fn intersect_postconds(&vec[postcond] pcs) -> postcond {
|
|||
ret intersect_postconds_go(bitv::clone(pcs.(0)), pcs);
|
||||
}
|
||||
|
||||
fn gen(&fn_ctxt fcx, &ann a, &constr_ c) -> bool {
|
||||
fn gen(&fn_ctxt fcx, node_id id, &constr_ c) -> bool {
|
||||
ret set_in_postcond(bit_num(fcx, c),
|
||||
ann_to_ts_ann(fcx.ccx, a).conditions);
|
||||
node_id_to_ts_ann(fcx.ccx, id).conditions);
|
||||
}
|
||||
|
||||
fn declare_var(&fn_ctxt fcx, &constr_ c, prestate pre) -> prestate {
|
||||
|
@ -149,19 +149,19 @@ fn declare_var(&fn_ctxt fcx, &constr_ c, prestate pre) -> prestate {
|
|||
ret res;
|
||||
}
|
||||
|
||||
fn relax_precond_block_non_recursive(&fn_ctxt fcx, uint i, &block b) {
|
||||
relax_precond(i, block_precond(fcx.ccx, b));
|
||||
fn relax_precond_block_non_recursive(&fn_ctxt fcx, node_id i, &block b) {
|
||||
relax_precond(i as uint, block_precond(fcx.ccx, b));
|
||||
}
|
||||
|
||||
fn relax_precond_expr(&fn_ctxt fcx, uint i, &@expr e) {
|
||||
relax_precond(i, expr_precond(fcx.ccx, e));
|
||||
fn relax_precond_expr(&fn_ctxt fcx, node_id i, &@expr e) {
|
||||
relax_precond(i as uint, expr_precond(fcx.ccx, e));
|
||||
}
|
||||
|
||||
fn relax_precond_stmt(&fn_ctxt fcx, uint i, &@stmt s) {
|
||||
relax_precond(i, stmt_precond(fcx.ccx, *s));
|
||||
fn relax_precond_stmt(&fn_ctxt fcx, node_id i, &@stmt s) {
|
||||
relax_precond(i as uint, stmt_precond(fcx.ccx, *s));
|
||||
}
|
||||
|
||||
fn relax_precond_block(&fn_ctxt fcx, uint i, &block b) {
|
||||
fn relax_precond_block(&fn_ctxt fcx, node_id i, &block b) {
|
||||
relax_precond_block_non_recursive(fcx, i, b);
|
||||
// FIXME: should use visit instead
|
||||
// could at least generalize this pattern
|
||||
|
@ -184,14 +184,16 @@ fn relax_precond_block(&fn_ctxt fcx, uint i, &block b) {
|
|||
walk::walk_block(v, b);
|
||||
}
|
||||
|
||||
fn gen_poststate(&fn_ctxt fcx, &ann a, &constr_ c) -> bool {
|
||||
fn gen_poststate(&fn_ctxt fcx, node_id id, &constr_ c) -> bool {
|
||||
log "gen_poststate";
|
||||
ret set_in_poststate(bit_num(fcx, c), ann_to_ts_ann(fcx.ccx, a).states);
|
||||
ret set_in_poststate(bit_num(fcx, c),
|
||||
node_id_to_ts_ann(fcx.ccx, id).states);
|
||||
}
|
||||
|
||||
fn kill_poststate(&fn_ctxt fcx, &ann a, &constr_ c) -> bool {
|
||||
fn kill_poststate(&fn_ctxt fcx, node_id id, &constr_ c) -> bool {
|
||||
log "kill_poststate";
|
||||
ret clear_in_poststate(bit_num(fcx, c), ann_to_ts_ann(fcx.ccx, a).states);
|
||||
ret clear_in_poststate(bit_num(fcx, c),
|
||||
node_id_to_ts_ann(fcx.ccx, id).states);
|
||||
}
|
||||
//
|
||||
// Local Variables:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
import front::ast;
|
||||
import front::ast::method;
|
||||
import front::ast::ann;
|
||||
import front::ast::item;
|
||||
import front::ast::item_fn;
|
||||
import front::ast::_fn;
|
||||
|
@ -9,7 +8,9 @@ import front::ast::obj_field;
|
|||
import front::ast::_obj;
|
||||
import front::ast::stmt;
|
||||
import front::ast::ident;
|
||||
import front::ast::node_id;
|
||||
import front::ast::def_id;
|
||||
import front::ast::local_def;
|
||||
import front::ast::ty_param;
|
||||
import front::ast::crate;
|
||||
import front::ast::return;
|
||||
|
@ -118,8 +119,8 @@ fn check_states_stmt(&fn_ctxt fcx, &@stmt s) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a,
|
||||
&span sp, &ident i, &def_id d) {
|
||||
fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, node_id id,
|
||||
&span sp, &ident i) {
|
||||
/* Postorder traversal instead of pre is important
|
||||
because we want the smallest possible erroneous statement
|
||||
or expression. */
|
||||
|
@ -141,13 +142,13 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a,
|
|||
keep_going=bind kg(keepgoing)
|
||||
with walk::default_visitor());
|
||||
|
||||
walk::walk_fn(v, f, sp, i, d, a);
|
||||
walk::walk_fn(v, f, sp, i, id);
|
||||
|
||||
/* Finally, check that the return value is initialized */
|
||||
auto post = aux::block_poststate(fcx.ccx, f.body);
|
||||
let aux::constr_ ret_c = rec(id=fcx.id, c=aux::ninit(fcx.name));
|
||||
if (f.proto == ast::proto_fn && !promises(fcx, post, ret_c) &&
|
||||
!type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, a)) &&
|
||||
!type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, id)) &&
|
||||
f.decl.cf == return) {
|
||||
fcx.ccx.tcx.sess.span_note(f.body.span,
|
||||
"In function " + fcx.name +
|
||||
|
@ -171,8 +172,7 @@ fn check_states_against_conditions(&fn_ctxt fcx, &_fn f, &ann a,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_fn_states(&fn_ctxt fcx, &_fn f, &ann a, &span sp, &ident i,
|
||||
&def_id d) {
|
||||
fn check_fn_states(&fn_ctxt fcx, &_fn f, node_id id, &span sp, &ident i) {
|
||||
/* Compute the pre- and post-states for this function */
|
||||
|
||||
auto g = find_pre_post_state_fn;
|
||||
|
@ -180,17 +180,16 @@ fn check_fn_states(&fn_ctxt fcx, &_fn f, &ann a, &span sp, &ident i,
|
|||
/* Now compare each expr's pre-state to its precondition
|
||||
and post-state to its postcondition */
|
||||
|
||||
check_states_against_conditions(fcx, f, a, sp, i, d);
|
||||
check_states_against_conditions(fcx, f, id, sp, i);
|
||||
}
|
||||
|
||||
fn fn_states(&crate_ctxt ccx, &_fn f, &span sp, &ident i, &def_id id,
|
||||
&ann a) {
|
||||
fn fn_states(&crate_ctxt ccx, &_fn f, &span sp, &ident i, node_id id) {
|
||||
/* Look up the var-to-bit-num map for this function */
|
||||
|
||||
assert (ccx.fm.contains_key(id));
|
||||
auto f_info = ccx.fm.get(id);
|
||||
auto fcx = rec(enclosing=f_info, id=id, name=i, ccx=ccx);
|
||||
check_fn_states(fcx, f, a, sp, i, id);
|
||||
check_fn_states(fcx, f, id, sp, i);
|
||||
}
|
||||
|
||||
fn check_crate(ty::ctxt cx, @crate crate) {
|
||||
|
@ -205,7 +204,7 @@ fn check_crate(ty::ctxt cx, @crate crate) {
|
|||
|
||||
auto do_pre_post = walk::default_visitor();
|
||||
do_pre_post =
|
||||
rec(visit_fn_post=bind fn_pre_post(ccx, _, _, _, _, _)
|
||||
rec(visit_fn_post=bind fn_pre_post(ccx, _, _, _, _)
|
||||
with do_pre_post);
|
||||
walk::walk_crate(do_pre_post, *crate);
|
||||
/* Check the pre- and postcondition against the pre- and poststate
|
||||
|
@ -213,7 +212,7 @@ fn check_crate(ty::ctxt cx, @crate crate) {
|
|||
|
||||
auto do_states = walk::default_visitor();
|
||||
do_states =
|
||||
rec(visit_fn_post=bind fn_states(ccx, _, _, _, _, _) with do_states);
|
||||
rec(visit_fn_post=bind fn_states(ccx, _, _, _, _) with do_states);
|
||||
walk::walk_crate(do_states, *crate);
|
||||
}
|
||||
//
|
||||
|
|
|
@ -18,7 +18,8 @@ import aux::num_constraints;
|
|||
import aux::constr_map;
|
||||
import aux::expr_to_constr;
|
||||
import aux::constraints_expr;
|
||||
import aux::ann_to_def_strict;
|
||||
import aux::node_id_to_def_strict;
|
||||
import util::common::new_int_hash;
|
||||
import util::common::new_def_hash;
|
||||
import util::common::uistr;
|
||||
import util::common::span;
|
||||
|
@ -42,10 +43,10 @@ fn collect_pred(&ctxt cx, &@expr e) {
|
|||
}
|
||||
// If it's a call, generate appropriate instances of the
|
||||
// call's constraints.
|
||||
case (expr_call(?operator, ?operands, ?a)) {
|
||||
case (expr_call(?operator, ?operands, _)) {
|
||||
for (@ty::constr_def c in constraints_expr(cx.tcx, operator)) {
|
||||
let aux::constr ct = respan(c.span,
|
||||
rec(id=c.node.id,
|
||||
rec(id=c.node.id._1,
|
||||
c=aux::substitute_constr_args(cx.tcx,
|
||||
operands, c)));
|
||||
vec::push(*cx.cs, ct);
|
||||
|
@ -55,14 +56,14 @@ fn collect_pred(&ctxt cx, &@expr e) {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_locals(&ty::ctxt tcx, &_fn f, &span sp, &ident i, &def_id d, &ann a)
|
||||
fn find_locals(&ty::ctxt tcx, &_fn f, &span sp, &ident i, node_id id)
|
||||
-> ctxt {
|
||||
let ctxt cx = rec(cs=@mutable vec::alloc(0u), tcx=tcx);
|
||||
auto visitor = walk::default_visitor();
|
||||
visitor =
|
||||
rec(visit_local_pre=bind collect_local(cx, _),
|
||||
visit_expr_pre=bind collect_pred(cx, _) with visitor);
|
||||
walk_fn(visitor, f, sp, i, d, a);
|
||||
walk_fn(visitor, f, sp, i, id);
|
||||
ret cx;
|
||||
}
|
||||
|
||||
|
@ -103,14 +104,14 @@ fn add_constraint(&ty::ctxt tcx, aux::constr c, uint next, constr_map tbl) ->
|
|||
/* builds a table mapping each local var defined in f
|
||||
to a bit number in the precondition/postcondition vectors */
|
||||
fn mk_fn_info(&crate_ctxt ccx, &_fn f, &span f_sp, &ident f_name,
|
||||
&def_id f_id, &ann a) {
|
||||
auto res_map = @new_def_hash[constraint]();
|
||||
node_id id) {
|
||||
auto res_map = @new_int_hash[constraint]();
|
||||
let uint next = 0u;
|
||||
let vec[arg] f_args = f.decl.inputs;
|
||||
/* ignore args, which we know are initialized;
|
||||
just collect locally declared vars */
|
||||
|
||||
let ctxt cx = find_locals(ccx.tcx, f, f_sp, f_name, f_id, a);
|
||||
let ctxt cx = find_locals(ccx.tcx, f, f_sp, f_name, id);
|
||||
/* now we have to add bit nums for both the constraints
|
||||
and the variables... */
|
||||
|
||||
|
@ -120,13 +121,13 @@ fn mk_fn_info(&crate_ctxt ccx, &_fn f, &span f_sp, &ident f_name,
|
|||
/* add a pseudo-entry for the function's return value
|
||||
we can safely use the function's name itself for this purpose */
|
||||
|
||||
add_constraint(cx.tcx, respan(f_sp, rec(id=f_id, c=ninit(f_name))), next,
|
||||
add_constraint(cx.tcx, respan(f_sp, rec(id=id, c=ninit(f_name))), next,
|
||||
res_map);
|
||||
auto res =
|
||||
rec(constrs=res_map,
|
||||
num_constraints=vec::len(*cx.cs) + 1u,
|
||||
cf=f.decl.cf);
|
||||
ccx.fm.insert(f_id, res);
|
||||
ccx.fm.insert(id, res);
|
||||
log f_name + " has " + uistr(num_constraints(res)) + " constraints";
|
||||
}
|
||||
|
||||
|
@ -137,7 +138,7 @@ fn mk_fn_info(&crate_ctxt ccx, &_fn f, &span f_sp, &ident f_name,
|
|||
fn mk_f_to_fn_info(&crate_ctxt ccx, @crate c) {
|
||||
let ast_visitor vars_visitor = walk::default_visitor();
|
||||
vars_visitor =
|
||||
rec(visit_fn_pre=bind mk_fn_info(ccx, _, _, _, _, _)
|
||||
rec(visit_fn_pre=bind mk_fn_info(ccx, _, _, _, _)
|
||||
with vars_visitor);
|
||||
walk_crate(vars_visitor, *c);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import std::option;
|
|||
import std::option::none;
|
||||
import std::option::some;
|
||||
|
||||
// FIXME: needs to be tstate::ann because ann is also a type name...
|
||||
// that's probably a bug.
|
||||
import tstate::ann::pre_and_post;
|
||||
import tstate::ann::get_post;
|
||||
import tstate::ann::postcond;
|
||||
|
@ -40,9 +38,9 @@ import aux::expr_poststate;
|
|||
import aux::block_postcond;
|
||||
import aux::fn_info;
|
||||
import aux::log_pp;
|
||||
import aux::ann_to_def;
|
||||
import aux::ann_to_def_strict;
|
||||
import aux::ann_to_ts_ann;
|
||||
import aux::node_id_to_def;
|
||||
import aux::node_id_to_def_strict;
|
||||
import aux::node_id_to_ts_ann;
|
||||
import aux::set_postcond_false;
|
||||
import aux::controlflow_expr;
|
||||
import aux::expr_to_constr;
|
||||
|
@ -62,7 +60,8 @@ import bitvectors::bit_num;
|
|||
import bitvectors::gen;
|
||||
import bitvectors::relax_precond_block;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_ann;
|
||||
import middle::ty::expr_node_id;
|
||||
import util::common::new_int_hash;
|
||||
import util::common::new_def_hash;
|
||||
import util::common::uistr;
|
||||
import util::common::log_expr;
|
||||
|
@ -107,10 +106,10 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) {
|
|||
// make a fake fcx
|
||||
|
||||
auto fake_fcx =
|
||||
rec(enclosing=rec(constrs=@new_def_hash[constraint](),
|
||||
rec(enclosing=rec(constrs=@new_int_hash[constraint](),
|
||||
num_constraints=0u,
|
||||
cf=return),
|
||||
id=tup(0, 0),
|
||||
id=0,
|
||||
name="",
|
||||
ccx=ccx);
|
||||
find_pre_post_expr(fake_fcx, e);
|
||||
|
@ -137,7 +136,7 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) {
|
|||
sets the precondition in a to be the result of combining
|
||||
the preconditions for <args>, and the postcondition in a to
|
||||
be the union of all postconditions for <args> */
|
||||
fn find_pre_post_exprs(&fn_ctxt fcx, &vec[@expr] args, ann a) {
|
||||
fn find_pre_post_exprs(&fn_ctxt fcx, &vec[@expr] args, node_id id) {
|
||||
if (vec::len[@expr](args) > 0u) {
|
||||
log "find_pre_post_exprs: oper =";
|
||||
log_expr(*args.(0));
|
||||
|
@ -154,18 +153,18 @@ fn find_pre_post_exprs(&fn_ctxt fcx, &vec[@expr] args, ann a) {
|
|||
auto g = bind get_pp(fcx.ccx, _);
|
||||
auto pps = vec::map[@expr, pre_and_post](g, args);
|
||||
auto h = get_post;
|
||||
set_pre_and_post(fcx.ccx, a, seq_preconds(fcx, pps),
|
||||
set_pre_and_post(fcx.ccx, id, seq_preconds(fcx, pps),
|
||||
union_postconds(nv,
|
||||
vec::map[pre_and_post,
|
||||
postcond](h, pps)));
|
||||
}
|
||||
|
||||
fn find_pre_post_loop(&fn_ctxt fcx, &@local l, &@expr index, &block body,
|
||||
&ann a) {
|
||||
node_id id) {
|
||||
find_pre_post_expr(fcx, index);
|
||||
find_pre_post_block(fcx, body);
|
||||
auto v_init = rec(id=l.node.id, c=ninit(l.node.ident));
|
||||
relax_precond_block(fcx, bit_num(fcx, v_init), body);
|
||||
relax_precond_block(fcx, bit_num(fcx, v_init) as node_id, body);
|
||||
|
||||
auto loop_precond =
|
||||
seq_preconds(fcx,
|
||||
|
@ -174,14 +173,14 @@ fn find_pre_post_loop(&fn_ctxt fcx, &@local l, &@expr index, &block body,
|
|||
auto loop_postcond =
|
||||
intersect_postconds([expr_postcond(fcx.ccx, index),
|
||||
block_postcond(fcx.ccx, body)]);
|
||||
copy_pre_post_(fcx.ccx, a, loop_precond, loop_postcond);
|
||||
copy_pre_post_(fcx.ccx, id, loop_precond, loop_postcond);
|
||||
}
|
||||
|
||||
// Generates a pre/post assuming that a is the
|
||||
// annotation for an if-expression with consequent conseq
|
||||
// and alternative maybe_alt
|
||||
fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
||||
&option::t[@expr] maybe_alt, &ann a, &if_ty chck) {
|
||||
&option::t[@expr] maybe_alt, node_id id, &if_ty chck) {
|
||||
auto num_local_vars = num_constraints(fcx.enclosing);
|
||||
find_pre_post_expr(fcx, antec);
|
||||
find_pre_post_block(fcx, conseq);
|
||||
|
@ -190,7 +189,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
alt (chck) {
|
||||
case (if_check) {
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, antec);
|
||||
gen(fcx, expr_ann(antec), c.node);
|
||||
gen(fcx, expr_node_id(antec), c.node);
|
||||
}
|
||||
case (_) {}
|
||||
}
|
||||
|
@ -199,7 +198,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
seq_preconds(fcx,
|
||||
[expr_pp(fcx.ccx, antec),
|
||||
block_pp(fcx.ccx, conseq)]);
|
||||
set_pre_and_post(fcx.ccx, a, precond_res,
|
||||
set_pre_and_post(fcx.ccx, id, precond_res,
|
||||
expr_poststate(fcx.ccx, antec));
|
||||
}
|
||||
case (some(?altern)) {
|
||||
|
@ -223,7 +222,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
alt (chck) {
|
||||
case (if_check) {
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, antec);
|
||||
gen(fcx, expr_ann(antec), c.node);
|
||||
gen(fcx, expr_node_id(antec), c.node);
|
||||
}
|
||||
case (_) {}
|
||||
}
|
||||
|
@ -243,29 +242,29 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
auto postcond_res =
|
||||
intersect_postconds([postcond_true_case,
|
||||
postcond_false_case]);
|
||||
set_pre_and_post(fcx.ccx, a, precond_res, postcond_res);
|
||||
set_pre_and_post(fcx.ccx, id, precond_res, postcond_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_if_local(&fn_ctxt fcx, @expr lhs, @expr rhs, &ann larger_ann,
|
||||
&ann new_var, &path pth) {
|
||||
alt (ann_to_def(fcx.ccx, new_var)) {
|
||||
fn gen_if_local(&fn_ctxt fcx, @expr lhs, @expr rhs, node_id larger_id,
|
||||
node_id new_var, &path pth) {
|
||||
alt (node_id_to_def(fcx.ccx, new_var)) {
|
||||
case (some(?d)) {
|
||||
alt (d) {
|
||||
case (def_local(?d_id)) {
|
||||
find_pre_post_expr(fcx, rhs);
|
||||
auto p = expr_pp(fcx.ccx, rhs);
|
||||
set_pre_and_post(fcx.ccx, larger_ann, p.precondition,
|
||||
set_pre_and_post(fcx.ccx, larger_id, p.precondition,
|
||||
p.postcondition);
|
||||
gen(fcx, larger_ann,
|
||||
rec(id=d_id,
|
||||
gen(fcx, larger_id,
|
||||
rec(id=d_id._1,
|
||||
c=ninit(path_to_ident(fcx.ccx.tcx, pth))));
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_ann); }
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_id); }
|
||||
}
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_ann); }
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], larger_id); }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,10 +278,10 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
"):";
|
||||
log_expr(*e);
|
||||
alt (e.node) {
|
||||
case (expr_call(?operator, ?operands, ?a)) {
|
||||
case (expr_call(?operator, ?operands, ?id)) {
|
||||
auto args = vec::clone[@expr](operands);
|
||||
vec::push[@expr](args, operator);
|
||||
find_pre_post_exprs(fcx, args, a);
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
/* see if the call has any constraints on its type */
|
||||
|
||||
log "a function: ";
|
||||
|
@ -292,7 +291,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
{
|
||||
auto i =
|
||||
bit_num(fcx,
|
||||
rec(id=c.node.id,
|
||||
rec(id=c.node.id._1,
|
||||
c=substitute_constr_args(fcx.ccx.tcx,
|
||||
operands, c)));
|
||||
require(i, pp);
|
||||
|
@ -300,154 +299,156 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
|
||||
/* if this is a failing call, its postcondition sets everything */
|
||||
alt (controlflow_expr(fcx.ccx, operator)) {
|
||||
case (noreturn) { set_postcond_false(fcx.ccx, a); }
|
||||
case (noreturn) { set_postcond_false(fcx.ccx, id); }
|
||||
case (_) { }
|
||||
}
|
||||
}
|
||||
case (expr_spawn(_, _, ?operator, ?operands, ?a)) {
|
||||
case (expr_spawn(_, _, ?operator, ?operands, ?id)) {
|
||||
auto args = vec::clone[@expr](operands);
|
||||
vec::push[@expr](args, operator);
|
||||
find_pre_post_exprs(fcx, args, a);
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
}
|
||||
case (expr_vec(?args, _, _, ?a)) {
|
||||
find_pre_post_exprs(fcx, args, a);
|
||||
case (expr_vec(?args, _, _, ?id)) {
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
}
|
||||
case (expr_tup(?elts, ?a)) {
|
||||
find_pre_post_exprs(fcx, elt_exprs(elts), a);
|
||||
case (expr_tup(?elts, ?id)) {
|
||||
find_pre_post_exprs(fcx, elt_exprs(elts), id);
|
||||
}
|
||||
case (expr_path(?p, ?a)) {
|
||||
case (expr_path(?p, ?id)) {
|
||||
auto res = expr_pp(fcx.ccx, e);
|
||||
clear_pp(res);
|
||||
auto df = ann_to_def_strict(fcx.ccx.tcx, a);
|
||||
auto df = node_id_to_def_strict(fcx.ccx.tcx, id);
|
||||
alt (df) {
|
||||
case (def_local(?d_id)) {
|
||||
auto i =
|
||||
bit_num(fcx,
|
||||
rec(id=d_id,
|
||||
rec(id=d_id._1,
|
||||
c=ninit(path_to_ident(fcx.ccx.tcx, p))));
|
||||
require_and_preserve(i, res);
|
||||
}
|
||||
case (_) {/* nothing to check */ }
|
||||
}
|
||||
}
|
||||
case (expr_self_method(?v, ?a)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_log(_, ?arg, ?a)) {
|
||||
case (expr_self_method(?v, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_log(_, ?arg, ?id)) {
|
||||
find_pre_post_expr(fcx, arg);
|
||||
copy_pre_post(fcx.ccx, a, arg);
|
||||
copy_pre_post(fcx.ccx, id, arg);
|
||||
}
|
||||
case (expr_chan(?arg, ?a)) {
|
||||
case (expr_chan(?arg, ?id)) {
|
||||
find_pre_post_expr(fcx, arg);
|
||||
copy_pre_post(fcx.ccx, a, arg);
|
||||
copy_pre_post(fcx.ccx, id, arg);
|
||||
}
|
||||
case (expr_put(?opt, ?a)) {
|
||||
case (expr_put(?opt, ?id)) {
|
||||
alt (opt) {
|
||||
case (some(?arg)) {
|
||||
find_pre_post_expr(fcx, arg);
|
||||
copy_pre_post(fcx.ccx, a, arg);
|
||||
copy_pre_post(fcx.ccx, id, arg);
|
||||
}
|
||||
case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
}
|
||||
}
|
||||
case (
|
||||
// FIXME this was just put in here as a placeholder
|
||||
expr_fn(?f, ?a)) {
|
||||
expr_fn(?f, ?id)) {
|
||||
clear_pp(expr_pp(fcx.ccx, e));
|
||||
}
|
||||
case (expr_block(?b, ?a)) {
|
||||
case (expr_block(?b, ?id)) {
|
||||
find_pre_post_block(fcx, b);
|
||||
auto p = block_pp(fcx.ccx, b);
|
||||
set_pre_and_post(fcx.ccx, a, p.precondition, p.postcondition);
|
||||
set_pre_and_post(fcx.ccx, id, p.precondition, p.postcondition);
|
||||
}
|
||||
case (expr_rec(?fields, ?maybe_base, ?a)) {
|
||||
case (expr_rec(?fields, ?maybe_base, ?id)) {
|
||||
auto es = field_exprs(fields);
|
||||
vec::plus_option[@expr](es, maybe_base);
|
||||
find_pre_post_exprs(fcx, es, a);
|
||||
find_pre_post_exprs(fcx, es, id);
|
||||
}
|
||||
case (expr_move(?lhs, ?rhs, ?a)) {
|
||||
case (expr_move(?lhs, ?rhs, ?id)) {
|
||||
|
||||
// FIXME: this needs to deinitialize the rhs
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
gen_if_local(fcx, lhs, rhs, a, a_lhs, p);
|
||||
gen_if_local(fcx, lhs, rhs, id, a_lhs, p);
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], a); }
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], id); }
|
||||
}
|
||||
}
|
||||
case (expr_swap(?lhs, ?rhs, ?a)) {
|
||||
case (expr_swap(?lhs, ?rhs, ?id)) {
|
||||
// Both sides must already be initialized
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], a);
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], id);
|
||||
}
|
||||
case (expr_assign(?lhs, ?rhs, ?a)) {
|
||||
case (expr_assign(?lhs, ?rhs, ?id)) {
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
gen_if_local(fcx, lhs, rhs, a, a_lhs, p);
|
||||
gen_if_local(fcx, lhs, rhs, id, a_lhs, p);
|
||||
}
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], a); }
|
||||
case (_) { find_pre_post_exprs(fcx, [lhs, rhs], id); }
|
||||
}
|
||||
}
|
||||
case (expr_recv(?lhs, ?rhs, ?a)) {
|
||||
case (expr_recv(?lhs, ?rhs, ?id)) {
|
||||
alt (rhs.node) {
|
||||
case (expr_path(?p, ?a_rhs)) {
|
||||
gen_if_local(fcx, rhs, lhs, a, a_rhs, p);
|
||||
case (expr_path(?p, ?id_rhs)) {
|
||||
gen_if_local(fcx, rhs, lhs, id, id_rhs, p);
|
||||
}
|
||||
case (_) {
|
||||
// doesn't check that rhs is an lval, but
|
||||
// that's probably ok
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], a);
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], id);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (expr_assign_op(_, ?lhs, ?rhs, ?a)) {
|
||||
case (expr_assign_op(_, ?lhs, ?rhs, ?id)) {
|
||||
/* Different from expr_assign in that the lhs *must*
|
||||
already be initialized */
|
||||
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], a);
|
||||
find_pre_post_exprs(fcx, [lhs, rhs], id);
|
||||
}
|
||||
case (expr_lit(_, ?a)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ret(?maybe_val, ?a)) {
|
||||
case (expr_lit(_, ?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ret(?maybe_val, ?id)) {
|
||||
alt (maybe_val) {
|
||||
case (none) {
|
||||
clear_precond(fcx.ccx, a);
|
||||
set_postcond_false(fcx.ccx, a);
|
||||
clear_precond(fcx.ccx, id);
|
||||
set_postcond_false(fcx.ccx, id);
|
||||
}
|
||||
case (some(?ret_val)) {
|
||||
find_pre_post_expr(fcx, ret_val);
|
||||
set_precondition(ann_to_ts_ann(fcx.ccx, a),
|
||||
set_precondition(node_id_to_ts_ann(fcx.ccx, id),
|
||||
expr_precond(fcx.ccx, ret_val));
|
||||
set_postcond_false(fcx.ccx, a);
|
||||
set_postcond_false(fcx.ccx, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (expr_be(?e, ?a)) {
|
||||
case (expr_be(?e, ?id)) {
|
||||
find_pre_post_expr(fcx, e);
|
||||
set_pre_and_post(fcx.ccx, a, expr_prestate(fcx.ccx, e),
|
||||
set_pre_and_post(fcx.ccx, id, expr_prestate(fcx.ccx, e),
|
||||
false_postcond(num_local_vars));
|
||||
}
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt, ?a)) {
|
||||
join_then_else(fcx, antec, conseq, maybe_alt, a, plain_if);
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt, ?id)) {
|
||||
join_then_else(fcx, antec, conseq, maybe_alt, id, plain_if);
|
||||
}
|
||||
case (expr_binary(?bop, ?l, ?r, ?a)) {
|
||||
case (expr_binary(?bop, ?l, ?r, ?id)) {
|
||||
/* *unless* bop is lazy (e.g. and, or)?
|
||||
FIXME */
|
||||
|
||||
find_pre_post_exprs(fcx, [l, r], a);
|
||||
find_pre_post_exprs(fcx, [l, r], id);
|
||||
}
|
||||
case (expr_send(?l, ?r, ?a)) { find_pre_post_exprs(fcx, [l, r], a); }
|
||||
case (expr_unary(_, ?operand, ?a)) {
|
||||
case (expr_send(?l, ?r, ?id)) {
|
||||
find_pre_post_exprs(fcx, [l, r], id);
|
||||
}
|
||||
case (expr_unary(_, ?operand, ?id)) {
|
||||
find_pre_post_expr(fcx, operand);
|
||||
copy_pre_post(fcx.ccx, a, operand);
|
||||
copy_pre_post(fcx.ccx, id, operand);
|
||||
}
|
||||
case (expr_cast(?operand, _, ?a)) {
|
||||
case (expr_cast(?operand, _, ?id)) {
|
||||
find_pre_post_expr(fcx, operand);
|
||||
copy_pre_post(fcx.ccx, a, operand);
|
||||
copy_pre_post(fcx.ccx, id, operand);
|
||||
}
|
||||
case (expr_while(?test, ?body, ?a)) {
|
||||
case (expr_while(?test, ?body, ?id)) {
|
||||
find_pre_post_expr(fcx, test);
|
||||
find_pre_post_block(fcx, body);
|
||||
log "666";
|
||||
set_pre_and_post(fcx.ccx, a,
|
||||
set_pre_and_post(fcx.ccx, id,
|
||||
seq_preconds(fcx,
|
||||
[expr_pp(fcx.ccx, test),
|
||||
block_pp(fcx.ccx, body)]),
|
||||
|
@ -456,7 +457,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
block_postcond(fcx.ccx,
|
||||
body)]));
|
||||
}
|
||||
case (expr_do_while(?body, ?test, ?a)) {
|
||||
case (expr_do_while(?body, ?test, ?id)) {
|
||||
find_pre_post_block(fcx, body);
|
||||
find_pre_post_expr(fcx, test);
|
||||
auto loop_postcond =
|
||||
|
@ -469,22 +470,22 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
if (has_nonlocal_exits(body)) {
|
||||
loop_postcond = empty_poststate(num_local_vars);
|
||||
}
|
||||
set_pre_and_post(fcx.ccx, a,
|
||||
set_pre_and_post(fcx.ccx, id,
|
||||
seq_preconds(fcx,
|
||||
[block_pp(fcx.ccx, body),
|
||||
expr_pp(fcx.ccx, test)]),
|
||||
loop_postcond);
|
||||
}
|
||||
case (expr_for(?d, ?index, ?body, ?a)) {
|
||||
find_pre_post_loop(fcx, d, index, body, a);
|
||||
case (expr_for(?d, ?index, ?body, ?id)) {
|
||||
find_pre_post_loop(fcx, d, index, body, id);
|
||||
}
|
||||
case (expr_for_each(?d, ?index, ?body, ?a)) {
|
||||
find_pre_post_loop(fcx, d, index, body, a);
|
||||
case (expr_for_each(?d, ?index, ?body, ?id)) {
|
||||
find_pre_post_loop(fcx, d, index, body, id);
|
||||
}
|
||||
case (expr_index(?e, ?sub, ?a)) {
|
||||
find_pre_post_exprs(fcx, [e, sub], a);
|
||||
case (expr_index(?e, ?sub, ?id)) {
|
||||
find_pre_post_exprs(fcx, [e, sub], id);
|
||||
}
|
||||
case (expr_alt(?ex, ?alts, ?a)) {
|
||||
case (expr_alt(?ex, ?alts, ?id)) {
|
||||
find_pre_post_expr(fcx, ex);
|
||||
fn do_an_alt(&fn_ctxt fcx, &arm an_alt) -> pre_and_post {
|
||||
find_pre_post_block(fcx, an_alt.block);
|
||||
|
@ -506,54 +507,54 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
|
|||
auto g = bind combine_pp(antec_pp, fcx, _, _);
|
||||
auto alts_overall_pp =
|
||||
vec::foldl[pre_and_post, pre_and_post](g, e_pp, alt_pps);
|
||||
set_pre_and_post(fcx.ccx, a, alts_overall_pp.precondition,
|
||||
set_pre_and_post(fcx.ccx, id, alts_overall_pp.precondition,
|
||||
alts_overall_pp.postcondition);
|
||||
}
|
||||
case (expr_field(?operator, _, ?a)) {
|
||||
case (expr_field(?operator, _, ?id)) {
|
||||
find_pre_post_expr(fcx, operator);
|
||||
copy_pre_post(fcx.ccx, a, operator);
|
||||
copy_pre_post(fcx.ccx, id, operator);
|
||||
}
|
||||
case (expr_fail(?a, _)) {
|
||||
set_pre_and_post(fcx.ccx, a,
|
||||
case (expr_fail(?id, _)) {
|
||||
set_pre_and_post(fcx.ccx, id,
|
||||
/* if execution continues after fail,
|
||||
then everything is true! */
|
||||
empty_prestate(num_local_vars),
|
||||
false_postcond(num_local_vars));
|
||||
}
|
||||
case (expr_assert(?p, ?a)) {
|
||||
case (expr_assert(?p, ?id)) {
|
||||
find_pre_post_expr(fcx, p);
|
||||
copy_pre_post(fcx.ccx, a, p);
|
||||
copy_pre_post(fcx.ccx, id, p);
|
||||
}
|
||||
case (expr_check(?p, ?a)) {
|
||||
case (expr_check(?p, ?id)) {
|
||||
find_pre_post_expr(fcx, p);
|
||||
copy_pre_post(fcx.ccx, a, p);
|
||||
copy_pre_post(fcx.ccx, id, p);
|
||||
/* predicate p holds after this expression executes */
|
||||
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, p);
|
||||
gen(fcx, a, c.node);
|
||||
gen(fcx, id, c.node);
|
||||
}
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt, ?a)) {
|
||||
join_then_else(fcx, p, conseq, maybe_alt, a, if_check);
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt, ?id)) {
|
||||
join_then_else(fcx, p, conseq, maybe_alt, id, if_check);
|
||||
}
|
||||
|
||||
case (expr_bind(?operator, ?maybe_args, ?a)) {
|
||||
case (expr_bind(?operator, ?maybe_args, ?id)) {
|
||||
auto args = vec::cat_options[@expr](maybe_args);
|
||||
vec::push[@expr](args, operator); /* ??? order of eval? */
|
||||
|
||||
find_pre_post_exprs(fcx, args, a);
|
||||
find_pre_post_exprs(fcx, args, id);
|
||||
}
|
||||
case (expr_break(?a)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_cont(?a)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_port(?a)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ext(_, _, _, ?expanded, ?a)) {
|
||||
case (expr_break(?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_cont(?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_port(?id)) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
case (expr_ext(_, _, _, ?expanded, ?id)) {
|
||||
find_pre_post_expr(fcx, expanded);
|
||||
copy_pre_post(fcx.ccx, a, expanded);
|
||||
copy_pre_post(fcx.ccx, id, expanded);
|
||||
}
|
||||
case (expr_anon_obj(?anon_obj, _, _, ?a)) {
|
||||
case (expr_anon_obj(?anon_obj, _, _, ?id)) {
|
||||
alt (anon_obj.with_obj) {
|
||||
case (some(?ex)) {
|
||||
find_pre_post_expr(fcx, ex);
|
||||
copy_pre_post(fcx.ccx, a, ex);
|
||||
copy_pre_post(fcx.ccx, id, ex);
|
||||
}
|
||||
case (none) { clear_pp(expr_pp(fcx.ccx, e)); }
|
||||
}
|
||||
|
@ -567,39 +568,40 @@ fn find_pre_post_stmt(&fn_ctxt fcx, &stmt s) {
|
|||
auto enclosing = fcx.enclosing;
|
||||
auto num_local_vars = num_constraints(enclosing);
|
||||
alt (s.node) {
|
||||
case (stmt_decl(?adecl, ?a)) {
|
||||
case (stmt_decl(?adecl, ?id)) {
|
||||
alt (adecl.node) {
|
||||
case (decl_local(?alocal)) {
|
||||
alt (alocal.node.init) {
|
||||
case (some(?an_init)) {
|
||||
find_pre_post_expr(fcx, an_init.expr);
|
||||
copy_pre_post(fcx.ccx, alocal.node.ann,
|
||||
copy_pre_post(fcx.ccx, alocal.node.id,
|
||||
an_init.expr);
|
||||
/* Inherit ann from initializer, and add var being
|
||||
initialized to the postcondition */
|
||||
|
||||
copy_pre_post(fcx.ccx, a, an_init.expr);
|
||||
gen(fcx, a,
|
||||
copy_pre_post(fcx.ccx, id, an_init.expr);
|
||||
gen(fcx, id,
|
||||
rec(id=alocal.node.id,
|
||||
c=ninit(alocal.node.ident)));
|
||||
}
|
||||
case (none) {
|
||||
clear_pp(ann_to_ts_ann(fcx.ccx,
|
||||
alocal.node.ann)
|
||||
clear_pp(node_id_to_ts_ann(fcx.ccx,
|
||||
alocal.node.id)
|
||||
.conditions);
|
||||
clear_pp(node_id_to_ts_ann(fcx.ccx, id)
|
||||
.conditions);
|
||||
clear_pp(ann_to_ts_ann(fcx.ccx, a).conditions);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (decl_item(?anitem)) {
|
||||
clear_pp(ann_to_ts_ann(fcx.ccx, a).conditions);
|
||||
clear_pp(node_id_to_ts_ann(fcx.ccx, id).conditions);
|
||||
find_pre_post_item(fcx.ccx, *anitem);
|
||||
}
|
||||
}
|
||||
}
|
||||
case (stmt_expr(?e, ?a)) {
|
||||
case (stmt_expr(?e, ?id)) {
|
||||
find_pre_post_expr(fcx, e);
|
||||
copy_pre_post(fcx.ccx, a, e);
|
||||
copy_pre_post(fcx.ccx, id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -661,7 +663,7 @@ fn find_pre_post_block(&fn_ctxt fcx, block b) {
|
|||
if (!has_nonlocal_exits(b)) {
|
||||
block_postcond = union_postconds(nv, postconds);
|
||||
}
|
||||
set_pre_and_post(fcx.ccx, b.node.a, block_precond, block_postcond);
|
||||
set_pre_and_post(fcx.ccx, b.node.id, block_precond, block_postcond);
|
||||
}
|
||||
|
||||
fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
|
||||
|
@ -670,17 +672,17 @@ fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
|
|||
// Treat the tail expression as a return statement
|
||||
alt (f.body.node.expr) {
|
||||
case (some(?tailexpr)) {
|
||||
auto tailann = expr_ann(tailexpr);
|
||||
auto tailann = expr_node_id(tailexpr);
|
||||
set_postcond_false(fcx.ccx, tailann);
|
||||
}
|
||||
case (none) {/* fallthrough */ }
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_pre_post(crate_ctxt ccx, &_fn f, &span sp, &ident i, &def_id id,
|
||||
&ann a) {
|
||||
fn fn_pre_post(crate_ctxt ccx, &_fn f, &span sp, &ident i, node_id id) {
|
||||
assert (ccx.fm.contains_key(id));
|
||||
auto fcx = rec(enclosing=ccx.fm.get(id), id=id, name=i, ccx=ccx);
|
||||
auto fcx = rec(enclosing=ccx.fm.get(id), id=id, name=i,
|
||||
ccx=ccx);
|
||||
find_pre_post_fn(fcx, f);
|
||||
}
|
||||
//
|
||||
|
|
|
@ -55,7 +55,7 @@ import aux::log_states;
|
|||
import aux::log_states_err;
|
||||
import aux::block_states;
|
||||
import aux::controlflow_expr;
|
||||
import aux::ann_to_def;
|
||||
import aux::node_id_to_def;
|
||||
import aux::expr_to_constr;
|
||||
import aux::ninit;
|
||||
import aux::npred;
|
||||
|
@ -73,7 +73,7 @@ import bitvectors::gen_poststate;
|
|||
import bitvectors::kill_poststate;
|
||||
import front::ast;
|
||||
import front::ast::*;
|
||||
import middle::ty::expr_ann;
|
||||
import middle::ty::expr_node_id;
|
||||
import middle::ty::expr_ty;
|
||||
import middle::ty::type_is_nil;
|
||||
import middle::ty::type_is_bot;
|
||||
|
@ -101,23 +101,23 @@ fn seq_states(&fn_ctxt fcx, prestate pres, vec[@expr] exprs) ->
|
|||
ret tup(changed, post);
|
||||
}
|
||||
|
||||
fn find_pre_post_state_exprs(&fn_ctxt fcx, &prestate pres, &ann a,
|
||||
fn find_pre_post_state_exprs(&fn_ctxt fcx, &prestate pres, ast::node_id id,
|
||||
&vec[@expr] es) -> bool {
|
||||
auto res = seq_states(fcx, pres, es);
|
||||
auto changed = res._0;
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, a, res._1) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, res._1) || changed;
|
||||
ret changed;
|
||||
}
|
||||
|
||||
fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l,
|
||||
&@expr index, &block body, &ann a) -> bool {
|
||||
&@expr index, &block body, node_id id) -> bool {
|
||||
auto changed = false;
|
||||
/* same issues as while */
|
||||
|
||||
// FIXME: also want to set l as initialized, no?
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, index) || changed;
|
||||
/* in general, would need the intersection of
|
||||
(poststate of index, poststate of body) */
|
||||
|
@ -127,21 +127,21 @@ fn find_pre_post_state_loop(&fn_ctxt fcx, prestate pres, &@local l,
|
|||
|| changed;
|
||||
|
||||
if (has_nonlocal_exits(body)) {
|
||||
changed = set_poststate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = set_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
}
|
||||
|
||||
auto res_p =
|
||||
intersect_postconds([expr_poststate(fcx.ccx, index),
|
||||
block_poststate(fcx.ccx, body)]);
|
||||
changed = extend_poststate_ann(fcx.ccx, a, res_p) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, res_p) || changed;
|
||||
ret changed;
|
||||
}
|
||||
|
||||
fn gen_if_local(&fn_ctxt fcx, &ann a_new_var, &ann a, &path p) -> bool {
|
||||
alt (ann_to_def(fcx.ccx, a_new_var)) {
|
||||
fn gen_if_local(&fn_ctxt fcx, node_id new_var, node_id id, &path p) -> bool {
|
||||
alt (node_id_to_def(fcx.ccx, new_var)) {
|
||||
case (some(def_local(?loc))) {
|
||||
ret gen_poststate(fcx, a,
|
||||
rec(id=loc,
|
||||
ret gen_poststate(fcx, id,
|
||||
rec(id=loc._1,
|
||||
c=ninit(path_to_ident(fcx.ccx.tcx, p))));
|
||||
}
|
||||
case (_) { ret false; }
|
||||
|
@ -149,11 +149,11 @@ fn gen_if_local(&fn_ctxt fcx, &ann a_new_var, &ann a, &path p) -> bool {
|
|||
}
|
||||
|
||||
fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
||||
&option::t[@expr] maybe_alt, &ann a, &if_ty chk,
|
||||
&option::t[@expr] maybe_alt, ast::node_id id, &if_ty chk,
|
||||
&prestate pres) -> bool {
|
||||
auto changed = false;
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, antec) || changed;
|
||||
|
||||
/*
|
||||
|
@ -179,7 +179,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
conseq) || changed;
|
||||
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, antec))
|
||||
|| changed;
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
|
|||
block_poststate(fcx.ccx, conseq))); */
|
||||
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, poststate_res) ||
|
||||
extend_poststate_ann(fcx.ccx, id, poststate_res) ||
|
||||
changed;
|
||||
}
|
||||
}
|
||||
|
@ -238,13 +238,13 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
|
||||
/* FIXME could get rid of some of the copy/paste */
|
||||
alt (e.node) {
|
||||
case (expr_vec(?elts, _, _, ?a)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, a, elts);
|
||||
case (expr_vec(?elts, _, _, ?id)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, id, elts);
|
||||
}
|
||||
case (expr_tup(?elts, ?a)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, a, elt_exprs(elts));
|
||||
case (expr_tup(?elts, ?id)) {
|
||||
ret find_pre_post_state_exprs(fcx, pres, id, elt_exprs(elts));
|
||||
}
|
||||
case (expr_call(?operator, ?operands, ?a)) {
|
||||
case (expr_call(?operator, ?operands, ?id)) {
|
||||
/* do the prestate for the rator */
|
||||
|
||||
/* fcx.ccx.tcx.sess.span_note(operator.span,
|
||||
|
@ -258,13 +258,13 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
changed =
|
||||
find_pre_post_state_exprs(fcx,
|
||||
expr_poststate(fcx.ccx, operator),
|
||||
a, operands) || changed;
|
||||
id, operands) || changed;
|
||||
/* if this is a failing call, it sets everything as initialized */
|
||||
|
||||
alt (controlflow_expr(fcx.ccx, operator)) {
|
||||
case (noreturn) {
|
||||
changed =
|
||||
set_poststate_ann(fcx.ccx, a,
|
||||
set_poststate_ann(fcx.ccx, id,
|
||||
false_postcond(num_local_vars)) ||
|
||||
changed;
|
||||
}
|
||||
|
@ -276,80 +276,80 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
*/
|
||||
ret changed;
|
||||
}
|
||||
case (expr_spawn(_, _, ?operator, ?operands, ?a)) {
|
||||
case (expr_spawn(_, _, ?operator, ?operands, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operator);
|
||||
ret find_pre_post_state_exprs(fcx,
|
||||
expr_poststate(fcx.ccx, operator),
|
||||
a, operands) || changed;
|
||||
id, operands) || changed;
|
||||
}
|
||||
case (expr_bind(?operator, ?maybe_args, ?a)) {
|
||||
case (expr_bind(?operator, ?maybe_args, ?id)) {
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, operator) || changed;
|
||||
ret find_pre_post_state_exprs(fcx,
|
||||
expr_poststate(fcx.ccx, operator),
|
||||
a, cat_options[@expr](maybe_args))
|
||||
id, cat_options[@expr](maybe_args))
|
||||
|| changed;
|
||||
}
|
||||
case (expr_path(_, ?a)) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (expr_log(_, ?e, ?a)) {
|
||||
case (expr_path(_, ?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_log(_, ?e, ?id)) {
|
||||
/* factor out the "one exp" pattern */
|
||||
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, e))
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_chan(?e, ?a)) {
|
||||
case (expr_chan(?e, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, e))
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_ext(_, _, _, ?expanded, ?a)) {
|
||||
case (expr_ext(_, _, _, ?expanded, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, expanded);
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, expanded)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_put(?maybe_e, ?a)) {
|
||||
case (expr_put(?maybe_e, ?id)) {
|
||||
alt (maybe_e) {
|
||||
case (some(?arg)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, arg);
|
||||
changed =
|
||||
extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, arg)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (none) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (none) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
}
|
||||
}
|
||||
case (expr_lit(?l, ?a)) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (expr_lit(?l, ?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (
|
||||
// FIXME This was just put in here as a placeholder
|
||||
expr_fn(?f, ?a)) {
|
||||
ret pure_exp(fcx.ccx, a, pres);
|
||||
expr_fn(?f, ?id)) {
|
||||
ret pure_exp(fcx.ccx, id, pres);
|
||||
}
|
||||
case (expr_block(?b, ?a)) {
|
||||
case (expr_block(?b, ?id)) {
|
||||
changed = find_pre_post_state_block(fcx, pres, b) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, block_poststate(fcx.ccx, b))
|
||||
extend_poststate_ann(fcx.ccx, id, block_poststate(fcx.ccx, b))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_rec(?fields, ?maybe_base, ?a)) {
|
||||
case (expr_rec(?fields, ?maybe_base, ?id)) {
|
||||
changed =
|
||||
find_pre_post_state_exprs(fcx, pres, a, field_exprs(fields))
|
||||
find_pre_post_state_exprs(fcx, pres, id, field_exprs(fields))
|
||||
|| changed;
|
||||
alt (maybe_base) {
|
||||
case (none) {/* do nothing */ }
|
||||
|
@ -357,29 +357,29 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, base) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, base)) ||
|
||||
changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_move(?lhs, ?rhs, ?a)) {
|
||||
case (expr_move(?lhs, ?rhs, ?id)) {
|
||||
// FIXME: this needs to deinitialize the rhs
|
||||
|
||||
extend_prestate_ann(fcx.ccx, a, pres);
|
||||
extend_prestate_ann(fcx.ccx, id, pres);
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
case (expr_path(?p, ?id_lhs)) {
|
||||
// assignment to local var
|
||||
|
||||
changed = pure_exp(fcx.ccx, a_lhs, pres) || changed;
|
||||
changed = pure_exp(fcx.ccx, id_lhs, pres) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
changed = gen_if_local(fcx, a_lhs, a, p) || changed;
|
||||
changed = gen_if_local(fcx, id_lhs, id, p) || changed;
|
||||
}
|
||||
case (_) {
|
||||
// assignment to something that must already have been
|
||||
|
@ -392,15 +392,15 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_assign(?lhs, ?rhs, ?a)) {
|
||||
extend_prestate_ann(fcx.ccx, a, pres);
|
||||
case (expr_assign(?lhs, ?rhs, ?id)) {
|
||||
extend_prestate_ann(fcx.ccx, id, pres);
|
||||
alt (lhs.node) {
|
||||
case (expr_path(?p, ?a_lhs)) {
|
||||
// assignment to local var
|
||||
|
@ -409,10 +409,10 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
changed = gen_if_local(fcx, a_lhs, a, p) || changed;
|
||||
changed = gen_if_local(fcx, a_lhs, id, p) || changed;
|
||||
}
|
||||
case (_) {
|
||||
// assignment to something that must already have been
|
||||
|
@ -425,40 +425,40 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) ||
|
||||
changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_swap(?lhs, ?rhs, ?a)) {
|
||||
case (expr_swap(?lhs, ?rhs, ?id)) {
|
||||
/* quite similar to binary -- should abstract this */
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, rhs))
|
||||
|| changed;
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs)) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_recv(?lhs, ?rhs, ?a)) {
|
||||
extend_prestate_ann(fcx.ccx, a, pres);
|
||||
case (expr_recv(?lhs, ?rhs, ?id)) {
|
||||
extend_prestate_ann(fcx.ccx, id, pres);
|
||||
alt (rhs.node) {
|
||||
case (expr_path(?p, ?a_rhs)) {
|
||||
case (expr_path(?p, ?id_rhs)) {
|
||||
// receive to local var
|
||||
|
||||
changed = pure_exp(fcx.ccx, a_rhs, pres) || changed;
|
||||
changed = pure_exp(fcx.ccx, id_rhs, pres) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, lhs)) ||
|
||||
changed;
|
||||
changed = gen_if_local(fcx, a_rhs, a, p) || changed;
|
||||
changed = gen_if_local(fcx, id_rhs, id, p) || changed;
|
||||
}
|
||||
case (_) {
|
||||
// receive to something that must already have been init'd
|
||||
|
@ -470,25 +470,26 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
expr_poststate(fcx.ccx, rhs),
|
||||
lhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, lhs)) ||
|
||||
changed;
|
||||
}
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_ret(?maybe_ret_val, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_ret(?maybe_ret_val, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
/* normally, everything is true if execution continues after
|
||||
a ret expression (since execution never continues locally
|
||||
after a ret expression */
|
||||
|
||||
set_poststate_ann(fcx.ccx, a, false_postcond(num_local_vars));
|
||||
set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars));
|
||||
/* return from an always-failing function clears the return bit */
|
||||
|
||||
alt (fcx.enclosing.cf) {
|
||||
case (noreturn) {
|
||||
kill_poststate(fcx, a, rec(id=fcx.id, c=ninit(fcx.name)));
|
||||
kill_poststate(fcx, id, rec(id=fcx.id,
|
||||
c=ninit(fcx.name)));
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
|
@ -502,58 +503,59 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_be(?e, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
set_poststate_ann(fcx.ccx, a, false_postcond(num_local_vars));
|
||||
case (expr_be(?e, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars));
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt, ?a)) {
|
||||
changed = join_then_else(fcx, antec, conseq, maybe_alt, a,
|
||||
case (expr_if(?antec, ?conseq, ?maybe_alt, ?id)) {
|
||||
changed = join_then_else(fcx, antec, conseq, maybe_alt, id,
|
||||
plain_if, pres)
|
||||
|| changed;
|
||||
|
||||
ret changed;
|
||||
}
|
||||
case (expr_binary(?bop, ?l, ?r, ?a)) {
|
||||
case (expr_binary(?bop, ?l, ?r, ?id)) {
|
||||
/* FIXME: what if bop is lazy? */
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, l) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r)
|
||||
|| changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, r))
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, r))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_send(?l, ?r, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_send(?l, ?r, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, l) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, l), r)
|
||||
|| changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, r))
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, r))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_assign_op(?op, ?lhs, ?rhs, ?a)) {
|
||||
case (expr_assign_op(?op, ?lhs, ?rhs, ?id)) {
|
||||
/* quite similar to binary -- should abstract this */
|
||||
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, lhs) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, lhs),
|
||||
rhs) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, rhs))
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, rhs))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_while(?test, ?body, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_while(?test, ?body, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
/* to handle general predicates, we need to pass in
|
||||
pres `intersect` (poststate(a))
|
||||
like: auto test_pres = intersect_postconds(pres,
|
||||
|
@ -570,22 +572,22 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
/* conservative approximation: if a loop contains a break
|
||||
or cont, we assume nothing about the poststate */
|
||||
if (has_nonlocal_exits(body)) {
|
||||
changed = set_poststate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = set_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
}
|
||||
|
||||
changed =
|
||||
{
|
||||
auto e_post = expr_poststate(fcx.ccx, test);
|
||||
auto b_post = block_poststate(fcx.ccx, body);
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
intersect_postconds([e_post,
|
||||
b_post])) ||
|
||||
changed
|
||||
};
|
||||
ret changed;
|
||||
}
|
||||
case (expr_do_while(?body, ?test, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_do_while(?body, ?test, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
auto changed0 = changed;
|
||||
changed = find_pre_post_state_block(fcx, pres, body) || changed;
|
||||
/* conservative approximination: if the body of the loop
|
||||
|
@ -600,7 +602,7 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
// FIXME
|
||||
// This doesn't set "changed", as if the previous state
|
||||
// was different, this might come back true every time
|
||||
set_poststate_ann(fcx.ccx, body.node.a, pres);
|
||||
set_poststate_ann(fcx.ccx, body.node.id, pres);
|
||||
changed = changed0;
|
||||
}
|
||||
|
||||
|
@ -609,34 +611,34 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
test) || changed;
|
||||
|
||||
if (breaks) {
|
||||
set_poststate_ann(fcx.ccx, a, pres);
|
||||
set_poststate_ann(fcx.ccx, id, pres);
|
||||
}
|
||||
else {
|
||||
changed = extend_poststate_ann(fcx.ccx, a,
|
||||
changed = extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, test)) ||
|
||||
changed;
|
||||
}
|
||||
ret changed;
|
||||
}
|
||||
case (expr_for(?d, ?index, ?body, ?a)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, a);
|
||||
case (expr_for(?d, ?index, ?body, ?id)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, id);
|
||||
}
|
||||
case (expr_for_each(?d, ?index, ?body, ?a)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, a);
|
||||
case (expr_for_each(?d, ?index, ?body, ?id)) {
|
||||
ret find_pre_post_state_loop(fcx, pres, d, index, body, id);
|
||||
}
|
||||
case (expr_index(?e, ?sub, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_index(?e, ?sub, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
changed =
|
||||
find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, e), sub)
|
||||
|| changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, sub));
|
||||
ret changed;
|
||||
}
|
||||
case (expr_alt(?e, ?alts, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_alt(?e, ?alts, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, e) || changed;
|
||||
auto e_post = expr_poststate(fcx.ccx, e);
|
||||
auto a_post;
|
||||
|
@ -657,85 +659,85 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
|
|||
|
||||
a_post = e_post;
|
||||
}
|
||||
changed = extend_poststate_ann(fcx.ccx, a, a_post) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, a_post) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_field(?e, _, ?a)) {
|
||||
case (expr_field(?e, _, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a, expr_poststate(fcx.ccx, e))
|
||||
extend_poststate_ann(fcx.ccx, id, expr_poststate(fcx.ccx, e))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_unary(_, ?operand, ?a)) {
|
||||
case (expr_unary(_, ?operand, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operand) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, operand)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_cast(?operand, _, ?a)) {
|
||||
case (expr_cast(?operand, _, ?id)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, operand) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, operand)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_fail(?a, _)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_fail(?id, _)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
/* if execution continues after fail, then everything is true!
|
||||
woo! */
|
||||
|
||||
changed =
|
||||
set_poststate_ann(fcx.ccx, a, false_postcond(num_local_vars))
|
||||
set_poststate_ann(fcx.ccx, id, false_postcond(num_local_vars))
|
||||
|| changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_assert(?p, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_assert(?p, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, p) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_check(?p, ?a)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
case (expr_check(?p, ?id)) {
|
||||
changed = extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed = find_pre_post_state_expr(fcx, pres, p) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, a, pres) || changed;
|
||||
changed = extend_poststate_ann(fcx.ccx, id, pres) || changed;
|
||||
/* predicate p holds after this expression executes */
|
||||
|
||||
let aux::constr c = expr_to_constr(fcx.ccx.tcx, p);
|
||||
changed = gen_poststate(fcx, a, c.node) || changed;
|
||||
changed = gen_poststate(fcx, id, c.node) || changed;
|
||||
ret changed;
|
||||
}
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt, ?a)) {
|
||||
changed = join_then_else(fcx, p, conseq, maybe_alt, a, if_check,
|
||||
case (expr_if_check(?p, ?conseq, ?maybe_alt, ?id)) {
|
||||
changed = join_then_else(fcx, p, conseq, maybe_alt, id, if_check,
|
||||
pres)
|
||||
|| changed;
|
||||
|
||||
ret changed;
|
||||
}
|
||||
case (expr_break(?a)) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (expr_cont(?a)) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (expr_port(?a)) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (expr_self_method(_, ?a)) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (expr_anon_obj(?anon_obj, _, _, ?a)) {
|
||||
case (expr_break(?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_cont(?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_port(?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_self_method(_, ?id)) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
case (expr_anon_obj(?anon_obj, _, _, ?id)) {
|
||||
alt (anon_obj.with_obj) {
|
||||
case (some(?e)) {
|
||||
changed = find_pre_post_state_expr(fcx, pres, e);
|
||||
changed =
|
||||
extend_prestate_ann(fcx.ccx, a, pres) || changed;
|
||||
extend_prestate_ann(fcx.ccx, id, pres) || changed;
|
||||
changed =
|
||||
extend_poststate_ann(fcx.ccx, a,
|
||||
extend_poststate_ann(fcx.ccx, id,
|
||||
expr_poststate(fcx.ccx, e)) ||
|
||||
changed;
|
||||
ret changed;
|
||||
}
|
||||
case (none) { ret pure_exp(fcx.ccx, a, pres); }
|
||||
case (none) { ret pure_exp(fcx.ccx, id, pres); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -757,7 +759,7 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
|
|||
*/
|
||||
|
||||
alt (s.node) {
|
||||
case (stmt_decl(?adecl, ?a)) {
|
||||
case (stmt_decl(?adecl, ?id)) {
|
||||
alt (adecl.node) {
|
||||
case (decl_local(?alocal)) {
|
||||
alt (alocal.node.init) {
|
||||
|
@ -775,7 +777,7 @@ fn find_pre_post_state_stmt(&fn_ctxt fcx, &prestate pres, @stmt s) -> bool {
|
|||
an_init.expr))
|
||||
|| changed;
|
||||
changed =
|
||||
gen_poststate(fcx, a,
|
||||
gen_poststate(fcx, id,
|
||||
rec(id=alocal.node.id,
|
||||
c=ninit(alocal.node.ident)))
|
||||
|| changed;
|
||||
|
@ -868,8 +870,8 @@ fn find_pre_post_state_block(&fn_ctxt fcx, &prestate pres0, &block b) ->
|
|||
}
|
||||
}
|
||||
|
||||
set_prestate_ann(fcx.ccx, b.node.a, pres0);
|
||||
set_poststate_ann(fcx.ccx, b.node.a, post);
|
||||
set_prestate_ann(fcx.ccx, b.node.id, pres0);
|
||||
set_poststate_ann(fcx.ccx, b.node.id, post);
|
||||
|
||||
/*
|
||||
log_err "For block:";
|
||||
|
@ -894,7 +896,7 @@ fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool {
|
|||
|
||||
alt (f.body.node.expr) {
|
||||
case (some(?tailexpr)) {
|
||||
auto tailann = expr_ann(tailexpr);
|
||||
auto tailann = expr_node_id(tailexpr);
|
||||
auto tailty = expr_ty(fcx.ccx.tcx, tailexpr);
|
||||
|
||||
// Since blocks and alts and ifs that don't have results
|
||||
|
@ -906,7 +908,7 @@ fn find_pre_post_state_fn(&fn_ctxt fcx, &_fn f) -> bool {
|
|||
auto p = false_postcond(num_local_vars);
|
||||
set_poststate_ann(fcx.ccx, tailann, p);
|
||||
// be sure to set the block poststate to the same thing
|
||||
set_poststate_ann(fcx.ccx, f.body.node.a, p);
|
||||
set_poststate_ann(fcx.ccx, f.body.node.id, p);
|
||||
alt (fcx.enclosing.cf) {
|
||||
case (noreturn) {
|
||||
kill_poststate(fcx, tailann,
|
||||
|
|
|
@ -24,10 +24,10 @@ import util::data::interner;
|
|||
import pretty::ppaux::ty_to_str;
|
||||
|
||||
|
||||
export ann_to_monotype;
|
||||
export ann_to_type;
|
||||
export ann_to_type_params;
|
||||
export ann_to_ty_param_substs_opt_and_ty;
|
||||
export node_id_to_monotype;
|
||||
export node_id_to_type;
|
||||
export node_id_to_type_params;
|
||||
export node_id_to_ty_param_substs_opt_and_ty;
|
||||
export any_item_native;
|
||||
export any_item_rust;
|
||||
export arg;
|
||||
|
@ -42,7 +42,7 @@ export ctxt;
|
|||
export decl_local_ty;
|
||||
export def_has_ty_params;
|
||||
export eq_ty;
|
||||
export expr_ann;
|
||||
export expr_node_id;
|
||||
export expr_has_ty_params;
|
||||
export expr_ty;
|
||||
export fold_ty;
|
||||
|
@ -95,7 +95,7 @@ export mo_val;
|
|||
export mo_alias;
|
||||
export mt;
|
||||
export node_type_table;
|
||||
export pat_ann;
|
||||
export pat_node_id;
|
||||
export pat_ty;
|
||||
export path_to_str;
|
||||
export rename;
|
||||
|
@ -106,7 +106,7 @@ export sequence_element_type;
|
|||
export sequence_is_interior;
|
||||
export struct;
|
||||
export sort_methods;
|
||||
export stmt_ann;
|
||||
export stmt_node_id;
|
||||
export strip_boxes;
|
||||
export sty;
|
||||
export substitute_type_params;
|
||||
|
@ -195,9 +195,8 @@ tag any_item {
|
|||
any_item_native(@ast::native_item, ast::native_abi);
|
||||
}
|
||||
|
||||
type item_table = hashmap[ast::def_id, any_item];
|
||||
|
||||
type constr_table = hashmap[ast::def_id, vec[constr_def]];
|
||||
type item_table = hashmap[ast::node_id, any_item];
|
||||
type constr_table = hashmap[ast::node_id, vec[constr_def]];
|
||||
|
||||
type mt = rec(t ty, ast::mutability mut);
|
||||
|
||||
|
@ -400,7 +399,7 @@ fn mk_ctxt(session::session s, resolve::def_map dm, constr_table cs) -> ctxt {
|
|||
let node_type_table ntt =
|
||||
@smallintmap::mk[ty::ty_param_substs_opt_and_ty]();
|
||||
auto tcache = new_def_hash[ty::ty_param_count_and_ty]();
|
||||
auto items = new_def_hash[any_item]();
|
||||
auto items = new_int_hash[any_item]();
|
||||
auto ts = @interner::mk[raw_t](hash_raw_ty, eq_raw_ty);
|
||||
auto cx =
|
||||
rec(ts=ts,
|
||||
|
@ -1602,32 +1601,32 @@ fn eq_ty(&t a, &t b) -> bool { ret a == b; }
|
|||
|
||||
|
||||
// Type lookups
|
||||
fn ann_to_ty_param_substs_opt_and_ty(&ctxt cx, &ast::ann ann) ->
|
||||
fn node_id_to_ty_param_substs_opt_and_ty(&ctxt cx, &ast::node_id id) ->
|
||||
ty_param_substs_opt_and_ty {
|
||||
|
||||
// Pull out the node type table.
|
||||
alt (smallintmap::find(*cx.node_types, ann.id)) {
|
||||
alt (smallintmap::find(*cx.node_types, id as uint)) {
|
||||
case (none) {
|
||||
cx.sess.bug("ann_to_ty_param_substs_opt_and_ty() called on an " +
|
||||
"untyped node");
|
||||
cx.sess.bug("node_id_to_ty_param_substs_opt_and_ty() called on " +
|
||||
"an untyped node (" + std::int::to_str(id, 10u) + ")");
|
||||
}
|
||||
case (some(?tpot)) { ret tpot; }
|
||||
}
|
||||
}
|
||||
|
||||
fn ann_to_type(&ctxt cx, &ast::ann ann) -> t {
|
||||
ret ann_to_ty_param_substs_opt_and_ty(cx, ann)._1;
|
||||
fn node_id_to_type(&ctxt cx, &ast::node_id id) -> t {
|
||||
ret node_id_to_ty_param_substs_opt_and_ty(cx, id)._1;
|
||||
}
|
||||
|
||||
fn ann_to_type_params(&ctxt cx, &ast::ann ann) -> vec[t] {
|
||||
alt (ann_to_ty_param_substs_opt_and_ty(cx, ann)._0) {
|
||||
fn node_id_to_type_params(&ctxt cx, &ast::node_id id) -> vec[t] {
|
||||
alt (node_id_to_ty_param_substs_opt_and_ty(cx, id)._0) {
|
||||
case (none) { let vec[t] result = []; ret result; }
|
||||
case (some(?tps)) { ret tps; }
|
||||
}
|
||||
}
|
||||
|
||||
fn ann_has_type_params(&ctxt cx, &ast::ann ann) -> bool {
|
||||
auto tpt = ann_to_ty_param_substs_opt_and_ty(cx, ann);
|
||||
fn node_id_has_type_params(&ctxt cx, &ast::node_id id) -> bool {
|
||||
auto tpt = node_id_to_ty_param_substs_opt_and_ty(cx, id);
|
||||
ret !option::is_none[vec[t]](tpt._0);
|
||||
}
|
||||
|
||||
|
@ -1645,8 +1644,8 @@ fn ty_param_substs_opt_and_ty_to_monotype(&ctxt cx,
|
|||
|
||||
// Returns the type of an annotation, with type parameter substitutions
|
||||
// performed if applicable.
|
||||
fn ann_to_monotype(&ctxt cx, ast::ann a) -> t {
|
||||
auto tpot = ann_to_ty_param_substs_opt_and_ty(cx, a);
|
||||
fn node_id_to_monotype(&ctxt cx, ast::node_id id) -> t {
|
||||
auto tpot = node_id_to_ty_param_substs_opt_and_ty(cx, id);
|
||||
ret ty_param_substs_opt_and_ty_to_monotype(cx, tpot);
|
||||
}
|
||||
|
||||
|
@ -1726,59 +1725,61 @@ fn ty_var_id(&ctxt cx, t typ) -> int {
|
|||
|
||||
|
||||
// Type accessors for AST nodes
|
||||
fn block_ty(&ctxt cx, &ast::block b) -> t { ret ann_to_type(cx, b.node.a); }
|
||||
fn block_ty(&ctxt cx, &ast::block b) -> t {
|
||||
ret node_id_to_type(cx, b.node.id);
|
||||
}
|
||||
|
||||
|
||||
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
|
||||
// doesn't provide type parameter substitutions.
|
||||
fn pat_ty(&ctxt cx, &@ast::pat pat) -> t {
|
||||
ret ann_to_monotype(cx, pat_ann(pat));
|
||||
ret node_id_to_monotype(cx, pat_node_id(pat));
|
||||
}
|
||||
|
||||
fn expr_ann(&@ast::expr e) -> ast::ann {
|
||||
alt (e.node) {
|
||||
case (ast::expr_vec(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_tup(_, ?a)) { ret a; }
|
||||
case (ast::expr_rec(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_call(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_bind(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_binary(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_unary(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_lit(_, ?a)) { ret a; }
|
||||
case (ast::expr_cast(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_if(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_if_check(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_while(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_for(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_for_each(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_do_while(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_alt(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_fn(_, ?a)) { ret a; }
|
||||
case (ast::expr_block(_, ?a)) { ret a; }
|
||||
case (ast::expr_move(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_assign(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_swap(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_assign_op(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_send(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_recv(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_field(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_index(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_path(_, ?a)) { ret a; }
|
||||
case (ast::expr_ext(_, _, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_fail(?a, _)) { ret a; }
|
||||
case (ast::expr_ret(_, ?a)) { ret a; }
|
||||
case (ast::expr_put(_, ?a)) { ret a; }
|
||||
case (ast::expr_be(_, ?a)) { ret a; }
|
||||
case (ast::expr_log(_, _, ?a)) { ret a; }
|
||||
case (ast::expr_assert(_, ?a)) { ret a; }
|
||||
case (ast::expr_check(_, ?a)) { ret a; }
|
||||
case (ast::expr_port(?a)) { ret a; }
|
||||
case (ast::expr_chan(_, ?a)) { ret a; }
|
||||
case (ast::expr_anon_obj(_, _, _, ?a)) { ret a; }
|
||||
case (ast::expr_break(?a)) { ret a; }
|
||||
case (ast::expr_cont(?a)) { ret a; }
|
||||
case (ast::expr_self_method(_, ?a)) { ret a; }
|
||||
case (ast::expr_spawn(_, _, _, _, ?a)) { ret a; }
|
||||
fn expr_node_id(&@ast::expr e) -> ast::node_id {
|
||||
ret alt (e.node) {
|
||||
case (ast::expr_vec(_, _, _, ?id)) { id }
|
||||
case (ast::expr_tup(_, ?id)) { id }
|
||||
case (ast::expr_rec(_, _, ?id)) { id }
|
||||
case (ast::expr_call(_, _, ?id)) { id }
|
||||
case (ast::expr_bind(_, _, ?id)) { id }
|
||||
case (ast::expr_binary(_, _, _, ?id)) { id }
|
||||
case (ast::expr_unary(_, _, ?id)) { id }
|
||||
case (ast::expr_lit(_, ?id)) { id }
|
||||
case (ast::expr_cast(_, _, ?id)) { id }
|
||||
case (ast::expr_if(_, _, _, ?id)) { id }
|
||||
case (ast::expr_if_check(_, _, _, ?id)) { id }
|
||||
case (ast::expr_while(_, _, ?id)) { id }
|
||||
case (ast::expr_for(_, _, _, ?id)) { id }
|
||||
case (ast::expr_for_each(_, _, _, ?id)) { id }
|
||||
case (ast::expr_do_while(_, _, ?id)) { id }
|
||||
case (ast::expr_alt(_, _, ?id)) { id }
|
||||
case (ast::expr_fn(_, ?id)) { id }
|
||||
case (ast::expr_block(_, ?id)) { id }
|
||||
case (ast::expr_move(_, _, ?id)) { id }
|
||||
case (ast::expr_assign(_, _, ?id)) { id }
|
||||
case (ast::expr_swap(_, _, ?id)) { id }
|
||||
case (ast::expr_assign_op(_, _, _, ?id)) { id }
|
||||
case (ast::expr_send(_, _, ?id)) { id }
|
||||
case (ast::expr_recv(_, _, ?id)) { id }
|
||||
case (ast::expr_field(_, _, ?id)) { id }
|
||||
case (ast::expr_index(_, _, ?id)) { id }
|
||||
case (ast::expr_path(_, ?id)) { id }
|
||||
case (ast::expr_ext(_, _, _, _, ?id)) { id }
|
||||
case (ast::expr_fail(?id, _)) { id }
|
||||
case (ast::expr_ret(_, ?id)) { id }
|
||||
case (ast::expr_put(_, ?id)) { id }
|
||||
case (ast::expr_be(_, ?id)) { id }
|
||||
case (ast::expr_log(_, _, ?id)) { id }
|
||||
case (ast::expr_assert(_, ?id)) { id }
|
||||
case (ast::expr_check(_, ?id)) { id }
|
||||
case (ast::expr_port(?id)) { id }
|
||||
case (ast::expr_chan(_, ?id)) { id }
|
||||
case (ast::expr_anon_obj(_, _, _, ?id)) { id }
|
||||
case (ast::expr_break(?id)) { id }
|
||||
case (ast::expr_cont(?id)) { id }
|
||||
case (ast::expr_self_method(_, ?id)) { id }
|
||||
case (ast::expr_spawn(_, _, _, _, ?id)) { id }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1790,39 +1791,39 @@ fn expr_ann(&@ast::expr e) -> ast::ann {
|
|||
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
|
||||
// expr_ty_params_and_ty() below.
|
||||
fn expr_ty(&ctxt cx, &@ast::expr expr) -> t {
|
||||
ret ann_to_monotype(cx, expr_ann(expr));
|
||||
ret node_id_to_monotype(cx, expr_node_id(expr));
|
||||
}
|
||||
|
||||
fn expr_ty_params_and_ty(&ctxt cx, &@ast::expr expr) -> tup(vec[t], t) {
|
||||
auto a = expr_ann(expr);
|
||||
ret tup(ann_to_type_params(cx, a), ann_to_type(cx, a));
|
||||
auto a = expr_node_id(expr);
|
||||
ret tup(node_id_to_type_params(cx, a), node_id_to_type(cx, a));
|
||||
}
|
||||
|
||||
fn expr_has_ty_params(&ctxt cx, &@ast::expr expr) -> bool {
|
||||
ret ann_has_type_params(cx, expr_ann(expr));
|
||||
ret node_id_has_type_params(cx, expr_node_id(expr));
|
||||
}
|
||||
|
||||
fn decl_local_ty(&ctxt cx, &@ast::local l) -> t {
|
||||
ret ann_to_type(cx, l.node.ann);
|
||||
ret node_id_to_type(cx, l.node.id);
|
||||
}
|
||||
|
||||
fn stmt_ann(&@ast::stmt s) -> ast::ann {
|
||||
fn stmt_node_id(&@ast::stmt s) -> ast::node_id {
|
||||
alt (s.node) {
|
||||
case (ast::stmt_decl(_, ?a)) { ret a; }
|
||||
case (ast::stmt_expr(_, ?a)) { ret a; }
|
||||
case (ast::stmt_decl(_, ?id)) { ret id; }
|
||||
case (ast::stmt_expr(_, ?id)) { ret id; }
|
||||
case (ast::stmt_crate_directive(_)) {
|
||||
log_err "ty::stmt_ann(): crate directive found";
|
||||
log_err "ty::stmt_node_id(): crate directive found";
|
||||
fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pat_ann(&@ast::pat p) -> ast::ann {
|
||||
fn pat_node_id(&@ast::pat p) -> ast::node_id {
|
||||
alt (p.node) {
|
||||
case (ast::pat_wild(?a)) { ret a; }
|
||||
case (ast::pat_bind(_, _, ?a)) { ret a; }
|
||||
case (ast::pat_lit(_, ?a)) { ret a; }
|
||||
case (ast::pat_tag(_, _, ?a)) { ret a; }
|
||||
case (ast::pat_wild(?id)) { ret id; }
|
||||
case (ast::pat_bind(_, ?id)) { ret id; }
|
||||
case (ast::pat_lit(_, ?id)) { ret id; }
|
||||
case (ast::pat_tag(_, _, ?id)) { ret id; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2688,14 +2689,15 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
|
|||
if (cx.sess.get_targ_crate_num() != id._0) {
|
||||
ret creader::get_tag_variants(cx, id);
|
||||
}
|
||||
assert (cx.items.contains_key(id));
|
||||
alt (cx.items.get(id)) {
|
||||
assert (cx.items.contains_key(id._1));
|
||||
alt (cx.items.get(id._1)) {
|
||||
case (any_item_rust(?item)) {
|
||||
alt (item.node) {
|
||||
case (ast::item_tag(?variants, _)) {
|
||||
let vec[variant_info] result = [];
|
||||
for (ast::variant variant in variants) {
|
||||
auto ctor_ty = ann_to_monotype(cx, variant.node.ann);
|
||||
auto ctor_ty = node_id_to_monotype
|
||||
(cx, variant.node.id);
|
||||
let vec[t] arg_tys = [];
|
||||
if (vec::len[ast::variant_arg](variant.node.args) >
|
||||
0u) {
|
||||
|
@ -2705,7 +2707,9 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> vec[variant_info] {
|
|||
}
|
||||
auto did = variant.node.id;
|
||||
result +=
|
||||
[rec(args=arg_tys, ctor_ty=ctor_ty, id=did)];
|
||||
[rec(args=arg_tys,
|
||||
ctor_ty=ctor_ty,
|
||||
id=ast::local_def(did))];
|
||||
}
|
||||
ret result;
|
||||
}
|
||||
|
@ -2759,8 +2763,8 @@ fn ret_ty_of_fn_ty(ctxt cx, t a_ty) -> t {
|
|||
}
|
||||
}
|
||||
|
||||
fn ret_ty_of_fn(ctxt cx, ast::ann ann) -> t {
|
||||
ret ret_ty_of_fn_ty(cx, ann_to_type(cx, ann));
|
||||
fn ret_ty_of_fn(ctxt cx, ast::node_id id) -> t {
|
||||
ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id));
|
||||
}
|
||||
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -34,7 +34,7 @@ type visitor[E] =
|
|||
fn(&@expr, &E, &vt[E]) visit_expr,
|
||||
fn(&@ty, &E, &vt[E]) visit_ty,
|
||||
fn(&@constr, &E, &vt[E]) visit_constr,
|
||||
fn(&_fn, &vec[ty_param], &span, &ident, &def_id, &ann, &E, &vt[E])
|
||||
fn(&_fn, &vec[ty_param], &span, &ident, node_id, &E, &vt[E])
|
||||
visit_fn);
|
||||
|
||||
fn default_visitor[E]() -> visitor[E] {
|
||||
|
@ -51,7 +51,7 @@ fn default_visitor[E]() -> visitor[E] {
|
|||
visit_expr=bind visit_expr[E](_, _, _),
|
||||
visit_ty=bind visit_ty[E](_, _, _),
|
||||
visit_constr=bind visit_constr[E](_, _, _),
|
||||
visit_fn=bind visit_fn[E](_, _, _, _, _, _, _, _));
|
||||
visit_fn=bind visit_fn[E](_, _, _, _, _, _, _));
|
||||
}
|
||||
|
||||
fn visit_crate[E](&crate c, &E e, &vt[E] v) {
|
||||
|
@ -103,7 +103,7 @@ fn visit_item[E](&@item i, &E e, &vt[E] v) {
|
|||
vt(v).visit_expr(ex, e, v);
|
||||
}
|
||||
case (item_fn(?f, ?tp)) {
|
||||
vt(v).visit_fn(f, tp, i.span, i.ident, i.id, i.ann, e, v);
|
||||
vt(v).visit_fn(f, tp, i.span, i.ident, i.id, e, v);
|
||||
}
|
||||
case (item_mod(?m)) { vt(v).visit_mod(m, i.span, e, v); }
|
||||
case (item_native_mod(?nm)) {
|
||||
|
@ -126,13 +126,13 @@ fn visit_item[E](&@item i, &E e, &vt[E] v) {
|
|||
for (obj_field f in ob.fields) { vt(v).visit_ty(f.ty, e, v); }
|
||||
for (@method m in ob.methods) {
|
||||
vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident,
|
||||
m.node.id, m.node.ann, e, v);
|
||||
m.node.id, e, v);
|
||||
}
|
||||
alt (ob.dtor) {
|
||||
case (none) { }
|
||||
case (some(?m)) {
|
||||
vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident,
|
||||
m.node.id, m.node.ann, e, v);
|
||||
m.node.id, e, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ fn visit_pat[E](&@pat p, &E e, &vt[E] v) {
|
|||
|
||||
fn visit_native_item[E](&@native_item ni, &E e, &vt[E] v) {
|
||||
alt (ni.node) {
|
||||
case (native_item_fn(_, _, ?fd, _, _, _)) { visit_fn_decl(fd, e, v); }
|
||||
case (native_item_fn(_, _, ?fd, _, _)) { visit_fn_decl(fd, e, v); }
|
||||
case (native_item_ty(_, _)) { }
|
||||
}
|
||||
}
|
||||
|
@ -213,8 +213,8 @@ fn visit_fn_decl[E](&fn_decl fd, &E e, &vt[E] v) {
|
|||
vt(v).visit_ty(fd.output, e, v);
|
||||
}
|
||||
|
||||
fn visit_fn[E](&_fn f, &vec[ty_param] tp, &span sp, &ident i, &def_id d,
|
||||
&ann a, &E e, &vt[E] v) {
|
||||
fn visit_fn[E](&_fn f, &vec[ty_param] tp, &span sp, &ident i,
|
||||
node_id id, &E e, &vt[E] v) {
|
||||
visit_fn_decl(f.decl, e, v);
|
||||
vt(v).visit_block(f.body, e, v);
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
|
|||
}
|
||||
for (@method m in anon_obj.methods) {
|
||||
vt(v).visit_fn(m.node.meth, [], m.span, m.node.ident,
|
||||
m.node.id, m.node.ann, e, v);
|
||||
m.node.id, e, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,10 +40,8 @@ type ast_visitor =
|
|||
fn(&@ast::ty) visit_ty_pre,
|
||||
fn(&@ast::ty) visit_ty_post,
|
||||
fn(&@ast::constr) visit_constr,
|
||||
fn(&ast::_fn, &span, &ast::ident, &ast::def_id, &ast::ann)
|
||||
visit_fn_pre,
|
||||
fn(&ast::_fn, &span, &ast::ident, &ast::def_id, &ast::ann)
|
||||
visit_fn_post);
|
||||
fn(&ast::_fn, &span, &ast::ident, ast::node_id) visit_fn_pre,
|
||||
fn(&ast::_fn, &span, &ast::ident, ast::node_id) visit_fn_post);
|
||||
|
||||
fn walk_crate(&ast_visitor v, &ast::crate c) {
|
||||
if (!v.keep_going()) { ret; }
|
||||
|
@ -104,7 +102,7 @@ fn walk_item(&ast_visitor v, @ast::item i) {
|
|||
alt (i.node) {
|
||||
case (ast::item_const(?t, ?e)) { walk_ty(v, t); walk_expr(v, e); }
|
||||
case (ast::item_fn(?f, _)) {
|
||||
walk_fn(v, f, i.span, i.ident, i.id, i.ann);
|
||||
walk_fn(v, f, i.span, i.ident, i.id);
|
||||
}
|
||||
case (ast::item_mod(?m)) { walk_mod(v, m); }
|
||||
case (ast::item_native_mod(?nm)) { walk_native_mod(v, nm); }
|
||||
|
@ -120,15 +118,13 @@ fn walk_item(&ast_visitor v, @ast::item i) {
|
|||
for (ast::obj_field f in ob.fields) { walk_ty(v, f.ty); }
|
||||
for (@ast::method m in ob.methods) {
|
||||
v.visit_method_pre(m);
|
||||
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id,
|
||||
m.node.ann);
|
||||
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id);
|
||||
v.visit_method_post(m);
|
||||
}
|
||||
alt (ob.dtor) {
|
||||
case (none) { }
|
||||
case (some(?m)) {
|
||||
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id,
|
||||
m.node.ann);
|
||||
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +203,7 @@ fn walk_native_item(&ast_visitor v, @ast::native_item ni) {
|
|||
if (!v.keep_going()) { ret; }
|
||||
v.visit_native_item_pre(ni);
|
||||
alt (ni.node) {
|
||||
case (ast::native_item_fn(_, _, ?fd, _, _, _)) {
|
||||
case (ast::native_item_fn(_, _, ?fd, _, _)) {
|
||||
walk_fn_decl(v, fd);
|
||||
}
|
||||
case (ast::native_item_ty(_, _)) { }
|
||||
|
@ -222,12 +218,12 @@ fn walk_fn_decl(&ast_visitor v, &ast::fn_decl fd) {
|
|||
}
|
||||
|
||||
fn walk_fn(&ast_visitor v, &ast::_fn f, &span sp, &ast::ident i,
|
||||
&ast::def_id d, &ast::ann a) {
|
||||
ast::node_id d) {
|
||||
if (!v.keep_going()) { ret; }
|
||||
v.visit_fn_pre(f, sp, i, d, a);
|
||||
v.visit_fn_pre(f, sp, i, d);
|
||||
walk_fn_decl(v, f.decl);
|
||||
walk_block(v, f.body);
|
||||
v.visit_fn_post(f, sp, i, d, a);
|
||||
v.visit_fn_post(f, sp, i, d);
|
||||
}
|
||||
|
||||
fn walk_block(&ast_visitor v, &ast::block b) {
|
||||
|
@ -402,8 +398,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
|
|||
// Methods
|
||||
for (@ast::method m in anon_obj.methods) {
|
||||
v.visit_method_pre(m);
|
||||
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id,
|
||||
m.node.ann);
|
||||
walk_fn(v, m.node.meth, m.span, m.node.ident, m.node.id);
|
||||
v.visit_method_post(m);
|
||||
}
|
||||
}
|
||||
|
@ -445,9 +440,7 @@ fn def_visit_ty(&@ast::ty t) { }
|
|||
|
||||
fn def_visit_constr(&@ast::constr c) { }
|
||||
|
||||
fn def_visit_fn(&ast::_fn f, &span sp, &ast::ident i, &ast::def_id d,
|
||||
&ast::ann a) {
|
||||
}
|
||||
fn def_visit_fn(&ast::_fn f, &span sp, &ast::ident i, ast::node_id d) { }
|
||||
|
||||
fn default_visitor() -> ast_visitor {
|
||||
ret rec(keep_going=def_keep_going,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
import std::uint;
|
||||
import std::int;
|
||||
import std::vec;
|
||||
import std::str;
|
||||
import std::io;
|
||||
|
@ -323,8 +324,8 @@ fn print_item(&ps s, &@ast::item item) {
|
|||
word_nbsp(s, "type");
|
||||
word(s.s, id);
|
||||
}
|
||||
case (ast::native_item_fn(?id, ?lname, ?decl, ?typarams,
|
||||
_, _)) {
|
||||
case (ast::native_item_fn(?id, ?lname, ?decl,
|
||||
?typarams, _)) {
|
||||
print_fn(s, decl, ast::proto_fn, id, typarams);
|
||||
alt (lname) {
|
||||
case (none) { }
|
||||
|
@ -426,7 +427,7 @@ fn print_item(&ps s, &@ast::item item) {
|
|||
alt (s.mode) {
|
||||
case (mo_identified) {
|
||||
space(s.s);
|
||||
synth_comment(s, uint::to_str(item.ann.id, 10u));
|
||||
synth_comment(s, int::to_str(item.id, 10u));
|
||||
}
|
||||
case (_) {/* no-op */ }
|
||||
}
|
||||
|
@ -497,7 +498,7 @@ fn print_block(&ps s, ast::block blk) {
|
|||
alt (s.mode) {
|
||||
case (mo_identified) {
|
||||
space(s.s);
|
||||
synth_comment(s, "block " + uint::to_str(blk.node.a.id, 10u));
|
||||
synth_comment(s, "block " + int::to_str(blk.node.id, 10u));
|
||||
}
|
||||
case (_) {/* no-op */ }
|
||||
}
|
||||
|
@ -865,7 +866,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
|
|||
}
|
||||
case (mo_identified) {
|
||||
space(s.s);
|
||||
synth_comment(s, uint::to_str(ty::expr_ann(expr).id, 10u));
|
||||
synth_comment(s, int::to_str(ty::expr_node_id(expr), 10u));
|
||||
pclose(s);
|
||||
}
|
||||
}
|
||||
|
@ -891,7 +892,7 @@ fn print_decl(&ps s, &@ast::decl decl) {
|
|||
alt (s.mode) {
|
||||
case (mo_untyped) {/* no-op */ }
|
||||
case (mo_typed(?tcx)) {
|
||||
auto lty = ty::ann_to_type(tcx, loc.node.ann);
|
||||
auto lty = ty::node_id_to_type(tcx, loc.node.id);
|
||||
word_space(s, ppaux::ty_to_str(tcx, lty));
|
||||
}
|
||||
case (mo_identified) {/* no-op */ }
|
||||
|
@ -943,7 +944,7 @@ fn print_pat(&ps s, &@ast::pat pat) {
|
|||
maybe_print_comment(s, pat.span.lo);
|
||||
alt (pat.node) {
|
||||
case (ast::pat_wild(_)) { word(s.s, "_"); }
|
||||
case (ast::pat_bind(?id, _, _)) { word(s.s, "?" + id); }
|
||||
case (ast::pat_bind(?id, _)) { word(s.s, "?" + id); }
|
||||
case (ast::pat_lit(?lit, _)) { print_literal(s, lit); }
|
||||
case (ast::pat_tag(?path, ?args, _)) {
|
||||
print_path(s, path);
|
||||
|
@ -959,7 +960,7 @@ fn print_pat(&ps s, &@ast::pat pat) {
|
|||
alt (s.mode) {
|
||||
case (mo_identified) {
|
||||
space(s.s);
|
||||
synth_comment(s, uint::to_str(ty::pat_ann(pat).id, 10u));
|
||||
synth_comment(s, int::to_str(ty::pat_node_id(pat), 10u));
|
||||
}
|
||||
case (_) {/* no-op */ }
|
||||
}
|
||||
|
@ -1029,7 +1030,7 @@ fn print_view_item(&ps s, &@ast::view_item item) {
|
|||
hardbreak_if_not_bol(s);
|
||||
maybe_print_comment(s, item.span.lo);
|
||||
alt (item.node) {
|
||||
case (ast::view_item_use(?id, ?mta, _, _)) {
|
||||
case (ast::view_item_use(?id, ?mta, _)) {
|
||||
head(s, "use");
|
||||
word(s.s, id);
|
||||
if (vec::len(mta) > 0u) {
|
||||
|
@ -1059,7 +1060,7 @@ fn print_view_item(&ps s, &@ast::view_item item) {
|
|||
}
|
||||
word(s.s, "::*");
|
||||
}
|
||||
case (ast::view_item_export(?id)) {
|
||||
case (ast::view_item_export(?id, _)) {
|
||||
head(s, "export");
|
||||
word(s.s, id);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue