librustc: De-export metadata. rs=deexporting

This commit is contained in:
Patrick Walton 2013-01-29 16:51:16 -08:00
parent bae4821851
commit 464ec27fd3
11 changed files with 277 additions and 426 deletions

View file

@ -11,84 +11,84 @@
// EBML enum definitions and utils shared by the encoder and decoder // EBML enum definitions and utils shared by the encoder and decoder
const tag_items: uint = 0x02u; pub const tag_items: uint = 0x02u;
const tag_paths_data_name: uint = 0x04u; pub const tag_paths_data_name: uint = 0x04u;
const tag_def_id: uint = 0x07u; pub const tag_def_id: uint = 0x07u;
const tag_items_data: uint = 0x08u; pub const tag_items_data: uint = 0x08u;
const tag_items_data_item: uint = 0x09u; pub const tag_items_data_item: uint = 0x09u;
const tag_items_data_item_family: uint = 0x0au; pub const tag_items_data_item_family: uint = 0x0au;
const tag_items_data_item_ty_param_bounds: uint = 0x0bu; pub const tag_items_data_item_ty_param_bounds: uint = 0x0bu;
const tag_items_data_item_type: uint = 0x0cu; pub const tag_items_data_item_type: uint = 0x0cu;
const tag_items_data_item_symbol: uint = 0x0du; pub const tag_items_data_item_symbol: uint = 0x0du;
const tag_items_data_item_variant: uint = 0x0eu; pub const tag_items_data_item_variant: uint = 0x0eu;
const tag_items_data_parent_item: uint = 0x0fu; pub const tag_items_data_parent_item: uint = 0x0fu;
const tag_index: uint = 0x11u; pub const tag_index: uint = 0x11u;
const tag_index_buckets: uint = 0x12u; pub const tag_index_buckets: uint = 0x12u;
const tag_index_buckets_bucket: uint = 0x13u; pub const tag_index_buckets_bucket: uint = 0x13u;
const tag_index_buckets_bucket_elt: uint = 0x14u; pub const tag_index_buckets_bucket_elt: uint = 0x14u;
const tag_index_table: uint = 0x15u; pub const tag_index_table: uint = 0x15u;
const tag_meta_item_name_value: uint = 0x18u; pub const tag_meta_item_name_value: uint = 0x18u;
const tag_meta_item_name: uint = 0x19u; pub const tag_meta_item_name: uint = 0x19u;
const tag_meta_item_value: uint = 0x20u; pub const tag_meta_item_value: uint = 0x20u;
const tag_attributes: uint = 0x21u; pub const tag_attributes: uint = 0x21u;
const tag_attribute: uint = 0x22u; pub const tag_attribute: uint = 0x22u;
const tag_meta_item_word: uint = 0x23u; pub const tag_meta_item_word: uint = 0x23u;
const tag_meta_item_list: uint = 0x24u; pub const tag_meta_item_list: uint = 0x24u;
// The list of crates that this crate depends on // The list of crates that this crate depends on
const tag_crate_deps: uint = 0x25u; pub const tag_crate_deps: uint = 0x25u;
// A single crate dependency // A single crate dependency
const tag_crate_dep: uint = 0x26u; pub const tag_crate_dep: uint = 0x26u;
const tag_crate_hash: uint = 0x28u; pub const tag_crate_hash: uint = 0x28u;
const tag_parent_item: uint = 0x29u; pub const tag_parent_item: uint = 0x29u;
const tag_crate_dep_name: uint = 0x2au; pub const tag_crate_dep_name: uint = 0x2au;
const tag_crate_dep_hash: uint = 0x2bu; pub const tag_crate_dep_hash: uint = 0x2bu;
const tag_crate_dep_vers: uint = 0x2cu; pub const tag_crate_dep_vers: uint = 0x2cu;
const tag_mod_impl: uint = 0x30u; pub const tag_mod_impl: uint = 0x30u;
const tag_item_trait_method: uint = 0x31u; pub const tag_item_trait_method: uint = 0x31u;
const tag_impl_trait: uint = 0x32u; pub const tag_impl_trait: uint = 0x32u;
// discriminator value for variants // discriminator value for variants
const tag_disr_val: uint = 0x34u; pub const tag_disr_val: uint = 0x34u;
// used to encode ast_map::path and ast_map::path_elt // used to encode ast_map::path and ast_map::path_elt
const tag_path: uint = 0x40u; pub const tag_path: uint = 0x40u;
const tag_path_len: uint = 0x41u; pub const tag_path_len: uint = 0x41u;
const tag_path_elt_mod: uint = 0x42u; pub const tag_path_elt_mod: uint = 0x42u;
const tag_path_elt_name: uint = 0x43u; pub const tag_path_elt_name: uint = 0x43u;
const tag_item_field: uint = 0x44u; pub const tag_item_field: uint = 0x44u;
const tag_struct_mut: uint = 0x45u; pub const tag_struct_mut: uint = 0x45u;
const tag_region_param: uint = 0x46u; pub const tag_region_param: uint = 0x46u;
const tag_mod_impl_trait: uint = 0x47u; pub const tag_mod_impl_trait: uint = 0x47u;
/* /*
trait items contain tag_item_trait_method elements, trait items contain tag_item_trait_method elements,
impl items contain tag_item_impl_method elements, and classes impl items contain tag_item_impl_method elements, and classes
@ -97,19 +97,19 @@ const tag_mod_impl_trait: uint = 0x47u;
both, tag_item_trait_method and tag_item_impl_method have to be two both, tag_item_trait_method and tag_item_impl_method have to be two
different tags. different tags.
*/ */
const tag_item_impl_method: uint = 0x48u; pub const tag_item_impl_method: uint = 0x48u;
const tag_item_dtor: uint = 0x49u; pub const tag_item_dtor: uint = 0x49u;
const tag_item_trait_method_self_ty: uint = 0x4b; pub const tag_item_trait_method_self_ty: uint = 0x4b;
const tag_item_trait_method_self_ty_region: uint = 0x4c; pub const tag_item_trait_method_self_ty_region: uint = 0x4c;
// Reexports are found within module tags. Each reexport contains def_ids // Reexports are found within module tags. Each reexport contains def_ids
// and names. // and names.
const tag_items_data_item_reexport: uint = 0x4d; pub const tag_items_data_item_reexport: uint = 0x4d;
const tag_items_data_item_reexport_def_id: uint = 0x4e; pub const tag_items_data_item_reexport_def_id: uint = 0x4e;
const tag_items_data_item_reexport_name: uint = 0x4f; pub const tag_items_data_item_reexport_name: uint = 0x4f;
// used to encode crate_ctxt side tables // used to encode crate_ctxt side tables
enum astencode_tag { // Reserves 0x50 -- 0x6f pub enum astencode_tag { // Reserves 0x50 -- 0x6f
tag_ast = 0x50, tag_ast = 0x50,
tag_tree = 0x51, tag_tree = 0x51,
@ -136,9 +136,9 @@ enum astencode_tag { // Reserves 0x50 -- 0x6f
tag_table_value_mode = 0x64 tag_table_value_mode = 0x64
} }
const tag_item_trait_method_sort: uint = 0x70; pub const tag_item_trait_method_sort: uint = 0x70;
const tag_item_impl_type_basename: uint = 0x71; pub const tag_item_impl_type_basename: uint = 0x71;
// Language items are a top-level directory (for speed). Hierarchy: // Language items are a top-level directory (for speed). Hierarchy:
// //
@ -147,10 +147,10 @@ const tag_item_impl_type_basename: uint = 0x71;
// - tag_lang_items_item_id: u32 // - tag_lang_items_item_id: u32
// - tag_lang_items_item_node_id: u32 // - tag_lang_items_item_node_id: u32
const tag_lang_items: uint = 0x72; pub const tag_lang_items: uint = 0x72;
const tag_lang_items_item: uint = 0x73; pub const tag_lang_items_item: uint = 0x73;
const tag_lang_items_item_id: uint = 0x74; pub const tag_lang_items_item_id: uint = 0x74;
const tag_lang_items_item_node_id: uint = 0x75; pub const tag_lang_items_item_node_id: uint = 0x75;
type link_meta = {name: @str, vers: @str, extras_hash: @str}; pub type link_meta = {name: @str, vers: @str, extras_hash: @str};

View file

