2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
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.
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.
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.
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/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
27 module Ast0
= Ast0_cocci
28 module Ast
= Ast_cocci
30 (* types that clutter the .mly file *)
31 (* for iso metavariables, true if they can only match nonmodified, unitary
36 Include
of string | Iso
of (string,string) Common.either
37 | Virt
of string list
(* virtual rules *)
40 line_type
* int * int * int * int (* starting spaces *) *
41 (Ast_cocci.added_string
* Ast0.position_info
) list
(* code before *) *
42 (Ast_cocci.added_string
* Ast0.position_info
) list
(* code after *) *
43 Ast0.anything list
(* position variable, minus only *)
45 (* ---------------------------------------------------------------------- *)
47 (* Things that need to be seen by the lexer and parser. *)
50 MINUS
| OPTMINUS
| UNIQUEMINUS
52 | CONTEXT
| UNIQUE
| OPT
54 type iconstraints
= Ast.idconstraint
55 type econstraints
= Ast0.constraints
56 type pconstraints
= Ast.meta_name list
58 let in_rule_name = ref false
59 let in_meta = ref false
60 let in_iso = ref false
61 let in_generating = ref false
62 let ignore_patch_or_match = ref false
63 let in_prolog = ref false
64 (* state machine for lexer..., allows smpl keywords as type names *)
65 let saw_struct = ref false
66 let inheritable_positions =
67 ref ([] : string list
) (* rules from which posns can be inherited *)
70 in_meta := true; saw_struct := false;
76 (Hashtbl.create
(100) : (string, Ast.metavar list
) Hashtbl.t
)
78 let clear_meta: (unit -> unit) ref =
79 ref (fun _
-> failwith
"uninitialized add_meta")
81 let add_meta_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
82 ref (fun _
-> failwith
"uninitialized add_meta")
85 (Ast.meta_name
-> iconstraints
-> Ast0.pure
-> unit) ref =
86 ref (fun _
-> failwith
"uninitialized add_meta")
88 let add_virt_id_meta_found: (string -> string -> unit) ref =
89 ref (fun _
-> failwith
"uninitialized add_meta")
91 let add_virt_id_meta_not_found:
92 (Ast_cocci.meta_name
-> Ast0_cocci.pure
-> unit) ref =
93 ref (fun _
-> failwith
"uninitialized add_meta")
95 let add_fresh_id_meta: (Ast.meta_name
-> Ast.seed
-> unit) ref =
96 ref (fun _
-> failwith
"uninitialized add_meta")
98 let add_type_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
99 ref (fun _
-> failwith
"uninitialized add_meta")
101 let add_init_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
102 ref (fun _
-> failwith
"uninitialized add_meta")
104 let add_initlist_meta:
105 (Ast.meta_name
-> Ast.list_len
-> Ast0.pure
-> unit) ref =
106 ref (fun _
-> failwith
"uninitialized add_meta")
108 let add_param_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
109 ref (fun _
-> failwith
"uninitialized add_meta")
111 let add_paramlist_meta:
112 (Ast.meta_name
-> Ast.list_len
-> Ast0.pure
-> unit) ref =
113 ref (fun _
-> failwith
"uninitialized add_meta")
116 (Type_cocci.typeC list
option -> Ast.meta_name
-> econstraints
->
119 ref (fun _
-> failwith
"uninitialized add_meta")
122 (Ast.meta_name
-> econstraints
-> Ast0.pure
-> unit) ref =
123 ref (fun _
-> failwith
"uninitialized add_meta")
126 (Type_cocci.typeC list
option -> Ast.meta_name
-> econstraints
->
129 ref (fun _
-> failwith
"uninitialized add_meta")
132 (Type_cocci.typeC list
option -> Ast.meta_name
-> econstraints
->
135 ref (fun _
-> failwith
"uninitialized add_meta")
137 let add_local_idexp_meta:
138 (Type_cocci.typeC list
option -> Ast.meta_name
-> econstraints
->
141 ref (fun _
-> failwith
"uninitialized add_meta")
143 let add_explist_meta:
144 (Ast.meta_name
-> Ast.list_len
-> Ast0.pure
-> unit) ref =
145 ref (fun _
-> failwith
"uninitialized add_meta")
147 let add_decl_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
148 ref (fun _
-> failwith
"uninitialized add_meta")
150 let add_field_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
151 ref (fun _
-> failwith
"uninitialized add_meta")
153 let add_field_list_meta:
154 (Ast.meta_name
-> Ast.list_len
-> Ast0.pure
-> unit) ref =
155 ref (fun _
-> failwith
"uninitialized add_meta")
157 let add_symbol_meta: (string -> unit) ref =
158 ref (fun _
-> failwith
"uninitialized add_meta")
160 let add_stm_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
161 ref (fun _
-> failwith
"uninitialized add_meta")
163 let add_stmlist_meta: (Ast.meta_name
-> Ast0.pure
-> unit) ref =
164 ref (fun _
-> failwith
"uninitialized add_meta")
167 (Ast.meta_name
-> iconstraints
-> Ast0.pure
-> unit) ref =
168 ref (fun _
-> failwith
"uninitialized add_meta")
170 let add_local_func_meta:
171 (Ast.meta_name
-> iconstraints
-> Ast0.pure
-> unit) ref =
172 ref (fun _
-> failwith
"uninitialized add_meta")
174 let add_declarer_meta:
175 (Ast.meta_name
-> iconstraints
-> Ast0.pure
-> unit) ref =
176 ref (fun _
-> failwith
"uninitialized add_decl")
178 let add_iterator_meta:
179 (Ast.meta_name
-> iconstraints
-> Ast0.pure
-> unit) ref =
180 ref (fun _
-> failwith
"uninitialized add_iter")
183 (Ast.meta_name
-> pconstraints
-> Ast.meta_collect
-> unit) ref =
184 ref (fun _
-> failwith
"uninitialized add_meta")
186 let add_type_name: (string -> unit) ref =
187 ref (fun _
-> failwith
"uninitialized add_type")
189 let add_declarer_name: (string -> unit) ref =
190 ref (fun _
-> failwith
"uninitialized add_decl")
192 let add_iterator_name: (string -> unit) ref =
193 ref (fun _
-> failwith
"uninitialized add_iter")
195 let init_rule: (unit -> unit) ref =
196 ref (fun _
-> failwith
"uninitialized install_bindings")
198 let install_bindings: (string -> unit) ref =
199 ref (fun _
-> failwith
"uninitialized install_bindings")