提交 1386420c 编写于 作者: B Brian Anderson

Move used_crate_files from session to cstore

上级 82983e50
......@@ -2,6 +2,7 @@
// -*- rust -*-
import metadata::creader;
import metadata::cstore;
import syntax::parse::parser;
import syntax::parse::token;
import syntax::ast;
......@@ -352,8 +353,8 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
fn build_session(@session::options sopts) -> session::session {
auto target_cfg = build_target_config();
auto cstore = metadata::cstore::mk_cstore();
ret session::session(target_cfg, sopts, cstore, [],
auto cstore = cstore::mk_cstore();
ret session::session(target_cfg, sopts, cstore,
[], [], codemap::new_codemap(), 0u);
}
......@@ -516,7 +517,7 @@ fn rmext(str filename) -> str {
};
}
for (str cratepath in sess.get_used_crate_files()) {
for (str cratepath in cstore::get_used_crate_files(sess.get_cstore())) {
auto dir = fs::dirname(cratepath);
if (dir != "") {
gcc_args += ["-L" + dir];
......
......@@ -46,7 +46,6 @@
obj session(@config targ_cfg,
@options opts,
metadata::cstore::cstore cstore,
mutable vec[str] used_crate_files,
mutable vec[str] used_libraries,
mutable vec[str] used_link_args,
codemap::codemap cm,
......@@ -123,19 +122,6 @@ fn add_used_library(&str lib) -> bool {
fn get_used_libraries() -> vec[str] {
ret used_libraries;
}
fn add_used_crate_file(&str lib) {
// A program has a small number of crates, so a vector is probably
// a good data structure in here.
for (str l in used_crate_files) {
if (l == lib) {
ret;
}
}
used_crate_files += [lib];
}
fn get_used_crate_files() -> vec[str] {
ret used_crate_files;
}
fn get_codemap() -> codemap::codemap { ret cm; }
fn lookup_pos(uint pos) -> codemap::loc {
ret codemap::lookup_pos(cm, pos);
......
......@@ -138,9 +138,10 @@ fn load_library_crate(&session::session sess, span span, int cnum,
&vec[str] library_search_paths) {
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
case (some(?t)) {
cstore::set_crate_data(sess.get_cstore(), cnum,
auto cstore = sess.get_cstore();
cstore::set_crate_data(cstore, cnum,
rec(name=ident, data=t._1));
sess.add_used_crate_file(t._0);
cstore::add_used_crate_file(cstore, t._0);
ret;
}
case (_) { }
......
import std::map;
import std::vec;
type crate_metadata = rec(str name, vec[u8] data);
type cstore = @rec(map::hashmap[int, crate_metadata] metas,
vec[str] used_crate_files,
vec[str] used_libraries,
vec[str] used_link_args);
mutable vec[str] used_crate_files,
mutable vec[str] used_libraries,
mutable vec[str] used_link_args);
fn mk_cstore() -> cstore {
auto meta_cache = map::new_int_hash[crate_metadata]();
ret @rec(metas = meta_cache,
used_crate_files = [],
used_libraries = [],
used_link_args = []);
mutable used_crate_files = [],
mutable used_libraries = [],
mutable used_link_args = []);
}
fn get_crate_data(&cstore cstore, int cnum) -> crate_metadata {
......@@ -27,6 +28,16 @@ fn have_crate_data(&cstore cstore, int cnum) -> bool {
ret cstore.metas.contains_key(cnum);
}
fn add_used_crate_file(&cstore cstore, &str lib) {
if (!vec::member(lib, cstore.used_crate_files)) {
cstore.used_crate_files += [lib];
}
}
fn get_used_crate_files(&cstore cstore) -> vec[str] {
ret cstore.used_crate_files;
}
// Local Variables:
// mode: rust
// fill-column: 78;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册