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