Skip to content

Commit ec22fe9

Browse files
marijnhunknown
authored and
unknown
committed
Add ty_obj case to pretty printer
1 parent aed40fb commit ec22fe9

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/comp/pretty/pprust.rs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,21 @@ impure fn print_type(ps s, @ast.ty ty) {
9191
commasep[ast.ty_field](s, fields, f);
9292
pclose(s);
9393
}
94-
case (ast.ty_fn(?proto,?inputs,?output)) {
95-
if (proto == ast.proto_fn) {wrd(s, "fn");}
96-
else {wrd(s, "iter");}
97-
popen(s);
98-
impure fn print_arg(ps s, ast.ty_arg input) {
99-
if (middle.ty.mode_is_alias(input.mode)) {wrd(s, "&");}
100-
print_type(s, input.ty);
101-
}
102-
auto f = print_arg;
103-
commasep[ast.ty_arg](s, inputs, f);
104-
pclose(s);
105-
if (output.node != ast.ty_nil) {
106-
space(s);
94+
case (ast.ty_obj(?methods)) {
95+
wrd1(s, "obj");
96+
bopen(s);
97+
for (ast.ty_method m in methods) {
10798
hbox(s);
108-
wrd1(s, "->");
109-
print_type(s, output);
99+
print_ty_fn(s, m.proto, option.some[str](m.ident),
100+
m.inputs, m.output);
101+
wrd(s, ";");
110102
end(s);
103+
line(s);
111104
}
105+
bclose(s);
106+
}
107+
case (ast.ty_fn(?proto,?inputs,?output)) {
108+
print_ty_fn(s, proto, option.none[str], inputs, output);
112109
}
113110
case (ast.ty_path(?path,_)) {
114111
print_path(s, path);
@@ -528,7 +525,6 @@ impure fn print_expr(ps s, @ast.expr expr) {
528525
}
529526
// TODO: extension 'body'
530527
}
531-
case (_) {wrd(s, "X");}
532528
}
533529
end(s);
534530
}
@@ -730,3 +726,28 @@ fn escape_str(str st, char to_escape) -> str {
730726
impure fn print_string(ps s, str st) {
731727
wrd(s, "\""); wrd(s, escape_str(st, '"')); wrd(s, "\"");
732728
}
729+
730+
impure fn print_ty_fn(ps s, ast.proto proto, option.t[str] id,
731+
vec[ast.ty_arg] inputs, @ast.ty output) {
732+
if (proto == ast.proto_fn) {wrd(s, "fn");}
733+
else {wrd(s, "iter");}
734+
alt (id) {
735+
case (option.some[str](?id)) {space(s); wrd(s, id);}
736+
case (_) {}
737+
}
738+
popen(s);
739+
impure fn print_arg(ps s, ast.ty_arg input) {
740+
if (middle.ty.mode_is_alias(input.mode)) {wrd(s, "&");}
741+
print_type(s, input.ty);
742+
}
743+
auto f = print_arg;
744+
commasep[ast.ty_arg](s, inputs, f);
745+
pclose(s);
746+
if (output.node != ast.ty_nil) {
747+
space(s);
748+
hbox(s);
749+
wrd1(s, "->");
750+
print_type(s, output);
751+
end(s);
752+
}
753+
}

0 commit comments

Comments
 (0)