123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112(**************************************************************************)(* This file is part of the Codex semantics library. *)(* *)(* Copyright (C) 2013-2025 *)(* 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 GNU Lesser General Public License version 2.1 *)(* for more details (enclosed in the file LICENSE). *)(* *)(**************************************************************************)(* Standard abstraction for booleans; powerset of {true;false} *)(* TODO: Should become Quadrivalent_Lattice. And should go into lattice? *)typeboolean=Boolean_standard.Quadrivalent.t=|Bottom|True|False|TopmoduleBooleanDT=(structtypet=booleanletprettyfmtt=letstring=matchtwith|Bottom->"{}"|True->"{true}"|False->"{false}"|Top->"{true;false}"inFormat.fprintffmt"%s"stringlet_equal=(==)letcompare(a:boolean)(b:boolean)=Stdlib.compareablethash=function|Bottom->0|True->1|False->2|Top->3end)moduleBoolean_Lattice=structincludeBooleanDTletbottom()=Bottomletboolean_bottom=bottom()letis_bottomx=(x=Bottom)lettop()=Topletsingleton=function|true->True|false->Falselettruth_valuex=xletof_bools~may_be_false~may_be_true=match(may_be_false,may_be_true)with|(false,false)->Bottom|(false,true)->True|(true,false)->False|(true,true)->Top(* Conversion to a couple (may_be_false,may_be_true) *)letto_bools=function|Bottom->(false,false)|True->(false,true)|False->(true,false)|Top->(true,true)letjoinab=match(a,b)with|Bottom,x|x,Bottom->x|False,False->False|True,True->True|True,False|False,True->Top|Top,_|_,Top->Topletincludesab=matcha,bwith|Top,_->true|_,Bottom->true|True,True|False,False->true|_->falseletwiden~previousb=joinpreviousbletincludes_or_widen~previousb=ifincludespreviousbthen(true,b)else(false,joinpreviousb)letinterab=match(a,b)with|Bottom,_|_,Bottom->Bottom|Top,x|x,Top->x|True,False|False,True->Bottom|True,True->True|False,False->False;;endletto_quadrivalentx=xincludeBoolean_Latticeletequal=(==)