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