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