@@ -1511,108 +1511,168 @@ impl<'a> State<'a> {
1511
1511
Ok ( ( ) )
1512
1512
}
1513
1513
1514
+ fn print_expr_box ( & mut self ,
1515
+ place : & Option < P < ast:: Expr > > ,
1516
+ expr : & ast:: Expr ) -> IoResult < ( ) > {
1517
+ try!( word ( & mut self . s , "box" ) ) ;
1518
+ try!( word ( & mut self . s , "(" ) ) ;
1519
+ try!( place. as_ref ( ) . map_or ( Ok ( ( ) ) , |e|self . print_expr ( & * * e) ) ) ;
1520
+ try!( self . word_space ( ")" ) ) ;
1521
+ self . print_expr ( expr)
1522
+ }
1523
+
1524
+ fn print_expr_vec ( & mut self , exprs : & [ P < ast:: Expr > ] ) -> IoResult < ( ) > {
1525
+ try!( self . ibox ( indent_unit) ) ;
1526
+ try!( word ( & mut self . s , "[" ) ) ;
1527
+ try!( self . commasep_exprs ( Inconsistent , & exprs[ ] ) ) ;
1528
+ try!( word ( & mut self . s , "]" ) ) ;
1529
+ self . end ( )
1530
+ }
1531
+
1532
+ fn print_expr_repeat ( & mut self ,
1533
+ element : & ast:: Expr ,
1534
+ count : & ast:: Expr ) -> IoResult < ( ) > {
1535
+ try!( self . ibox ( indent_unit) ) ;
1536
+ try!( word ( & mut self . s , "[" ) ) ;
1537
+ try!( self . print_expr ( element) ) ;
1538
+ try!( self . word_space ( ";" ) ) ;
1539
+ try!( self . print_expr ( count) ) ;
1540
+ try!( word ( & mut self . s , "]" ) ) ;
1541
+ self . end ( )
1542
+ }
1543
+
1544
+ fn print_expr_struct ( & mut self ,
1545
+ path : & ast:: Path ,
1546
+ fields : & [ ast:: Field ] ,
1547
+ wth : & Option < P < ast:: Expr > > ) -> IoResult < ( ) > {
1548
+ try!( self . print_path ( path, true ) ) ;
1549
+ if !( fields. is_empty ( ) && wth. is_none ( ) ) {
1550
+ try!( word ( & mut self . s , "{" ) ) ;
1551
+ try!( self . commasep_cmnt (
1552
+ Consistent ,
1553
+ & fields[ ] ,
1554
+ |s, field| {
1555
+ try!( s. ibox ( indent_unit) ) ;
1556
+ try!( s. print_ident ( field. ident . node ) ) ;
1557
+ try!( s. word_space ( ":" ) ) ;
1558
+ try!( s. print_expr ( & * field. expr ) ) ;
1559
+ s. end ( )
1560
+ } ,
1561
+ |f| f. span ) ) ;
1562
+ match * wth {
1563
+ Some ( ref expr) => {
1564
+ try!( self . ibox ( indent_unit) ) ;
1565
+ if !fields. is_empty ( ) {
1566
+ try!( word ( & mut self . s , "," ) ) ;
1567
+ try!( space ( & mut self . s ) ) ;
1568
+ }
1569
+ try!( word ( & mut self . s , ".." ) ) ;
1570
+ try!( self . print_expr ( & * * expr) ) ;
1571
+ try!( self . end ( ) ) ;
1572
+ }
1573
+ _ => try!( word ( & mut self . s , "," ) ) ,
1574
+ }
1575
+ try!( word ( & mut self . s , "}" ) ) ;
1576
+ }
1577
+ Ok ( ( ) )
1578
+ }
1579
+
1580
+ fn print_expr_tup ( & mut self , exprs : & [ P < ast:: Expr > ] ) -> IoResult < ( ) > {
1581
+ try!( self . popen ( ) ) ;
1582
+ try!( self . commasep_exprs ( Inconsistent , & exprs[ ] ) ) ;
1583
+ if exprs. len ( ) == 1 {
1584
+ try!( word ( & mut self . s , "," ) ) ;
1585
+ }
1586
+ self . pclose ( )
1587
+ }
1588
+
1589
+ fn print_expr_call ( & mut self ,
1590
+ func : & ast:: Expr ,
1591
+ args : & [ P < ast:: Expr > ] ) -> IoResult < ( ) > {
1592
+ try!( self . print_expr_maybe_paren ( func) ) ;
1593
+ self . print_call_post ( args)
1594
+ }
1595
+
1596
+ fn print_expr_method_call ( & mut self ,
1597
+ ident : ast:: SpannedIdent ,
1598
+ tys : & [ P < ast:: Ty > ] ,
1599
+ args : & [ P < ast:: Expr > ] ) -> IoResult < ( ) > {
1600
+ let base_args = args. slice_from ( 1 ) ;
1601
+ try!( self . print_expr ( & * args[ 0 ] ) ) ;
1602
+ try!( word ( & mut self . s , "." ) ) ;
1603
+ try!( self . print_ident ( ident. node ) ) ;
1604
+ if tys. len ( ) > 0 u {
1605
+ try!( word ( & mut self . s , "::<" ) ) ;
1606
+ try!( self . commasep ( Inconsistent , tys,
1607
+ |s, ty| s. print_type ( & * * ty) ) ) ;
1608
+ try!( word ( & mut self . s , ">" ) ) ;
1609
+ }
1610
+ self . print_call_post ( base_args)
1611
+ }
1612
+
1613
+ fn print_expr_binary ( & mut self ,
1614
+ op : ast:: BinOp ,
1615
+ lhs : & ast:: Expr ,
1616
+ rhs : & ast:: Expr ) -> IoResult < ( ) > {
1617
+ try!( self . print_expr ( lhs) ) ;
1618
+ try!( space ( & mut self . s ) ) ;
1619
+ try!( self . word_space ( ast_util:: binop_to_string ( op) ) ) ;
1620
+ self . print_expr ( rhs)
1621
+ }
1622
+
1623
+ fn print_expr_unary ( & mut self ,
1624
+ op : ast:: UnOp ,
1625
+ expr : & ast:: Expr ) -> IoResult < ( ) > {
1626
+ try!( word ( & mut self . s , ast_util:: unop_to_string ( op) ) ) ;
1627
+ self . print_expr_maybe_paren ( expr)
1628
+ }
1629
+
1630
+ fn print_expr_addr_of ( & mut self ,
1631
+ mutability : ast:: Mutability ,
1632
+ expr : & ast:: Expr ) -> IoResult < ( ) > {
1633
+ try!( word ( & mut self . s , "&" ) ) ;
1634
+ try!( self . print_mutability ( mutability) ) ;
1635
+ self . print_expr_maybe_paren ( expr)
1636
+ }
1637
+
1514
1638
pub fn print_expr ( & mut self , expr : & ast:: Expr ) -> IoResult < ( ) > {
1515
1639
try!( self . maybe_print_comment ( expr. span . lo ) ) ;
1516
1640
try!( self . ibox ( indent_unit) ) ;
1517
1641
try!( self . ann . pre ( self , NodeExpr ( expr) ) ) ;
1518
1642
match expr. node {
1519
- ast:: ExprBox ( ref p, ref e) => {
1520
- try!( word ( & mut self . s , "box" ) ) ;
1521
- try!( word ( & mut self . s , "(" ) ) ;
1522
- try!( p. as_ref ( ) . map_or ( Ok ( ( ) ) , |e|self . print_expr ( & * * e) ) ) ;
1523
- try!( self . word_space ( ")" ) ) ;
1524
- try!( self . print_expr ( & * * e) ) ;
1643
+ ast:: ExprBox ( ref place, ref expr) => {
1644
+ try!( self . print_expr_box ( place, & * * expr) ) ;
1525
1645
}
1526
1646
ast:: ExprVec ( ref exprs) => {
1527
- try!( self . ibox ( indent_unit) ) ;
1528
- try!( word ( & mut self . s , "[" ) ) ;
1529
- try!( self . commasep_exprs ( Inconsistent , & exprs[ ] ) ) ;
1530
- try!( word ( & mut self . s , "]" ) ) ;
1531
- try!( self . end ( ) ) ;
1647
+ try!( self . print_expr_vec ( & exprs[ ] ) ) ;
1532
1648
}
1533
-
1534
1649
ast:: ExprRepeat ( ref element, ref count) => {
1535
- try!( self . ibox ( indent_unit) ) ;
1536
- try!( word ( & mut self . s , "[" ) ) ;
1537
- try!( self . print_expr ( & * * element) ) ;
1538
- try!( self . word_space ( ";" ) ) ;
1539
- try!( self . print_expr ( & * * count) ) ;
1540
- try!( word ( & mut self . s , "]" ) ) ;
1541
- try!( self . end ( ) ) ;
1650
+ try!( self . print_expr_repeat ( & * * element, & * * count) ) ;
1542
1651
}
1543
-
1544
1652
ast:: ExprStruct ( ref path, ref fields, ref wth) => {
1545
- try!( self . print_path ( path, true ) ) ;
1546
- if !( fields. is_empty ( ) && wth. is_none ( ) ) {
1547
- try!( word ( & mut self . s , "{" ) ) ;
1548
- try!( self . commasep_cmnt (
1549
- Consistent ,
1550
- & fields[ ] ,
1551
- |s, field| {
1552
- try!( s. ibox ( indent_unit) ) ;
1553
- try!( s. print_ident ( field. ident . node ) ) ;
1554
- try!( s. word_space ( ":" ) ) ;
1555
- try!( s. print_expr ( & * field. expr ) ) ;
1556
- s. end ( )
1557
- } ,
1558
- |f| f. span ) ) ;
1559
- match * wth {
1560
- Some ( ref expr) => {
1561
- try!( self . ibox ( indent_unit) ) ;
1562
- if !fields. is_empty ( ) {
1563
- try!( word ( & mut self . s , "," ) ) ;
1564
- try!( space ( & mut self . s ) ) ;
1565
- }
1566
- try!( word ( & mut self . s , ".." ) ) ;
1567
- try!( self . print_expr ( & * * expr) ) ;
1568
- try!( self . end ( ) ) ;
1569
- }
1570
- _ => try!( word ( & mut self . s , "," ) ) ,
1571
- }
1572
- try!( word ( & mut self . s , "}" ) ) ;
1573
- }
1653
+ try!( self . print_expr_struct ( path, & fields[ ] , wth) ) ;
1574
1654
}
1575
1655
ast:: ExprTup ( ref exprs) => {
1576
- try!( self . popen ( ) ) ;
1577
- try!( self . commasep_exprs ( Inconsistent , & exprs[ ] ) ) ;
1578
- if exprs. len ( ) == 1 {
1579
- try!( word ( & mut self . s , "," ) ) ;
1580
- }
1581
- try!( self . pclose ( ) ) ;
1656
+ try!( self . print_expr_tup ( & exprs[ ] ) ) ;
1582
1657
}
1583
1658
ast:: ExprCall ( ref func, ref args) => {
1584
- try!( self . print_expr_maybe_paren ( & * * func) ) ;
1585
- try!( self . print_call_post ( & args[ ] ) ) ;
1659
+ try!( self . print_expr_call ( & * * func, & args[ ] ) ) ;
1586
1660
}
1587
1661
ast:: ExprMethodCall ( ident, ref tys, ref args) => {
1588
- let base_args = args. slice_from ( 1 ) ;
1589
- try!( self . print_expr ( & * args[ 0 ] ) ) ;
1590
- try!( word ( & mut self . s , "." ) ) ;
1591
- try!( self . print_ident ( ident. node ) ) ;
1592
- if tys. len ( ) > 0 u {
1593
- try!( word ( & mut self . s , "::<" ) ) ;
1594
- try!( self . commasep ( Inconsistent , & tys[ ] ,
1595
- |s, ty| s. print_type ( & * * ty) ) ) ;
1596
- try!( word ( & mut self . s , ">" ) ) ;
1597
- }
1598
- try!( self . print_call_post ( base_args) ) ;
1662
+ try!( self . print_expr_method_call ( ident, & tys[ ] , & args[ ] ) ) ;
1599
1663
}
1600
1664
ast:: ExprBinary ( op, ref lhs, ref rhs) => {
1601
- try!( self . print_expr ( & * * lhs) ) ;
1602
- try!( space ( & mut self . s ) ) ;
1603
- try!( self . word_space ( ast_util:: binop_to_string ( op) ) ) ;
1604
- try!( self . print_expr ( & * * rhs) ) ;
1665
+ try!( self . print_expr_binary ( op, & * * lhs, & * * rhs) ) ;
1605
1666
}
1606
1667
ast:: ExprUnary ( op, ref expr) => {
1607
- try!( word ( & mut self . s , ast_util:: unop_to_string ( op) ) ) ;
1608
- try!( self . print_expr_maybe_paren ( & * * expr) ) ;
1668
+ try!( self . print_expr_unary ( op, & * * expr) ) ;
1609
1669
}
1610
1670
ast:: ExprAddrOf ( m, ref expr) => {
1611
- try!( word ( & mut self . s , "&" ) ) ;
1612
- try!( self . print_mutability ( m) ) ;
1613
- try!( self . print_expr_maybe_paren ( & * * expr) ) ;
1671
+ try!( self . print_expr_addr_of ( m, & * * expr) ) ;
1672
+ }
1673
+ ast:: ExprLit ( ref lit) => {
1674
+ try!( self . print_literal ( & * * lit) ) ;
1614
1675
}
1615
- ast:: ExprLit ( ref lit) => try!( self . print_literal ( & * * lit) ) ,
1616
1676
ast:: ExprCast ( ref expr, ref ty) => {
1617
1677
try!( self . print_expr ( & * * expr) ) ;
1618
1678
try!( space ( & mut self . s ) ) ;
0 commit comments