Commit | Line | Data |
---|---|---|
f537ebc4 | 1 | (* |
17ba0788 C |
2 | * Copyright 2012, INRIA |
3 | * Julia Lawall, Gilles Muller | |
4 | * Copyright 2010-2011, INRIA, University of Copenhagen | |
f537ebc4 C |
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. | |
9 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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/>. | |
21 | * | |
22 | * The authors reserve the right to distribute this or future versions of | |
23 | * Coccinelle under other licenses. | |
24 | *) | |
25 | ||
26 | ||
34e49164 C |
27 | module Ast0 = Ast0_cocci |
28 | module Ast = Ast_cocci | |
29 | ||
30 | (* types that clutter the .mly file *) | |
31 | (* for iso metavariables, true if they can only match nonmodified, unitary | |
32 | metavariables *) | |
33 | type fresh = bool | |
34 | ||
951c7801 C |
35 | type incl_iso = |
36 | Include of string | Iso of (string,string) Common.either | |
37 | | Virt of string list (* virtual rules *) | |
978fd7e5 | 38 | |
34e49164 C |
39 | type clt = |
40 | line_type * int * int * int * int (* starting spaces *) * | |
c3e37e97 C |
41 | (Ast_cocci.added_string * Ast0.position_info) list (* code before *) * |
42 | (Ast_cocci.added_string * Ast0.position_info) list (* code after *) * | |
17ba0788 | 43 | Ast0.anything list (* position variable, minus only *) |
34e49164 C |
44 | |
45 | (* ---------------------------------------------------------------------- *) | |
46 | ||
47 | (* Things that need to be seen by the lexer and parser. *) | |
48 | ||
49 | and line_type = | |
50 | MINUS | OPTMINUS | UNIQUEMINUS | |
951c7801 | 51 | | PLUS | PLUSPLUS |
34e49164 C |
52 | | CONTEXT | UNIQUE | OPT |
53 | ||
951c7801 C |
54 | type iconstraints = Ast.idconstraint |
55 | type econstraints = Ast0.constraints | |
34e49164 C |
56 | type pconstraints = Ast.meta_name list |
57 | ||
58 | let in_rule_name = ref false | |
59 | let in_meta = ref false | |
60 | let in_iso = ref false | |
faf9a90c | 61 | let in_generating = ref false |
7f004419 | 62 | let ignore_patch_or_match = ref false |
34e49164 | 63 | let in_prolog = ref false |
978fd7e5 C |
64 | (* state machine for lexer..., allows smpl keywords as type names *) |
65 | let saw_struct = ref false | |
34e49164 C |
66 | let inheritable_positions = |
67 | ref ([] : string list) (* rules from which posns can be inherited *) | |
68 | ||
978fd7e5 C |
69 | let call_in_meta f = |
70 | in_meta := true; saw_struct := false; | |
71 | let res = f() in | |
72 | in_meta := false; | |
73 | res | |
74 | ||
34e49164 C |
75 | let all_metadecls = |
76 | (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t) | |
77 | ||
faf9a90c C |
78 | let clear_meta: (unit -> unit) ref = |
79 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 80 | |
b23ff9c7 C |
81 | let add_meta_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
82 | ref (fun _ -> failwith "uninitialized add_meta") | |
83 | ||
34e49164 | 84 | let add_id_meta: |
faf9a90c C |
85 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
86 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 87 | |
ae4735db C |
88 | let add_virt_id_meta_found: (string -> string -> unit) ref = |
89 | ref (fun _ -> failwith "uninitialized add_meta") | |
90 | ||
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") | |
94 | ||
8babbc8f | 95 | let add_fresh_id_meta: (Ast.meta_name -> Ast.seed -> unit) ref = |
b1b2de81 C |
96 | ref (fun _ -> failwith "uninitialized add_meta") |
97 | ||
faf9a90c C |
98 | let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
99 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 100 | |
113803cf | 101 | let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
8f657093 C |
102 | ref (fun _ -> failwith "uninitialized add_meta") |
103 | ||
104 | let add_initlist_meta: | |
105 | (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref = | |
113803cf C |
106 | ref (fun _ -> failwith "uninitialized add_meta") |
107 | ||
faf9a90c C |
108 | let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
109 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
110 | |
111 | let add_paramlist_meta: | |
88e71198 | 112 | (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref = |
faf9a90c | 113 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
114 | |
115 | let add_const_meta: | |
116 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
117 | Ast0.pure -> unit) | |
118 | ref = | |
faf9a90c | 119 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
120 | |
121 | let add_err_meta: | |
122 | (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 123 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
124 | |
125 | let add_exp_meta: | |
126 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
127 | Ast0.pure -> unit) | |
128 | ref = | |
faf9a90c | 129 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
130 | |
131 | let add_idexp_meta: | |
132 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
133 | Ast0.pure -> unit) | |
134 | ref = | |
faf9a90c | 135 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
136 | |
137 | let add_local_idexp_meta: | |
138 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
139 | Ast0.pure -> unit) | |
140 | ref = | |
faf9a90c | 141 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
142 | |
143 | let add_explist_meta: | |
88e71198 | 144 | (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref = |
faf9a90c | 145 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 | 146 | |
413ffc02 C |
147 | let add_decl_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
148 | ref (fun _ -> failwith "uninitialized add_meta") | |
149 | ||
150 | let add_field_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = | |
151 | ref (fun _ -> failwith "uninitialized add_meta") | |
152 | ||
190f1acf C |
153 | let add_field_list_meta: |
154 | (Ast.meta_name -> Ast.list_len -> Ast0.pure -> unit) ref = | |
155 | ref (fun _ -> failwith "uninitialized add_meta") | |
156 | ||
97111a47 C |
157 | let add_symbol_meta: (string -> unit) ref = |
158 | ref (fun _ -> failwith "uninitialized add_meta") | |
159 | ||
faf9a90c C |
160 | let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
161 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 162 | |
faf9a90c C |
163 | let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
164 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
165 | |
166 | let add_func_meta: | |
faf9a90c C |
167 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
168 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
169 | |
170 | let add_local_func_meta: | |
faf9a90c C |
171 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
172 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
173 | |
174 | let add_declarer_meta: | |
175 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 176 | ref (fun _ -> failwith "uninitialized add_decl") |
34e49164 C |
177 | |
178 | let add_iterator_meta: | |
179 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 180 | ref (fun _ -> failwith "uninitialized add_iter") |
34e49164 C |
181 | |
182 | let add_pos_meta: | |
faf9a90c C |
183 | (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref = |
184 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 185 | |
faf9a90c C |
186 | let add_type_name: (string -> unit) ref = |
187 | ref (fun _ -> failwith "uninitialized add_type") | |
34e49164 | 188 | |
faf9a90c C |
189 | let add_declarer_name: (string -> unit) ref = |
190 | ref (fun _ -> failwith "uninitialized add_decl") | |
34e49164 | 191 | |
faf9a90c C |
192 | let add_iterator_name: (string -> unit) ref = |
193 | ref (fun _ -> failwith "uninitialized add_iter") | |
34e49164 C |
194 | |
195 | let init_rule: (unit -> unit) ref = | |
faf9a90c | 196 | ref (fun _ -> failwith "uninitialized install_bindings") |
34e49164 C |
197 | |
198 | let install_bindings: (string -> unit) ref = | |
faf9a90c | 199 | ref (fun _ -> failwith "uninitialized install_bindings") |