/// Translate a non-assignment binary operator. It is expected that the `lhs` and `rhs`
/// arguments be usable as rvalues.
Translate a non-assignment binary operator. It is expected that the `lhs` and `rhs`
arguments be usable as rvalues.
Translate a non - assignment binary operator . It is expected that the ` lhs ` and ` rhs ` arguments be usable as rvalues .
fn convert_binary_operator(
        &self,
        op: c_ast::BinOp,
        ty: P<Ty>,
        ctype: CTypeId,
        lhs_type: CQualTypeId,
        rhs_type: CQualTypeId,
        lhs: P<Expr>,
        rhs: P<Expr>,
    ) -> P<Expr> {
        let is_unsigned_integral_type = self.ast_context.index(ctype).kind.is_unsigned_integral_type();
        match op {
            c_ast::BinOp::Add => self.convert_addition(lhs_type, rhs_type, lhs, rhs),
            c_ast::BinOp::Subtract => self.convert_subtraction(ty, lhs_type, rhs_type, lhs, rhs),
            c_ast::BinOp::Multiply if is_unsigned_integral_type =>
                mk().method_call_expr(lhs, mk().path_segment("wrapping_mul"), vec![rhs]),
            c_ast::BinOp::Multiply => mk().binary_expr(BinOpKind::Mul, lhs, rhs),
            c_ast::BinOp::Divide if is_unsigned_integral_type =>
                mk().method_call_expr(lhs, mk().path_segment("wrapping_div"), vec![rhs]),
            c_ast::BinOp::Divide => mk().binary_expr(BinOpKind::Div, lhs, rhs),
            c_ast::BinOp::Modulus if is_unsigned_integral_type =>
                mk().method_call_expr(lhs, mk().path_segment("wrapping_rem"), vec![rhs]),
            c_ast::BinOp::Modulus => mk().binary_expr(BinOpKind::Rem, lhs, rhs),
            c_ast::BinOp::BitXor => mk().binary_expr(BinOpKind::BitXor, lhs, rhs),
            c_ast::BinOp::ShiftRight => mk().binary_expr(BinOpKind::Shr, lhs, rhs),
            c_ast::BinOp::ShiftLeft => mk().binary_expr(BinOpKind::Shl, lhs, rhs),
            c_ast::BinOp::EqualEqual => bool_to_int(mk().binary_expr(BinOpKind::Eq, lhs, rhs)),
            c_ast::BinOp::NotEqual => bool_to_int(mk().binary_expr(BinOpKind::Ne, lhs, rhs)),
            c_ast::BinOp::Less => bool_to_int(mk().binary_expr(BinOpKind::Lt, lhs, rhs)),
            c_ast::BinOp::Greater => bool_to_int(mk().binary_expr(BinOpKind::Gt, lhs, rhs)),
            c_ast::BinOp::GreaterEqual => bool_to_int(mk().binary_expr(BinOpKind::Ge, lhs, rhs)),
            c_ast::BinOp::LessEqual => bool_to_int(mk().binary_expr(BinOpKind::Le, lhs, rhs)),
            c_ast::BinOp::BitAnd => mk().binary_expr(BinOpKind::BitAnd, lhs, rhs),
            c_ast::BinOp::BitOr => mk().binary_expr(BinOpKind::BitOr, lhs, rhs),
            op => unimplemented!("Translation of binary operator {:?}", op),
        }
    }
fn convert_binary_operator ( & self , op : c_ast :: BinOp , ty : P < Ty > , ctype : CTypeId , lhs_type : CQualTypeId , rhs_type : CQualTypeId , lhs : P < Expr > , rhs : P < Expr > , ) -> P < Expr > { let is_unsigned_integral_type = self . ast_context . index ( ctype ) . kind . is_unsigned_integral_type ( ) ; match op { c_ast :: BinOp :: Add => self . convert_addition ( lhs_type , rhs_type , lhs , rhs ) , c_ast :: BinOp :: Subtract => self . convert_subtraction ( ty , lhs_type , rhs_type , lhs , rhs ) , c_ast :: BinOp :: Multiply if is_unsigned_integral_type => mk ( ) . method_call_expr ( lhs , mk ( ) . path_segment ( " " ) , vec ! [ rhs ] ) , c_ast :: BinOp :: Multiply => mk ( ) . binary_expr ( BinOpKind :: Mul , lhs , rhs ) , c_ast :: BinOp :: Divide if is_unsigned_integral_type => mk ( ) . method_call_expr ( lhs , mk ( ) . path_segment ( " " ) , vec ! [ rhs ] ) , c_ast :: BinOp :: Divide => mk ( ) . binary_expr ( BinOpKind :: Div , lhs , rhs ) , c_ast :: BinOp :: Modulus if is_unsigned_integral_type => mk ( ) . method_call_expr ( lhs , mk ( ) . path_segment ( " " ) , vec ! [ rhs ] ) , c_ast :: BinOp :: Modulus => mk ( ) . binary_expr ( BinOpKind :: Rem , lhs , rhs ) , c_ast :: BinOp :: BitXor => mk ( ) . binary_expr ( BinOpKind :: BitXor , lhs , rhs ) , c_ast :: BinOp :: ShiftRight => mk ( ) . binary_expr ( BinOpKind :: Shr , lhs , rhs ) , c_ast :: BinOp :: ShiftLeft => mk ( ) . binary_expr ( BinOpKind :: Shl , lhs , rhs ) , c_ast :: BinOp :: EqualEqual => bool_to_int ( mk ( ) . binary_expr ( BinOpKind :: Eq , lhs , rhs ) ) , c_ast :: BinOp :: NotEqual => bool_to_int ( mk ( ) . binary_expr ( BinOpKind :: Ne , lhs , rhs ) ) , c_ast :: BinOp :: Less => bool_to_int ( mk ( ) . binary_expr ( BinOpKind :: Lt , lhs , rhs ) ) , c_ast :: BinOp :: Greater => bool_to_int ( mk ( ) . binary_expr ( BinOpKind :: Gt , lhs , rhs ) ) , c_ast :: BinOp :: GreaterEqual => bool_to_int ( mk ( ) . binary_expr ( BinOpKind :: Ge , lhs , rhs ) ) , c_ast :: BinOp :: LessEqual => bool_to_int ( mk ( ) . binary_expr ( BinOpKind :: Le , lhs , rhs ) ) , c_ast :: BinOp :: BitAnd => mk ( ) . binary_expr ( BinOpKind :: BitAnd , lhs , rhs ) , c_ast :: BinOp :: BitOr => mk ( ) . binary_expr ( BinOpKind :: BitOr , lhs , rhs ) , op => unimplemented ! ( " " op ) , } }
Translate a non-assignment binary operator.
Translate a non - assignment binary operator .
&self
op
c_ast::BinOp
ty
P<Ty>
ctype
CTypeId
lhs_type
CQualTypeId
rhs_type
CQualTypeId
lhs
P<Expr>
rhs
P<Expr>