use metadata::cstore;
use metadata::encoder::def_to_u64;
use metadata::inline::InlinedItem;
-use metadata::tydecode::{parse_ty_data, parse_region_data,
- parse_type_param_def_data, parse_bare_fn_ty_data,
- parse_trait_ref_data, parse_predicate_data};
+use metadata::tydecode::TyDecoder;
use middle::def;
use middle::lang_items;
use middle::subst;
fn doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Ty<'tcx> {
let tp = reader::get_doc(doc, tag_items_data_item_type);
- parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
- |_, did| translate_def_id(cdata, did))
+ TyDecoder::with_doc(tcx, cdata.cnum, tp,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_ty()
}
fn maybe_doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Option<Ty<'tcx>> {
reader::maybe_get_doc(doc, tag_items_data_item_type).map(|tp| {
- parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
- |_, did| translate_def_id(cdata, did))
+ TyDecoder::with_doc(tcx, cdata.cnum, tp,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_ty()
})
}
fn doc_method_fty<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>,
cdata: Cmd) -> ty::BareFnTy<'tcx> {
let tp = reader::get_doc(doc, tag_item_method_fty);
- parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
- |_, did| translate_def_id(cdata, did))
+ TyDecoder::with_doc(tcx, cdata.cnum, tp,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_bare_fn_ty()
}
pub fn item_type<'tcx>(_item_id: ast::DefId, item: rbml::Doc,
fn doc_trait_ref<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd)
-> ty::TraitRef<'tcx> {
- parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
- |_, did| translate_def_id(cdata, did))
+ TyDecoder::with_doc(tcx, cdata.cnum, doc,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_trait_ref()
}
fn item_trait_ref<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd)
let mut types = subst::VecPerParamSpace::empty();
for p in reader::tagged_docs(doc, tag_type_param_def) {
- let bd = parse_type_param_def_data(
- p.data, p.start, cdata.cnum, tcx,
- |_, did| translate_def_id(cdata, did));
+ let bd =
+ TyDecoder::with_doc(tcx, cdata.cnum, p,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_type_param_def();
types.push(bd.space, bd);
}
let index = reader::doc_as_u64(doc) as u32;
let bounds = reader::tagged_docs(rp_doc, tag_items_data_region).map(|p| {
- parse_region_data(p.data, cdata.cnum, p.start, tcx,
- |_, did| translate_def_id(cdata, did))
+ TyDecoder::with_doc(tcx, cdata.cnum, p,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_region()
}).collect();
regions.push(space, ty::RegionParameterDef { name: name,
let space = subst::ParamSpace::from_uint(reader::doc_as_u8(space_doc) as usize);
let data_doc = reader::get_doc(predicate_doc, tag_predicate_data);
- let data = parse_predicate_data(data_doc.data, data_doc.start, cdata.cnum, tcx,
- |_, did| translate_def_id(cdata, did));
+ let data =
+ TyDecoder::with_doc(tcx, cdata.cnum, data_doc,
+ &mut |_, did| translate_def_id(cdata, did))
+ .parse_predicate();
predicates.push(space, data);
}
ClosureSource
}
-pub fn parse_ty_closure_data<'tcx, F>(data: &[u8],
- crate_num: ast::CrateNum,
- pos: usize,
- tcx: &ty::ctxt<'tcx>,
- mut conv: F)
- -> ty::ClosureTy<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_closure_ty()
-}
-
-pub fn parse_ty_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: usize,
- tcx: &ty::ctxt<'tcx>, mut conv: F) -> Ty<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- debug!("parse_ty_data {}", data_log_string(data, pos));
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_ty()
-}
-
-pub fn parse_region_data<F>(data: &[u8], crate_num: ast::CrateNum, pos: usize, tcx: &ty::ctxt,
- mut conv: F) -> ty::Region where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- debug!("parse_region_data {}", data_log_string(data, pos));
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_region()
-}
-
-pub fn parse_bare_fn_ty_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: usize,
- tcx: &ty::ctxt<'tcx>, mut conv: F)
- -> ty::BareFnTy<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- debug!("parse_bare_fn_ty_data {}", data_log_string(data, pos));
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_bare_fn_ty()
-}
-
-pub fn parse_trait_ref_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: usize,
- tcx: &ty::ctxt<'tcx>, mut conv: F)
- -> ty::TraitRef<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- debug!("parse_trait_ref_data {}", data_log_string(data, pos));
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_trait_ref()
-}
-
-pub fn parse_substs_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum, pos: usize,
- tcx: &ty::ctxt<'tcx>, mut conv: F) -> subst::Substs<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- debug!("parse_substs_data{}", data_log_string(data, pos));
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_substs()
-}
-
-pub fn parse_existential_bounds_data<'tcx, F>(data: &[u8], crate_num: ast::CrateNum,
- pos: usize, tcx: &ty::ctxt<'tcx>, mut conv: F)
- -> ty::ExistentialBounds<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_existential_bounds()
-}
-
-pub fn parse_builtin_bounds_data<F>(data: &[u8], crate_num: ast::CrateNum,
- pos: usize, tcx: &ty::ctxt, mut conv: F)
- -> ty::BuiltinBounds where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- let mut st = TyDecoder::new(data, crate_num, pos, tcx, &mut conv);
- st.parse_builtin_bounds()
-}
-
-pub fn parse_type_param_def_data<'tcx, F>(data: &[u8], start: usize,
- crate_num: ast::CrateNum, tcx: &ty::ctxt<'tcx>,
- mut conv: F) -> ty::TypeParameterDef<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- let mut st = TyDecoder::new(data, crate_num, start, tcx, &mut conv);
- st.parse_type_param_def()
-}
-
-pub fn parse_predicate_data<'tcx, F>(data: &[u8],
- start: usize,
- crate_num: ast::CrateNum,
- tcx: &ty::ctxt<'tcx>,
- mut conv: F)
- -> ty::Predicate<'tcx> where
- F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
-{
- let mut st = TyDecoder::new(data, crate_num, start, tcx, &mut conv);
- st.parse_predicate()
-}
-
pub type DefIdConvert<'a> = &'a mut FnMut(DefIdSource, ast::DefId) -> ast::DefId;
pub struct TyDecoder<'a, 'tcx: 'a> {
}
}
- fn parse_region(&mut self) -> ty::Region {
+ pub fn parse_region(&mut self) -> ty::Region {
match self.next() {
'b' => {
assert_eq!(self.next(), '[');
}
}
- fn parse_bare_fn_ty(&mut self) -> ty::BareFnTy<'tcx> {
+ pub fn parse_bare_fn_ty(&mut self) -> ty::BareFnTy<'tcx> {
let unsafety = parse_unsafety(self.next());
let abi = self.parse_abi_set();
let sig = self.parse_sig();
}
}
-fn data_log_string(data: &[u8], pos: usize) -> String {
- let mut buf = String::new();
- buf.push_str("<<");
- for i in pos..data.len() {
- let c = data[i];
- if c > 0x20 && c <= 0x7F {
- buf.push(c as char);
- } else {
- buf.push('.');
- }
- }
- buf.push_str(">>");
- buf
-}
-
// Rust metadata parsing
fn parse_defid(buf: &[u8]) -> ast::DefId {
let mut colon_idx = 0;