123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2025 *)(* 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_typesmoduleCallsite=Datatype.Pair(Kernel_function)(Cil_datatype.Kinstr)typecall_site=Callsite.tincludeDatatype.With_collections(Datatype.List(Callsite))letinitkf=[(kf,Kglobal)]letpopcs=matchcswith|[]|(_,Kglobal)::_::_|[(_,Kstmt_)]->assertfalse(* Invariant *)|[(_,Kglobal)]->None|(kf,Kstmtstmt)::t->Some(kf,stmt,t)lettop_kfcs=matchcswith|[]|(_,Kglobal)::_::_|[(_,Kstmt_)]->assertfalse(* Invariant *)|(kf,_)::_->kfletrecpop_downtotop_kf=function|[]->failwith"the callstack doesn't contain this function"|((kf,_kinstr)::tail)ascs->ifKernel_function.equalkftop_kfthencselsepop_downtotop_kftailletpush(kf,stmt)cs=matchcswith(* When the callstack is truncated, we ignore the first callsite *)|[]->[(kf,Kglobal)]|cs->(kf,Kstmtstmt)::csletrecis_prefixcs1cs2=matchcs1,cs2with|[],_->true|_,[]->false|[(kf,Kglobal)],(kf',_)::_->Kernel_function.equalkfkf'|_,[(_,Kglobal)]->false|s1::t1,s2::t2->ifCallsite.equals1s2thenis_prefixt1t2elsefalselettruncate_to_subfull_cssub_cs=letrecauxacc=function|[]->None|(s::t)ascs->ifis_prefixsub_cscsthenSome(List.rev_appendaccsub_cs)elseaux(s::acc)tinaux[]full_cs