Move the calculation of the crate name, vers and cmh to a single function

This commit is contained in:
Brian Anderson 2011-06-29 12:18:43 -07:00
parent 8c535d4aba
commit 325f46da06
2 changed files with 24 additions and 14 deletions

View file

@ -275,6 +275,22 @@ mod write {
* system linkers understand.
*
*/
type link_meta = rec(str name,
str vers,
str extras_hash);
fn build_link_meta(&session::session sess, &ast::crate c,
&str output, sha1 sha) -> link_meta {
auto meta_info = crate_link_metas(c);
auto name = crate_meta_name(sess, c, output);
auto vers = crate_meta_vers(sess, c);
auto extras_hash = crate_meta_extras_hash(sha, c);
ret rec(name = name, vers = vers, extras_hash = extras_hash);
}
type link_metas = rec(option::t[str] name,
option::t[str] vers,
vec[@ast::meta_item] cmh_items);
@ -385,8 +401,9 @@ fn get_symbol_hash(&@crate_ctxt ccx, &ty::t t) -> str {
case (some(?h)) { hash = h; }
case (none) {
hash =
symbol_hash(ccx.tcx, ccx.sha, t, ccx.crate_meta_name,
ccx.crate_meta_extras_hash);
symbol_hash(ccx.tcx, ccx.sha, t,
ccx.link_meta.name,
ccx.link_meta.extras_hash);
ccx.type_sha1s.insert(t, hash);
}
}
@ -413,7 +430,7 @@ fn exported_name(&vec[str] path, &str hash, &str vers) -> str {
fn mangle_exported_name(&@crate_ctxt ccx, &vec[str] path, &ty::t t) -> str {
auto hash = get_symbol_hash(ccx, t);
ret exported_name(path, hash, ccx.crate_meta_vers);
ret exported_name(path, hash, ccx.link_meta.vers);
}
fn mangle_internal_name_by_type_only(&@crate_ctxt ccx, &ty::t t, &str name) ->

View file

@ -62,9 +62,6 @@ import link::mangle_internal_name_by_seq;
import link::mangle_internal_name_by_path;
import link::mangle_internal_name_by_path_and_seq;
import link::mangle_exported_name;
import link::crate_meta_name;
import link::crate_meta_vers;
import link::crate_meta_extras_hash;
import metadata::tyencode;
import metadata::creader;
import metadata::decoder;
@ -132,9 +129,7 @@ type crate_ctxt =
ast_map::map ast_map,
hashmap[ast::node_id, str] item_symbols,
mutable option::t[ValueRef] main_fn,
str crate_meta_name,
str crate_meta_vers,
str crate_meta_extras_hash,
link::link_meta link_meta,
// TODO: hashmap[tup(tag_id,subtys), @tag_info]
hashmap[ty::t, uint] tag_sizes,
@ -7270,7 +7265,7 @@ fn new_local_ctxt(&@crate_ctxt ccx) -> @local_ctxt {
let vec[ast::ty_param] obj_typarams = [];
let vec[ast::obj_field] obj_fields = [];
ret @rec(path=pth,
module_path=[ccx.crate_meta_name],
module_path=[ccx.link_meta.name],
obj_typarams=obj_typarams,
obj_fields=obj_fields,
ccx=ccx);
@ -8522,7 +8517,7 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef {
vec::push[ValueRef](subcrates, C_int(0));
auto mapname;
if (ccx.sess.get_opts().shared) {
mapname = ccx.crate_meta_name;
mapname = ccx.link_meta.name;
} else { mapname = "toplevel"; }
auto sym_name = "_rust_crate_map_" + mapname;
auto arrtype = T_array(T_int(), vec::len[ValueRef](subcrates));
@ -8578,9 +8573,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
ast_map=amap,
item_symbols=new_int_hash[str](),
mutable main_fn=none[ValueRef],
crate_meta_name=crate_meta_name(sess, *crate, output),
crate_meta_vers=crate_meta_vers(sess, *crate),
crate_meta_extras_hash=crate_meta_extras_hash(sha, *crate),
link_meta=link::build_link_meta(sess, *crate, output, sha),
tag_sizes=tag_sizes,
discrims=new_int_hash[ValueRef](),
discrim_symbols=new_int_hash[str](),