123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: 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, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program 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. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Pretty-printer of Apron environments *)openMopsaopenApronletcoeff_eq_1(c:Coeff.t)=matchcwith|Coeff.ScalarswhenScalar.cmp_ints1=0->true|Coeff.IntervaliwhenScalar.cmp_inti.Interval.inf1=0&&Scalar.cmp_inti.Interval.sup1=0->true|_->falseletcoeff_eq_0(c:Coeff.t)=matchcwith|Coeff.Scalars->Scalar.cmp_ints0=0|Coeff.Intervali->Scalar.cmp_inti.Interval.inf0=0&&Scalar.cmp_inti.Interval.sup0=0letcoeff_cmp_0(c:Coeff.t)=matchcwith|Coeff.Scalars->Some(Scalar.cmp_ints0)|Coeff.Intervali->ifScalar.cmp_inti.Interval.inf0>0thenSome1elseifScalar.cmp_inti.Interval.sup0<0thenSome(-1)elseNoneletlinexpr_to_list_pairenv(x:Linexpr1.t)=letenvi,envf=Environment.varsenvinletprocessposnegenv=Array.fold_left(fun(pos,neg)var->letc=Linexpr1.get_coeffxvarinifcoeff_eq_0cthen(pos,neg)elsematchcoeff_cmp_0cwith|None->(c,var)::pos,neg|Somexwhenx>0->(c,var)::pos,neg|Somex->pos,(c,var)::neg)(pos,neg)envinletpos,neg=process[][]enviinprocessposnegenvfletpp_coef_var_listbndfmtl=matchlwith|[]->Format.fprintffmt"0"|_->Format.pp_print_list~pp_sep:(funfmt()->Format.fprintffmt" + ")(funfmt(c,v)->ifcoeff_eq_1cthenFormat.fprintffmt"%a"pp_var(Binding.apron_to_mopsa_varvbnd)elseFormat.fprintffmt"%a%a"Coeff.printcpp_var(Binding.apron_to_mopsa_varvbnd))fmtlletpp_typfmt(x,b)=matchx,bwith|Lincons1.DISEQ,_->Format.fprintffmt"!="|Lincons1.EQ,_->Format.fprintffmt"="|Lincons1.SUP,false->Format.fprintffmt">"|Lincons1.SUP,true->Format.fprintffmt"<"|Lincons1.SUPEQ,false->Format.fprintffmt"≥"|Lincons1.SUPEQ,true->Format.fprintffmt"≤"|Lincons1.EQMOD_,_->assertfalseletneg_listl=List.map(fun(c,v)->Coeff.negc,v)lletpp_linconsbndfmtlc=letcst=Lincons1.get_cstlcinlettyp=Lincons1.get_typlcinletpos,neg=linexpr_to_list_pair(Lincons1.get_envlc)(Lincons1.get_linexpr1lc)inifcoeff_eq_0(cst)thenFormat.fprintffmt"%a %a %a"(pp_coef_var_listbnd)pospp_typ(typ,false)(pp_coef_var_listbnd)(neg_listneg)elsematchcoeff_cmp_0(cst)with|Somexwhenx>0->ifpos=[]thenFormat.fprintffmt"%a %a %a"(pp_coef_var_listbnd)(neg_listneg)pp_typ(typ,true)Coeff.printcstelseifneg=[]thenFormat.fprintffmt"%a %a %a"(pp_coef_var_listbnd)pospp_typ(typ,false)Coeff.print(Coeff.negcst)elseFormat.fprintffmt"%a %a %a + %a"(pp_coef_var_listbnd)(neg_listneg)pp_typ(typ,true)(pp_coef_var_listbnd)posCoeff.printcst|_->ifneg=[]thenFormat.fprintffmt"%a %a %a"(pp_coef_var_listbnd)pospp_typ(typ,false)Coeff.print(Coeff.negcst)elseifpos=[]thenFormat.fprintffmt"%a %a %a"(pp_coef_var_listbnd)(neg_listneg)pp_typ(typ,true)Coeff.print(cst)elseFormat.fprintffmt"%a %a %a + %a"(pp_coef_var_listbnd)pospp_typ(typ,false)(pp_coef_var_listbnd)(neg_listneg)Coeff.print(Coeff.negcst)letpp_lincons_earraybndprea=letrecreadn=ifn<0then[]elseletx=Lincons1.array_geteaninx::(read(n-1))inletl=read(Lincons1.array_lengthea-1)inmatchlwith|[]->pp_stringpr"⊤"|_->letsl=List.map(func->Format.asprintf"%a"(pp_linconsbnd)c)linpp_setpp_stringpr(SetExtPoly.of_listString.comparesl)letpp_envmanpr(x,bnd)=ifAbstract1.is_bottommanxthenpp_stringpr"⊥"elsetryletea=Abstract1.to_lincons_arraymanxinpp_lincons_earraybndpreawith(Failures)whenString.starts_with~prefix:"Linexpr1.get_coeff"s->let()=warn"%s~>%s"s"defaulting to standard printing"inpp_stringpr(Format.asprintf"%a"Abstract1.printx)