1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889(****************************************************************************)(* *)(* 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/>. *)(* *)(****************************************************************************)(** Common exceptions and warnings *)(** {2 Warnings} *)(** =-=-=-=-=-=- *)letwarn=Debug.warnletwarn_at=Debug.warn_at(** {2 Panic exceptions} *)(** =-=-=-=-=-=-=-=-=-=- *)letppfmt=Debug.debug~channel:"panic"fmtlet()=Debug.add_channel"panic"letpp_atrangefmt=Format.kasprintf(funstr->pp"%a: %s"Location.pp_rangerangestr)fmtexceptionPanicofstring(** message *)*string(** OCaml line of code *)exceptionPanicAtLocationofLocation.range*string(** message *)*string(** OCaml line of code *)exceptionPanicAtFrameofLocation.range*Callstack.callstack*string(** message *)*string(** OCaml line of code *)(** Raise a panic exception using a formatted string *)letpanic?(loc="")fmt=Format.kasprintf(funstr->raise(Panic(str,loc)))fmtletpanic_at?(loc="")rangefmt=Format.kasprintf(funstr->raise(PanicAtLocation(range,str,loc)))fmtletpanic_at_frame?(loc="")rangecsfmt=Format.kasprintf(funstr->raise(PanicAtFrame(range,cs,str,loc)))fmt(** {2 Syntax-related exceptions *)(** =-=-=-=-=-=-=-=-=-=-=-=-=-=- *)exceptionSyntaxErrorofLocation.range*stringexceptionSyntaxErrorListof(Location.range*string)listexceptionUnnamedSyntaxErrorofLocation.rangeexceptionUnnamedSyntaxErrorListofLocation.rangelistletsyntax_errorrangefmt=Format.kasprintf(funstr->raise(SyntaxError(range,str)))fmtletsyntax_errorsl=raise(SyntaxErrorListl)letunnamed_syntax_errorrange=raise(UnnamedSyntaxErrorrange)letunnamed_syntax_errorsranges=raise(UnnamedSyntaxErrorListranges)