Skip to content

Commit 771d76e

Browse files
committed
Add type accessors for fn types.
1 parent 0040a31 commit 771d76e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/comp/middle/ty.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,29 @@ fn count_ty_params(@t ty) -> uint {
518518
ret _vec.len[ast.def_id](*param_ids);
519519
}
520520

521+
// Type accessors for substructures of types
522+
523+
fn ty_fn_args(@t fty) -> vec[arg] {
524+
alt (fty.struct) {
525+
case (ty.ty_fn(?a, _)) { ret a; }
526+
}
527+
}
528+
529+
fn ty_fn_ret(@t fty) -> @t {
530+
alt (fty.struct) {
531+
case (ty.ty_fn(_, ?r)) { ret r; }
532+
}
533+
}
534+
535+
fn is_fn_ty(@t fty) -> bool {
536+
alt (fty.struct) {
537+
case (ty.ty_fn(_, _)) { ret true; }
538+
case (_) { ret false; }
539+
}
540+
ret false;
541+
}
542+
543+
521544
// Type accessors for AST nodes
522545

523546
fn stmt_ty(@ast.stmt s) -> @t {
@@ -552,6 +575,7 @@ fn expr_ty(@ast.expr expr) -> @t {
552575
case (ast.expr_vec(_, ?ann)) { ret ann_to_type(ann); }
553576
case (ast.expr_tup(_, ?ann)) { ret ann_to_type(ann); }
554577
case (ast.expr_rec(_, ?ann)) { ret ann_to_type(ann); }
578+
case (ast.expr_bind(_, _, ?ann)) { ret ann_to_type(ann); }
555579
case (ast.expr_call(_, _, ?ann)) { ret ann_to_type(ann); }
556580
case (ast.expr_binary(_, _, _, ?ann)) { ret ann_to_type(ann); }
557581
case (ast.expr_unary(_, _, ?ann)) { ret ann_to_type(ann); }

0 commit comments

Comments
 (0)