1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(**************************************************************************)(* *)(* 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). *)(* *)(**************************************************************************)openLangopenTactical(* -------------------------------------------------------------------------- *)(* --- Compute Term --- *)(* -------------------------------------------------------------------------- *)exceptionSplitofF.term*F.term*F.termexceptionUnfoldofF.term*Lang.lfun*F.termletheade=ifF.lc_closede&¬@@F.is_primitiveethenmatchF.reprewith|If(c,a,b)->raise(Split(c,a,b))|Fun(f,es)->raise(Unfold(e,f,TacUnfold.unfoldfes))|_->()letprocess(fd:Tactical.feedback)?ate=tryletq=Queue.create()inletm=refF.Tset.emptyinletlookupe=heade;m:=F.Tset.adde!m;F.lc_iter(fune->Queue.pusheq)einlookupe;whilenot@@Queue.is_emptyqdolete=Queue.popqinifnot@@F.Tset.meme!mthenlookupe;done;Not_applicablewith|Split(a,b,c)->letp=F.p_boolcinletq=F.p_notpinfd#set_title"Compute (split)";fd#set_descr"Split on if-then-else condition";Applicable(Tactical.rewrite?at["If-Then",p,e,a;"If-Else",q,e,b])|Unfold(e,f,d)->fd#set_title"Compute (def)";fd#set_descr"Unfold definition of '%s'"(Lang.name_of_lfunf);Applicable(Tactical.rewrite?at["Definition",F.p_true,e,d])classcompute:Tactical.tactical=objectinheritTactical.make~id:"Wp.compute"~title:"Compute"~descr:"Unfold definitions and split on conditions"~params:[]methodselectfeedback(s:Tactical.selection)=processfeedback?at:(Tactical.ats)(Tactical.selecteds)endlettactical=Tactical.export(newcompute)letstrategy=Strategy.maketactical~arguments:[](* -------------------------------------------------------------------------- *)