@ -51,6 +51,47 @@ let assignment_arc_mode context e1 typ e2 loc rhs_owning_method is_e1_decl =
( e1 , [ retain ; autorelease ; assign ] , [] )
( e1 , [ retain ; autorelease ; assign ] , [] )
| _ -> ( e1 , [ assign ] , [] )
| _ -> ( e1 , [ assign ] , [] )
(* Returns a pair ( [binary_expression], instructions ) for binary operator representing a *)
(* CompoundAssignment. "binary_expression" is returned when we are calculating an expression *)
(* "instructions" is not empty when the binary operator is actually a statement like an *)
(* assignment. *)
let compound_assignment_binary_operation_instruction boi e1 typ e2 loc =
let id = Ident . create_fresh Ident . knormal in
let instr1 = Sil . Letderef ( id , e1 , typ , loc ) in
let e_res , instr_op = match boi . Clang_ast_t . boi_kind with
| ` AddAssign ->
let e1_plus_e2 = Sil . BinOp ( Sil . PlusA , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_plus_e2 , loc ) ] )
| ` SubAssign ->
let e1_sub_e2 = Sil . BinOp ( Sil . MinusA , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_sub_e2 , loc ) ] )
| ` MulAssign ->
let e1_mul_e2 = Sil . BinOp ( Sil . Mult , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_mul_e2 , loc ) ] )
| ` DivAssign ->
let e1_div_e2 = Sil . BinOp ( Sil . Div , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_div_e2 , loc ) ] )
| ` ShlAssign ->
let e1_shl_e2 = Sil . BinOp ( Sil . Shiftlt , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_shl_e2 , loc ) ] )
| ` ShrAssign ->
let e1_shr_e2 = Sil . BinOp ( Sil . Shiftrt , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_shr_e2 , loc ) ] )
| ` RemAssign ->
let e1_mod_e2 = Sil . BinOp ( Sil . Mod , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_mod_e2 , loc ) ] )
| ` AndAssign ->
let e1_and_e2 = Sil . BinOp ( Sil . BAnd , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_and_e2 , loc ) ] )
| ` OrAssign ->
let e1_or_e2 = Sil . BinOp ( Sil . BOr , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_or_e2 , loc ) ] )
| ` XorAssign ->
let e1_xor_e2 = Sil . BinOp ( Sil . BXor , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_xor_e2 , loc ) ] )
| bok -> assert false in
( e_res , instr1 :: instr_op , [ id ] )
(* Returns a pair ( [binary_expression], instructions ) . "binary_expression" *)
(* Returns a pair ( [binary_expression], instructions ) . "binary_expression" *)
(* is returned when we are calculating an expression "instructions" is not *)
(* is returned when we are calculating an expression "instructions" is not *)
(* empty when the binary operator is actually a statement like an *)
(* empty when the binary operator is actually a statement like an *)
@ -84,7 +125,7 @@ let binary_operation_instruction context boi e1 typ e2 loc rhs_owning_method =
| ` Comma -> ( e2 , [] , [] ) (* C99 6.5.17-2 *)
| ` Comma -> ( e2 , [] , [] ) (* C99 6.5.17-2 *)
| ` MulAssign | ` DivAssign | ` RemAssign | ` AddAssign | ` SubAssign
| ` MulAssign | ` DivAssign | ` RemAssign | ` AddAssign | ` SubAssign
| ` ShlAssign | ` ShrAssign | ` AndAssign | ` XorAssign | ` OrAssign ->
| ` ShlAssign | ` ShrAssign | ` AndAssign | ` XorAssign | ` OrAssign ->
assert false
compound_assignment_binary_operation_instruction boi e1 typ e2 loc
(* We should not get here. *)
(* We should not get here. *)
(* These should be treated by compound_assignment_binary_operation_instruction *)
(* These should be treated by compound_assignment_binary_operation_instruction *)
| bok ->
| bok ->
@ -93,50 +134,6 @@ let binary_operation_instruction context boi e1 typ e2 loc rhs_owning_method =
( Clang_ast_j . string_of_binary_operator_kind bok ) ;
( Clang_ast_j . string_of_binary_operator_kind bok ) ;
( Sil . exp_minus_one , [] , [] )
( Sil . exp_minus_one , [] , [] )
(* Returns a pair ( [binary_expression], instructions ) for binary operator representing a CompoundAssignment. *)
(* "binary_expression" is returned when we are calculating an expression *)
(* "instructions" is not empty when the binary operator is actually a statement like an assignment. *)
let compound_assignment_binary_operation_instruction boi e1 typ e2 loc =
let id = Ident . create_fresh Ident . knormal in
let instr1 = Sil . Letderef ( id , e1 , typ , loc ) in
let e_res , instr_op = match boi . Clang_ast_t . boi_kind with
| ` AddAssign ->
let e1_plus_e2 = Sil . BinOp ( Sil . PlusA , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_plus_e2 , loc ) ] )
| ` SubAssign ->
let e1_sub_e2 = Sil . BinOp ( Sil . MinusA , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_sub_e2 , loc ) ] )
| ` MulAssign ->
let e1_mul_e2 = Sil . BinOp ( Sil . Mult , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_mul_e2 , loc ) ] )
| ` DivAssign ->
let e1_div_e2 = Sil . BinOp ( Sil . Div , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_div_e2 , loc ) ] )
| ` ShlAssign ->
let e1_shl_e2 = Sil . BinOp ( Sil . Shiftlt , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_shl_e2 , loc ) ] )
| ` ShrAssign ->
let e1_shr_e2 = Sil . BinOp ( Sil . Shiftrt , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_shr_e2 , loc ) ] )
| ` RemAssign ->
let e1_mod_e2 = Sil . BinOp ( Sil . Mod , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_mod_e2 , loc ) ] )
| ` AndAssign ->
let e1_and_e2 = Sil . BinOp ( Sil . BAnd , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_and_e2 , loc ) ] )
| ` OrAssign ->
let e1_or_e2 = Sil . BinOp ( Sil . BOr , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_or_e2 , loc ) ] )
| ` XorAssign ->
let e1_xor_e2 = Sil . BinOp ( Sil . BXor , Sil . Var id , e2 ) in
( e1 , [ Sil . Set ( e1 , typ , e1_xor_e2 , loc ) ] )
| bok ->
Printing . log_stats
" \n WARNING: Missing translation for CompoundAssignment Binary Operator Kind %s. Construct ignored... \n "
( Clang_ast_j . string_of_binary_operator_kind bok ) ;
( Sil . exp_minus_one , [] ) in
( [ id ] , e_res , instr1 :: instr_op )
let unary_operation_instruction uoi e typ loc =
let unary_operation_instruction uoi e typ loc =
let uok = Clang_ast_j . string_of_unary_operator_kind ( uoi . Clang_ast_t . uoi_kind ) in
let uok = Clang_ast_j . string_of_unary_operator_kind ( uoi . Clang_ast_t . uoi_kind ) in
let un_exp op =
let un_exp op =