Skip to content

Commit 6b3114e

Browse files
committed
Further cleanup of ownership injections
1 parent 1b830b1 commit 6b3114e

File tree

1 file changed

+22
-39
lines changed

1 file changed

+22
-39
lines changed

lib/fulminate/executable_spec_internal.ml

+22-39
Original file line numberDiff line numberDiff line change
@@ -119,49 +119,32 @@ let generate_c_specs_internal
119119
(modify_magic_comment_loc loc, generate_ail_stat_strs bs_and_ss))
120120
ail_executable_spec.in_stmt
121121
in
122-
let rec split_return_and_non_return_injs rs nrs = function
123-
| [] -> (rs, nrs)
122+
let rec get_return_and_non_return_injs return_ownership_stmts block_ownership_stmts
123+
= function
124+
| [] -> (return_ownership_stmts, block_ownership_stmts)
124125
| (inj : OE.ownership_injection) :: injs ->
126+
let strs = generate_ail_stat_strs ~with_newline:true inj.bs_and_ss in
125127
(match inj.injection_kind with
126-
| OE.ReturnInj _ -> split_return_and_non_return_injs (inj :: rs) nrs injs
127-
| NonReturnInj -> split_return_and_non_return_injs rs (inj :: nrs) injs)
128-
in
129-
let return_injs, non_return_injs =
130-
split_return_and_non_return_injs [] [] block_ownership_injs
131-
in
132-
let block_ownership_stmts =
133-
List.map
134-
(fun (ownership_inj : OE.ownership_injection) ->
135-
( ownership_inj.loc,
136-
generate_ail_stat_strs ~with_newline:true ownership_inj.bs_and_ss ))
137-
non_return_injs
138-
in
139-
let block_ownership_stmts =
140-
List.map (fun (loc, strs) -> (loc, [ String.concat "\n" strs ])) block_ownership_stmts
141-
in
142-
let return_ownership_stmts =
143-
List.map
144-
(fun (ownership_inj : OE.ownership_injection) ->
145-
let return_kind =
146-
match ownership_inj.injection_kind with
147-
| OE.ReturnInj r -> r
148-
| NonReturnInj ->
149-
failwith
150-
(__LOC__
151-
^ "Non-return injection should have been filtered out by this point")
152-
in
128+
| OE.ReturnInj return_kind ->
153129
let return_inj_expr_opt =
154-
match return_kind with OE.ReturnExpr e -> Some e | ReturnVoid -> None
130+
match return_kind with ReturnExpr e -> Some e | ReturnVoid -> None
155131
in
156-
( ownership_inj.loc,
157-
return_inj_expr_opt,
158-
generate_ail_stat_strs ~with_newline:true ownership_inj.bs_and_ss ))
159-
return_injs
160-
in
161-
let return_ownership_stmts =
162-
List.map
163-
(fun (loc, e_opt, strs) -> (loc, (e_opt, [ String.concat "\n" strs ])))
164-
return_ownership_stmts
132+
let return_ownership_stmt =
133+
(inj.loc, (return_inj_expr_opt, [ String.concat "\n" strs ]))
134+
in
135+
get_return_and_non_return_injs
136+
(return_ownership_stmt :: return_ownership_stmts)
137+
block_ownership_stmts
138+
injs
139+
| NonReturnInj ->
140+
let block_ownership_stmt = (inj.loc, [ String.concat "\n" strs ]) in
141+
get_return_and_non_return_injs
142+
return_ownership_stmts
143+
(block_ownership_stmt :: block_ownership_stmts)
144+
injs)
145+
in
146+
let return_ownership_stmts, block_ownership_stmts =
147+
get_return_and_non_return_injs [] [] block_ownership_injs
165148
in
166149
let loop_invariant_injs =
167150
if without_loop_invariants then

0 commit comments

Comments
 (0)