123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167(****************************************************************************)(* *)(* 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/>. *)(* *)(****************************************************************************)(** Abstraction of zero and non-zero integer values. *)openMopsaopenSig.Abstraction.Simplified_valueopenAstmoduleValue=structtypet=|TOP|BOT|ZERO|NON_ZEROincludeGenValueId(structtypenonrect=tletname="universal.numeric.values.zero"letdisplay="zero"end)letaccept_type=function|T_int|T_bool->true|_->falseletbottom=BOTlettop=TOPletis_bottoma=(a=BOT)letsubset(a1:t)(a2:t):bool=matcha1,a2with|_,TOP->true|TOP,_->false|BOT,_->true|_,BOT->false|ZERO,ZERO->true|NON_ZERO,NON_ZERO->true|_->falseletjoin(a1:t)(a2:t):t=matcha1,a2with|TOP,_|_,TOP->TOP|BOT,x|x,BOT->x|ZERO,ZERO->ZERO|NON_ZERO,NON_ZERO->NON_ZERO|ZERO,NON_ZERO|NON_ZERO,ZERO->TOPletmeet(a1:t)(a2:t):t=matcha1,a2with|TOP,x|x,TOP->x|BOT,_|_,BOT->BOT|ZERO,ZERO->ZERO|NON_ZERO,NON_ZERO->NON_ZERO|ZERO,NON_ZERO|NON_ZERO,ZERO->BOTletwidenctx(a1:t)(a2:t):t=joina1a2letprintprinter(a:t)=matchawith|TOP->pp_stringprinter"⊤"|BOT->pp_stringprinter"⊥"|ZERO->pp_stringprinter"0"|NON_ZERO->pp_stringprinter"≠ 0"includeDefaultValueFunctionsletconstantct=matchcwith|C_booltrue->NON_ZERO|C_boolfalse->ZERO|C_intiwhenZ.equaliZ.zero->ZERO|C_inti->NON_ZERO|C_int_interval(i1,i2)whenItvUtils.IntBound.is_zeroi1&&ItvUtils.IntBound.is_zeroi2->ZERO|C_int_interval(i1,i2)whenItvUtils.IntBound.is_positive_stricti1||ItvUtils.IntBound.is_negative_stricti2->NON_ZERO|_->TOPletunopoptatr=matchopwith|O_log_not->beginmatchawith|TOP->TOP|BOT->BOT|ZERO->NON_ZERO|NON_ZERO->ZEROend|O_minus->a|O_plus->a|_->topletbinopopt1a1t2a2tr=matchopwith|O_plus|O_minus->beginmatcha1,a2with|BOT,_|_,BOT->BOT|TOP,_|_,TOP->TOP|ZERO,x|x,ZERO->x|_->TOPend|O_mult->beginmatcha1,a2with|BOT,_|_,BOT->BOT|TOP,_|_,TOP->TOP|ZERO,x|x,ZERO->ZERO|_->TOPend|_->topletfilterbta=matchawith|TOP->TOP|BOT->BOT|ZERO->ifbthenBOTelsea|NON_ZERO->ifbthenaelseBOTletcompareopbt1a1t2a2=letop=ifbthenopelsenegate_comparison_opopinmatchopwith|O_eq->leta=meeta1a2ina,a|O_ne|O_gt|O_lt->beginmatcha1,a2with|BOT,_|_,BOT->BOT,BOT|ZERO,ZERO->BOT,BOT|ZERO,TOP->ZERO,NON_ZERO|TOP,ZERO->NON_ZERO,ZERO|_->a1,a2end|_->default_compareopbt1a1t2a2endlet()=register_simplified_value_abstraction(moduleValue)