let rec find_function_value f arg =
(*
First, let us find the " value of arg if this is a set.
*)
let arg_real =
List.map
(function
If_function(g,l) -> find_function_value g l
| a -> a)
arg
in
let nb_args = List.length arg_real in
(*
We know that the value of [f] is a pointer to a set containing a couple whose first argument
is [arg_real]. First, let us retrieve this set. We currently handle only the case where
the function is a variable or a constant. In this last case, we consider the constant to be the pointer itself.
whenever this processus fails, we raise an exception.
*)
let set_of_definition =
match f with
If_address set_addr ->
get_value set_addr
| If_const pointer ->
(Globals.value_table#get_value
(Globals.memory_map#get_map
(Globals.global_var_id#get_id_of 0 pointer)))
| _ -> raise Not_found
in
match set_of_definition with
(* If_lst l *)
If_set l ->
(*
We have found a set [l] that should contain the association between a point
and its value. Each element of [l] should be a pair (arg,value).
*)
(* let association_list =
(List.map
(fun element ->
match element with
* If_lst(l2)*
If_set(l2) ->
let rec find_val r_a = function
[If_function(g,l3)] -> (r_a, find_function_value g l3)
| [a] -> (r_a, a)
| If_function(g,l3)::la ->
find_val (r_a@[find_function_value g l3]) la
| a::la ->
find_val (r_a@[a]) la
| [] -> raise Not_found
in
find_val [] l2
| _ -> raise Not_found)
l)*)
let association_list =
(List.map
(fun element ->
let rec find_val r_a = function
0 ->
(function
If_function(g,l2) ->
(r_a, find_function_value g l2)
| t2 ->
(r_a, t2))
| n ->
(function
If_pair(If_function(g,l2),t2) ->
find_val (r_a@[find_function_value g l2]) (n-1) t2
| If_pair(t1,t2) ->
find_val (r_a@[t1]) (n-1) t2
| _ -> raise Not_found)
in
find_val [] nb_args element)
l)
in
List.assoc arg_real association_list
| _ -> raise Not_found