(
context: &mut ParserContext,
env: &mut Environment,
tokens: &[Token],
position: &mut usize,
)
| 2144 | } |
| 2145 | |
| 2146 | fn parse_bitwise_shift_expression( |
| 2147 | context: &mut ParserContext, |
| 2148 | env: &mut Environment, |
| 2149 | tokens: &[Token], |
| 2150 | position: &mut usize, |
| 2151 | ) -> Result<Box<dyn Expr>, Box<Diagnostic>> { |
| 2152 | let mut lhs = parse_term_expression(context, env, tokens, position)?; |
| 2153 | |
| 2154 | 'parse_expr: while is_bitwise_shift_operator(tokens, position) { |
| 2155 | let operator = &tokens[*position]; |
| 2156 | |
| 2157 | // Consume `<<` or `>>` operator |
| 2158 | *position += 1; |
| 2159 | |
| 2160 | let rhs = parse_term_expression(context, env, tokens, position)?; |
| 2161 | let lhs_type = lhs.expr_type(); |
| 2162 | let rhs_type = rhs.expr_type(); |
| 2163 | |
| 2164 | // Parse and Check sides for `<<` operator |
| 2165 | if operator.kind == TokenKind::BitwiseRightShift { |
| 2166 | let expected_rhs_types = lhs_type.can_perform_shr_op_with(); |
| 2167 | |
| 2168 | // Can perform this operator between LHS and RHS |
| 2169 | if expected_rhs_types.contains(&rhs_type) { |
| 2170 | lhs = Box::new(BitwiseExpr { |
| 2171 | left: lhs, |
| 2172 | operator: BinaryBitwiseOperator::RightShift, |
| 2173 | right: rhs, |
| 2174 | result_type: rhs_type.shr_op_result_type(&rhs_type), |
| 2175 | }); |
| 2176 | |
| 2177 | continue 'parse_expr; |
| 2178 | } |
| 2179 | |
| 2180 | // Check if RHS expr can be implicit casted to Expected LHS type to make this |
| 2181 | // Expression valid |
| 2182 | for expected_type in expected_rhs_types.iter() { |
| 2183 | if !expected_type.has_implicit_cast_from(&rhs) { |
| 2184 | continue; |
| 2185 | } |
| 2186 | |
| 2187 | let casting = Box::new(CastExpr { |
| 2188 | value: rhs, |
| 2189 | result_type: expected_type.clone(), |
| 2190 | }); |
| 2191 | |
| 2192 | lhs = Box::new(BitwiseExpr { |
| 2193 | left: lhs, |
| 2194 | operator: BinaryBitwiseOperator::RightShift, |
| 2195 | right: casting, |
| 2196 | result_type: lhs_type.shr_op_result_type(expected_type), |
| 2197 | }); |
| 2198 | |
| 2199 | continue 'parse_expr; |
| 2200 | } |
| 2201 | |
| 2202 | // Check if LHS expr can be implicit casted to Expected RHS type to make this |
| 2203 | // Expression valid |
no test coverage detected
searching dependent graphs…