123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596(****************************************************************************)(* *)(* 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/>. *)(* *)(****************************************************************************)(**
Top - Top element
*)(** {2 Types} *)type'awith_top=TOP|Ntof'a(** Add a top element to a type. *)(** {2 Operator lifting} *)lettop_lift1(f:'a->'b)(a:'awith_top):'bwith_top=matchawithTOP->TOP|Ntx->Nt(fx)lettop_lift2(f:'a->'b->'c)(a:'awith_top)(b:'bwith_top):'cwith_top=matcha,bwithTOP,_|_,TOP->TOP|Ntx,Nty->Nt(fxy)lettop_absorb1(f:'a->'bwith_top)(a:'awith_top):'bwith_top=matchawithTOP->TOP|Ntx->fxlettop_absorb2(f:'a->'b->'cwith_top)(a:'awith_top)(b:'bwith_top):'cwith_top=matcha,bwithTOP,_|_,TOP->TOP|Ntx,Nty->fxylettop_neutral2(f:'a->'a->'a)(a:'awith_top)(b:'awith_top):'awith_top=matcha,bwithTOP,_->b|_,TOP->a|Ntx,Nty->Nt(fxy)lettop_apply(f:'b->'a)(a:'a)(b:'bwith_top):'a=matchbwithTOP->a|Ntx->fxlettop_apply2(a1:'a)(a2:'a)(f:'b->'b->'a)(b1:'bwith_top)(b2:'bwith_top):'a=matchb1,b2with|TOP,TOP->a1|TOP,_|_,TOP->a2|Ntx1,Ntx2->fx1x2lettop_equal(f:'a->'b->bool)(a:'awith_top)(b:'bwith_top):bool=matcha,bwithTOP,TOP->true|Ntx,Nty->fxy|_->falselettop_included(f:'a->'b->bool)(a:'awith_top)(b:'bwith_top):bool=matcha,bwith_,TOP->true|Ntx,Nty->fxy|_->falselettop_compare(cmp:'a->'a->int)(a:'awith_top)(b:'awith_top):int=matcha,bwithTOP,TOP->0|TOP,_->1|_,TOP->-1|Ntx,Nty->cmpxylettop_dfl1(dfl:'b)(f:'a->'c)(a:'awith_top):'c=matchawithTOP->dfl|Ntx->fxlettop_dfl2(dfl:'c)(f:'a->'b->'c)(a:'awith_top)(b:'bwith_top):'c=matcha,bwithNtx,Nty->fxy|_->dfl(** {2 Exceptions} *)exceptionFound_TOPletraise_top()=raiseFound_TOPletcatch_top(f:'a->'b)(a:'a)(dfl:'b):'b=tryfawithFound_TOP->dflletdetop(a:'awith_top):'a=matchawithTOP->raiseFound_TOP|Ntx->xletretop(f:'a->'b)(x:'a):'bwith_top=tryNt(fx)withFound_TOP->TOPletexn_to_top=retoplettop_to_exn=detop(** {2 Printing} *)lettop_string="⊤"lettop_to_stringfx=matchxwithTOP->top_string|Ntx->fxlettop_printfchx=matchxwithTOP->output_stringchtop_string|Ntx->fchxlettop_fprintfchx=matchxwithTOP->Format.pp_print_stringchtop_string|Ntx->fchxlettop_bprintfchx=matchxwithTOP->Buffer.add_stringchtop_string|Ntx->fchx