1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859(* 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.
*)openAst_generic(*****************************************************************************)(* Prelude *)(*****************************************************************************)(* Try to generate a normalized form for the program so we need to handle
* less variations in sgrep, which in turn will allow one pattern
* to match more equivalent code.
*
* TODO:
* - rewrite also IncrDecr to AssignOp
* - use IL instead and go even further in the normalization process?
*)(*****************************************************************************)(* Entry point *)(*****************************************************************************)letnormalize2any=letvisitor=Map_ast.mk_visitor{Map_ast.default_visitorwithMap_ast.kexpr=(fun(k,_)e->(* apply on children *)lete=keinmatchewith|Call(IdSpecial(ArithOpop,tok),[a;b])->letrewrite_opt=matchopwith|NotEq->Some(Not,Eq)|_->Nonein(matchrewrite_optwith|None->e|Some(not_op,other_op)->Call(IdSpecial(ArithOpnot_op,tok),[Arg(Call(IdSpecial(ArithOpother_op,tok),[a;b]))]))|_->e)}invisitor.Map_ast.vanyanyletnormalizea=Common.profile_code"Normalize_ast.normalize"(fun()->normalize2a)