mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-12 00:24:03 +00:00
Rename middle::metadata to metadata::cwriter. Move creader to metadata
Preparation for a lot more metadata refactoring
This commit is contained in:
parent
d4a5487e1c
commit
ba5c7a570d
@ -2,8 +2,8 @@
|
||||
import driver::session;
|
||||
import lib::llvm::llvm;
|
||||
import middle::trans;
|
||||
import middle::metadata;
|
||||
import middle::ty;
|
||||
import metadata::cwriter;
|
||||
import std::str;
|
||||
import std::fs;
|
||||
import std::vec;
|
||||
@ -398,15 +398,15 @@ fn symbol_hash(ty::ctxt tcx, sha1 sha, &ty::t t, str crate_meta_name,
|
||||
// to be independent of one another in the crate.
|
||||
|
||||
auto cx =
|
||||
@rec(ds=metadata::def_to_str,
|
||||
@rec(ds=metadata::cwriter::def_to_str,
|
||||
tcx=tcx,
|
||||
abbrevs=metadata::ac_no_abbrevs);
|
||||
abbrevs=metadata::cwriter::ac_no_abbrevs);
|
||||
sha.reset();
|
||||
sha.input_str(crate_meta_name);
|
||||
sha.input_str("-");
|
||||
sha.input_str(crate_meta_name);
|
||||
sha.input_str("-");
|
||||
sha.input_str(metadata::encode::ty_str(cx, t));
|
||||
sha.input_str(metadata::cwriter::encode::ty_str(cx, t));
|
||||
auto hash = truncated_sha1_result(sha);
|
||||
// Prefix with _ so that it never blends into adjacent digits
|
||||
|
||||
@ -452,8 +452,8 @@ fn mangle_exported_name(&@crate_ctxt ccx, &vec[str] path, &ty::t t) -> str {
|
||||
|
||||
fn mangle_internal_name_by_type_only(&@crate_ctxt ccx, &ty::t t, &str name) ->
|
||||
str {
|
||||
auto f = metadata::def_to_str;
|
||||
auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata::ac_no_abbrevs);
|
||||
auto f = metadata::cwriter::def_to_str;
|
||||
auto cx = @rec(ds=f, tcx=ccx.tcx, abbrevs=metadata::cwriter::ac_no_abbrevs);
|
||||
auto s = pretty::ppaux::ty_to_short_str(ccx.tcx, t);
|
||||
auto hash = get_symbol_hash(ccx, t);
|
||||
ret mangle([name, s, hash]);
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
|
||||
// -*- rust -*-
|
||||
import front::creader;
|
||||
import metadata::creader;
|
||||
import front::parser;
|
||||
import front::token;
|
||||
import front::eval;
|
||||
@ -349,7 +349,7 @@ fn main(vec[str] args) {
|
||||
case (none[pp_mode]) {/* continue */ }
|
||||
}
|
||||
if (ls) {
|
||||
front::creader::list_file_metadata(ifile, std::io::stdout());
|
||||
metadata::creader::list_file_metadata(ifile, std::io::stdout());
|
||||
ret;
|
||||
}
|
||||
alt (output_file) {
|
||||
|
@ -9,7 +9,7 @@ import lib::llvm::mk_object_file;
|
||||
import lib::llvm::mk_section_iter;
|
||||
import middle::resolve;
|
||||
import middle::walk;
|
||||
import middle::metadata;
|
||||
import cwriter;
|
||||
import middle::trans;
|
||||
import middle::ty;
|
||||
import back::x86;
|
||||
@ -404,15 +404,15 @@ fn parse_def_id(vec[u8] buf) -> ast::def_id {
|
||||
|
||||
fn lookup_hash(&ebml::doc d, fn(vec[u8]) -> bool eq_fn, uint hash) ->
|
||||
vec[ebml::doc] {
|
||||
auto index = ebml::get_doc(d, metadata::tag_index);
|
||||
auto table = ebml::get_doc(index, metadata::tag_index_table);
|
||||
auto index = ebml::get_doc(d, cwriter::tag_index);
|
||||
auto table = ebml::get_doc(index, cwriter::tag_index_table);
|
||||
auto hash_pos = table.start + hash % 256u * 4u;
|
||||
auto pos = ebml::be_uint_from_bytes(d.data, hash_pos, 4u);
|
||||
auto bucket = ebml::doc_at(d.data, pos);
|
||||
// Awkward logic because we can't ret from foreach yet
|
||||
|
||||
let vec[ebml::doc] result = [];
|
||||
auto belt = metadata::tag_index_buckets_bucket_elt;
|
||||
auto belt = cwriter::tag_index_buckets_bucket_elt;
|
||||
for each (ebml::doc elt in ebml::tagged_docs(bucket, belt)) {
|
||||
auto pos = ebml::be_uint_from_bytes(elt.data, elt.start, 4u);
|
||||
if (eq_fn(vec::slice[u8](elt.data, elt.start + 4u, elt.end))) {
|
||||
@ -431,11 +431,11 @@ fn resolve_path(vec[ast::ident] path, vec[u8] data) -> vec[ast::def_id] {
|
||||
}
|
||||
auto s = str::connect(path, "::");
|
||||
auto md = ebml::new_doc(data);
|
||||
auto paths = ebml::get_doc(md, metadata::tag_paths);
|
||||
auto paths = ebml::get_doc(md, cwriter::tag_paths);
|
||||
auto eqer = bind eq_item(_, s);
|
||||
let vec[ast::def_id] result = [];
|
||||
for (ebml::doc doc in lookup_hash(paths, eqer, metadata::hash_path(s))) {
|
||||
auto did_doc = ebml::get_doc(doc, metadata::tag_def_id);
|
||||
for (ebml::doc doc in lookup_hash(paths, eqer, cwriter::hash_path(s))) {
|
||||
auto did_doc = ebml::get_doc(doc, cwriter::tag_def_id);
|
||||
vec::push(result, parse_def_id(ebml::doc_data(did_doc)));
|
||||
}
|
||||
ret result;
|
||||
@ -446,7 +446,7 @@ fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] {
|
||||
ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id;
|
||||
}
|
||||
auto eqer = bind eq_item(_, item_id);
|
||||
auto found = lookup_hash(items, eqer, metadata::hash_def_id(item_id));
|
||||
auto found = lookup_hash(items, eqer, cwriter::hash_def_id(item_id));
|
||||
if (vec::len(found) == 0u) {
|
||||
ret option::none[ebml::doc];
|
||||
} else { ret option::some[ebml::doc](found.(0)); }
|
||||
@ -460,22 +460,22 @@ fn find_item(int item_id, &ebml::doc items) -> ebml::doc {
|
||||
// Looks up an item in the given metadata and returns an ebml doc pointing
|
||||
// to the item data.
|
||||
fn lookup_item(int item_id, vec[u8] data) -> ebml::doc {
|
||||
auto items = ebml::get_doc(ebml::new_doc(data), metadata::tag_items);
|
||||
auto items = ebml::get_doc(ebml::new_doc(data), cwriter::tag_items);
|
||||
ret find_item(item_id, items);
|
||||
}
|
||||
|
||||
fn item_kind(&ebml::doc item) -> u8 {
|
||||
auto kind = ebml::get_doc(item, metadata::tag_items_data_item_kind);
|
||||
auto kind = ebml::get_doc(item, cwriter::tag_items_data_item_kind);
|
||||
ret ebml::doc_as_uint(kind) as u8;
|
||||
}
|
||||
|
||||
fn item_symbol(&ebml::doc item) -> str {
|
||||
auto sym = ebml::get_doc(item, metadata::tag_items_data_item_symbol);
|
||||
auto sym = ebml::get_doc(item, cwriter::tag_items_data_item_symbol);
|
||||
ret str::unsafe_from_bytes(ebml::doc_data(sym));
|
||||
}
|
||||
|
||||
fn variant_tag_id(&ebml::doc d) -> ast::def_id {
|
||||
auto tagdoc = ebml::get_doc(d, metadata::tag_items_data_item_tag_id);
|
||||
auto tagdoc = ebml::get_doc(d, cwriter::tag_items_data_item_tag_id);
|
||||
ret parse_def_id(ebml::doc_data(tagdoc));
|
||||
}
|
||||
|
||||
@ -490,7 +490,7 @@ fn item_type(&ebml::doc item, int this_cnum, ty::ctxt tcx) -> ty::t {
|
||||
auto external_def_id = parse_def_id(buf);
|
||||
ret tup(this_cnum, external_def_id._1);
|
||||
}
|
||||
auto tp = ebml::get_doc(item, metadata::tag_items_data_item_type);
|
||||
auto tp = ebml::get_doc(item, cwriter::tag_items_data_item_type);
|
||||
auto s = str::unsafe_from_bytes(ebml::doc_data(tp));
|
||||
ret parse_ty_data(item.data, this_cnum, tp.start, tp.end - tp.start,
|
||||
bind parse_external_def_id(this_cnum, _), tcx);
|
||||
@ -498,7 +498,7 @@ fn item_type(&ebml::doc item, int this_cnum, ty::ctxt tcx) -> ty::t {
|
||||
|
||||
fn item_ty_param_count(&ebml::doc item, int this_cnum) -> uint {
|
||||
let uint ty_param_count = 0u;
|
||||
auto tp = metadata::tag_items_data_item_ty_param_count;
|
||||
auto tp = cwriter::tag_items_data_item_ty_param_count;
|
||||
for each (ebml::doc p in ebml::tagged_docs(item, tp)) {
|
||||
ty_param_count = ebml::vint_at(ebml::doc_data(p), 0u)._0;
|
||||
}
|
||||
@ -507,7 +507,7 @@ fn item_ty_param_count(&ebml::doc item, int this_cnum) -> uint {
|
||||
|
||||
fn tag_variant_ids(&ebml::doc item, int this_cnum) -> vec[ast::def_id] {
|
||||
let vec[ast::def_id] ids = [];
|
||||
auto v = metadata::tag_items_data_item_variant;
|
||||
auto v = cwriter::tag_items_data_item_variant;
|
||||
for each (ebml::doc p in ebml::tagged_docs(item, v)) {
|
||||
auto ext = parse_def_id(ebml::doc_data(p));
|
||||
vec::push[ast::def_id](ids, tup(this_cnum, ext._1));
|
||||
@ -538,12 +538,12 @@ fn get_metadata_section(str filename) -> option::t[vec[u8]] {
|
||||
fn get_exported_metadata(&session::session sess, &str path, &vec[u8] data) ->
|
||||
hashmap[str, str] {
|
||||
auto meta_items =
|
||||
ebml::get_doc(ebml::new_doc(data), metadata::tag_meta_export);
|
||||
ebml::get_doc(ebml::new_doc(data), cwriter::tag_meta_export);
|
||||
auto mm = common::new_str_hash[str]();
|
||||
for each (ebml::doc m in
|
||||
ebml::tagged_docs(meta_items, metadata::tag_meta_item)) {
|
||||
auto kd = ebml::get_doc(m, metadata::tag_meta_item_key);
|
||||
auto vd = ebml::get_doc(m, metadata::tag_meta_item_value);
|
||||
ebml::tagged_docs(meta_items, cwriter::tag_meta_item)) {
|
||||
auto kd = ebml::get_doc(m, cwriter::tag_meta_item_key);
|
||||
auto vd = ebml::get_doc(m, cwriter::tag_meta_item_value);
|
||||
auto k = str::unsafe_from_bytes(ebml::doc_data(kd));
|
||||
auto v = str::unsafe_from_bytes(ebml::doc_data(vd));
|
||||
log #fmt("metadata in %s: %s = %s", path, k, v);
|
||||
@ -807,7 +807,7 @@ fn get_symbol(session::session sess, ast::def_id def) -> str {
|
||||
fn get_tag_variants(ty::ctxt tcx, ast::def_id def) -> vec[ty::variant_info] {
|
||||
auto external_crate_id = def._0;
|
||||
auto data = tcx.sess.get_external_crate(external_crate_id).data;
|
||||
auto items = ebml::get_doc(ebml::new_doc(data), metadata::tag_items);
|
||||
auto items = ebml::get_doc(ebml::new_doc(data), cwriter::tag_items);
|
||||
auto item = find_item(def._1, items);
|
||||
let vec[ty::variant_info] infos = [];
|
||||
auto variant_ids = tag_variant_ids(item, external_crate_id);
|
||||
@ -848,17 +848,17 @@ fn read_path(&ebml::doc d) -> tup(str, uint) {
|
||||
|
||||
fn list_crate_metadata(vec[u8] bytes, io::writer out) {
|
||||
auto md = ebml::new_doc(bytes);
|
||||
auto paths = ebml::get_doc(md, metadata::tag_paths);
|
||||
auto items = ebml::get_doc(md, metadata::tag_items);
|
||||
auto index = ebml::get_doc(paths, metadata::tag_index);
|
||||
auto bs = ebml::get_doc(index, metadata::tag_index_buckets);
|
||||
auto paths = ebml::get_doc(md, cwriter::tag_paths);
|
||||
auto items = ebml::get_doc(md, cwriter::tag_items);
|
||||
auto index = ebml::get_doc(paths, cwriter::tag_index);
|
||||
auto bs = ebml::get_doc(index, cwriter::tag_index_buckets);
|
||||
for each (ebml::doc bucket in
|
||||
ebml::tagged_docs(bs, metadata::tag_index_buckets_bucket)) {
|
||||
auto et = metadata::tag_index_buckets_bucket_elt;
|
||||
ebml::tagged_docs(bs, cwriter::tag_index_buckets_bucket)) {
|
||||
auto et = cwriter::tag_index_buckets_bucket_elt;
|
||||
for each (ebml::doc elt in ebml::tagged_docs(bucket, et)) {
|
||||
auto data = read_path(elt);
|
||||
auto def = ebml::doc_at(bytes, data._1);
|
||||
auto did_doc = ebml::get_doc(def, metadata::tag_def_id);
|
||||
auto did_doc = ebml::get_doc(def, cwriter::tag_def_id);
|
||||
auto did = parse_def_id(ebml::doc_data(did_doc));
|
||||
out.write_str(#fmt("%s (%s)\n", data._0,
|
||||
describe_def(items, did)));
|
@ -662,13 +662,13 @@ fn encode_info_for_items(&@trans::crate_ctxt cx, &ebml::writer ebml_w) ->
|
||||
vec[tup(int, uint)] {
|
||||
let vec[tup(int, uint)] index = [];
|
||||
ebml::start_tag(ebml_w, tag_items_data);
|
||||
for each (@tup(node_id, ast_map::ast_node) kvp in cx.ast_map.items()) {
|
||||
for each (@tup(node_id, middle::ast_map::ast_node) kvp in cx.ast_map.items()) {
|
||||
alt (kvp._1) {
|
||||
case (ast_map::node_item(?i)) {
|
||||
case (middle::ast_map::node_item(?i)) {
|
||||
index += [tup(kvp._0, ebml_w.writer.tell())];
|
||||
encode_info_for_item(cx, ebml_w, i, index);
|
||||
}
|
||||
case (ast_map::node_native_item(?i)) {
|
||||
case (middle::ast_map::node_native_item(?i)) {
|
||||
index += [tup(kvp._0, ebml_w.writer.tell())];
|
||||
encode_info_for_native_item(cx, ebml_w, i);
|
||||
}
|
@ -6,7 +6,7 @@ import front::ast::def_id;
|
||||
import front::ast::node_id;
|
||||
import front::ast::local_def;
|
||||
|
||||
import front::creader;
|
||||
import metadata::creader;
|
||||
import driver::session::session;
|
||||
import util::common::new_def_hash;
|
||||
import util::common::new_int_hash;
|
||||
|
@ -25,7 +25,8 @@ import std::option::some;
|
||||
import std::option::none;
|
||||
import std::fs;
|
||||
import front::ast;
|
||||
import front::creader;
|
||||
import metadata::creader;
|
||||
import metadata::cwriter;
|
||||
import driver::session;
|
||||
import middle::ty;
|
||||
import back::link;
|
||||
@ -148,7 +149,7 @@ type crate_ctxt =
|
||||
namegen names,
|
||||
std::sha1::sha1 sha,
|
||||
hashmap[ty::t, str] type_sha1s,
|
||||
hashmap[ty::t, metadata::ty_abbrev] type_abbrevs,
|
||||
hashmap[ty::t, cwriter::ty_abbrev] type_abbrevs,
|
||||
hashmap[ty::t, str] type_short_names,
|
||||
ty::ctxt tcx,
|
||||
stats stats,
|
||||
@ -8400,7 +8401,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
|
||||
auto tydescs = map::mk_hashmap[ty::t, @tydesc_info](hasher, eqer);
|
||||
auto lltypes = map::mk_hashmap[ty::t, TypeRef](hasher, eqer);
|
||||
auto sha1s = map::mk_hashmap[ty::t, str](hasher, eqer);
|
||||
auto abbrevs = map::mk_hashmap[ty::t, metadata::ty_abbrev](hasher, eqer);
|
||||
auto abbrevs = map::mk_hashmap[ty::t, cwriter::ty_abbrev](hasher, eqer);
|
||||
auto short_names = map::mk_hashmap[ty::t, str](hasher, eqer);
|
||||
auto sha = std::sha1::mk_sha1();
|
||||
auto ccx =
|
||||
@ -8449,7 +8450,7 @@ fn trans_crate(&session::session sess, &@ast::crate crate, &ty::ctxt tcx,
|
||||
emit_tydescs(ccx);
|
||||
// Translate the metadata:
|
||||
|
||||
middle::metadata::write_metadata(cx.ccx, crate);
|
||||
cwriter::write_metadata(cx.ccx, crate);
|
||||
if (ccx.sess.get_opts().stats) {
|
||||
log_err "--- trans stats ---";
|
||||
log_err #fmt("n_static_tydescs: %u", ccx.stats.n_static_tydescs);
|
||||
|
@ -17,8 +17,8 @@ import front::ast::def_id;
|
||||
import front::ast::constr_arg_general;
|
||||
import front::ast::mutability;
|
||||
import front::ast::controlflow;
|
||||
import front::creader;
|
||||
import middle::metadata;
|
||||
import metadata::creader;
|
||||
import metadata::cwriter;
|
||||
import util::common::*;
|
||||
import util::data::interner;
|
||||
import pretty::ppaux::ty_to_str;
|
||||
|
@ -2,7 +2,7 @@
|
||||
import front::ast;
|
||||
import front::ast::mutability;
|
||||
import front::ast::local_def;
|
||||
import front::creader;
|
||||
import metadata::creader;
|
||||
import driver::session;
|
||||
import util::common;
|
||||
import util::common::span;
|
||||
|
@ -150,8 +150,8 @@ fn ty_to_str(&ctxt cx, &t typ) -> str {
|
||||
|
||||
fn ty_to_short_str(&ctxt cx, t typ) -> str {
|
||||
auto f = def_to_str;
|
||||
auto ecx = @rec(ds=f, tcx=cx, abbrevs=middle::metadata::ac_no_abbrevs);
|
||||
auto s = middle::metadata::encode::ty_str(ecx, typ);
|
||||
auto ecx = @rec(ds=f, tcx=cx, abbrevs=metadata::cwriter::ac_no_abbrevs);
|
||||
auto s = metadata::cwriter::encode::ty_str(ecx, typ);
|
||||
if (str::byte_len(s) >= 32u) { s = str::substr(s, 0u, 32u); }
|
||||
ret s;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ mod middle {
|
||||
mod ty;
|
||||
mod walk;
|
||||
mod visit;
|
||||
mod metadata;
|
||||
mod ast_map;
|
||||
mod resolve;
|
||||
mod typeck;
|
||||
@ -46,7 +45,6 @@ mod pretty {
|
||||
|
||||
mod front {
|
||||
mod ast;
|
||||
mod creader;
|
||||
mod ext;
|
||||
mod extfmt;
|
||||
mod extenv;
|
||||
@ -64,6 +62,11 @@ mod back {
|
||||
mod x86;
|
||||
}
|
||||
|
||||
mod metadata {
|
||||
mod creader;
|
||||
mod cwriter;
|
||||
}
|
||||
|
||||
mod driver {
|
||||
mod rustc;
|
||||
mod session;
|
||||
|
Loading…
Reference in New Issue
Block a user