diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-08-07 16:08:09 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-08-07 16:09:08 -0700 |
| commit | 0f711e72f72cf69166902fe9df9c5063e5aa14ff (patch) | |
| tree | 6025c53bc18b4c615caf042dbc2d9fe68b7f1c03 /src/libsyntax/print | |
| parent | 1f0574e8f0d304afa6931f4fa1019c80a708b94d (diff) | |
| download | rust-0f711e72f72cf69166902fe9df9c5063e5aa14ff.tar.gz rust-0f711e72f72cf69166902fe9df9c5063e5aa14ff.zip | |
libsyntax: Break struct definitions out of classes internally in a few more places
Diffstat (limited to 'src/libsyntax/print')
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 145 |
1 files changed, 75 insertions, 70 deletions
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c4bb680c220..db62637a673 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -532,76 +532,8 @@ fn print_item(s: ps, &&item: @ast::item) { } ast::item_class(struct_def, tps) => { head(s, ~"class"); - word_nbsp(s, *item.ident); - print_type_params(s, tps); - if vec::len(struct_def.traits) != 0u { - word_space(s, ~":"); - commasep(s, inconsistent, struct_def.traits, |s, p| - print_path(s, p.path, false)); - } - bopen(s); - hardbreak_if_not_bol(s); - do option::iter(struct_def.ctor) |ctor| { - maybe_print_comment(s, ctor.span.lo); - print_outer_attributes(s, ctor.node.attrs); - // Doesn't call head because there shouldn't be a space after new. - cbox(s, indent_unit); - ibox(s, 4); - word(s.s, ~"new("); - print_fn_args(s, ctor.node.dec, ~[]); - word(s.s, ~")"); - space(s.s); - print_block(s, ctor.node.body); - } - do option::iter(struct_def.dtor) |dtor| { - hardbreak_if_not_bol(s); - maybe_print_comment(s, dtor.span.lo); - print_outer_attributes(s, dtor.node.attrs); - head(s, ~"drop"); - print_block(s, dtor.node.body); - } - for struct_def.members.each |ci| { - /* - FIXME (#1893): collect all private items and print - them in a single "priv" section - - tjc: I'm not going to fix this yet b/c we might - change how exports work, including for class items - */ - hardbreak_if_not_bol(s); - maybe_print_comment(s, ci.span.lo); - let pr = ast_util::class_member_visibility(ci); - match pr { - ast::private => { - head(s, ~"priv"); - bopen(s); - hardbreak_if_not_bol(s); - } - _ => () - } - match ci.node { - ast::instance_var(nm, t, mt, _,_) => { - word_nbsp(s, ~"let"); - match mt { - ast::class_mutable => word_nbsp(s, ~"mut"), - _ => () - } - word(s.s, *nm); - word_nbsp(s, ~":"); - print_type(s, t); - word(s.s, ~";"); - } - ast::class_method(m) => { - print_method(s, m); - } - } - match pr { - ast::private => bclose(s, ci.span), - _ => () - } - } - bclose(s, item.span); - } + print_struct(s, struct_def, tps, item.ident, item.span); + } ast::item_impl(tps, traits, ty, methods) => { head(s, ~"impl"); word(s.s, *item.ident); @@ -650,6 +582,79 @@ fn print_item(s: ps, &&item: @ast::item) { s.ann.post(ann_node); } +fn print_struct(s: ps, struct_def: ast::struct_def, tps: ~[ast::ty_param], + ident: ast::ident, span: ast::span) { + word_nbsp(s, *ident); + print_type_params(s, tps); + if vec::len(struct_def.traits) != 0u { + word_space(s, ~":"); + commasep(s, inconsistent, struct_def.traits, |s, p| + print_path(s, p.path, false)); + } + bopen(s); + hardbreak_if_not_bol(s); + do option::iter(struct_def.ctor) |ctor| { + maybe_print_comment(s, ctor.span.lo); + print_outer_attributes(s, ctor.node.attrs); + // Doesn't call head because there shouldn't be a space after new. + cbox(s, indent_unit); + ibox(s, 4); + word(s.s, ~"new("); + print_fn_args(s, ctor.node.dec, ~[]); + word(s.s, ~")"); + space(s.s); + print_block(s, ctor.node.body); + } + do option::iter(struct_def.dtor) |dtor| { + hardbreak_if_not_bol(s); + maybe_print_comment(s, dtor.span.lo); + print_outer_attributes(s, dtor.node.attrs); + head(s, ~"drop"); + print_block(s, dtor.node.body); + } + for struct_def.members.each |ci| { + /* + FIXME (#1893): collect all private items and print + them in a single "priv" section + + tjc: I'm not going to fix this yet b/c we might + change how exports work, including for class items + */ + hardbreak_if_not_bol(s); + maybe_print_comment(s, ci.span.lo); + let pr = ast_util::class_member_visibility(ci); + match pr { + ast::private => { + head(s, ~"priv"); + bopen(s); + hardbreak_if_not_bol(s); + } + _ => () + } + match ci.node { + ast::instance_var(nm, t, mt, _,_) => { + word_nbsp(s, ~"let"); + match mt { + ast::class_mutable => word_nbsp(s, ~"mut"), + _ => () + } + word(s.s, *nm); + word_nbsp(s, ~":"); + print_type(s, t); + word(s.s, ~";"); + } + ast::class_method(m) => { + print_method(s, m); + } + } + match pr { + ast::private => bclose(s, ci.span), + _ => () + } + } + bclose(s, span); +} + /// This doesn't deserve to be called "pretty" printing, but it should be /// meaning-preserving. A quick hack that might help would be to look at the /// spans embedded in the TTs to decide where to put spaces and newlines. |
