@@ -532,76 +532,8 @@ fn print_item(s: ps, &&item: @ast::item) {
532
532
}
533
533
ast::item_class(struct_def, tps) => {
534
534
head(s, ~" class") ;
535
- word_nbsp ( s, * item. ident ) ;
536
- print_type_params ( s, tps) ;
537
- if vec:: len ( struct_def. traits ) != 0 u {
538
- word_space ( s, ~": ") ;
539
- commasep ( s, inconsistent, struct_def. traits , |s, p|
540
- print_path ( s, p. path , false ) ) ;
541
- }
542
- bopen ( s) ;
543
- hardbreak_if_not_bol ( s) ;
544
- do option:: iter ( struct_def. ctor ) |ctor| {
545
- maybe_print_comment ( s, ctor. span . lo ) ;
546
- print_outer_attributes ( s, ctor. node . attrs ) ;
547
- // Doesn't call head because there shouldn't be a space after new.
548
- cbox ( s, indent_unit) ;
549
- ibox ( s, 4 ) ;
550
- word ( s. s , ~"new ( ");
551
- print_fn_args(s, ctor.node.dec, ~[]);
552
- word(s.s, ~" ) ") ;
553
- space ( s. s ) ;
554
- print_block ( s, ctor. node . body ) ;
555
- }
556
- do option:: iter ( struct_def. dtor ) |dtor| {
557
- hardbreak_if_not_bol ( s) ;
558
- maybe_print_comment ( s, dtor. span . lo ) ;
559
- print_outer_attributes ( s, dtor. node . attrs ) ;
560
- head ( s, ~"drop") ;
561
- print_block ( s, dtor. node . body ) ;
562
- }
563
- for struct_def. members . each |ci| {
564
- /*
565
- FIXME (#1893): collect all private items and print
566
- them in a single "priv" section
567
-
568
- tjc: I'm not going to fix this yet b/c we might
569
- change how exports work, including for class items
570
- */
571
- hardbreak_if_not_bol ( s) ;
572
- maybe_print_comment ( s, ci. span . lo ) ;
573
- let pr = ast_util:: class_member_visibility ( ci) ;
574
- match pr {
575
- ast:: private => {
576
- head ( s, ~"priv") ;
577
- bopen ( s) ;
578
- hardbreak_if_not_bol ( s) ;
579
- }
580
- _ => ( )
581
- }
582
- match ci. node {
583
- ast:: instance_var( nm, t, mt, _, _) => {
584
- word_nbsp( s, ~"let ");
585
- match mt {
586
- ast::class_mutable => word_nbsp(s, ~" mut "),
587
- _ => ()
588
- }
589
- word(s.s, *nm);
590
- word_nbsp(s, ~" : ") ;
591
- print_type ( s, t) ;
592
- word( s. s , ~"; ");
593
- }
594
- ast::class_method(m) => {
595
- print_method(s, m);
596
- }
597
- }
598
- match pr {
599
- ast::private => bclose(s, ci.span),
600
- _ => ()
601
- }
602
- }
603
- bclose(s, item.span);
604
- }
535
+ print_struct ( s, struct_def, tps, item. ident , item. span ) ;
536
+ }
605
537
ast:: item_impl ( tps, traits, ty, methods) => {
606
538
head ( s, ~"impl ") ;
607
539
word ( s. s , * item. ident ) ;
@@ -650,6 +582,79 @@ fn print_item(s: ps, &&item: @ast::item) {
650
582
s. ann . post ( ann_node) ;
651
583
}
652
584
585
+ fn print_struct( s : ps , struct_def : ast:: struct_def , tps : ~[ ast:: ty_param ] ,
586
+ ident : ast:: ident , span : ast:: span ) {
587
+ word_nbsp ( s, * ident) ;
588
+ print_type_params ( s, tps) ;
589
+ if vec:: len ( struct_def. traits ) != 0 u {
590
+ word_space ( s, ~": ") ;
591
+ commasep ( s, inconsistent, struct_def. traits , |s, p|
592
+ print_path ( s, p. path , false ) ) ;
593
+ }
594
+ bopen ( s) ;
595
+ hardbreak_if_not_bol ( s) ;
596
+ do option:: iter ( struct_def. ctor ) |ctor| {
597
+ maybe_print_comment ( s, ctor. span . lo ) ;
598
+ print_outer_attributes ( s, ctor. node . attrs ) ;
599
+ // Doesn't call head because there shouldn't be a space after new.
600
+ cbox ( s, indent_unit) ;
601
+ ibox ( s, 4 ) ;
602
+ word ( s. s , ~"new ( ");
603
+ print_fn_args(s, ctor.node.dec, ~[]);
604
+ word(s.s, ~" ) ") ;
605
+ space ( s. s ) ;
606
+ print_block ( s, ctor. node . body ) ;
607
+ }
608
+ do option:: iter ( struct_def. dtor ) |dtor| {
609
+ hardbreak_if_not_bol ( s) ;
610
+ maybe_print_comment ( s, dtor. span . lo ) ;
611
+ print_outer_attributes ( s, dtor. node . attrs ) ;
612
+ head ( s, ~"drop") ;
613
+ print_block ( s, dtor. node . body ) ;
614
+ }
615
+ for struct_def. members . each |ci| {
616
+ /*
617
+ FIXME (#1893): collect all private items and print
618
+ them in a single "priv" section
619
+
620
+ tjc: I'm not going to fix this yet b/c we might
621
+ change how exports work, including for class items
622
+ */
623
+ hardbreak_if_not_bol ( s) ;
624
+ maybe_print_comment ( s, ci. span . lo ) ;
625
+ let pr = ast_util:: class_member_visibility ( ci) ;
626
+ match pr {
627
+ ast:: private => {
628
+ head ( s, ~"priv") ;
629
+ bopen ( s) ;
630
+ hardbreak_if_not_bol ( s) ;
631
+ }
632
+ _ => ( )
633
+ }
634
+ match ci. node {
635
+ ast:: instance_var( nm, t, mt, _, _) => {
636
+ word_nbsp( s, ~"let ");
637
+ match mt {
638
+ ast::class_mutable => word_nbsp(s, ~" mut "),
639
+ _ => ()
640
+ }
641
+ word(s.s, *nm);
642
+ word_nbsp(s, ~" : ") ;
643
+ print_type ( s, t) ;
644
+ word( s. s , ~"; ");
645
+ }
646
+ ast::class_method(m) => {
647
+ print_method(s, m);
648
+ }
649
+ }
650
+ match pr {
651
+ ast::private => bclose(s, ci.span),
652
+ _ => ()
653
+ }
654
+ }
655
+ bclose(s, span);
656
+ }
657
+
653
658
/// This doesn't deserve to be called " pretty" printing, but it should be
654
659
/// meaning-preserving. A quick hack that might help would be to look at the
655
660
/// spans embedded in the TTs to decide where to put spaces and newlines.
0 commit comments