X-Git-Url: https://git.hcoop.net/bpt/coccinelle.git/blobdiff_plain/faf9a90c4f9e1e85931cb6b01de660587416eb97..5636bb2c2537506718da74f85a2b81a5ff3df16f:/parsing_cocci/unitary_ast0.ml diff --git a/parsing_cocci/unitary_ast0.ml b/parsing_cocci/unitary_ast0.ml index a58ffef..6d46bc7 100644 --- a/parsing_cocci/unitary_ast0.ml +++ b/parsing_cocci/unitary_ast0.ml @@ -1,29 +1,52 @@ (* -* Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen -* Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller -* This file is part of Coccinelle. -* -* Coccinelle is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, according to version 2 of the License. -* -* Coccinelle 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 General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with Coccinelle. If not, see . -* -* The authors reserve the right to distribute this or future versions of -* Coccinelle under other licenses. -*) + * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen + * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix + * This file is part of Coccinelle. + * + * Coccinelle is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, according to version 2 of the License. + * + * Coccinelle 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Coccinelle. If not, see . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) + + +(* + * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen + * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix + * This file is part of Coccinelle. + * + * Coccinelle is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, according to version 2 of the License. + * + * Coccinelle 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Coccinelle. If not, see . + * + * The authors reserve the right to distribute this or future versions of + * Coccinelle under other licenses. + *) (* find unitary metavariables *) module Ast0 = Ast0_cocci module Ast = Ast_cocci module V0 = Visitor_ast0 +module VT0 = Visitor_ast0_types let set_minus s minus = List.filter (function n -> not (List.mem n minus)) s @@ -39,14 +62,12 @@ let rec nub = function let minus_checker name = let id = Ast0.unwrap_mcode name in [id] (* take only what is in the plus code *) -let plus_checker (nm,_,_,mc,_) = - match mc with Ast0.PLUS -> [nm] | _ -> [] +let plus_checker (nm,_,_,mc,_,_) = + match mc with Ast0.PLUS _ -> [nm] | _ -> [] let get_free checker t = let bind x y = x @ y in let option_default = [] in - let donothing r k e = k e in - let mcode _ = option_default in (* considers a single list *) let collect_unitary_nonunitary free_usage = @@ -95,14 +116,14 @@ let get_free checker t = Ast0.MetaErr(name,_,_) | Ast0.MetaExpr(name,_,_,_,_) | Ast0.MetaExprList(name,_,_) -> checker name | Ast0.DisjExpr(starter,expr_list,mids,ender) -> - detect_unitary_frees(List.map r.V0.combiner_expression expr_list) + detect_unitary_frees(List.map r.VT0.combiner_rec_expression expr_list) | _ -> k e in let typeC r k t = match Ast0.unwrap t with Ast0.MetaType(name,_) -> checker name | Ast0.DisjType(starter,types,mids,ender) -> - detect_unitary_frees(List.map r.V0.combiner_typeC types) + detect_unitary_frees(List.map r.VT0.combiner_rec_typeC types) | _ -> k t in let parameter r k p = @@ -113,45 +134,56 @@ let get_free checker t = let declaration r k d = match Ast0.unwrap d with Ast0.DisjDecl(starter,decls,mids,ender) -> - detect_unitary_frees(List.map r.V0.combiner_declaration decls) + detect_unitary_frees(List.map r.VT0.combiner_rec_declaration decls) | _ -> k d in + let case_line r k c = + match Ast0.unwrap c with + Ast0.DisjCase(starter,case_lines,mids,ender) -> + detect_unitary_frees(List.map r.VT0.combiner_rec_case_line case_lines) + | _ -> k c in + let statement r k s = match Ast0.unwrap s with Ast0.MetaStmt(name,_) | Ast0.MetaStmtList(name,_) -> checker name | Ast0.Disj(starter,stmt_list,mids,ender) -> - detect_unitary_frees(List.map r.V0.combiner_statement_dots stmt_list) + detect_unitary_frees + (List.map r.VT0.combiner_rec_statement_dots stmt_list) | Ast0.Nest(starter,stmt_dots,ender,whn,multi) -> - bind (r.V0.combiner_statement_dots stmt_dots) + bind (r.VT0.combiner_rec_statement_dots stmt_dots) (detect_unitary_frees (List.map - (whencode r.V0.combiner_statement_dots r.V0.combiner_statement - r.V0.combiner_expression) + (whencode + r.VT0.combiner_rec_statement_dots + r.VT0.combiner_rec_statement + r.VT0.combiner_rec_expression) whn)) | Ast0.Dots(d,whn) | Ast0.Circles(d,whn) | Ast0.Stars(d,whn) -> detect_unitary_frees (List.map - (whencode r.V0.combiner_statement_dots r.V0.combiner_statement - r.V0.combiner_expression) + (whencode + r.VT0.combiner_rec_statement_dots r.VT0.combiner_rec_statement + r.VT0.combiner_rec_expression) whn) | _ -> k s in let res = V0.combiner bind option_default - mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing - ident expression typeC donothing parameter declaration statement - donothing donothing in + {V0.combiner_functions with + VT0.combiner_identfn = ident; + VT0.combiner_exprfn = expression; + VT0.combiner_tyfn = typeC; + VT0.combiner_paramfn = parameter; + VT0.combiner_declfn = declaration; + VT0.combiner_stmtfn = statement; + VT0.combiner_casefn = case_line} in collect_unitary_nonunitary - (List.concat (List.map res.V0.combiner_top_level t)) + (List.concat (List.map res.VT0.combiner_rec_top_level t)) (* ----------------------------------------------------------------------- *) (* update the variables that are unitary *) let update_unitary unitary = - let donothing r k e = k e in - let mcode x = x in - let is_unitary name = match (List.mem (Ast0.unwrap_mcode name) unitary, !Flag.sgrep_mode2, Ast0.get_mcode_mcodekind name) with @@ -203,12 +235,14 @@ let update_unitary unitary = | _ -> k s in let res = V0.rebuilder - mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode - donothing donothing donothing donothing donothing donothing - ident expression typeC donothing parameter donothing statement - donothing donothing in + {V0.rebuilder_functions with + VT0.rebuilder_identfn = ident; + VT0.rebuilder_exprfn = expression; + VT0.rebuilder_tyfn = typeC; + VT0.rebuilder_paramfn = parameter; + VT0.rebuilder_stmtfn = statement} in - List.map res.V0.rebuilder_top_level + List.map res.VT0.rebuilder_rec_top_level (* ----------------------------------------------------------------------- *) @@ -229,7 +263,8 @@ let do_unitary rules = [] -> ([],[]) | (r::rules) -> match r with - Ast0.ScriptRule (a,b,c,d) -> + Ast0.ScriptRule (_,_,_,_) + | Ast0.InitialScriptRule (_,_,_) | Ast0.FinalScriptRule (_,_,_) -> let (x,rules) = loop rules in (x, r::rules) | Ast0.CocciRule ((minus,metavars,chosen_isos),((plus,_) as plusz),rt) ->