Skip to content

Commit 0dff123

Browse files
peterohanley-galoisZippeyKeys12
authored andcommitted
[CN-Exec] Do not inject synthesized terms
They don't have source locations.
1 parent 4c861f1 commit 0dff123

File tree

4 files changed

+48
-24
lines changed

4 files changed

+48
-24
lines changed

cn.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ depends: [
2323
"zarith" {>= "1.13"}
2424
]
2525
pin-depends: [
26-
["cerberus-lib.dev" "git+https://github.com/rems-project/cerberus.git#ef237b3"]
26+
["cerberus-lib.dev" "git+https://github.com/rems-project/cerberus.git#6e3e8be"]
2727
]
2828
build: [
2929
["dune" "subst"] {pinned}

lib/fulminate/fulminate.ml

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ let copy_source_dir_files_into_output_dir filename already_opened_fns_and_ocs pr
130130
let 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
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
return code: 2
22
tests/cn/list_literal_type.error.c:3:15: error: unexpected token after 'list' and before '<'
3-
Please add error message for state 1844 to parsers/c/c_parser_error.messages
3+
Please add error message for state 1846 to parsers/c/c_parser_error.messages
44
function (list<integer>) nonempty_list() {
55
^
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
return code: 2
22
tests/cn/tree16/as_auto_mutual_dt/tree16.error.c:30:21: error: unexpected token after 'list' and before '<'
3-
Please add error message for state 1014 to parsers/c/c_parser_error.messages
3+
Please add error message for state 1016 to parsers/c/c_parser_error.messages
44
Node {i32 v, list <datatype tree> children}
55
^

0 commit comments

Comments
 (0)