Skip to content

Commit 6fcf553

Browse files
committed
Resolve the easy case of type paths.
1 parent fdac6ff commit 6fcf553

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/comp/middle/resolve.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import std.option;
1212
import std.option.some;
1313
import std.option.none;
1414
import std._str;
15+
import std._vec;
1516

1617
tag scope {
1718
scope_crate(@ast.crate);
@@ -105,6 +106,10 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
105106
fn fold_expr_name(&env e, &span sp, &ast.name n,
106107
&option.t[def] d, ann a) -> @ast.expr {
107108

109+
if (_vec.len[@ast.ty](n.node.types) > 0u) {
110+
e.sess.unimpl("resoling name expr with ty params");
111+
}
112+
108113
auto d_ = lookup_name(e, n.node.ident);
109114

110115
alt (d_) {
@@ -119,6 +124,35 @@ fn fold_expr_name(&env e, &span sp, &ast.name n,
119124
ret @fold.respan[ast.expr_](sp, ast.expr_name(n, d_, a));
120125
}
121126

127+
fn fold_ty_path(&env e, &span sp, ast.path p,
128+
&option.t[def] d) -> @ast.ty {
129+
130+
let uint len = _vec.len[ast.name](p);
131+
check (len != 0u);
132+
if (len > 1u) {
133+
e.sess.unimpl("resoling path ty with >1 component");
134+
}
135+
136+
let ast.name n = p.(0);
137+
138+
if (_vec.len[@ast.ty](n.node.types) > 0u) {
139+
e.sess.unimpl("resoling path ty with ty params");
140+
}
141+
142+
auto d_ = lookup_name(e, n.node.ident);
143+
144+
alt (d_) {
145+
case (some[def](_)) {
146+
// log "resolved name " + n.node.ident;
147+
}
148+
case (none[def]) {
149+
e.sess.err("unresolved name: " + n.node.ident);
150+
}
151+
}
152+
153+
ret @fold.respan[ast.ty_](sp, ast.ty_path(p, d_));
154+
}
155+
122156
fn update_env_for_crate(&env e, @ast.crate c) -> env {
123157
ret rec(scopes = cons[scope](scope_crate(c), @e.scopes) with e);
124158
}
@@ -136,6 +170,7 @@ fn resolve_crate(session.session sess, @ast.crate crate) -> @ast.crate {
136170
let fold.ast_fold[env] fld = fold.new_identity_fold[env]();
137171

138172
fld = @rec( fold_expr_name = bind fold_expr_name(_,_,_,_,_),
173+
fold_ty_path = bind fold_ty_path(_,_,_,_),
139174
update_env_for_crate = bind update_env_for_crate(_,_),
140175
update_env_for_item = bind update_env_for_item(_,_),
141176
update_env_for_block = bind update_env_for_block(_,_)

0 commit comments

Comments
 (0)