2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
25 (*****************************************************************************)
27 (*****************************************************************************)
30 | MatchPos of Ograph_extended.nodei
31 | MatchNeg of Ograph_extended.nodei
33 (* could generate exn instead, but in many cases as for my acomment gui
34 * I still want to print the match for the other elements, so one failure
35 * should not stop everything
37 | MatchProblem of string
40 (*****************************************************************************)
42 (*****************************************************************************)
44 (*****************************************************************************)
45 (* Specific finder wrappers *)
46 (*****************************************************************************)
47 let (find_nodes_satisfying_pattern:
48 Control_flow_c.cflow -> Ast_cocci.rule_elem -> Ograph_extended.nodei list)=
51 let nodes = flow#nodes in
52 let nodes = nodes#tolist in
53 nodes +> Common.map_filter (fun (nodei, node) ->
55 Pattern_c.match_re_node [] (* dropped isos *)
59 if List.length res > 0
65 let (find_nodes_containing_expr:
66 Control_flow_c.cflow -> Ast_c.expression -> Ograph_extended.nodei list)=
69 let expr = Lib_parsing_c.real_al_expr expr in
71 let nodes = flow#nodes in
72 let nodes = nodes#tolist in
73 nodes +> Common.map_filter (fun (nodei, node) ->
74 let node = Lib_parsing_c.real_al_node node in
76 let found = ref false in
78 Visitor_c.vk_node { Visitor_c.default_visitor_c with
79 Visitor_c.kexpr = (fun (k, bigf) e2 ->
93 (*****************************************************************************)
95 (*****************************************************************************)
99 * todo: Check for all path upwards ?
102 let (find_nodes_upward_satisfying_protocol:
103 Ograph_extended.nodei -> Control_flow_c.cflow ->
104 Ast_cocci.rule_elem * Ast_cocci.rule_elem ->
107 fun nodei flow (pattern1, pattern2) ->
109 let already_done = ref [nodei] in
110 let found = ref [] in
114 List.map fst ((flow#predecessors nodei)#tolist)
116 pred +> List.iter (fun nodei2 ->
117 if List.mem nodei2 !already_done
120 Common.push2 nodei2 already_done;
122 let node2 = flow#nodes#assoc nodei2 in
125 Pattern_c.match_re_node []
130 Pattern_c.match_re_node []
134 match List.length res1 > 0, List.length res2 > 0 with
136 Common.push2 (MatchPos nodei2) found
138 Common.push2 (MatchNeg nodei2) found
140 failwith "wierd, node match both rule_elem"
151 failwith "multiple found";