Skip to content

Commit cce16ea

Browse files
committed
---
yaml --- r: 1192 b: refs/heads/master c: 2ec0b72 h: refs/heads/master v: v3
1 parent 6fd4cee commit cce16ea

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 7c8f99fdc1be0ed80095af160fffae2995cda83f
2+
refs/heads/master: 2ec0b724c46073d57973e076e222b047e36fee9d

trunk/src/comp/middle/ty.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,44 @@ fn is_fn_ty(@t fty) -> bool {
543543

544544
// Type accessors for AST nodes
545545

546+
// Given an item, returns the associated type as well as a list of the IDs of
547+
// its type parameters.
548+
fn item_ty(@ast.item it) -> tup(vec[ast.def_id], @t) {
549+
let vec[ast.ty_param] ty_params;
550+
auto result_ty;
551+
alt (it.node) {
552+
case (ast.item_const(_, _, _, _, ?ann)) {
553+
ty_params = vec();
554+
result_ty = ann_to_type(ann);
555+
}
556+
case (ast.item_fn(_, _, ?tps, _, ?ann)) {
557+
ty_params = tps;
558+
result_ty = ann_to_type(ann);
559+
}
560+
case (ast.item_mod(_, _, _)) {
561+
fail; // modules are typeless
562+
}
563+
case (ast.item_ty(_, _, ?tps, _, ?ann)) {
564+
ty_params = tps;
565+
result_ty = ann_to_type(ann);
566+
}
567+
case (ast.item_tag(_, _, ?tps, ?did)) {
568+
ty_params = tps;
569+
result_ty = plain_ty(ty_tag(did));
570+
}
571+
case (ast.item_obj(_, _, ?tps, _, ?ann)) {
572+
ty_params = tps;
573+
result_ty = ann_to_type(ann);
574+
}
575+
}
576+
577+
let vec[ast.def_id] ty_param_ids = vec();
578+
for (ast.ty_param tp in ty_params) {
579+
ty_param_ids += vec(tp.id);
580+
}
581+
ret tup(ty_param_ids, result_ty);
582+
}
583+
546584
fn stmt_ty(@ast.stmt s) -> @t {
547585
alt (s.node) {
548586
case (ast.stmt_expr(?e)) {

0 commit comments

Comments
 (0)