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