@@ -130,6 +130,21 @@ let copy_source_dir_files_into_output_dir filename already_opened_fns_and_ocs pr
130130let memory_accesses_injections ail_prog =
131131 let open Cerb_frontend in
132132 let open Cerb_location in
133+ let string_of_aop aop =
134+ match aop with
135+ | AilSyntax. Mul -> " *"
136+ | Div -> " /"
137+ | Mod -> " %"
138+ | Add -> " +"
139+ | Sub -> " -"
140+ | Shl -> " <<"
141+ | Shr -> " >>"
142+ | Band -> " &"
143+ | Bxor -> " ^"
144+ | Bor -> " |"
145+ (* We could use the below here, but it's only the same by coincidence, Pp_ail is not intended to produce C output
146+ CF.Pp_utils.to_plain_string (Pp_ail.pp_arithmeticOperator aop) *)
147+ in
133148 let loc_of_expr (AilSyntax. AnnotatedExpression (_ , _ , loc , _ )) = loc in
134149 let pos_bbox loc =
135150 match bbox [ loc ] with `Other _ -> assert false | `Bbox (b , e ) -> (b, e)
@@ -153,27 +168,36 @@ let memory_accesses_injections ail_prog =
153168 :: (region (pos1, pos2) NoCursor , [ " , " ])
154169 :: (point e, [ " )" ])
155170 :: ! acc
156- | StoreOp { lvalue; aop; expr; _ } ->
157- let b, pos1 = pos_bbox (loc_of_expr lvalue) in
158- let pos2, e = pos_bbox (loc_of_expr expr) in
159- let op_str =
160- match aop with
161- | Mul -> " *"
162- | Div -> " /"
163- | Mod -> " %"
164- | Add -> " +"
165- | Sub -> " -"
166- | Shl -> " <<"
167- | Shr -> " >>"
168- | Band -> " &"
169- | Bxor -> " ^"
170- | Bor -> " |"
171- in
172- acc
173- := (point b, [ " CN_STORE_OP(" ])
174- :: (region (pos1, pos2) NoCursor , [ " ," ^ op_str ^ " ," ])
175- :: (point e, [ " )" ])
176- :: ! acc
171+ | StoreOp { lvalue; aop; expr; loc } ->
172+ (match bbox [ loc_of_expr expr ] with
173+ | `Other _ ->
174+ (* This prettyprinter doesn not produce valid C, but it's
175+ correct for simple expressions and we use it here for
176+ simple literals *)
177+ let pp_expr e = CF.Pp_utils. to_plain_string (Pp_ail. pp_expression e) in
178+ let sstart, ssend = pos_bbox loc in
179+ let b, _ = pos_bbox (loc_of_expr lvalue) in
180+ acc
181+ := (region (sstart, b) NoCursor , [ " " ])
182+ :: ( point b,
183+ [ " CN_STORE_OP("
184+ ^ pp_expr lvalue
185+ ^ " ,"
186+ ^ string_of_aop aop
187+ ^ " ,"
188+ ^ pp_expr expr
189+ ^ " )"
190+ ] )
191+ :: (region (b, ssend) NoCursor , [ " " ])
192+ :: ! acc
193+ | `Bbox _ ->
194+ let b, pos1 = pos_bbox (loc_of_expr lvalue) in
195+ let pos2, e = pos_bbox (loc_of_expr expr) in
196+ acc
197+ := (point b, [ " CN_STORE_OP(" ])
198+ :: (region (pos1, pos2) NoCursor , [ " ," ^ string_of_aop aop ^ " ," ])
199+ :: (point e, [ " )" ])
200+ :: ! acc)
177201 | Postfix { loc; op; lvalue } ->
178202 let op_str = match op with `Incr -> " ++" | `Decr -> " --" in
179203 let b, e = pos_bbox loc in
0 commit comments