Skip to content

Commit 0d83956

Browse files
committed
Refactor resolve_import
Issue #817
1 parent 206495b commit 0d83956

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

src/comp/middle/resolve.rs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ tag scope {
6161
type scopes = list<scope>;
6262

6363
tag import_state {
64-
todo(@ast::view_item, scopes); // only used for explicit imports
65-
todo_from(@ast::view_item, ast::import_ident, scopes);
66-
64+
todo(ast::node_id, ast::ident, [ast::ident], codemap::span, scopes);
6765
resolving(span);
6866
resolved(option::t<def>,
6967
/* value */
@@ -173,13 +171,15 @@ fn map_crate(e: &@env, c: &@ast::crate) {
173171
glob_imported_names: new_str_hash::<import_state>()});
174172
fn index_vi(e: @env, i: &@ast::view_item, sc: &scopes, v: &vt<scopes>) {
175173
alt i.node {
176-
ast::view_item_import(_, ids, id) {
177-
e.imports.insert(id, todo(i, sc));
174+
ast::view_item_import(name, ids, id) {
175+
e.imports.insert(id, todo(id, name, ids, i.span, sc));
178176
}
179177
ast::view_item_import_from(mod_path, idents, id) {
180178
for ident in idents {
181179
e.imports.insert(ident.node.id,
182-
todo_from(i, ident, sc));
180+
todo(ident.node.id, ident.node.name,
181+
mod_path + ~[ident.node.name],
182+
ident.span, sc));
183183
}
184184
}
185185
_ { }
@@ -251,23 +251,9 @@ fn resolve_imports(e: &env) {
251251
for each it: @{key: ast::node_id, val: import_state} in e.imports.items()
252252
{
253253
alt it.val {
254-
todo(item, sc) {
255-
alt item.node {
256-
ast::view_item_import(name, ids, id) {
257-
resolve_import(e, local_def(id),
258-
name, ids, item.span, sc);
259-
}
260-
}
261-
}
262-
todo_from(item, ident, sc) {
263-
alt item.node {
264-
ast::view_item_import_from(mod_path, idents, _) {
265-
resolve_import(e, local_def(ident.node.id),
266-
ident.node.name,
267-
mod_path + ~[ident.node.name],
268-
ident.span, sc);
269-
}
270-
}
254+
todo(node_id, name, path, span, scopes) {
255+
resolve_import(e, local_def(node_id),
256+
name, path, span, scopes);
271257
}
272258
resolved(_, _, _) { }
273259
}
@@ -947,24 +933,9 @@ fn found_view_item(e: &env, vi: @ast::view_item, ns: namespace) ->
947933

948934
fn lookup_import(e: &env, defid: def_id, ns: namespace) -> option::t<def> {
949935
alt e.imports.get(defid.node) {
950-
todo(item, sc) {
951-
alt item.node {
952-
ast::view_item_import(name, ids, id) {
953-
resolve_import(e, local_def(id),
954-
name, ids, item.span, sc);
955-
}
956-
}
957-
ret lookup_import(e, defid, ns);
958-
}
959-
todo_from(item, ident, sc) {
960-
alt item.node {
961-
ast::view_item_import_from(mod_path, idents, _) {
962-
resolve_import(e, local_def(ident.node.id),
963-
ident.node.name,
964-
mod_path + ~[ident.node.name],
965-
ident.span, sc);
966-
}
967-
}
936+
todo(node_id, name, path, span, scopes) {
937+
resolve_import(e, local_def(node_id),
938+
name, path, span, scopes);
968939
ret lookup_import(e, defid, ns);
969940
}
970941
resolving(sp) { e.sess.span_err(sp, "cyclic import"); ret none; }
@@ -1051,7 +1022,7 @@ fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident,
10511022
info.glob_imported_names.insert(id, resolved(val, typ, md));
10521023
}
10531024
alt info.glob_imported_names.get(id) {
1054-
todo(_, _) { e.sess.bug("Shouldn't've put a todo in."); }
1025+
todo(_, _, _, _, _) { e.sess.bug("Shouldn't've put a todo in."); }
10551026
resolving(sp) {
10561027
ret none::<def>; //circularity is okay in import globs
10571028

0 commit comments

Comments
 (0)