Commit | Line | Data |
---|---|---|
5636bb2c | 1 | (* |
90aeb998 C |
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 | |
9f8e26f4 C |
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 | ||
34e49164 C |
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 | ||
951c7801 C |
33 | type incl_iso = |
34 | Include of string | Iso of (string,string) Common.either | |
35 | | Virt of string list (* virtual rules *) | |
978fd7e5 | 36 | |
34e49164 C |
37 | type clt = |
38 | line_type * int * int * int * int (* starting spaces *) * | |
c3e37e97 C |
39 | (Ast_cocci.added_string * Ast0.position_info) list (* code before *) * |
40 | (Ast_cocci.added_string * Ast0.position_info) list (* code after *) * | |
34e49164 C |
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 | |
951c7801 | 49 | | PLUS | PLUSPLUS |
34e49164 C |
50 | | CONTEXT | UNIQUE | OPT |
51 | ||
951c7801 C |
52 | type iconstraints = Ast.idconstraint |
53 | type econstraints = Ast0.constraints | |
34e49164 C |
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 | |
faf9a90c | 59 | let in_generating = ref false |
7f004419 | 60 | let ignore_patch_or_match = ref false |
34e49164 | 61 | let in_prolog = ref false |
978fd7e5 C |
62 | (* state machine for lexer..., allows smpl keywords as type names *) |
63 | let saw_struct = ref false | |
34e49164 C |
64 | let inheritable_positions = |
65 | ref ([] : string list) (* rules from which posns can be inherited *) | |
66 | ||
978fd7e5 C |
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 | ||
34e49164 C |
73 | let all_metadecls = |
74 | (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t) | |
75 | ||
faf9a90c C |
76 | let clear_meta: (unit -> unit) ref = |
77 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
78 | |
79 | let add_id_meta: | |
faf9a90c C |
80 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
81 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 82 | |
ae4735db C |
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 | ||
b1b2de81 C |
90 | let add_fresh_id_meta: (Ast.meta_name -> unit) ref = |
91 | ref (fun _ -> failwith "uninitialized add_meta") | |
92 | ||
faf9a90c C |
93 | let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
94 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 95 | |
113803cf C |
96 | let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
97 | ref (fun _ -> failwith "uninitialized add_meta") | |
98 | ||
faf9a90c C |
99 | let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
100 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
101 | |
102 | let add_paramlist_meta: | |
faf9a90c C |
103 | (Ast.meta_name -> Ast.meta_name option -> Ast0.pure -> unit) ref = |
104 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
105 | |
106 | let add_const_meta: | |
107 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
108 | Ast0.pure -> unit) | |
109 | ref = | |
faf9a90c | 110 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
111 | |
112 | let add_err_meta: | |
113 | (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 114 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
115 | |
116 | let add_exp_meta: | |
117 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
118 | Ast0.pure -> unit) | |
119 | ref = | |
faf9a90c | 120 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
121 | |
122 | let add_idexp_meta: | |
123 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
124 | Ast0.pure -> unit) | |
125 | ref = | |
faf9a90c | 126 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
127 | |
128 | let add_local_idexp_meta: | |
129 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
130 | Ast0.pure -> unit) | |
131 | ref = | |
faf9a90c | 132 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
133 | |
134 | let add_explist_meta: | |
faf9a90c C |
135 | (Ast.meta_name -> Ast.meta_name option -> Ast0.pure -> unit) ref = |
136 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 137 | |
faf9a90c C |
138 | let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
139 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 140 | |
faf9a90c C |
141 | let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
142 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
143 | |
144 | let add_func_meta: | |
faf9a90c C |
145 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
146 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
147 | |
148 | let add_local_func_meta: | |
faf9a90c C |
149 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
150 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
151 | |
152 | let add_declarer_meta: | |
153 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 154 | ref (fun _ -> failwith "uninitialized add_decl") |
34e49164 C |
155 | |
156 | let add_iterator_meta: | |
157 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 158 | ref (fun _ -> failwith "uninitialized add_iter") |
34e49164 C |
159 | |
160 | let add_pos_meta: | |
faf9a90c C |
161 | (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref = |
162 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 163 | |
faf9a90c C |
164 | let add_type_name: (string -> unit) ref = |
165 | ref (fun _ -> failwith "uninitialized add_type") | |
34e49164 | 166 | |
faf9a90c C |
167 | let add_declarer_name: (string -> unit) ref = |
168 | ref (fun _ -> failwith "uninitialized add_decl") | |
34e49164 | 169 | |
faf9a90c C |
170 | let add_iterator_name: (string -> unit) ref = |
171 | ref (fun _ -> failwith "uninitialized add_iter") | |
34e49164 C |
172 | |
173 | let init_rule: (unit -> unit) ref = | |
faf9a90c | 174 | ref (fun _ -> failwith "uninitialized install_bindings") |
34e49164 C |
175 | |
176 | let install_bindings: (string -> unit) ref = | |
faf9a90c | 177 | ref (fun _ -> failwith "uninitialized install_bindings") |