1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374(* Yoann Padioleau
*
* Copyright (C) 2010 Facebook
* Copyright (C) 2019 r2c
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library 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 file
* license.txt for more details.
*)openCommonopenAst_genericmoduleV=Visitor_astmoduleE=Error_codemoduleCFGB=Controlflow_build(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* Most of the hard work is done by Controlflow_build_generic.ml.
*
* TODO: check dead statements for toplevel blocks ?
*)(*****************************************************************************)(* Helpers *)(*****************************************************************************)letcheck_func_deffdef=tryletflow=Controlflow_build.cfg_of_funcfdefinControlflow_build.deadcode_detectionflow;withControlflow_build.Error(err,loc)->lets=Controlflow_build.string_of_error_kinderrin(matcherr,locwith|CFGB.UnreachableStatement_,Sometok->E.errortok(E.UnreachableStatements)|CFGB.UnreachableStatement_,None->pr2"TODO: unreachable statement detected but no location";|_,Sometok->E.errortok(E.CFGErrors)|_,None->pr2(spf"TODO: CFG error detected but no location: %s"s);)(*****************************************************************************)(* Main entry point *)(*****************************************************************************)letcheck_program2prog=letvisitor=V.mk_visitor{V.default_visitorwith(* also valid for methods *)V.kdef=(fun(k,_)x->let(_entity,def)=xin(matchdefwith|FuncDeffdef->check_func_deffdef|_->());(* process nested definitions *)kx);}invisitor(Prprog)letcheck_programa=Common.profile_code"Checker.cfg"(fun()->check_program2a)