aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-15 17:33:05 -0700
committerPatrick Walton <[email protected]>2011-03-15 17:33:05 -0700
commit71b6e602c54f78dc2f8f33de2d74b40879316165 (patch)
tree87d92ce397c471e3046868b38a40ed67a69ca9f3 /src/comp/front
parentRevert "Change the numbering of upcall functions. upcall_0 now calls a functi... (diff)
downloadrust-71b6e602c54f78dc2f8f33de2d74b40879316165.tar.xz
rust-71b6e602c54f78dc2f8f33de2d74b40879316165.zip
rustc: Add an annotation for the crate definition to view_item_use
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs4
-rw-r--r--src/comp/front/creader.rs43
-rw-r--r--src/comp/front/parser.rs3
3 files changed, 40 insertions, 10 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 3de72406..1970f788 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -349,7 +349,7 @@ type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann);
type view_item = spanned[view_item_];
tag view_item_ {
- view_item_use(ident, vec[@meta_item], def_id);
+ view_item_use(ident, vec[@meta_item], def_id, ann);
view_item_import(ident, vec[ident], def_id, option.t[def]);
view_item_export(ident);
}
@@ -376,7 +376,7 @@ type external_crate_info = ();
fn index_view_item(mod_index index, @view_item it) {
alt (it.node) {
- case(ast.view_item_use(?id, _, _)) {
+ case(ast.view_item_use(?id, _, _, _)) {
index.insert(id, ast.mie_view_item(it));
}
case(ast.view_item_import(?def_ident,_,_,_)) {
diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs
index 4564ae2b..d1eaba85 100644
--- a/src/comp/front/creader.rs
+++ b/src/comp/front/creader.rs
@@ -5,24 +5,53 @@ import front.ast;
import middle.fold;
import util.common;
import util.common.span;
+
+import std.fs;
import std.map.hashmap;
// TODO: map to a real type here.
-type env = @hashmap[str, @ast.external_crate_info];
+type env = @rec(
+ @hashmap[str, @ast.external_crate_info] crate_cache,
+ vec[str] library_search_paths
+);
+
+// TODO: return something
+fn load_crate(ast.ident ident, vec[str] library_search_paths) -> @() {
+ for (str library_search_path in library_search_paths) {
+ auto path = fs.connect(library_search_path, ident);
+ // TODO
+ }
+
+ ret @();
+}
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
+ vec[@ast.meta_item] meta_items, ast.def_id id, ast.ann orig_ann)
+ -> @ast.view_item {
+ auto external_crate;
+ if (!e.crate_cache.contains_key(ident)) {
+ external_crate = load_crate(ident, e.library_search_paths);
+ e.crate_cache.insert(ident, external_crate);
+ } else {
+ external_crate = e.crate_cache.get(ident);
+ }
- auto viu = ast.view_item_use(ident, meta_items, id);
+ auto ann = ast.ann_crate(external_crate);
+ auto viu = ast.view_item_use(ident, meta_items, id, ann);
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]();
+fn read_crates(session.session sess,
+ @ast.crate crate,
+ vec[str] library_search_paths) -> @ast.crate {
+ auto e = @rec(
+ [email protected]_str_hash[@ast.external_crate_info](),
+ library_search_paths=library_search_paths
+ );
+
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);
+ ret fold.fold_crate[env](e, fld, crate);
}
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index df57bc19..a5c79926 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -2151,7 +2151,8 @@ impure fn parse_use(parser p) -> @ast.view_item {
auto ident = parse_ident(p);
auto metadata = parse_optional_meta(p);
expect(p, token.SEMI);
- auto use_decl = ast.view_item_use(ident, metadata, p.next_def_id());
+ auto use_decl = ast.view_item_use(ident, metadata, p.next_def_id(),
+ ast.ann_none);
ret @spanned(lo, hi, use_decl);
}