eliminate_let.ml 1.5 KB
Newer Older
1 2 3
(********************************************************************)
(*                                                                  *)
(*  The Why3 Verification Platform   /   The Why3 Development Team  *)
Guillaume Melquiond's avatar
Guillaume Melquiond committed
4
(*  Copyright 2010-2018   --   Inria - CNRS - Paris-Sud University  *)
5 6 7 8
(*                                                                  *)
(*  This software is distributed under the terms of the GNU Lesser  *)
(*  General Public License version 2.1, with the special exception  *)
(*  on linking described in file LICENSE.                           *)
9
(*                                                                  *)
10
(********************************************************************)
11 12 13 14 15

open Term

(* eliminate let *)

Quentin Garchery's avatar
Quentin Garchery committed
16
let rec elim_t func pred t = match t.t_node with
17
  | Tlet (t1,tb) when (if t.t_ty = None then pred else func) ->
Quentin Garchery's avatar
Quentin Garchery committed
18 19
      let t1 = elim_t func pred t1 in
      elim_t func pred (t_open_bound_with t1 tb)
20
  | _ ->
Quentin Garchery's avatar
Quentin Garchery committed
21
      t_map (elim_t func pred) t
22

Quentin Garchery's avatar
Quentin Garchery committed
23 24 25
let eliminate_let_term = Trans.rewrite (elim_t true false) None
let eliminate_let_fmla = Trans.rewrite (elim_t false true) None
let eliminate_let      = Trans.rewrite (elim_t true true) None
26 27

let () =
28
  Trans.register_transform "eliminate_let_term" eliminate_let_term
Andrei Paskevich's avatar
Andrei Paskevich committed
29
    ~desc:"Eliminate@ let-expressions@ in@ terms.";
30
  Trans.register_transform "eliminate_let_fmla" eliminate_let_fmla
Andrei Paskevich's avatar
Andrei Paskevich committed
31
    ~desc:"Eliminate@ let-expressions@ in@ formulas.";
32
  Trans.register_transform "eliminate_let" eliminate_let
Andrei Paskevich's avatar
Andrei Paskevich committed
33
    ~desc:"Eliminate@ all@ let-expressions.";