Commit | Line | Data |
---|---|---|
9bc82bae C |
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 | ||
c491d8ee C |
25 | (* |
26 | * Copyright 2010, INRIA, University of Copenhagen | |
27 | * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix | |
28 | * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen | |
29 | * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix | |
30 | * This file is part of Coccinelle. | |
31 | * | |
32 | * Coccinelle is free software: you can redistribute it and/or modify | |
33 | * it under the terms of the GNU General Public License as published by | |
34 | * the Free Software Foundation, according to version 2 of the License. | |
35 | * | |
36 | * Coccinelle is distributed in the hope that it will be useful, | |
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
39 | * GNU General Public License for more details. | |
40 | * | |
41 | * You should have received a copy of the GNU General Public License | |
42 | * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>. | |
43 | * | |
44 | * The authors reserve the right to distribute this or future versions of | |
45 | * Coccinelle under other licenses. | |
46 | *) | |
47 | ||
48 | ||
34e49164 C |
49 | module Ast0 = Ast0_cocci |
50 | module Ast = Ast_cocci | |
51 | ||
52 | (* types that clutter the .mly file *) | |
53 | (* for iso metavariables, true if they can only match nonmodified, unitary | |
54 | metavariables *) | |
55 | type fresh = bool | |
56 | ||
951c7801 C |
57 | type incl_iso = |
58 | Include of string | Iso of (string,string) Common.either | |
59 | | Virt of string list (* virtual rules *) | |
978fd7e5 | 60 | |
34e49164 C |
61 | type clt = |
62 | line_type * int * int * int * int (* starting spaces *) * | |
c3e37e97 C |
63 | (Ast_cocci.added_string * Ast0.position_info) list (* code before *) * |
64 | (Ast_cocci.added_string * Ast0.position_info) list (* code after *) * | |
34e49164 C |
65 | Ast0.meta_pos (* position variable, minus only *) |
66 | ||
67 | (* ---------------------------------------------------------------------- *) | |
68 | ||
69 | (* Things that need to be seen by the lexer and parser. *) | |
70 | ||
71 | and line_type = | |
72 | MINUS | OPTMINUS | UNIQUEMINUS | |
951c7801 | 73 | | PLUS | PLUSPLUS |
34e49164 C |
74 | | CONTEXT | UNIQUE | OPT |
75 | ||
951c7801 C |
76 | type iconstraints = Ast.idconstraint |
77 | type econstraints = Ast0.constraints | |
34e49164 C |
78 | type pconstraints = Ast.meta_name list |
79 | ||
80 | let in_rule_name = ref false | |
81 | let in_meta = ref false | |
82 | let in_iso = ref false | |
faf9a90c | 83 | let in_generating = ref false |
7f004419 | 84 | let ignore_patch_or_match = ref false |
34e49164 | 85 | let in_prolog = ref false |
978fd7e5 C |
86 | (* state machine for lexer..., allows smpl keywords as type names *) |
87 | let saw_struct = ref false | |
34e49164 C |
88 | let inheritable_positions = |
89 | ref ([] : string list) (* rules from which posns can be inherited *) | |
90 | ||
978fd7e5 C |
91 | let call_in_meta f = |
92 | in_meta := true; saw_struct := false; | |
93 | let res = f() in | |
94 | in_meta := false; | |
95 | res | |
96 | ||
34e49164 C |
97 | let all_metadecls = |
98 | (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t) | |
99 | ||
faf9a90c C |
100 | let clear_meta: (unit -> unit) ref = |
101 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
102 | |
103 | let add_id_meta: | |
faf9a90c C |
104 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
105 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 106 | |
ae4735db C |
107 | let add_virt_id_meta_found: (string -> string -> unit) ref = |
108 | ref (fun _ -> failwith "uninitialized add_meta") | |
109 | ||
110 | let add_virt_id_meta_not_found: | |
111 | (Ast_cocci.meta_name -> Ast0_cocci.pure -> unit) ref = | |
112 | ref (fun _ -> failwith "uninitialized add_meta") | |
113 | ||
b1b2de81 C |
114 | let add_fresh_id_meta: (Ast.meta_name -> unit) ref = |
115 | ref (fun _ -> failwith "uninitialized add_meta") | |
116 | ||
faf9a90c C |
117 | let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
118 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 119 | |
113803cf C |
120 | let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
121 | ref (fun _ -> failwith "uninitialized add_meta") | |
122 | ||
faf9a90c C |
123 | let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
124 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
125 | |
126 | let add_paramlist_meta: | |
88e71198 | 127 | (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref = |
faf9a90c | 128 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
129 | |
130 | let add_const_meta: | |
131 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
132 | Ast0.pure -> unit) | |
133 | ref = | |
faf9a90c | 134 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
135 | |
136 | let add_err_meta: | |
137 | (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 138 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
139 | |
140 | let add_exp_meta: | |
141 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
142 | Ast0.pure -> unit) | |
143 | ref = | |
faf9a90c | 144 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
145 | |
146 | let add_idexp_meta: | |
147 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
148 | Ast0.pure -> unit) | |
149 | ref = | |
faf9a90c | 150 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
151 | |
152 | let add_local_idexp_meta: | |
153 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
154 | Ast0.pure -> unit) | |
155 | ref = | |
faf9a90c | 156 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
157 | |
158 | let add_explist_meta: | |
88e71198 | 159 | (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref = |
faf9a90c | 160 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 | 161 | |
413ffc02 C |
162 | let add_decl_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
163 | ref (fun _ -> failwith "uninitialized add_meta") | |
164 | ||
165 | let add_field_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = | |
166 | ref (fun _ -> failwith "uninitialized add_meta") | |
167 | ||
faf9a90c C |
168 | let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
169 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 170 | |
faf9a90c C |
171 | let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
172 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
173 | |
174 | let add_func_meta: | |
faf9a90c C |
175 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
176 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
177 | |
178 | let add_local_func_meta: | |
faf9a90c C |
179 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
180 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
181 | |
182 | let add_declarer_meta: | |
183 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 184 | ref (fun _ -> failwith "uninitialized add_decl") |
34e49164 C |
185 | |
186 | let add_iterator_meta: | |
187 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 188 | ref (fun _ -> failwith "uninitialized add_iter") |
34e49164 C |
189 | |
190 | let add_pos_meta: | |
faf9a90c C |
191 | (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref = |
192 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 193 | |
faf9a90c C |
194 | let add_type_name: (string -> unit) ref = |
195 | ref (fun _ -> failwith "uninitialized add_type") | |
34e49164 | 196 | |
faf9a90c C |
197 | let add_declarer_name: (string -> unit) ref = |
198 | ref (fun _ -> failwith "uninitialized add_decl") | |
34e49164 | 199 | |
faf9a90c C |
200 | let add_iterator_name: (string -> unit) ref = |
201 | ref (fun _ -> failwith "uninitialized add_iter") | |
34e49164 C |
202 | |
203 | let init_rule: (unit -> unit) ref = | |
faf9a90c | 204 | ref (fun _ -> failwith "uninitialized install_bindings") |
34e49164 C |
205 | |
206 | let install_bindings: (string -> unit) ref = | |
faf9a90c | 207 | ref (fun _ -> failwith "uninitialized install_bindings") |