let rec by_ptr_reference x n calls =
let s = "[by_ptr_reference]" in
debug "%s %a of arity %d" s pp_var_type x n;
match calls with
| [] ->
debug "%s %a: ok " s pp_var_type x;
oracle "%s %a ByPref" s pp_var_type x;
ByPReference.replace x (n,[])
| (k,(b,Prop))::m ->
let sb = string_addr b in
debug "%s %a: (builtin,%d,%s)" s pp_var_type x k sb;
if k <= n then
(debug "%s arity of call ok" s; decr_addr_taken_bool x b;
by_ptr_reference x n m)
else
(debug "%s arity of call too big" s; remove_ptr_reference_param x)
| (k,(b,p))::m ->
let bv = ByValue.mem p in let ba = ByAReference.mem p in
let c = k > n in let sb = string_addr b in
if c || bv || ba then
(debug "%s: KO %a ByValue:%b ; Aref : %b; call arity:%b"
s pp_var_type p bv bv c ; remove_ptr_reference_param x)
else
(debug "%s: OK %a ByValue:%b ; Aref : %b; call ari:%b; with %s"
s pp_var_type p bv ba c sb ;
try (match ByPReference.find p with
| (i,[]) ->
debug "%s %a already resolved ; arity :%d"
s pp_var_type p i;
if k <= i then
(debug"%s arity OK" s; decr_addr_taken_bool x b;
by_ptr_reference x n m)
else
(debug "%s arity KO %a with %d and %a with %d used %d"
s pp_var_type x n pp_var_type p i k;
remove_ptr_reference_param x )
| (i,lp) ->
debug "%s %a has to be resolved; with %d used %d"
s pp_var_type p i k;
if k <= i then
(by_ptr_reference p i lp;
by_ptr_reference x n ((k,(b,p))::m))
else remove_ptr_reference_param x
)
with Not_found ->
debug "%s %a NOT in PRef param" s pp_var_type p;
let i = stars_var_type_typ p in
add_ptr_reference_param p i;
if not (ByPReference.mem p) || ByValue.mem p
then remove_ptr_reference_param x
else by_ptr_reference x n ((k,(b,p))::m))