about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-03-15 16:30:43 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-03-15 16:30:43 -0700
commit7d32f3d052b46f09bfd21effd801eebeab4204b3 (patch)
treed6c7cf9282192058382f8c09b3595fd07f9f5dd5
parentbb081d661161f7b68a85a828a998b63bbf6cfd13 (diff)
downloadrust-7d32f3d052b46f09bfd21effd801eebeab4204b3.tar.gz
rust-7d32f3d052b46f09bfd21effd801eebeab4204b3.zip
rustc: Add a stub crate reader module for "use" directives
-rw-r--r--src/comp/driver/rustc.rs21
-rw-r--r--src/comp/front/ast.rs4
-rw-r--r--src/comp/front/creader.rs28
-rw-r--r--src/comp/rustc.rc1
4 files changed, 51 insertions, 3 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 51151742ea6..ed03f1d2e48 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -1,5 +1,6 @@
 // -*- rust -*-
 
+import front.creader;
 import front.parser;
 import front.token;
 import front.eval;
@@ -53,10 +54,12 @@ impure fn parse_input(session.session sess,
 impure fn compile_input(session.session sess,
                         eval.env env,
                         str input, str output,
-                        bool shared) {
+                        bool shared,
+                        vec[str] library_search_paths) {
     auto def = tup(0, 0);
     auto p = parser.new_parser(sess, env, def, input);
     auto crate = parse_input(sess, p, input);
+    crate = creader.read_crates(sess, crate);
     crate = resolve.resolve_crate(sess, crate);
     crate = typeck.check_crate(sess, crate);
     trans.trans_crate(sess, crate, output, shared);
@@ -87,6 +90,7 @@ fn usage(session.session sess, str argv0) {
     log "    -glue              generate glue.bc file";
     log "    -shared            compile a shared-library crate";
     log "    -pp                pretty-print the input instead of compiling";
+    log "    -L <path>          add a directory to the library search path";
     log "    -h                 display this message";
     log "";
     log "";
@@ -111,6 +115,7 @@ impure fn main(vec[str] args) {
     auto sess = session.session(target_cfg);
     let option.t[str] input_file = none[str];
     let option.t[str] output_file = none[str];
+    let vec[str] library_search_paths = vec();
     let bool do_warn = true;
     let bool shared = false;
     let bool pretty = false;
@@ -139,6 +144,14 @@ impure fn main(vec[str] args) {
                     usage(sess, args.(0));
                     sess.err("-o requires an argument");
                 }
+            } else if (_str.eq(arg, "-L")) {
+                if (i+1u < len) {
+                    library_search_paths += vec(args.(i+1u));
+                    i += 1u;
+                } else {
+                    usage(sess, args.(0));
+                    sess.err("-L requires an argument");
+                }
             } else if (_str.eq(arg, "-h")) {
                 usage(sess, args.(0));
             } else {
@@ -193,10 +206,12 @@ impure fn main(vec[str] args) {
                         parts = _vec.pop[str](parts);
                         parts += ".bc";
                         auto ofile = _str.concat(parts);
-                        compile_input(sess, env, ifile, ofile, shared);
+                        compile_input(sess, env, ifile, ofile, shared,
+                                      library_search_paths);
                     }
                     case (some[str](?ofile)) {
-                        compile_input(sess, env, ifile, ofile, shared);
+                        compile_input(sess, env, ifile, ofile, shared,
+                                      library_search_paths);
                     }
                 }
             }
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index a7ff64fa9a7..3de72406448 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -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, _, _)) {
diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs
new file mode 100644
index 00000000000..4564ae2b422
--- /dev/null
+++ b/src/comp/front/creader.rs
@@ -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);
+}
+
diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc
index 3584289f887..7f1a7a03ebc 100644
--- a/src/comp/rustc.rc
+++ b/src/comp/rustc.rc
@@ -5,6 +5,7 @@ use std;
 
 mod front {
     mod ast;
+    mod creader;
     mod extfmt;
     mod lexer;
     mod parser;