75a83e5071827a1f70510f7a6987db1ef6085ecc
[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_id_meta:
80 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
81 ref (fun _ -> failwith "uninitialized add_meta")
82
83 let add_virt_id_meta_found: (string -> string -> unit) ref =
84 ref (fun _ -> failwith "uninitialized add_meta")
85
86 let add_virt_id_meta_not_found:
87 (Ast_cocci.meta_name -> Ast0_cocci.pure -> unit) ref =
88 ref (fun _ -> failwith "uninitialized add_meta")
89
90 let add_fresh_id_meta: (Ast.meta_name -> unit) ref =
91 ref (fun _ -> failwith "uninitialized add_meta")
92
93 let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
94 ref (fun _ -> failwith "uninitialized add_meta")
95
96 let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
97 ref (fun _ -> failwith "uninitialized add_meta")
98
99 let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
100 ref (fun _ -> failwith "uninitialized add_meta")
101
102 let add_paramlist_meta:
103 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
104 ref (fun _ -> failwith "uninitialized add_meta")
105
106 let add_const_meta:
107 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
108 Ast0.pure -> unit)
109 ref =
110 ref (fun _ -> failwith "uninitialized add_meta")
111
112 let add_err_meta:
113 (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref =
114 ref (fun _ -> failwith "uninitialized add_meta")
115
116 let add_exp_meta:
117 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
118 Ast0.pure -> unit)
119 ref =
120 ref (fun _ -> failwith "uninitialized add_meta")
121
122 let add_idexp_meta:
123 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
124 Ast0.pure -> unit)
125 ref =
126 ref (fun _ -> failwith "uninitialized add_meta")
127
128 let add_local_idexp_meta:
129 (Type_cocci.typeC list option -> Ast.meta_name -> econstraints ->
130 Ast0.pure -> unit)
131 ref =
132 ref (fun _ -> failwith "uninitialized add_meta")
133
134 let add_explist_meta:
135 (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref =
136 ref (fun _ -> failwith "uninitialized add_meta")
137
138 let add_decl_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
139 ref (fun _ -> failwith "uninitialized add_meta")
140
141 let add_field_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
142 ref (fun _ -> failwith "uninitialized add_meta")
143
144 let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
145 ref (fun _ -> failwith "uninitialized add_meta")
146
147 let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref =
148 ref (fun _ -> failwith "uninitialized add_meta")
149
150 let add_func_meta:
151 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
152 ref (fun _ -> failwith "uninitialized add_meta")
153
154 let add_local_func_meta:
155 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
156 ref (fun _ -> failwith "uninitialized add_meta")
157
158 let add_declarer_meta:
159 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
160 ref (fun _ -> failwith "uninitialized add_decl")
161
162 let add_iterator_meta:
163 (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref =
164 ref (fun _ -> failwith "uninitialized add_iter")
165
166 let add_pos_meta:
167 (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref =
168 ref (fun _ -> failwith "uninitialized add_meta")
169
170 let add_type_name: (string -> unit) ref =
171 ref (fun _ -> failwith "uninitialized add_type")
172
173 let add_declarer_name: (string -> unit) ref =
174 ref (fun _ -> failwith "uninitialized add_decl")
175
176 let add_iterator_name: (string -> unit) ref =
177 ref (fun _ -> failwith "uninitialized add_iter")
178
179 let init_rule: (unit -> unit) ref =
180 ref (fun _ -> failwith "uninitialized install_bindings")
181
182 let install_bindings: (string -> unit) ref =
183 ref (fun _ -> failwith "uninitialized install_bindings")