123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107(**************************************************************************)(* *)(* This file is part of WP plug-in of Frama-C. *)(* *)(* Copyright (C) 2007-2024 *)(* 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). *)(* *)(**************************************************************************)openCil_types(* -------------------------------------------------------------------------- *)(* --- User-Defined Probes --- *)(* -------------------------------------------------------------------------- *)typeprobe={id:int;name:string;stmt:stmtoption;loc:location;}letcreate=letid=ref(-1)infun~loc?stmt~name()->incrid;{id=!id;loc;stmt;name}moduleS=structincludeDatatype.Undefinedletname="WP.Conditions.Probe.t"letreprs=[{loc=Cil_datatype.Location.unknown;stmt=None;name="";id=1}]typet=probelethashx=x.idletequalxy=Int.equalx.idy.idletcomparexy=Int.comparey.idx.id(* lastly created first (wp) *)letprettyfmtp=ifWp_parameters.debug_atleast1thenFormat.fprintffmt"%s#%d"p.namep.idelseFormat.fprintffmt"%s"p.nameendincludeDatatype.Make_with_collections(S)(* -------------------------------------------------------------------------- *)(* --- ACSL Extension --- *)(* -------------------------------------------------------------------------- *)letrecname_of_host=function|TVar{lv_name=x}->x|TResult_->"result"(* currently not used, but could be one day *)|TMemt->name_of_termtandname_of_term(t:term)=matcht.term_namewitha::_->a|_->matcht.term_nodewith|TLval(lh,_)|TAddrOf(lh,_)|TStartOf(lh,_)->name_of_hostlh|_->raiseNot_foundletannotationsstmt=letcollect_emitterannotacc=matchannot.annot_contentwith|Cil_types.AExtended(_,_,{ext_name="probe";ext_kind=Ext_termsps;})->List.rev_appendpsacc|_->accinletmk_probet=tryname_of_termt,twithNot_found->Wp_parameters.abort~source:(fstt.term_loc)"Missing name for probe, use @probe A: term;"inList.rev_mapmk_probe(Annotations.fold_code_annotcollectstmt[])letparse_probe:Acsl_extension.extension_typer=funcontext_locterms->(* use default context of the code-annotation (like an assert clause) *)letparse_term=context.type_termcontextcontext.pre_stateinExt_terms(List.mapparse_termterms)letregistered=reffalseletregister()=ifnot!registered&&Wp_parameters.Probes.get()thenbeginregistered:=true;Acsl_extension.register_code_annot~plugin:"wp""probe"parse_probefalse;endlet()=Cmdline.run_after_configuring_stageregister(* -------------------------------------------------------------------------- *)