Release coccinelle-0.2.3rc3
[bpt/coccinelle.git] / parsing_cocci / parse_aux.ml
CommitLineData
9f8e26f4 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
5636bb2c
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(* exports everything, used only by parser_cocci_menhir.mly *)
26module Ast0 = Ast0_cocci
27module Ast = Ast_cocci
28
29(* types for metavariable tokens *)
30type info = Ast.meta_name * Ast0.pure * Data.clt
31type idinfo = Ast.meta_name * Data.iconstraints * Ast0.pure * Data.clt
32type expinfo = Ast.meta_name * Data.econstraints * Ast0.pure * Data.clt
33type tyinfo = Ast.meta_name * Ast0.typeC list * Ast0.pure * Data.clt
34type list_info = Ast.meta_name * Ast.meta_name option * Ast0.pure * Data.clt
951c7801 35type typed_expinfo =
34e49164
C
36 Ast.meta_name * Data.econstraints * Ast0.pure *
37 Type_cocci.typeC list option * Data.clt
38type pos_info = Ast.meta_name * Data.pconstraints * Ast.meta_collect * Data.clt
39
34e49164
C
40let get_option fn = function
41 None -> None
42 | Some x -> Some (fn x)
43
44let make_info line logical_line offset col strbef straft =
0708f913
C
45 let new_pos_info =
46 {Ast0.line_start = line; Ast0.line_end = line;
47 Ast0.logical_start = logical_line; Ast0.logical_end = logical_line;
708f4980 48 Ast0.column = col; Ast0.offset = offset; } in
0708f913 49 { Ast0.pos_info = new_pos_info;
34e49164
C
50 Ast0.attachable_start = true; Ast0.attachable_end = true;
51 Ast0.mcode_start = []; Ast0.mcode_end = [];
34e49164
C
52 Ast0.strings_before = strbef; Ast0.strings_after = straft; }
53
54let clt2info (_,line,logical_line,offset,col,strbef,straft,pos) =
55 make_info line logical_line offset col strbef straft
56
57let drop_bef (arity,line,lline,offset,col,strbef,straft,pos) =
58 (arity,line,lline,offset,col,[],straft,pos)
59
60let drop_aft (arity,line,lline,offset,col,strbef,straft,pos) =
61 (arity,line,lline,offset,col,strbef,[],pos)
62
7f004419
C
63let drop_pos (arity,line,lline,offset,col,strbef,straft,pos) =
64 (arity,line,lline,offset,col,strbef,straft,Ast0.NoMetaPos)
65
34e49164
C
66let clt2mcode str = function
67 (Data.MINUS,line,lline,offset,col,strbef,straft,pos) ->
68 (str,Ast0.NONE,make_info line lline offset col strbef straft,
708f4980 69 Ast0.MINUS(ref([],Ast0.default_token_info)),ref pos,-1)
34e49164
C
70 | (Data.OPTMINUS,line,lline,offset,col,strbef,straft,pos) ->
71 (str,Ast0.OPT,make_info line lline offset col strbef straft,
708f4980 72 Ast0.MINUS(ref([],Ast0.default_token_info)),ref pos,-1)
34e49164
C
73 | (Data.UNIQUEMINUS,line,lline,offset,col,strbef,straft,pos) ->
74 (str,Ast0.UNIQUE,make_info line lline offset col strbef straft,
708f4980 75 Ast0.MINUS(ref([],Ast0.default_token_info)),ref pos,-1)
34e49164 76 | (Data.PLUS,line,lline,offset,col,strbef,straft,pos) ->
951c7801
C
77 (str,Ast0.NONE,make_info line lline offset col strbef straft,
78 Ast0.PLUS(Ast.ONE),ref pos,-1)
79 | (Data.PLUSPLUS,line,lline,offset,col,strbef,straft,pos) ->
80 (str,Ast0.NONE,make_info line lline offset col strbef straft,
81 Ast0.PLUS(Ast.MANY),ref pos,-1)
34e49164
C
82 | (Data.CONTEXT,line,lline,offset,col,strbef,straft,pos) ->
83 (str,Ast0.NONE,make_info line lline offset col strbef straft,
84 Ast0.CONTEXT(ref(Ast.NOTHING,
85 Ast0.default_token_info,Ast0.default_token_info)),
708f4980 86 ref pos,-1)
34e49164
C
87 | (Data.OPT,line,lline,offset,col,strbef,straft,pos) ->
88 (str,Ast0.OPT,make_info line lline offset col strbef straft,
89 Ast0.CONTEXT(ref(Ast.NOTHING,
90 Ast0.default_token_info,Ast0.default_token_info)),
708f4980 91 ref pos,-1)
34e49164
C
92 | (Data.UNIQUE,line,lline,offset,col,strbef,straft,pos) ->
93 (str,Ast0.UNIQUE,make_info line lline offset col strbef straft,
94 Ast0.CONTEXT(ref(Ast.NOTHING,
95 Ast0.default_token_info,Ast0.default_token_info)),
708f4980 96 ref pos,-1)
34e49164
C
97
98let id2name (name, clt) = name
99let id2clt (name, clt) = clt
100let id2mcode (name, clt) = clt2mcode name clt
101
102let mkdots str (dot,whencode) =
103 match str with
104 "..." -> Ast0.wrap(Ast0.Dots(clt2mcode str dot, whencode))
105 | "ooo" -> Ast0.wrap(Ast0.Circles(clt2mcode str dot, whencode))
106 | "***" -> Ast0.wrap(Ast0.Stars(clt2mcode str dot, whencode))
107 | _ -> failwith "cannot happen"
108
109let mkedots str (dot,whencode) =
110 match str with
111 "..." -> Ast0.wrap(Ast0.Edots(clt2mcode str dot, whencode))
112 | "ooo" -> Ast0.wrap(Ast0.Ecircles(clt2mcode str dot, whencode))
113 | "***" -> Ast0.wrap(Ast0.Estars(clt2mcode str dot, whencode))
114 | _ -> failwith "cannot happen"
115
116let mkdpdots str dot =
117 match str with
118 "..." -> Ast0.wrap(Ast0.DPdots(clt2mcode str dot))
119 | "ooo" -> Ast0.wrap(Ast0.DPcircles(clt2mcode str dot))
120 | _ -> failwith "cannot happen"
121
122let mkidots str (dot,whencode) =
123 match str with
124 "..." -> Ast0.wrap(Ast0.Idots(clt2mcode str dot, whencode))
125 | _ -> failwith "cannot happen"
126
127let mkddots str (dot,whencode) =
128 match (str,whencode) with
129 ("...",None) -> Ast0.wrap(Ast0.Ddots(clt2mcode str dot, None))
130 | ("...",Some [w]) -> Ast0.wrap(Ast0.Ddots(clt2mcode str dot, Some w))
131 | _ -> failwith "cannot happen"
132
133let mkpdots str dot =
134 match str with
135 "..." -> Ast0.wrap(Ast0.Pdots(clt2mcode str dot))
136 | "ooo" -> Ast0.wrap(Ast0.Pcircles(clt2mcode str dot))
137 | _ -> failwith "cannot happen"
138
139let arith_op ast_op left op right =
140 Ast0.wrap
141 (Ast0.Binary(left, clt2mcode (Ast.Arith ast_op) op, right))
142
143let logic_op ast_op left op right =
144 Ast0.wrap
145 (Ast0.Binary(left, clt2mcode (Ast.Logical ast_op) op, right))
146
147let make_cv cv ty =
148 match cv with None -> ty | Some x -> Ast0.wrap (Ast0.ConstVol(x,ty))
149
150let top_dots l =
151 let circle x =
152 match Ast0.unwrap x with Ast0.Circles(_) -> true | _ -> false in
153 let star x =
154 match Ast0.unwrap x with Ast0.Stars(_) -> true | _ -> false in
155 if List.exists circle l
156 then Ast0.wrap(Ast0.CIRCLES(l))
157 else
158 if List.exists star l
159 then Ast0.wrap(Ast0.STARS(l))
160 else Ast0.wrap(Ast0.DOTS(l))
161
162(* here the offset is that of the first in the sequence of *s, not that of
163each * individually *)
164let pointerify ty m =
165 List.fold_left
166 (function inner ->
167 function cur ->
168 Ast0.wrap(Ast0.Pointer(inner,clt2mcode "*" cur)))
169 ty m
170
171let ty_pointerify ty m =
172 List.fold_left
173 (function inner -> function cur -> Type_cocci.Pointer(inner))
174 ty m
175
176(* Left is <=>, Right is =>. Collect <=>s. *)
177(* The parser should have done this, with precedences. But whatever... *)
c3e37e97 178let iso_adjust first_fn fn first rest =
34e49164
C
179 let rec loop = function
180 [] -> [[]]
181 | (Common.Left x)::rest ->
182 (match loop rest with
183 front::after -> (fn x::front)::after
184 | _ -> failwith "not possible")
185 | (Common.Right x)::rest ->
186 (match loop rest with
187 front::after -> []::(fn x::front)::after
188 | _ -> failwith "not possible") in
189 match loop rest with
c3e37e97 190 front::after -> (first_fn first::front)::after
34e49164
C
191 | _ -> failwith "not possible"
192
174d1640
C
193let lookup rule name =
194 try
195 let info = Hashtbl.find Data.all_metadecls rule in
196 List.find (function mv -> Ast.get_meta_name mv = (rule,name)) info
197 with
198 Not_found ->
199 raise
200 (Semantic_cocci.Semantic("bad rule "^rule^" or bad variable "^name))
201
202let check_meta_tyopt type_irrelevant = function
34e49164
C
203 Ast.MetaIdDecl(Ast.NONE,(rule,name)) ->
204 (match lookup rule name with
205 Ast.MetaIdDecl(_,_) | Ast.MetaFreshIdDecl(_,_) -> ()
206 | _ ->
207 raise
208 (Semantic_cocci.Semantic
209 ("incompatible inheritance declaration "^name)))
b1b2de81 210 | Ast.MetaFreshIdDecl((rule,name),seed) ->
34e49164
C
211 raise
212 (Semantic_cocci.Semantic
213 "can't inherit the freshness of an identifier")
214 | Ast.MetaListlenDecl((rule,name)) ->
215 (match lookup rule name with
216 Ast.MetaListlenDecl(_) -> ()
217 | _ ->
218 raise
219 (Semantic_cocci.Semantic
220 ("incompatible inheritance declaration "^name)))
221 | Ast.MetaTypeDecl(Ast.NONE,(rule,name)) ->
222 (match lookup rule name with
223 Ast.MetaTypeDecl(_,_) -> ()
224 | _ ->
225 raise
226 (Semantic_cocci.Semantic
227 ("incompatible inheritance declaration "^name)))
113803cf
C
228 | Ast.MetaInitDecl(Ast.NONE,(rule,name)) ->
229 (match lookup rule name with
230 Ast.MetaInitDecl(_,_) -> ()
231 | _ ->
232 raise
233 (Semantic_cocci.Semantic
234 ("incompatible inheritance declaration "^name)))
34e49164
C
235 | Ast.MetaParamDecl(Ast.NONE,(rule,name)) ->
236 (match lookup rule name with
237 Ast.MetaParamDecl(_,_) -> ()
238 | _ ->
239 raise
240 (Semantic_cocci.Semantic
241 ("incompatible inheritance declaration "^name)))
242 | Ast.MetaParamListDecl(Ast.NONE,(rule,name),len_name) ->
243 (match lookup rule name with
244 Ast.MetaParamListDecl(_,_,_) -> ()
245 | _ ->
246 raise
247 (Semantic_cocci.Semantic
248 ("incompatible inheritance declaration "^name)))
249 | Ast.MetaErrDecl(Ast.NONE,(rule,name)) ->
250 (match lookup rule name with
251 Ast.MetaErrDecl(_,_) -> ()
252 | _ ->
253 raise
254 (Semantic_cocci.Semantic
255 ("incompatible inheritance declaration "^name)))
256 | Ast.MetaExpDecl(Ast.NONE,(rule,name),ty) ->
257 (match lookup rule name with
5636bb2c 258 Ast.MetaExpDecl(_,_,ty1) when type_irrelevant or ty = ty1 -> ()
34e49164
C
259 | _ ->
260 raise
261 (Semantic_cocci.Semantic
262 ("incompatible inheritance declaration "^name)))
263 | Ast.MetaIdExpDecl(Ast.NONE,(rule,name),ty) ->
264 (match lookup rule name with
5636bb2c 265 Ast.MetaIdExpDecl(_,_,ty1) when type_irrelevant or ty = ty1 -> ()
34e49164
C
266 | _ ->
267 raise
268 (Semantic_cocci.Semantic
269 ("incompatible inheritance declaration "^name)))
270 | Ast.MetaLocalIdExpDecl(Ast.NONE,(rule,name),ty) ->
271 (match lookup rule name with
5636bb2c 272 Ast.MetaLocalIdExpDecl(_,_,ty1) when type_irrelevant or ty = ty1 -> ()
34e49164
C
273 | _ ->
274 raise
275 (Semantic_cocci.Semantic
276 ("incompatible inheritance declaration "^name)))
277 | Ast.MetaExpListDecl(Ast.NONE,(rule,name),len_name) ->
278 (match lookup rule name with
279 Ast.MetaExpListDecl(_,_,_) -> ()
faf9a90c 280 | Ast.MetaParamListDecl(_,_,_) when not (!Flag.make_hrule = None) -> ()
34e49164
C
281 | _ ->
282 raise
283 (Semantic_cocci.Semantic
284 ("incompatible inheritance declaration "^name)))
285 | Ast.MetaStmDecl(Ast.NONE,(rule,name)) ->
286 (match lookup rule name with
287 Ast.MetaStmDecl(_,_) -> ()
288 | _ ->
289 raise
290 (Semantic_cocci.Semantic
291 ("incompatible inheritance declaration "^name)))
292 | Ast.MetaStmListDecl(Ast.NONE,(rule,name)) ->
293 (match lookup rule name with
294 Ast.MetaStmListDecl(_,_) -> ()
295 | _ ->
296 raise
297 (Semantic_cocci.Semantic
298 ("incompatible inheritance declaration "^name)))
299 | Ast.MetaFuncDecl(Ast.NONE,(rule,name)) ->
300 (match lookup rule name with
301 Ast.MetaFuncDecl(_,_) -> ()
302 | _ ->
303 raise
304 (Semantic_cocci.Semantic
305 ("incompatible inheritance declaration "^name)))
306 | Ast.MetaLocalFuncDecl(Ast.NONE,(rule,name)) ->
307 (match lookup rule name with
308 Ast.MetaLocalFuncDecl(_,_) -> ()
309 | _ ->
310 raise
311 (Semantic_cocci.Semantic
312 ("incompatible inheritance declaration "^name)))
313 | Ast.MetaConstDecl(Ast.NONE,(rule,name),ty) ->
314 (match lookup rule name with
5636bb2c 315 Ast.MetaConstDecl(_,_,ty1) when type_irrelevant or ty = ty1 -> ()
34e49164
C
316 | _ ->
317 raise
318 (Semantic_cocci.Semantic
319 ("incompatible inheritance declaration "^name)))
320 | Ast.MetaPosDecl(Ast.NONE,(rule,name)) ->
321 (match lookup rule name with
322 Ast.MetaPosDecl(_,_) ->
323 if not (List.mem rule !Data.inheritable_positions)
324 then
325 raise
326 (Semantic_cocci.Semantic
327 ("position cannot be inherited over modifications: "^name))
328 | _ ->
329 raise
330 (Semantic_cocci.Semantic
331 ("incompatible inheritance declaration "^name)))
332 | _ ->
333 raise
334 (Semantic_cocci.Semantic ("arity not allowed on imported declaration"))
335
5636bb2c
C
336let check_meta m = check_meta_tyopt false m
337
338let check_inherited_constraint meta_name fn =
339 match meta_name with
340 (None,_) -> failwith "constraint must be an inherited variable"
341 | (Some rule,name) ->
342 let i = (rule,name) in
343 check_meta_tyopt true (fn i);
344 i
345
34e49164
C
346let create_metadec ar ispure kindfn ids current_rule =
347 List.concat
348 (List.map
349 (function (rule,nm) ->
350 let (rule,checker) =
351 match rule with
352 None -> ((current_rule,nm),function x -> [Common.Left x])
353 | Some rule ->
354 ((rule,nm),
355 function x -> check_meta x; [Common.Right x]) in
356 kindfn ar rule ispure checker)
357 ids)
358
ae4735db
C
359
360let create_metadec_virt ar ispure kindfn ids current_rule =
361 List.concat
362 (List.map
363 (function nm ->
364 let checker = function x -> [Common.Right x] in
365 kindfn ar nm ispure checker !Flag.defined_virtual_env)
366 ids)
367
b1b2de81
C
368let create_fresh_metadec kindfn ids current_rule =
369 List.concat
370 (List.map
371 (function ((rule,nm),seed) ->
372 let (rule,checker) =
373 match rule with
374 None -> ((current_rule,nm),function x -> [Common.Left x])
375 | Some rule ->
376 ((rule,nm),
377 function x -> check_meta x; [Common.Right x]) in
378 kindfn rule checker seed)
379 ids)
380
951c7801 381let create_metadec_with_constraints ar ispure kindfn ids current_rule =
34e49164
C
382 List.concat
383 (List.map
384 (function ((rule,nm),constraints) ->
385 let (rule,checker) =
386 match rule with
951c7801
C
387 None -> ((current_rule,nm),function x -> [Common.Left x])
388 | Some rule ->
389 ((rule,nm),
390 function x -> check_meta x; [Common.Right x]) in
391 kindfn ar rule ispure checker constraints)
34e49164
C
392 ids)
393
394let create_metadec_ty ar ispure kindfn ids current_rule =
395 List.concat
396 (List.map
397 (function ((rule,nm),constraints) ->
398 let (rule,checker) =
399 match rule with
400 None -> ((current_rule,nm),function x -> [Common.Left x])
401 | Some rule ->
402 ((rule,nm),
403 function x -> check_meta x; [Common.Right x]) in
404 kindfn ar rule ispure checker constraints)
405 ids)
406
407let create_len_metadec ar ispure kindfn lenid ids current_rule =
408 let lendec =
409 create_metadec Ast.NONE Ast0.Impure
410 (fun _ name _ check_meta -> check_meta(Ast.MetaListlenDecl(name)))
411 [lenid] current_rule in
412 let lenname =
413 match lendec with
414 [Common.Left (Ast.MetaListlenDecl(x))] -> x
415 | [Common.Right (Ast.MetaListlenDecl(x))] -> x
416 | _ -> failwith "unexpected length declaration" in
417 lendec@(create_metadec ar ispure (kindfn lenname) ids current_rule)
418
419(* ---------------------------------------------------------------------- *)
420
421let str2inc s =
422 let elements = Str.split (Str.regexp "/") s in
423 List.map (function "..." -> Ast.IncDots | s -> Ast.IncPath s) elements
424
425(* ---------------------------------------------------------------------- *)
426(* statements *)
427
428let meta_stm name =
429 let (nm,pure,clt) = name in
430 Ast0.wrap(Ast0.MetaStmt(clt2mcode nm clt,pure))
431
432let exp_stm exp pv =
433 Ast0.wrap(Ast0.ExprStatement (exp, clt2mcode ";" pv))
434
435let ifthen iff lp tst rp thn =
436 Ast0.wrap(Ast0.IfThen(clt2mcode "if" iff,
437 clt2mcode "(" lp,tst,clt2mcode ")" rp,thn,
438 (Ast0.default_info(),Ast0.context_befaft())))
439
440let ifthenelse iff lp tst rp thn e els =
441 Ast0.wrap(Ast0.IfThenElse(clt2mcode "if" iff,
442 clt2mcode "(" lp,tst,clt2mcode ")" rp,thn,
443 clt2mcode "else" e,els,
444 (Ast0.default_info(),Ast0.context_befaft())))
445
446let forloop fr lp e1 sc1 e2 sc2 e3 rp s =
447 Ast0.wrap(Ast0.For(clt2mcode "for" fr,clt2mcode "(" lp,e1,
448 clt2mcode ";" sc1,e2,
449 clt2mcode ";" sc2,e3,clt2mcode ")" rp,s,
450 (Ast0.default_info(),Ast0.context_befaft())))
451
452let whileloop w lp e rp s =
453 Ast0.wrap(Ast0.While(clt2mcode "while" w,clt2mcode "(" lp,
454 e,clt2mcode ")" rp,s,
455 (Ast0.default_info(),Ast0.context_befaft())))
456
457let doloop d s w lp e rp pv =
458 Ast0.wrap(Ast0.Do(clt2mcode "do" d,s,clt2mcode "while" w,
459 clt2mcode "(" lp,e,clt2mcode ")" rp,
460 clt2mcode ";" pv))
461
462let iterator i lp e rp s =
463 Ast0.wrap(Ast0.Iterator(i,clt2mcode "(" lp,e,clt2mcode ")" rp,s,
464 (Ast0.default_info(),Ast0.context_befaft())))
465
fc1ad971
C
466let switch s lp e rp lb d c rb =
467 let d =
468 List.map
469 (function d ->
470 Ast0.wrap(Ast0.Decl((Ast0.default_info(),Ast0.context_befaft()),d)))
471 d in
34e49164
C
472 Ast0.wrap(Ast0.Switch(clt2mcode "switch" s,clt2mcode "(" lp,e,
473 clt2mcode ")" rp,clt2mcode "{" lb,
fc1ad971 474 Ast0.wrap(Ast0.DOTS(d)),
34e49164
C
475 Ast0.wrap(Ast0.DOTS(c)),clt2mcode "}" rb))
476
477let ret_exp r e pv =
478 Ast0.wrap(Ast0.ReturnExpr(clt2mcode "return" r,e,clt2mcode ";" pv))
479
480let ret r pv =
481 Ast0.wrap(Ast0.Return(clt2mcode "return" r,clt2mcode ";" pv))
482
483let break b pv =
484 Ast0.wrap(Ast0.Break(clt2mcode "break" b,clt2mcode ";" pv))
485
486let cont c pv =
487 Ast0.wrap(Ast0.Continue(clt2mcode "continue" c,clt2mcode ";" pv))
488
489let label i dd =
490 Ast0.wrap(Ast0.Label(i,clt2mcode ":" dd))
491
492let goto g i pv =
493 Ast0.wrap(Ast0.Goto(clt2mcode "goto" g,i,clt2mcode ";" pv))
494
495let seq lb s rb =
496 Ast0.wrap(Ast0.Seq(clt2mcode "{" lb,s,clt2mcode "}" rb))
497
498(* ---------------------------------------------------------------------- *)
499
500let make_iso_rule_name_result n =
501 (try let _ = Hashtbl.find Data.all_metadecls n in
502 raise (Semantic_cocci.Semantic ("repeated rule name"))
503 with Not_found -> ());
504 Ast.CocciRulename (Some n,Ast.NoDep,[],[],Ast.Undetermined,false (*discarded*))
505
506let make_cocci_rule_name_result nm d i a e ee =
507 match nm with
508 Some nm ->
509 let n = id2name nm in
510 (try let _ = Hashtbl.find Data.all_metadecls n in
511 raise (Semantic_cocci.Semantic ("repeated rule name"))
512 with Not_found -> ());
513 Ast.CocciRulename (Some n,d,i,a,e,ee)
514 | None -> Ast.CocciRulename (None,d,i,a,e,ee)
515
faf9a90c
C
516let make_generated_rule_name_result nm d i a e ee =
517 match nm with
518 Some nm ->
519 let n = id2name nm in
520 (try let _ = Hashtbl.find Data.all_metadecls n in
521 raise (Semantic_cocci.Semantic ("repeated rule name"))
522 with Not_found -> ());
523 Ast.GeneratedRulename (Some n,d,i,a,e,ee)
524 | None -> Ast.GeneratedRulename (None,d,i,a,e,ee)
525
1be43e12 526let make_script_rule_name_result lang deps =
34e49164 527 let l = id2name lang in
174d1640 528 Ast.ScriptRulename (None,l,deps)
b1b2de81 529
c3e37e97 530let make_initial_script_rule_name_result lang deps =
b1b2de81 531 let l = id2name lang in
174d1640 532 Ast.InitialScriptRulename(None,l,deps)
b1b2de81 533
c3e37e97 534let make_final_script_rule_name_result lang deps =
b1b2de81 535 let l = id2name lang in
174d1640 536 Ast.FinalScriptRulename(None,l,deps)
978fd7e5
C
537
538(* Allows type alone only when it is void and only when there is only one
539 parameter. This avoids ambiguity problems in the parser. *)
540let verify_parameter_declarations = function
541 [] -> ()
542 | [x] ->
543 (match Ast0.unwrap x with
544 Ast0.Param(t, None) ->
545 (match Ast0.unwrap t with
546 Ast0.BaseType(Ast.VoidType,_) -> ()
547 | _ ->
548 failwith
549 (Printf.sprintf
550 "%d: only void can be a parameter without an identifier"
551 (Ast0.get_line t)))
552 | _ -> ())
553 | l ->
554 List.iter
555 (function x ->
556 match Ast0.unwrap x with
557 Ast0.Param(t, None) ->
558 failwith
559 (Printf.sprintf
560 "%d: only void alone can be a parameter without an identifier"
561 (Ast0.get_line t))
562 | _ -> ())
563 l