42473b1fc1e8d41c27658ac94b689c1a10f15246
[bpt/coccinelle.git] / engine / lib_engine.ml
1 (*
2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
5 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
6 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
7 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
8 * This file is part of Coccinelle.
9 *
10 * Coccinelle is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, according to version 2 of the License.
13 *
14 * Coccinelle is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
21 *
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
24 *)
25
26
27 # 0 "./lib_engine.ml"
28 open Ograph_extended
29
30 (*****************************************************************************)
31 (* the different ctl formula related types *)
32 (*****************************************************************************)
33 type mvar = Ast_cocci.meta_name
34
35 type predicate =
36 InLoop | TrueBranch | FalseBranch
37 | After (* pointer to the code after an if or while *)
38 | FallThrough | LoopFallThrough
39 | Return (* any exit from the current function *)
40 | FunHeader | UnsafeBrace | Top | Exit | ErrorExit | Goto
41 | Paren of Ast_cocci.meta_name
42 | Match of Ast_cocci.rule_elem
43 | Label of Ast_cocci.meta_name
44 | BCLabel of Ast_cocci.meta_name (* parent of break or continue *)
45 | PrefixLabel of Ast_cocci.meta_name
46 | BindGood of Ast_cocci.meta_name (* used to implement \+ *)
47 | BindBad of Ast_cocci.meta_name
48 | FakeBrace
49
50 (* coccionly: *)
51 type ctlcocci = (predicate, Ast_cocci.meta_name) Wrapper_ctl.wrapped_ctl
52
53
54 (*****************************************************************************)
55 (* the different binding types *)
56 (*****************************************************************************)
57 type metavars_binding = Ast_c.metavars_binding
58
59 (* used in ctlcocci_integration *)
60 type metavar_binding_kind2 =
61 | NormalMetaVal of Ast_c.metavar_binding_kind
62 | ParenVal of Ast_cocci.meta_name
63 | LabelVal of labelval
64 | GoodVal | BadVal (* used to implement \+ *)
65
66 and labelval = Absolute of int list | Prefix of int list
67
68 and metavars_binding2 = (mvar, metavar_binding_kind2) Common.assoc
69
70
71
72 (*****************************************************************************)
73 (* the CTL model related types *)
74 (*****************************************************************************)
75 (* coccionly: *)
76 type label_ctlcocci =
77 predicate ->
78 (nodei *
79 (predicate * (mvar, metavar_binding_kind2) Ast_ctl.generic_substitution))
80 list
81
82 type model = Control_flow_c.cflow * label_ctlcocci * nodei list
83
84 type transformation_info =
85 (nodei * metavars_binding * Ast_cocci.rule_elem) list
86
87 type numbered_transformation_info =
88 (int list * (nodei * metavars_binding * Ast_cocci.rule_elem)) list
89
90
91 (*****************************************************************************)
92 (* comparing binding *)
93 (*****************************************************************************)
94
95 let equal_binding xs ys =
96 List.sort compare xs = List.sort compare ys