123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155(**************************************************************************)(* *)(* This file is part of the why3find. *)(* *)(* Copyright (C) 2022-2024 *)(* CEA (Commissariat à l'énergie atomique et aux énergies *)(* alternatives) *)(* *)(* you can redistribute it and/or modify it under the terms of the GNU *)(* Lesser General Public License as published by the Free Software *)(* Foundation, version 2.1. *)(* *)(* It is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU Lesser General Public License for more details. *)(* *)(* See the enclosed LICENSE.md for details. *)(* *)(**************************************************************************)(* -------------------------------------------------------------------------- *)(* --- Dump AST --- *)(* -------------------------------------------------------------------------- *)openWhy3type'aprinter=Format.formatter->'a->unit(* -------------------------------------------------------------------------- *)(* --- Basics --- *)(* -------------------------------------------------------------------------- *)letpp_idfmt(id:Ident.ident)=Format.fprintffmt"%s"id.id_stringletpp_anyfmts=Format.fprintffmt"(%s…)"s[@@warning"-32"]letpp_nlistitemfmtxs=letn=List.lengthxsinifn>0thenFormat.fprintffmt"@,%s[%d]"itemn[@@warning"-32"]letpp_manyitemfmtempty=ifnotemptythenFormat.fprintffmt"@,%s[…]"item[@@warning"-32"]letpp_someitemfmtopt=ifoptthenFormat.fprintffmt"%s"item[@@warning"-32"](* -------------------------------------------------------------------------- *)(* --- Term --- *)(* -------------------------------------------------------------------------- *)letpp_term=Pretty.print_term(* -------------------------------------------------------------------------- *)(* --- Ity --- *)(* -------------------------------------------------------------------------- *)letpp_ityfmt(ity:Ity.ity)=matchity.ity_nodewith|Ityreg_->pp_anyfmt"reg"|Ityvarx->pp_idfmtx.tv_name|Ityapp(its,[],[])->Format.fprintffmt"%a"pp_idits.its_ts.ts_name|Ityapp(its,xs,ys)->Format.fprintffmt"%a.%d.%d"pp_idits.its_ts.ts_name(List.lengthxs)(List.lengthys)letpp_pvsymbol_deffmt(pv:Ity.pvsymbol)=Format.fprintffmt"@[<hov 2>(%a%a:%a)@]"(pp_some"ghost ")pv.pv_ghostpp_idpv.pv_vs.vs_namepp_itypv.pv_ityletpp_pvsymbol_usefmt(pv:Ity.pvsymbol)=pp_idfmtpv.pv_vs.vs_nameletpp_clauseclauseppfmtc=Format.fprintffmt"@ @[<hov 2>%s { %a }@]"clauseppcletpp_ctyfmt(cty:Ity.cty)=beginList.iter(Format.fprintffmt"@,%a"pp_pvsymbol_def)cty.cty_args;Format.fprintffmt":%a"pp_itycty.cty_result;List.iter(pp_clause"pre"pp_termfmt)cty.cty_pre;List.iter(pp_clause"post"pp_termfmt)cty.cty_post;pp_many" xpost"fmt(Ity.Mxs.is_emptycty.cty_xpost);pp_many" oldies"fmt(Ity.Mpv.is_emptycty.cty_oldies);end(* -------------------------------------------------------------------------- *)(* --- Expr --- *)(* -------------------------------------------------------------------------- *)letpp_rs_kindfmt(rs:Expr.rs_kind)=matchrswith|RKnone->()|RKlemma->Format.fprintffmt"lemma "|RKlocal->Format.fprintffmt"local "|RKfunc->Format.fprintffmt"function "|RKpred->Format.fprintffmt"predicate "letpp_rsymbol_deffmt(rs:Expr.rsymbol)=Format.fprintffmt"@[<hov 2>%a%a%a@]"pp_rs_kind(Expr.rs_kindrs)pp_idrs.rs_namepp_ctyrs.rs_ctyletpp_rsymbol_usefmt(rs:Expr.rsymbol)=pp_idfmtrs.rs_nameletrecpp_exprfmt(expr:Expr.expr)=matchexpr.e_nodewith|Evarx->pp_pvsymbol_usefmtx|Econstc->Constant.print_deffmtc|Eassign_->pp_anyfmt"Eassign"|Eif_->pp_anyfmt"Eif"|Ematch_->pp_anyfmt"Ematch"|Ewhile_->pp_anyfmt"Ewhile"|Efor_->pp_anyfmt"Efor"|Eraise_->pp_anyfmt"Eraise"|Eexn_->pp_anyfmt"Eexn"|Eassert(Assume,t)->Format.fprintffmt"@[<hov 2>(assume %a)@]"pp_termt|Eassert(Assert,t)->Format.fprintffmt"@[<hov 2>(assert %a)@]"pp_termt|Eassert(Check,t)->Format.fprintffmt"@[<hov 2>(check %a)@]"pp_termt|Eghoste->Format.fprintffmt"(ghost %a)"pp_expre|Epuret->Format.fprintffmt"(pure %a)"pp_termt|Eabsurd->Format.fprintffmt"absurd"|Eexec(ce,_)->Format.fprintffmt"(exec %a)"pp_cexpce|Elet(def,e)->Format.fprintffmt"@[<hv 0>%a@ in %a@]"pp_let_defndefpp_expreandpp_let_defnfmt(def:Expr.let_defn)=matchdefwith|LDvar(pv,e)->Format.fprintffmt"@[<hov 4>let:pv %a = %a@]"pp_pvsymbol_defpvpp_expre|LDsym(rs,e)->Format.fprintffmt"@[<hov 4>let:rs %a = %a@]"pp_rsymbol_defrspp_cexpe|LDrec_->pp_anyfmt"let:rec"andpp_cexpfmt(cexp:Expr.cexp)=Format.fprintffmt"@[<hv 2>";beginmatchcexp.c_nodewith|Cfune->Format.fprintffmt"(Cfun %a)"pp_expre|Capp(rs,pvs)->Format.fprintffmt"@[<hov 2>(Capp %a"pp_idrs.rs_name;List.iter(Format.fprintffmt"@ %a"pp_pvsymbol_use)pvs;Format.fprintffmt")@]"|Cpur_->pp_anyfmt"Cpur"|Cany->Format.fprintffmt"Cany"end;pp_ctyfmtcexp.c_cty;Format.fprintffmt"@]"(* -------------------------------------------------------------------------- *)