use middle::subst::VecPerParamSpace;
use middle::ty::{self, ToPredicate, Ty, HasTypeFlags};
+use rbml;
use std::str;
use syntax::abi;
use syntax::ast;
}
impl<'a,'tcx> TyDecoder<'a,'tcx> {
+ pub fn with_doc(tcx: &'a ty::ctxt<'tcx>,
+ crate_num: ast::CrateNum,
+ doc: rbml::Doc<'a>,
+ conv: DefIdConvert<'a>)
+ -> TyDecoder<'a,'tcx> {
+ TyDecoder::new(doc.data, crate_num, doc.start, tcx, conv)
+ }
+
pub fn new(data: &'a [u8],
crate_num: ast::CrateNum,
pos: usize,
r
}
- fn parse_substs(&mut self) -> subst::Substs<'tcx> {
+ pub fn parse_substs(&mut self) -> subst::Substs<'tcx> {
let regions = self.parse_region_substs();
let types = self.parse_vec_per_param_space(|this| this.parse_ty());
subst::Substs { types: types, regions: regions }
result
}
- fn parse_trait_ref(&mut self) -> ty::TraitRef<'tcx> {
+ pub fn parse_trait_ref(&mut self) -> ty::TraitRef<'tcx> {
let def = self.parse_def(NominalType);
let substs = self.tcx.mk_substs(self.parse_substs());
ty::TraitRef {def_id: def, substs: substs}
}
- fn parse_ty(&mut self) -> Ty<'tcx> {
+ pub fn parse_ty(&mut self) -> Ty<'tcx> {
let tcx = self.tcx;
match self.next() {
'b' => return tcx.types.bool,
abi::lookup(&abi_str[..]).expect(abi_str)
}
- fn parse_closure_ty(&mut self) -> ty::ClosureTy<'tcx> {
+ pub fn parse_closure_ty(&mut self) -> ty::ClosureTy<'tcx> {
let unsafety = parse_unsafety(self.next());
let sig = self.parse_sig();
let abi = self.parse_abi_set();
variadic: variadic})
}
- fn parse_predicate(&mut self) -> ty::Predicate<'tcx> {
+ pub fn parse_predicate(&mut self) -> ty::Predicate<'tcx> {
match self.next() {
't' => ty::Binder(self.parse_trait_ref()).to_predicate(),
'e' => ty::Binder(ty::EquatePredicate(self.parse_ty(),
}
}
- fn parse_type_param_def(&mut self) -> ty::TypeParameterDef<'tcx> {
+ pub fn parse_type_param_def(&mut self) -> ty::TypeParameterDef<'tcx> {
let name = self.parse_name(':');
let def_id = self.parse_def(NominalType);
let space = self.parse_param_space();
}
}
- fn parse_existential_bounds(&mut self) -> ty::ExistentialBounds<'tcx> {
+ pub fn parse_existential_bounds(&mut self) -> ty::ExistentialBounds<'tcx> {
let builtin_bounds = self.parse_builtin_bounds();
let region_bound = self.parse_region();
let mut projection_bounds = Vec::new();
}
trait rbml_decoder_decoder_helpers<'tcx> {
+ fn read_ty_encoded<'a, 'b, F, R>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>,
+ f: F) -> R
+ where F: for<'x> FnOnce(&mut tydecode::TyDecoder<'x, 'tcx>) -> R;
+
fn read_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Ty<'tcx>;
fn read_tys<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Vec<Ty<'tcx>>;
fn read_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
fn read_ty_nodcx(&mut self,
- tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) -> Ty<'tcx> {
+ tcx: &ty::ctxt<'tcx>,
+ cdata: &cstore::crate_metadata)
+ -> Ty<'tcx> {
self.read_opaque(|_, doc| {
- Ok(tydecode::parse_ty_data(
- doc.data,
- cdata.cnum,
- doc.start,
- tcx,
- |_, id| decoder::translate_def_id(cdata, id)))
+ Ok(
+ tydecode::TyDecoder::with_doc(tcx, cdata.cnum, doc,
+ &mut |_, id| decoder::translate_def_id(cdata, id))
+ .parse_ty())
}).unwrap()
}
-> subst::Substs<'tcx>
{
self.read_opaque(|_, doc| {
- Ok(tydecode::parse_substs_data(
- doc.data,
- cdata.cnum,
- doc.start,
- tcx,
- |_, id| decoder::translate_def_id(cdata, id)))
+ Ok(
+ tydecode::TyDecoder::with_doc(tcx, cdata.cnum, doc,
+ &mut |_, id| decoder::translate_def_id(cdata, id))
+ .parse_substs())
}).unwrap()
}
- fn read_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) -> Ty<'tcx> {
- // Note: regions types embed local node ids. In principle, we
- // should translate these node ids into the new decode
- // context. However, we do not bother, because region types
- // are not used during trans.
-
+ fn read_ty_encoded<'b, 'c, F, R>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>, op: F) -> R
+ where F: for<'x> FnOnce(&mut tydecode::TyDecoder<'x,'tcx>) -> R
+ {
return self.read_opaque(|this, doc| {
- debug!("read_ty({})", type_string(doc));
-
- let ty = tydecode::parse_ty_data(
- doc.data,
- dcx.cdata.cnum,
- doc.start,
- dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a));
-
- Ok(ty)
+ debug!("read_ty_encoded({})", type_string(doc));
+ Ok(op(
+ &mut tydecode::TyDecoder::with_doc(
+ dcx.tcx, dcx.cdata.cnum, doc,
+ &mut |s, a| this.convert_def_id(dcx, s, a))))
}).unwrap();
fn type_string(doc: rbml::Doc) -> String {
}
}
+ fn read_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) -> Ty<'tcx> {
+ // Note: regions types embed local node ids. In principle, we
+ // should translate these node ids into the new decode
+ // context. However, we do not bother, because region types
+ // are not used during trans.
+
+ return self.read_ty_encoded(dcx, |decoder| decoder.parse_ty());
+ }
+
fn read_tys<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> Vec<Ty<'tcx>> {
self.read_to_vec(|this| Ok(this.read_ty(dcx))).unwrap().into_iter().collect()
fn read_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::TraitRef<'tcx> {
- self.read_opaque(|this, doc| {
- let ty = tydecode::parse_trait_ref_data(
- doc.data,
- dcx.cdata.cnum,
- doc.start,
- dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a));
- Ok(ty)
- }).unwrap()
+ self.read_ty_encoded(dcx, |decoder| decoder.parse_trait_ref())
}
fn read_poly_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::PolyTraitRef<'tcx> {
- ty::Binder(self.read_opaque(|this, doc| {
- let ty = tydecode::parse_trait_ref_data(
- doc.data,
- dcx.cdata.cnum,
- doc.start,
- dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a));
- Ok(ty)
- }).unwrap())
+ ty::Binder(self.read_ty_encoded(dcx, |decoder| decoder.parse_trait_ref()))
}
fn read_type_param_def<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::TypeParameterDef<'tcx> {
- self.read_opaque(|this, doc| {
- Ok(tydecode::parse_type_param_def_data(
- doc.data,
- doc.start,
- dcx.cdata.cnum,
- dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a)))
- }).unwrap()
+ self.read_ty_encoded(dcx, |decoder| decoder.parse_type_param_def())
}
fn read_predicate<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::Predicate<'tcx>
{
- self.read_opaque(|this, doc| {
- Ok(tydecode::parse_predicate_data(doc.data, doc.start, dcx.cdata.cnum, dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a)))
- }).unwrap()
+ self.read_ty_encoded(dcx, |decoder| decoder.parse_predicate())
}
fn read_type_scheme<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
fn read_existential_bounds<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::ExistentialBounds<'tcx>
{
- self.read_opaque(|this, doc| {
- Ok(tydecode::parse_existential_bounds_data(doc.data,
- dcx.cdata.cnum,
- doc.start,
- dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a)))
- }).unwrap()
+ self.read_ty_encoded(dcx, |decoder| decoder.parse_existential_bounds())
}
fn read_substs<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
fn read_closure_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
-> ty::ClosureTy<'tcx>
{
- self.read_opaque(|this, doc| {
- Ok(tydecode::parse_ty_closure_data(
- doc.data,
- dcx.cdata.cnum,
- doc.start,
- dcx.tcx,
- |s, a| this.convert_def_id(dcx, s, a)))
- }).unwrap()
+ self.read_ty_encoded(dcx, |decoder| decoder.parse_closure_ty())
}
/// Converts a def-id that appears in a type. The correct