Coccinelle release-1.0.0-rc11
[bpt/coccinelle.git] / parsing_cocci / data.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 module Ast0 = Ast0_cocci
28 module Ast = Ast_cocci
29
30 (* types that clutter the .mly file *)
31 (* for iso metavariables, true if they can only match nonmodified, unitary
32 metavariables *)
33 type fresh = bool
34
35 type incl_iso =
36 Include of string | Iso of (string,string) Common.either
37 | Virt of string list (* virtual rules *)
38
39 type clt =
40 line_type * int * int * int * int (* starting spaces *) *
41 (Ast_cocci.added_string * Ast0.position_info) list (* code before *) *
42 (Ast_cocci.added_string * Ast0.position_info) list (* code after *) *
43 Ast0.anything list (* position variable, minus only *)
44
45 (* ---------------------------------------------------------------------- *)
46
47 (* Things that need to be seen by the lexer and parser. *)
48
49 and line_type =
50 MINUS | OPTMINUS | UNIQUEMINUS
51 | PLUS | PLUSPLUS
52 | CONTEXT | UNIQUE | OPT
53
54 type iconstraints = Ast.idconstraint
55 type econstraints = Ast0.constraints
56 type pconstraints = Ast.meta_name list
57
58 let in_rule_name = ref false
59 let in_meta = ref false
60 let in_iso = ref false
61 let in_generating = ref false
62 let ignore_patch_or_match = ref false
63 let in_prolog = ref false
64 (* state machine for lexer..., allows smpl keywords as type names *)
65 let saw_struct = ref false
66 let inheritable_positions =
67 ref ([] : string list) (* rules from which posns can be inherited *)
68
69 let call_in_meta f =
70 in_meta := true; saw_struct := false;
71 let res = f() in
72 in_meta := false;
73 res
74
75 let all_metadecls =
76 (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t)
77
78 let clear_meta: (unit -> unit) ref =
79 ref (fun _ -> failwith "uninitialized add_meta")
80
81 let add_meta_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
82 ref (fun _ -> failwith "uninitialized add_meta")
83
84 let add_id_meta:
85 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
86 ref (fun _ -> failwith "uninitialized add_meta")
87
88 let add_virt_id_meta_found: (string -> string -> unit) ref =
89 ref (fun _ -> failwith "uninitialized add_meta")
90
91 let add_virt_id_meta_not_found:
92 (Ast_cocci.meta_name -> Ast0_cocci.pure -> unit) ref =
93 ref (fun _ -> failwith "uninitialized add_meta")
94
95 let add_fresh_id_meta: (Ast.meta_name -> Ast.seed -> unit) ref =
96 ref (fun _ -> failwith "uninitialized add_meta")
97
98 let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
99 ref (fun _ -> failwith "uninitialized add_meta")
100
101 let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
102 ref (fun _ -> failwith "uninitialized add_meta")
103
104 let add_initlist_meta:
105 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
106 ref (fun _ -> failwith "uninitialized add_meta")
107
108 let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
109 ref (fun _ -> failwith "uninitialized add_meta")
110
111 let add_paramlist_meta:
112 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
113 ref (fun _ -> failwith "uninitialized add_meta")
114
115 let add_const_meta:
116 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
117 Ast0.pure -> unit)
118 ref =
119 ref (fun _ -> failwith "uninitialized add_meta")
120
121 let add_err_meta:
122 (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref =
123 ref (fun _ -> failwith "uninitialized add_meta")
124
125 let add_exp_meta:
126 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
127 Ast0.pure -> unit)
128 ref =
129 ref (fun _ -> failwith "uninitialized add_meta")
130
131 let add_idexp_meta:
132 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
133 Ast0.pure -> unit)
134 ref =
135 ref (fun _ -> failwith "uninitialized add_meta")
136
137 let add_local_idexp_meta:
138 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
139 Ast0.pure -> unit)
140 ref =
141 ref (fun _ -> failwith "uninitialized add_meta")
142
143 let add_explist_meta:
144 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
145 ref (fun _ -> failwith "uninitialized add_meta")
146
147 let add_decl_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
148 ref (fun _ -> failwith "uninitialized add_meta")
149
150 let add_field_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
151 ref (fun _ -> failwith "uninitialized add_meta")
152
153 let add_field_list_meta:
154 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
155 ref (fun _ -> failwith "uninitialized add_meta")
156
157 let add_symbol_meta: (string -> unit) ref =
158 ref (fun _ -> failwith "uninitialized add_meta")
159
160 let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
161 ref (fun _ -> failwith "uninitialized add_meta")
162
163 let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
164 ref (fun _ -> failwith "uninitialized add_meta")
165
166 let add_func_meta:
167 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
168 ref (fun _ -> failwith "uninitialized add_meta")
169
170 let add_local_func_meta:
171 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
172 ref (fun _ -> failwith "uninitialized add_meta")
173
174 let add_declarer_meta:
175 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
176 ref (fun _ -> failwith "uninitialized add_decl")
177
178 let add_iterator_meta:
179 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
180 ref (fun _ -> failwith "uninitialized add_iter")
181
182 let add_pos_meta:
183 (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref =
184 ref (fun _ -> failwith "uninitialized add_meta")
185
186 let add_type_name: (string -> unit) ref =
187 ref (fun _ -> failwith "uninitialized add_type")
188
189 let add_declarer_name: (string -> unit) ref =
190 ref (fun _ -> failwith "uninitialized add_decl")
191
192 let add_iterator_name: (string -> unit) ref =
193 ref (fun _ -> failwith "uninitialized add_iter")
194
195 let init_rule: (unit -> unit) ref =
196 ref (fun _ -> failwith "uninitialized install_bindings")
197
198 let install_bindings: (string -> unit) ref =
199 ref (fun _ -> failwith "uninitialized install_bindings")