rustc: Add a stub crate reader module for "use" directives

This commit is contained in:
Patrick Walton 2011-03-15 16:30:43 -07:00
parent bb081d6611
commit 7d32f3d052
4 changed files with 51 additions and 3 deletions

View file

@ -21,6 +21,7 @@ type ty_param = rec(ident ident, def_id id);
// Annotations added during successive passes.
tag ann {
ann_none;
ann_crate(@external_crate_info);
ann_type(@middle.ty.t, option.t[vec[@middle.ty.t]] /* ty param substs */);
}
@ -370,6 +371,9 @@ tag native_item_ {
native_item_fn(ident, fn_decl, vec[ty_param], def_id, ann);
}
// TODO: Actually store something here.
type external_crate_info = ();
fn index_view_item(mod_index index, @view_item it) {
alt (it.node) {
case(ast.view_item_use(?id, _, _)) {

28
src/comp/front/creader.rs Normal file
View file

@ -0,0 +1,28 @@
// -*- rust -*-
import driver.session;
import front.ast;
import middle.fold;
import util.common;
import util.common.span;
import std.map.hashmap;
// TODO: map to a real type here.
type env = @hashmap[str, @ast.external_crate_info];
fn fold_view_item_use(&env e, &span sp, ast.ident ident,
vec[@ast.meta_item] meta_items, ast.def_id id) -> @ast.view_item {
// TODO: find the crate
auto viu = ast.view_item_use(ident, meta_items, id);
ret @fold.respan[ast.view_item_](sp, viu);
}
// Reads external crates referenced by "use" directives.
fn read_crates(session.session sess, @ast.crate crate) -> @ast.crate {
auto external_crates = @common.new_str_hash[@ast.external_crate_info]();
auto f = fold_view_item_use;
auto fld = @rec(fold_view_item_use=f with *fold.new_identity_fold[env]());
ret fold.fold_crate[env](external_crates, fld, crate);
}