Coccinelle release-1.0.0-rc11
[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 open Ograph_extended
28
29 (*****************************************************************************)
30 (* the different ctl formula related types *)
31 (*****************************************************************************)
32 type mvar = Ast_cocci.meta_name
33
34 type predicate =
35 InLoop | TrueBranch | FalseBranch
36 | After (* pointer to the code after an if or while *)
37 | FallThrough | LoopFallThrough
38 | Return (* any exit from the current function *)
39 | FunHeader | UnsafeBrace | Top | Exit | ErrorExit | Goto
40 | Paren of Ast_cocci.meta_name
41 | Match of Ast_cocci.rule_elem
42 | Label of Ast_cocci.meta_name
43 | BCLabel of Ast_cocci.meta_name (* parent of break or continue *)
44 | PrefixLabel of Ast_cocci.meta_name
45 | BindGood of Ast_cocci.meta_name (* used to implement \+ *)
46 | BindBad of Ast_cocci.meta_name
47 | FakeBrace
48
49 (* coccionly: *)
50 type ctlcocci = (predicate, Ast_cocci.meta_name) Wrapper_ctl.wrapped_ctl
51
52
53 (*****************************************************************************)
54 (* the different binding types *)
55 (*****************************************************************************)
56 type metavars_binding = Ast_c.metavars_binding
57
58 (* used in ctlcocci_integration *)
59 type metavar_binding_kind2 =
60 | NormalMetaVal of Ast_c.metavar_binding_kind
61 | ParenVal of Ast_cocci.meta_name
62 | LabelVal of labelval
63 | GoodVal | BadVal (* used to implement \+ *)
64
65 and labelval = Absolute of int list | Prefix of int list
66
67 and metavars_binding2 = (mvar, metavar_binding_kind2) Common.assoc
68
69
70
71 (*****************************************************************************)
72 (* the CTL model related types *)
73 (*****************************************************************************)
74 (* coccionly: *)
75 type label_ctlcocci =
76 predicate ->
77 (nodei *
78 (predicate * (mvar, metavar_binding_kind2) Ast_ctl.generic_substitution))
79 list
80
81 type model = Control_flow_c.cflow * label_ctlcocci * nodei list
82
83 type transformation_info =
84 (nodei * metavars_binding * Ast_cocci.rule_elem) list
85
86 type numbered_transformation_info =
87 (int list * (nodei * metavars_binding * Ast_cocci.rule_elem)) list
88
89
90 (*****************************************************************************)
91 (* comparing binding *)
92 (*****************************************************************************)
93
94 let equal_binding xs ys =
95 List.sort compare xs = List.sort compare ys