Skip to content

Commit a997132

Browse files
committed
Teach fold about ty_obj.
1 parent 0f914e6 commit a997132

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/comp/middle/fold.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ type ast_fold[ENV] =
5151
(fn(&ENV e, &span sp,
5252
vec[ast.ty_field] elts) -> @ty) fold_ty_rec,
5353

54+
(fn(&ENV e, &span sp,
55+
vec[ast.ty_method] meths) -> @ty) fold_ty_obj,
56+
5457
(fn(&ENV e, &span sp,
5558
vec[rec(ast.mode mode, @ty ty)] inputs,
5659
@ty output) -> @ty) fold_ty_fn,
@@ -291,6 +294,21 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
291294
ret fld.fold_ty_rec(env_, t.span, flds_);
292295
}
293296

297+
case (ast.ty_obj(?meths)) {
298+
let vec[ast.ty_method] meths_ = vec();
299+
for (ast.ty_method m in meths) {
300+
auto tfn = fld.fold_ty_fn(env_, t.span,
301+
m.inputs, m.output);
302+
alt (tfn.node) {
303+
case (ast.ty_fn(?ins, ?out)) {
304+
append[ast.ty_method]
305+
(meths_, rec(inputs=ins, output=out with m));
306+
}
307+
}
308+
}
309+
ret fld.fold_ty_obj(env_, t.span, meths_);
310+
}
311+
294312
case (ast.ty_path(?pth, ?ref_opt)) {
295313
let vec[ast.name] path = vec();
296314
for (ast.name n in pth) {
@@ -787,6 +805,11 @@ fn identity_fold_ty_rec[ENV](&ENV env, &span sp,
787805
ret @respan(sp, ast.ty_rec(elts));
788806
}
789807

808+
fn identity_fold_ty_obj[ENV](&ENV env, &span sp,
809+
vec[ast.ty_method] meths) -> @ty {
810+
ret @respan(sp, ast.ty_obj(meths));
811+
}
812+
790813
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
791814
vec[rec(ast.mode mode, @ty ty)] inputs,
792815
@ty output) -> @ty {
@@ -1091,6 +1114,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
10911114
fold_ty_vec = bind identity_fold_ty_vec[ENV](_,_,_),
10921115
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
10931116
fold_ty_rec = bind identity_fold_ty_rec[ENV](_,_,_),
1117+
fold_ty_obj = bind identity_fold_ty_obj[ENV](_,_,_),
10941118
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_),
10951119
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
10961120
fold_ty_mutable = bind identity_fold_ty_mutable[ENV](_,_,_),

0 commit comments

Comments
 (0)