Skip to content

Commit 5883874

Browse files
committed
---
yaml --- r: 1663 b: refs/heads/master c: 7d32f3d h: refs/heads/master i: 1661: 798d09e 1659: 0596e40 1655: 2f84b08 1647: dea0bcd 1631: b4f155c 1599: 5ce6008 1535: aa3059a v: v3
1 parent eb45bd1 commit 5883874

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: bb081d661161f7b68a85a828a998b63bbf6cfd13
2+
refs/heads/master: 7d32f3d052b46f09bfd21effd801eebeab4204b3

trunk/src/comp/driver/rustc.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// -*- rust -*-
22

3+
import front.creader;
34
import front.parser;
45
import front.token;
56
import front.eval;
@@ -53,10 +54,12 @@ impure fn parse_input(session.session sess,
5354
impure fn compile_input(session.session sess,
5455
eval.env env,
5556
str input, str output,
56-
bool shared) {
57+
bool shared,
58+
vec[str] library_search_paths) {
5759
auto def = tup(0, 0);
5860
auto p = parser.new_parser(sess, env, def, input);
5961
auto crate = parse_input(sess, p, input);
62+
crate = creader.read_crates(sess, crate);
6063
crate = resolve.resolve_crate(sess, crate);
6164
crate = typeck.check_crate(sess, crate);
6265
trans.trans_crate(sess, crate, output, shared);
@@ -87,6 +90,7 @@ fn usage(session.session sess, str argv0) {
8790
log " -glue generate glue.bc file";
8891
log " -shared compile a shared-library crate";
8992
log " -pp pretty-print the input instead of compiling";
93+
log " -L <path> add a directory to the library search path";
9094
log " -h display this message";
9195
log "";
9296
log "";
@@ -111,6 +115,7 @@ impure fn main(vec[str] args) {
111115
auto sess = session.session(target_cfg);
112116
let option.t[str] input_file = none[str];
113117
let option.t[str] output_file = none[str];
118+
let vec[str] library_search_paths = vec();
114119
let bool do_warn = true;
115120
let bool shared = false;
116121
let bool pretty = false;
@@ -139,6 +144,14 @@ impure fn main(vec[str] args) {
139144
usage(sess, args.(0));
140145
sess.err("-o requires an argument");
141146
}
147+
} else if (_str.eq(arg, "-L")) {
148+
if (i+1u < len) {
149+
library_search_paths += vec(args.(i+1u));
150+
i += 1u;
151+
} else {
152+
usage(sess, args.(0));
153+
sess.err("-L requires an argument");
154+
}
142155
} else if (_str.eq(arg, "-h")) {
143156
usage(sess, args.(0));
144157
} else {
@@ -193,10 +206,12 @@ impure fn main(vec[str] args) {
193206
parts = _vec.pop[str](parts);
194207
parts += ".bc";
195208
auto ofile = _str.concat(parts);
196-
compile_input(sess, env, ifile, ofile, shared);
209+
compile_input(sess, env, ifile, ofile, shared,
210+
library_search_paths);
197211
}
198212
case (some[str](?ofile)) {
199-
compile_input(sess, env, ifile, ofile, shared);
213+
compile_input(sess, env, ifile, ofile, shared,
214+
library_search_paths);
200215
}
201216
}
202217
}

trunk/src/comp/front/ast.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ty_param = rec(ident ident, def_id id);
2121
// Annotations added during successive passes.
2222
tag ann {
2323
ann_none;
24+
ann_crate(@external_crate_info);
2425
ann_type(@middle.ty.t, option.t[vec[@middle.ty.t]] /* ty param substs */);
2526
}
2627

@@ -370,6 +371,9 @@ tag native_item_ {
370371
native_item_fn(ident, fn_decl, vec[ty_param], def_id, ann);
371372
}
372373

374+
// TODO: Actually store something here.
375+
type external_crate_info = ();
376+
373377
fn index_view_item(mod_index index, @view_item it) {
374378
alt (it.node) {
375379
case(ast.view_item_use(?id, _, _)) {

trunk/src/comp/front/creader.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// -*- rust -*-
2+
3+
import driver.session;
4+
import front.ast;
5+
import middle.fold;
6+
import util.common;
7+
import util.common.span;
8+
import std.map.hashmap;
9+
10+
// TODO: map to a real type here.
11+
type env = @hashmap[str, @ast.external_crate_info];
12+
13+
fn fold_view_item_use(&env e, &span sp, ast.ident ident,
14+
vec[@ast.meta_item] meta_items, ast.def_id id) -> @ast.view_item {
15+
// TODO: find the crate
16+
17+
auto viu = ast.view_item_use(ident, meta_items, id);
18+
ret @fold.respan[ast.view_item_](sp, viu);
19+
}
20+
21+
// Reads external crates referenced by "use" directives.
22+
fn read_crates(session.session sess, @ast.crate crate) -> @ast.crate {
23+
auto external_crates = @common.new_str_hash[@ast.external_crate_info]();
24+
auto f = fold_view_item_use;
25+
auto fld = @rec(fold_view_item_use=f with *fold.new_identity_fold[env]());
26+
ret fold.fold_crate[env](external_crates, fld, crate);
27+
}
28+

trunk/src/comp/rustc.rc

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std;
55

66
mod front {
77
mod ast;
8+
mod creader;
89
mod extfmt;
910
mod lexer;
1011
mod parser;

0 commit comments

Comments
 (0)