1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586(* Yoann Padioleau
*
* 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_genericmoduleAst=Ast_genericmoduleV=Visitor_ast_generic(*****************************************************************************)(* Prelude *)(*****************************************************************************)(* See https://github.com/facebook/pfff/wiki/Sgrep
*
*)(*****************************************************************************)(* Type *)(*****************************************************************************)(* right now only Expr are actually supported *)typepattern=Ast.any(*****************************************************************************)(* Main entry point *)(*****************************************************************************)letsgrep_ast~hookpatternast=lethook=matchpatternwith|Epattern_expr->{V.default_visitorwithV.kexpr=(fun(k,_)x->letmatches_with_env=Matching_generic.match_e_epattern_exprxinifmatches_with_env=[]thenkxelsebegin(* could also recurse to find nested matching inside
* the matched code itself.
*)letmatched_tokens=Lib_ast_generic.ii_of_any(Ex)inmatches_with_env+>List.iter(funenv->hookenvmatched_tokens)end);}|Spattern->{V.default_visitorwithV.kstmt=(fun(k,_)x->letmatches_with_env=Matching_generic.match_st_stpatternxinifmatches_with_env=[]thenkxelsebegin(* could also recurse to find nested matching inside
* the matched code itself.
*)letmatched_tokens=Lib_ast_generic.ii_of_any(Sx)inmatches_with_env+>List.iter(funenv->hookenvmatched_tokens)end);}|_->failwith(spf"pattern not yet supported:")in(* opti ? dont analyze func if no constant in it ?*)(V.mk_visitorhook)(Prast)