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