123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899(****************************************************************************)(* *)(* This file is part of MOPSA, a Modular Open Platform for Static Analysis. *)(* *)(* Copyright (C) 2017-2019 The MOPSA Project. *)(* *)(* This program is free software: 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, either version 3 of the License, or *)(* (at your option) any later version. *)(* *)(* This program 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. *)(* *)(* You should have received a copy of the GNU Lesser General Public License *)(* along with this program. If not, see <http://www.gnu.org/licenses/>. *)(* *)(****************************************************************************)(** Callstack - representation of the call stack of a program execution *)openLocationtypecallsite={call_fun_orig_name:string;call_fun_uniq_name:string;call_range:range;}letpp_callsitefmtc=Format.fprintffmt"%a: %s"pp_relative_rangec.call_rangec.call_fun_orig_nameletcompare_callsitecc'=ifc==c'then0elseCompare.compose[(fun()->comparec.call_fun_uniq_namec'.call_fun_uniq_name);(fun()->compare_rangec.call_rangec'.call_range);]typecallstack=callsitelistletpp_callstackfmt(cs:callstack)=Format.fprintffmt"@[<v>%a@]"(Format.pp_print_list~pp_sep:(funfmt()->Format.fprintffmt"@,")(funfmtc->Format.fprintffmt"\tfrom %a"pp_callsitec))csletpp_callstack_shortfmtcs=Format.pp_print_list~pp_sep:(funfmt()->Format.fprintffmt" → ")(funfmtc->Format.fprintffmt"%s@%a"c.call_fun_orig_namepp_relative_rangec.call_range)fmtcsletcompare_callstackcscs'=Compare.listcompare_callsitecscs'letempty_callstack:callstack=[]letis_empty_callstack=function|[]->true|_->falseletcallstack_length(cs:callstack):int=List.lengthcsletpush_callstackorig?(uniq=orig)rangecs={call_fun_orig_name=orig;call_fun_uniq_name=uniq;call_range=range}::csexceptionEmpty_callstackletpop_callstackcs=matchcswith|[]->raiseEmpty_callstack|_->List.hdcs,List.tlcsletcallstack_top(cs:callstack):callsite=tryList.hdcswithFailure_->raiseEmpty_callstackletcallstack_begins_with(cs:callstack)(cs':callstack):bool=letn=callstack_lengthcsinletn'=callstack_lengthcs'inifn<=n'thenfalseelseletrecauxix=ifi=n'thencompare_callstackxcs'=0elseaux(i-1)(List.tlx)inauxncs