2010-10-06 20:36:28 -05:00
|
|
|
import front.ast;
|
2010-10-18 18:15:25 -05:00
|
|
|
import front.ast.ident;
|
|
|
|
import front.ast.def;
|
2010-11-03 17:53:53 -05:00
|
|
|
import front.ast.ann;
|
2010-10-06 20:36:28 -05:00
|
|
|
import driver.session;
|
2011-01-11 13:19:53 -06:00
|
|
|
import util.common.new_def_hash;
|
2010-10-07 20:34:22 -05:00
|
|
|
import util.common.span;
|
2010-10-18 16:37:30 -05:00
|
|
|
import std.map.hashmap;
|
|
|
|
import std.list.list;
|
|
|
|
import std.list.nil;
|
|
|
|
import std.list.cons;
|
2010-11-03 19:10:37 -05:00
|
|
|
import std.option;
|
|
|
|
import std.option.some;
|
|
|
|
import std.option.none;
|
2010-10-18 16:37:30 -05:00
|
|
|
import std._str;
|
2010-11-22 15:22:23 -06:00
|
|
|
import std._vec;
|
2010-10-06 20:36:28 -05:00
|
|
|
|
2010-10-18 16:37:30 -05:00
|
|
|
tag scope {
|
|
|
|
scope_crate(@ast.crate);
|
|
|
|
scope_item(@ast.item);
|
|
|
|
scope_block(ast.block);
|
2010-12-10 20:08:32 -06:00
|
|
|
scope_arm(ast.arm);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
|
2010-10-19 16:54:10 -05:00
|
|
|
type env = rec(list[scope] scopes,
|
|
|
|
session.session sess);
|
2010-10-07 20:34:22 -05:00
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
type import_map = std.map.hashmap[ast.def_id,def];
|
2011-01-11 13:19:53 -06:00
|
|
|
|
2011-01-07 16:38:13 -06:00
|
|
|
// A simple wrapper over defs that stores a bit more information about modules
|
|
|
|
// and uses so that we can use the regular lookup_name when resolving imports.
|
|
|
|
tag def_wrap {
|
|
|
|
def_wrap_use(@ast.view_item);
|
2011-01-13 22:19:42 -06:00
|
|
|
def_wrap_import(@ast.view_item);
|
2011-01-07 16:38:13 -06:00
|
|
|
def_wrap_mod(@ast.item);
|
|
|
|
def_wrap_other(def);
|
|
|
|
}
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
fn lookup_name(&env e, import_map index,
|
|
|
|
ast.ident i) -> option.t[def] {
|
|
|
|
auto d_ = lookup_name_wrapped(e, i);
|
2011-01-07 16:38:13 -06:00
|
|
|
alt (d_) {
|
|
|
|
case (none[def_wrap]) {
|
|
|
|
ret none[def];
|
|
|
|
}
|
|
|
|
case (some[def_wrap](?d)) {
|
|
|
|
alt (d) {
|
|
|
|
case (def_wrap_use(?it)) {
|
|
|
|
alt (it.node) {
|
|
|
|
case (ast.view_item_use(_, _, ?id)) {
|
|
|
|
ret some[def](ast.def_use(id));
|
|
|
|
}
|
|
|
|
}
|
2011-01-13 22:19:42 -06:00
|
|
|
}
|
|
|
|
case (def_wrap_import(?it)) {
|
|
|
|
alt (it.node) {
|
|
|
|
case (ast.view_item_import(_, ?id)) {
|
|
|
|
ret index.find(id);
|
|
|
|
}
|
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
}
|
|
|
|
case (def_wrap_mod(?i)) {
|
|
|
|
alt (i.node) {
|
|
|
|
case (ast.item_mod(_, _, ?id)) {
|
|
|
|
ret some[def](ast.def_mod(id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (def_wrap_other(?d)) {
|
|
|
|
ret some[def](d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Follow the path of an import and return what it ultimately points to.
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
fn find_final_def(&env e, &span sp, vec[ident] idents) -> def_wrap {
|
|
|
|
fn found_something(&env e, std.map.hashmap[ast.def_id, bool] pending,
|
|
|
|
&span sp, vec[ident] idents, def_wrap d) -> def_wrap {
|
|
|
|
alt (d) {
|
|
|
|
case (def_wrap_import(?imp)) {
|
|
|
|
alt (imp.node) {
|
|
|
|
case (ast.view_item_import(?new_idents, ?d)) {
|
|
|
|
if (pending.contains_key(d)) {
|
|
|
|
e.sess.span_err(sp,
|
|
|
|
"recursive import");
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
pending.insert(d, true);
|
|
|
|
auto x = inner(e, pending, sp, new_idents);
|
|
|
|
ret found_something(e, pending, sp, idents, x);
|
|
|
|
}
|
2011-01-12 14:03:00 -06:00
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
}
|
2011-01-13 22:19:42 -06:00
|
|
|
case (_) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto len = _vec.len[ident](idents);
|
|
|
|
if (len == 1u) {
|
|
|
|
ret d;
|
|
|
|
}
|
|
|
|
alt (d) {
|
|
|
|
case (def_wrap_mod(?i)) {
|
|
|
|
auto new_idents = _vec.slice[ident](idents, 1u, len);
|
|
|
|
auto tmp_e = rec(scopes = nil[scope],
|
|
|
|
sess = e.sess);
|
|
|
|
auto new_e = update_env_for_item(tmp_e, i);
|
|
|
|
ret inner(new_e, pending, sp, new_idents);
|
|
|
|
}
|
|
|
|
case (def_wrap_use(?c)) {
|
|
|
|
e.sess.span_err(sp, "Crate access is not implemented");
|
|
|
|
}
|
|
|
|
case (_) {
|
|
|
|
auto first = idents.(0);
|
|
|
|
e.sess.span_err(sp, first + " is not a module or crate");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
fn inner(&env e, std.map.hashmap[ast.def_id, bool] pending,
|
|
|
|
&span sp, vec[ident] idents) -> def_wrap {
|
|
|
|
auto first = idents.(0);
|
|
|
|
auto d_ = lookup_name_wrapped(e, first);
|
|
|
|
alt (d_) {
|
|
|
|
case (none[def_wrap]) {
|
|
|
|
e.sess.span_err(sp, "unresolved name: " + first);
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
case (some[def_wrap](?d)) {
|
|
|
|
ret found_something(e, pending, sp, idents, d);
|
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
}
|
|
|
|
}
|
2011-01-13 22:19:42 -06:00
|
|
|
auto pending = new_def_hash[bool]();
|
|
|
|
ret inner(e, pending, sp, idents);
|
2011-01-07 16:38:13 -06:00
|
|
|
}
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[def_wrap] {
|
2010-10-18 16:37:30 -05:00
|
|
|
|
2010-10-22 17:37:42 -05:00
|
|
|
// log "resolving name " + i;
|
2010-10-18 16:37:30 -05:00
|
|
|
|
2011-01-07 16:38:13 -06:00
|
|
|
fn found_def_item(@ast.item i) -> option.t[def_wrap] {
|
2010-10-18 20:19:16 -05:00
|
|
|
alt (i.node) {
|
2010-12-09 16:37:50 -06:00
|
|
|
case (ast.item_const(_, _, _, ?id, _)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_other(ast.def_const(id)));
|
2010-12-09 16:37:50 -06:00
|
|
|
}
|
2010-11-24 18:52:49 -06:00
|
|
|
case (ast.item_fn(_, _, _, ?id, _)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_other(ast.def_fn(id)));
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
|
|
|
case (ast.item_mod(_, _, ?id)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_mod(i));
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
2010-11-24 19:36:22 -06:00
|
|
|
case (ast.item_ty(_, _, _, ?id, _)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_other(ast.def_ty(id)));
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
2010-12-01 12:19:20 -06:00
|
|
|
case (ast.item_tag(_, _, _, ?id)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_other(ast.def_ty(id)));
|
2010-12-01 12:19:20 -06:00
|
|
|
}
|
2010-12-14 19:09:37 -06:00
|
|
|
case (ast.item_obj(_, _, _, ?id, _)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_other(ast.def_obj(id)));
|
2010-12-14 19:09:37 -06:00
|
|
|
}
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-07 16:38:13 -06:00
|
|
|
fn found_decl_stmt(@ast.stmt s) -> option.t[def_wrap] {
|
2010-10-18 20:19:16 -05:00
|
|
|
alt (s.node) {
|
|
|
|
case (ast.stmt_decl(?d)) {
|
|
|
|
alt (d.node) {
|
|
|
|
case (ast.decl_local(?loc)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_local(loc.id);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-10-18 18:15:25 -05:00
|
|
|
}
|
2010-10-18 20:19:16 -05:00
|
|
|
case (ast.decl_item(?it)) {
|
|
|
|
ret found_def_item(it);
|
2010-10-18 18:15:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
ret none[def_wrap];
|
2010-10-18 18:15:25 -05:00
|
|
|
}
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
fn found_def_view(&env e, @ast.view_item i) -> option.t[def_wrap] {
|
2011-01-01 12:13:00 -06:00
|
|
|
alt (i.node) {
|
|
|
|
case (ast.view_item_use(_, _, ?id)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
ret some[def_wrap](def_wrap_use(i));
|
2011-01-01 12:13:00 -06:00
|
|
|
}
|
2011-01-11 13:19:53 -06:00
|
|
|
case (ast.view_item_import(?idents,?d)) {
|
2011-01-13 22:19:42 -06:00
|
|
|
ret some[def_wrap](def_wrap_import(i));
|
2011-01-01 12:13:00 -06:00
|
|
|
}
|
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
fail;
|
2011-01-01 12:13:00 -06:00
|
|
|
}
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
fn check_mod(&env e, ast.ident i, ast._mod m) -> option.t[def_wrap] {
|
2010-10-18 20:19:16 -05:00
|
|
|
alt (m.index.find(i)) {
|
2010-12-01 12:19:20 -06:00
|
|
|
case (some[ast.mod_index_entry](?ent)) {
|
|
|
|
alt (ent) {
|
2011-01-04 17:19:36 -06:00
|
|
|
case (ast.mie_view_item(?view_item)) {
|
2011-01-13 22:19:42 -06:00
|
|
|
ret found_def_view(e, view_item);
|
2011-01-01 12:13:00 -06:00
|
|
|
}
|
2011-01-04 17:19:36 -06:00
|
|
|
case (ast.mie_item(?item)) {
|
|
|
|
ret found_def_item(item);
|
2010-12-01 12:19:20 -06:00
|
|
|
}
|
2011-01-04 17:19:36 -06:00
|
|
|
case (ast.mie_tag_variant(?item, ?variant_idx)) {
|
|
|
|
alt (item.node) {
|
2010-12-01 12:19:20 -06:00
|
|
|
case (ast.item_tag(_, ?variants, _, ?tid)) {
|
|
|
|
auto vid = variants.(variant_idx).id;
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_variant(tid, vid);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-12-01 12:19:20 -06:00
|
|
|
}
|
|
|
|
case (_) {
|
|
|
|
log "tag item not actually a tag";
|
|
|
|
fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
2010-12-12 18:49:51 -06:00
|
|
|
case (none[ast.mod_index_entry]) { /* fall through */ }
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
ret none[def_wrap];
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
fn in_scope(ast.ident i, env e, &scope s) -> option.t[def_wrap] {
|
2010-10-18 16:37:30 -05:00
|
|
|
alt (s) {
|
2010-10-18 18:15:25 -05:00
|
|
|
|
2010-10-18 16:37:30 -05:00
|
|
|
case (scope_crate(?c)) {
|
2011-01-13 22:19:42 -06:00
|
|
|
ret check_mod(e, i, c.node.module);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
2010-10-18 18:15:25 -05:00
|
|
|
|
2010-10-18 16:37:30 -05:00
|
|
|
case (scope_item(?it)) {
|
|
|
|
alt (it.node) {
|
2010-12-15 15:12:39 -06:00
|
|
|
case (ast.item_fn(_, ?f, ?ty_params, _, _)) {
|
2010-10-18 18:15:25 -05:00
|
|
|
for (ast.arg a in f.inputs) {
|
|
|
|
if (_str.eq(a.ident, i)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_arg(a.id);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
}
|
2010-12-15 15:12:39 -06:00
|
|
|
for (ast.ty_param tp in ty_params) {
|
|
|
|
if (_str.eq(tp.ident, i)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_ty_arg(tp.id);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-12-15 15:12:39 -06:00
|
|
|
}
|
|
|
|
}
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
2010-12-30 17:27:52 -06:00
|
|
|
case (ast.item_obj(_, ?ob, ?ty_params, _, _)) {
|
|
|
|
for (ast.obj_field f in ob.fields) {
|
|
|
|
if (_str.eq(f.ident, i)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_obj_field(f.id);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-12-30 17:27:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (ast.ty_param tp in ty_params) {
|
|
|
|
if (_str.eq(tp.ident, i)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_ty_arg(tp.id);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-12-30 17:27:52 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 20:19:16 -05:00
|
|
|
case (ast.item_mod(_, ?m, _)) {
|
2011-01-13 22:19:42 -06:00
|
|
|
ret check_mod(e, i, m);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
2010-12-08 13:52:34 -06:00
|
|
|
case (_) { /* fall through */ }
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
}
|
2010-10-18 20:19:16 -05:00
|
|
|
|
|
|
|
case (scope_block(?b)) {
|
|
|
|
alt (b.node.index.find(i)) {
|
|
|
|
case (some[uint](?ix)) {
|
|
|
|
ret found_decl_stmt(b.node.stmts.(ix));
|
|
|
|
}
|
2010-12-01 19:08:46 -06:00
|
|
|
case (_) { /* fall through */ }
|
2010-10-18 20:19:16 -05:00
|
|
|
}
|
|
|
|
}
|
2010-12-10 20:08:32 -06:00
|
|
|
|
|
|
|
case (scope_arm(?a)) {
|
|
|
|
alt (a.index.find(i)) {
|
|
|
|
case (some[ast.def_id](?did)) {
|
2011-01-07 16:38:13 -06:00
|
|
|
auto t = ast.def_binding(did);
|
|
|
|
ret some[def_wrap](def_wrap_other(t));
|
2010-12-10 20:08:32 -06:00
|
|
|
}
|
|
|
|
case (_) { /* fall through */ }
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
2011-01-07 16:38:13 -06:00
|
|
|
ret none[def_wrap];
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
|
2011-01-11 13:19:53 -06:00
|
|
|
ret std.list.find[scope,def_wrap](e.scopes,
|
2011-01-13 22:19:42 -06:00
|
|
|
bind in_scope(i, e, _));
|
2010-10-18 18:15:25 -05:00
|
|
|
}
|
|
|
|
|
2011-01-11 13:19:53 -06:00
|
|
|
fn fold_pat_tag(&env e, &span sp, import_map index, ident i,
|
|
|
|
vec[@ast.pat] args, option.t[ast.variant_def] old_def,
|
|
|
|
ann a) -> @ast.pat {
|
2010-12-12 18:47:37 -06:00
|
|
|
auto new_def;
|
2011-01-13 22:19:42 -06:00
|
|
|
alt (lookup_name(e, index, i)) {
|
2010-12-12 18:47:37 -06:00
|
|
|
case (some[def](?d)) {
|
|
|
|
alt (d) {
|
|
|
|
case (ast.def_variant(?did, ?vid)) {
|
|
|
|
new_def = some[ast.variant_def](tup(did, vid));
|
|
|
|
}
|
|
|
|
case (_) {
|
2010-12-31 16:43:43 -06:00
|
|
|
e.sess.span_err(sp, "not a tag variant: " + i);
|
2010-12-12 18:47:37 -06:00
|
|
|
new_def = none[ast.variant_def];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case (none[def]) {
|
|
|
|
new_def = none[ast.variant_def];
|
2010-12-31 16:43:43 -06:00
|
|
|
e.sess.span_err(sp, "unresolved name: " + i);
|
2010-12-12 18:47:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret @fold.respan[ast.pat_](sp, ast.pat_tag(i, args, new_def, a));
|
|
|
|
}
|
|
|
|
|
2011-01-13 19:42:28 -06:00
|
|
|
// We received a path expression of the following form:
|
|
|
|
//
|
|
|
|
// a.b.c.d
|
|
|
|
//
|
|
|
|
// Somewhere along this path there might be a split from a path-expr
|
|
|
|
// to a runtime field-expr. For example:
|
|
|
|
//
|
|
|
|
// 'a' could be the name of a variable in the local scope
|
|
|
|
// and 'b.c.d' could be a field-sequence inside it.
|
|
|
|
//
|
|
|
|
// Or:
|
|
|
|
//
|
|
|
|
// 'a.b' could be a module path to a constant record, and 'c.d'
|
|
|
|
// could be a field within it.
|
|
|
|
//
|
|
|
|
// Our job here is to figure out what the prefix of 'a.b.c.d' is that
|
|
|
|
// corresponds to a static binding-name (a module or slot, with no type info)
|
|
|
|
// and split that off as the 'primary' expr_path, with secondary expr_field
|
|
|
|
// expressions tacked on the end.
|
|
|
|
|
|
|
|
fn fold_expr_path(&env e, &span sp, import_map index,
|
|
|
|
&ast.path p, &option.t[def] d, ann a) -> @ast.expr {
|
|
|
|
|
|
|
|
if (_vec.len[@ast.ty](p.node.types) > 0u) {
|
2010-12-12 18:37:31 -06:00
|
|
|
e.sess.unimpl("resolving name expr with ty params");
|
2010-11-22 15:22:23 -06:00
|
|
|
}
|
|
|
|
|
2011-01-13 19:42:28 -06:00
|
|
|
auto n_idents = _vec.len[ast.ident](p.node.idents);
|
|
|
|
|
|
|
|
check (n_idents != 0u);
|
|
|
|
auto id0 = p.node.idents.(0);
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
auto d_ = lookup_name(e, index, id0);
|
2010-10-18 18:15:25 -05:00
|
|
|
|
|
|
|
alt (d_) {
|
|
|
|
case (some[def](_)) {
|
2010-10-22 17:37:42 -05:00
|
|
|
// log "resolved name " + n.node.ident;
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
2010-10-18 18:15:25 -05:00
|
|
|
case (none[def]) {
|
2011-01-13 19:42:28 -06:00
|
|
|
e.sess.span_err(sp, "unresolved name: " + id0);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-13 19:42:28 -06:00
|
|
|
// FIXME: once espindola's modifications to lookup land, actually step
|
|
|
|
// through the path doing speculative lookup, and extend the maximal
|
|
|
|
// static prefix. For now we are always using the minimal prefix: first
|
|
|
|
// ident is static anchor, rest turn into fields.
|
|
|
|
|
|
|
|
auto p_ = rec(node=rec(idents = vec(id0) with p.node) with p);
|
|
|
|
auto ex = @fold.respan[ast.expr_](sp, ast.expr_path(p_, d_, a));
|
|
|
|
auto i = 1u;
|
|
|
|
while (i < n_idents) {
|
|
|
|
auto id = p.node.idents.(i);
|
|
|
|
ex = @fold.respan[ast.expr_](sp, ast.expr_field(ex, id, a));
|
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
ret ex;
|
2010-10-07 20:34:22 -05:00
|
|
|
}
|
|
|
|
|
2011-01-11 13:19:53 -06:00
|
|
|
fn fold_view_item_import(&env e, &span sp,
|
|
|
|
import_map index,
|
|
|
|
vec[ident] is, ast.def_id id) -> @ast.view_item {
|
2011-01-10 14:56:55 -06:00
|
|
|
// Produce errors for invalid imports
|
|
|
|
auto len = _vec.len[ast.ident](is);
|
|
|
|
auto last_id = is.(len - 1u);
|
2011-01-12 13:38:53 -06:00
|
|
|
auto d = find_final_def(e, sp, is);
|
2011-01-10 14:56:55 -06:00
|
|
|
alt (d) {
|
2011-01-13 22:19:42 -06:00
|
|
|
case (def_wrap_mod(?m)) {
|
|
|
|
alt (m.node) {
|
|
|
|
case (ast.item_mod(_, _, ?id)) {
|
|
|
|
index.insert(id, ast.def_mod(id));
|
|
|
|
}
|
|
|
|
}
|
2011-01-10 14:56:55 -06:00
|
|
|
}
|
2011-01-13 22:19:42 -06:00
|
|
|
case (def_wrap_other(?target_def)) {
|
|
|
|
index.insert(id, target_def);
|
2011-01-10 14:56:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret @fold.respan[ast.view_item_](sp, ast.view_item_import(is, id));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-11 13:19:53 -06:00
|
|
|
fn fold_ty_path(&env e, &span sp, import_map index, ast.path p,
|
2010-11-22 15:22:23 -06:00
|
|
|
&option.t[def] d) -> @ast.ty {
|
|
|
|
|
2011-01-13 19:42:28 -06:00
|
|
|
let uint len = _vec.len[ast.ident](p.node.idents);
|
2010-11-22 15:22:23 -06:00
|
|
|
check (len != 0u);
|
|
|
|
if (len > 1u) {
|
2010-12-12 18:37:31 -06:00
|
|
|
e.sess.unimpl("resolving path ty with >1 component");
|
2010-11-22 15:22:23 -06:00
|
|
|
}
|
|
|
|
|
2011-01-13 19:42:28 -06:00
|
|
|
if (_vec.len[@ast.ty](p.node.types) > 0u) {
|
2010-12-12 18:37:31 -06:00
|
|
|
e.sess.unimpl("resolving path ty with ty params");
|
2010-11-22 15:22:23 -06:00
|
|
|
}
|
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
auto d_ = lookup_name(e, index, p.node.idents.(0));
|
2010-11-22 15:22:23 -06:00
|
|
|
|
|
|
|
alt (d_) {
|
2011-01-13 19:42:28 -06:00
|
|
|
case (some[def](?d)) {
|
2010-11-22 15:22:23 -06:00
|
|
|
// log "resolved name " + n.node.ident;
|
|
|
|
}
|
|
|
|
case (none[def]) {
|
2011-01-13 19:42:28 -06:00
|
|
|
e.sess.span_err(sp, "unresolved name: " + p.node.idents.(0));
|
2010-11-22 15:22:23 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret @fold.respan[ast.ty_](sp, ast.ty_path(p, d_));
|
|
|
|
}
|
|
|
|
|
2010-10-18 16:37:30 -05:00
|
|
|
fn update_env_for_crate(&env e, @ast.crate c) -> env {
|
2010-10-19 16:54:10 -05:00
|
|
|
ret rec(scopes = cons[scope](scope_crate(c), @e.scopes) with e);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update_env_for_item(&env e, @ast.item i) -> env {
|
2010-10-19 16:54:10 -05:00
|
|
|
ret rec(scopes = cons[scope](scope_item(i), @e.scopes) with e);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
|
2010-10-18 20:19:16 -05:00
|
|
|
fn update_env_for_block(&env e, &ast.block b) -> env {
|
2010-10-19 16:54:10 -05:00
|
|
|
ret rec(scopes = cons[scope](scope_block(b), @e.scopes) with e);
|
2010-10-18 16:37:30 -05:00
|
|
|
}
|
|
|
|
|
2010-12-10 20:08:32 -06:00
|
|
|
fn update_env_for_arm(&env e, &ast.arm p) -> env {
|
|
|
|
ret rec(scopes = cons[scope](scope_arm(p), @e.scopes) with e);
|
|
|
|
}
|
|
|
|
|
2010-10-07 20:34:22 -05:00
|
|
|
fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate {
|
2010-10-19 16:54:10 -05:00
|
|
|
|
2010-10-07 20:34:22 -05:00
|
|
|
let fold.ast_fold[env] fld = fold.new_identity_fold[env]();
|
2010-10-19 16:54:10 -05:00
|
|
|
|
2011-01-13 22:19:42 -06:00
|
|
|
auto import_index = new_def_hash[def]();
|
2011-01-11 13:19:53 -06:00
|
|
|
fld = @rec( fold_pat_tag = bind fold_pat_tag(_,_,import_index,_,_,_,_),
|
2011-01-13 19:42:28 -06:00
|
|
|
fold_expr_path = bind fold_expr_path(_,_,import_index,_,_,_),
|
2011-01-11 13:19:53 -06:00
|
|
|
fold_view_item_import
|
|
|
|
= bind fold_view_item_import(_,_,import_index,_,_),
|
|
|
|
fold_ty_path = bind fold_ty_path(_,_,import_index,_,_),
|
2010-10-18 16:37:30 -05:00
|
|
|
update_env_for_crate = bind update_env_for_crate(_,_),
|
|
|
|
update_env_for_item = bind update_env_for_item(_,_),
|
2010-12-10 20:08:32 -06:00
|
|
|
update_env_for_block = bind update_env_for_block(_,_),
|
|
|
|
update_env_for_arm = bind update_env_for_arm(_,_)
|
2010-10-07 20:34:22 -05:00
|
|
|
with *fld );
|
2010-10-19 16:54:10 -05:00
|
|
|
|
|
|
|
auto e = rec(scopes = nil[scope],
|
|
|
|
sess = sess);
|
|
|
|
|
|
|
|
ret fold.fold_crate[env](e, fld, crate);
|
2010-10-07 20:34:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|