Keep resolve data in external hash table, rather than embedded defs

One step closer to removing fold and having a single, immutable AST.
Resolve still uses fold, because it has to detect and transform
expr_field expressions. If we go through on our plan of moving to a
different syntax for module dereferencing, the parser can spit out
expr_field expressions, and resolve can move to walk.

(I am truly sorry for the things I did in typestate_check.rs. I expect
we'll want to change that to walk as well in the near future, at which
point it should probably pass around a context record, which could
hold the def_map.)
This commit is contained in:
Marijn Haverbeke
2011-05-12 13:25:18 +02:00
parent 2b36e40c58
commit 358a1aeec9
14 changed files with 521 additions and 486 deletions

View File

@@ -34,7 +34,8 @@ type ctx = @rec(parser p,
eval_mode mode,
mutable vec[str] deps,
session.session sess,
mutable uint chpos);
mutable uint chpos,
mutable uint next_ann);
fn mk_env() -> env {
let env e = vec();
@@ -113,7 +114,7 @@ fn eval_lit(ctx cx, span sp, @ast.lit lit) -> val {
fn eval_expr(ctx cx, env e, @ast.expr x) -> val {
alt (x.node) {
case (ast.expr_path(?pth, _, _)) {
case (ast.expr_path(?pth, _)) {
if (Vec.len[ident](pth.node.idents) == 1u &&
Vec.len[@ast.ty](pth.node.types) == 0u) {
ret lookup(cx.sess, e, x.span, pth.node.idents.(0));
@@ -383,12 +384,14 @@ fn eval_crate_directive(ctx cx,
}
auto start_id = cx.p.next_def_id();
auto p0 = new_parser(cx.sess, e, start_id, full_path, cx.chpos);
auto p0 = new_parser(cx.sess, e, start_id, full_path, cx.chpos,
cx.next_ann);
auto m0 = parse_mod_items(p0, token.EOF);
auto next_id = p0.next_def_id();
// Thread defids and chpos through the parsers
cx.p.set_def(next_id._1);
cx.chpos = p0.get_chpos();
cx.next_ann = p0.next_ann_num();
auto im = ast.item_mod(id, m0, next_id);
auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
Vec.push[@ast.item](items, i);