Release coccinelle-0.2.4
[bpt/coccinelle.git] / parsing_cocci / data.ml
1 (*
2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
7 *
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
11 *
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
25 (*
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
31 *
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
35 *
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
40 *
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
43 *
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
46 *)
47
48
49 module Ast0 = Ast0_cocci
50 module Ast = Ast_cocci
51
52 (* types that clutter the .mly file *)
53 (* for iso metavariables, true if they can only match nonmodified, unitary
54 metavariables *)
55 type fresh = bool
56
57 type incl_iso =
58 Include of string | Iso of (string,string) Common.either
59 | Virt of string list (* virtual rules *)
60
61 type clt =
62 line_type * int * int * int * int (* starting spaces *) *
63 (Ast_cocci.added_string * Ast0.position_info) list (* code before *) *
64 (Ast_cocci.added_string * Ast0.position_info) list (* code after *) *
65 Ast0.meta_pos (* position variable, minus only *)
66
67 (* ---------------------------------------------------------------------- *)
68
69 (* Things that need to be seen by the lexer and parser. *)
70
71 and line_type =
72 MINUS | OPTMINUS | UNIQUEMINUS
73 | PLUS | PLUSPLUS
74 | CONTEXT | UNIQUE | OPT
75
76 type iconstraints = Ast.idconstraint
77 type econstraints = Ast0.constraints
78 type pconstraints = Ast.meta_name list
79
80 let in_rule_name = ref false
81 let in_meta = ref false
82 let in_iso = ref false
83 let in_generating = ref false
84 let ignore_patch_or_match = ref false
85 let in_prolog = ref false
86 (* state machine for lexer..., allows smpl keywords as type names *)
87 let saw_struct = ref false
88 let inheritable_positions =
89 ref ([] : string list) (* rules from which posns can be inherited *)
90
91 let call_in_meta f =
92 in_meta := true; saw_struct := false;
93 let res = f() in
94 in_meta := false;
95 res
96
97 let all_metadecls =
98 (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t)
99
100 let clear_meta: (unit -> unit) ref =
101 ref (fun _ -> failwith "uninitialized add_meta")
102
103 let add_id_meta:
104 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
105 ref (fun _ -> failwith "uninitialized add_meta")
106
107 let add_virt_id_meta_found: (string -> string -> unit) ref =
108 ref (fun _ -> failwith "uninitialized add_meta")
109
110 let add_virt_id_meta_not_found:
111 (Ast_cocci.meta_name -> Ast0_cocci.pure -> unit) ref =
112 ref (fun _ -> failwith "uninitialized add_meta")
113
114 let add_fresh_id_meta: (Ast.meta_name -> unit) ref =
115 ref (fun _ -> failwith "uninitialized add_meta")
116
117 let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
118 ref (fun _ -> failwith "uninitialized add_meta")
119
120 let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
121 ref (fun _ -> failwith "uninitialized add_meta")
122
123 let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
124 ref (fun _ -> failwith "uninitialized add_meta")
125
126 let add_paramlist_meta:
127 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
128 ref (fun _ -> failwith "uninitialized add_meta")
129
130 let add_const_meta:
131 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
132 Ast0.pure -> unit)
133 ref =
134 ref (fun _ -> failwith "uninitialized add_meta")
135
136 let add_err_meta:
137 (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref =
138 ref (fun _ -> failwith "uninitialized add_meta")
139
140 let add_exp_meta:
141 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
142 Ast0.pure -> unit)
143 ref =
144 ref (fun _ -> failwith "uninitialized add_meta")
145
146 let add_idexp_meta:
147 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
148 Ast0.pure -> unit)
149 ref =
150 ref (fun _ -> failwith "uninitialized add_meta")
151
152 let add_local_idexp_meta:
153 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
154 Ast0.pure -> unit)
155 ref =
156 ref (fun _ -> failwith "uninitialized add_meta")
157
158 let add_explist_meta:
159 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
160 ref (fun _ -> failwith "uninitialized add_meta")
161
162 let add_decl_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
163 ref (fun _ -> failwith "uninitialized add_meta")
164
165 let add_field_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
166 ref (fun _ -> failwith "uninitialized add_meta")
167
168 let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
169 ref (fun _ -> failwith "uninitialized add_meta")
170
171 let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
172 ref (fun _ -> failwith "uninitialized add_meta")
173
174 let add_func_meta:
175 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
176 ref (fun _ -> failwith "uninitialized add_meta")
177
178 let add_local_func_meta:
179 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
180 ref (fun _ -> failwith "uninitialized add_meta")
181
182 let add_declarer_meta:
183 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
184 ref (fun _ -> failwith "uninitialized add_decl")
185
186 let add_iterator_meta:
187 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
188 ref (fun _ -> failwith "uninitialized add_iter")
189
190 let add_pos_meta:
191 (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref =
192 ref (fun _ -> failwith "uninitialized add_meta")
193
194 let add_type_name: (string -> unit) ref =
195 ref (fun _ -> failwith "uninitialized add_type")
196
197 let add_declarer_name: (string -> unit) ref =
198 ref (fun _ -> failwith "uninitialized add_decl")
199
200 let add_iterator_name: (string -> unit) ref =
201 ref (fun _ -> failwith "uninitialized add_iter")
202
203 let init_rule: (unit -> unit) ref =
204 ref (fun _ -> failwith "uninitialized install_bindings")
205
206 let install_bindings: (string -> unit) ref =
207 ref (fun _ -> failwith "uninitialized install_bindings")