@@ -8,7 +8,6 @@ import pp::{break_offset, word, printer,
8
8
import driver:: diagnostic;
9
9
10
10
// The ps is stored here to prevent recursive type.
11
- // FIXME use a nominal enum instead
12
11
enum ann_node {
13
12
node_block( ps , ast:: blk ) ,
14
13
node_item( ps , @ast:: item ) ,
@@ -357,7 +356,7 @@ fn print_type(s: ps, &&ty: @ast::ty) {
357
356
ast:: ty_constr ( t, cs) {
358
357
print_type ( s, t) ;
359
358
space ( s. s ) ;
360
- word ( s. s , ast_ty_constrs_str ( cs) ) ;
359
+ word ( s. s , constrs_str ( cs, ty_constr_to_str ) ) ;
361
360
}
362
361
ast:: ty_mac ( _) {
363
362
fail "print_type doesn't know how to print a ty_mac" ;
@@ -482,7 +481,7 @@ fn print_item(s: ps, &&item: @ast::item) {
482
481
print_block ( s, ctor_body) ;
483
482
for ci in items {
484
483
/*
485
- TODO : collect all private items and print them
484
+ FIXME : collect all private items and print them
486
485
in a single "priv" section
487
486
*/
488
487
hardbreak_if_not_bol ( s) ;
@@ -1249,7 +1248,10 @@ fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl) {
1249
1248
}
1250
1249
commasep ( s, inconsistent, decl. inputs , print_arg) ;
1251
1250
pclose ( s) ;
1252
- word ( s. s , ast_fn_constrs_str ( decl, decl. constraints ) ) ;
1251
+ word ( s. s , constrs_str ( decl. constraints , { |c|
1252
+ ast_fn_constr_to_str ( decl, c)
1253
+ } ) ) ;
1254
+
1253
1255
maybe_print_comment ( s, decl. output . span . lo ) ;
1254
1256
if decl. output . node != ast:: ty_nil {
1255
1257
space_if_not_bol ( s) ;
@@ -1479,7 +1481,7 @@ fn print_ty_fn(s: ps, opt_proto: option<ast::proto>,
1479
1481
else { print_type ( s, decl. output ) ; }
1480
1482
end ( s) ;
1481
1483
}
1482
- word ( s. s , ast_ty_fn_constrs_str ( decl. constraints ) ) ;
1484
+ word ( s. s , constrs_str ( decl. constraints , ast_ty_fn_constr_to_str ) ) ;
1483
1485
end ( s) ;
1484
1486
}
1485
1487
@@ -1684,8 +1686,6 @@ fn next_comment(s: ps) -> option<lexer::cmnt> {
1684
1686
}
1685
1687
}
1686
1688
1687
- // Removing the aliases from the type of f in the next two functions
1688
- // triggers memory corruption, but I haven't isolated the bug yet. FIXME
1689
1689
fn constr_args_to_str < T > ( f : fn @( T ) -> str , args : [ @ast:: sp_constr_arg < T > ] ) ->
1690
1690
str {
1691
1691
let comma = false ;
@@ -1712,43 +1712,38 @@ fn constr_arg_to_str<T>(f: fn@(T) -> str, c: ast::constr_arg_general_<T>) ->
1712
1712
// (argh)
1713
1713
fn uint_to_str ( & & i: uint ) -> str { ret uint:: str ( i) ; }
1714
1714
1715
- fn ast_ty_fn_constr_to_str ( c : @ast:: constr ) -> str {
1715
+ fn ast_ty_fn_constr_to_str ( & & c: @ast:: constr ) -> str {
1716
1716
ret path_to_str ( c. node . path ) +
1717
1717
constr_args_to_str ( uint_to_str, c. node . args ) ;
1718
1718
}
1719
1719
1720
- // FIXME: fix repeated code
1721
- fn ast_ty_fn_constrs_str ( constrs : [ @ast:: constr ] ) -> str {
1722
- let s = "" ;
1723
- let colon = true ;
1724
- for c: @ast:: constr in constrs {
1725
- if colon { s += " : " ; colon = false ; } else { s += ", " ; }
1726
- s += ast_ty_fn_constr_to_str ( c) ;
1727
- }
1728
- ret s;
1720
+ fn ast_fn_constr_to_str ( decl : ast:: fn_decl , & & c: @ast:: constr ) -> str {
1721
+ let arg_to_str = bind fn_arg_idx_to_str ( decl, _) ;
1722
+ ret path_to_str ( c. node . path ) +
1723
+ constr_args_to_str ( arg_to_str, c. node . args ) ;
1729
1724
}
1730
1725
1731
- fn fn_arg_idx_to_str ( decl : ast:: fn_decl , & & idx: uint ) -> str {
1732
- decl. inputs [ idx] . ident
1733
- }
1726
+ fn ty_constr_to_str ( & & c: @ast:: ty_constr ) -> str {
1727
+ fn ty_constr_path_to_str ( & & p: @ast:: path ) -> str { "*." + path_to_str ( p) }
1734
1728
1735
- fn ast_fn_constr_to_str ( decl : ast:: fn_decl , c : @ast:: constr ) -> str {
1736
- let arg_to_str = bind fn_arg_idx_to_str ( decl, _) ;
1737
1729
ret path_to_str ( c. node . path ) +
1738
- constr_args_to_str ( arg_to_str, c. node . args ) ;
1730
+ constr_args_to_str :: < @ast:: path > ( ty_constr_path_to_str,
1731
+ c. node . args ) ;
1739
1732
}
1740
1733
1741
- // FIXME: fix repeated code
1742
- fn ast_fn_constrs_str ( decl : ast:: fn_decl , constrs : [ @ast:: constr ] ) -> str {
1743
- let s = "" ;
1744
- let colon = true ;
1745
- for c: @ast:: constr in constrs {
1734
+ fn constrs_str < T > ( constrs : [ T ] , elt : fn ( T ) -> str ) -> str {
1735
+ let s = "" , colon = true ;
1736
+ for c in constrs {
1746
1737
if colon { s += " : " ; colon = false ; } else { s += ", " ; }
1747
- s += ast_fn_constr_to_str ( decl , c) ;
1738
+ s += elt ( c) ;
1748
1739
}
1749
1740
ret s;
1750
1741
}
1751
1742
1743
+ fn fn_arg_idx_to_str ( decl : ast:: fn_decl , & & idx: uint ) -> str {
1744
+ decl. inputs [ idx] . ident
1745
+ }
1746
+
1752
1747
fn opt_proto_to_str ( opt_p : option < ast:: proto > ) -> str {
1753
1748
alt opt_p {
1754
1749
none { "fn" }
@@ -1766,25 +1761,6 @@ fn proto_to_str(p: ast::proto) -> str {
1766
1761
} ;
1767
1762
}
1768
1763
1769
- fn ty_constr_to_str ( c : @ast:: ty_constr ) -> str {
1770
- fn ty_constr_path_to_str ( & & p: @ast:: path ) -> str { "*." + path_to_str ( p) }
1771
-
1772
- ret path_to_str ( c. node . path ) +
1773
- constr_args_to_str :: < @ast:: path > ( ty_constr_path_to_str,
1774
- c. node . args ) ;
1775
- }
1776
-
1777
-
1778
- fn ast_ty_constrs_str ( constrs : [ @ast:: ty_constr ] ) -> str {
1779
- let s = "" ;
1780
- let colon = true ;
1781
- for c: @ast:: ty_constr in constrs {
1782
- if colon { s += " : " ; colon = false ; } else { s += ", " ; }
1783
- s += ty_constr_to_str ( c) ;
1784
- }
1785
- ret s;
1786
- }
1787
-
1788
1764
fn ends_in_lit_int ( ex : @ast:: expr ) -> bool {
1789
1765
alt ex. node {
1790
1766
ast:: expr_lit ( @{ node: ast:: lit_int ( _, ast:: ty_i) , _} ) { true }
0 commit comments