123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081(*********************************************************************************)(* Xtmpl *)(* *)(* Copyright (C) 2012-2021 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* 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 Library 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, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(* *)(*********************************************************************************)(** *)letmkloc=Location.mklocletlidlocs=letb=Lexing.from_stringsinmkloc(Parse.longidentb)locleterrorlocmsg=raise(Location.Error(Location.error~locmsg))letkerrorloc=Printf.ksprintf(errorloc)openPpxlibopenAst_helpermoduleLocation=Ppxlib_ast__Import.Location(** Test if a case is a catchall. *)letis_catchallcase=letrecis_catchall_patp=matchp.ppat_descwith|Ppat_any|Ppat_var_->true|Ppat_alias(p,_)|Ppat_constraint(p,_)->is_catchall_patp|_->falseincase.pc_guard=None&&is_catchall_patcase.pc_lhsclassmapper=object(self)inheritAst_traverse.mapassupermethod!expressionexpr=matchexprwith|{pexp_desc=Pexp_extension({txt="debug";loc},PStr[{pstr_desc=Pstr_eval(e,_)}]);_}->(letargs=matche.pexp_descwith|Ast.Pexp_apply(e,args)->e::(List.mapsndargs)|_->[e]inletargs=List.map(funa->(Nolabel,a))argsinletmoduleB=Ast_builderinletapply=B.Default.pexp_apply~loc[%exprprint]argsinletdbg=[%exprLog.debug(funprint->[%eapply]);]inlete=[%exprif!Log.debug_enabledthen[%edbg]]insuper#expressione)|_->super#expressionexprendlet()=letmapper=newmapperinDriver.register_transformation~impl:mapper#structure"stk_ppx_debug"