- }
- }
- fn method_to_str(cx: ctxt, m: ty::Method) -> ~str {
- bare_fn_to_str(cx,
- m.fty.purity,
- m.fty.abis,
- Some(m.ident),
- &m.fty.sig) + ";"
- }
- fn field_to_str(cx: ctxt, f: field) -> ~str {
- return fmt!("%s: %s", cx.sess.str_of(f.ident), mt_to_str(cx, &f.mt));
- }
-
- // if there is an id, print that instead of the structural type:
- /*for ty::type_def_id(typ).iter().advance |def_id| {
- // note that this typedef cannot have type parameters
- return ast_map::path_to_str(ty::item_path(cx, *def_id),
- cx.sess.intr());
- }*/
-
- // pretty print the structural type representation:
- return match ty::get(typ).sty {
- ty_nil => ~"()",
- ty_bot => ~"!",
- ty_bool => ~"bool",
- ty_int(ast::ty_i) => ~"int",
- ty_int(ast::ty_char) => ~"char",
- ty_int(t) => ast_util::int_ty_to_str(t),
- ty_uint(ast::ty_u) => ~"uint",
- ty_uint(t) => ast_util::uint_ty_to_str(t),
- ty_float(ast::ty_f) => ~"float",
- ty_float(t) => ast_util::float_ty_to_str(t),
- ty_box(ref tm) => ~"@" + mt_to_str(cx, tm),
- ty_uniq(ref tm) => ~"~" + mt_to_str(cx, tm),
- ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
- ty_rptr(r, ref tm) => {
- region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
- }
- ty_unboxed_vec(ref tm) => { fmt!("unboxed_vec<%s>", mt_to_str(cx, tm)) }
- ty_type => ~"type",
- ty_tup(ref elems) => {
- let strs = elems.map(|elem| ty_to_str(cx, *elem));
- ~"(" + strs.connect(",") + ")"
- }
- ty_closure(ref f) => {
- closure_to_str(cx, f)
- }
- ty_bare_fn(ref f) => {
- bare_fn_to_str(cx, f.purity, f.abis, None, &f.sig)
- }
- ty_infer(infer_ty) => infer_ty.to_str(),
- ty_err => ~"[type error]",
- ty_param(param_ty {idx: id, def_id: did}) => {
- let mut parm = (('T' as uint) + id) as char;
- if (parm as uint) > ('Z' as uint) {
- parm = (parm as uint - 26) as char;
- }
-
- if cx.sess.verbose() {
- fmt!("%c:%?", parm, did)
- } else {
- fmt!("%c", parm)
- }
- }
- ty_self(*) => ~"Self",
- ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
- let path = ty::item_path(cx, did);
- let base = ast_map::path_to_str(path, cx.sess.intr());
- parameterized(cx, base, substs.self_r, substs.tps)
- }
- ty_trait(did, ref substs, s, mutbl, ref bounds) => {
- let path = ty::item_path(cx, did);
- let base = ast_map::path_to_str(path, cx.sess.intr());
- let ty = parameterized(cx, base, substs.self_r, substs.tps);
- let bound_sep = if bounds.is_empty() { "" } else { ":" };
- let bound_str = bounds.repr(cx);
- fmt!("%s%s%s%s%s", trait_store_to_str(cx, s), mutability_to_str(mutbl), ty,
- bound_sep, bound_str)
- }
- ty_evec(ref mt, vs) => {
- vstore_ty_to_str(cx, mt, vs)
- }
- ty_estr(vs) => fmt!("%s%s", vstore_to_str(cx, vs), "str"),
- ty_opaque_box => ~"@?",
- ty_opaque_closure_ptr(ast::BorrowedSigil) => ~"&closure",
- ty_opaque_closure_ptr(ast::ManagedSigil) => ~"@closure",
- ty_opaque_closure_ptr(ast::OwnedSigil) => ~"~closure",
- }
-}
-
-pub fn parameterized(cx: ctxt,
- base: &str,
- self_r: Option<ty::Region>,
- tps: &[ty::t]) -> ~str {
-
- let mut strs = ~[];
- match self_r {
- None => (),
- Some(r) => {
- strs.push(region_to_str(cx, "", false, r))
- }
- };