@@ -986,10 +986,57 @@ fn print_expr(&ps s, &@ast::expr expr) {
986
986
print_expr ( s, expr) ;
987
987
pclose ( s) ;
988
988
}
989
- case ( ast:: expr_anon_obj ( _, _) ) {
990
- word ( s. s , "anon obj" ) ;
991
- // FIXME (issue #499): nicer pretty-printing of anon objs
989
+ case ( ast:: expr_anon_obj ( ?anon_obj, ?tps) ) {
990
+ head ( s, "obj" ) ;
991
+ print_type_params ( s, tps) ;
992
+
993
+ // Fields
994
+ popen ( s) ;
995
+ fn print_field ( & ps s, & ast:: anon_obj_field field) {
996
+ ibox ( s, indent_unit) ;
997
+ print_mutability ( s, field. mut ) ;
998
+ print_type ( s, * field. ty ) ;
999
+ space ( s. s ) ;
1000
+ word ( s. s , field. ident ) ;
1001
+ word_space ( s, "=" ) ;
1002
+ print_expr ( s, field. expr ) ;
1003
+ end ( s) ;
1004
+ }
1005
+ fn get_span ( & ast:: anon_obj_field f) -> codemap:: span {
1006
+ ret f. ty . span ;
1007
+ }
1008
+ alt ( anon_obj. fields ) {
1009
+ case ( none) { }
1010
+ case ( some ( ?fields) ) {
1011
+ commasep_cmnt_ivec ( s, consistent, fields, print_field,
1012
+ get_span) ;
1013
+ }
1014
+ }
1015
+ pclose ( s) ;
1016
+ space ( s. s ) ;
1017
+ bopen ( s) ;
1018
+
1019
+ // Methods
1020
+ for ( @ast:: method meth in anon_obj. methods) {
1021
+ let ast:: ty_param[ ] typarams = ~[ ] ;
1022
+ hardbreak_if_not_bol ( s) ;
1023
+ maybe_print_comment ( s, meth. span . lo ) ;
1024
+ print_fn ( s, meth. node . meth . decl , meth. node . meth . proto ,
1025
+ meth. node . ident , typarams) ;
1026
+ word ( s. s , " " ) ;
1027
+ print_block ( s, meth. node . meth . body ) ;
1028
+ }
1029
+ space ( s. s ) ;
992
1030
1031
+ // With object
1032
+ alt ( anon_obj. with_obj ) {
1033
+ case ( none) { }
1034
+ case ( some ( ?e) ) {
1035
+ word_space ( s, "with" ) ;
1036
+ print_expr ( s, e) ;
1037
+ }
1038
+ }
1039
+ bclose ( s, expr. span ) ;
993
1040
}
994
1041
}
995
1042
s. ann . post ( ann_node) ;
0 commit comments