let rename_entities file =
  let add_variable v =
    v.vname <- unique_name v.vname;
    match v.vlogic_var_assoc with
      | None -> ()
      | Some lv -> lv.lv_name <- v.vname
  in
  let add_logic_variable v =
    match v.lv_origin with
        None -> (* pure logic variable *)
          v.lv_name <- unique_logic_name v.lv_name
      | Some _ -> () (* we take care of that in the C world *)
  in
  Globals.Vars.iter (fun v _init -> add_variable v);
  Globals.Functions.iter
    (fun kf ->
       add_variable (Globals.Functions.get_vi kf);
       List.iter add_variable (Globals.Functions.get_params kf));
  Globals.Annotations.replace_all
    (fun annot gen ->
       let rec replace_annot annot = match annot with
         | Dfun_or_pred _ -> annot
         | Daxiomatic(id, l) -> Daxiomatic(id, List.map replace_annot l)
         | Dtype(infos) ->
             Dtype({ infos with
                       lt_name = unique_logic_name infos.lt_name;
                       lt_ctors =
                       opt_map
                         (List.map
                            (fun x ->
                               { x with ctor_name =
                                   unique_logic_name x.ctor_name}))
                         infos.lt_ctors;})
         | Dlemma(name,is_axiom,labels,poly,property) ->
             Dlemma(unique_logic_name name,is_axiom,labels,poly,property)
         | Dtype_annot _info | Dinvariant _info ->
             (* Useful ? harmless ?
                info.l_name <- unique_logic_name info.l_name;
             *)

             annot
       in replace_annot annot,gen
    );

  (* preprocess of renaming logic functions  *)
  Logic_env.LogicInfo.iter
    (fun name _li ->
(*
       Format.eprintf "Jessie.Rewrite: checking overloading of %s -> " name;
*)

       try
         let x = Hashtbl.find logic_names_overloading name in
(*
         Format.eprintf "true!@.";
*)

         x := true
       with
           Not_found ->
(*
             Format.eprintf "false@.";
*)

             Hashtbl.add logic_names_overloading name (ref false)
    );

  let visitor = new renameEntities (add_variable) (add_logic_variable) in
  visitFramacFile visitor file