Add ty_obj case to pretty printer

This commit is contained in:
Marijn Haverbeke 2011-03-09 12:28:18 +01:00 committed by unknown
parent aed40fbcd8
commit ec22fe9733

View File

@ -91,24 +91,21 @@ impure fn print_type(ps s, @ast.ty ty) {
commasep[ast.ty_field](s, fields, f);
pclose(s);
}
case (ast.ty_fn(?proto,?inputs,?output)) {
if (proto == ast.proto_fn) {wrd(s, "fn");}
else {wrd(s, "iter");}
popen(s);
impure fn print_arg(ps s, ast.ty_arg input) {
if (middle.ty.mode_is_alias(input.mode)) {wrd(s, "&");}
print_type(s, input.ty);
}
auto f = print_arg;
commasep[ast.ty_arg](s, inputs, f);
pclose(s);
if (output.node != ast.ty_nil) {
space(s);
case (ast.ty_obj(?methods)) {
wrd1(s, "obj");
bopen(s);
for (ast.ty_method m in methods) {
hbox(s);
wrd1(s, "->");
print_type(s, output);
print_ty_fn(s, m.proto, option.some[str](m.ident),
m.inputs, m.output);
wrd(s, ";");
end(s);
line(s);
}
bclose(s);
}
case (ast.ty_fn(?proto,?inputs,?output)) {
print_ty_fn(s, proto, option.none[str], inputs, output);
}
case (ast.ty_path(?path,_)) {
print_path(s, path);
@ -528,7 +525,6 @@ impure fn print_expr(ps s, @ast.expr expr) {
}
// TODO: extension 'body'
}
case (_) {wrd(s, "X");}
}
end(s);
}
@ -730,3 +726,28 @@ fn escape_str(str st, char to_escape) -> str {
impure fn print_string(ps s, str st) {
wrd(s, "\""); wrd(s, escape_str(st, '"')); wrd(s, "\"");
}
impure fn print_ty_fn(ps s, ast.proto proto, option.t[str] id,
vec[ast.ty_arg] inputs, @ast.ty output) {
if (proto == ast.proto_fn) {wrd(s, "fn");}
else {wrd(s, "iter");}
alt (id) {
case (option.some[str](?id)) {space(s); wrd(s, id);}
case (_) {}
}
popen(s);
impure fn print_arg(ps s, ast.ty_arg input) {
if (middle.ty.mode_is_alias(input.mode)) {wrd(s, "&");}
print_type(s, input.ty);
}
auto f = print_arg;
commasep[ast.ty_arg](s, inputs, f);
pclose(s);
if (output.node != ast.ty_nil) {
space(s);
hbox(s);
wrd1(s, "->");
print_type(s, output);
end(s);
}
}