MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / parse_bitwise_shift_expression

Function parse_bitwise_shift_expression

crates/gitql-parser/src/parser.rs:2146–2304  ·  view source on GitHub ↗
(
    context: &mut ParserContext,
    env: &mut Environment,
    tokens: &[Token],
    position: &mut usize,
)

Source from the content-addressed store, hash-verified

2144}
2145
2146fn 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

Callers 1

Calls 11

parse_term_expressionFunction · 0.85
expr_typeMethod · 0.80
containsMethod · 0.80
as_boxedMethod · 0.80
with_locationMethod · 0.80
shr_op_result_typeMethod · 0.45
shl_op_result_typeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…