[sledge] Add Term.fold_map

Reviewed By: jvillard

Differential Revision: D20863529

fbshipit-source-id: 82c6038e0
master
Josh Berdine 5 years ago committed by Facebook GitHub Bot
parent b35e3d30e0
commit ef63683a16

@ -1075,6 +1075,16 @@ let map e ~f =
e e
| Var _ | Label _ | Nondet _ | Float _ | Integer _ -> e | Var _ | Label _ | Nondet _ | Float _ | Integer _ -> e
let fold_map e ~init ~f =
let s = ref init in
let f x =
let s', x' = f !s x in
s := s' ;
x'
in
let e' = map e ~f in
(!s, e')
(** Pre-order transformation that preserves cycles. Each subterm [x] from (** Pre-order transformation that preserves cycles. Each subterm [x] from
root to leaves is presented to [f]. If [f x = Some x'] then the subterms root to leaves is presented to [f]. If [f x = Some x'] then the subterms
of [x] are not traversed and [x] is transformed to [x']. Otherwise of [x] are not traversed and [x] is transformed to [x']. Otherwise

@ -234,6 +234,7 @@ val size_of : Typ.t -> t
(** Transform *) (** Transform *)
val map : t -> f:(t -> t) -> t val map : t -> f:(t -> t) -> t
val fold_map : t -> init:'a -> f:('a -> t -> 'a * t) -> 'a * t
val rename : Var.Subst.t -> t -> t val rename : Var.Subst.t -> t -> t
(** Traverse *) (** Traverse *)

Loading…
Cancel
Save