Release coccinelle-0.2.3rc2
[bpt/coccinelle.git] / parsing_c / visitor_c.ml
CommitLineData
0708f913 1(* Yoann Padioleau
ae4735db
C
2 *
3 * Copyright (C) 2010, University of Copenhagen DIKU and INRIA.
0708f913 4 * Copyright (C) 2006, 2007, 2008, 2009 Ecole des Mines de Nantes
34e49164
C
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License (GPL)
8 * version 2 as published by the Free Software Foundation.
ae4735db 9 *
34e49164
C
10 * This program 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 * file license.txt for more details.
14 *)
15open Common
16
17
18open Ast_c
19module F = Control_flow_c
20
91eba41f
C
21(*****************************************************************************)
22(* Prelude *)
23(*****************************************************************************)
24
25(* todo? dont go in Include. Have a visitor flag ? disable_go_include ?
26 * disable_go_type_annotation ?
27 *)
28
708f4980
C
29(*****************************************************************************)
30(* Wrappers *)
31(*****************************************************************************)
32let pr2, pr2_once = Common.mk_pr2_wrappers Flag_parsing_c.verbose_visit
33
34e49164
C
34(*****************************************************************************)
35(* Functions to visit the Ast, and now also the CFG nodes *)
36(*****************************************************************************)
37
ae4735db
C
38(* Why this module ?
39 *
40 * The problem is that we manipulate the AST of C programs
41 * and some of our analysis need only to specify an action for
113803cf 42 * specific cases, such as the function call case, and recurse
ae4735db
C
43 * for the other cases.
44 * Here is a simplification of our AST:
45 *
46 * type ctype =
113803cf
C
47 * | Basetype of ...
48 * | Pointer of ctype
49 * | Array of expression option * ctype
50 * | ...
ae4735db 51 * and expression =
113803cf
C
52 * | Ident of string
53 * | FunCall of expression * expression list
54 * | Postfix of ...
55 * | RecordAccess of ..
56 * | ...
ae4735db 57 * and statement =
113803cf
C
58 * ...
59 * and declaration =
60 * ...
ae4735db 61 * and program =
113803cf
C
62 * ...
63 *
ae4735db
C
64 * What we want is really write code like
65 *
66 * let my_analysis program =
113803cf
C
67 * analyze_all_expressions program (fun expr ->
68 * match expr with
69 * | FunCall (e, es) -> do_something()
ae4735db 70 * | _ -> <find_a_way_to_recurse_for_all_the_other_cases>
113803cf 71 * )
ae4735db 72 *
113803cf
C
73 * The problem is how to write analyze_all_expressions
74 * and find_a_way_to_recurse_for_all_the_other_cases.
ae4735db
C
75 *
76 * Our solution is to mix the ideas of visitor, pattern matching,
113803cf 77 * and continuation. Here is how it looks like
ae4735db
C
78 * using our hybrid-visitor API:
79 *
80 * let my_analysis program =
113803cf 81 * Visitor.visit_iter program {
ae4735db 82 * Visitor.kexpr = (fun k e ->
113803cf
C
83 * match e with
84 * | FunCall (e, es) -> do_something()
85 * | _ -> k e
86 * );
87 * }
ae4735db
C
88 *
89 * You can of course also give action "hooks" for
113803cf
C
90 * kstatement, ktype, or kdeclaration. But we don't overuse
91 * visitors and so it would be stupid to provide
92 * kfunction_call, kident, kpostfix hooks as one can just
93 * use pattern matching with kexpr to achieve the same effect.
ae4735db 94 *
0708f913
C
95 * Note: when want to apply recursively, always apply the continuator
96 * on the toplevel expression, otherwise may miss some intermediate steps.
97 * Do
98 * match expr with
99 * | FunCall (e, es) -> ...
100 * k expr
101 * Or
102 * match expr with
103 * | FunCall (e, es) -> ...
104 * Visitor_c.vk_expr bigf e
105 * Not
106 * match expr with
107 * | FunCall (e, es) -> ...
108 * k e
109 *
ae4735db
C
110 *
111 *
112 *
113 *
113803cf
C
114 * Alternatives: from the caml mailing list:
115 * "You should have a look at the Camlp4 metaprogramming facilities :
116 * http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
117 * You would write something like" :
118 * let my_analysis program =
119 * let analysis = object (self)
120 * inherit fold as super
121 * method expr = function
122 * | FunCall (e, es) -> do_something (); self
123 * | other -> super#expr other
124 * end in analysis#expr
ae4735db
C
125 *
126 * The problem is that you don't have control about what is generated
113803cf 127 * and in our case we sometimes dont want to visit too much. For instance
b1b2de81 128 * our visitor don't recurse on the type annotation of expressions
ae4735db 129 * Ok, this could be worked around, but the pb remains, you
113803cf
C
130 * don't have control and at some point you may want. In the same
131 * way we want to enforce a certain order in the visit (ok this is not good,
132 * but it's convenient) of ast elements. For instance first
133 * processing the left part 'e' of a Funcall(e,es), then the arguments 'es'.
ae4735db 134 *
113803cf 135 *)
34e49164 136
ae4735db
C
137(* Visitor based on continuation. Cleaner than the one based on mutable
138 * pointer functions that I had before.
485bce71 139 * src: based on a (vague) idea from Remy Douence.
ae4735db
C
140 *
141 *
142 *
34e49164 143 * Diff with Julia's visitor ? She does:
ae4735db 144 *
34e49164
C
145 * let ident r k i =
146 * ...
147 * let expression r k e =
ae4735db 148 * ...
34e49164
C
149 * ... (List.map r.V0.combiner_expression expr_list) ...
150 * ...
ae4735db 151 * let res = V0.combiner bind option_default
34e49164
C
152 * mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
153 * donothing donothing donothing donothing
154 * ident expression typeC donothing parameter declaration statement
155 * donothing in
156 * ...
157 * collect_unitary_nonunitary
158 * (List.concat (List.map res.V0.combiner_top_level t))
ae4735db
C
159 *
160 *
161 *
34e49164 162 * So she has to remember at which position you must put the 'expression'
ae4735db
C
163 * function. I use record which is easier.
164 *
34e49164 165 * When she calls recursively, her res.V0.combiner_xxx does not take bigf
ae4735db
C
166 * in param whereas I do
167 * | F.Decl decl -> Visitor_c.vk_decl bigf decl
34e49164
C
168 * And with the record she gets, she does not have to do my
169 * multiple defs of function such as 'let al_type = V0.vk_type_s bigf'
ae4735db 170 *
34e49164
C
171 * The code of visitor.ml is cleaner with julia because mutual recursive calls
172 * are clean such as ... 'expression e' ... and not 'f (k, bigf) e'
173 * or 'vk_expr bigf e'.
ae4735db 174 *
34e49164
C
175 * So it is very dual:
176 * - I give a record but then I must handle bigf.
177 * - She gets a record, and gives a list of function
ae4735db
C
178 *
179 *)
180
34e49164 181
ae4735db 182(* old: first version (only visiting expr)
34e49164
C
183
184let (iter_expr:((expression -> unit) -> expression -> unit) -> expression -> unit)
185 = fun f expr ->
ae4735db 186 let rec k e =
34e49164
C
187 match e with
188 | Constant c -> ()
189 | FunCall (e, es) -> f k e; List.iter (f k) es
190 | CondExpr (e1, e2, e3) -> f k e1; f k e2; f k e3
191 | Sequence (e1, e2) -> f k e1; f k e2;
192 | Assignment (e1, op, e2) -> f k e1; f k e2;
ae4735db 193
34e49164
C
194 | Postfix (e, op) -> f k e
195 | Infix (e, op) -> f k e
196 | Unary (e, op) -> f k e
197 | Binary (e1, op, e2) -> f k e1; f k e2;
ae4735db 198
34e49164
C
199 | ArrayAccess (e1, e2) -> f k e1; f k e2;
200 | RecordAccess (e, s) -> f k e
201 | RecordPtAccess (e, s) -> f k e
202
203 | SizeOfExpr e -> f k e
204 | SizeOfType t -> ()
205 | _ -> failwith "to complete"
206
207 in f k expr
208
ae4735db 209let ex1 = Sequence (Sequence (Constant (Ident "1"), Constant (Ident "2")),
34e49164 210 Constant (Ident "4"))
ae4735db 211let test =
34e49164
C
212 iter_expr (fun k e -> match e with
213 | Constant (Ident x) -> Common.pr2 x
214 | rest -> k rest
ae4735db
C
215 ) ex1
216==>
34e49164
C
2171
2182
2194
220
221*)
222
223(*****************************************************************************)
224(* Side effect style visitor *)
225(*****************************************************************************)
226
227(* Visitors for all langage concept, not just for expression.
ae4735db 228 *
34e49164
C
229 * Note that I don't visit necesserally in the order of the token
230 * found in the original file. So don't assume such hypothesis!
ae4735db 231 *
951c7801 232 * todo? parameter ?
34e49164 233 *)
ae4735db
C
234type visitor_c =
235 {
34e49164
C
236 kexpr: (expression -> unit) * visitor_c -> expression -> unit;
237 kstatement: (statement -> unit) * visitor_c -> statement -> unit;
238 ktype: (fullType -> unit) * visitor_c -> fullType -> unit;
239
240 kdecl: (declaration -> unit) * visitor_c -> declaration -> unit;
951c7801
C
241 konedecl: (onedecl -> unit) * visitor_c -> onedecl -> unit;
242 kparam: (parameterType -> unit) * visitor_c -> parameterType -> unit;
ae4735db 243 kdef: (definition -> unit) * visitor_c -> definition -> unit;
b1b2de81
C
244 kname : (name -> unit) * visitor_c -> name -> unit;
245
ae4735db 246 kini: (initialiser -> unit) * visitor_c -> initialiser -> unit;
b1b2de81 247 kfield: (field -> unit) * visitor_c -> field -> unit;
34e49164 248
485bce71
C
249 kcppdirective: (cpp_directive -> unit) * visitor_c -> cpp_directive -> unit;
250 kdefineval : (define_val -> unit) * visitor_c -> define_val -> unit;
251 kstatementseq: (statement_sequencable -> unit) * visitor_c -> statement_sequencable -> unit;
34e49164 252
0708f913 253
34e49164
C
254 (* CFG *)
255 knode: (F.node -> unit) * visitor_c -> F.node -> unit;
256 (* AST *)
257 ktoplevel: (toplevel -> unit) * visitor_c -> toplevel -> unit;
485bce71
C
258
259 kinfo: (info -> unit) * visitor_c -> info -> unit;
ae4735db 260 }
34e49164 261
ae4735db 262let default_visitor_c =
b1b2de81
C
263 { kexpr = (fun (k,_) e -> k e);
264 kstatement = (fun (k,_) st -> k st);
265 ktype = (fun (k,_) t -> k t);
266 kdecl = (fun (k,_) d -> k d);
951c7801
C
267 konedecl = (fun (k,_) d -> k d);
268 kparam = (fun (k,_) d -> k d);
b1b2de81
C
269 kdef = (fun (k,_) d -> k d);
270 kini = (fun (k,_) ie -> k ie);
271 kname = (fun (k,_) x -> k x);
272 kinfo = (fun (k,_) ii -> k ii);
273 knode = (fun (k,_) n -> k n);
274 ktoplevel = (fun (k,_) p -> k p);
485bce71 275 kcppdirective = (fun (k,_) p -> k p);
b1b2de81
C
276 kdefineval = (fun (k,_) p -> k p);
277 kstatementseq = (fun (k,_) p -> k p);
278 kfield = (fun (k,_) p -> k p);
ae4735db 279 }
34e49164 280
485bce71
C
281
282(* ------------------------------------------------------------------------ *)
283
284
34e49164
C
285let rec vk_expr = fun bigf expr ->
286 let iif ii = vk_ii bigf ii in
287
288 let rec exprf e = bigf.kexpr (k,bigf) e
91eba41f 289 (* !!! dont go in _typ !!! *)
ae4735db 290 and k ((e,_typ), ii) =
34e49164
C
291 iif ii;
292 match e with
b1b2de81 293 | Ident (name) -> vk_name bigf name
34e49164 294 | Constant (c) -> ()
ae4735db
C
295 | FunCall (e, es) ->
296 exprf e;
485bce71 297 vk_argument_list bigf es;
ae4735db 298 | CondExpr (e1, e2, e3) ->
34e49164
C
299 exprf e1; do_option (exprf) e2; exprf e3
300 | Sequence (e1, e2) -> exprf e1; exprf e2;
301 | Assignment (e1, op, e2) -> exprf e1; exprf e2;
ae4735db 302
34e49164
C
303 | Postfix (e, op) -> exprf e
304 | Infix (e, op) -> exprf e
305 | Unary (e, op) -> exprf e
306 | Binary (e1, op, e2) -> exprf e1; exprf e2;
ae4735db 307
34e49164 308 | ArrayAccess (e1, e2) -> exprf e1; exprf e2;
b1b2de81
C
309 | RecordAccess (e, name) -> exprf e; vk_name bigf name
310 | RecordPtAccess (e, name) -> exprf e; vk_name bigf name
34e49164
C
311
312 | SizeOfExpr (e) -> exprf e
313 | SizeOfType (t) -> vk_type bigf t
314 | Cast (t, e) -> vk_type bigf t; exprf e
315
ae4735db
C
316 (* old: | StatementExpr (((declxs, statxs), is)), is2 ->
317 * List.iter (vk_decl bigf) declxs;
318 * List.iter (vk_statement bigf) statxs
34e49164 319 *)
ae4735db 320 | StatementExpr ((statxs, is)) ->
34e49164 321 iif is;
485bce71 322 statxs +> List.iter (vk_statement_sequencable bigf);
34e49164 323
ae4735db 324 | Constructor (t, initxs) ->
34e49164 325 vk_type bigf t;
ae4735db 326 initxs +> List.iter (fun (ini, ii) ->
34e49164
C
327 vk_ini bigf ini;
328 vk_ii bigf ii;
ae4735db
C
329 )
330
34e49164
C
331 | ParenExpr (e) -> exprf e
332
333
334 in exprf expr
335
34e49164 336
b1b2de81 337(* ------------------------------------------------------------------------ *)
ae4735db 338and vk_name = fun bigf ident ->
b1b2de81 339 let iif ii = vk_ii bigf ii in
34e49164 340
ae4735db
C
341 let rec namef x = bigf.kname (k,bigf) x
342 and k id =
b1b2de81
C
343 match id with
344 | RegularName (s, ii) -> iif ii
ae4735db
C
345 | CppConcatenatedName xs ->
346 xs +> List.iter (fun ((x,ii1), ii2) ->
b1b2de81
C
347 iif ii2;
348 iif ii1;
349 );
350 | CppVariadicName (s, ii) -> iif ii
ae4735db 351 | CppIdentBuilder ((s,iis), xs) ->
b1b2de81 352 iif iis;
ae4735db 353 xs +> List.iter (fun ((x,iix), iicomma) ->
b1b2de81
C
354 iif iicomma;
355 iif iix;
356 )
357 in
358 namef ident
359
360(* ------------------------------------------------------------------------ *)
34e49164
C
361
362
ae4735db 363and vk_statement = fun bigf (st: Ast_c.statement) ->
34e49164
C
364 let iif ii = vk_ii bigf ii in
365
ae4735db
C
366 let rec statf x = bigf.kstatement (k,bigf) x
367 and k st =
34e49164
C
368 let (unwrap_st, ii) = st in
369 iif ii;
370 match unwrap_st with
ae4735db 371 | Labeled (Label (name, st)) ->
708f4980
C
372 vk_name bigf name;
373 statf st;
34e49164 374 | Labeled (Case (e, st)) -> vk_expr bigf e; statf st;
ae4735db 375 | Labeled (CaseRange (e, e2, st)) ->
34e49164
C
376 vk_expr bigf e; vk_expr bigf e2; statf st;
377 | Labeled (Default st) -> statf st;
378
ae4735db 379 | Compound statxs ->
485bce71 380 statxs +> List.iter (vk_statement_sequencable bigf)
34e49164
C
381 | ExprStatement (eopt) -> do_option (vk_expr bigf) eopt;
382
ae4735db 383 | Selection (If (e, st1, st2)) ->
34e49164 384 vk_expr bigf e; statf st1; statf st2;
ae4735db 385 | Selection (Switch (e, st)) ->
34e49164 386 vk_expr bigf e; statf st;
ae4735db 387 | Iteration (While (e, st)) ->
34e49164 388 vk_expr bigf e; statf st;
ae4735db
C
389 | Iteration (DoWhile (st, e)) -> statf st; vk_expr bigf e;
390 | Iteration (For ((e1opt,i1), (e2opt,i2), (e3opt,i3), st)) ->
391 statf (mk_st (ExprStatement (e1opt)) i1);
392 statf (mk_st (ExprStatement (e2opt)) i2);
393 statf (mk_st (ExprStatement (e3opt)) i3);
34e49164
C
394 statf st;
395
ae4735db 396 | Iteration (MacroIteration (s, es, st)) ->
485bce71 397 vk_argument_list bigf es;
34e49164 398 statf st;
ae4735db 399
b1b2de81 400 | Jump (Goto name) -> vk_name bigf name
34e49164
C
401 | Jump ((Continue|Break|Return)) -> ()
402 | Jump (ReturnExpr e) -> vk_expr bigf e;
403 | Jump (GotoComputed e) -> vk_expr bigf e;
404
ae4735db 405 | Decl decl -> vk_decl bigf decl
34e49164
C
406 | Asm asmbody -> vk_asmbody bigf asmbody
407 | NestedFunc def -> vk_def bigf def
408 | MacroStmt -> ()
409
410 in statf st
411
ae4735db
C
412and vk_statement_sequencable = fun bigf stseq ->
413 let f = bigf.kstatementseq in
485bce71 414
ae4735db 415 let rec k stseq =
485bce71
C
416 match stseq with
417 | StmtElem st -> vk_statement bigf st
ae4735db 418 | CppDirectiveStmt directive ->
485bce71 419 vk_cpp_directive bigf directive
ae4735db 420 | IfdefStmt ifdef ->
485bce71 421 vk_ifdef_directive bigf ifdef
ae4735db 422 | IfdefStmt2 (ifdef, xxs) ->
485bce71 423 ifdef +> List.iter (vk_ifdef_directive bigf);
ae4735db 424 xxs +> List.iter (fun xs ->
485bce71
C
425 xs +> List.iter (vk_statement_sequencable bigf)
426 )
ae4735db 427
485bce71
C
428 in f (k, bigf) stseq
429
34e49164 430
34e49164 431
ae4735db 432and vk_type = fun bigf t ->
34e49164
C
433 let iif ii = vk_ii bigf ii in
434
ae4735db
C
435 let rec typef x = bigf.ktype (k, bigf) x
436 and k t =
34e49164
C
437 let (q, t) = t in
438 let (unwrap_q, iiq) = q in
439 let (unwrap_t, iit) = t in
440 iif iiq;
441 iif iit;
442 match unwrap_t with
443 | BaseType _ -> ()
444 | Pointer t -> typef t
ae4735db 445 | Array (eopt, t) ->
34e49164 446 do_option (vk_expr bigf) eopt;
ae4735db
C
447 typef t
448 | FunctionType (returnt, paramst) ->
34e49164
C
449 typef returnt;
450 (match paramst with
ae4735db 451 | (ts, (b,iihas3dots)) ->
34e49164 452 iif iihas3dots;
485bce71 453 vk_param_list bigf ts
34e49164
C
454 )
455
ae4735db
C
456 | Enum (sopt, enumt) ->
457 enumt +> List.iter (fun ((name, eopt), iicomma) ->
458 vk_name bigf name;
b1b2de81 459 iif iicomma;
ae4735db 460 eopt +> Common.do_option (fun (info, e) ->
b1b2de81
C
461 iif [info];
462 vk_expr bigf e
463 )
ae4735db
C
464 );
465
466 | StructUnion (sopt, _su, fields) ->
34e49164
C
467 vk_struct_fields bigf fields
468
469 | StructUnionName (s, structunion) -> ()
470 | EnumName s -> ()
471
472 (* dont go in _typ *)
ae4735db 473 | TypeName (name,_typ) ->
b1b2de81 474 vk_name bigf name
34e49164
C
475
476 | ParenType t -> typef t
477 | TypeOfExpr e -> vk_expr bigf e
478 | TypeOfType t -> typef t
479
480 in typef t
481
485bce71 482
ae4735db 483and vk_attribute = fun bigf attr ->
485bce71
C
484 let iif ii = vk_ii bigf ii in
485 match attr with
ae4735db 486 | Attribute s, ii ->
485bce71
C
487 iif ii
488
489
490(* ------------------------------------------------------------------------ *)
491
ae4735db 492and vk_decl = fun bigf d ->
34e49164
C
493 let iif ii = vk_ii bigf ii in
494
ae4735db
C
495 let f = bigf.kdecl in
496 let rec k decl =
497 match decl with
498 | DeclList (xs,ii) -> xs +> List.iter (fun (x,ii) ->
91eba41f
C
499 iif ii;
500 vk_onedecl bigf x;
501 );
ae4735db 502 | MacroDecl ((s, args),ii) ->
34e49164 503 iif ii;
485bce71 504 vk_argument_list bigf args;
ae4735db 505 in f (k, bigf) d
91eba41f
C
506
507
ae4735db 508and vk_onedecl = fun bigf onedecl ->
91eba41f 509 let iif ii = vk_ii bigf ii in
ae4735db
C
510 let f = bigf.konedecl in
511 let rec k onedecl =
91eba41f 512 match onedecl with
ae4735db
C
513 | ({v_namei = var;
514 v_type = t;
978fd7e5 515 v_type_bis = tbis;
ae4735db
C
516 v_storage = _sto;
517 v_attr = attrs}) ->
34e49164 518
34e49164 519 vk_type bigf t;
978fd7e5 520 (* dont go in tbis *)
485bce71 521 attrs +> List.iter (vk_attribute bigf);
ae4735db 522 var +> Common.do_option (fun (name, iniopt) ->
b1b2de81 523 vk_name bigf name;
ae4735db 524 iniopt +> Common.do_option (fun (info, ini) ->
b1b2de81
C
525 iif [info];
526 vk_ini bigf ini;
527 );
528 )
951c7801 529 in f (k, bigf) onedecl
34e49164 530
ae4735db 531and vk_ini = fun bigf ini ->
34e49164
C
532 let iif ii = vk_ii bigf ii in
533
ae4735db
C
534 let rec inif x = bigf.kini (k, bigf) x
535 and k (ini, iini) =
34e49164
C
536 iif iini;
537 match ini with
538 | InitExpr e -> vk_expr bigf e
ae4735db
C
539 | InitList initxs ->
540 initxs +> List.iter (fun (ini, ii) ->
34e49164
C
541 inif ini;
542 iif ii;
ae4735db
C
543 )
544 | InitDesignators (xs, e) ->
34e49164
C
545 xs +> List.iter (vk_designator bigf);
546 inif e
547
548 | InitFieldOld (s, e) -> inif e
549 | InitIndexOld (e1, e) ->
550 vk_expr bigf e1; inif e
551
485bce71 552
34e49164
C
553 in inif ini
554
555
ae4735db 556and vk_designator = fun bigf design ->
34e49164
C
557 let iif ii = vk_ii bigf ii in
558 let (designator, ii) = design in
559 iif ii;
560 match designator with
561 | DesignatorField s -> ()
562 | DesignatorIndex e -> vk_expr bigf e
563 | DesignatorRange (e1, e2) -> vk_expr bigf e1; vk_expr bigf e2
564
485bce71
C
565
566(* ------------------------------------------------------------------------ *)
567
ae4735db 568and vk_struct_fields = fun bigf fields ->
0708f913
C
569 fields +> List.iter (vk_struct_field bigf);
570
ae4735db 571and vk_struct_field = fun bigf field ->
34e49164
C
572 let iif ii = vk_ii bigf ii in
573
0708f913 574 let f = bigf.kfield in
ae4735db 575 let rec k field =
0708f913 576
ae4735db
C
577 match field with
578 | DeclarationField
579 (FieldDeclList (onefield_multivars, iiptvirg)) ->
485bce71
C
580 vk_struct_fieldkinds bigf onefield_multivars;
581 iif iiptvirg;
708f4980 582 | EmptyField info -> iif [info]
ae4735db 583 | MacroDeclField ((s, args),ii) ->
708f4980
C
584 iif ii;
585 vk_argument_list bigf args;
485bce71 586
ae4735db 587 | CppDirectiveStruct directive ->
485bce71 588 vk_cpp_directive bigf directive
ae4735db 589 | IfdefStruct ifdef ->
485bce71 590 vk_ifdef_directive bigf ifdef
0708f913
C
591 in
592 f (k, bigf) field
485bce71 593
34e49164 594
ae4735db
C
595
596
597and vk_struct_fieldkinds = fun bigf onefield_multivars ->
34e49164
C
598 let iif ii = vk_ii bigf ii in
599 onefield_multivars +> List.iter (fun (field, iicomma) ->
600 iif iicomma;
601 match field with
ae4735db 602 | Simple (nameopt, t) ->
b1b2de81
C
603 Common.do_option (vk_name bigf) nameopt;
604 vk_type bigf t;
ae4735db 605 | BitField (nameopt, t, info, expr) ->
b1b2de81
C
606 Common.do_option (vk_name bigf) nameopt;
607 vk_info bigf info;
34e49164 608 vk_expr bigf expr;
ae4735db 609 vk_type bigf t
34e49164
C
610 )
611
485bce71 612(* ------------------------------------------------------------------------ *)
34e49164
C
613
614
ae4735db 615and vk_def = fun bigf d ->
34e49164
C
616 let iif ii = vk_ii bigf ii in
617
618 let f = bigf.kdef in
ae4735db 619 let rec k d =
34e49164 620 match d with
708f4980 621 | {f_name = name;
485bce71
C
622 f_type = (returnt, (paramst, (b, iib)));
623 f_storage = sto;
624 f_body = statxs;
625 f_attr = attrs;
91eba41f 626 f_old_c_style = oldstyle;
ae4735db
C
627 }, ii
628 ->
34e49164
C
629 iif ii;
630 iif iib;
485bce71 631 attrs +> List.iter (vk_attribute bigf);
34e49164 632 vk_type bigf returnt;
708f4980 633 vk_name bigf name;
ae4735db 634 paramst +> List.iter (fun (param,iicomma) ->
34e49164
C
635 vk_param bigf param;
636 iif iicomma;
637 );
ae4735db 638 oldstyle +> Common.do_option (fun decls ->
91eba41f
C
639 decls +> List.iter (vk_decl bigf);
640 );
641
485bce71 642 statxs +> List.iter (vk_statement_sequencable bigf)
ae4735db 643 in f (k, bigf) d
34e49164
C
644
645
646
647
ae4735db 648and vk_toplevel = fun bigf p ->
34e49164
C
649 let f = bigf.ktoplevel in
650 let iif ii = vk_ii bigf ii in
ae4735db 651 let rec k p =
34e49164
C
652 match p with
653 | Declaration decl -> (vk_decl bigf decl)
654 | Definition def -> (vk_def bigf def)
655 | EmptyDef ii -> iif ii
ae4735db 656 | MacroTop (s, xs, ii) ->
485bce71
C
657 vk_argument_list bigf xs;
658 iif ii
659
660 | CppTop top -> vk_cpp_directive bigf top
661 | IfdefTop ifdefdir -> vk_ifdef_directive bigf ifdefdir
ae4735db 662
485bce71
C
663 | NotParsedCorrectly ii -> iif ii
664 | FinalDef info -> vk_info bigf info
665 in f (k, bigf) p
666
ae4735db 667and vk_program = fun bigf xs ->
485bce71
C
668 xs +> List.iter (vk_toplevel bigf)
669
ae4735db 670and vk_ifdef_directive bigf directive =
485bce71
C
671 let iif ii = vk_ii bigf ii in
672 match directive with
673 | IfdefDirective (ifkind, ii) -> iif ii
674
675
676and vk_cpp_directive bigf directive =
677 let iif ii = vk_ii bigf ii in
678 let f = bigf.kcppdirective in
ae4735db 679 let rec k directive =
485bce71
C
680 match directive with
681 | Include {i_include = (s, ii);
682 i_content = copt;
683 }
ae4735db 684 ->
91eba41f
C
685 (* go inside ? yes, can be useful, for instance for type_annotater.
686 * The only pb may be that when we want to unparse the code we
ae4735db 687 * don't want to unparse the included file but the unparser
91eba41f
C
688 * and pretty_print do not use visitor_c so no problem.
689 *)
485bce71 690 iif ii;
ae4735db 691 copt +> Common.do_option (fun (file, asts) ->
485bce71
C
692 vk_program bigf asts
693 );
ae4735db 694 | Define ((s,ii), (defkind, defval)) ->
34e49164
C
695 iif ii;
696 vk_define_kind bigf defkind;
697 vk_define_val bigf defval
ae4735db 698 | Undef (s, ii) ->
485bce71 699 iif ii
ae4735db 700 | PragmaAndCo (ii) ->
485bce71
C
701 iif ii
702 in f (k, bigf) directive
34e49164 703
34e49164 704
ae4735db 705and vk_define_kind bigf defkind =
34e49164
C
706 match defkind with
707 | DefineVar -> ()
ae4735db 708 | DefineFunc (params, ii) ->
34e49164 709 vk_ii bigf ii;
ae4735db 710 params +> List.iter (fun ((s,iis), iicomma) ->
34e49164
C
711 vk_ii bigf iis;
712 vk_ii bigf iicomma;
713 )
714
ae4735db
C
715and vk_define_val bigf defval =
716 let f = bigf.kdefineval in
485bce71 717
ae4735db 718 let rec k defval =
34e49164 719 match defval with
ae4735db 720 | DefineExpr e ->
34e49164
C
721 vk_expr bigf e
722 | DefineStmt stmt -> vk_statement bigf stmt
ae4735db 723 | DefineDoWhileZero ((stmt, e), ii) ->
34e49164 724 vk_statement bigf stmt;
485bce71 725 vk_expr bigf e;
34e49164
C
726 vk_ii bigf ii
727 | DefineFunction def -> vk_def bigf def
728 | DefineType ty -> vk_type bigf ty
729 | DefineText (s, ii) -> vk_ii bigf ii
730 | DefineEmpty -> ()
485bce71
C
731 | DefineInit ini -> vk_ini bigf ini
732
ae4735db 733 | DefineTodo ->
91eba41f 734 pr2_once "DefineTodo";
485bce71
C
735 ()
736 in f (k, bigf) defval
34e49164 737
ae4735db
C
738
739
34e49164
C
740
741(* ------------------------------------------------------------------------ *)
ae4735db 742(* Now keep fullstatement inside the control flow node,
34e49164 743 * so that can then get in a MetaStmtVar the fullstatement to later
ae4735db 744 * pp back when the S is in a +. But that means that
34e49164
C
745 * Exp will match an Ifnode even if there is no such exp
746 * inside the condition of the Ifnode (because the exp may
747 * be deeper, in the then branch). So have to not visit
748 * all inside a node anymore.
ae4735db 749 *
485bce71 750 * update: j'ai choisi d'accrocher au noeud du CFG a la
ae4735db 751 * fois le fullstatement et le partialstatement et appeler le
34e49164
C
752 * visiteur que sur le partialstatement.
753 *)
754
ae4735db 755and vk_node = fun bigf node ->
34e49164
C
756 let iif ii = vk_ii bigf ii in
757 let infof info = vk_info bigf info in
758
759 let f = bigf.knode in
ae4735db 760 let rec k n =
34e49164
C
761 match F.unwrap n with
762
91eba41f
C
763 | F.FunHeader (def) ->
764 assert(null (fst def).f_body);
765 vk_def bigf def;
34e49164 766
ae4735db
C
767 | F.Decl decl -> vk_decl bigf decl
768 | F.ExprStatement (st, (eopt, ii)) ->
34e49164
C
769 iif ii;
770 eopt +> do_option (vk_expr bigf)
771
ae4735db 772 | F.IfHeader (_, (e,ii))
34e49164
C
773 | F.SwitchHeader (_, (e,ii))
774 | F.WhileHeader (_, (e,ii))
ae4735db 775 | F.DoWhileTail (e,ii) ->
34e49164
C
776 iif ii;
777 vk_expr bigf e
778
ae4735db 779 | F.ForHeader (_st, (((e1opt,i1), (e2opt,i2), (e3opt,i3)), ii)) ->
34e49164
C
780 iif i1; iif i2; iif i3;
781 iif ii;
782 e1opt +> do_option (vk_expr bigf);
783 e2opt +> do_option (vk_expr bigf);
784 e3opt +> do_option (vk_expr bigf);
ae4735db 785 | F.MacroIterHeader (_s, ((s,es), ii)) ->
34e49164 786 iif ii;
485bce71 787 vk_argument_list bigf es;
ae4735db 788
34e49164 789 | F.ReturnExpr (_st, (e,ii)) -> iif ii; vk_expr bigf e
ae4735db 790
34e49164 791 | F.Case (_st, (e,ii)) -> iif ii; vk_expr bigf e
ae4735db 792 | F.CaseRange (_st, ((e1, e2),ii)) ->
34e49164
C
793 iif ii; vk_expr bigf e1; vk_expr bigf e2
794
795
796 | F.CaseNode i -> ()
797
798 | F.DefineExpr e -> vk_expr bigf e
799 | F.DefineType ft -> vk_type bigf ft
ae4735db 800 | F.DefineHeader ((s,ii), (defkind)) ->
34e49164
C
801 iif ii;
802 vk_define_kind bigf defkind;
803
804 | F.DefineDoWhileZeroHeader (((),ii)) -> iif ii
ae4735db 805 | F.DefineTodo ->
91eba41f 806 pr2_once "DefineTodo";
485bce71
C
807 ()
808
34e49164 809
485bce71 810 | F.Include {i_include = (s, ii);} -> iif ii;
34e49164 811
ae4735db 812 | F.MacroTop (s, args, ii) ->
34e49164 813 iif ii;
485bce71 814 vk_argument_list bigf args
34e49164 815
ae4735db
C
816 | F.IfdefHeader (info) -> vk_ifdef_directive bigf info
817 | F.IfdefElse (info) -> vk_ifdef_directive bigf info
818 | F.IfdefEndif (info) -> vk_ifdef_directive bigf info
34e49164
C
819
820 | F.Break (st,((),ii)) -> iif ii
821 | F.Continue (st,((),ii)) -> iif ii
822 | F.Default (st,((),ii)) -> iif ii
823 | F.Return (st,((),ii)) -> iif ii
b1b2de81
C
824 | F.Goto (st, name, ((),ii)) -> vk_name bigf name; iif ii
825 | F.Label (st, name, ((),ii)) -> vk_name bigf name; iif ii
485bce71 826
34e49164 827 | F.DoHeader (st, info) -> infof info
485bce71 828
34e49164 829 | F.Else info -> infof info
485bce71
C
830 | F.EndStatement iopt -> do_option infof iopt
831
34e49164
C
832 | F.SeqEnd (i, info) -> infof info
833 | F.SeqStart (st, i, info) -> infof info
834
835 | F.MacroStmt (st, ((),ii)) -> iif ii
ae4735db 836 | F.Asm (st, (asmbody,ii)) ->
34e49164
C
837 iif ii;
838 vk_asmbody bigf asmbody
839
840 | (
841 F.TopNode|F.EndNode|
951c7801
C
842 F.ErrorExit|F.Exit|F.Enter|F.LoopFallThroughNode|F.FallThroughNode|
843 F.AfterNode|F.FalseNode|F.TrueNode|F.InLoopNode|
34e49164
C
844 F.Fake
845 ) -> ()
846
847
848
849 in
850 f (k, bigf) node
851
852(* ------------------------------------------------------------------------ *)
ae4735db 853and vk_info = fun bigf info ->
34e49164
C
854 let rec infof ii = bigf.kinfo (k, bigf) ii
855 and k i = ()
856 in
857 infof info
858
ae4735db 859and vk_ii = fun bigf ii ->
34e49164
C
860 List.iter (vk_info bigf) ii
861
862
485bce71 863(* ------------------------------------------------------------------------ *)
ae4735db
C
864and vk_argument = fun bigf arg ->
865 let rec do_action = function
485bce71
C
866 | (ActMisc ii) -> vk_ii bigf ii
867 in
868 match arg with
869 | Left e -> (vk_expr bigf) e
870 | Right (ArgType param) -> vk_param bigf param
871 | Right (ArgAction action) -> do_action action
872
ae4735db 873and vk_argument_list = fun bigf es ->
485bce71 874 let iif ii = vk_ii bigf ii in
ae4735db 875 es +> List.iter (fun (e, ii) ->
485bce71
C
876 iif ii;
877 vk_argument bigf e
878 )
879
880
881
b1b2de81 882and vk_param = fun bigf param ->
34e49164 883 let iif ii = vk_ii bigf ii in
ae4735db 884 let f = bigf.kparam in
951c7801
C
885 let rec k param =
886 let {p_namei = swrapopt; p_register = (b, iib); p_type=ft} = param in
887 swrapopt +> Common.do_option (vk_name bigf);
888 iif iib;
889 vk_type bigf ft
890 in f (k, bigf) param
34e49164 891
ae4735db 892and vk_param_list = fun bigf ts ->
485bce71 893 let iif ii = vk_ii bigf ii in
ae4735db 894 ts +> List.iter (fun (param,iicomma) ->
485bce71
C
895 vk_param bigf param;
896 iif iicomma;
897 )
898
899
900
901(* ------------------------------------------------------------------------ *)
ae4735db 902and vk_asmbody = fun bigf (string_list, colon_list) ->
485bce71
C
903 let iif ii = vk_ii bigf ii in
904
905 iif string_list;
ae4735db 906 colon_list +> List.iter (fun (Colon xs, ii) ->
485bce71 907 iif ii;
ae4735db 908 xs +> List.iter (fun (x,iicomma) ->
485bce71
C
909 iif iicomma;
910 (match x with
ae4735db
C
911 | ColonMisc, ii -> iif ii
912 | ColonExpr e, ii ->
485bce71
C
913 vk_expr bigf e;
914 iif ii
915 )
916 ))
917
34e49164 918
485bce71 919(* ------------------------------------------------------------------------ *)
ae4735db 920let vk_args_splitted = fun bigf args_splitted ->
34e49164 921 let iif ii = vk_ii bigf ii in
ae4735db 922 args_splitted +> List.iter (function
34e49164
C
923 | Left arg -> vk_argument bigf arg
924 | Right ii -> iif ii
925 )
926
927
ae4735db 928let vk_define_params_splitted = fun bigf args_splitted ->
34e49164 929 let iif ii = vk_ii bigf ii in
ae4735db 930 args_splitted +> List.iter (function
34e49164
C
931 | Left (s, iis) -> vk_ii bigf iis
932 | Right ii -> iif ii
933 )
934
935
936
ae4735db 937let vk_params_splitted = fun bigf args_splitted ->
34e49164 938 let iif ii = vk_ii bigf ii in
ae4735db 939 args_splitted +> List.iter (function
34e49164
C
940 | Left arg -> vk_param bigf arg
941 | Right ii -> iif ii
942 )
943
485bce71 944(* ------------------------------------------------------------------------ *)
ae4735db 945let vk_cst = fun bigf (cst, ii) ->
34e49164
C
946 let iif ii = vk_ii bigf ii in
947 iif ii;
948 (match cst with
949 | Left cst -> ()
950 | Right s -> ()
951 )
952
953
ae4735db 954
34e49164
C
955
956(*****************************************************************************)
957(* "syntetisized attributes" style *)
958(*****************************************************************************)
485bce71
C
959
960(* TODO port the xxs_s to new cpp construct too *)
961
ae4735db 962type 'a inout = 'a -> 'a
34e49164 963
ae4735db 964(* _s for synthetizized attributes
34e49164
C
965 *
966 * Note that I don't visit necesserally in the order of the token
967 * found in the original file. So don't assume such hypothesis!
968 *)
ae4735db 969type visitor_c_s = {
34e49164
C
970 kexpr_s: (expression inout * visitor_c_s) -> expression inout;
971 kstatement_s: (statement inout * visitor_c_s) -> statement inout;
972 ktype_s: (fullType inout * visitor_c_s) -> fullType inout;
34e49164
C
973
974 kdecl_s: (declaration inout * visitor_c_s) -> declaration inout;
ae4735db 975 kdef_s: (definition inout * visitor_c_s) -> definition inout;
b1b2de81 976 kname_s: (name inout * visitor_c_s) -> name inout;
34e49164 977
ae4735db 978 kini_s: (initialiser inout * visitor_c_s) -> initialiser inout;
34e49164 979
485bce71 980 kcppdirective_s: (cpp_directive inout * visitor_c_s) -> cpp_directive inout;
34e49164 981 kdefineval_s: (define_val inout * visitor_c_s) -> define_val inout;
485bce71
C
982 kstatementseq_s: (statement_sequencable inout * visitor_c_s) -> statement_sequencable inout;
983 kstatementseq_list_s: (statement_sequencable list inout * visitor_c_s) -> statement_sequencable list inout;
984
985 knode_s: (F.node inout * visitor_c_s) -> F.node inout;
34e49164 986
485bce71
C
987
988 ktoplevel_s: (toplevel inout * visitor_c_s) -> toplevel inout;
34e49164 989 kinfo_s: (info inout * visitor_c_s) -> info inout;
ae4735db 990 }
34e49164 991
ae4735db 992let default_visitor_c_s =
34e49164
C
993 { kexpr_s = (fun (k,_) e -> k e);
994 kstatement_s = (fun (k,_) st -> k st);
995 ktype_s = (fun (k,_) t -> k t);
996 kdecl_s = (fun (k,_) d -> k d);
997 kdef_s = (fun (k,_) d -> k d);
b1b2de81 998 kname_s = (fun (k,_) x -> k x);
34e49164
C
999 kini_s = (fun (k,_) d -> k d);
1000 ktoplevel_s = (fun (k,_) p -> k p);
1001 knode_s = (fun (k,_) n -> k n);
1002 kinfo_s = (fun (k,_) i -> k i);
1003 kdefineval_s = (fun (k,_) x -> k x);
485bce71
C
1004 kstatementseq_s = (fun (k,_) x -> k x);
1005 kstatementseq_list_s = (fun (k,_) x -> k x);
1006 kcppdirective_s = (fun (k,_) x -> k x);
ae4735db 1007 }
34e49164
C
1008
1009let rec vk_expr_s = fun bigf expr ->
1010 let iif ii = vk_ii_s bigf ii in
1011 let rec exprf e = bigf.kexpr_s (k, bigf) e
ae4735db 1012 and k e =
34e49164 1013 let ((unwrap_e, typ), ii) = e in
91eba41f 1014 (* !!! don't analyse optional type !!!
ae4735db 1015 * old: typ +> map_option (vk_type_s bigf) in
34e49164 1016 *)
ae4735db
C
1017 let typ' = typ in
1018 let e' =
34e49164 1019 match unwrap_e with
b1b2de81 1020 | Ident (name) -> Ident (vk_name_s bigf name)
34e49164 1021 | Constant (c) -> Constant (c)
ae4735db 1022 | FunCall (e, es) ->
34e49164 1023 FunCall (exprf e,
ae4735db 1024 es +> List.map (fun (e,ii) ->
34e49164
C
1025 vk_argument_s bigf e, iif ii
1026 ))
ae4735db 1027
faf9a90c 1028 | CondExpr (e1, e2, e3) -> CondExpr (exprf e1, fmap exprf e2, exprf e3)
34e49164
C
1029 | Sequence (e1, e2) -> Sequence (exprf e1, exprf e2)
1030 | Assignment (e1, op, e2) -> Assignment (exprf e1, op, exprf e2)
ae4735db 1031
34e49164
C
1032 | Postfix (e, op) -> Postfix (exprf e, op)
1033 | Infix (e, op) -> Infix (exprf e, op)
1034 | Unary (e, op) -> Unary (exprf e, op)
1035 | Binary (e1, op, e2) -> Binary (exprf e1, op, exprf e2)
ae4735db 1036
34e49164 1037 | ArrayAccess (e1, e2) -> ArrayAccess (exprf e1, exprf e2)
ae4735db
C
1038 | RecordAccess (e, name) ->
1039 RecordAccess (exprf e, vk_name_s bigf name)
1040 | RecordPtAccess (e, name) ->
1041 RecordPtAccess (exprf e, vk_name_s bigf name)
34e49164
C
1042
1043 | SizeOfExpr (e) -> SizeOfExpr (exprf e)
1044 | SizeOfType (t) -> SizeOfType (vk_type_s bigf t)
1045 | Cast (t, e) -> Cast (vk_type_s bigf t, exprf e)
1046
ae4735db 1047 | StatementExpr (statxs, is) ->
34e49164 1048 StatementExpr (
485bce71 1049 vk_statement_sequencable_list_s bigf statxs,
34e49164 1050 iif is)
ae4735db
C
1051 | Constructor (t, initxs) ->
1052 Constructor
1053 (vk_type_s bigf t,
1054 (initxs +> List.map (fun (ini, ii) ->
1055 vk_ini_s bigf ini, vk_ii_s bigf ii)
34e49164 1056 ))
ae4735db 1057
34e49164
C
1058 | ParenExpr (e) -> ParenExpr (exprf e)
1059
1060 in
1061 (e', typ'), (iif ii)
1062 in exprf expr
1063
b1b2de81 1064
ae4735db 1065and vk_argument_s bigf argument =
34e49164 1066 let iif ii = vk_ii_s bigf ii in
ae4735db 1067 let rec do_action = function
34e49164
C
1068 | (ActMisc ii) -> ActMisc (iif ii)
1069 in
1070 (match argument with
1071 | Left e -> Left (vk_expr_s bigf e)
1072 | Right (ArgType param) -> Right (ArgType (vk_param_s bigf param))
1073 | Right (ArgAction action) -> Right (ArgAction (do_action action))
1074 )
1075
b1b2de81
C
1076(* ------------------------------------------------------------------------ *)
1077
34e49164 1078
ae4735db 1079and vk_name_s = fun bigf ident ->
b1b2de81 1080 let iif ii = vk_ii_s bigf ii in
ae4735db
C
1081 let rec namef x = bigf.kname_s (k,bigf) x
1082 and k id =
b1b2de81
C
1083 (match id with
1084 | RegularName (s,ii) -> RegularName (s, iif ii)
ae4735db
C
1085 | CppConcatenatedName xs ->
1086 CppConcatenatedName (xs +> List.map (fun ((x,ii1), ii2) ->
b1b2de81
C
1087 (x, iif ii1), iif ii2
1088 ))
1089 | CppVariadicName (s, ii) -> CppVariadicName (s, iif ii)
ae4735db 1090 | CppIdentBuilder ((s,iis), xs) ->
b1b2de81 1091 CppIdentBuilder ((s, iif iis),
ae4735db 1092 xs +> List.map (fun ((x,iix), iicomma) ->
b1b2de81
C
1093 ((x, iif iix), iif iicomma)))
1094 )
1095 in
1096 namef ident
34e49164 1097
b1b2de81 1098(* ------------------------------------------------------------------------ *)
34e49164
C
1099
1100
1101
ae4735db
C
1102and vk_statement_s = fun bigf st ->
1103 let rec statf st = bigf.kstatement_s (k, bigf) st
1104 and k st =
34e49164 1105 let (unwrap_st, ii) = st in
ae4735db 1106 let st' =
34e49164 1107 match unwrap_st with
ae4735db 1108 | Labeled (Label (name, st)) ->
708f4980 1109 Labeled (Label (vk_name_s bigf name, statf st))
ae4735db 1110 | Labeled (Case (e, st)) ->
34e49164 1111 Labeled (Case ((vk_expr_s bigf) e , statf st))
ae4735db
C
1112 | Labeled (CaseRange (e, e2, st)) ->
1113 Labeled (CaseRange ((vk_expr_s bigf) e,
1114 (vk_expr_s bigf) e2,
34e49164
C
1115 statf st))
1116 | Labeled (Default st) -> Labeled (Default (statf st))
ae4735db 1117 | Compound statxs ->
485bce71 1118 Compound (vk_statement_sequencable_list_s bigf statxs)
34e49164
C
1119 | ExprStatement (None) -> ExprStatement (None)
1120 | ExprStatement (Some e) -> ExprStatement (Some ((vk_expr_s bigf) e))
ae4735db 1121 | Selection (If (e, st1, st2)) ->
34e49164 1122 Selection (If ((vk_expr_s bigf) e, statf st1, statf st2))
ae4735db 1123 | Selection (Switch (e, st)) ->
34e49164 1124 Selection (Switch ((vk_expr_s bigf) e, statf st))
ae4735db 1125 | Iteration (While (e, st)) ->
34e49164 1126 Iteration (While ((vk_expr_s bigf) e, statf st))
ae4735db 1127 | Iteration (DoWhile (st, e)) ->
34e49164 1128 Iteration (DoWhile (statf st, (vk_expr_s bigf) e))
ae4735db 1129 | Iteration (For ((e1opt,i1), (e2opt,i2), (e3opt,i3), st)) ->
708f4980
C
1130 let e1opt' = statf (mk_st (ExprStatement (e1opt)) i1) in
1131 let e2opt' = statf (mk_st (ExprStatement (e2opt)) i2) in
1132 let e3opt' = statf (mk_st (ExprStatement (e3opt)) i3) in
1133
1134 let e1' = Ast_c.unwrap_st e1opt' in
1135 let e2' = Ast_c.unwrap_st e2opt' in
1136 let e3' = Ast_c.unwrap_st e3opt' in
1137 let i1' = Ast_c.get_ii_st_take_care e1opt' in
1138 let i2' = Ast_c.get_ii_st_take_care e2opt' in
1139 let i3' = Ast_c.get_ii_st_take_care e3opt' in
1140
1141 (match (e1', e2', e3') with
ae4735db 1142 | ((ExprStatement x1), (ExprStatement x2), ((ExprStatement x3))) ->
708f4980
C
1143 Iteration (For ((x1,i1'), (x2,i2'), (x3,i3'), statf st))
1144
34e49164
C
1145 | x -> failwith "cant be here if iterator keep ExprStatement as is"
1146 )
1147
ae4735db
C
1148 | Iteration (MacroIteration (s, es, st)) ->
1149 Iteration
34e49164
C
1150 (MacroIteration
1151 (s,
ae4735db 1152 es +> List.map (fun (e, ii) ->
34e49164 1153 vk_argument_s bigf e, vk_ii_s bigf ii
ae4735db 1154 ),
34e49164
C
1155 statf st
1156 ))
1157
ae4735db 1158
b1b2de81 1159 | Jump (Goto name) -> Jump (Goto (vk_name_s bigf name))
34e49164
C
1160 | Jump (((Continue|Break|Return) as x)) -> Jump (x)
1161 | Jump (ReturnExpr e) -> Jump (ReturnExpr ((vk_expr_s bigf) e))
1162 | Jump (GotoComputed e) -> Jump (GotoComputed (vk_expr_s bigf e));
1163
1164 | Decl decl -> Decl (vk_decl_s bigf decl)
1165 | Asm asmbody -> Asm (vk_asmbody_s bigf asmbody)
1166 | NestedFunc def -> NestedFunc (vk_def_s bigf def)
1167 | MacroStmt -> MacroStmt
1168 in
1169 st', vk_ii_s bigf ii
1170 in statf st
1171
485bce71 1172
ae4735db 1173and vk_statement_sequencable_s = fun bigf stseq ->
485bce71 1174 let f = bigf.kstatementseq_s in
ae4735db 1175 let k stseq =
485bce71
C
1176
1177 match stseq with
ae4735db 1178 | StmtElem st ->
485bce71 1179 StmtElem (vk_statement_s bigf st)
ae4735db 1180 | CppDirectiveStmt directive ->
485bce71 1181 CppDirectiveStmt (vk_cpp_directive_s bigf directive)
ae4735db 1182 | IfdefStmt ifdef ->
485bce71 1183 IfdefStmt (vk_ifdef_directive_s bigf ifdef)
ae4735db 1184 | IfdefStmt2 (ifdef, xxs) ->
485bce71 1185 let ifdef' = List.map (vk_ifdef_directive_s bigf) ifdef in
ae4735db 1186 let xxs' = xxs +> List.map (fun xs ->
b1b2de81 1187 xs +> vk_statement_sequencable_list_s bigf
485bce71
C
1188 )
1189 in
1190 IfdefStmt2(ifdef', xxs')
1191 in f (k, bigf) stseq
1192
ae4735db 1193and vk_statement_sequencable_list_s = fun bigf statxs ->
485bce71 1194 let f = bigf.kstatementseq_list_s in
ae4735db 1195 let k xs =
485bce71
C
1196 xs +> List.map (vk_statement_sequencable_s bigf)
1197 in
1198 f (k, bigf) statxs
485bce71
C
1199
1200
ae4735db
C
1201
1202and vk_asmbody_s = fun bigf (string_list, colon_list) ->
34e49164
C
1203 let iif ii = vk_ii_s bigf ii in
1204
1205 iif string_list,
ae4735db
C
1206 colon_list +> List.map (fun (Colon xs, ii) ->
1207 Colon
1208 (xs +> List.map (fun (x, iicomma) ->
34e49164 1209 (match x with
ae4735db 1210 | ColonMisc, ii -> ColonMisc, iif ii
34e49164
C
1211 | ColonExpr e, ii -> ColonExpr (vk_expr_s bigf e), iif ii
1212 ), iif iicomma
ae4735db
C
1213 )),
1214 iif ii
34e49164 1215 )
ae4735db
C
1216
1217
34e49164
C
1218
1219
0708f913 1220(* todo? a visitor for qualifier *)
ae4735db 1221and vk_type_s = fun bigf t ->
34e49164
C
1222 let rec typef t = bigf.ktype_s (k,bigf) t
1223 and iif ii = vk_ii_s bigf ii
ae4735db 1224 and k t =
34e49164
C
1225 let (q, t) = t in
1226 let (unwrap_q, iiq) = q in
faf9a90c
C
1227 (* strip_info_visitor needs iiq to be processed before iit *)
1228 let iif_iiq = iif iiq in
0708f913 1229 let q' = unwrap_q in
34e49164 1230 let (unwrap_t, iit) = t in
ae4735db 1231 let t' =
34e49164
C
1232 match unwrap_t with
1233 | BaseType x -> BaseType x
1234 | Pointer t -> Pointer (typef t)
ae4735db
C
1235 | Array (eopt, t) -> Array (fmap (vk_expr_s bigf) eopt, typef t)
1236 | FunctionType (returnt, paramst) ->
1237 FunctionType
1238 (typef returnt,
34e49164 1239 (match paramst with
ae4735db
C
1240 | (ts, (b, iihas3dots)) ->
1241 (ts +> List.map (fun (param,iicomma) ->
34e49164
C
1242 (vk_param_s bigf param, iif iicomma)),
1243 (b, iif iihas3dots))
1244 ))
1245
ae4735db 1246 | Enum (sopt, enumt) ->
34e49164 1247 Enum (sopt,
ae4735db
C
1248 enumt +> List.map (fun ((name, eopt), iicomma) ->
1249
1250 ((vk_name_s bigf name,
1251 eopt +> Common.fmap (fun (info, e) ->
b1b2de81
C
1252 vk_info_s bigf info,
1253 vk_expr_s bigf e
ae4735db 1254 )),
b1b2de81
C
1255 iif iicomma)
1256 )
34e49164 1257 )
ae4735db 1258 | StructUnion (sopt, su, fields) ->
34e49164
C
1259 StructUnion (sopt, su, vk_struct_fields_s bigf fields)
1260
1261
1262 | StructUnionName (s, structunion) -> StructUnionName (s, structunion)
1263 | EnumName s -> EnumName s
b1b2de81 1264 | TypeName (name, typ) -> TypeName (vk_name_s bigf name, typ)
34e49164
C
1265
1266 | ParenType t -> ParenType (typef t)
1267 | TypeOfExpr e -> TypeOfExpr (vk_expr_s bigf e)
1268 | TypeOfType t -> TypeOfType (typef t)
1269 in
ae4735db 1270 (q', iif_iiq),
faf9a90c 1271 (t', iif iit)
34e49164
C
1272
1273
1274 in typef t
1275
ae4735db 1276and vk_attribute_s = fun bigf attr ->
485bce71
C
1277 let iif ii = vk_ii_s bigf ii in
1278 match attr with
ae4735db 1279 | Attribute s, ii ->
485bce71
C
1280 Attribute s, iif ii
1281
1282
1283
ae4735db
C
1284and vk_decl_s = fun bigf d ->
1285 let f = bigf.kdecl_s in
34e49164 1286 let iif ii = vk_ii_s bigf ii in
ae4735db 1287 let rec k decl =
34e49164 1288 match decl with
ae4735db 1289 | DeclList (xs, ii) ->
34e49164 1290 DeclList (List.map aux xs, iif ii)
ae4735db
C
1291 | MacroDecl ((s, args),ii) ->
1292 MacroDecl
1293 ((s,
34e49164
C
1294 args +> List.map (fun (e,ii) -> vk_argument_s bigf e, iif ii)
1295 ),
1296 iif ii)
1297
1298
ae4735db
C
1299 and aux ({v_namei = var;
1300 v_type = t;
1301 v_type_bis = tbis;
1302 v_storage = sto;
1303 v_local= local;
1304 v_attr = attrs}, iicomma) =
1305 {v_namei =
1306 (var +> map_option (fun (name, iniopt) ->
1307 vk_name_s bigf name,
1308 iniopt +> map_option (fun (info, init) ->
b1b2de81
C
1309 vk_info_s bigf info,
1310 vk_ini_s bigf init
1311 )));
485bce71 1312 v_type = vk_type_s bigf t;
978fd7e5
C
1313 (* !!! dont go in semantic related stuff !!! *)
1314 v_type_bis = tbis;
485bce71
C
1315 v_storage = sto;
1316 v_local = local;
1317 v_attr = attrs +> List.map (vk_attribute_s bigf);
1318 },
1319 iif iicomma
34e49164 1320
ae4735db 1321 in f (k, bigf) d
34e49164 1322
ae4735db 1323and vk_ini_s = fun bigf ini ->
34e49164 1324 let rec inif ini = bigf.kini_s (k,bigf) ini
ae4735db 1325 and k ini =
34e49164 1326 let (unwrap_ini, ii) = ini in
ae4735db 1327 let ini' =
34e49164
C
1328 match unwrap_ini with
1329 | InitExpr e -> InitExpr (vk_expr_s bigf e)
ae4735db
C
1330 | InitList initxs ->
1331 InitList (initxs +> List.map (fun (ini, ii) ->
1332 inif ini, vk_ii_s bigf ii)
34e49164
C
1333 )
1334
1335
ae4735db
C
1336 | InitDesignators (xs, e) ->
1337 InitDesignators
34e49164 1338 (xs +> List.map (vk_designator_s bigf),
ae4735db 1339 inif e
34e49164
C
1340 )
1341
1342 | InitFieldOld (s, e) -> InitFieldOld (s, inif e)
1343 | InitIndexOld (e1, e) -> InitIndexOld (vk_expr_s bigf e1, inif e)
1344
485bce71 1345
34e49164
C
1346 in ini', vk_ii_s bigf ii
1347 in inif ini
1348
1349
ae4735db 1350and vk_designator_s = fun bigf design ->
34e49164
C
1351 let iif ii = vk_ii_s bigf ii in
1352 let (designator, ii) = design in
1353 (match designator with
1354 | DesignatorField s -> DesignatorField s
1355 | DesignatorIndex e -> DesignatorIndex (vk_expr_s bigf e)
ae4735db 1356 | DesignatorRange (e1, e2) ->
34e49164
C
1357 DesignatorRange (vk_expr_s bigf e1, vk_expr_s bigf e2)
1358 ), iif ii
1359
1360
1361
1362
ae4735db 1363and vk_struct_fieldkinds_s = fun bigf onefield_multivars ->
485bce71 1364 let iif ii = vk_ii_s bigf ii in
ae4735db 1365
485bce71
C
1366 onefield_multivars +> List.map (fun (field, iicomma) ->
1367 (match field with
ae4735db
C
1368 | Simple (nameopt, t) ->
1369 Simple (Common.map_option (vk_name_s bigf) nameopt,
b1b2de81 1370 vk_type_s bigf t)
ae4735db
C
1371 | BitField (nameopt, t, info, expr) ->
1372 BitField (Common.map_option (vk_name_s bigf) nameopt,
1373 vk_type_s bigf t,
b1b2de81
C
1374 vk_info_s bigf info,
1375 vk_expr_s bigf expr)
485bce71
C
1376 ), iif iicomma
1377 )
1378
ae4735db 1379and vk_struct_fields_s = fun bigf fields ->
34e49164
C
1380
1381 let iif ii = vk_ii_s bigf ii in
1382
ae4735db 1383 fields +> List.map (fun (field) ->
708f4980 1384 (match field with
ae4735db 1385 | (DeclarationField (FieldDeclList (onefield_multivars, iiptvirg))) ->
485bce71 1386 DeclarationField
ae4735db 1387 (FieldDeclList
485bce71 1388 (vk_struct_fieldkinds_s bigf onefield_multivars, iif iiptvirg))
708f4980 1389 | EmptyField info -> EmptyField (vk_info_s bigf info)
ae4735db 1390 | MacroDeclField ((s, args),ii) ->
708f4980 1391 MacroDeclField
ae4735db 1392 ((s,
708f4980
C
1393 args +> List.map (fun (e,ii) -> vk_argument_s bigf e, iif ii)
1394 ),
1395 iif ii)
485bce71 1396
ae4735db 1397 | CppDirectiveStruct directive ->
485bce71 1398 CppDirectiveStruct (vk_cpp_directive_s bigf directive)
ae4735db 1399 | IfdefStruct ifdef ->
485bce71
C
1400 IfdefStruct (vk_ifdef_directive_s bigf ifdef)
1401
708f4980 1402 )
34e49164
C
1403 )
1404
1405
ae4735db 1406and vk_def_s = fun bigf d ->
34e49164
C
1407 let f = bigf.kdef_s in
1408 let iif ii = vk_ii_s bigf ii in
ae4735db 1409 let rec k d =
34e49164 1410 match d with
708f4980 1411 | {f_name = name;
485bce71
C
1412 f_type = (returnt, (paramst, (b, iib)));
1413 f_storage = sto;
1414 f_body = statxs;
1415 f_attr = attrs;
91eba41f 1416 f_old_c_style = oldstyle;
ae4735db
C
1417 }, ii
1418 ->
708f4980 1419 {f_name = vk_name_s bigf name;
ae4735db
C
1420 f_type =
1421 (vk_type_s bigf returnt,
485bce71
C
1422 (paramst +> List.map (fun (param, iicomma) ->
1423 (vk_param_s bigf param, iif iicomma)
1424 ), (b, iif iib)));
1425 f_storage = sto;
ae4735db 1426 f_body =
485bce71 1427 vk_statement_sequencable_list_s bigf statxs;
ae4735db 1428 f_attr =
91eba41f 1429 attrs +> List.map (vk_attribute_s bigf);
ae4735db
C
1430 f_old_c_style =
1431 oldstyle +> Common.map_option (fun decls ->
91eba41f
C
1432 decls +> List.map (vk_decl_s bigf)
1433 );
485bce71 1434 },
34e49164
C
1435 iif ii
1436
ae4735db 1437 in f (k, bigf) d
34e49164 1438
ae4735db 1439and vk_toplevel_s = fun bigf p ->
34e49164
C
1440 let f = bigf.ktoplevel_s in
1441 let iif ii = vk_ii_s bigf ii in
ae4735db 1442 let rec k p =
34e49164
C
1443 match p with
1444 | Declaration decl -> Declaration (vk_decl_s bigf decl)
1445 | Definition def -> Definition (vk_def_s bigf def)
1446 | EmptyDef ii -> EmptyDef (iif ii)
ae4735db 1447 | MacroTop (s, xs, ii) ->
34e49164 1448 MacroTop
ae4735db
C
1449 (s,
1450 xs +> List.map (fun (elem, iicomma) ->
34e49164
C
1451 vk_argument_s bigf elem, iif iicomma
1452 ),
1453 iif ii
1454 )
485bce71
C
1455 | CppTop top -> CppTop (vk_cpp_directive_s bigf top)
1456 | IfdefTop ifdefdir -> IfdefTop (vk_ifdef_directive_s bigf ifdefdir)
34e49164
C
1457
1458 | NotParsedCorrectly ii -> NotParsedCorrectly (iif ii)
1459 | FinalDef info -> FinalDef (vk_info_s bigf info)
1460 in f (k, bigf) p
1461
ae4735db 1462and vk_program_s = fun bigf xs ->
485bce71
C
1463 xs +> List.map (vk_toplevel_s bigf)
1464
1465
1466and vk_cpp_directive_s = fun bigf top ->
1467 let iif ii = vk_ii_s bigf ii in
1468 let f = bigf.kcppdirective_s in
ae4735db
C
1469 let rec k top =
1470 match top with
485bce71
C
1471 (* go inside ? *)
1472 | Include {i_include = (s, ii);
1473 i_rel_pos = h_rel_pos;
1474 i_is_in_ifdef = b;
1475 i_content = copt;
ae4735db 1476 }
485bce71
C
1477 -> Include {i_include = (s, iif ii);
1478 i_rel_pos = h_rel_pos;
1479 i_is_in_ifdef = b;
ae4735db 1480 i_content = copt +> Common.map_option (fun (file, asts) ->
485bce71
C
1481 file, vk_program_s bigf asts
1482 );
1483 }
ae4735db
C
1484 | Define ((s,ii), (defkind, defval)) ->
1485 Define ((s, iif ii),
485bce71
C
1486 (vk_define_kind_s bigf defkind, vk_define_val_s bigf defval))
1487 | Undef (s, ii) -> Undef (s, iif ii)
1488 | PragmaAndCo (ii) -> PragmaAndCo (iif ii)
1489
1490 in f (k, bigf) top
1491
ae4735db 1492and vk_ifdef_directive_s = fun bigf ifdef ->
485bce71
C
1493 let iif ii = vk_ii_s bigf ii in
1494 match ifdef with
1495 | IfdefDirective (ifkind, ii) -> IfdefDirective (ifkind, iif ii)
1496
1497
1498
ae4735db 1499and vk_define_kind_s = fun bigf defkind ->
34e49164 1500 match defkind with
ae4735db
C
1501 | DefineVar -> DefineVar
1502 | DefineFunc (params, ii) ->
1503 DefineFunc
1504 (params +> List.map (fun ((s,iis),iicomma) ->
34e49164
C
1505 ((s, vk_ii_s bigf iis), vk_ii_s bigf iicomma)
1506 ),
1507 vk_ii_s bigf ii
1508 )
1509
1510
ae4735db 1511and vk_define_val_s = fun bigf x ->
34e49164
C
1512 let f = bigf.kdefineval_s in
1513 let iif ii = vk_ii_s bigf ii in
ae4735db 1514 let rec k x =
34e49164
C
1515 match x with
1516 | DefineExpr e -> DefineExpr (vk_expr_s bigf e)
1517 | DefineStmt st -> DefineStmt (vk_statement_s bigf st)
ae4735db 1518 | DefineDoWhileZero ((st,e),ii) ->
485bce71
C
1519 let st' = vk_statement_s bigf st in
1520 let e' = vk_expr_s bigf e in
1521 DefineDoWhileZero ((st',e'), iif ii)
34e49164
C
1522 | DefineFunction def -> DefineFunction (vk_def_s bigf def)
1523 | DefineType ty -> DefineType (vk_type_s bigf ty)
1524 | DefineText (s, ii) -> DefineText (s, iif ii)
1525 | DefineEmpty -> DefineEmpty
485bce71
C
1526 | DefineInit ini -> DefineInit (vk_ini_s bigf ini)
1527
ae4735db 1528 | DefineTodo ->
91eba41f 1529 pr2_once "DefineTodo";
485bce71 1530 DefineTodo
34e49164
C
1531 in
1532 f (k, bigf) x
34e49164 1533
ae4735db
C
1534
1535and vk_info_s = fun bigf info ->
34e49164
C
1536 let rec infof ii = bigf.kinfo_s (k, bigf) ii
1537 and k i = i
1538 in
1539 infof info
1540
ae4735db 1541and vk_ii_s = fun bigf ii ->
34e49164
C
1542 List.map (vk_info_s bigf) ii
1543
1544(* ------------------------------------------------------------------------ *)
ae4735db 1545and vk_node_s = fun bigf node ->
34e49164
C
1546 let iif ii = vk_ii_s bigf ii in
1547 let infof info = vk_info_s bigf info in
1548
1549 let rec nodef n = bigf.knode_s (k, bigf) n
ae4735db 1550 and k node =
34e49164
C
1551 F.rewrap node (
1552 match F.unwrap node with
ae4735db 1553 | F.FunHeader (def) ->
91eba41f
C
1554 assert (null (fst def).f_body);
1555 F.FunHeader (vk_def_s bigf def)
ae4735db 1556
34e49164 1557 | F.Decl declb -> F.Decl (vk_decl_s bigf declb)
ae4735db 1558 | F.ExprStatement (st, (eopt, ii)) ->
34e49164 1559 F.ExprStatement (st, (eopt +> map_option (vk_expr_s bigf), iif ii))
ae4735db
C
1560
1561 | F.IfHeader (st, (e,ii)) ->
34e49164 1562 F.IfHeader (st, (vk_expr_s bigf e, iif ii))
ae4735db 1563 | F.SwitchHeader (st, (e,ii)) ->
34e49164 1564 F.SwitchHeader(st, (vk_expr_s bigf e, iif ii))
ae4735db 1565 | F.WhileHeader (st, (e,ii)) ->
34e49164 1566 F.WhileHeader (st, (vk_expr_s bigf e, iif ii))
ae4735db 1567 | F.DoWhileTail (e,ii) ->
34e49164
C
1568 F.DoWhileTail (vk_expr_s bigf e, iif ii)
1569
ae4735db 1570 | F.ForHeader (st, (((e1opt,i1), (e2opt,i2), (e3opt,i3)), ii)) ->
34e49164
C
1571 F.ForHeader (st,
1572 (((e1opt +> Common.map_option (vk_expr_s bigf), iif i1),
1573 (e2opt +> Common.map_option (vk_expr_s bigf), iif i2),
1574 (e3opt +> Common.map_option (vk_expr_s bigf), iif i3)),
1575 iif ii))
1576
ae4735db 1577 | F.MacroIterHeader (st, ((s,es), ii)) ->
34e49164
C
1578 F.MacroIterHeader
1579 (st,
1580 ((s, es +> List.map (fun (e, ii) -> vk_argument_s bigf e, iif ii)),
1581 iif ii))
1582
ae4735db
C
1583
1584 | F.ReturnExpr (st, (e,ii)) ->
34e49164 1585 F.ReturnExpr (st, (vk_expr_s bigf e, iif ii))
ae4735db 1586
34e49164 1587 | F.Case (st, (e,ii)) -> F.Case (st, (vk_expr_s bigf e, iif ii))
ae4735db 1588 | F.CaseRange (st, ((e1, e2),ii)) ->
34e49164
C
1589 F.CaseRange (st, ((vk_expr_s bigf e1, vk_expr_s bigf e2), iif ii))
1590
1591 | F.CaseNode i -> F.CaseNode i
1592
ae4735db 1593 | F.DefineHeader((s,ii), (defkind)) ->
34e49164
C
1594 F.DefineHeader ((s, iif ii), (vk_define_kind_s bigf defkind))
1595
1596 | F.DefineExpr e -> F.DefineExpr (vk_expr_s bigf e)
1597 | F.DefineType ft -> F.DefineType (vk_type_s bigf ft)
ae4735db 1598 | F.DefineDoWhileZeroHeader ((),ii) ->
34e49164 1599 F.DefineDoWhileZeroHeader ((),iif ii)
485bce71
C
1600 | F.DefineTodo -> F.DefineTodo
1601
1602 | F.Include {i_include = (s, ii);
1603 i_rel_pos = h_rel_pos;
1604 i_is_in_ifdef = b;
1605 i_content = copt;
ae4735db
C
1606 }
1607 ->
b1b2de81 1608 assert (copt =*= None);
485bce71
C
1609 F.Include {i_include = (s, iif ii);
1610 i_rel_pos = h_rel_pos;
1611 i_is_in_ifdef = b;
1612 i_content = copt;
1613 }
34e49164 1614
ae4735db
C
1615 | F.MacroTop (s, args, ii) ->
1616 F.MacroTop
34e49164
C
1617 (s,
1618 args +> List.map (fun (e, ii) -> vk_argument_s bigf e, iif ii),
1619 iif ii)
1620
1621
1622 | F.MacroStmt (st, ((),ii)) -> F.MacroStmt (st, ((),iif ii))
1623 | F.Asm (st, (body,ii)) -> F.Asm (st, (vk_asmbody_s bigf body,iif ii))
1624
1625 | F.Break (st,((),ii)) -> F.Break (st,((),iif ii))
1626 | F.Continue (st,((),ii)) -> F.Continue (st,((),iif ii))
1627 | F.Default (st,((),ii)) -> F.Default (st,((),iif ii))
1628 | F.Return (st,((),ii)) -> F.Return (st,((),iif ii))
ae4735db 1629 | F.Goto (st, name, ((),ii)) ->
b1b2de81 1630 F.Goto (st, vk_name_s bigf name, ((),iif ii))
ae4735db 1631 | F.Label (st, name, ((),ii)) ->
b1b2de81 1632 F.Label (st, vk_name_s bigf name, ((),iif ii))
34e49164
C
1633 | F.EndStatement iopt -> F.EndStatement (map_option infof iopt)
1634 | F.DoHeader (st, info) -> F.DoHeader (st, infof info)
1635 | F.Else info -> F.Else (infof info)
1636 | F.SeqEnd (i, info) -> F.SeqEnd (i, infof info)
1637 | F.SeqStart (st, i, info) -> F.SeqStart (st, i, infof info)
1638
485bce71
C
1639 | F.IfdefHeader (info) -> F.IfdefHeader (vk_ifdef_directive_s bigf info)
1640 | F.IfdefElse (info) -> F.IfdefElse (vk_ifdef_directive_s bigf info)
1641 | F.IfdefEndif (info) -> F.IfdefEndif (vk_ifdef_directive_s bigf info)
1642
34e49164
C
1643 | (
1644 (
1645 F.TopNode|F.EndNode|
951c7801
C
1646 F.ErrorExit|F.Exit|F.Enter|F.LoopFallThroughNode|F.FallThroughNode|
1647 F.AfterNode|F.FalseNode|F.TrueNode|F.InLoopNode|
34e49164
C
1648 F.Fake
1649 ) as x) -> x
1650
1651
1652 )
1653 in
1654 nodef node
ae4735db 1655
34e49164 1656(* ------------------------------------------------------------------------ *)
ae4735db 1657and vk_param_s = fun bigf param ->
34e49164 1658 let iif ii = vk_ii_s bigf ii in
b1b2de81
C
1659 let {p_namei = swrapopt; p_register = (b, iib); p_type=ft} = param in
1660 { p_namei = swrapopt +> Common.map_option (vk_name_s bigf);
1661 p_register = (b, iif iib);
1662 p_type = vk_type_s bigf ft;
1663 }
faf9a90c 1664
ae4735db 1665let vk_args_splitted_s = fun bigf args_splitted ->
34e49164 1666 let iif ii = vk_ii_s bigf ii in
ae4735db 1667 args_splitted +> List.map (function
34e49164
C
1668 | Left arg -> Left (vk_argument_s bigf arg)
1669 | Right ii -> Right (iif ii)
1670 )
1671
ae4735db 1672let vk_arguments_s = fun bigf args ->
34e49164
C
1673 let iif ii = vk_ii_s bigf ii in
1674 args +> List.map (fun (e, ii) -> vk_argument_s bigf e, iif ii)
1675
1676
ae4735db 1677let vk_params_splitted_s = fun bigf args_splitted ->
34e49164 1678 let iif ii = vk_ii_s bigf ii in
ae4735db 1679 args_splitted +> List.map (function
34e49164
C
1680 | Left arg -> Left (vk_param_s bigf arg)
1681 | Right ii -> Right (iif ii)
1682 )
1683
ae4735db 1684let vk_params_s = fun bigf args ->
34e49164
C
1685 let iif ii = vk_ii_s bigf ii in
1686 args +> List.map (fun (p,ii) -> vk_param_s bigf p, iif ii)
1687
ae4735db 1688let vk_define_params_splitted_s = fun bigf args_splitted ->
34e49164 1689 let iif ii = vk_ii_s bigf ii in
ae4735db 1690 args_splitted +> List.map (function
34e49164
C
1691 | Left (s, iis) -> Left (s, vk_ii_s bigf iis)
1692 | Right ii -> Right (iif ii)
1693 )
1694
ae4735db 1695let vk_cst_s = fun bigf (cst, ii) ->
34e49164
C
1696 let iif ii = vk_ii_s bigf ii in
1697 (match cst with
ae4735db 1698 | Left cst -> Left cst
34e49164
C
1699 | Right s -> Right s
1700 ), iif ii