Coccinelle release 0.2.5-rc7.
[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
4dfbc1c2
C
333 | New t -> vk_argument bigf t
334 | Delete e -> vk_expr bigf e
f59c9fb7 335
34e49164
C
336
337 in exprf expr
338
34e49164 339
b1b2de81 340(* ------------------------------------------------------------------------ *)
ae4735db 341and vk_name = fun bigf ident ->
b1b2de81 342 let iif ii = vk_ii bigf ii in
34e49164 343
ae4735db
C
344 let rec namef x = bigf.kname (k,bigf) x
345 and k id =
b1b2de81
C
346 match id with
347 | RegularName (s, ii) -> iif ii
ae4735db
C
348 | CppConcatenatedName xs ->
349 xs +> List.iter (fun ((x,ii1), ii2) ->
b1b2de81
C
350 iif ii2;
351 iif ii1;
352 );
353 | CppVariadicName (s, ii) -> iif ii
ae4735db 354 | CppIdentBuilder ((s,iis), xs) ->
b1b2de81 355 iif iis;
ae4735db 356 xs +> List.iter (fun ((x,iix), iicomma) ->
b1b2de81
C
357 iif iicomma;
358 iif iix;
359 )
360 in
361 namef ident
362
363(* ------------------------------------------------------------------------ *)
34e49164
C
364
365
ae4735db 366and vk_statement = fun bigf (st: Ast_c.statement) ->
34e49164
C
367 let iif ii = vk_ii bigf ii in
368
ae4735db
C
369 let rec statf x = bigf.kstatement (k,bigf) x
370 and k st =
34e49164
C
371 let (unwrap_st, ii) = st in
372 iif ii;
373 match unwrap_st with
ae4735db 374 | Labeled (Label (name, st)) ->
708f4980
C
375 vk_name bigf name;
376 statf st;
34e49164 377 | Labeled (Case (e, st)) -> vk_expr bigf e; statf st;
ae4735db 378 | Labeled (CaseRange (e, e2, st)) ->
34e49164
C
379 vk_expr bigf e; vk_expr bigf e2; statf st;
380 | Labeled (Default st) -> statf st;
381
ae4735db 382 | Compound statxs ->
485bce71 383 statxs +> List.iter (vk_statement_sequencable bigf)
34e49164
C
384 | ExprStatement (eopt) -> do_option (vk_expr bigf) eopt;
385
ae4735db 386 | Selection (If (e, st1, st2)) ->
34e49164 387 vk_expr bigf e; statf st1; statf st2;
ae4735db 388 | Selection (Switch (e, st)) ->
34e49164 389 vk_expr bigf e; statf st;
ae4735db 390 | Iteration (While (e, st)) ->
34e49164 391 vk_expr bigf e; statf st;
ae4735db
C
392 | Iteration (DoWhile (st, e)) -> statf st; vk_expr bigf e;
393 | Iteration (For ((e1opt,i1), (e2opt,i2), (e3opt,i3), st)) ->
394 statf (mk_st (ExprStatement (e1opt)) i1);
395 statf (mk_st (ExprStatement (e2opt)) i2);
396 statf (mk_st (ExprStatement (e3opt)) i3);
34e49164
C
397 statf st;
398
ae4735db 399 | Iteration (MacroIteration (s, es, st)) ->
485bce71 400 vk_argument_list bigf es;
34e49164 401 statf st;
ae4735db 402
b1b2de81 403 | Jump (Goto name) -> vk_name bigf name
34e49164
C
404 | Jump ((Continue|Break|Return)) -> ()
405 | Jump (ReturnExpr e) -> vk_expr bigf e;
406 | Jump (GotoComputed e) -> vk_expr bigf e;
407
ae4735db 408 | Decl decl -> vk_decl bigf decl
34e49164
C
409 | Asm asmbody -> vk_asmbody bigf asmbody
410 | NestedFunc def -> vk_def bigf def
411 | MacroStmt -> ()
412
413 in statf st
414
ae4735db
C
415and vk_statement_sequencable = fun bigf stseq ->
416 let f = bigf.kstatementseq in
485bce71 417
ae4735db 418 let rec k stseq =
485bce71
C
419 match stseq with
420 | StmtElem st -> vk_statement bigf st
ae4735db 421 | CppDirectiveStmt directive ->
485bce71 422 vk_cpp_directive bigf directive
ae4735db 423 | IfdefStmt ifdef ->
485bce71 424 vk_ifdef_directive bigf ifdef
ae4735db 425 | IfdefStmt2 (ifdef, xxs) ->
485bce71 426 ifdef +> List.iter (vk_ifdef_directive bigf);
ae4735db 427 xxs +> List.iter (fun xs ->
485bce71
C
428 xs +> List.iter (vk_statement_sequencable bigf)
429 )
ae4735db 430
485bce71
C
431 in f (k, bigf) stseq
432
34e49164 433
34e49164 434
ae4735db 435and vk_type = fun bigf t ->
34e49164
C
436 let iif ii = vk_ii bigf ii in
437
ae4735db
C
438 let rec typef x = bigf.ktype (k, bigf) x
439 and k t =
34e49164
C
440 let (q, t) = t in
441 let (unwrap_q, iiq) = q in
442 let (unwrap_t, iit) = t in
443 iif iiq;
444 iif iit;
445 match unwrap_t with
f59c9fb7 446 | NoType _ -> ()
34e49164
C
447 | BaseType _ -> ()
448 | Pointer t -> typef t
ae4735db 449 | Array (eopt, t) ->
34e49164 450 do_option (vk_expr bigf) eopt;
ae4735db
C
451 typef t
452 | FunctionType (returnt, paramst) ->
34e49164
C
453 typef returnt;
454 (match paramst with
ae4735db 455 | (ts, (b,iihas3dots)) ->
34e49164 456 iif iihas3dots;
485bce71 457 vk_param_list bigf ts
34e49164
C
458 )
459
ae4735db 460 | Enum (sopt, enumt) ->
c491d8ee 461 vk_enum_fields bigf enumt
ae4735db
C
462
463 | StructUnion (sopt, _su, fields) ->
34e49164
C
464 vk_struct_fields bigf fields
465
466 | StructUnionName (s, structunion) -> ()
467 | EnumName s -> ()
468
469 (* dont go in _typ *)
ae4735db 470 | TypeName (name,_typ) ->
b1b2de81 471 vk_name bigf name
34e49164
C
472
473 | ParenType t -> typef t
474 | TypeOfExpr e -> vk_expr bigf e
475 | TypeOfType t -> typef t
476
477 in typef t
478
485bce71 479
ae4735db 480and vk_attribute = fun bigf attr ->
485bce71
C
481 let iif ii = vk_ii bigf ii in
482 match attr with
ae4735db 483 | Attribute s, ii ->
485bce71
C
484 iif ii
485
486
487(* ------------------------------------------------------------------------ *)
488
ae4735db 489and vk_decl = fun bigf d ->
34e49164
C
490 let iif ii = vk_ii bigf ii in
491
ae4735db
C
492 let f = bigf.kdecl in
493 let rec k decl =
494 match decl with
785a3008
C
495 | DeclList (xs,ii) ->
496 iif ii;
497 xs +> List.iter (fun (x,ii) ->
91eba41f
C
498 iif ii;
499 vk_onedecl bigf x;
500 );
ae4735db 501 | MacroDecl ((s, args),ii) ->
34e49164 502 iif ii;
485bce71 503 vk_argument_list bigf args;
ae4735db 504 in f (k, bigf) d
91eba41f
C
505
506
ae4735db 507and vk_onedecl = fun bigf onedecl ->
91eba41f 508 let iif ii = vk_ii bigf ii in
ae4735db
C
509 let f = bigf.konedecl in
510 let rec k onedecl =
91eba41f 511 match onedecl with
ae4735db
C
512 | ({v_namei = var;
513 v_type = t;
978fd7e5 514 v_type_bis = tbis;
ae4735db
C
515 v_storage = _sto;
516 v_attr = attrs}) ->
34e49164 517
34e49164 518 vk_type bigf t;
978fd7e5 519 (* dont go in tbis *)
485bce71 520 attrs +> List.iter (vk_attribute bigf);
ae4735db 521 var +> Common.do_option (fun (name, iniopt) ->
b1b2de81 522 vk_name bigf name;
4dfbc1c2
C
523 (match iniopt with
524 Ast_c.NoInit -> ()
525 | Ast_c.ValInit(iini,init) -> iif [iini]; vk_ini bigf init
526 | Ast_c.ConstrInit((init,ii)) -> iif ii; vk_argument_list bigf init)
b1b2de81 527 )
951c7801 528 in f (k, bigf) onedecl
34e49164 529
ae4735db 530and vk_ini = fun bigf ini ->
34e49164
C
531 let iif ii = vk_ii bigf ii in
532
ae4735db
C
533 let rec inif x = bigf.kini (k, bigf) x
534 and k (ini, iini) =
34e49164
C
535 iif iini;
536 match ini with
537 | InitExpr e -> vk_expr bigf e
ae4735db
C
538 | InitList initxs ->
539 initxs +> List.iter (fun (ini, ii) ->
34e49164
C
540 inif ini;
541 iif ii;
ae4735db
C
542 )
543 | InitDesignators (xs, e) ->
34e49164
C
544 xs +> List.iter (vk_designator bigf);
545 inif e
546
547 | InitFieldOld (s, e) -> inif e
548 | InitIndexOld (e1, e) ->
549 vk_expr bigf e1; inif e
550
485bce71 551
34e49164
C
552 in inif ini
553
554
ae4735db 555and vk_designator = fun bigf design ->
34e49164
C
556 let iif ii = vk_ii bigf ii in
557 let (designator, ii) = design in
558 iif ii;
559 match designator with
560 | DesignatorField s -> ()
561 | DesignatorIndex e -> vk_expr bigf e
562 | DesignatorRange (e1, e2) -> vk_expr bigf e1; vk_expr bigf e2
563
485bce71
C
564
565(* ------------------------------------------------------------------------ *)
566
ae4735db 567and vk_struct_fields = fun bigf fields ->
0708f913
C
568 fields +> List.iter (vk_struct_field bigf);
569
ae4735db 570and vk_struct_field = fun bigf field ->
34e49164
C
571 let iif ii = vk_ii bigf ii in
572
0708f913 573 let f = bigf.kfield in
ae4735db 574 let rec k field =
0708f913 575
ae4735db
C
576 match field with
577 | DeclarationField
578 (FieldDeclList (onefield_multivars, iiptvirg)) ->
485bce71
C
579 vk_struct_fieldkinds bigf onefield_multivars;
580 iif iiptvirg;
708f4980 581 | EmptyField info -> iif [info]
ae4735db 582 | MacroDeclField ((s, args),ii) ->
708f4980
C
583 iif ii;
584 vk_argument_list bigf args;
485bce71 585
ae4735db 586 | CppDirectiveStruct directive ->
485bce71 587 vk_cpp_directive bigf directive
ae4735db 588 | IfdefStruct ifdef ->
485bce71 589 vk_ifdef_directive bigf ifdef
0708f913
C
590 in
591 f (k, bigf) field
485bce71 592
34e49164 593
ae4735db
C
594
595
596and vk_struct_fieldkinds = fun bigf onefield_multivars ->
34e49164
C
597 let iif ii = vk_ii bigf ii in
598 onefield_multivars +> List.iter (fun (field, iicomma) ->
599 iif iicomma;
600 match field with
ae4735db 601 | Simple (nameopt, t) ->
b1b2de81
C
602 Common.do_option (vk_name bigf) nameopt;
603 vk_type bigf t;
ae4735db 604 | BitField (nameopt, t, info, expr) ->
b1b2de81
C
605 Common.do_option (vk_name bigf) nameopt;
606 vk_info bigf info;
34e49164 607 vk_expr bigf expr;
ae4735db 608 vk_type bigf t
34e49164
C
609 )
610
c491d8ee
C
611
612and vk_enum_fields = fun bigf enumt ->
613 let iif ii = vk_ii bigf ii in
614 enumt +> List.iter (fun ((name, eopt), iicomma) ->
615 vk_oneEnum bigf (name, eopt);
616 iif iicomma)
617
618and vk_oneEnum = fun bigf (name, eopt) ->
619 let iif ii = vk_ii bigf ii in
620 vk_name bigf name;
621 eopt +> Common.do_option (fun (info, e) ->
622 iif [info];
623 vk_expr bigf e
624 )
625
485bce71 626(* ------------------------------------------------------------------------ *)
34e49164
C
627
628
ae4735db 629and vk_def = fun bigf d ->
34e49164
C
630 let iif ii = vk_ii bigf ii in
631
632 let f = bigf.kdef in
ae4735db 633 let rec k d =
34e49164 634 match d with
708f4980 635 | {f_name = name;
485bce71
C
636 f_type = (returnt, (paramst, (b, iib)));
637 f_storage = sto;
638 f_body = statxs;
639 f_attr = attrs;
91eba41f 640 f_old_c_style = oldstyle;
ae4735db
C
641 }, ii
642 ->
34e49164
C
643 iif ii;
644 iif iib;
485bce71 645 attrs +> List.iter (vk_attribute bigf);
34e49164 646 vk_type bigf returnt;
708f4980 647 vk_name bigf name;
ae4735db 648 paramst +> List.iter (fun (param,iicomma) ->
34e49164
C
649 vk_param bigf param;
650 iif iicomma;
651 );
ae4735db 652 oldstyle +> Common.do_option (fun decls ->
91eba41f
C
653 decls +> List.iter (vk_decl bigf);
654 );
655
485bce71 656 statxs +> List.iter (vk_statement_sequencable bigf)
ae4735db 657 in f (k, bigf) d
34e49164
C
658
659
660
661
ae4735db 662and vk_toplevel = fun bigf p ->
34e49164
C
663 let f = bigf.ktoplevel in
664 let iif ii = vk_ii bigf ii in
ae4735db 665 let rec k p =
34e49164
C
666 match p with
667 | Declaration decl -> (vk_decl bigf decl)
668 | Definition def -> (vk_def bigf def)
669 | EmptyDef ii -> iif ii
ae4735db 670 | MacroTop (s, xs, ii) ->
485bce71
C
671 vk_argument_list bigf xs;
672 iif ii
673
674 | CppTop top -> vk_cpp_directive bigf top
675 | IfdefTop ifdefdir -> vk_ifdef_directive bigf ifdefdir
ae4735db 676
485bce71
C
677 | NotParsedCorrectly ii -> iif ii
678 | FinalDef info -> vk_info bigf info
679 in f (k, bigf) p
680
ae4735db 681and vk_program = fun bigf xs ->
485bce71
C
682 xs +> List.iter (vk_toplevel bigf)
683
ae4735db 684and vk_ifdef_directive bigf directive =
485bce71
C
685 let iif ii = vk_ii bigf ii in
686 match directive with
687 | IfdefDirective (ifkind, ii) -> iif ii
688
689
690and vk_cpp_directive bigf directive =
691 let iif ii = vk_ii bigf ii in
692 let f = bigf.kcppdirective in
ae4735db 693 let rec k directive =
485bce71
C
694 match directive with
695 | Include {i_include = (s, ii);
696 i_content = copt;
697 }
ae4735db 698 ->
91eba41f
C
699 (* go inside ? yes, can be useful, for instance for type_annotater.
700 * The only pb may be that when we want to unparse the code we
ae4735db 701 * don't want to unparse the included file but the unparser
91eba41f
C
702 * and pretty_print do not use visitor_c so no problem.
703 *)
485bce71 704 iif ii;
ae4735db 705 copt +> Common.do_option (fun (file, asts) ->
485bce71
C
706 vk_program bigf asts
707 );
ae4735db 708 | Define ((s,ii), (defkind, defval)) ->
34e49164
C
709 iif ii;
710 vk_define_kind bigf defkind;
711 vk_define_val bigf defval
ae4735db 712 | PragmaAndCo (ii) ->
485bce71
C
713 iif ii
714 in f (k, bigf) directive
34e49164 715
34e49164 716
ae4735db 717and vk_define_kind bigf defkind =
34e49164
C
718 match defkind with
719 | DefineVar -> ()
ae4735db 720 | DefineFunc (params, ii) ->
34e49164 721 vk_ii bigf ii;
ae4735db 722 params +> List.iter (fun ((s,iis), iicomma) ->
34e49164
C
723 vk_ii bigf iis;
724 vk_ii bigf iicomma;
725 )
3a314143 726 | Undef -> ()
34e49164 727
ae4735db
C
728and vk_define_val bigf defval =
729 let f = bigf.kdefineval in
485bce71 730
ae4735db 731 let rec k defval =
34e49164 732 match defval with
ae4735db 733 | DefineExpr e ->
34e49164
C
734 vk_expr bigf e
735 | DefineStmt stmt -> vk_statement bigf stmt
ae4735db 736 | DefineDoWhileZero ((stmt, e), ii) ->
34e49164 737 vk_statement bigf stmt;
485bce71 738 vk_expr bigf e;
34e49164
C
739 vk_ii bigf ii
740 | DefineFunction def -> vk_def bigf def
741 | DefineType ty -> vk_type bigf ty
742 | DefineText (s, ii) -> vk_ii bigf ii
743 | DefineEmpty -> ()
485bce71
C
744 | DefineInit ini -> vk_ini bigf ini
745
ae4735db 746 | DefineTodo ->
91eba41f 747 pr2_once "DefineTodo";
485bce71
C
748 ()
749 in f (k, bigf) defval
34e49164 750
ae4735db
C
751
752
34e49164
C
753
754(* ------------------------------------------------------------------------ *)
ae4735db 755(* Now keep fullstatement inside the control flow node,
34e49164 756 * so that can then get in a MetaStmtVar the fullstatement to later
ae4735db 757 * pp back when the S is in a +. But that means that
34e49164
C
758 * Exp will match an Ifnode even if there is no such exp
759 * inside the condition of the Ifnode (because the exp may
760 * be deeper, in the then branch). So have to not visit
761 * all inside a node anymore.
ae4735db 762 *
485bce71 763 * update: j'ai choisi d'accrocher au noeud du CFG a la
ae4735db 764 * fois le fullstatement et le partialstatement et appeler le
34e49164
C
765 * visiteur que sur le partialstatement.
766 *)
767
ae4735db 768and vk_node = fun bigf node ->
34e49164
C
769 let iif ii = vk_ii bigf ii in
770 let infof info = vk_info bigf info in
771
772 let f = bigf.knode in
ae4735db 773 let rec k n =
34e49164
C
774 match F.unwrap n with
775
91eba41f
C
776 | F.FunHeader (def) ->
777 assert(null (fst def).f_body);
778 vk_def bigf def;
34e49164 779
ae4735db
C
780 | F.Decl decl -> vk_decl bigf decl
781 | F.ExprStatement (st, (eopt, ii)) ->
34e49164
C
782 iif ii;
783 eopt +> do_option (vk_expr bigf)
784
ae4735db 785 | F.IfHeader (_, (e,ii))
34e49164
C
786 | F.SwitchHeader (_, (e,ii))
787 | F.WhileHeader (_, (e,ii))
ae4735db 788 | F.DoWhileTail (e,ii) ->
34e49164
C
789 iif ii;
790 vk_expr bigf e
791
ae4735db 792 | F.ForHeader (_st, (((e1opt,i1), (e2opt,i2), (e3opt,i3)), ii)) ->
34e49164
C
793 iif i1; iif i2; iif i3;
794 iif ii;
795 e1opt +> do_option (vk_expr bigf);
796 e2opt +> do_option (vk_expr bigf);
797 e3opt +> do_option (vk_expr bigf);
ae4735db 798 | F.MacroIterHeader (_s, ((s,es), ii)) ->
34e49164 799 iif ii;
485bce71 800 vk_argument_list bigf es;
ae4735db 801
34e49164 802 | F.ReturnExpr (_st, (e,ii)) -> iif ii; vk_expr bigf e
ae4735db 803
34e49164 804 | F.Case (_st, (e,ii)) -> iif ii; vk_expr bigf e
ae4735db 805 | F.CaseRange (_st, ((e1, e2),ii)) ->
34e49164
C
806 iif ii; vk_expr bigf e1; vk_expr bigf e2
807
808
809 | F.CaseNode i -> ()
810
811 | F.DefineExpr e -> vk_expr bigf e
812 | F.DefineType ft -> vk_type bigf ft
ae4735db 813 | F.DefineHeader ((s,ii), (defkind)) ->
34e49164
C
814 iif ii;
815 vk_define_kind bigf defkind;
816
817 | F.DefineDoWhileZeroHeader (((),ii)) -> iif ii
ae4735db 818 | F.DefineTodo ->
91eba41f 819 pr2_once "DefineTodo";
485bce71
C
820 ()
821
485bce71 822 | F.Include {i_include = (s, ii);} -> iif ii;
34e49164 823
ae4735db 824 | F.MacroTop (s, args, ii) ->
34e49164 825 iif ii;
485bce71 826 vk_argument_list bigf args
34e49164 827
ae4735db
C
828 | F.IfdefHeader (info) -> vk_ifdef_directive bigf info
829 | F.IfdefElse (info) -> vk_ifdef_directive bigf info
830 | F.IfdefEndif (info) -> vk_ifdef_directive bigf info
34e49164
C
831
832 | F.Break (st,((),ii)) -> iif ii
833 | F.Continue (st,((),ii)) -> iif ii
834 | F.Default (st,((),ii)) -> iif ii
835 | F.Return (st,((),ii)) -> iif ii
b1b2de81
C
836 | F.Goto (st, name, ((),ii)) -> vk_name bigf name; iif ii
837 | F.Label (st, name, ((),ii)) -> vk_name bigf name; iif ii
485bce71 838
34e49164 839 | F.DoHeader (st, info) -> infof info
485bce71 840
34e49164 841 | F.Else info -> infof info
485bce71
C
842 | F.EndStatement iopt -> do_option infof iopt
843
34e49164
C
844 | F.SeqEnd (i, info) -> infof info
845 | F.SeqStart (st, i, info) -> infof info
846
847 | F.MacroStmt (st, ((),ii)) -> iif ii
ae4735db 848 | F.Asm (st, (asmbody,ii)) ->
34e49164
C
849 iif ii;
850 vk_asmbody bigf asmbody
851
852 | (
853 F.TopNode|F.EndNode|
951c7801
C
854 F.ErrorExit|F.Exit|F.Enter|F.LoopFallThroughNode|F.FallThroughNode|
855 F.AfterNode|F.FalseNode|F.TrueNode|F.InLoopNode|
34e49164
C
856 F.Fake
857 ) -> ()
858
859
860
861 in
862 f (k, bigf) node
863
864(* ------------------------------------------------------------------------ *)
ae4735db 865and vk_info = fun bigf info ->
34e49164
C
866 let rec infof ii = bigf.kinfo (k, bigf) ii
867 and k i = ()
868 in
869 infof info
870
ae4735db 871and vk_ii = fun bigf ii ->
34e49164
C
872 List.iter (vk_info bigf) ii
873
874
485bce71 875(* ------------------------------------------------------------------------ *)
ae4735db
C
876and vk_argument = fun bigf arg ->
877 let rec do_action = function
485bce71
C
878 | (ActMisc ii) -> vk_ii bigf ii
879 in
880 match arg with
881 | Left e -> (vk_expr bigf) e
882 | Right (ArgType param) -> vk_param bigf param
883 | Right (ArgAction action) -> do_action action
884
ae4735db 885and vk_argument_list = fun bigf es ->
485bce71 886 let iif ii = vk_ii bigf ii in
ae4735db 887 es +> List.iter (fun (e, ii) ->
485bce71
C
888 iif ii;
889 vk_argument bigf e
890 )
891
892
893
b1b2de81 894and vk_param = fun bigf param ->
34e49164 895 let iif ii = vk_ii bigf ii in
ae4735db 896 let f = bigf.kparam in
951c7801
C
897 let rec k param =
898 let {p_namei = swrapopt; p_register = (b, iib); p_type=ft} = param in
899 swrapopt +> Common.do_option (vk_name bigf);
900 iif iib;
901 vk_type bigf ft
902 in f (k, bigf) param
34e49164 903
ae4735db 904and vk_param_list = fun bigf ts ->
485bce71 905 let iif ii = vk_ii bigf ii in
ae4735db 906 ts +> List.iter (fun (param,iicomma) ->
485bce71
C
907 vk_param bigf param;
908 iif iicomma;
909 )
910
911
912
913(* ------------------------------------------------------------------------ *)
ae4735db 914and vk_asmbody = fun bigf (string_list, colon_list) ->
485bce71
C
915 let iif ii = vk_ii bigf ii in
916
917 iif string_list;
ae4735db 918 colon_list +> List.iter (fun (Colon xs, ii) ->
485bce71 919 iif ii;
ae4735db 920 xs +> List.iter (fun (x,iicomma) ->
485bce71
C
921 iif iicomma;
922 (match x with
ae4735db
C
923 | ColonMisc, ii -> iif ii
924 | ColonExpr e, ii ->
485bce71
C
925 vk_expr bigf e;
926 iif ii
927 )
928 ))
929
34e49164 930
485bce71 931(* ------------------------------------------------------------------------ *)
c491d8ee 932let vk_splitted element = fun bigf args_splitted ->
34e49164 933 let iif ii = vk_ii bigf ii in
ae4735db 934 args_splitted +> List.iter (function
c491d8ee 935 | Left arg -> element bigf arg
34e49164
C
936 | Right ii -> iif ii
937 )
938
c491d8ee
C
939let vk_args_splitted = vk_splitted vk_argument
940let vk_define_params_splitted = vk_splitted (fun bigf (_,ii) -> vk_ii bigf ii)
941let vk_params_splitted = vk_splitted vk_param
942let vk_enum_fields_splitted = vk_splitted vk_oneEnum
943let vk_inis_splitted = vk_splitted vk_ini
34e49164 944
485bce71 945(* ------------------------------------------------------------------------ *)
ae4735db 946let vk_cst = fun bigf (cst, ii) ->
34e49164
C
947 let iif ii = vk_ii bigf ii in
948 iif ii;
949 (match cst with
950 | Left cst -> ()
951 | Right s -> ()
952 )
953
954
ae4735db 955
34e49164
C
956
957(*****************************************************************************)
958(* "syntetisized attributes" style *)
959(*****************************************************************************)
485bce71
C
960
961(* TODO port the xxs_s to new cpp construct too *)
962
ae4735db 963type 'a inout = 'a -> 'a
34e49164 964
ae4735db 965(* _s for synthetizized attributes
34e49164
C
966 *
967 * Note that I don't visit necesserally in the order of the token
968 * found in the original file. So don't assume such hypothesis!
969 *)
ae4735db 970type visitor_c_s = {
34e49164
C
971 kexpr_s: (expression inout * visitor_c_s) -> expression inout;
972 kstatement_s: (statement inout * visitor_c_s) -> statement inout;
973 ktype_s: (fullType inout * visitor_c_s) -> fullType inout;
34e49164
C
974
975 kdecl_s: (declaration inout * visitor_c_s) -> declaration inout;
ae4735db 976 kdef_s: (definition inout * visitor_c_s) -> definition inout;
b1b2de81 977 kname_s: (name inout * visitor_c_s) -> name inout;
34e49164 978
ae4735db 979 kini_s: (initialiser inout * visitor_c_s) -> initialiser inout;
34e49164 980
485bce71 981 kcppdirective_s: (cpp_directive inout * visitor_c_s) -> cpp_directive inout;
34e49164 982 kdefineval_s: (define_val inout * visitor_c_s) -> define_val inout;
485bce71
C
983 kstatementseq_s: (statement_sequencable inout * visitor_c_s) -> statement_sequencable inout;
984 kstatementseq_list_s: (statement_sequencable list inout * visitor_c_s) -> statement_sequencable list inout;
985
986 knode_s: (F.node inout * visitor_c_s) -> F.node inout;
34e49164 987
485bce71
C
988
989 ktoplevel_s: (toplevel inout * visitor_c_s) -> toplevel inout;
34e49164 990 kinfo_s: (info inout * visitor_c_s) -> info inout;
ae4735db 991 }
34e49164 992
ae4735db 993let default_visitor_c_s =
34e49164
C
994 { kexpr_s = (fun (k,_) e -> k e);
995 kstatement_s = (fun (k,_) st -> k st);
996 ktype_s = (fun (k,_) t -> k t);
997 kdecl_s = (fun (k,_) d -> k d);
998 kdef_s = (fun (k,_) d -> k d);
b1b2de81 999 kname_s = (fun (k,_) x -> k x);
34e49164
C
1000 kini_s = (fun (k,_) d -> k d);
1001 ktoplevel_s = (fun (k,_) p -> k p);
1002 knode_s = (fun (k,_) n -> k n);
1003 kinfo_s = (fun (k,_) i -> k i);
1004 kdefineval_s = (fun (k,_) x -> k x);
485bce71
C
1005 kstatementseq_s = (fun (k,_) x -> k x);
1006 kstatementseq_list_s = (fun (k,_) x -> k x);
1007 kcppdirective_s = (fun (k,_) x -> k x);
ae4735db 1008 }
34e49164
C
1009
1010let rec vk_expr_s = fun bigf expr ->
1011 let iif ii = vk_ii_s bigf ii in
1012 let rec exprf e = bigf.kexpr_s (k, bigf) e
ae4735db 1013 and k e =
34e49164 1014 let ((unwrap_e, typ), ii) = e in
91eba41f 1015 (* !!! don't analyse optional type !!!
ae4735db 1016 * old: typ +> map_option (vk_type_s bigf) in
34e49164 1017 *)
ae4735db
C
1018 let typ' = typ in
1019 let e' =
34e49164 1020 match unwrap_e with
b1b2de81 1021 | Ident (name) -> Ident (vk_name_s bigf name)
34e49164 1022 | Constant (c) -> Constant (c)
ae4735db 1023 | FunCall (e, es) ->
34e49164 1024 FunCall (exprf e,
ae4735db 1025 es +> List.map (fun (e,ii) ->
34e49164
C
1026 vk_argument_s bigf e, iif ii
1027 ))
ae4735db 1028
faf9a90c 1029 | CondExpr (e1, e2, e3) -> CondExpr (exprf e1, fmap exprf e2, exprf e3)
34e49164
C
1030 | Sequence (e1, e2) -> Sequence (exprf e1, exprf e2)
1031 | Assignment (e1, op, e2) -> Assignment (exprf e1, op, exprf e2)
ae4735db 1032
34e49164
C
1033 | Postfix (e, op) -> Postfix (exprf e, op)
1034 | Infix (e, op) -> Infix (exprf e, op)
1035 | Unary (e, op) -> Unary (exprf e, op)
1036 | Binary (e1, op, e2) -> Binary (exprf e1, op, exprf e2)
ae4735db 1037
34e49164 1038 | ArrayAccess (e1, e2) -> ArrayAccess (exprf e1, exprf e2)
ae4735db
C
1039 | RecordAccess (e, name) ->
1040 RecordAccess (exprf e, vk_name_s bigf name)
1041 | RecordPtAccess (e, name) ->
1042 RecordPtAccess (exprf e, vk_name_s bigf name)
34e49164
C
1043
1044 | SizeOfExpr (e) -> SizeOfExpr (exprf e)
1045 | SizeOfType (t) -> SizeOfType (vk_type_s bigf t)
1046 | Cast (t, e) -> Cast (vk_type_s bigf t, exprf e)
1047
ae4735db 1048 | StatementExpr (statxs, is) ->
34e49164 1049 StatementExpr (
485bce71 1050 vk_statement_sequencable_list_s bigf statxs,
34e49164 1051 iif is)
ae4735db
C
1052 | Constructor (t, initxs) ->
1053 Constructor
1054 (vk_type_s bigf t,
1055 (initxs +> List.map (fun (ini, ii) ->
1056 vk_ini_s bigf ini, vk_ii_s bigf ii)
34e49164 1057 ))
ae4735db 1058
34e49164
C
1059 | ParenExpr (e) -> ParenExpr (exprf e)
1060
f59c9fb7 1061 | New t -> New (vk_argument_s bigf t)
4dfbc1c2 1062 | Delete e -> Delete (vk_expr_s bigf e)
f59c9fb7 1063
34e49164
C
1064 in
1065 (e', typ'), (iif ii)
1066 in exprf expr
1067
b1b2de81 1068
ae4735db 1069and vk_argument_s bigf argument =
34e49164 1070 let iif ii = vk_ii_s bigf ii in
ae4735db 1071 let rec do_action = function
34e49164
C
1072 | (ActMisc ii) -> ActMisc (iif ii)
1073 in
1074 (match argument with
1075 | Left e -> Left (vk_expr_s bigf e)
1076 | Right (ArgType param) -> Right (ArgType (vk_param_s bigf param))
1077 | Right (ArgAction action) -> Right (ArgAction (do_action action))
1078 )
1079
b1b2de81
C
1080(* ------------------------------------------------------------------------ *)
1081
34e49164 1082
ae4735db 1083and vk_name_s = fun bigf ident ->
b1b2de81 1084 let iif ii = vk_ii_s bigf ii in
ae4735db
C
1085 let rec namef x = bigf.kname_s (k,bigf) x
1086 and k id =
b1b2de81
C
1087 (match id with
1088 | RegularName (s,ii) -> RegularName (s, iif ii)
ae4735db
C
1089 | CppConcatenatedName xs ->
1090 CppConcatenatedName (xs +> List.map (fun ((x,ii1), ii2) ->
b1b2de81
C
1091 (x, iif ii1), iif ii2
1092 ))
1093 | CppVariadicName (s, ii) -> CppVariadicName (s, iif ii)
ae4735db 1094 | CppIdentBuilder ((s,iis), xs) ->
b1b2de81 1095 CppIdentBuilder ((s, iif iis),
ae4735db 1096 xs +> List.map (fun ((x,iix), iicomma) ->
b1b2de81
C
1097 ((x, iif iix), iif iicomma)))
1098 )
1099 in
1100 namef ident
34e49164 1101
b1b2de81 1102(* ------------------------------------------------------------------------ *)
34e49164
C
1103
1104
1105
ae4735db
C
1106and vk_statement_s = fun bigf st ->
1107 let rec statf st = bigf.kstatement_s (k, bigf) st
1108 and k st =
34e49164 1109 let (unwrap_st, ii) = st in
ae4735db 1110 let st' =
34e49164 1111 match unwrap_st with
ae4735db 1112 | Labeled (Label (name, st)) ->
708f4980 1113 Labeled (Label (vk_name_s bigf name, statf st))
ae4735db 1114 | Labeled (Case (e, st)) ->
34e49164 1115 Labeled (Case ((vk_expr_s bigf) e , statf st))
ae4735db
C
1116 | Labeled (CaseRange (e, e2, st)) ->
1117 Labeled (CaseRange ((vk_expr_s bigf) e,
1118 (vk_expr_s bigf) e2,
34e49164
C
1119 statf st))
1120 | Labeled (Default st) -> Labeled (Default (statf st))
ae4735db 1121 | Compound statxs ->
485bce71 1122 Compound (vk_statement_sequencable_list_s bigf statxs)
34e49164
C
1123 | ExprStatement (None) -> ExprStatement (None)
1124 | ExprStatement (Some e) -> ExprStatement (Some ((vk_expr_s bigf) e))
ae4735db 1125 | Selection (If (e, st1, st2)) ->
34e49164 1126 Selection (If ((vk_expr_s bigf) e, statf st1, statf st2))
ae4735db 1127 | Selection (Switch (e, st)) ->
34e49164 1128 Selection (Switch ((vk_expr_s bigf) e, statf st))
ae4735db 1129 | Iteration (While (e, st)) ->
34e49164 1130 Iteration (While ((vk_expr_s bigf) e, statf st))
ae4735db 1131 | Iteration (DoWhile (st, e)) ->
34e49164 1132 Iteration (DoWhile (statf st, (vk_expr_s bigf) e))
ae4735db 1133 | Iteration (For ((e1opt,i1), (e2opt,i2), (e3opt,i3), st)) ->
708f4980
C
1134 let e1opt' = statf (mk_st (ExprStatement (e1opt)) i1) in
1135 let e2opt' = statf (mk_st (ExprStatement (e2opt)) i2) in
1136 let e3opt' = statf (mk_st (ExprStatement (e3opt)) i3) in
1137
1138 let e1' = Ast_c.unwrap_st e1opt' in
1139 let e2' = Ast_c.unwrap_st e2opt' in
1140 let e3' = Ast_c.unwrap_st e3opt' in
1141 let i1' = Ast_c.get_ii_st_take_care e1opt' in
1142 let i2' = Ast_c.get_ii_st_take_care e2opt' in
1143 let i3' = Ast_c.get_ii_st_take_care e3opt' in
1144
1145 (match (e1', e2', e3') with
ae4735db 1146 | ((ExprStatement x1), (ExprStatement x2), ((ExprStatement x3))) ->
708f4980
C
1147 Iteration (For ((x1,i1'), (x2,i2'), (x3,i3'), statf st))
1148
34e49164
C
1149 | x -> failwith "cant be here if iterator keep ExprStatement as is"
1150 )
1151
ae4735db
C
1152 | Iteration (MacroIteration (s, es, st)) ->
1153 Iteration
34e49164
C
1154 (MacroIteration
1155 (s,
ae4735db 1156 es +> List.map (fun (e, ii) ->
34e49164 1157 vk_argument_s bigf e, vk_ii_s bigf ii
ae4735db 1158 ),
34e49164
C
1159 statf st
1160 ))
1161
ae4735db 1162
b1b2de81 1163 | Jump (Goto name) -> Jump (Goto (vk_name_s bigf name))
34e49164
C
1164 | Jump (((Continue|Break|Return) as x)) -> Jump (x)
1165 | Jump (ReturnExpr e) -> Jump (ReturnExpr ((vk_expr_s bigf) e))
1166 | Jump (GotoComputed e) -> Jump (GotoComputed (vk_expr_s bigf e));
1167
1168 | Decl decl -> Decl (vk_decl_s bigf decl)
1169 | Asm asmbody -> Asm (vk_asmbody_s bigf asmbody)
1170 | NestedFunc def -> NestedFunc (vk_def_s bigf def)
1171 | MacroStmt -> MacroStmt
1172 in
1173 st', vk_ii_s bigf ii
1174 in statf st
1175
485bce71 1176
ae4735db 1177and vk_statement_sequencable_s = fun bigf stseq ->
485bce71 1178 let f = bigf.kstatementseq_s in
ae4735db 1179 let k stseq =
485bce71
C
1180
1181 match stseq with
ae4735db 1182 | StmtElem st ->
485bce71 1183 StmtElem (vk_statement_s bigf st)
ae4735db 1184 | CppDirectiveStmt directive ->
485bce71 1185 CppDirectiveStmt (vk_cpp_directive_s bigf directive)
ae4735db 1186 | IfdefStmt ifdef ->
485bce71 1187 IfdefStmt (vk_ifdef_directive_s bigf ifdef)
ae4735db 1188 | IfdefStmt2 (ifdef, xxs) ->
485bce71 1189 let ifdef' = List.map (vk_ifdef_directive_s bigf) ifdef in
ae4735db 1190 let xxs' = xxs +> List.map (fun xs ->
b1b2de81 1191 xs +> vk_statement_sequencable_list_s bigf
485bce71
C
1192 )
1193 in
1194 IfdefStmt2(ifdef', xxs')
1195 in f (k, bigf) stseq
1196
ae4735db 1197and vk_statement_sequencable_list_s = fun bigf statxs ->
485bce71 1198 let f = bigf.kstatementseq_list_s in
ae4735db 1199 let k xs =
485bce71
C
1200 xs +> List.map (vk_statement_sequencable_s bigf)
1201 in
1202 f (k, bigf) statxs
485bce71
C
1203
1204
ae4735db
C
1205
1206and vk_asmbody_s = fun bigf (string_list, colon_list) ->
34e49164
C
1207 let iif ii = vk_ii_s bigf ii in
1208
1209 iif string_list,
ae4735db
C
1210 colon_list +> List.map (fun (Colon xs, ii) ->
1211 Colon
1212 (xs +> List.map (fun (x, iicomma) ->
34e49164 1213 (match x with
ae4735db 1214 | ColonMisc, ii -> ColonMisc, iif ii
34e49164
C
1215 | ColonExpr e, ii -> ColonExpr (vk_expr_s bigf e), iif ii
1216 ), iif iicomma
ae4735db
C
1217 )),
1218 iif ii
34e49164 1219 )
ae4735db
C
1220
1221
34e49164
C
1222
1223
0708f913 1224(* todo? a visitor for qualifier *)
ae4735db 1225and vk_type_s = fun bigf t ->
34e49164
C
1226 let rec typef t = bigf.ktype_s (k,bigf) t
1227 and iif ii = vk_ii_s bigf ii
ae4735db 1228 and k t =
34e49164
C
1229 let (q, t) = t in
1230 let (unwrap_q, iiq) = q in
faf9a90c
C
1231 (* strip_info_visitor needs iiq to be processed before iit *)
1232 let iif_iiq = iif iiq in
0708f913 1233 let q' = unwrap_q in
34e49164 1234 let (unwrap_t, iit) = t in
ae4735db 1235 let t' =
34e49164 1236 match unwrap_t with
f59c9fb7 1237 | NoType -> NoType
34e49164
C
1238 | BaseType x -> BaseType x
1239 | Pointer t -> Pointer (typef t)
ae4735db
C
1240 | Array (eopt, t) -> Array (fmap (vk_expr_s bigf) eopt, typef t)
1241 | FunctionType (returnt, paramst) ->
1242 FunctionType
1243 (typef returnt,
34e49164 1244 (match paramst with
ae4735db
C
1245 | (ts, (b, iihas3dots)) ->
1246 (ts +> List.map (fun (param,iicomma) ->
34e49164
C
1247 (vk_param_s bigf param, iif iicomma)),
1248 (b, iif iihas3dots))
1249 ))
1250
ae4735db 1251 | Enum (sopt, enumt) ->
c491d8ee 1252 Enum (sopt, vk_enum_fields_s bigf enumt)
ae4735db 1253 | StructUnion (sopt, su, fields) ->
34e49164
C
1254 StructUnion (sopt, su, vk_struct_fields_s bigf fields)
1255
1256
1257 | StructUnionName (s, structunion) -> StructUnionName (s, structunion)
1258 | EnumName s -> EnumName s
b1b2de81 1259 | TypeName (name, typ) -> TypeName (vk_name_s bigf name, typ)
34e49164
C
1260
1261 | ParenType t -> ParenType (typef t)
1262 | TypeOfExpr e -> TypeOfExpr (vk_expr_s bigf e)
1263 | TypeOfType t -> TypeOfType (typef t)
1264 in
ae4735db 1265 (q', iif_iiq),
faf9a90c 1266 (t', iif iit)
34e49164
C
1267
1268
1269 in typef t
1270
ae4735db 1271and vk_attribute_s = fun bigf attr ->
485bce71
C
1272 let iif ii = vk_ii_s bigf ii in
1273 match attr with
ae4735db 1274 | Attribute s, ii ->
485bce71
C
1275 Attribute s, iif ii
1276
1277
1278
ae4735db
C
1279and vk_decl_s = fun bigf d ->
1280 let f = bigf.kdecl_s in
34e49164 1281 let iif ii = vk_ii_s bigf ii in
ae4735db 1282 let rec k decl =
34e49164 1283 match decl with
ae4735db 1284 | DeclList (xs, ii) ->
34e49164 1285 DeclList (List.map aux xs, iif ii)
ae4735db
C
1286 | MacroDecl ((s, args),ii) ->
1287 MacroDecl
1288 ((s,
34e49164
C
1289 args +> List.map (fun (e,ii) -> vk_argument_s bigf e, iif ii)
1290 ),
1291 iif ii)
1292
1293
ae4735db
C
1294 and aux ({v_namei = var;
1295 v_type = t;
1296 v_type_bis = tbis;
1297 v_storage = sto;
1298 v_local= local;
1299 v_attr = attrs}, iicomma) =
1300 {v_namei =
1301 (var +> map_option (fun (name, iniopt) ->
1302 vk_name_s bigf name,
4dfbc1c2
C
1303 (match iniopt with
1304 Ast_c.NoInit -> iniopt
1305 | Ast_c.ValInit(iini,init) ->
1306 Ast_c.ValInit(vk_info_s bigf iini,vk_ini_s bigf init)
1307 | Ast_c.ConstrInit((init,ii)) ->
1308 let init =
1309 init +> List.map (fun (e,ii) -> vk_argument_s bigf e, iif ii) in
1310 Ast_c.ConstrInit((init, List.map (vk_info_s bigf) ii)))
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
413ffc02 1379and vk_struct_field_s = fun bigf field ->
34e49164
C
1380 let iif ii = vk_ii_s bigf ii in
1381
413ffc02
C
1382 match field with
1383 (DeclarationField (FieldDeclList (onefield_multivars, iiptvirg))) ->
1384 DeclarationField
1385 (FieldDeclList
1386 (vk_struct_fieldkinds_s bigf onefield_multivars, iif iiptvirg))
1387 | EmptyField info -> EmptyField (vk_info_s bigf info)
1388 | MacroDeclField ((s, args),ii) ->
1389 MacroDeclField
1390 ((s,
1391 args +> List.map (fun (e,ii) -> vk_argument_s bigf e, iif ii)
1392 ),
1393 iif ii)
1394
1395 | CppDirectiveStruct directive ->
1396 CppDirectiveStruct (vk_cpp_directive_s bigf directive)
1397 | IfdefStruct ifdef ->
1398 IfdefStruct (vk_ifdef_directive_s bigf ifdef)
485bce71 1399
413ffc02 1400and vk_struct_fields_s = fun bigf fields ->
413ffc02 1401 fields +> List.map (vk_struct_field_s bigf)
34e49164 1402
c491d8ee
C
1403and vk_enum_fields_s = fun bigf enumt ->
1404 let iif ii = vk_ii_s bigf ii in
1405 enumt +> List.map (fun ((name, eopt), iicomma) ->
1406 vk_oneEnum_s bigf (name, eopt), iif iicomma)
1407
1408and vk_oneEnum_s = fun bigf oneEnum ->
1409 let (name,eopt) = oneEnum in
1410 (vk_name_s bigf name,
1411 eopt +> Common.fmap (fun (info, e) ->
1412 vk_info_s bigf info,
1413 vk_expr_s bigf e
1414 ))
34e49164 1415
ae4735db 1416and vk_def_s = fun bigf d ->
34e49164
C
1417 let f = bigf.kdef_s in
1418 let iif ii = vk_ii_s bigf ii in
ae4735db 1419 let rec k d =
34e49164 1420 match d with
708f4980 1421 | {f_name = name;
485bce71
C
1422 f_type = (returnt, (paramst, (b, iib)));
1423 f_storage = sto;
1424 f_body = statxs;
1425 f_attr = attrs;
91eba41f 1426 f_old_c_style = oldstyle;
ae4735db
C
1427 }, ii
1428 ->
708f4980 1429 {f_name = vk_name_s bigf name;
ae4735db
C
1430 f_type =
1431 (vk_type_s bigf returnt,
485bce71
C
1432 (paramst +> List.map (fun (param, iicomma) ->
1433 (vk_param_s bigf param, iif iicomma)
1434 ), (b, iif iib)));
1435 f_storage = sto;
ae4735db 1436 f_body =
485bce71 1437 vk_statement_sequencable_list_s bigf statxs;
ae4735db 1438 f_attr =
91eba41f 1439 attrs +> List.map (vk_attribute_s bigf);
ae4735db
C
1440 f_old_c_style =
1441 oldstyle +> Common.map_option (fun decls ->
91eba41f
C
1442 decls +> List.map (vk_decl_s bigf)
1443 );
485bce71 1444 },
34e49164
C
1445 iif ii
1446
ae4735db 1447 in f (k, bigf) d
34e49164 1448
ae4735db 1449and vk_toplevel_s = fun bigf p ->
34e49164
C
1450 let f = bigf.ktoplevel_s in
1451 let iif ii = vk_ii_s bigf ii in
ae4735db 1452 let rec k p =
34e49164
C
1453 match p with
1454 | Declaration decl -> Declaration (vk_decl_s bigf decl)
1455 | Definition def -> Definition (vk_def_s bigf def)
1456 | EmptyDef ii -> EmptyDef (iif ii)
ae4735db 1457 | MacroTop (s, xs, ii) ->
34e49164 1458 MacroTop
ae4735db
C
1459 (s,
1460 xs +> List.map (fun (elem, iicomma) ->
34e49164
C
1461 vk_argument_s bigf elem, iif iicomma
1462 ),
1463 iif ii
1464 )
485bce71
C
1465 | CppTop top -> CppTop (vk_cpp_directive_s bigf top)
1466 | IfdefTop ifdefdir -> IfdefTop (vk_ifdef_directive_s bigf ifdefdir)
34e49164
C
1467
1468 | NotParsedCorrectly ii -> NotParsedCorrectly (iif ii)
1469 | FinalDef info -> FinalDef (vk_info_s bigf info)
1470 in f (k, bigf) p
1471
ae4735db 1472and vk_program_s = fun bigf xs ->
485bce71
C
1473 xs +> List.map (vk_toplevel_s bigf)
1474
1475
1476and vk_cpp_directive_s = fun bigf top ->
1477 let iif ii = vk_ii_s bigf ii in
1478 let f = bigf.kcppdirective_s in
ae4735db
C
1479 let rec k top =
1480 match top with
485bce71
C
1481 (* go inside ? *)
1482 | Include {i_include = (s, ii);
1483 i_rel_pos = h_rel_pos;
1484 i_is_in_ifdef = b;
1485 i_content = copt;
ae4735db 1486 }
485bce71
C
1487 -> Include {i_include = (s, iif ii);
1488 i_rel_pos = h_rel_pos;
1489 i_is_in_ifdef = b;
ae4735db 1490 i_content = copt +> Common.map_option (fun (file, asts) ->
485bce71
C
1491 file, vk_program_s bigf asts
1492 );
1493 }
ae4735db
C
1494 | Define ((s,ii), (defkind, defval)) ->
1495 Define ((s, iif ii),
485bce71 1496 (vk_define_kind_s bigf defkind, vk_define_val_s bigf defval))
485bce71
C
1497 | PragmaAndCo (ii) -> PragmaAndCo (iif ii)
1498
1499 in f (k, bigf) top
1500
ae4735db 1501and vk_ifdef_directive_s = fun bigf ifdef ->
485bce71
C
1502 let iif ii = vk_ii_s bigf ii in
1503 match ifdef with
1504 | IfdefDirective (ifkind, ii) -> IfdefDirective (ifkind, iif ii)
1505
1506
1507
ae4735db 1508and vk_define_kind_s = fun bigf defkind ->
34e49164 1509 match defkind with
ae4735db
C
1510 | DefineVar -> DefineVar
1511 | DefineFunc (params, ii) ->
1512 DefineFunc
1513 (params +> List.map (fun ((s,iis),iicomma) ->
34e49164
C
1514 ((s, vk_ii_s bigf iis), vk_ii_s bigf iicomma)
1515 ),
1516 vk_ii_s bigf ii
1517 )
3a314143 1518 | Undef -> Undef
34e49164
C
1519
1520
ae4735db 1521and vk_define_val_s = fun bigf x ->
34e49164
C
1522 let f = bigf.kdefineval_s in
1523 let iif ii = vk_ii_s bigf ii in
ae4735db 1524 let rec k x =
34e49164
C
1525 match x with
1526 | DefineExpr e -> DefineExpr (vk_expr_s bigf e)
1527 | DefineStmt st -> DefineStmt (vk_statement_s bigf st)
ae4735db 1528 | DefineDoWhileZero ((st,e),ii) ->
485bce71
C
1529 let st' = vk_statement_s bigf st in
1530 let e' = vk_expr_s bigf e in
1531 DefineDoWhileZero ((st',e'), iif ii)
34e49164
C
1532 | DefineFunction def -> DefineFunction (vk_def_s bigf def)
1533 | DefineType ty -> DefineType (vk_type_s bigf ty)
1534 | DefineText (s, ii) -> DefineText (s, iif ii)
1535 | DefineEmpty -> DefineEmpty
485bce71
C
1536 | DefineInit ini -> DefineInit (vk_ini_s bigf ini)
1537
ae4735db 1538 | DefineTodo ->
91eba41f 1539 pr2_once "DefineTodo";
485bce71 1540 DefineTodo
34e49164
C
1541 in
1542 f (k, bigf) x
34e49164 1543
ae4735db
C
1544
1545and vk_info_s = fun bigf info ->
34e49164
C
1546 let rec infof ii = bigf.kinfo_s (k, bigf) ii
1547 and k i = i
1548 in
1549 infof info
1550
ae4735db 1551and vk_ii_s = fun bigf ii ->
34e49164
C
1552 List.map (vk_info_s bigf) ii
1553
1554(* ------------------------------------------------------------------------ *)
ae4735db 1555and vk_node_s = fun bigf node ->
34e49164
C
1556 let iif ii = vk_ii_s bigf ii in
1557 let infof info = vk_info_s bigf info in
1558
1559 let rec nodef n = bigf.knode_s (k, bigf) n
ae4735db 1560 and k node =
34e49164
C
1561 F.rewrap node (
1562 match F.unwrap node with
ae4735db 1563 | F.FunHeader (def) ->
91eba41f
C
1564 assert (null (fst def).f_body);
1565 F.FunHeader (vk_def_s bigf def)
ae4735db 1566
34e49164 1567 | F.Decl declb -> F.Decl (vk_decl_s bigf declb)
ae4735db 1568 | F.ExprStatement (st, (eopt, ii)) ->
34e49164 1569 F.ExprStatement (st, (eopt +> map_option (vk_expr_s bigf), iif ii))
ae4735db
C
1570
1571 | F.IfHeader (st, (e,ii)) ->
34e49164 1572 F.IfHeader (st, (vk_expr_s bigf e, iif ii))
ae4735db 1573 | F.SwitchHeader (st, (e,ii)) ->
34e49164 1574 F.SwitchHeader(st, (vk_expr_s bigf e, iif ii))
ae4735db 1575 | F.WhileHeader (st, (e,ii)) ->
34e49164 1576 F.WhileHeader (st, (vk_expr_s bigf e, iif ii))
ae4735db 1577 | F.DoWhileTail (e,ii) ->
34e49164
C
1578 F.DoWhileTail (vk_expr_s bigf e, iif ii)
1579
ae4735db 1580 | F.ForHeader (st, (((e1opt,i1), (e2opt,i2), (e3opt,i3)), ii)) ->
34e49164
C
1581 F.ForHeader (st,
1582 (((e1opt +> Common.map_option (vk_expr_s bigf), iif i1),
1583 (e2opt +> Common.map_option (vk_expr_s bigf), iif i2),
1584 (e3opt +> Common.map_option (vk_expr_s bigf), iif i3)),
1585 iif ii))
1586
ae4735db 1587 | F.MacroIterHeader (st, ((s,es), ii)) ->
34e49164
C
1588 F.MacroIterHeader
1589 (st,
1590 ((s, es +> List.map (fun (e, ii) -> vk_argument_s bigf e, iif ii)),
1591 iif ii))
1592
ae4735db
C
1593
1594 | F.ReturnExpr (st, (e,ii)) ->
34e49164 1595 F.ReturnExpr (st, (vk_expr_s bigf e, iif ii))
ae4735db 1596
34e49164 1597 | F.Case (st, (e,ii)) -> F.Case (st, (vk_expr_s bigf e, iif ii))
ae4735db 1598 | F.CaseRange (st, ((e1, e2),ii)) ->
34e49164
C
1599 F.CaseRange (st, ((vk_expr_s bigf e1, vk_expr_s bigf e2), iif ii))
1600
1601 | F.CaseNode i -> F.CaseNode i
1602
ae4735db 1603 | F.DefineHeader((s,ii), (defkind)) ->
34e49164
C
1604 F.DefineHeader ((s, iif ii), (vk_define_kind_s bigf defkind))
1605
1606 | F.DefineExpr e -> F.DefineExpr (vk_expr_s bigf e)
1607 | F.DefineType ft -> F.DefineType (vk_type_s bigf ft)
ae4735db 1608 | F.DefineDoWhileZeroHeader ((),ii) ->
34e49164 1609 F.DefineDoWhileZeroHeader ((),iif ii)
485bce71
C
1610 | F.DefineTodo -> F.DefineTodo
1611
1612 | F.Include {i_include = (s, ii);
1613 i_rel_pos = h_rel_pos;
1614 i_is_in_ifdef = b;
1615 i_content = copt;
ae4735db
C
1616 }
1617 ->
b1b2de81 1618 assert (copt =*= None);
485bce71
C
1619 F.Include {i_include = (s, iif ii);
1620 i_rel_pos = h_rel_pos;
1621 i_is_in_ifdef = b;
1622 i_content = copt;
1623 }
34e49164 1624
ae4735db
C
1625 | F.MacroTop (s, args, ii) ->
1626 F.MacroTop
34e49164
C
1627 (s,
1628 args +> List.map (fun (e, ii) -> vk_argument_s bigf e, iif ii),
1629 iif ii)
1630
1631
1632 | F.MacroStmt (st, ((),ii)) -> F.MacroStmt (st, ((),iif ii))
1633 | F.Asm (st, (body,ii)) -> F.Asm (st, (vk_asmbody_s bigf body,iif ii))
1634
1635 | F.Break (st,((),ii)) -> F.Break (st,((),iif ii))
1636 | F.Continue (st,((),ii)) -> F.Continue (st,((),iif ii))
1637 | F.Default (st,((),ii)) -> F.Default (st,((),iif ii))
1638 | F.Return (st,((),ii)) -> F.Return (st,((),iif ii))
ae4735db 1639 | F.Goto (st, name, ((),ii)) ->
b1b2de81 1640 F.Goto (st, vk_name_s bigf name, ((),iif ii))
ae4735db 1641 | F.Label (st, name, ((),ii)) ->
b1b2de81 1642 F.Label (st, vk_name_s bigf name, ((),iif ii))
34e49164
C
1643 | F.EndStatement iopt -> F.EndStatement (map_option infof iopt)
1644 | F.DoHeader (st, info) -> F.DoHeader (st, infof info)
1645 | F.Else info -> F.Else (infof info)
1646 | F.SeqEnd (i, info) -> F.SeqEnd (i, infof info)
1647 | F.SeqStart (st, i, info) -> F.SeqStart (st, i, infof info)
1648
485bce71
C
1649 | F.IfdefHeader (info) -> F.IfdefHeader (vk_ifdef_directive_s bigf info)
1650 | F.IfdefElse (info) -> F.IfdefElse (vk_ifdef_directive_s bigf info)
1651 | F.IfdefEndif (info) -> F.IfdefEndif (vk_ifdef_directive_s bigf info)
1652
34e49164
C
1653 | (
1654 (
1655 F.TopNode|F.EndNode|
951c7801
C
1656 F.ErrorExit|F.Exit|F.Enter|F.LoopFallThroughNode|F.FallThroughNode|
1657 F.AfterNode|F.FalseNode|F.TrueNode|F.InLoopNode|
34e49164
C
1658 F.Fake
1659 ) as x) -> x
1660
1661
1662 )
1663 in
1664 nodef node
ae4735db 1665
34e49164 1666(* ------------------------------------------------------------------------ *)
ae4735db 1667and vk_param_s = fun bigf param ->
34e49164 1668 let iif ii = vk_ii_s bigf ii in
b1b2de81
C
1669 let {p_namei = swrapopt; p_register = (b, iib); p_type=ft} = param in
1670 { p_namei = swrapopt +> Common.map_option (vk_name_s bigf);
1671 p_register = (b, iif iib);
1672 p_type = vk_type_s bigf ft;
1673 }
faf9a90c 1674
ae4735db 1675let vk_arguments_s = fun bigf args ->
34e49164
C
1676 let iif ii = vk_ii_s bigf ii in
1677 args +> List.map (fun (e, ii) -> vk_argument_s bigf e, iif ii)
1678
ae4735db 1679let vk_params_s = fun bigf args ->
34e49164
C
1680 let iif ii = vk_ii_s bigf ii in
1681 args +> List.map (fun (p,ii) -> vk_param_s bigf p, iif ii)
1682
ae4735db 1683let vk_cst_s = fun bigf (cst, ii) ->
34e49164
C
1684 let iif ii = vk_ii_s bigf ii in
1685 (match cst with
ae4735db 1686 | Left cst -> Left cst
34e49164
C
1687 | Right s -> Right s
1688 ), iif ii
c491d8ee
C
1689
1690(* ------------------------------------------------------------------------ *)
1691
1692let vk_splitted_s element = fun bigf args_splitted ->
1693 let iif ii = vk_ii_s bigf ii in
1694 args_splitted +> List.map (function
1695 | Left arg -> Left (element bigf arg)
1696 | Right ii -> Right (iif ii)
1697 )
1698
1699let vk_args_splitted_s = vk_splitted_s vk_argument_s
1700let vk_params_splitted_s = vk_splitted_s vk_param_s
1701let vk_define_params_splitted_s =
1702 vk_splitted_s (fun bigf (s,ii) -> (s,vk_ii_s bigf ii))
1703let vk_enum_fields_splitted_s = vk_splitted_s vk_oneEnum_s
1704let vk_inis_splitted_s = vk_splitted_s vk_ini_s