@@ -504,7 +504,12 @@ pub struct CommonDeclaration {
504
504
}
505
505
506
506
#[ derive( Clone , Debug ) ]
507
- pub struct FunctionDefinition { }
507
+ pub struct FunctionDefinition {
508
+ pub attributes : Vec < Attribute > ,
509
+ pub declaration_specifiers : DeclarationSpecifiers ,
510
+ pub declarator : Declarator ,
511
+ pub body : CompoundStatement ,
512
+ }
508
513
509
514
#[ derive( Clone , Debug ) ]
510
515
pub struct ConstExpr {
@@ -639,10 +644,10 @@ impl<'a> Parser<'a> {
639
644
}
640
645
}
641
646
}
642
- Declaration :: StaticAssert ( _) => todo ! ( ) ,
643
- Declaration :: Attribute ( _) => todo ! ( ) ,
647
+ Declaration :: StaticAssert ( _) => todo ! ( "c static assert" ) ,
648
+ Declaration :: Attribute ( _) => todo ! ( "c attribute declaration" ) ,
644
649
} ,
645
- ExternalDeclaration :: FunctionDefinition ( _) => todo ! ( ) ,
650
+ ExternalDeclaration :: FunctionDefinition ( _) => todo ! ( "define c function" ) ,
646
651
}
647
652
}
648
653
@@ -658,11 +663,17 @@ impl<'a> Parser<'a> {
658
663
}
659
664
660
665
fn parse_function_definition ( & mut self ) -> Result < FunctionDefinition , ParseError > {
661
- self . parse_attribute_specifier_sequence ( ) ?;
662
- self . parse_declaration_specifiers ( ) ?;
663
- self . parse_declarator ( ) ?;
664
- self . parse_function_body ( ) ?;
665
- Ok ( todo ! ( "parse_function_definition" ) )
666
+ let attributes = self . parse_attribute_specifier_sequence ( ) ?;
667
+ let declaration_specifiers = self . parse_declaration_specifiers ( ) ?;
668
+ let declarator = self . parse_declarator ( ) ?;
669
+ let body = self . parse_function_body ( ) ?;
670
+
671
+ Ok ( FunctionDefinition {
672
+ attributes,
673
+ declaration_specifiers,
674
+ declarator,
675
+ body,
676
+ } )
666
677
}
667
678
668
679
fn parse_attribute_specifier_sequence ( & mut self ) -> Result < Vec < Attribute > , ParseError > {
@@ -1469,7 +1480,7 @@ impl<'a> Parser<'a> {
1469
1480
1470
1481
let attribute_specifiers = self . parse_attribute_specifier_sequence ( ) ?;
1471
1482
1472
- if self . eat_punctuator ( Punctuator :: Semicolon ) {
1483
+ if !attribute_specifiers . is_empty ( ) && self . eat_punctuator ( Punctuator :: Semicolon ) {
1473
1484
// attribute-declaration
1474
1485
todo ! ( "parse attribute declaration" ) ;
1475
1486
return Ok ( todo ! ( ) ) ;
@@ -1629,9 +1640,8 @@ impl<'a> Parser<'a> {
1629
1640
Ok ( Designation { path } )
1630
1641
}
1631
1642
1632
- fn parse_function_body ( & mut self ) -> Result < ( ) , ParseError > {
1633
- let _statements = self . parse_compound_statement ( ) ?;
1634
- todo ! ( "parse_function_body" ) ;
1643
+ fn parse_function_body ( & mut self ) -> Result < CompoundStatement , ParseError > {
1644
+ self . parse_compound_statement ( )
1635
1645
}
1636
1646
1637
1647
fn parse_compound_statement ( & mut self ) -> Result < CompoundStatement , ParseError > {
@@ -1649,17 +1659,19 @@ impl<'a> Parser<'a> {
1649
1659
break ;
1650
1660
}
1651
1661
1652
- if let Ok ( declaration) = self . parse_declaration ( ) {
1662
+ if let Ok ( declaration) = speculate ! ( self . input , self . parse_declaration( ) ) {
1653
1663
statements. push ( declaration. into ( ) ) ;
1654
1664
continue ;
1655
1665
}
1656
1666
1657
- if let Ok ( unlabeled_statement) = self . parse_unlabeled_statement ( ) {
1667
+ if let Ok ( unlabeled_statement) =
1668
+ speculate ! ( self . input, self . parse_unlabeled_statement( ) )
1669
+ {
1658
1670
statements. push ( unlabeled_statement. into ( ) ) ;
1659
1671
continue ;
1660
1672
}
1661
1673
1662
- if let Ok ( label) = self . parse_label ( ) {
1674
+ if let Ok ( label) = speculate ! ( self . input , self . parse_label( ) ) {
1663
1675
statements. push ( label. into ( ) ) ;
1664
1676
continue ;
1665
1677
}
@@ -1674,11 +1686,34 @@ impl<'a> Parser<'a> {
1674
1686
}
1675
1687
1676
1688
fn parse_unlabeled_statement ( & mut self ) -> Result < UnlabeledStatement , ParseError > {
1677
- if let Ok ( expr_statement) = self . parse_expr_statement ( ) {
1689
+ if let Ok ( expr_statement) = speculate ! ( self . input , self . parse_expr_statement( ) ) {
1678
1690
return Ok ( expr_statement. into ( ) ) ;
1679
1691
}
1680
1692
1681
- todo ! ( "parse_unlabeled_statement" )
1693
+ let _attribute_specifier_sequence = self . parse_attribute_specifier_sequence ( ) ?;
1694
+
1695
+ if let Ok ( _primary_block) = speculate ! ( self . input, self . parse_primary_block( ) ) {
1696
+ return todo ! ( "handle parsed primary block" ) ;
1697
+ }
1698
+
1699
+ if let Ok ( _primary_block) = speculate ! ( self . input, self . parse_jump_block( ) ) {
1700
+ return todo ! ( "handle parsed jump block" ) ;
1701
+ }
1702
+
1703
+ todo ! ( "parse_unlabeled_statement" ) ;
1704
+
1705
+ return Err ( ParseError :: message (
1706
+ "Expected unlabeled statement" ,
1707
+ self . input . peek ( ) . source ,
1708
+ ) ) ;
1709
+ }
1710
+
1711
+ fn parse_primary_block ( & mut self ) -> Result < ( ) , ParseError > {
1712
+ todo ! ( "parse_primary_block" )
1713
+ }
1714
+
1715
+ fn parse_jump_block ( & mut self ) -> Result < ( ) , ParseError > {
1716
+ todo ! ( "parse_jump_block" )
1682
1717
}
1683
1718
1684
1719
fn parse_expr_statement ( & mut self ) -> Result < ExprStatement , ParseError > {
0 commit comments