about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-12-16 16:55:22 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2011-12-16 22:17:47 +0100
commitdd9693f211f65d4c69a2e65c3e33ccc337d7f695 (patch)
treed3f744255966cdc6e20d69633c159278161fe3bb
parentdbfa1b56894c06dd1556cb00d16d8208447db3b8 (diff)
downloadrust-dd9693f211f65d4c69a2e65c3e33ccc337d7f695.tar.gz
rust-dd9693f211f65d4c69a2e65c3e33ccc337d7f695.zip
Reserve node_id 0 for the crate top-level module
And define a const to refer to it.
-rw-r--r--src/comp/middle/resolve.rs20
-rw-r--r--src/comp/syntax/ast.rs1
2 files changed, 12 insertions, 9 deletions
diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs
index 7b3db277ef6..75bd5de7c68 100644
--- a/src/comp/middle/resolve.rs
+++ b/src/comp/middle/resolve.rs
@@ -27,8 +27,6 @@ export def_map, ext_map, exp_map, impl_map, iscopes;
 // locates all names (in expressions, types, and alt patterns) and resolves
 // them, storing the resulting def in the AST nodes.
 
-const crate_mod: int = -1;
-
 tag scope {
     scope_crate;
     scope_item(@ast::item);
@@ -176,7 +174,7 @@ fn map_crate(e: @env, c: @ast::crate) {
     visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v_map_mod));
 
     // Register the top-level mod
-    e.mod_map.insert(crate_mod,
+    e.mod_map.insert(ast::crate_node_id,
                      @{m: some(c.node.module),
                        index: index_mod(c.node.module),
                        mutable glob_imports: [],
@@ -260,7 +258,7 @@ fn map_crate(e: @env, c: @ast::crate) {
                     e.block_map.insert(b.node.id, globs);
                   }
                   scope_crate. {
-                    e.mod_map.get(crate_mod).glob_imports += [glob];
+                    e.mod_map.get(ast::crate_node_id).glob_imports += [glob];
                   }
                 }
             }
@@ -534,7 +532,8 @@ fn resolve_import(e: env, defid: ast::def_id, name: ast::ident,
             lst(id, b.node.view_items)
           }
           cons(scope_crate., _) {
-            lst(id, option::get(e.mod_map.get(crate_mod).m).view_items)
+            lst(id,
+                option::get(e.mod_map.get(ast::crate_node_id).m).view_items)
           }
         }
     }
@@ -639,7 +638,7 @@ fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
         let did = def_id_of_def(def);
         if did.crate == ast::local_crate {
             path = e.mod_map.get(did.node).path + path;
-        } else if did.node != -1 {
+        } else if did.node != ast::crate_node_id {
             let paths = e.ext_map.get(did);
             if vec::len(paths) > 0u {
                 path = str::connect(paths, "::") + "::" + path;
@@ -744,7 +743,8 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
        option::t<def> {
         alt s {
           scope_crate. {
-            ret lookup_in_local_mod(e, crate_mod, sp, name, ns, inside);
+            ret lookup_in_local_mod(e, ast::crate_node_id, sp,
+                                    name, ns, inside);
           }
           scope_item(it) {
             alt it.node {
@@ -1057,7 +1057,9 @@ fn lookup_in_mod(e: env, m: def, sp: span, name: ident, ns: namespace,
         let cached = e.ext_cache.find({did: defid, ident: name, ns: ns});
         if !is_none(cached) { ret cached; }
         let path = [name];
-        if defid.node != crate_mod { path = e.ext_map.get(defid) + path; }
+        if defid.node != ast::crate_node_id {
+            path = e.ext_map.get(defid) + path; 
+        }
         let fnd = lookup_external(e, defid.crate, path, ns);
         if !is_none(fnd) {
             e.ext_cache.insert({did: defid, ident: name, ns: ns},
@@ -1079,7 +1081,7 @@ fn found_view_item(e: env, vi: @ast::view_item) -> option::t<def> {
     alt vi.node {
       ast::view_item_use(_, _, id) {
         let cnum = cstore::get_use_stmt_cnum(e.cstore, id);
-        ret some(ast::def_mod({crate: cnum, node: crate_mod}));
+        ret some(ast::def_mod({crate: cnum, node: ast::crate_node_id}));
       }
     }
 }
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index d85849b2571..b7af23e9dd5 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -22,6 +22,7 @@ type node_id = int;
 type def_id = {crate: crate_num, node: node_id};
 
 const local_crate: crate_num = 0;
+const crate_node_id: node_id = 0;
 
 type ty_param = {ident: ident, kind: kind};