Commit | Line | Data |
---|---|---|
9f8e26f4 | 1 | (* |
ae4735db | 2 | * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen |
9f8e26f4 C |
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 | ||
34e49164 C |
23 | module Ast0 = Ast0_cocci |
24 | module Ast = Ast_cocci | |
25 | ||
26 | (* types that clutter the .mly file *) | |
27 | (* for iso metavariables, true if they can only match nonmodified, unitary | |
28 | metavariables *) | |
29 | type fresh = bool | |
30 | ||
951c7801 C |
31 | type incl_iso = |
32 | Include of string | Iso of (string,string) Common.either | |
33 | | Virt of string list (* virtual rules *) | |
978fd7e5 | 34 | |
34e49164 C |
35 | type clt = |
36 | line_type * int * int * int * int (* starting spaces *) * | |
c3e37e97 C |
37 | (Ast_cocci.added_string * Ast0.position_info) list (* code before *) * |
38 | (Ast_cocci.added_string * Ast0.position_info) list (* code after *) * | |
34e49164 C |
39 | Ast0.meta_pos (* position variable, minus only *) |
40 | ||
41 | (* ---------------------------------------------------------------------- *) | |
42 | ||
43 | (* Things that need to be seen by the lexer and parser. *) | |
44 | ||
45 | and line_type = | |
46 | MINUS | OPTMINUS | UNIQUEMINUS | |
951c7801 | 47 | | PLUS | PLUSPLUS |
34e49164 C |
48 | | CONTEXT | UNIQUE | OPT |
49 | ||
951c7801 C |
50 | type iconstraints = Ast.idconstraint |
51 | type econstraints = Ast0.constraints | |
34e49164 C |
52 | type pconstraints = Ast.meta_name list |
53 | ||
54 | let in_rule_name = ref false | |
55 | let in_meta = ref false | |
56 | let in_iso = ref false | |
faf9a90c | 57 | let in_generating = ref false |
7f004419 | 58 | let ignore_patch_or_match = ref false |
34e49164 | 59 | let in_prolog = ref false |
978fd7e5 C |
60 | (* state machine for lexer..., allows smpl keywords as type names *) |
61 | let saw_struct = ref false | |
34e49164 C |
62 | let inheritable_positions = |
63 | ref ([] : string list) (* rules from which posns can be inherited *) | |
64 | ||
978fd7e5 C |
65 | let call_in_meta f = |
66 | in_meta := true; saw_struct := false; | |
67 | let res = f() in | |
68 | in_meta := false; | |
69 | res | |
70 | ||
34e49164 C |
71 | let all_metadecls = |
72 | (Hashtbl.create(100) : (string, Ast.metavar list) Hashtbl.t) | |
73 | ||
faf9a90c C |
74 | let clear_meta: (unit -> unit) ref = |
75 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
76 | |
77 | let add_id_meta: | |
faf9a90c C |
78 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
79 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 80 | |
ae4735db C |
81 | let add_virt_id_meta_found: (string -> string -> unit) ref = |
82 | ref (fun _ -> failwith "uninitialized add_meta") | |
83 | ||
84 | let add_virt_id_meta_not_found: | |
85 | (Ast_cocci.meta_name -> Ast0_cocci.pure -> unit) ref = | |
86 | ref (fun _ -> failwith "uninitialized add_meta") | |
87 | ||
b1b2de81 C |
88 | let add_fresh_id_meta: (Ast.meta_name -> unit) ref = |
89 | ref (fun _ -> failwith "uninitialized add_meta") | |
90 | ||
faf9a90c C |
91 | let add_type_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
92 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 93 | |
113803cf C |
94 | let add_init_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
95 | ref (fun _ -> failwith "uninitialized add_meta") | |
96 | ||
faf9a90c C |
97 | let add_param_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
98 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
99 | |
100 | let add_paramlist_meta: | |
faf9a90c C |
101 | (Ast.meta_name -> Ast.meta_name option -> Ast0.pure -> unit) ref = |
102 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
103 | |
104 | let add_const_meta: | |
105 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
106 | Ast0.pure -> unit) | |
107 | ref = | |
faf9a90c | 108 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
109 | |
110 | let add_err_meta: | |
111 | (Ast.meta_name -> econstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 112 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
113 | |
114 | let add_exp_meta: | |
115 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
116 | Ast0.pure -> unit) | |
117 | ref = | |
faf9a90c | 118 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
119 | |
120 | let add_idexp_meta: | |
121 | (Type_cocci.typeC list option -> Ast.meta_name -> econstraints -> | |
122 | Ast0.pure -> unit) | |
123 | ref = | |
faf9a90c | 124 | ref (fun _ -> failwith "uninitialized add_meta") |
34e49164 C |
125 | |
126 | let add_local_idexp_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_explist_meta: | |
faf9a90c C |
133 | (Ast.meta_name -> Ast.meta_name option -> Ast0.pure -> unit) ref = |
134 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 135 | |
faf9a90c C |
136 | let add_stm_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
137 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 138 | |
faf9a90c C |
139 | let add_stmlist_meta: (Ast.meta_name -> Ast0.pure -> unit) ref = |
140 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
141 | |
142 | let add_func_meta: | |
faf9a90c C |
143 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
144 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
145 | |
146 | let add_local_func_meta: | |
faf9a90c C |
147 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = |
148 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 C |
149 | |
150 | let add_declarer_meta: | |
151 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 152 | ref (fun _ -> failwith "uninitialized add_decl") |
34e49164 C |
153 | |
154 | let add_iterator_meta: | |
155 | (Ast.meta_name -> iconstraints -> Ast0.pure -> unit) ref = | |
faf9a90c | 156 | ref (fun _ -> failwith "uninitialized add_iter") |
34e49164 C |
157 | |
158 | let add_pos_meta: | |
faf9a90c C |
159 | (Ast.meta_name -> pconstraints -> Ast.meta_collect -> unit) ref = |
160 | ref (fun _ -> failwith "uninitialized add_meta") | |
34e49164 | 161 | |
faf9a90c C |
162 | let add_type_name: (string -> unit) ref = |
163 | ref (fun _ -> failwith "uninitialized add_type") | |
34e49164 | 164 | |
faf9a90c C |
165 | let add_declarer_name: (string -> unit) ref = |
166 | ref (fun _ -> failwith "uninitialized add_decl") | |
34e49164 | 167 | |
faf9a90c C |
168 | let add_iterator_name: (string -> unit) ref = |
169 | ref (fun _ -> failwith "uninitialized add_iter") | |
34e49164 C |
170 | |
171 | let init_rule: (unit -> unit) ref = | |
faf9a90c | 172 | ref (fun _ -> failwith "uninitialized install_bindings") |
34e49164 C |
173 | |
174 | let install_bindings: (string -> unit) ref = | |
faf9a90c | 175 | ref (fun _ -> failwith "uninitialized install_bindings") |