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