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