refactor(term): printing utils

This commit is contained in:
Simon Cruanes 2018-08-18 14:47:39 -05:00
parent 446690eb11
commit ce9bcb234d
4 changed files with 12 additions and 5 deletions

View file

@ -197,7 +197,7 @@ let rec pp_ty out t = match t.ty_view with
Fmt.fprintf out "(@[%a@ %a@])" ID.pp id (Util.pp_list pp_ty) args Fmt.fprintf out "(@[%a@ %a@])" ID.pp id (Util.pp_list pp_ty) args
| Ty_atomic {def=Ty_def def; args; _} -> def.pp pp_ty out args | Ty_atomic {def=Ty_def def; args; _} -> def.pp pp_ty out args
let pp_term_view ~pp_id ~pp_t out = function let pp_term_view_gen ~pp_id ~pp_t out = function
| Bool true -> Fmt.string out "true" | Bool true -> Fmt.string out "true"
| Bool false -> Fmt.string out "false" | Bool false -> Fmt.string out "false"
| App_cst ({cst_view=Cst_def {pp=Some pp_custom;_};_},l) -> pp_custom pp_t out l | App_cst ({cst_view=Cst_def {pp=Some pp_custom;_};_},l) -> pp_custom pp_t out l
@ -212,12 +212,12 @@ let pp_term_top ~ids out t =
let rec pp out t = let rec pp out t =
pp_rec out t; pp_rec out t;
(* FIXME if Config.pp_hashcons then Format.fprintf out "/%d" t.term_id; *) (* FIXME if Config.pp_hashcons then Format.fprintf out "/%d" t.term_id; *)
and pp_rec out t = pp_term_view ~pp_id ~pp_t:pp_rec out t.term_view and pp_rec out t = pp_term_view_gen ~pp_id ~pp_t:pp_rec out t.term_view
and pp_id = if ids then ID.pp else ID.pp_name in and pp_id = if ids then ID.pp else ID.pp_name in
pp out t pp out t
let pp_term = pp_term_top ~ids:false let pp_term = pp_term_top ~ids:false
let pp_term_view = pp_term_view ~pp_id:ID.pp_name ~pp_t:pp_term let pp_term_view = pp_term_view_gen ~pp_id:ID.pp_name ~pp_t:pp_term
let pp_lit out l = let pp_lit out l =
if l.lit_sign then pp_term out l.lit_term if l.lit_sign then pp_term out l.lit_term

View file

@ -20,6 +20,9 @@ let equal = term_equal_
let hash = term_hash_ let hash = term_hash_
let compare a b = CCInt.compare a.term_id b.term_id let compare a b = CCInt.compare a.term_id b.term_id
(* TODO: when GC is implemented, add a field for recycling IDs
that have been free'd, so we can keep the ID space dense. *)
type state = { type state = {
tbl : term Term_cell.Tbl.t; tbl : term Term_cell.Tbl.t;
mutable n: int; mutable n: int;

View file

@ -14,6 +14,7 @@ module type ARG = sig
type t type t
val hash : t -> int val hash : t -> int
val equal : t -> t -> bool val equal : t -> t -> bool
val pp : t Fmt.printer
end end
module Make_eq(A : ARG) = struct module Make_eq(A : ARG) = struct
@ -35,12 +36,15 @@ module Make_eq(A : ARG) = struct
sub_eq a1 a2 && sub_eq b1 b2 && sub_eq c1 c2 sub_eq a1 a2 && sub_eq b1 b2 && sub_eq c1 c2
| Bool _, _ | App_cst _, _ | If _, _ | Bool _, _ | App_cst _, _ | If _, _
-> false -> false
let pp = Solver_types.pp_term_view_gen ~pp_id:ID.pp_name ~pp_t:A.pp
end[@@inline] end[@@inline]
include Make_eq(struct include Make_eq(struct
type t = term type t = term
let equal (t1:t) t2 = t1==t2 let equal (t1:t) t2 = t1==t2
let hash (t:term): int = t.term_id let hash (t:term): int = t.term_id
let pp = pp_term
end) end)
let true_ = Bool true let true_ = Bool true
@ -53,8 +57,6 @@ let if_ a b c =
assert (Ty.equal b.term_ty c.term_ty); assert (Ty.equal b.term_ty c.term_ty);
If (a,b,c) If (a,b,c)
let pp = pp_term_view
let ty (t:t): Ty.t = match t with let ty (t:t): Ty.t = match t with
| Bool _ -> Ty.prop | Bool _ -> Ty.prop
| App_cst (f, args) -> | App_cst (f, args) ->

View file

@ -28,9 +28,11 @@ module type ARG = sig
type t type t
val hash : t -> int val hash : t -> int
val equal : t -> t -> bool val equal : t -> t -> bool
val pp : t Fmt.printer
end end
module Make_eq(X : ARG) : sig module Make_eq(X : ARG) : sig
val equal : X.t view -> X.t view -> bool val equal : X.t view -> X.t view -> bool
val hash : X.t view -> int val hash : X.t view -> int
val pp : X.t view Fmt.printer
end end