@@ -584,7 +584,7 @@ pub struct AstNode {
584
584
pub location : SourceLocation ,
585
585
}
586
586
587
- #[ derive( Clone , PartialEq ) ]
587
+ #[ derive( Debug , Clone , PartialEq ) ]
588
588
pub enum AstStatement {
589
589
EmptyStatement ( EmptyStatement ) ,
590
590
// a placeholder that indicates a default value of a datatype
@@ -601,6 +601,7 @@ pub enum AstStatement {
601
601
BinaryExpression ( BinaryExpression ) ,
602
602
UnaryExpression ( UnaryExpression ) ,
603
603
ExpressionList ( Vec < AstNode > ) ,
604
+ ParenExpression ( Box < AstNode > ) ,
604
605
RangeStatement ( RangeStatement ) ,
605
606
VlaRangeStatement ,
606
607
// Assignment
@@ -639,6 +640,9 @@ impl Debug for AstNode {
639
640
AstStatement :: ExpressionList ( expressions) => {
640
641
f. debug_struct ( "ExpressionList" ) . field ( "expressions" , expressions) . finish ( )
641
642
}
643
+ AstStatement :: ParenExpression ( expression) => {
644
+ f. debug_struct ( "ParenExpression" ) . field ( "expression" , expression) . finish ( )
645
+ }
642
646
AstStatement :: RangeStatement ( RangeStatement { start, end } ) => {
643
647
f. debug_struct ( "RangeStatement" ) . field ( "start" , start) . field ( "end" , end) . finish ( )
644
648
}
@@ -860,6 +864,10 @@ impl AstNode {
860
864
)
861
865
}
862
866
867
+ pub fn is_paren ( & self ) -> bool {
868
+ matches ! ( self . stmt, AstStatement :: ParenExpression { .. } )
869
+ }
870
+
863
871
pub fn is_expression_list ( & self ) -> bool {
864
872
matches ! ( self . stmt, AstStatement :: ExpressionList { .. } )
865
873
}
@@ -1012,6 +1020,7 @@ pub fn flatten_expression_list(list: &AstNode) -> Vec<&AstNode> {
1012
1020
AstStatement :: MultipliedStatement ( MultipliedStatement { multiplier, element } , ..) => {
1013
1021
std:: iter:: repeat ( flatten_expression_list ( element) ) . take ( * multiplier as usize ) . flatten ( ) . collect ( )
1014
1022
}
1023
+ AstStatement :: ParenExpression ( expression) => flatten_expression_list ( expression) ,
1015
1024
_ => vec ! [ list] ,
1016
1025
}
1017
1026
}
@@ -1133,6 +1142,10 @@ impl AstFactory {
1133
1142
AstNode { stmt : AstStatement :: ExpressionList ( expressions) , location, id }
1134
1143
}
1135
1144
1145
+ pub fn create_paren_expression ( expression : AstNode , location : SourceLocation , id : AstId ) -> AstNode {
1146
+ AstNode { stmt : AstStatement :: ParenExpression ( Box :: new ( expression) ) , location, id }
1147
+ }
1148
+
1136
1149
/// creates a new if-statement
1137
1150
pub fn create_if_statement (
1138
1151
blocks : Vec < ConditionalBlock > ,
@@ -1500,75 +1513,75 @@ impl AstFactory {
1500
1513
AstNode { stmt : AstStatement :: LabelStatement ( LabelStatement { name } ) , location, id }
1501
1514
}
1502
1515
}
1503
- #[ derive( Clone , PartialEq ) ]
1516
+ #[ derive( Debug , Clone , PartialEq ) ]
1504
1517
pub struct EmptyStatement { }
1505
1518
1506
- #[ derive( Clone , PartialEq ) ]
1519
+ #[ derive( Debug , Clone , PartialEq ) ]
1507
1520
pub struct DefaultValue { }
1508
1521
1509
- #[ derive( Clone , PartialEq ) ]
1522
+ #[ derive( Debug , Clone , PartialEq ) ]
1510
1523
pub struct CastStatement {
1511
1524
pub target : Box < AstNode > ,
1512
1525
pub type_name : String ,
1513
1526
}
1514
1527
1515
- #[ derive( Clone , PartialEq ) ]
1528
+ #[ derive( Debug , Clone , PartialEq ) ]
1516
1529
pub struct MultipliedStatement {
1517
1530
pub multiplier : u32 ,
1518
1531
pub element : Box < AstNode > ,
1519
1532
}
1520
- #[ derive( Clone , PartialEq ) ]
1533
+ #[ derive( Debug , Clone , PartialEq ) ]
1521
1534
pub struct ReferenceExpr {
1522
1535
pub access : ReferenceAccess ,
1523
1536
pub base : Option < Box < AstNode > > ,
1524
1537
}
1525
1538
1526
- #[ derive( Clone , PartialEq ) ]
1539
+ #[ derive( Debug , Clone , PartialEq ) ]
1527
1540
pub struct DirectAccess {
1528
1541
pub access : DirectAccessType ,
1529
1542
pub index : Box < AstNode > ,
1530
1543
}
1531
1544
1532
- #[ derive( Clone , PartialEq ) ]
1545
+ #[ derive( Debug , Clone , PartialEq ) ]
1533
1546
pub struct HardwareAccess {
1534
1547
pub direction : HardwareAccessType ,
1535
1548
pub access : DirectAccessType ,
1536
1549
pub address : Vec < AstNode > ,
1537
1550
}
1538
1551
1539
- #[ derive( Clone , PartialEq ) ]
1552
+ #[ derive( Debug , Clone , PartialEq ) ]
1540
1553
pub struct BinaryExpression {
1541
1554
pub operator : Operator ,
1542
1555
pub left : Box < AstNode > ,
1543
1556
pub right : Box < AstNode > ,
1544
1557
}
1545
1558
1546
- #[ derive( Clone , PartialEq ) ]
1559
+ #[ derive( Debug , Clone , PartialEq ) ]
1547
1560
pub struct UnaryExpression {
1548
1561
pub operator : Operator ,
1549
1562
pub value : Box < AstNode > ,
1550
1563
}
1551
1564
1552
- #[ derive( Clone , PartialEq ) ]
1565
+ #[ derive( Debug , Clone , PartialEq ) ]
1553
1566
pub struct RangeStatement {
1554
1567
pub start : Box < AstNode > ,
1555
1568
pub end : Box < AstNode > ,
1556
1569
}
1557
1570
1558
- #[ derive( Clone , PartialEq ) ]
1571
+ #[ derive( Debug , Clone , PartialEq ) ]
1559
1572
pub struct Assignment {
1560
1573
pub left : Box < AstNode > ,
1561
1574
pub right : Box < AstNode > ,
1562
1575
}
1563
1576
1564
- #[ derive( Clone , PartialEq ) ]
1577
+ #[ derive( Debug , Clone , PartialEq ) ]
1565
1578
pub struct CallStatement {
1566
1579
pub operator : Box < AstNode > ,
1567
1580
pub parameters : Option < Box < AstNode > > ,
1568
1581
}
1569
1582
1570
1583
/// Represents a conditional jump from current location to a specified label
1571
- #[ derive( Clone , Debug , PartialEq ) ]
1584
+ #[ derive( Debug , Clone , PartialEq ) ]
1572
1585
pub struct JumpStatement {
1573
1586
/// The condition based on which the current statement will perform a jump
1574
1587
pub condition : Box < AstNode > ,
@@ -1577,7 +1590,7 @@ pub struct JumpStatement {
1577
1590
}
1578
1591
1579
1592
/// Represents a location in code that could be jumbed to
1580
- #[ derive( Clone , Debug , PartialEq ) ]
1593
+ #[ derive( Debug , Clone , PartialEq ) ]
1581
1594
pub struct LabelStatement {
1582
1595
pub name : String ,
1583
1596
}
0 commit comments