@@ -513,60 +513,46 @@ impl<'c> Translation<'c> {
513513 }
514514
515515 // Everything else
516- AssignAdd if pointer_lhs. is_some ( ) => {
517- let mul = self . compute_size_of_expr ( pointer_lhs . unwrap ( ) . ctype ) ;
518- let ptr = pointer_offset ( write. clone ( ) , rhs , mul , false , false ) ;
519- WithStmts :: new_unsafe_val ( mk ( ) . assign_expr ( write , ptr ) )
520- }
521- AssignSubtract if pointer_lhs . is_some ( ) => {
522- let mul = self . compute_size_of_expr ( pointer_lhs . unwrap ( ) . ctype ) ;
523- let ptr = pointer_offset ( write . clone ( ) , rhs , mul , true , false ) ;
524- WithStmts :: new_unsafe_val ( mk ( ) . assign_expr ( write, ptr) )
516+ AssignAdd | AssignSubtract if pointer_lhs. is_some ( ) => {
517+ let ptr = self . convert_pointer_offset (
518+ write. clone ( ) ,
519+ rhs ,
520+ pointer_lhs . unwrap ( ) . ctype ,
521+ op == AssignSubtract ,
522+ false ,
523+ ) ;
524+ ptr . map ( |ptr| mk ( ) . assign_expr ( write, ptr) )
525525 }
526526
527527 _ => {
528- if let ( AssignAdd | AssignSubtract , Some ( pointer_lhs) ) =
529- ( op, pointer_lhs)
530- {
531- let mul = self . compute_size_of_expr ( pointer_lhs. ctype ) ;
532- let ptr = pointer_offset (
533- write. clone ( ) ,
534- rhs,
535- mul,
536- op == AssignSubtract ,
537- false ,
538- ) ;
539- WithStmts :: new_unsafe_val ( mk ( ) . assign_expr ( write, ptr) )
540- } else {
541- fn eq < Token : Default , F : Fn ( Token ) -> BinOp > ( f : F ) -> BinOp {
542- f ( Default :: default ( ) )
543- }
544-
545- let ( bin_op, bin_op_kind) = match op {
546- AssignAdd => ( Add , eq ( BinOp :: AddAssign ) ) ,
547- AssignSubtract => ( Subtract , eq ( BinOp :: SubAssign ) ) ,
548- AssignMultiply => ( Multiply , eq ( BinOp :: MulAssign ) ) ,
549- AssignDivide => ( Divide , eq ( BinOp :: DivAssign ) ) ,
550- AssignModulus => ( Modulus , eq ( BinOp :: RemAssign ) ) ,
551- AssignBitXor => ( BitXor , eq ( BinOp :: BitXorAssign ) ) ,
552- AssignShiftLeft => ( ShiftLeft , eq ( BinOp :: ShlAssign ) ) ,
553- AssignShiftRight => ( ShiftRight , eq ( BinOp :: ShrAssign ) ) ,
554- AssignBitOr => ( BitOr , eq ( BinOp :: BitOrAssign ) ) ,
555- AssignBitAnd => ( BitAnd , eq ( BinOp :: BitAndAssign ) ) ,
556- _ => panic ! ( "Cannot convert non-assignment operator" ) ,
557- } ;
558- self . convert_assignment_operator_aux (
559- bin_op_kind,
560- bin_op,
561- read. clone ( ) ,
562- write,
563- rhs,
564- compute_lhs_type_id. unwrap ( ) ,
565- compute_res_type_id. unwrap ( ) ,
566- expr_type_id,
567- rhs_type_id,
568- ) ?
528+ fn eq < Token : Default , F : Fn ( Token ) -> BinOp > ( f : F ) -> BinOp {
529+ f ( Default :: default ( ) )
569530 }
531+
532+ let ( bin_op, bin_op_kind) = match op {
533+ AssignAdd => ( Add , eq ( BinOp :: AddAssign ) ) ,
534+ AssignSubtract => ( Subtract , eq ( BinOp :: SubAssign ) ) ,
535+ AssignMultiply => ( Multiply , eq ( BinOp :: MulAssign ) ) ,
536+ AssignDivide => ( Divide , eq ( BinOp :: DivAssign ) ) ,
537+ AssignModulus => ( Modulus , eq ( BinOp :: RemAssign ) ) ,
538+ AssignBitXor => ( BitXor , eq ( BinOp :: BitXorAssign ) ) ,
539+ AssignShiftLeft => ( ShiftLeft , eq ( BinOp :: ShlAssign ) ) ,
540+ AssignShiftRight => ( ShiftRight , eq ( BinOp :: ShrAssign ) ) ,
541+ AssignBitOr => ( BitOr , eq ( BinOp :: BitOrAssign ) ) ,
542+ AssignBitAnd => ( BitAnd , eq ( BinOp :: BitAndAssign ) ) ,
543+ _ => panic ! ( "Cannot convert non-assignment operator" ) ,
544+ } ;
545+ self . convert_assignment_operator_aux (
546+ bin_op_kind,
547+ bin_op,
548+ read. clone ( ) ,
549+ write,
550+ rhs,
551+ compute_lhs_type_id. unwrap ( ) ,
552+ compute_res_type_id. unwrap ( ) ,
553+ expr_type_id,
554+ rhs_type_id,
555+ ) ?
570556 }
571557 } ;
572558
@@ -698,15 +684,9 @@ impl<'c> Translation<'c> {
698684 let rhs_type = & self . ast_context . resolve_type ( rhs_type_id. ctype ) . kind ;
699685
700686 if let & CTypeKind :: Pointer ( pointee) = lhs_type {
701- let mul = self . compute_size_of_expr ( pointee. ctype ) ;
702- Ok ( WithStmts :: new_unsafe_val ( pointer_offset (
703- lhs, rhs, mul, false , false ,
704- ) ) )
687+ Ok ( self . convert_pointer_offset ( lhs, rhs, pointee. ctype , false , false ) )
705688 } else if let & CTypeKind :: Pointer ( pointee) = rhs_type {
706- let mul = self . compute_size_of_expr ( pointee. ctype ) ;
707- Ok ( WithStmts :: new_unsafe_val ( pointer_offset (
708- rhs, lhs, mul, false , false ,
709- ) ) )
689+ Ok ( self . convert_pointer_offset ( rhs, lhs, pointee. ctype , false , false ) )
710690 } else if lhs_type. is_unsigned_integral_type ( ) {
711691 Ok ( WithStmts :: new_val ( mk ( ) . method_call_expr (
712692 lhs,
@@ -743,10 +723,7 @@ impl<'c> Translation<'c> {
743723
744724 Ok ( WithStmts :: new_unsafe_val ( mk ( ) . cast_expr ( offset, ty) ) )
745725 } else if let & CTypeKind :: Pointer ( pointee) = lhs_type {
746- let mul = self . compute_size_of_expr ( pointee. ctype ) ;
747- Ok ( WithStmts :: new_unsafe_val ( pointer_offset (
748- lhs, rhs, mul, true , false ,
749- ) ) )
726+ Ok ( self . convert_pointer_offset ( lhs, rhs, pointee. ctype , true , false ) )
750727 } else if lhs_type. is_unsigned_integral_type ( ) {
751728 Ok ( WithStmts :: new_val ( mk ( ) . method_call_expr (
752729 lhs,
0 commit comments