let update_dummy_vars lhs rhs lgid =
let primed_terms =
let rec get_fresh_terms lt = function
Pair(t1,t2)
| Scrypt(t1,t2)
| Crypt(t1,t2)
| Cons(t1,t2)
| Delete(t1,t2) ->
get_fresh_terms (get_fresh_terms lt t1) t2
| Inv(t) ->
get_fresh_terms lt t
| Function(t1,l) ->
List.fold_left
get_fresh_terms
(get_fresh_terms lt t1)
l
| Set(l) ->
List.fold_left get_fresh_terms lt l
| Prime(Var(x)) ->
if (List.mem x lt) then lt
else x::lt
| _ -> lt
in
List.fold_left
(fun lt ->
(function
Not(Equal(t1,t2))
| Not(Leq(t1,t2))
| Not(In(t1,t2))
| Equal(t1,t2)
| Leq(t1,t2)
| In(t1,t2) ->
get_fresh_terms (get_fresh_terms lt t1) t2
| Event(_,lt2) ->
List.fold_left get_fresh_terms lt lt2
| New(x) ->
x::lt
| _ -> lt))
[]
(lhs@rhs)
in
let subst = ref [] in
let lnewgid =
List.map
(fun gid ->
let var_id = global_var_id#get_name_of gid in
if (List.mem var_id primed_terms)
then
let new_name = "Test_"^(string_id#get_name var_id) in
let new_id = string_id#register_name new_name 0
and typ_var_id = type_table#get_type var_id
in
(if (type_table#register_type new_id typ_var_id <> typ_var_id) then
Semantic_check.add_sem_error
(20, "variable "^new_name^" declared with incorrect type (reserved)", "", "","","");
subst := (var_id,Base(Var(new_id)))::!subst;
Base(Var(new_id)))
else
Base(Var(var_id)))
lgid
in
let apply_subst_on_atom =
let rec apply_subst_on_term = function
Pair(t1,t2) ->
Pair(apply_subst_on_term t1, apply_subst_on_term t2)
| Scrypt(t1,t2) ->
Scrypt(apply_subst_on_term t1, apply_subst_on_term t2)
| Crypt(t1,t2) ->
Crypt(apply_subst_on_term t1, apply_subst_on_term t2)
| Cons(t1,t2) ->
Cons(apply_subst_on_term t1, apply_subst_on_term t2)
| Delete(t1,t2) ->
Delete(apply_subst_on_term t1, apply_subst_on_term t2)
| Inv(t) ->
Inv(apply_subst_on_term t)
| Function(t1,l) ->
Function(apply_subst_on_term t1,
List.map apply_subst_on_term l)
| Set(l) ->
Set(List.map apply_subst_on_term l)
| Base(Var(x)) as t ->
if List.mem_assoc x !subst then
List.assoc x !subst
else t
| t -> t
in function
Equal(t1,t2) ->
Equal(apply_subst_on_term t1, apply_subst_on_term t2)
| Not(Equal(t1,t2)) ->
Not(Equal(apply_subst_on_term t1, apply_subst_on_term t2))
| Leq(t1,t2) ->
Leq(apply_subst_on_term t1, apply_subst_on_term t2)
| Not(Leq(t1,t2)) ->
Not(Leq(apply_subst_on_term t1, apply_subst_on_term t2))
| In(t1,t2) ->
In(apply_subst_on_term t1, apply_subst_on_term t2)
| Not(In(t1,t2)) ->
Not(In(apply_subst_on_term t1, apply_subst_on_term t2))
| Event(a,l) ->
Event(a, List.map apply_subst_on_term l)
| p -> p
in
(lnewgid,
List.map apply_subst_on_atom lhs,
List.map apply_subst_on_atom rhs)