@ -32,17 +32,15 @@ use syntax::visit;
use syntax::{ast, ast_util}; use syntax::{ast, ast_util};
use std::map::HashMap; use std::map::HashMap;
export read_crates;
// Traverses an AST, reading all the information about use'd crates and extern // Traverses an AST, reading all the information about use'd crates and extern
// libraries necessary for later resolving, typechecking, linking, etc. // libraries necessary for later resolving, typechecking, linking, etc.
fn read_crates(diag: span_handler, pub fn read_crates(diag: span_handler,
crate: ast::crate, crate: ast::crate,
cstore: cstore::CStore, cstore: cstore::CStore,
filesearch: FileSearch, filesearch: FileSearch,
os: loader::os, os: loader::os,
static: bool, static: bool,
intr: @ident_interner) { intr: @ident_interner) {
let e = @{diag: diag, let e = @{diag: diag,
filesearch: filesearch, filesearch: filesearch,
cstore: cstore, cstore: cstore,

View file

@ -31,64 +31,39 @@ use syntax::ast_util;
use syntax::diagnostic::expect; use syntax::diagnostic::expect;
use syntax::diagnostic::span_handler; use syntax::diagnostic::span_handler;
export struct_dtor; pub struct ProvidedTraitMethodInfo {
export get_symbol;
export get_struct_fields;
export get_field_type;
export get_type_param_count;
export get_region_param;
export get_enum_variants;
export get_impls_for_mod;
export get_trait_methods;
export get_provided_trait_methods;
export get_supertraits;
export get_method_names_if_trait;
export get_type_name_if_impl;
export get_static_methods_if_impl;
export get_item_attrs;
export each_lang_item;
export each_path;
export get_type;
export get_impl_traits;
export get_impl_method;
export get_item_path;
export get_lang_items;
export maybe_get_item_ast, found_ast, found, found_parent, not_found;
export ProvidedTraitMethodInfo;
export StaticMethodInfo;
struct ProvidedTraitMethodInfo {
ty: ty::method, ty: ty::method,
def_id: ast::def_id def_id: ast::def_id
} }
struct StaticMethodInfo { pub struct StaticMethodInfo {
ident: ast::ident, ident: ast::ident,
def_id: ast::def_id, def_id: ast::def_id,
purity: ast::purity purity: ast::purity
} }
fn get_symbol(cstore: cstore::CStore, def: ast::def_id) -> ~str { pub fn get_symbol(cstore: cstore::CStore, def: ast::def_id) -> ~str {
let cdata = cstore::get_crate_data(cstore, def.crate).data; let cdata = cstore::get_crate_data(cstore, def.crate).data;
return decoder::get_symbol(cdata, def.node); return decoder::get_symbol(cdata, def.node);
} }
fn get_type_param_count(cstore: cstore::CStore, def: ast::def_id) -> uint { pub fn get_type_param_count(cstore: cstore::CStore, def: ast::def_id)
-> uint {
let cdata = cstore::get_crate_data(cstore, def.crate).data; let cdata = cstore::get_crate_data(cstore, def.crate).data;
return decoder::get_type_param_count(cdata, def.node); return decoder::get_type_param_count(cdata, def.node);
} }
/// Iterates over all the language items in the given crate. /// Iterates over all the language items in the given crate.
fn each_lang_item(cstore: cstore::CStore, pub fn each_lang_item(cstore: cstore::CStore,
cnum: ast::crate_num, cnum: ast::crate_num,
f: &fn(ast::node_id, uint) -> bool) { f: &fn(ast::node_id, uint) -> bool) {
let crate_data = cstore::get_crate_data(cstore, cnum); let crate_data = cstore::get_crate_data(cstore, cnum);
decoder::each_lang_item(crate_data, f) decoder::each_lang_item(crate_data, f)
} }
/// Iterates over all the paths in the given crate. /// Iterates over all the paths in the given crate.
fn each_path(cstore: cstore::CStore, cnum: ast::crate_num, pub fn each_path(cstore: cstore::CStore, cnum: ast::crate_num,
f: fn(&str, decoder::def_like) -> bool) { f: fn(&str, decoder::def_like) -> bool) {
let crate_data = cstore::get_crate_data(cstore, cnum); let crate_data = cstore::get_crate_data(cstore, cnum);
let get_crate_data: decoder::GetCrateDataCb = |cnum| { let get_crate_data: decoder::GetCrateDataCb = |cnum| {
cstore::get_crate_data(cstore, cnum) cstore::get_crate_data(cstore, cnum)
@ -96,7 +71,7 @@ fn each_path(cstore: cstore::CStore, cnum: ast::crate_num,
decoder::each_path(cstore.intr, crate_data, get_crate_data, f); decoder::each_path(cstore.intr, crate_data, get_crate_data, f);
} }
fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path { pub fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
let path = decoder::get_item_path(cstore.intr, cdata, def.node); let path = decoder::get_item_path(cstore.intr, cdata, def.node);
@ -107,7 +82,7 @@ fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path {
/*bad*/copy cdata.name))], path) /*bad*/copy cdata.name))], path)
} }
enum found_ast { pub enum found_ast {
found(ast::inlined_item), found(ast::inlined_item),
found_parent(ast::def_id, ast::inlined_item), found_parent(ast::def_id, ast::inlined_item),
not_found, not_found,
@ -116,97 +91,102 @@ enum found_ast {
// Finds the AST for this item in the crate metadata, if any. If the item was // Finds the AST for this item in the crate metadata, if any. If the item was
// not marked for inlining, then the AST will not be present and hence none // not marked for inlining, then the AST will not be present and hence none
// will be returned. // will be returned.
fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::def_id, pub fn maybe_get_item_ast(tcx: ty::ctxt, def: ast::def_id,
decode_inlined_item: decoder::decode_inlined_item) decode_inlined_item: decoder::decode_inlined_item)
-> found_ast { -> found_ast {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::maybe_get_item_ast(cstore.intr, cdata, tcx, def.node, decoder::maybe_get_item_ast(cstore.intr, cdata, tcx, def.node,
decode_inlined_item) decode_inlined_item)
} }
fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) pub fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id)
-> ~[ty::VariantInfo] { -> ~[ty::VariantInfo] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx) return decoder::get_enum_variants(cstore.intr, cdata, def.node, tcx)
} }
fn get_impls_for_mod(cstore: cstore::CStore, def: ast::def_id, pub fn get_impls_for_mod(cstore: cstore::CStore, def: ast::def_id,
name: Option<ast::ident>) name: Option<ast::ident>)
-> @~[@decoder::_impl] { -> @~[@decoder::_impl] {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
do decoder::get_impls_for_mod(cstore.intr, cdata, def.node, name) |cnum| { do decoder::get_impls_for_mod(cstore.intr, cdata, def.node, name) |cnum| {
cstore::get_crate_data(cstore, cnum) cstore::get_crate_data(cstore, cnum)
} }
} }
fn get_trait_methods(tcx: ty::ctxt, def: ast::def_id) -> @~[ty::method] { pub fn get_trait_methods(tcx: ty::ctxt,
def: ast::def_id)
-> @~[ty::method] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_trait_methods(cstore.intr, cdata, def.node, tcx) decoder::get_trait_methods(cstore.intr, cdata, def.node, tcx)
} }
fn get_provided_trait_methods(tcx: ty::ctxt, def: ast::def_id) -> pub fn get_provided_trait_methods(tcx: ty::ctxt,
~[ProvidedTraitMethodInfo] { def: ast::def_id)
-> ~[ProvidedTraitMethodInfo] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx) decoder::get_provided_trait_methods(cstore.intr, cdata, def.node, tcx)
} }
fn get_supertraits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] { pub fn get_supertraits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_supertraits(cdata, def.node, tcx) decoder::get_supertraits(cdata, def.node, tcx)
} }
fn get_method_names_if_trait(cstore: cstore::CStore, def: ast::def_id) pub fn get_method_names_if_trait(cstore: cstore::CStore, def: ast::def_id)
-> Option<@DVec<(ast::ident, ast::self_ty_)>> { -> Option<@DVec<(ast::ident, ast::self_ty_)>> {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
return decoder::get_method_names_if_trait(cstore.intr, cdata, def.node); return decoder::get_method_names_if_trait(cstore.intr, cdata, def.node);
} }
fn get_type_name_if_impl(cstore: cstore::CStore, def: ast::def_id) -> pub fn get_type_name_if_impl(cstore: cstore::CStore, def: ast::def_id) ->
Option<ast::ident> { Option<ast::ident> {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_type_name_if_impl(cstore.intr, cdata, def.node) decoder::get_type_name_if_impl(cstore.intr, cdata, def.node)
} }
fn get_static_methods_if_impl(cstore: cstore::CStore, def: ast::def_id) -> pub fn get_static_methods_if_impl(cstore: cstore::CStore,
Option<~[StaticMethodInfo]> { def: ast::def_id)
-> Option<~[StaticMethodInfo]> {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_static_methods_if_impl(cstore.intr, cdata, def.node) decoder::get_static_methods_if_impl(cstore.intr, cdata, def.node)
} }
fn get_item_attrs(cstore: cstore::CStore, pub fn get_item_attrs(cstore: cstore::CStore,
def_id: ast::def_id, def_id: ast::def_id,
f: fn(~[@ast::meta_item])) { f: fn(~[@ast::meta_item])) {
let cdata = cstore::get_crate_data(cstore, def_id.crate); let cdata = cstore::get_crate_data(cstore, def_id.crate);
decoder::get_item_attrs(cdata, def_id.node, f) decoder::get_item_attrs(cdata, def_id.node, f)
} }
fn get_struct_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] { pub fn get_struct_fields(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::field_ty] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_struct_fields(cstore.intr, cdata, def.node) decoder::get_struct_fields(cstore.intr, cdata, def.node)
} }
fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_bounds_and_ty { pub fn get_type(tcx: ty::ctxt,
def: ast::def_id)
-> ty::ty_param_bounds_and_ty {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_type(cdata, def.node, tcx) decoder::get_type(cdata, def.node, tcx)
} }
fn get_region_param(cstore: metadata::cstore::CStore, pub fn get_region_param(cstore: metadata::cstore::CStore,
def: ast::def_id) -> Option<ty::region_variance> { def: ast::def_id) -> Option<ty::region_variance> {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
return decoder::get_region_param(cdata, def.node); return decoder::get_region_param(cdata, def.node);
} }
fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id, pub fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
def: ast::def_id) -> ty::ty_param_bounds_and_ty { def: ast::def_id) -> ty::ty_param_bounds_and_ty {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, class_id.crate); let cdata = cstore::get_crate_data(cstore, class_id.crate);
let all_items = reader::get_doc(reader::Doc(cdata.data), tag_items); let all_items = reader::get_doc(reader::Doc(cdata.data), tag_items);
@ -230,21 +210,22 @@ fn get_field_type(tcx: ty::ctxt, class_id: ast::def_id,
// Given a def_id for an impl or class, return the traits it implements, // Given a def_id for an impl or class, return the traits it implements,
// or the empty vector if it's not for an impl or for a class that implements // or the empty vector if it's not for an impl or for a class that implements
// traits // traits
fn get_impl_traits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] { pub fn get_impl_traits(tcx: ty::ctxt, def: ast::def_id) -> ~[ty::t] {
let cstore = tcx.cstore; let cstore = tcx.cstore;
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_impl_traits(cdata, def.node, tcx) decoder::get_impl_traits(cdata, def.node, tcx)
} }
fn get_impl_method(cstore: cstore::CStore, pub fn get_impl_method(cstore: cstore::CStore,
def: ast::def_id, mname: ast::ident) def: ast::def_id,
-> ast::def_id { mname: ast::ident)
-> ast::def_id {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_impl_method(cstore.intr, cdata, def.node, mname) decoder::get_impl_method(cstore.intr, cdata, def.node, mname)
} }
/* If def names a class with a dtor, return it. Otherwise, return none. */ /* If def names a class with a dtor, return it. Otherwise, return none. */
fn struct_dtor(cstore: cstore::CStore, def: ast::def_id) pub fn struct_dtor(cstore: cstore::CStore, def: ast::def_id)
-> Option<ast::def_id> { -> Option<ast::def_id> {
let cdata = cstore::get_crate_data(cstore, def.crate); let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::struct_dtor(cdata, def.node) decoder::struct_dtor(cdata, def.node)

View file

@ -27,44 +27,23 @@ use std;
use syntax::{ast, attr}; use syntax::{ast, attr};
use syntax::parse::token::ident_interner; use syntax::parse::token::ident_interner;
export CStore;
export cnum_map;
export crate_metadata;
export mk_cstore;
export get_crate_data;
export set_crate_data;
export get_crate_hash;
export get_crate_vers;
export have_crate_data;
export iter_crate_data;
export add_used_crate_file;
export get_used_crate_files;
export add_used_library;
export get_used_libraries;
export add_used_link_args;
export get_used_link_args;
export add_use_stmt_cnum;
export find_use_stmt_cnum;
export get_dep_hashes;
// A map from external crate numbers (as decoded from some crate file) to // A map from external crate numbers (as decoded from some crate file) to
// local crate numbers (as generated during this session). Each external // local crate numbers (as generated during this session). Each external
// crate may refer to types in other external crates, and each has their // crate may refer to types in other external crates, and each has their
// own crate numbers. // own crate numbers.
type cnum_map = map::HashMap<ast::crate_num, ast::crate_num>; pub type cnum_map = map::HashMap<ast::crate_num, ast::crate_num>;
type crate_metadata = @{name: ~str, pub type crate_metadata = @{name: ~str,
data: @~[u8], data: @~[u8],
cnum_map: cnum_map, cnum_map: cnum_map,
cnum: ast::crate_num}; cnum: ast::crate_num};
// This is a bit of an experiment at encapsulating the data in cstore. By // This is a bit of an experiment at encapsulating the data in cstore. By
// keeping all the data in a non-exported enum variant, it's impossible for // keeping all the data in a non-exported enum variant, it's impossible for
// other modules to access the cstore's private data. This could also be // other modules to access the cstore's private data. This could also be
// achieved with an obj, but at the expense of a vtable. Not sure if this is a // achieved with an obj, but at the expense of a vtable. Not sure if this is a
// good pattern or not. // good pattern or not.
enum CStore { private(cstore_private), } pub enum CStore { private(cstore_private), }
type cstore_private = type cstore_private =
@{metas: map::HashMap<ast::crate_num, crate_metadata>, @{metas: map::HashMap<ast::crate_num, crate_metadata>,
@ -82,7 +61,7 @@ pure fn p(cstore: CStore) -> cstore_private {
match cstore { private(p) => p } match cstore { private(p) => p }
} }
fn mk_cstore(intr: @ident_interner) -> CStore { pub fn mk_cstore(intr: @ident_interner) -> CStore {
let meta_cache = map::HashMap(); let meta_cache = map::HashMap();
let crate_map = map::HashMap(); let crate_map = map::HashMap();
return private(@{metas: meta_cache, return private(@{metas: meta_cache,
@ -93,45 +72,47 @@ fn mk_cstore(intr: @ident_interner) -> CStore {
intr: intr}); intr: intr});
} }
fn get_crate_data(cstore: CStore, cnum: ast::crate_num) -> crate_metadata { pub fn get_crate_data(cstore: CStore, cnum: ast::crate_num)
-> crate_metadata {
return p(cstore).metas.get(cnum); return p(cstore).metas.get(cnum);
} }
fn get_crate_hash(cstore: CStore, cnum: ast::crate_num) -> ~str { pub fn get_crate_hash(cstore: CStore, cnum: ast::crate_num) -> ~str {
let cdata = get_crate_data(cstore, cnum); let cdata = get_crate_data(cstore, cnum);
return decoder::get_crate_hash(cdata.data); return decoder::get_crate_hash(cdata.data);
} }
fn get_crate_vers(cstore: CStore, cnum: ast::crate_num) -> ~str { pub fn get_crate_vers(cstore: CStore, cnum: ast::crate_num) -> ~str {
let cdata = get_crate_data(cstore, cnum); let cdata = get_crate_data(cstore, cnum);
return decoder::get_crate_vers(cdata.data); return decoder::get_crate_vers(cdata.data);
} }
fn set_crate_data(cstore: CStore, pub fn set_crate_data(cstore: CStore,
cnum: ast::crate_num, cnum: ast::crate_num,
data: crate_metadata) { data: crate_metadata) {
p(cstore).metas.insert(cnum, data); p(cstore).metas.insert(cnum, data);
} }
fn have_crate_data(cstore: CStore, cnum: ast::crate_num) -> bool { pub fn have_crate_data(cstore: CStore, cnum: ast::crate_num) -> bool {
return p(cstore).metas.contains_key(cnum); return p(cstore).metas.contains_key(cnum);
} }
fn iter_crate_data(cstore: CStore, i: fn(ast::crate_num, crate_metadata)) { pub fn iter_crate_data(cstore: CStore,
i: fn(ast::crate_num, crate_metadata)) {
for p(cstore).metas.each |k,v| { i(k, v);}; for p(cstore).metas.each |k,v| { i(k, v);};
} }
fn add_used_crate_file(cstore: CStore, lib: &Path) { pub fn add_used_crate_file(cstore: CStore, lib: &Path) {
if !vec::contains(p(cstore).used_crate_files, lib) { if !vec::contains(p(cstore).used_crate_files, lib) {
p(cstore).used_crate_files.push(copy *lib); p(cstore).used_crate_files.push(copy *lib);
} }
} }
fn get_used_crate_files(cstore: CStore) -> ~[Path] { pub fn get_used_crate_files(cstore: CStore) -> ~[Path] {
return /*bad*/copy p(cstore).used_crate_files; return /*bad*/copy p(cstore).used_crate_files;
} }
fn add_used_library(cstore: CStore, +lib: ~str) -> bool { pub fn add_used_library(cstore: CStore, +lib: ~str) -> bool {
assert lib != ~""; assert lib != ~"";
if vec::contains(p(cstore).used_libraries, &lib) { return false; } if vec::contains(p(cstore).used_libraries, &lib) { return false; }
@ -139,31 +120,31 @@ fn add_used_library(cstore: CStore, +lib: ~str) -> bool {
return true; return true;
} }
fn get_used_libraries(cstore: CStore) -> ~[~str] { pub fn get_used_libraries(cstore: CStore) -> ~[~str] {
return /*bad*/copy p(cstore).used_libraries; return /*bad*/copy p(cstore).used_libraries;
} }
fn add_used_link_args(cstore: CStore, args: ~str) { pub fn add_used_link_args(cstore: CStore, args: ~str) {
p(cstore).used_link_args.push_all(str::split_char(args, ' ')); p(cstore).used_link_args.push_all(str::split_char(args, ' '));
} }
fn get_used_link_args(cstore: CStore) -> ~[~str] { pub fn get_used_link_args(cstore: CStore) -> ~[~str] {
return /*bad*/copy p(cstore).used_link_args; return /*bad*/copy p(cstore).used_link_args;
} }
fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id, pub fn add_use_stmt_cnum(cstore: CStore, use_id: ast::node_id,
cnum: ast::crate_num) { cnum: ast::crate_num) {
p(cstore).use_crate_map.insert(use_id, cnum); p(cstore).use_crate_map.insert(use_id, cnum);
} }
fn find_use_stmt_cnum(cstore: CStore, pub fn find_use_stmt_cnum(cstore: CStore,
use_id: ast::node_id) -> Option<ast::crate_num> { use_id: ast::node_id) -> Option<ast::crate_num> {
p(cstore).use_crate_map.find(use_id) p(cstore).use_crate_map.find(use_id)
} }
// returns hashes of crates directly used by this crate. Hashes are // returns hashes of crates directly used by this crate. Hashes are
// sorted by crate name. // sorted by crate name.
fn get_dep_hashes(cstore: CStore) -> ~[~str] { pub fn get_dep_hashes(cstore: CStore) -> ~[~str] {
type crate_hash = {name: ~str, hash: ~str}; type crate_hash = {name: ~str, hash: ~str};
let mut result = ~[]; let mut result = ~[];

View file

@ -46,48 +46,6 @@ use syntax::parse::token::ident_interner;
use syntax::print::pprust; use syntax::print::pprust;
use syntax::{ast, ast_util}; use syntax::{ast, ast_util};
export struct_dtor;
export get_struct_fields;
export get_symbol;
export get_enum_variants;
export get_type;
export get_region_param;
export get_type_param_count;
export get_impl_traits;
export get_impl_method;
export get_static_methods_if_impl;
export lookup_def;
export resolve_path;
export get_crate_attributes;
export list_crate_metadata;
export crate_dep;
export get_crate_deps;
export get_crate_hash;
export get_crate_vers;
export get_impls_for_mod;
export get_trait_methods;
export get_provided_trait_methods;
export get_supertraits;
export get_method_names_if_trait;
export get_type_name_if_impl;
export get_item_attrs;
export def_like;
export dl_def;
export dl_impl;
export dl_field;
export each_lang_item;
export each_path;
export get_item_path;
export maybe_find_item; // sketchy
export item_type; // sketchy
export maybe_get_item_ast;
export decode_inlined_item;
export method_info, _impl;
export GetCrateDataCb;
// Used internally by astencode:
export translate_def_id;
// A function that takes a def_id relative to the crate being searched and // A function that takes a def_id relative to the crate being searched and
// returns a def_id relative to the compilation environment, i.e. if we hit a // returns a def_id relative to the compilation environment, i.e. if we hit a
// def_id for an item defined in another crate, somebody needs to figure out // def_id for an item defined in another crate, somebody needs to figure out
@ -114,7 +72,7 @@ fn lookup_hash(d: ebml::Doc, eq_fn: fn(x:&[u8]) -> bool, hash: uint) ->
pub type GetCrateDataCb = &fn(ast::crate_num) -> cmd; pub type GetCrateDataCb = &fn(ast::crate_num) -> cmd;
fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option<ebml::Doc> { pub fn maybe_find_item(item_id: int, items: ebml::Doc) -> Option<ebml::Doc> {
fn eq_item(bytes: &[u8], item_id: int) -> bool { fn eq_item(bytes: &[u8], item_id: int) -> bool {
return io::u64_from_be_bytes(vec::view(bytes, 0u, 4u), 0u, 4u) as int return io::u64_from_be_bytes(vec::view(bytes, 0u, 4u), 0u, 4u) as int
== item_id; == item_id;
@ -267,8 +225,8 @@ fn doc_type(doc: ebml::Doc, tcx: ty::ctxt, cdata: cmd) -> ty::t {
|_, did| translate_def_id(cdata, did)) |_, did| translate_def_id(cdata, did))
} }
fn item_type(item_id: ast::def_id, item: ebml::Doc, pub fn item_type(item_id: ast::def_id, item: ebml::Doc,
tcx: ty::ctxt, cdata: cmd) -> ty::t { tcx: ty::ctxt, cdata: cmd) -> ty::t {
let t = doc_type(item, tcx, cdata); let t = doc_type(item, tcx, cdata);
if family_names_type(item_family(item)) { if family_names_type(item_family(item)) {
ty::mk_with_id(tcx, t, item_id) ty::mk_with_id(tcx, t, item_id)
@ -380,7 +338,7 @@ fn item_to_def_like(item: ebml::Doc, did: ast::def_id, cnum: ast::crate_num)
} }
} }
fn lookup_def(cnum: ast::crate_num, data: @~[u8], did_: ast::def_id) -> pub fn lookup_def(cnum: ast::crate_num, data: @~[u8], did_: ast::def_id) ->
ast::def { ast::def {
let item = lookup_item(did_.node, data); let item = lookup_item(did_.node, data);
let did = ast::def_id { crate: cnum, node: did_.node }; let did = ast::def_id { crate: cnum, node: did_.node };
@ -388,7 +346,7 @@ fn lookup_def(cnum: ast::crate_num, data: @~[u8], did_: ast::def_id) ->
return def_like_to_def(item_to_def_like(item, did, cnum)); return def_like_to_def(item_to_def_like(item, did, cnum));
} }
fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) pub fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
-> ty::ty_param_bounds_and_ty { -> ty::ty_param_bounds_and_ty {
let item = lookup_item(id, cdata.data); let item = lookup_item(id, cdata.data);
@ -403,23 +361,24 @@ fn get_type(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
ty: t}; ty: t};
} }
fn get_region_param(cdata: cmd, id: ast::node_id) pub fn get_region_param(cdata: cmd, id: ast::node_id)
-> Option<ty::region_variance> { -> Option<ty::region_variance> {
let item = lookup_item(id, cdata.data); let item = lookup_item(id, cdata.data);
return item_ty_region_param(item); return item_ty_region_param(item);
} }
fn get_type_param_count(data: @~[u8], id: ast::node_id) -> uint { pub fn get_type_param_count(data: @~[u8], id: ast::node_id) -> uint {
item_ty_param_count(lookup_item(id, data)) item_ty_param_count(lookup_item(id, data))
} }
fn get_impl_traits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) -> ~[ty::t] { pub fn get_impl_traits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
-> ~[ty::t] {
item_impl_traits(lookup_item(id, cdata.data), tcx, cdata) item_impl_traits(lookup_item(id, cdata.data), tcx, cdata)
} }
fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id, pub fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
name: ast::ident) -> ast::def_id { name: ast::ident) -> ast::def_id {
let items = reader::get_doc(reader::Doc(cdata.data), tag_items); let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
let mut found = None; let mut found = None;
for reader::tagged_docs(find_item(id, items), tag_item_impl_method) for reader::tagged_docs(find_item(id, items), tag_item_impl_method)
@ -432,7 +391,7 @@ fn get_impl_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
found.get() found.get()
} }
fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> { pub fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
let items = reader::get_doc(reader::Doc(cdata.data), tag_items); let items = reader::get_doc(reader::Doc(cdata.data), tag_items);
let mut found = None; let mut found = None;
let cls_items = match maybe_find_item(id, items) { let cls_items = match maybe_find_item(id, items) {
@ -448,12 +407,12 @@ fn struct_dtor(cdata: cmd, id: ast::node_id) -> Option<ast::def_id> {
found found
} }
fn get_symbol(data: @~[u8], id: ast::node_id) -> ~str { pub fn get_symbol(data: @~[u8], id: ast::node_id) -> ~str {
return item_symbol(lookup_item(id, data)); return item_symbol(lookup_item(id, data));
} }
// Something that a name can resolve to. // Something that a name can resolve to.
enum def_like { pub enum def_like {
dl_def(ast::def), dl_def(ast::def),
dl_impl(ast::def_id), dl_impl(ast::def_id),
dl_field dl_field
@ -468,7 +427,7 @@ fn def_like_to_def(def_like: def_like) -> ast::def {
} }
/// Iterates over the language items in the given crate. /// Iterates over the language items in the given crate.
fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) { pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
let root = reader::Doc(cdata.data); let root = reader::Doc(cdata.data);
let lang_items = reader::get_doc(root, tag_lang_items); let lang_items = reader::get_doc(root, tag_lang_items);
for reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| { for reader::tagged_docs(lang_items, tag_lang_items_item) |item_doc| {
@ -485,9 +444,9 @@ fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
} }
/// Iterates over all the paths in the given crate. /// Iterates over all the paths in the given crate.
fn each_path(intr: @ident_interner, cdata: cmd, pub fn each_path(intr: @ident_interner, cdata: cmd,
get_crate_data: GetCrateDataCb, get_crate_data: GetCrateDataCb,
f: fn(&str, def_like) -> bool) { f: fn(&str, def_like) -> bool) {
let root = reader::Doc(cdata.data); let root = reader::Doc(cdata.data);
let items = reader::get_doc(root, tag_items); let items = reader::get_doc(root, tag_items);
let items_data = reader::get_doc(items, tag_items_data); let items_data = reader::get_doc(items, tag_items_data);
@ -575,21 +534,21 @@ fn each_path(intr: @ident_interner, cdata: cmd,
} }
} }
fn get_item_path(intr: @ident_interner, cdata: cmd, id: ast::node_id) pub fn get_item_path(intr: @ident_interner, cdata: cmd, id: ast::node_id)
-> ast_map::path { -> ast_map::path {
item_path(intr, lookup_item(id, cdata.data)) item_path(intr, lookup_item(id, cdata.data))
} }
type decode_inlined_item = fn( pub type decode_inlined_item = fn(
cdata: cstore::crate_metadata, cdata: cstore::crate_metadata,
tcx: ty::ctxt, tcx: ty::ctxt,
path: ast_map::path, path: ast_map::path,
par_doc: ebml::Doc) -> Option<ast::inlined_item>; par_doc: ebml::Doc) -> Option<ast::inlined_item>;
fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt, pub fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt,
id: ast::node_id, id: ast::node_id,
decode_inlined_item: decode_inlined_item decode_inlined_item: decode_inlined_item)
) -> csearch::found_ast { -> csearch::found_ast {
debug!("Looking up item: %d", id); debug!("Looking up item: %d", id);
let item_doc = lookup_item(id, cdata.data); let item_doc = lookup_item(id, cdata.data);
let path = vec::init(item_path(intr, item_doc)); let path = vec::init(item_path(intr, item_doc));
@ -612,7 +571,7 @@ fn maybe_get_item_ast(intr: @ident_interner, cdata: cmd, tcx: ty::ctxt,
} }
} }
fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id, pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
tcx: ty::ctxt) -> ~[ty::VariantInfo] { tcx: ty::ctxt) -> ~[ty::VariantInfo] {
let data = cdata.data; let data = cdata.data;
let items = reader::get_doc(reader::Doc(data), tag_items); let items = reader::get_doc(reader::Doc(data), tag_items);
@ -646,14 +605,18 @@ fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
} }
// NB: These types are duplicated in resolve.rs // NB: These types are duplicated in resolve.rs
type method_info = { pub type method_info = {
did: ast::def_id, did: ast::def_id,
n_tps: uint, n_tps: uint,
ident: ast::ident, ident: ast::ident,
self_type: ast::self_ty_ self_type: ast::self_ty_
}; };
type _impl = {did: ast::def_id, ident: ast::ident, methods: ~[@method_info]}; pub type _impl = {
did: ast::def_id,
ident: ast::ident,
methods: ~[@method_info]
};
fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ { fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
fn get_mutability(ch: u8) -> ast::mutability { fn get_mutability(ch: u8) -> ast::mutability {
@ -699,10 +662,10 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
rslt rslt
} }
fn get_impls_for_mod(intr: @ident_interner, cdata: cmd, pub fn get_impls_for_mod(intr: @ident_interner, cdata: cmd,
m_id: ast::node_id, name: Option<ast::ident>, m_id: ast::node_id, name: Option<ast::ident>,
get_cdata: fn(ast::crate_num) -> cmd) get_cdata: fn(ast::crate_num) -> cmd)
-> @~[@_impl] { -> @~[@_impl] {
let data = cdata.data; let data = cdata.data;
let mod_item = lookup_item(m_id, data); let mod_item = lookup_item(m_id, data);
@ -730,8 +693,8 @@ fn get_impls_for_mod(intr: @ident_interner, cdata: cmd,
} }
/* Works for both classes and traits */ /* Works for both classes and traits */
fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id, pub fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id,
tcx: ty::ctxt) -> @~[ty::method] { tcx: ty::ctxt) -> @~[ty::method] {
let data = cdata.data; let data = cdata.data;
let item = lookup_item(id, data); let item = lookup_item(id, data);
let mut result = ~[]; let mut result = ~[];
@ -754,8 +717,8 @@ fn get_trait_methods(intr: @ident_interner, cdata: cmd, id: ast::node_id,
@result @result
} }
fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd, pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
id: ast::node_id, tcx: ty::ctxt) -> id: ast::node_id, tcx: ty::ctxt) ->
~[ProvidedTraitMethodInfo] { ~[ProvidedTraitMethodInfo] {
let data = cdata.data; let data = cdata.data;
let item = lookup_item(id, data); let item = lookup_item(id, data);
@ -794,7 +757,8 @@ fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
} }
/// Returns the supertraits of the given trait. /// Returns the supertraits of the given trait.
fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) -> ~[ty::t] { pub fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt)
-> ~[ty::t] {
let results = dvec::DVec(); let results = dvec::DVec();
let item_doc = lookup_item(id, cdata.data); let item_doc = lookup_item(id, cdata.data);
for reader::tagged_docs(item_doc, tag_impl_trait) |trait_doc| { for reader::tagged_docs(item_doc, tag_impl_trait) |trait_doc| {
@ -806,9 +770,9 @@ fn get_supertraits(cdata: cmd, id: ast::node_id, tcx: ty::ctxt) -> ~[ty::t] {
// If the item in question is a trait, returns its set of methods and // If the item in question is a trait, returns its set of methods and
// their self types. Otherwise, returns none. This overlaps in an // their self types. Otherwise, returns none. This overlaps in an
// annoying way with get_trait_methods. // annoying way with get_trait_methods.
fn get_method_names_if_trait(intr: @ident_interner, cdata: cmd, pub fn get_method_names_if_trait(intr: @ident_interner, cdata: cmd,
node_id: ast::node_id) node_id: ast::node_id)
-> Option<@DVec<(ast::ident, ast::self_ty_)>> { -> Option<@DVec<(ast::ident, ast::self_ty_)>> {
let item = lookup_item(node_id, cdata.data); let item = lookup_item(node_id, cdata.data);
if item_family(item) != Trait { if item_family(item) != Trait {
@ -823,9 +787,9 @@ fn get_method_names_if_trait(intr: @ident_interner, cdata: cmd,
return Some(resulting_methods); return Some(resulting_methods);
} }
fn get_type_name_if_impl(intr: @ident_interner, pub fn get_type_name_if_impl(intr: @ident_interner,
cdata: cmd, cdata: cmd,
node_id: ast::node_id) -> Option<ast::ident> { node_id: ast::node_id) -> Option<ast::ident> {
let item = lookup_item(node_id, cdata.data); let item = lookup_item(node_id, cdata.data);
if item_family(item) != Impl { if item_family(item) != Impl {
return None; return None;
@ -838,10 +802,10 @@ fn get_type_name_if_impl(intr: @ident_interner,
return None; return None;
} }
fn get_static_methods_if_impl(intr: @ident_interner, pub fn get_static_methods_if_impl(intr: @ident_interner,
cdata: cmd, cdata: cmd,
node_id: ast::node_id) -> node_id: ast::node_id)
Option<~[StaticMethodInfo]> { -> Option<~[StaticMethodInfo]> {
let item = lookup_item(node_id, cdata.data); let item = lookup_item(node_id, cdata.data);
if item_family(item) != Impl { if item_family(item) != Impl {
return None; return None;
@ -884,9 +848,9 @@ fn get_static_methods_if_impl(intr: @ident_interner,
return Some(dvec::unwrap(move static_impl_methods)); return Some(dvec::unwrap(move static_impl_methods));
} }
fn get_item_attrs(cdata: cmd, pub fn get_item_attrs(cdata: cmd,
node_id: ast::node_id, node_id: ast::node_id,
f: fn(~[@ast::meta_item])) { f: fn(~[@ast::meta_item])) {
let item = lookup_item(node_id, cdata.data); let item = lookup_item(node_id, cdata.data);
for reader::tagged_docs(item, tag_attributes) |attributes| { for reader::tagged_docs(item, tag_attributes) |attributes| {
@ -905,7 +869,7 @@ pure fn family_to_visibility(family: Family) -> ast::visibility {
} }
} }
fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id) pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
-> ~[ty::field_ty] { -> ~[ty::field_ty] {
let data = cdata.data; let data = cdata.data;
let item = lookup_item(id, data); let item = lookup_item(id, data);
@ -1050,14 +1014,14 @@ fn list_crate_attributes(intr: @ident_interner, md: ebml::Doc, hash: ~str,
out.write_str(~"\n\n"); out.write_str(~"\n\n");
} }
fn get_crate_attributes(data: @~[u8]) -> ~[ast::attribute] { pub fn get_crate_attributes(data: @~[u8]) -> ~[ast::attribute] {
return get_attributes(reader::Doc(data)); return get_attributes(reader::Doc(data));
} }
type crate_dep = {cnum: ast::crate_num, name: ast::ident, pub type crate_dep = {cnum: ast::crate_num, name: ast::ident,
vers: ~str, hash: ~str}; vers: ~str, hash: ~str};
fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] { pub fn get_crate_deps(intr: @ident_interner, data: @~[u8]) -> ~[crate_dep] {
let mut deps: ~[crate_dep] = ~[]; let mut deps: ~[crate_dep] = ~[];
let cratedoc = reader::Doc(data); let cratedoc = reader::Doc(data);
let depsdoc = reader::get_doc(cratedoc, tag_crate_deps); let depsdoc = reader::get_doc(cratedoc, tag_crate_deps);
@ -1087,13 +1051,13 @@ fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: io::Writer) {
out.write_str(~"\n"); out.write_str(~"\n");
} }
fn get_crate_hash(data: @~[u8]) -> ~str { pub fn get_crate_hash(data: @~[u8]) -> ~str {
let cratedoc = reader::Doc(data); let cratedoc = reader::Doc(data);
let hashdoc = reader::get_doc(cratedoc, tag_crate_hash); let hashdoc = reader::get_doc(cratedoc, tag_crate_hash);
return str::from_bytes(reader::doc_data(hashdoc)); return str::from_bytes(reader::doc_data(hashdoc));
} }
fn get_crate_vers(data: @~[u8]) -> ~str { pub fn get_crate_vers(data: @~[u8]) -> ~str {
let attrs = decoder::get_crate_attributes(data); let attrs = decoder::get_crate_attributes(data);
return match attr::last_meta_item_value_str_by_name( return match attr::last_meta_item_value_str_by_name(
attr::find_linkage_metas(attrs), ~"vers") { attr::find_linkage_metas(attrs), ~"vers") {
@ -1116,8 +1080,8 @@ fn iter_crate_items(intr: @ident_interner, cdata: cmd,
} }
} }
fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8], pub fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
out: io::Writer) { out: io::Writer) {
let hash = get_crate_hash(bytes); let hash = get_crate_hash(bytes);
let md = reader::Doc(bytes); let md = reader::Doc(bytes);
list_crate_attributes(intr, md, hash, out); list_crate_attributes(intr, md, hash, out);
@ -1129,7 +1093,7 @@ fn list_crate_metadata(intr: @ident_interner, bytes: @~[u8],
// external crates - if those types further refer to types in other crates // external crates - if those types further refer to types in other crates
// then we must translate the crate number from that encoded in the external // then we must translate the crate number from that encoded in the external
// crate to the correct local crate number. // crate to the correct local crate number.
fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id { pub fn translate_def_id(cdata: cmd, did: ast::def_id) -> ast::def_id {
if did.crate == ast::local_crate { if did.crate == ast::local_crate {
return ast::def_id { crate: cdata.cnum, node: did.node }; return ast::def_id { crate: cdata.cnum, node: did.node };
} }

View file

@ -51,20 +51,7 @@ use syntax::{ast_util, visit};
use syntax; use syntax;
use writer = std::ebml::writer; use writer = std::ebml::writer;
export encode_parms;
export encode_metadata;
export encoded_ty;
export reachable;
export encode_inlined_item;
export metadata_encoding_version;
// used by astencode: // used by astencode:
export def_to_str;
export encode_ctxt;
export write_type;
export write_vstore;
export encode_def_id;
type abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>; type abbrev_map = map::HashMap<ty::t, tyencode::ty_abbrev>;
pub type encode_inlined_item = fn@(ecx: @encode_ctxt, pub type encode_inlined_item = fn@(ecx: @encode_ctxt,
@ -72,7 +59,7 @@ pub type encode_inlined_item = fn@(ecx: @encode_ctxt,
path: &[ast_map::path_elt], path: &[ast_map::path_elt],
ii: ast::inlined_item); ii: ast::inlined_item);
type encode_parms = { pub type encode_parms = {
diag: span_handler, diag: span_handler,
tcx: ty::ctxt, tcx: ty::ctxt,
reachable: HashMap<ast::node_id, ()>, reachable: HashMap<ast::node_id, ()>,
@ -97,7 +84,7 @@ type stats = {
mut n_inlines: uint mut n_inlines: uint
}; };
enum encode_ctxt = { pub enum encode_ctxt = {
diag: span_handler, diag: span_handler,
tcx: ty::ctxt, tcx: ty::ctxt,
stats: stats, stats: stats,
@ -111,7 +98,7 @@ enum encode_ctxt = {
type_abbrevs: abbrev_map type_abbrevs: abbrev_map
}; };
fn reachable(ecx: @encode_ctxt, id: node_id) -> bool { pub fn reachable(ecx: @encode_ctxt, id: node_id) -> bool {
ecx.reachable.contains_key(id) ecx.reachable.contains_key(id)
} }
@ -125,7 +112,7 @@ fn encode_impl_type_basename(ecx: @encode_ctxt, ebml_w: writer::Encoder,
ecx.tcx.sess.str_of(name)); ecx.tcx.sess.str_of(name));
} }
fn encode_def_id(ebml_w: writer::Encoder, id: def_id) { pub fn encode_def_id(ebml_w: writer::Encoder, id: def_id) {
ebml_w.wr_tagged_str(tag_def_id, def_to_str(id)); ebml_w.wr_tagged_str(tag_def_id, def_to_str(id));
} }
@ -177,7 +164,7 @@ fn encode_family(ebml_w: writer::Encoder, c: char) {
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn def_to_str(did: def_id) -> ~str { fmt!("%d:%d", did.crate, did.node) } pub fn def_to_str(did: def_id) -> ~str { fmt!("%d:%d", did.crate, did.node) }
fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt, fn encode_ty_type_param_bounds(ebml_w: writer::Encoder, ecx: @encode_ctxt,
params: @~[ty::param_bounds]) { params: @~[ty::param_bounds]) {
@ -208,7 +195,7 @@ fn encode_variant_id(ebml_w: writer::Encoder, vid: def_id) {
ebml_w.end_tag(); ebml_w.end_tag();
} }
fn write_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) { pub fn write_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
let ty_str_ctxt = @tyencode::ctxt { let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag, diag: ecx.diag,
ds: def_to_str, ds: def_to_str,
@ -218,8 +205,8 @@ fn write_type(ecx: @encode_ctxt, ebml_w: writer::Encoder, typ: ty::t) {
tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ); tyencode::enc_ty(ebml_w.writer, ty_str_ctxt, typ);
} }
fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Encoder, pub fn write_vstore(ecx: @encode_ctxt, ebml_w: writer::Encoder,
vstore: ty::vstore) { vstore: ty::vstore) {
let ty_str_ctxt = @tyencode::ctxt { let ty_str_ctxt = @tyencode::ctxt {
diag: ecx.diag, diag: ecx.diag,
ds: def_to_str, ds: def_to_str,
@ -1156,13 +1143,13 @@ fn encode_hash(ebml_w: writer::Encoder, hash: &str) {
} }
// NB: Increment this as you change the metadata encoding version. // NB: Increment this as you change the metadata encoding version.
const metadata_encoding_version : &[u8] = &[0x72, //'r' as u8, pub const metadata_encoding_version : &[u8] = &[0x72, //'r' as u8,
0x75, //'u' as u8, 0x75, //'u' as u8,
0x73, //'s' as u8, 0x73, //'s' as u8,
0x74, //'t' as u8, 0x74, //'t' as u8,
0, 0, 0, 1 ]; 0, 0, 0, 1 ];
fn encode_metadata(parms: encode_parms, crate: &crate) -> ~[u8] { pub fn encode_metadata(parms: encode_parms, crate: &crate) -> ~[u8] {
let wr = @io::BytesWriter(); let wr = @io::BytesWriter();
let stats = let stats =
{mut inline_bytes: 0, {mut inline_bytes: 0,
@ -1260,7 +1247,7 @@ fn encode_metadata(parms: encode_parms, crate: &crate) -> ~[u8] {
} }
// Get the encoded string for a type // Get the encoded string for a type
fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> ~str { pub fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> ~str {
let cx = @tyencode::ctxt { let cx = @tyencode::ctxt {
diag: tcx.diag, diag: tcx.diag,
ds: def_to_str, ds: def_to_str,

View file

@ -21,34 +21,23 @@ use core::result::Result;
use core::result; use core::result;
use core::str; use core::str;
export FileSearch; pub type pick<T> = fn(path: &Path) -> Option<T>;
export mk_filesearch;
export pick;
export pick_file;
export search;
export relative_target_lib_path;
export get_cargo_sysroot;
export get_cargo_root;
export get_cargo_root_nearest;
export libdir;
type pick<T> = fn(path: &Path) -> Option<T>; pub fn pick_file(file: Path, path: &Path) -> Option<Path> {
fn pick_file(file: Path, path: &Path) -> Option<Path> {
if path.file_path() == file { option::Some(copy *path) } if path.file_path() == file { option::Some(copy *path) }
else { option::None } else { option::None }
} }
trait FileSearch { pub trait FileSearch {
fn sysroot() -> Path; fn sysroot() -> Path;
fn lib_search_paths() -> ~[Path]; fn lib_search_paths() -> ~[Path];
fn get_target_lib_path() -> Path; fn get_target_lib_path() -> Path;
fn get_target_lib_file_path(file: &Path) -> Path; fn get_target_lib_file_path(file: &Path) -> Path;
} }
fn mk_filesearch(maybe_sysroot: Option<Path>, pub fn mk_filesearch(maybe_sysroot: Option<Path>,
target_triple: &str, target_triple: &str,
+addl_lib_search_paths: ~[Path]) -> FileSearch { +addl_lib_search_paths: ~[Path]) -> FileSearch {
type filesearch_impl = {sysroot: Path, type filesearch_impl = {sysroot: Path,
addl_lib_search_paths: ~[Path], addl_lib_search_paths: ~[Path],
target_triple: ~str}; target_triple: ~str};
@ -85,7 +74,7 @@ fn mk_filesearch(maybe_sysroot: Option<Path>,
target_triple: str::from_slice(target_triple)} as FileSearch target_triple: str::from_slice(target_triple)} as FileSearch
} }
fn search<T: Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> { pub fn search<T: Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> {
let mut rslt = None; let mut rslt = None;
for filesearch.lib_search_paths().each |lib_search_path| { for filesearch.lib_search_paths().each |lib_search_path| {
debug!("searching %s", lib_search_path.to_str()); debug!("searching %s", lib_search_path.to_str());
@ -105,7 +94,7 @@ fn search<T: Copy>(filesearch: FileSearch, pick: pick<T>) -> Option<T> {
return rslt; return rslt;
} }
fn relative_target_lib_path(target_triple: &str) -> Path { pub fn relative_target_lib_path(target_triple: &str) -> Path {
Path(libdir()).push_many([~"rustc", Path(libdir()).push_many([~"rustc",
str::from_slice(target_triple), str::from_slice(target_triple),
libdir()]) libdir()])
@ -130,11 +119,11 @@ fn get_sysroot(maybe_sysroot: Option<Path>) -> Path {
} }
} }
fn get_cargo_sysroot() -> Result<Path, ~str> { pub fn get_cargo_sysroot() -> Result<Path, ~str> {
result::Ok(get_or_default_sysroot().push_many([libdir(), ~"cargo"])) result::Ok(get_or_default_sysroot().push_many([libdir(), ~"cargo"]))
} }
fn get_cargo_root() -> Result<Path, ~str> { pub fn get_cargo_root() -> Result<Path, ~str> {
match os::getenv(~"CARGO_ROOT") { match os::getenv(~"CARGO_ROOT") {
Some(ref _p) => result::Ok(Path((*_p))), Some(ref _p) => result::Ok(Path((*_p))),
None => match os::homedir() { None => match os::homedir() {
@ -144,7 +133,7 @@ fn get_cargo_root() -> Result<Path, ~str> {
} }
} }
fn get_cargo_root_nearest() -> Result<Path, ~str> { pub fn get_cargo_root_nearest() -> Result<Path, ~str> {
do result::chain(get_cargo_root()) |p| { do result::chain(get_cargo_root()) |p| {
let cwd = os::getcwd(); let cwd = os::getcwd();
let cwd_cargo = cwd.push(".cargo"); let cwd_cargo = cwd.push(".cargo");
@ -184,7 +173,7 @@ fn get_cargo_lib_path_nearest() -> Result<Path, ~str> {
// The name of the directory rustc expects libraries to be located. // The name of the directory rustc expects libraries to be located.
// On Unix should be "lib", on windows "bin" // On Unix should be "lib", on windows "bin"
fn libdir() -> ~str { pub fn libdir() -> ~str {
let libdir = env!("CFG_LIBDIR"); let libdir = env!("CFG_LIBDIR");
if str::is_empty(libdir) { if str::is_empty(libdir) {
fail ~"rustc compiled without CFG_LIBDIR environment variable"; fail ~"rustc compiled without CFG_LIBDIR environment variable";

View file

@ -35,17 +35,7 @@ use core::str;
use core::uint; use core::uint;
use core::vec; use core::vec;
export os; pub enum os {
export os_macos, os_win32, os_linux, os_freebsd, os_android;
export ctxt;
export load_library_crate;
export list_file_metadata;
export note_linkage_attrs;
export crate_name_from_metas;
export metadata_matches;
export meta_section_name;
enum os {
os_macos, os_macos,
os_win32, os_win32,
os_linux, os_linux,
@ -53,7 +43,7 @@ enum os {
os_freebsd os_freebsd
} }
type ctxt = { pub type ctxt = {
diag: span_handler, diag: span_handler,
filesearch: FileSearch, filesearch: FileSearch,
span: span, span: span,
@ -65,7 +55,7 @@ type ctxt = {
intr: @ident_interner intr: @ident_interner
}; };
fn load_library_crate(cx: ctxt) -> {ident: ~str, data: @~[u8]} { pub fn load_library_crate(cx: ctxt) -> {ident: ~str, data: @~[u8]} {
match find_library_crate(cx) { match find_library_crate(cx) {
Some(ref t) => return (/*bad*/copy *t), Some(ref t) => return (/*bad*/copy *t),
None => { None => {
@ -152,7 +142,7 @@ fn find_library_crate_aux(cx: ctxt,
} }
} }
fn crate_name_from_metas(+metas: ~[@ast::meta_item]) -> ~str { pub fn crate_name_from_metas(+metas: ~[@ast::meta_item]) -> ~str {
let name_items = attr::find_meta_items_by_name(metas, ~"name"); let name_items = attr::find_meta_items_by_name(metas, ~"name");
match vec::last_opt(name_items) { match vec::last_opt(name_items) {
Some(i) => { Some(i) => {
@ -167,8 +157,8 @@ fn crate_name_from_metas(+metas: ~[@ast::meta_item]) -> ~str {
} }
} }
fn note_linkage_attrs(intr: @ident_interner, diag: span_handler, pub fn note_linkage_attrs(intr: @ident_interner, diag: span_handler,
attrs: ~[ast::attribute]) { attrs: ~[ast::attribute]) {
for attr::find_linkage_metas(attrs).each |mi| { for attr::find_linkage_metas(attrs).each |mi| {
diag.handler().note(fmt!("meta: %s", diag.handler().note(fmt!("meta: %s",
pprust::meta_item_to_str(*mi,intr))); pprust::meta_item_to_str(*mi,intr)));
@ -186,8 +176,8 @@ fn crate_matches(crate_data: @~[u8], +metas: ~[@ast::meta_item],
metadata_matches(linkage_metas, metas) metadata_matches(linkage_metas, metas)
} }
fn metadata_matches(extern_metas: ~[@ast::meta_item], pub fn metadata_matches(extern_metas: ~[@ast::meta_item],
local_metas: ~[@ast::meta_item]) -> bool { local_metas: ~[@ast::meta_item]) -> bool {
debug!("matching %u metadata requirements against %u items", debug!("matching %u metadata requirements against %u items",
vec::len(local_metas), vec::len(extern_metas)); vec::len(local_metas), vec::len(extern_metas));
@ -250,7 +240,7 @@ fn get_metadata_section(os: os,
} }
} }
fn meta_section_name(os: os) -> ~str { pub fn meta_section_name(os: os) -> ~str {
match os { match os {
os_macos => ~"__DATA,__note.rustc", os_macos => ~"__DATA,__note.rustc",
os_win32 => ~".note.rustc", os_win32 => ~".note.rustc",
@ -261,8 +251,8 @@ fn meta_section_name(os: os) -> ~str {
} }
// A diagnostic function for dumping crate metadata to an output stream // A diagnostic function for dumping crate metadata to an output stream
fn list_file_metadata(intr: @ident_interner, pub fn list_file_metadata(intr: @ident_interner,
os: os, path: &Path, out: io::Writer) { os: os, path: &Path, out: io::Writer) {
match get_metadata_section(os, path) { match get_metadata_section(os, path) {
option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out), option::Some(bytes) => decoder::list_crate_metadata(intr, bytes, out),
option::None => { option::None => {

View file

@ -8,37 +8,14 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#[legacy_exports]; pub mod common;
pub mod tyencode;
export encoder; pub mod tydecode;
export creader; pub mod encoder;
export cstore; pub mod decoder;
export csearch; pub mod creader;
export common; pub mod cstore;
export decoder; pub mod csearch;
export tyencode; pub mod loader;
export tydecode; pub mod filesearch;
export loader;
export filesearch;
#[legacy_exports]
mod common;
#[legacy_exports]
mod tyencode;
#[legacy_exports]
mod tydecode;
#[legacy_exports]
mod encoder;
#[legacy_exports]
mod decoder;
#[legacy_exports]
mod creader;
#[legacy_exports]
mod cstore;
#[legacy_exports]
mod csearch;
#[legacy_exports]
mod loader;
#[legacy_exports]
mod filesearch;

View file

@ -30,12 +30,6 @@ use syntax::ast_util;
use syntax::ast_util::respan; use syntax::ast_util::respan;
use std::map::HashMap; use std::map::HashMap;
export parse_state_from_data;
export parse_arg_data, parse_ty_data, parse_def_id, parse_ident;
export parse_bounds_data;
export pstate;
export DefIdSource, NominalType, TypeWithId, TypeParameter;
// Compact string representation for ty::t values. API ty_str & // Compact string representation for ty::t values. API ty_str &
// parse_from_str. Extra parameters are for converting to/from def_ids in the // parse_from_str. Extra parameters are for converting to/from def_ids in the
// data buffer. Whatever format you choose should not contain pipe characters. // data buffer. Whatever format you choose should not contain pipe characters.
@ -50,7 +44,7 @@ export DefIdSource, NominalType, TypeWithId, TypeParameter;
// def-id will depend on where it originated from. Therefore, the conversion // def-id will depend on where it originated from. Therefore, the conversion
// function is given an indicator of the source of the def-id. See // function is given an indicator of the source of the def-id. See
// astencode.rs for more information. // astencode.rs for more information.
enum DefIdSource { pub enum DefIdSource {
// Identifies a struct, trait, enum, etc. // Identifies a struct, trait, enum, etc.
NominalType, NominalType,
@ -62,7 +56,7 @@ enum DefIdSource {
} }
type conv_did = fn(source: DefIdSource, ast::def_id) -> ast::def_id; type conv_did = fn(source: DefIdSource, ast::def_id) -> ast::def_id;
type pstate = {data: @~[u8], crate: int, mut pos: uint, tcx: ty::ctxt}; pub type pstate = {data: @~[u8], crate: int, mut pos: uint, tcx: ty::ctxt};
fn peek(st: @pstate) -> char { fn peek(st: @pstate) -> char {
st.data[st.pos] as char st.data[st.pos] as char
@ -80,7 +74,7 @@ fn next_byte(st: @pstate) -> u8 {
return b; return b;
} }
fn parse_ident(st: @pstate, last: char) -> ast::ident { pub fn parse_ident(st: @pstate, last: char) -> ast::ident {
fn is_last(b: char, c: char) -> bool { return c == b; } fn is_last(b: char, c: char) -> bool { return c == b; }
return parse_ident_(st, |a| is_last(last, a) ); return parse_ident_(st, |a| is_last(last, a) );
} }
@ -94,21 +88,19 @@ fn parse_ident_(st: @pstate, is_last: fn@(char) -> bool) ->
return st.tcx.sess.ident_of(rslt); return st.tcx.sess.ident_of(rslt);
} }
fn parse_state_from_data(data: @~[u8], crate_num: int, pub fn parse_state_from_data(data: @~[u8], crate_num: int,
pos: uint, tcx: ty::ctxt) pos: uint, tcx: ty::ctxt) -> @pstate {
-> @pstate
{
@{data: data, crate: crate_num, mut pos: pos, tcx: tcx} @{data: data, crate: crate_num, mut pos: pos, tcx: tcx}
} }
fn parse_ty_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt, pub fn parse_ty_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
conv: conv_did) -> ty::t { conv: conv_did) -> ty::t {
let st = parse_state_from_data(data, crate_num, pos, tcx); let st = parse_state_from_data(data, crate_num, pos, tcx);
parse_ty(st, conv) parse_ty(st, conv)
} }
fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt, pub fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
conv: conv_did) -> ty::arg { conv: conv_did) -> ty::arg {
let st = parse_state_from_data(data, crate_num, pos, tcx); let st = parse_state_from_data(data, crate_num, pos, tcx);
parse_arg(st, conv) parse_arg(st, conv)
} }
@ -466,7 +458,7 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
// Rust metadata parsing // Rust metadata parsing
fn parse_def_id(buf: &[u8]) -> ast::def_id { pub fn parse_def_id(buf: &[u8]) -> ast::def_id {
let mut colon_idx = 0u; let mut colon_idx = 0u;
let len = vec::len(buf); let len = vec::len(buf);
while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; } while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; }
@ -491,10 +483,9 @@ fn parse_def_id(buf: &[u8]) -> ast::def_id {
ast::def_id { crate: crate_num, node: def_num } ast::def_id { crate: crate_num, node: def_num }
} }
fn parse_bounds_data(data: @~[u8], start: uint, pub fn parse_bounds_data(data: @~[u8], start: uint,
crate_num: int, tcx: ty::ctxt, conv: conv_did) crate_num: int, tcx: ty::ctxt, conv: conv_did)
-> @~[ty::param_bound] -> @~[ty::param_bound] {
{
let st = parse_state_from_data(data, crate_num, start, tcx); let st = parse_state_from_data(data, crate_num, start, tcx);
parse_bounds(st, conv) parse_bounds(st, conv)
} }

View file

@ -26,17 +26,7 @@ use syntax::diagnostic::span_handler;
use syntax::print::pprust::*; use syntax::print::pprust::*;
use middle::ty::Vid; use middle::ty::Vid;
export ctxt; pub struct ctxt {
export ty_abbrev;
export ac_no_abbrevs;
export ac_use_abbrevs;
export enc_ty;
export enc_bounds;
export enc_mode;
export enc_arg;
export enc_vstore;
struct ctxt {
diag: span_handler, diag: span_handler,
// Def -> str Callback: // Def -> str Callback:
ds: fn@(def_id) -> ~str, ds: fn@(def_id) -> ~str,
@ -49,9 +39,12 @@ struct ctxt {
// Compact string representation for ty.t values. API ty_str & parse_from_str. // Compact string representation for ty.t values. API ty_str & parse_from_str.
// Extra parameters are for converting to/from def_ids in the string rep. // Extra parameters are for converting to/from def_ids in the string rep.
// Whatever format you choose should not contain pipe characters. // Whatever format you choose should not contain pipe characters.
type ty_abbrev = {pos: uint, len: uint, s: @~str}; pub type ty_abbrev = {pos: uint, len: uint, s: @~str};
enum abbrev_ctxt { ac_no_abbrevs, ac_use_abbrevs(HashMap<ty::t, ty_abbrev>), } pub enum abbrev_ctxt {
ac_no_abbrevs,
ac_use_abbrevs(HashMap<ty::t, ty_abbrev>),
}
fn cx_uses_abbrevs(cx: @ctxt) -> bool { fn cx_uses_abbrevs(cx: @ctxt) -> bool {
match cx.abbrevs { match cx.abbrevs {
@ -60,7 +53,7 @@ fn cx_uses_abbrevs(cx: @ctxt) -> bool {
} }
} }
fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) { pub fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
match cx.abbrevs { match cx.abbrevs {
ac_no_abbrevs => { ac_no_abbrevs => {
let result_str = match cx.tcx.short_names_cache.find(t) { let result_str = match cx.tcx.short_names_cache.find(t) {
@ -197,7 +190,7 @@ fn enc_bound_region(w: io::Writer, cx: @ctxt, br: ty::bound_region) {
} }
} }
fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) { pub fn enc_vstore(w: io::Writer, cx: @ctxt, v: ty::vstore) {
w.write_char('/'); w.write_char('/');
match v { match v {
ty::vstore_fixed(u) => { ty::vstore_fixed(u) => {
@ -342,12 +335,12 @@ fn enc_proto(w: io::Writer, proto: Proto) {
} }
} }
fn enc_arg(w: io::Writer, cx: @ctxt, arg: ty::arg) { pub fn enc_arg(w: io::Writer, cx: @ctxt, arg: ty::arg) {
enc_mode(w, cx, arg.mode); enc_mode(w, cx, arg.mode);
enc_ty(w, cx, arg.ty); enc_ty(w, cx, arg.ty);
} }
fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) { pub fn enc_mode(w: io::Writer, cx: @ctxt, m: mode) {
match ty::resolved_mode(cx.tcx, m) { match ty::resolved_mode(cx.tcx, m) {
by_move => w.write_char('-'), by_move => w.write_char('-'),
by_copy => w.write_char('+'), by_copy => w.write_char('+'),
@ -386,7 +379,7 @@ fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) {
enc_ty(w, cx, ft.sig.output); enc_ty(w, cx, ft.sig.output);
} }
fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) { pub fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
for vec::each(*bs) |bound| { for vec::each(*bs) |bound| {
match *bound { match *bound {
ty::bound_owned => w.write_char('S'), ty::bound_owned => w.write_char('S'),