123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* CEA (Commissariat a l'energie atomique et aux energies *)(* 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 licenses/LGPLv2.1). *)(* *)(**************************************************************************)openLang.FopenSigstype(_,_)eq=Equal:'a->('a,'a)eq|NotEqual:('a,'b)eqmoduleIdent:sigtype'atvalcreate:'a->'atvalget:'at->'avaleq:'at->'bt->('a,'b)eqend=structletk=ref0type'at=int*'aletget=sndletcreates=incrk;(!k,s)leteq(k,s)(k',_)=ifk=k'thenObj.magic(Equals)elseNotEqualend(* -------------------------------------------------------------------------- *)(* --- L-Val Utility --- *)(* -------------------------------------------------------------------------- *)letindex(host,ofs)k=host,ofs@[Mindexk]letfield(host,ofs)f=host,ofs@[Mfieldf]lethost_eqab=matcha,bwith|Mvarx,Mvary->Cil_datatype.Varinfo.equalxy|Mmema,Mmemb->a==b|_->falseletofs_eqab=matcha,bwith|Mindexi,Mindexj->i=j|Mfieldf,Mfieldg->Cil_datatype.Fieldinfo.equalfg|_->falseletrecoffset_eqpq=matchp,qwith|[],[]->true|a::p,b::q->ofs_eqab&&offset_eqpq|_->falseletequalab=a==b||(host_eq(fsta)(fstb)&&offset_eq(snda)(sndb))(* -------------------------------------------------------------------------- *)(* --- Memory State Pretty Printing Information --- *)(* -------------------------------------------------------------------------- *)type'aoperations={apply:(term->term)->'a->'a;lookup:'a->term->mval;updates:'asequence->Vars.t->updateBag.t;iter:(mval->term->unit)->'a->unit;}type'amodel=MODEL:'aoperationsIdent.t*('b->'a)->'bmodelletcreate(types)(moduleM:Sigs.ModelwithtypeSigma.t=s)=letop={apply=M.apply;lookup=M.lookup;updates=M.updates;iter=M.iter;}inMODEL(Ident.createop,M.state)typestate=STATE:'aoperationsIdent.t*'a->stateletstatemodelsigma=matchmodelwithMODEL(op,state)->STATE(op,statesigma)letiterf=functionSTATE(m,s)->(Ident.getm).iterfsletapplyf=functionSTATE(m,s)->STATE(m,(Ident.getm).applyfs)letlookupse=matchswithSTATE(m,s)->(Ident.getm).lookupseletupdatesseqvars=matchseq.pre,seq.postwithSTATE(p,u),STATE(q,v)->matchIdent.eqpqwith|Equals->s.updates{pre=u;post=v}vars|NotEqual->Bag.empty(* assert false *)(* -------------------------------------------------------------------------- *)