about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-06-20 09:59:16 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-06-20 23:53:28 +0200
commit40db3aa6fbe2f0d8d7f9bb85a9fd47b8cca2938b (patch)
treee60308a91da459967a7bf419c44986fbed7f6819 /src
parent77af54bf6f7d5e7cb704e08689ea96746bc57819 (diff)
Add a separate AST mapping phase
This will replace the various node_id-to-node mappings done in several
other passes. This commit already uses the new map in resolve, dropping
the ast_map that was built there before.
Diffstat (limited to 'src')
-rw-r--r--src/comp/driver/rustc.rs7
-rw-r--r--src/comp/middle/resolve.rs30
-rw-r--r--src/comp/rustc.rc1
3 files changed, 16 insertions, 22 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index f5f79fb0a2a..040b551a529 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -80,9 +80,11 @@ fn compile_input(session::session sess, eval::env env, str input,
     auto crate =
         time(time_passes, "parsing", bind parse_input(sess, p, input));
     if (sess.get_opts().output_type == link::output_type_none) { ret; }
+    auto ast_map = time(time_passes, "ast indexing",
+                        bind middle::ast_map::map_crate(*crate));
     auto d =
         time(time_passes, "resolution",
-             bind resolve::resolve_crate(sess, crate));
+             bind resolve::resolve_crate(sess, ast_map, crate));
     auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
     time[()](time_passes, "typechecking",
              bind typeck::check_crate(ty_cx, crate));
@@ -107,7 +109,8 @@ fn pretty_print_input(session::session sess, eval::env env, str input,
     auto mode;
     alt (ppm) {
         case (ppm_typed) {
-            auto d = resolve::resolve_crate(sess, crate);
+            auto amap = middle::ast_map::map_crate(*crate);
+            auto d = resolve::resolve_crate(sess, amap, crate);
             auto ty_cx = ty::mk_ctxt(sess, d._0, d._1);
             typeck::check_crate(ty_cx, crate);
             mode = ppaux::mo_typed(ty_cx);
diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs
index f24d0e71859..24341176079 100644
--- a/src/comp/middle/resolve.rs
+++ b/src/comp/middle/resolve.rs
@@ -116,7 +116,7 @@ type env =
     rec(crate_map crate_map,
         def_map def_map,
         constr_table fn_constrs,
-        hashmap[ast::node_id, @ast::item] ast_map,
+        ast_map::map ast_map,
         hashmap[ast::node_id, import_state] imports,
         hashmap[ast::node_id, @indexed_mod] mod_map,
         hashmap[def_id, vec[ident]] ext_map,
@@ -130,13 +130,13 @@ tag dir { inside; outside; }
 
 tag namespace { ns_value; ns_type; ns_module; }
 
-fn resolve_crate(session sess, @ast::crate crate) ->
+fn resolve_crate(session sess, &ast_map::map amap, @ast::crate crate) ->
    tup(def_map, constr_table) {
     auto e =
         @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](),
+             ast_map=amap,
              imports=new_int_hash[import_state](),
              mod_map=new_int_hash[@indexed_mod](),
              ext_map=new_def_hash[vec[ident]](),
@@ -187,7 +187,6 @@ fn map_crate(&@env e, &@ast::crate c) {
                                       index=index_mod(md),
                                       mutable glob_imports=vec::empty[def](),
                                       glob_imported_names=s));
-                e.ast_map.insert(i.id, i);
             }
             case (ast::item_native_mod(?nmd)) {
                 auto s = new_str_hash[import_state]();
@@ -196,13 +195,8 @@ fn map_crate(&@env e, &@ast::crate c) {
                                       index=index_nmod(nmd),
                                       mutable glob_imports=vec::empty[def](),
                                       glob_imported_names=s));
-                e.ast_map.insert(i.id, i);
             }
-            case (ast::item_obj(_, _, ?ctor_id)) {
-                e.ast_map.insert(i.id, i);
-                e.ast_map.insert(ctor_id, i);
-            }
-            case (_) { e.ast_map.insert(i.id, i); }
+            case (_) { }
         }
     }
     // Next, assemble the links for globbed imports.
@@ -969,16 +963,12 @@ 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)._1)) {
-                    case (some(?it)) {
-                        e.sess.span_note(it.span,
-                                         "'" + id + "' is defined here.");
-                    }
-                    case (_) {
-                        e.sess.bug("Internal error: imports and matches " +
-                                   "don't agree");
-                    }
-                }
+                auto span = alt (e.ast_map.get(ast::def_id_of_def(match)._1)){
+                    case (ast_map::node_item(?it)) { it.span }
+                    case (ast_map::node_obj_ctor(?it)) { it.span }
+                    case (ast_map::node_native_item(?it)) { it.span }
+                };
+                e.sess.span_note(span, "'" + id + "' is defined here.");
             }
             e.sess.span_fatal(sp,
                             "'" + id + "' is glob-imported from" +
diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc
index b75b2f221fc..da2a8640a7d 100644
--- a/src/comp/rustc.rc
+++ b/src/comp/rustc.rc
@@ -19,6 +19,7 @@ mod middle {
     mod walk;
     mod visit;
     mod metadata;
+    mod ast_map;
     mod resolve;
     mod typeck;
     mod alias;