123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167(**************************************************************************)(* 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). *)(* *)(**************************************************************************)moduleType=structtype'aor_bottom=[`Valueof'a|`Bottom](* This monad propagates the `Bottom value if needed. *)let(>>-)tf=matchtwith|`Bottom->`Bottom|`Valuet->ft(* Use this monad if the following function returns a simple value. *)let(>>-:)tf=matchtwith|`Bottom->`Bottom|`Valuet->`Value(ft)endincludeTypeletis_bottom=function|`Bottom->true|`Value_->falseletnon_bottom=function|`Valuev->v|`Bottom->assertfalseletequalequalxy=matchx,ywith|`Bottom,`Bottom->true|`Valuevx,`Valuevy->equalvxvy|_->falseletis_includedis_includedxy=matchx,ywith|`Bottom,_->true|_,`Bottom->false|`Valuevx,`Valuevy->is_includedvxvyletjoinjoinxy=matchx,ywith|`Valuevx,`Valuevy->`Value(joinvxvy)|`Bottom,(`Value_asv)|(`Value_asv),`Bottom|(`Bottomasv),`Bottom->vletjoin_listjl=List.fold_left(joinj)`Bottomlletnarrownarrowxy=matchx,ywith|`Valuevx,`Valuevy->narrowvxvy|`Bottom,`Value_|`Value_,`Bottom|`Bottom,`Bottom->`Bottomletprettyprettyfmt=function|`Bottom->Format.fprintffmt"Bottom"|`Valuev->prettyfmtvletcounter=ref0moduleMake_Datatype(Domain:Datatype_sig.S)=(* Datatype.Make *)(struct(* include Datatype.Serializable_undefined *)typet=Domain.tor_bottomlet()=incrcounter(* let name = Domain.name ^ "+bottom(" ^ string_of_int !counter ^ ")" *)(* let reprs = [`Bottom; `Value (List.hd Domain.reprs)]
* let structural_descr = Structural_descr.t_unknown *)(* Structural_descr.t_sum [| [| Domain.packed_descr |] |] *)letequalab=matcha,bwith|`Bottom,`Bottom->true|`Valuev,`Valuew->Domain.equalvw|_,_->falseletcompareab=matcha,bwith|`Bottom,`Bottom->0|`Bottom,_->-1|_,`Bottom->1|`Valuev,`Valuew->Domain.comparevwlethash=function|`Bottom->0|`Valuev->Domain.hashv(* let rehash = Datatype.identity
*
* let copy = function
* | `Bottom -> `Bottom
* | `Value v -> `Value (Domain.copy v) *)letprettyfmt=function|`Bottom->Format.fprintffmt"Bottom"|`Valuev->Domain.prettyfmtv(* let mem_project = Datatype.never_any_project *)end)moduleBound_Lattice(Lattice:sigincludeDatatype_sig.Svaljoin:t->t->tend)=structincludeMake_Datatype(Lattice)letbottom=`Bottomletjoin=joinLattice.join(* let is_included = is_included Lattice.is_included *)endletto_list=function|`Bottom->[]|`Valuev->[v]letbot_of_list=function|[]->`Bottom|l->`Valuelletlist_of_bot=function|`Bottom->[]|`Valuel->lletadd_to_listeltlist=matcheltwith|`Bottom->list|`Valueelt->elt::listletalll=List.fold_left(funlelt->add_to_listeltl)[]lmoduleTop=structtype'aor_top_bottom=['aor_bottom|`Top]letjoinvjoinxy=matchx,ywith|`Top,_|_,`Top->`Top|(#or_bottomasx),(#or_bottomasy)->joinvjoinxyletnarrowvnarrowxy=matchx,ywith|`Top,v|v,`Top->v|(#or_bottomasx),(#or_bottomasy)->(narrowvnarrowxy:>_or_top_bottom)end