(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 1768 | } |
| 1769 | |
| 1770 | fn parse_bitwise_xor_expression( |
| 1771 | context: &mut ParserContext, |
| 1772 | env: &mut Environment, |
| 1773 | tokens: &[Token], |
| 1774 | position: &mut usize, |
| 1775 | ) -> Result<Box<dyn Expr>, Box<Diagnostic>> { |
| 1776 | let mut lhs = parse_logical_xor_expression(context, env, tokens, position)?; |
| 1777 | |
| 1778 | 'parse_expr: while is_current_token(tokens, position, TokenKind::BitwiseXor) { |
| 1779 | let operator = &tokens[*position]; |
| 1780 | |
| 1781 | // Consume`#` operator |
| 1782 | *position += 1; |
| 1783 | |
| 1784 | let rhs = parse_logical_xor_expression(context, env, tokens, position)?; |
| 1785 | |
| 1786 | let lhs_type = lhs.expr_type(); |
| 1787 | let rhs_type = rhs.expr_type(); |
| 1788 | |
| 1789 | let expected_rhs_types = lhs_type.can_perform_xor_op_with(); |
| 1790 | |
| 1791 | // Can perform this operator between LHS and RHS |
| 1792 | if expected_rhs_types.contains(&rhs_type) { |
| 1793 | lhs = Box::new(BitwiseExpr { |
| 1794 | left: lhs, |
| 1795 | operator: BinaryBitwiseOperator::Xor, |
| 1796 | right: rhs, |
| 1797 | result_type: lhs_type.xor_op_result_type(&rhs_type), |
| 1798 | }); |
| 1799 | |
| 1800 | continue 'parse_expr; |
| 1801 | } |
| 1802 | |
| 1803 | // Check if RHS expr can be implicit casted to Expected LHS type to make this |
| 1804 | // Expression valid |
| 1805 | for expected_type in expected_rhs_types.iter() { |
| 1806 | if !expected_type.has_implicit_cast_from(&rhs) { |
| 1807 | continue; |
| 1808 | } |
| 1809 | |
| 1810 | let casting = Box::new(CastExpr { |
| 1811 | value: rhs, |
| 1812 | result_type: expected_type.clone(), |
| 1813 | }); |
| 1814 | |
| 1815 | lhs = Box::new(BitwiseExpr { |
| 1816 | left: lhs, |
| 1817 | operator: BinaryBitwiseOperator::Xor, |
| 1818 | right: casting, |
| 1819 | result_type: lhs_type.or_op_result_type(expected_type), |
| 1820 | }); |
| 1821 | |
| 1822 | continue 'parse_expr; |
| 1823 | } |
| 1824 | |
| 1825 | // Check if LHS expr can be implicit casted to Expected RHS type to make this |
| 1826 | // Expression valid |
| 1827 | let expected_lhs_types = rhs_type.can_perform_xor_op_with(); |
no test coverage detected
searching dependent graphs…