pub fn type_needs_infer(t: t) -> bool {
tbox_has_flag(get(t), needs_infer)
}
-pub fn type_has_regions(t: t) -> bool {
- tbox_has_flag(get(t), has_regions)
-}
pub fn type_id(t: t) -> uint { get(t).id }
#[deriving(Clone, Eq, TotalEq, Hash)]
|t| { fldt(t); t }).fold_ty(ty)
}
-pub fn fold_regions(cx: &ctxt, ty: t, fldr: |r: Region| -> Region) -> t {
- ty_fold::RegionFolder::regions(cx, fldr).fold_ty(ty)
-}
-
// Substitute *only* type parameters. Used in trans where regions are erased.
pub fn subst_tps(tcx: &ctxt, tps: &[t], self_ty_opt: Option<t>, typ: t) -> t {
let mut subst = TpsSubst { tcx: tcx, self_ty_opt: self_ty_opt, tps: tps };
}
}
-pub fn type_is_sequence(ty: t) -> bool {
- match get(ty).sty {
- ty_str(_) | ty_vec(_, _) => true,
- _ => false
- }
-}
-
pub fn type_is_simd(cx: &ctxt, ty: t) -> bool {
match get(ty).sty {
ty_struct(did, _) => lookup_simd(cx, did),
}
}
-pub fn type_is_str(ty: t) -> bool {
- match get(ty).sty {
- ty_str(_) => true,
- _ => false
- }
-}
-
pub fn sequence_element_type(cx: &ctxt, ty: t) -> t {
match get(ty).sty {
ty_str(_) => return mk_mach_uint(ast::TyU8),
}
}
-pub fn get_element_type(ty: t, i: uint) -> t {
- match get(ty).sty {
- ty_tup(ref ts) => return *ts.get(i),
- _ => fail!("get_element_type called on invalid type")
- }
-}
-
-pub fn type_is_box(ty: t) -> bool {
- match get(ty).sty {
- ty_box(_) => return true,
- _ => return false
- }
-}
-
pub fn type_is_boxed(ty: t) -> bool {
match get(ty).sty {
ty_box(_) => true,
}
}
-pub fn type_is_slice(ty: t) -> bool {
- match get(ty).sty {
- ty_vec(_, vstore_slice(_)) | ty_str(vstore_slice(_)) => true,
- _ => return false
- }
-}
-
-pub fn type_is_unique_box(ty: t) -> bool {
- match get(ty).sty {
- ty_uniq(_) => return true,
- _ => return false
- }
-}
-
pub fn type_is_unsafe_ptr(ty: t) -> bool {
match get(ty).sty {
ty_ptr(_) => return true,
}
}
-pub fn type_is_vec(ty: t) -> bool {
- return match get(ty).sty {
- ty_vec(_, _) | ty_unboxed_vec(_) => true,
- ty_str(_) => true,
- _ => false
- };
-}
-
pub fn type_is_unique(ty: t) -> bool {
match get(ty).sty {
ty_uniq(_) | ty_vec(_, vstore_uniq) | ty_str(vstore_uniq) => true,
)
impl TypeContents {
- pub fn meets_bounds(&self, cx: &ctxt, bbs: BuiltinBounds) -> bool {
- bbs.iter().all(|bb| self.meets_bound(cx, bb))
- }
-
pub fn meets_bound(&self, cx: &ctxt, bb: BuiltinBound) -> bool {
match bb {
BoundStatic => self.is_static(cx),
v.iter().fold(TC::None, |tc, t| tc | f(t))
}
- pub fn inverse(&self) -> TypeContents {
- TypeContents { bits: !self.bits }
- }
-
pub fn has_dtor(&self) -> bool {
self.intersects(TC::OwnsDtor)
}
}
}
-pub fn type_has_dtor(cx: &ctxt, t: ty::t) -> bool {
- type_contents(cx, t).has_dtor()
-}
-
pub fn type_is_static(cx: &ctxt, t: ty::t) -> bool {
type_contents(cx, t).is_static(cx)
}
}
}
-pub fn type_is_enum(ty: t) -> bool {
- match get(ty).sty {
- ty_enum(_, _) => return true,
- _ => return false
- }
-}
-
// Is the type's representation size known at compile time?
+#[allow(dead_code)] // leaving in for DST
pub fn type_is_sized(cx: &ctxt, ty: ty::t) -> bool {
match get(ty).sty {
// FIXME(#6308) add trait, vec, str, etc here.
}
}
-pub fn type_param(ty: t) -> Option<uint> {
- match get(ty).sty {
- ty_param(p) => return Some(p.idx),
- _ => {/* fall through */ }
- }
- return None;
-}
-
// Returns the type and mutability of *t.
//
// The parameter `explicit` indicates if this is an *explicit* dereference.
}
}
-fn node_id_has_type_params(cx: &ctxt, id: ast::NodeId) -> bool {
- cx.node_type_substs.borrow().contains_key(&id)
-}
-
pub fn fn_is_variadic(fty: t) -> bool {
match get(fty).sty {
ty_bare_fn(ref f) => f.sig.variadic,
}
}
-pub fn ty_fn_purity(fty: t) -> ast::Purity {
- match get(fty).sty {
- ty_bare_fn(ref f) => f.purity,
- ty_closure(ref f) => f.purity,
- ref s => {
- fail!("ty_fn_purity() called on non-fn type: {:?}", s)
- }
- }
-}
-
pub fn ty_fn_ret(fty: t) -> t {
match get(fty).sty {
ty_bare_fn(ref f) => f.sig.output,
}
}
-pub fn ty_vstore(ty: t) -> vstore {
- match get(ty).sty {
- ty_vec(_, vstore) => vstore,
- ty_str(vstore) => vstore,
- ref s => fail!("ty_vstore() called on invalid sty: {:?}", s)
- }
-}
-
pub fn ty_region(tcx: &ctxt,
span: Span,
ty: t) -> Region {
}
}
-pub fn replace_fn_sig(cx: &ctxt, fsty: &sty, new_sig: FnSig) -> t {
- match *fsty {
- ty_bare_fn(ref f) => mk_bare_fn(cx, BareFnTy {sig: new_sig, ..*f}),
- ty_closure(ref f) => mk_closure(cx, ClosureTy {sig: new_sig, ..**f}),
- ref s => {
- cx.sess.bug(
- format!("ty_fn_sig() called on non-fn type: {:?}", s));
- }
- }
-}
-
-pub fn replace_closure_return_type(tcx: &ctxt, fn_type: t, ret_type: t) -> t {
- /*!
- *
- * Returns a new function type based on `fn_type` but returning a value of
- * type `ret_type` instead. */
-
- match ty::get(fn_type).sty {
- ty::ty_closure(ref fty) => {
- ty::mk_closure(tcx, ClosureTy {
- sig: FnSig {output: ret_type, ..fty.sig.clone()},
- ..(**fty).clone()
- })
- }
- _ => {
- tcx.sess.bug(format!(
- "replace_fn_ret() invoked with non-fn-type: {}",
- ty_to_str(tcx, fn_type)));
- }
- }
-}
-
-// Returns a vec of all the input and output types of fty.
-pub fn tys_in_fn_sig(sig: &FnSig) -> Vec<t> {
- sig.inputs.iter().map(|a| *a).collect::<Vec<_>>().append_one(sig.output)
-}
-
-// Type accessors for AST nodes
-pub fn block_ty(cx: &ctxt, b: &ast::Block) -> t {
- return node_id_to_type(cx, b.id);
-}
-
-
// Returns the type of a pattern as a monotype. Like @expr_ty, this function
// doesn't provide type parameter substitutions.
pub fn pat_ty(cx: &ctxt, pat: &ast::Pat) -> t {
pub ty: t
}
+#[allow(dead_code)] // this may be useful?
pub fn expr_ty_params_and_ty(cx: &ctxt,
expr: &ast::Expr)
-> ParamsTy {
}
}
-pub fn expr_has_ty_params(cx: &ctxt, expr: &ast::Expr) -> bool {
- return node_id_has_type_params(cx, expr.id);
-}
-
pub fn method_call_type_param_defs(tcx: &ctxt, origin: typeck::MethodOrigin)
-> Rc<Vec<TypeParameterDef>> {
match origin {
}
}
-pub fn field_idx(name: ast::Name, fields: &[field]) -> Option<uint> {
- let mut i = 0u;
- for f in fields.iter() { if f.ident.name == name { return Some(i); } i += 1u; }
- return None;
-}
-
pub fn field_idx_strict(tcx: &ctxt, name: ast::Name, fields: &[field])
-> uint {
let mut i = 0u;
}
}
-pub fn def_has_ty_params(def: ast::Def) -> bool {
- match def {
- ast::DefFn(_, _) | ast::DefVariant(_, _, _) | ast::DefStruct(_)
- => true,
- _ => false
- }
-}
-
pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
cx.provided_method_sources.borrow().find(&id).map(|x| *x)
}
pub fn ty_to_def_id(ty: t) -> Option<ast::DefId> {
match get(ty).sty {
- ty_trait(~TyTrait { def_id: id, .. }) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
- _ => None
+ ty_trait(~TyTrait { def_id: id, .. }) | ty_struct(id, _) | ty_enum(id, _) => Some(id),
+ _ => None
}
}
}
}
-pub fn lookup_struct_field(cx: &ctxt,
- parent: ast::DefId,
- field_id: ast::DefId)
- -> field_ty {
- let r = lookup_struct_fields(cx, parent);
- match r.iter().find(
- |f| f.id.node == field_id.node) {
- Some(t) => *t,
- None => cx.sess.bug("struct ID not found in parent's fields")
- }
-}
-
fn struct_field_tys(fields: &[StructField]) -> Vec<field_ty> {
fields.iter().map(|field| {
match field.node.kind {
return tbl[tycat(cx, ty)][opcat(op)];
}
-pub fn ty_params_to_tys(tcx: &ctxt, generics: &ast::Generics) -> Vec<t> {
- Vec::from_fn(generics.ty_params.len(), |i| {
- let id = generics.ty_params.get(i).id;
- ty::mk_param(tcx, i, ast_util::local_def(id))
- })
-}
-
/// Returns an equivalent type with all the typedefs and self regions removed.
pub fn normalize_ty(cx: &ctxt, t: t) -> t {
let u = TypeNormalizer(cx).fold_ty(t);
return true;
}
-pub fn count_traits_and_supertraits(tcx: &ctxt,
- type_param_defs: &[TypeParameterDef]) -> uint {
- let mut total = 0;
- for type_param_def in type_param_defs.iter() {
- each_bound_trait_and_supertraits(
- tcx, type_param_def.bounds.trait_bounds.as_slice(), |_| {
- total += 1;
- true
- });
- }
- return total;
-}
-
pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, ~str> {
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
tcx.intrinsic_defs.borrow().find_copy(&tydesc_lang_item)
UniqueImmBorrow => "uniquely immutable",
}
}
-
- pub fn to_short_str(&self) -> &'static str {
- match *self {
- MutBorrow => "mut",
- ImmBorrow => "imm",
- UniqueImmBorrow => "own",
- }
- }
}