123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2023 *)(* 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 licenses/LGPLv2.1). *)(* *)(**************************************************************************)openCil_typesopenInstantiator_builderletbase:(string,(moduleInstantiator))Hashtbl.t=Hashtbl.create17letregister(moduleG:Generator_sig)=letmoduleInstantiator=Make_instantiator(G)inHashtbl.addbaseG.function_name(moduleInstantiator)letget_kfs()=letget_kfs_instantiator=letmoduleI=(valinstantiator:Instantiator)inletres=I.get_kfs()inresinHashtbl.fold(funkvl->(get_kfskv)@l)base[]letclear()=Global_context.clear();letclear_instantiator=letmoduleI=(valinstantiator:Instantiator)inI.clear()inHashtbl.iterclearbasemoduleVISet=Cil_datatype.Varinfo.Hptsetclasstransformer=object(self)inheritVisitor.frama_c_inplacevalintroduced_instantiators=refVISet.emptyvalused_instantiator_last_kf=Queue.create()method!vfile_=letpostf=f.globals<-(Global_context.globals(Cil.CurrentLoc.get()))@f.globals;Ast.mark_as_changed();Ast.mark_as_grown();finCil.DoChildrenPostpostmethod!vglob_aux_=letpostg=letloc=Cil.CurrentLoc.get()inletfoldinglfd=ifVISet.memfd.svar!introduced_instantiatorsthenlelsebeginintroduced_instantiators:=VISet.addfd.svar!introduced_instantiators;GFun(fd,loc)::lendinQueue.foldfoldinggused_instantiator_last_kfinCil.DoChildrenPostpostmethod!vfuncf=letkf=Globals.Functions.getf.svarinifnot(Options.Kfs.is_set())||Options.Kfs.memkfthenCil.DoChildrenelseCil.SkipChildrenmethodprivatefind_enabled_instantiatorfct=letinstantiator=Hashtbl.findbasefct.vnameinletmoduleI=(valinstantiator:Instantiator)inifnot(I.Enabled.get())thenraiseNot_found;instantiatormethodprivatereplace_call(lval,fct,args)=tryletmoduleI=(val(self#find_enabled_instantiatorfct):Instantiator)inifI.well_typed_calllvalfctargsthenletkey=I.key_from_calllvalfctargsinletfundec=I.get_overridekeyinletnew_args=I.retype_argskeyargsinQueue.addfundecused_instantiator_last_kf;(fundec.svar),new_argselsebeginOptions.warning~current:true"%s instantiator cannot replace call"fct.vname;(fct,args)endwith|Not_found->(fct,args)method!vinst=function|Call(_,{enode=Lval((Var_),NoOffset)},_,_)|Local_init(_,ConsInit(_,_,Plain_func),_)->letchange=function|[Call(r,({enode=Lval((Varf),NoOffset)}ase),args,loc)]->letf,args=self#replace_call(r,f,args)in[Call(r,{ewithenode=Lval((Varf),NoOffset)},args,loc)]|[Local_init(r,ConsInit(f,args,Plain_func),loc)]->letf,args=self#replace_call(Some(Cil.varr),f,args)in[Local_init(r,ConsInit(f,args,Plain_func),loc)]|_->assertfalseinCil.DoChildrenPostchange|_->Cil.DoChildrenendletvalidate_propertyp=Property_status.emitOptions.emitter~hyps:[]pProperty_status.Trueletcompute_call_preconditions_statuseskf=letstmt=Kernel_function.find_first_stmtkfinlet_=Kernel_function.find_all_enclosing_blocksstmtinmatchstmt.skindwith|Instr(Local_init(_,ConsInit(fct,_,Plain_func),_))|Instr(Call(_,{enode=Lval((Varfct),NoOffset)},_,_))->letcalled_kf=Globals.Functions.getfctinStatuses_by_call.setup_all_preconditions_proxiescalled_kf;letreqs=Statuses_by_call.all_call_preconditions_at~warn_missing:truecalled_kfstmtinList.iter(fun(_,p)->validate_propertyp)reqs;|_->Options.fatal"Transformation: unexpected instruction kind on precondition"letcompute_postconditions_statuseskf=letpostsbhv=List.itervalidate_property(Property.ip_post_cond_of_behaviorkf~active:[]Kglobalbhv)inAnnotations.iter_behaviors(fun_->posts)kfletcompute_comp_disj_statuseskf=letopenPropertyinletcompsc=validate_property(ip_of_completekfKglobal~active:[]c)inletdisjsd=validate_property(ip_of_disjointkfKglobal~active:[]d)inAnnotations.iter_complete(fun_->comps)kf;Annotations.iter_disjoint(fun_->disjs)kfletcompute_statuses_all_kfs()=letkfs=get_kfs()inList.itercompute_call_preconditions_statuseskfs;List.itercompute_postconditions_statuseskfs;List.itercompute_comp_disj_statuseskfslettransformfile=clear();Visitor.visitFramacFile(newtransformer)file;File.reorder_ast();compute_statuses_all_kfs()