2a5f0762ecc0c0da9770d12f44b0157203e425c0
[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 (* 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 -> 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_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
103 ref (fun _ -> failwith "uninitialized add_meta")
104
105 let add_paramlist_meta:
106 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
107 ref (fun _ -> failwith "uninitialized add_meta")
108
109 let add_const_meta:
110 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
111 Ast0.pure -> unit)
112 ref =
113 ref (fun _ -> failwith "uninitialized add_meta")
114
115 let add_err_meta:
116 (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref =
117 ref (fun _ -> failwith "uninitialized add_meta")
118
119 let add_exp_meta:
120 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
121 Ast0.pure -> unit)
122 ref =
123 ref (fun _ -> failwith "uninitialized add_meta")
124
125 let add_idexp_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_local_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_explist_meta:
138 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
139 ref (fun _ -> failwith "uninitialized add_meta")
140
141 let add_decl_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
142 ref (fun _ -> failwith "uninitialized add_meta")
143
144 let add_field_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
145 ref (fun _ -> failwith "uninitialized add_meta")
146
147 let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
148 ref (fun _ -> failwith "uninitialized add_meta")
149
150 let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
151 ref (fun _ -> failwith "uninitialized add_meta")
152
153 let add_func_meta:
154 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
155 ref (fun _ -> failwith "uninitialized add_meta")
156
157 let add_local_func_meta:
158 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
159 ref (fun _ -> failwith "uninitialized add_meta")
160
161 let add_declarer_meta:
162 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
163 ref (fun _ -> failwith "uninitialized add_decl")
164
165 let add_iterator_meta:
166 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
167 ref (fun _ -> failwith "uninitialized add_iter")
168
169 let add_pos_meta:
170 (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref =
171 ref (fun _ -> failwith "uninitialized add_meta")
172
173 let add_type_name: (string -> unit) ref =
174 ref (fun _ -> failwith "uninitialized add_type")
175
176 let add_declarer_name: (string -> unit) ref =
177 ref (fun _ -> failwith "uninitialized add_decl")
178
179 let add_iterator_name: (string -> unit) ref =
180 ref (fun _ -> failwith "uninitialized add_iter")
181
182 let init_rule: (unit -> unit) ref =
183 ref (fun _ -> failwith "uninitialized install_bindings")
184
185 let install_bindings: (string -> unit) ref =
186 ref (fun _ -> failwith "uninitialized install_bindings")