@@ -112,7 +112,7 @@ pub enum ParameterDeclarationCore {
112
112
113
113
#[ derive( Clone , Debug ) ]
114
114
pub struct ParameterDeclaration {
115
- pub attributes : Vec < ( ) > ,
115
+ pub attributes : Vec < Attribute > ,
116
116
pub declaration_specifiers : DeclarationSpecifiers ,
117
117
pub core : ParameterDeclarationCore ,
118
118
pub source : Source ,
@@ -176,7 +176,7 @@ pub struct FunctionQualifier {
176
176
177
177
#[ derive( Clone , Debug ) ]
178
178
pub struct Pointer {
179
- pub attributes : Vec < ( ) > ,
179
+ pub attributes : Vec < Attribute > ,
180
180
pub type_qualifiers : Vec < TypeQualifier > ,
181
181
pub source : Source ,
182
182
}
@@ -291,7 +291,7 @@ impl TypeSpecifierQualifier {
291
291
292
292
#[ derive( Clone , Debug ) ]
293
293
pub struct SpecifierQualifierList {
294
- pub attributes : Vec < ( ) > ,
294
+ pub attributes : Vec < Attribute > ,
295
295
pub type_specifier_qualifiers : Vec < TypeSpecifierQualifier > ,
296
296
}
297
297
@@ -347,7 +347,7 @@ pub enum AlignmentSpecifierKind {
347
347
#[ derive( Clone , Debug ) ]
348
348
pub struct DeclarationSpecifiers {
349
349
pub specifiers : Vec < DeclarationSpecifier > ,
350
- pub attributes : Vec < ( ) > ,
350
+ pub attributes : Vec < Attribute > ,
351
351
}
352
352
353
353
impl From < & SpecifierQualifierList > for DeclarationSpecifiers {
@@ -379,7 +379,7 @@ pub struct StaticAssertDeclaration {
379
379
380
380
#[ derive( Clone , Debug ) ]
381
381
pub struct Member {
382
- pub attributes : Vec < ( ) > ,
382
+ pub attributes : Vec < Attribute > ,
383
383
pub specifier_qualifiers : SpecifierQualifierList ,
384
384
pub member_declarators : Vec < MemberDeclarator > ,
385
385
}
@@ -396,16 +396,109 @@ pub enum ExternalDeclaration {
396
396
FunctionDefinition ( FunctionDefinition ) ,
397
397
}
398
398
399
+ #[ derive( Clone , Debug , From ) ]
400
+ pub enum BlockItem {
401
+ ExternalDeclaration ( ExternalDeclaration ) ,
402
+ UnlabeledStatement ( UnlabeledStatement ) ,
403
+ Label ( Label ) ,
404
+ }
405
+
406
+ #[ derive( Clone , Debug , From ) ]
407
+ pub enum UnlabeledStatement {
408
+ ExprStatement ( ExprStatement ) ,
409
+ PrimaryBlock ( Vec < Attribute > , PrimaryBlock ) ,
410
+ JumpStatement ( Vec < Attribute > , JumpStatement ) ,
411
+ }
412
+
413
+ #[ derive( Clone , Debug ) ]
414
+ pub enum ExprStatement {
415
+ Empty ,
416
+ Normal ( Vec < Attribute > , Expr ) ,
417
+ }
418
+
419
+ #[ derive( Clone , Debug ) ]
420
+ pub struct Attribute {
421
+ pub kind : AttributeKind ,
422
+ pub clause : Vec < CToken > ,
423
+ }
424
+
425
+ #[ derive( Clone , Debug ) ]
426
+ pub enum AttributeKind {
427
+ Standard ( String ) ,
428
+ Namespaced ( String , String ) ,
429
+ }
430
+
431
+ #[ derive( Clone , Debug ) ]
432
+ pub enum JumpStatement {
433
+ Goto ( String ) ,
434
+ Continue ,
435
+ Break ,
436
+ Return ( Option < Expr > ) ,
437
+ }
438
+
439
+ #[ derive( Clone , Debug ) ]
440
+ pub enum PrimaryBlock {
441
+ CompoundStatement ( CompoundStatement ) ,
442
+ SelectionStatement ( SelectionStatement ) ,
443
+ IterationStatement ( IterationStatement ) ,
444
+ }
445
+
446
+ #[ derive( Clone , Debug ) ]
447
+ pub enum IterationStatement {
448
+ While ( Expr , SecondaryBlock ) ,
449
+ DoWhile ( SecondaryBlock , Expr ) ,
450
+ For ( Option < Expr > , Option < Expr > , Option < Expr > ) ,
451
+ }
452
+
453
+ #[ derive( Clone , Debug ) ]
454
+ pub struct CompoundStatement {
455
+ pub statements : Vec < BlockItem > ,
456
+ }
457
+
458
+ type SecondaryBlock = Statement ;
459
+
460
+ #[ derive( Clone , Debug ) ]
461
+ pub enum Statement {
462
+ LabeledStatement ( Box < LabeledStatement > ) ,
463
+ UnlabeledStatement ( Box < UnlabeledStatement > ) ,
464
+ }
465
+
466
+ #[ derive( Clone , Debug ) ]
467
+ pub struct LabeledStatement {
468
+ pub label : Label ,
469
+ pub statement : Statement ,
470
+ }
471
+
472
+ #[ derive( Clone , Debug ) ]
473
+ pub enum SelectionStatement {
474
+ If ( Expr , SecondaryBlock ) ,
475
+ IfElse ( Expr , SecondaryBlock , SecondaryBlock ) ,
476
+ Switch ( Expr , SecondaryBlock ) ,
477
+ }
478
+
479
+ #[ derive( Clone , Debug ) ]
480
+ pub enum LabelKind {
481
+ UserDefined ( String ) ,
482
+ Case ( ConstExpr ) ,
483
+ Default ,
484
+ }
485
+
486
+ #[ derive( Clone , Debug ) ]
487
+ pub struct Label {
488
+ pub attributes : Vec < Attribute > ,
489
+ pub kind : LabelKind ,
490
+ }
491
+
399
492
#[ derive( Clone , Debug ) ]
400
493
pub enum Declaration {
401
494
Common ( CommonDeclaration ) ,
402
495
StaticAssert ( StaticAssertDeclaration ) ,
403
- Attribute ( Vec < ( ) > ) ,
496
+ Attribute ( Vec < Attribute > ) ,
404
497
}
405
498
406
499
#[ derive( Clone , Debug ) ]
407
500
pub struct CommonDeclaration {
408
- pub attribute_specifiers : Vec < ( ) > ,
501
+ pub attribute_specifiers : Vec < Attribute > ,
409
502
pub declaration_specifiers : DeclarationSpecifiers ,
410
503
pub init_declarator_list : Vec < InitDeclarator > ,
411
504
}
@@ -429,7 +522,7 @@ pub struct Composite {
429
522
pub kind : CompositeKind ,
430
523
pub source : Source ,
431
524
pub name : Option < String > ,
432
- pub attributes : Vec < ( ) > ,
525
+ pub attributes : Vec < Attribute > ,
433
526
pub members : Option < Vec < MemberDeclaration > > ,
434
527
}
435
528
@@ -441,7 +534,7 @@ pub struct EnumTypeSpecifier {
441
534
#[ derive( Clone , Debug ) ]
442
535
pub struct Enumerator {
443
536
pub name : String ,
444
- pub attributes : Vec < ( ) > ,
537
+ pub attributes : Vec < Attribute > ,
445
538
pub value : Option < ConstExpr > ,
446
539
pub source : Source ,
447
540
}
@@ -464,7 +557,7 @@ impl Enumeration {
464
557
#[ derive( Clone , Debug ) ]
465
558
pub struct EnumerationDefinition {
466
559
pub name : Option < String > ,
467
- pub attributes : Vec < ( ) > ,
560
+ pub attributes : Vec < Attribute > ,
468
561
pub enum_type_specifier : Option < EnumTypeSpecifier > ,
469
562
pub body : Vec < Enumerator > ,
470
563
pub source : Source ,
@@ -572,7 +665,7 @@ impl<'a> Parser<'a> {
572
665
Ok ( ( ) )
573
666
}
574
667
575
- fn parse_attribute_specifier_sequence ( & mut self ) -> Result < Vec < ( ) > , ParseError > {
668
+ fn parse_attribute_specifier_sequence ( & mut self ) -> Result < Vec < Attribute > , ParseError > {
576
669
#[ allow( clippy:: never_loop) ]
577
670
while self . eat_sequence ( & [
578
671
CTokenKind :: Punctuator ( Punctuator :: OpenBracket ) ,
@@ -1541,27 +1634,72 @@ impl<'a> Parser<'a> {
1541
1634
}
1542
1635
1543
1636
fn parse_function_body ( & mut self ) -> Result < ( ) , ParseError > {
1544
- self . parse_compound_statement ( )
1637
+ let _statements = self . parse_compound_statement ( ) ?;
1638
+ todo ! ( "parse_function_body" ) ;
1545
1639
}
1546
1640
1547
- fn parse_compound_statement ( & mut self ) -> Result < ( ) , ParseError > {
1641
+ fn parse_compound_statement ( & mut self ) -> Result < CompoundStatement , ParseError > {
1548
1642
if !self . eat_punctuator ( Punctuator :: OpenCurly ) {
1549
1643
return Err ( ParseError :: new (
1550
1644
ParseErrorKind :: Misc ( "Expected '{' to begin compound statement" ) ,
1551
1645
self . input . peek ( ) . source ,
1552
1646
) ) ;
1553
1647
}
1554
1648
1555
- todo ! ( "parse compound statement" ) ;
1649
+ let mut statements = vec ! [ ] ;
1650
+
1651
+ loop {
1652
+ if self . eat_punctuator ( Punctuator :: CloseCurly ) {
1653
+ break ;
1654
+ }
1655
+
1656
+ if let Ok ( declaration) = self . parse_declaration ( ) {
1657
+ statements. push ( declaration. into ( ) ) ;
1658
+ }
1659
+
1660
+ if let Ok ( unlabeled_statement) = self . parse_unlabeled_statement ( ) {
1661
+ statements. push ( unlabeled_statement. into ( ) ) ;
1662
+ }
1663
+
1664
+ if let Ok ( label) = self . parse_label ( ) {
1665
+ statements. push ( label. into ( ) ) ;
1666
+ }
1556
1667
1557
- if !self . eat_punctuator ( Punctuator :: CloseCurly ) {
1558
1668
return Err ( ParseError :: new (
1559
- ParseErrorKind :: Misc ( "Expected '}' to close compound statement" ) ,
1669
+ ParseErrorKind :: Misc ( "Expected '}' to end compound statement" ) ,
1560
1670
self . input . peek ( ) . source ,
1561
1671
) ) ;
1562
1672
}
1563
1673
1564
- Ok ( ( ) )
1674
+ Ok ( CompoundStatement { statements } )
1675
+ }
1676
+
1677
+ fn parse_unlabeled_statement ( & mut self ) -> Result < UnlabeledStatement , ParseError > {
1678
+ if let Ok ( expr_statement) = self . parse_expr_statement ( ) {
1679
+ return Ok ( expr_statement. into ( ) ) ;
1680
+ }
1681
+
1682
+ todo ! ( "parse_unlabeled_statement" )
1683
+ }
1684
+
1685
+ fn parse_expr_statement ( & mut self ) -> Result < ExprStatement , ParseError > {
1686
+ if self
1687
+ . input
1688
+ . peek_is ( CTokenKind :: Punctuator ( Punctuator :: Semicolon ) )
1689
+ {
1690
+ return Ok ( ExprStatement :: Empty ) ;
1691
+ }
1692
+
1693
+ let attributes = self . parse_attribute_specifier_sequence ( ) ?;
1694
+
1695
+ return Ok ( ExprStatement :: Normal (
1696
+ attributes,
1697
+ self . parse_expr_multiple ( ) ?,
1698
+ ) ) ;
1699
+ }
1700
+
1701
+ fn parse_label ( & mut self ) -> Result < Label , ParseError > {
1702
+ todo ! ( "parse_label" )
1565
1703
}
1566
1704
1567
1705
fn eat ( & mut self , expected : CTokenKind ) -> bool {
0 commit comments