Release coccinelle-0.1.3
[bpt/coccinelle.git] / parsing_cocci / .#visitor_ast.ml.1.89
1 (*
2 * Copyright 2005-2008, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
4 * This file is part of Coccinelle.
5 *
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
9 *
10 * Coccinelle 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 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
20 *)
21
22
23 module Ast = Ast_cocci
24
25 (* --------------------------------------------------------------------- *)
26 (* Generic traversal: combiner *)
27 (* parameters:
28 combining function
29 treatment of: mcode, identifiers, expressions, fullTypes, types,
30 declarations, statements, toplevels
31 default value for options *)
32
33 type 'a combiner =
34 {combiner_ident : Ast.ident -> 'a;
35 combiner_expression : Ast.expression -> 'a;
36 combiner_fullType : Ast.fullType -> 'a;
37 combiner_typeC : Ast.typeC -> 'a;
38 combiner_declaration : Ast.declaration -> 'a;
39 combiner_initialiser : Ast.initialiser -> 'a;
40 combiner_parameter : Ast.parameterTypeDef -> 'a;
41 combiner_parameter_list : Ast.parameter_list -> 'a;
42 combiner_rule_elem : Ast.rule_elem -> 'a;
43 combiner_statement : Ast.statement -> 'a;
44 combiner_case_line : Ast.case_line -> 'a;
45 combiner_top_level : Ast.top_level -> 'a;
46 combiner_anything : Ast.anything -> 'a;
47 combiner_expression_dots : Ast.expression Ast.dots -> 'a;
48 combiner_statement_dots : Ast.statement Ast.dots -> 'a;
49 combiner_declaration_dots : Ast.declaration Ast.dots -> 'a}
50
51 type ('mc,'a) cmcode = 'a combiner -> 'mc Ast_cocci.mcode -> 'a
52 type ('cd,'a) ccode = 'a combiner -> ('cd -> 'a) -> 'cd -> 'a
53
54
55 let combiner bind option_default
56 meta_mcodefn string_mcodefn const_mcodefn assign_mcodefn fix_mcodefn
57 unary_mcodefn binary_mcodefn
58 cv_mcodefn base_mcodefn sign_mcodefn struct_mcodefn storage_mcodefn
59 inc_file_mcodefn
60 expdotsfn paramdotsfn stmtdotsfn decldotsfn
61 identfn exprfn ftfn tyfn initfn paramfn declfn rulefn stmtfn casefn
62 topfn anyfn =
63 let multibind l =
64 let rec loop = function
65 [] -> option_default
66 | [x] -> x
67 | x::xs -> bind x (loop xs) in
68 loop l in
69 let get_option f = function
70 Some x -> f x
71 | None -> option_default in
72
73 let rec meta_mcode x = meta_mcodefn all_functions x
74 and string_mcode x = string_mcodefn all_functions x
75 and const_mcode x = const_mcodefn all_functions x
76 and assign_mcode x = assign_mcodefn all_functions x
77 and fix_mcode x = fix_mcodefn all_functions x
78 and unary_mcode x = unary_mcodefn all_functions x
79 and binary_mcode x = binary_mcodefn all_functions x
80 and cv_mcode x = cv_mcodefn all_functions x
81 and base_mcode x = base_mcodefn all_functions x
82 and sign_mcode x = sign_mcodefn all_functions x
83 and struct_mcode x = struct_mcodefn all_functions x
84 and storage_mcode x = storage_mcodefn all_functions x
85 and inc_file_mcode x = inc_file_mcodefn all_functions x
86
87 and expression_dots d =
88 let k d =
89 match Ast.unwrap d with
90 Ast.DOTS(l) | Ast.CIRCLES(l) | Ast.STARS(l) ->
91 multibind (List.map expression l) in
92 expdotsfn all_functions k d
93
94 and parameter_dots d =
95 let k d =
96 match Ast.unwrap d with
97 Ast.DOTS(l) | Ast.CIRCLES(l) | Ast.STARS(l) ->
98 multibind (List.map parameterTypeDef l) in
99 paramdotsfn all_functions k d
100
101 and statement_dots d =
102 let k d =
103 match Ast.unwrap d with
104 Ast.DOTS(l) | Ast.CIRCLES(l) | Ast.STARS(l) ->
105 multibind (List.map statement l) in
106 stmtdotsfn all_functions k d
107
108 and declaration_dots d =
109 let k d =
110 match Ast.unwrap d with
111 Ast.DOTS(l) | Ast.CIRCLES(l) | Ast.STARS(l) ->
112 multibind (List.map declaration l) in
113 decldotsfn all_functions k d
114
115 and ident i =
116 let k i =
117 match Ast.unwrap i with
118 Ast.Id(name) -> string_mcode name
119 | Ast.MetaId(name,_,_,_) -> meta_mcode name
120 | Ast.MetaFunc(name,_,_,_) -> meta_mcode name
121 | Ast.MetaLocalFunc(name,_,_,_) -> meta_mcode name
122 | Ast.OptIdent(id) -> ident id
123 | Ast.UniqueIdent(id) -> ident id in
124 identfn all_functions k i
125
126 and expression e =
127 let k e =
128 match Ast.unwrap e with
129 Ast.Ident(id) -> ident id
130 | Ast.Constant(const) -> const_mcode const
131 | Ast.FunCall(fn,lp,args,rp) ->
132 multibind [expression fn; string_mcode lp; expression_dots args;
133 string_mcode rp]
134 | Ast.Assignment(left,op,right,simple) ->
135 multibind [expression left; assign_mcode op; expression right]
136 | Ast.CondExpr(exp1,why,exp2,colon,exp3) ->
137 multibind [expression exp1; string_mcode why;
138 get_option expression exp2; string_mcode colon;
139 expression exp3]
140 | Ast.Postfix(exp,op) -> bind (expression exp) (fix_mcode op)
141 | Ast.Infix(exp,op) -> bind (fix_mcode op) (expression exp)
142 | Ast.Unary(exp,op) -> bind (unary_mcode op) (expression exp)
143 | Ast.Binary(left,op,right) ->
144 multibind [expression left; binary_mcode op; expression right]
145 | Ast.Nested(left,op,right) ->
146 multibind [expression left; binary_mcode op; expression right]
147 | Ast.Paren(lp,exp,rp) ->
148 multibind [string_mcode lp; expression exp; string_mcode rp]
149 | Ast.ArrayAccess(exp1,lb,exp2,rb) ->
150 multibind
151 [expression exp1; string_mcode lb; expression exp2;
152 string_mcode rb]
153 | Ast.RecordAccess(exp,pt,field) ->
154 multibind [expression exp; string_mcode pt; ident field]
155 | Ast.RecordPtAccess(exp,ar,field) ->
156 multibind [expression exp; string_mcode ar; ident field]
157 | Ast.Cast(lp,ty,rp,exp) ->
158 multibind
159 [string_mcode lp; fullType ty; string_mcode rp; expression exp]
160 | Ast.SizeOfExpr(szf,exp) ->
161 multibind [string_mcode szf; expression exp]
162 | Ast.SizeOfType(szf,lp,ty,rp) ->
163 multibind
164 [string_mcode szf; string_mcode lp; fullType ty; string_mcode rp]
165 | Ast.TypeExp(ty) -> fullType ty
166 | Ast.MetaErr(name,_,_,_)
167 | Ast.MetaExpr(name,_,_,_,_,_)
168 | Ast.MetaExprList(name,_,_,_) -> meta_mcode name
169 | Ast.EComma(cm) -> string_mcode cm
170 | Ast.DisjExpr(exp_list) -> multibind (List.map expression exp_list)
171 | Ast.NestExpr(expr_dots,whencode,multi) ->
172 bind (expression_dots expr_dots) (get_option expression whencode)
173 | Ast.Edots(dots,whencode) | Ast.Ecircles(dots,whencode)
174 | Ast.Estars(dots,whencode) ->
175 bind (string_mcode dots) (get_option expression whencode)
176 | Ast.OptExp(exp) | Ast.UniqueExp(exp) ->
177 expression exp in
178 exprfn all_functions k e
179
180 and fullType ft =
181 let k ft =
182 match Ast.unwrap ft with
183 Ast.Type(cv,ty) -> bind (get_option cv_mcode cv) (typeC ty)
184 | Ast.DisjType(types) -> multibind (List.map fullType types)
185 | Ast.OptType(ty) -> fullType ty
186 | Ast.UniqueType(ty) -> fullType ty in
187 ftfn all_functions k ft
188
189 and function_pointer (ty,lp1,star,rp1,lp2,params,rp2) extra =
190 (* have to put the treatment of the identifier into the right position *)
191 multibind
192 ([fullType ty; string_mcode lp1; string_mcode star] @ extra @
193 [string_mcode rp1;
194 string_mcode lp2; parameter_dots params; string_mcode rp2])
195
196 and function_type (ty,lp1,params,rp1) extra =
197 (* have to put the treatment of the identifier into the right position *)
198 multibind
199 ([get_option fullType ty] @ extra @
200 [string_mcode lp1; parameter_dots params; string_mcode rp1])
201
202 and array_type (ty,lb,size,rb) extra =
203 multibind
204 ([fullType ty] @ extra @
205 [string_mcode lb; get_option expression size; string_mcode rb])
206
207 and typeC ty =
208 let k ty =
209 match Ast.unwrap ty with
210 Ast.BaseType(ty,sgn) ->
211 bind (get_option sign_mcode sgn) (base_mcode ty)
212 | Ast.ImplicitInt(sgn) -> sign_mcode sgn
213 | Ast.Pointer(ty,star) ->
214 bind (fullType ty) (string_mcode star)
215 | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
216 function_pointer (ty,lp1,star,rp1,lp2,params,rp2) []
217 | Ast.FunctionType (_,ty,lp1,params,rp1) ->
218 function_type (ty,lp1,params,rp1) []
219 | Ast.Array(ty,lb,size,rb) -> array_type (ty,lb,size,rb) []
220 | Ast.StructUnionName(kind,name) ->
221 bind (struct_mcode kind) (get_option ident name)
222 | Ast.StructUnionDef(ty,lb,decls,rb) ->
223 multibind
224 [fullType ty; string_mcode lb; declaration_dots decls;
225 string_mcode rb]
226 | Ast.TypeName(name) -> string_mcode name
227 | Ast.MetaType(name,_,_) -> meta_mcode name in
228 tyfn all_functions k ty
229
230 and named_type ty id =
231 match Ast.unwrap ty with
232 Ast.Type(None,ty1) ->
233 (match Ast.unwrap ty1 with
234 Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
235 function_pointer (ty,lp1,star,rp1,lp2,params,rp2) [ident id]
236 | Ast.FunctionType(_,ty,lp1,params,rp1) ->
237 function_type (ty,lp1,params,rp1) [ident id]
238 | Ast.Array(ty,lb,size,rb) -> array_type (ty,lb,size,rb) [ident id]
239 | _ -> bind (fullType ty) (ident id))
240 | _ -> bind (fullType ty) (ident id)
241
242 and declaration d =
243 let k d =
244 match Ast.unwrap d with
245 Ast.Init(stg,ty,id,eq,ini,sem) ->
246 bind (get_option storage_mcode stg)
247 (bind (named_type ty id)
248 (multibind
249 [string_mcode eq; initialiser ini; string_mcode sem]))
250 | Ast.UnInit(stg,ty,id,sem) ->
251 bind (get_option storage_mcode stg)
252 (bind (named_type ty id) (string_mcode sem))
253 | Ast.MacroDecl(name,lp,args,rp,sem) ->
254 multibind
255 [ident name; string_mcode lp; expression_dots args;
256 string_mcode rp; string_mcode sem]
257 | Ast.TyDecl(ty,sem) -> bind (fullType ty) (string_mcode sem)
258 | Ast.Typedef(stg,ty,id,sem) ->
259 bind (string_mcode stg)
260 (bind (fullType ty) (bind (typeC id) (string_mcode sem)))
261 | Ast.DisjDecl(decls) -> multibind (List.map declaration decls)
262 | Ast.Ddots(dots,whencode) ->
263 bind (string_mcode dots) (get_option declaration whencode)
264 | Ast.MetaDecl(name,_,_) -> meta_mcode name
265 | Ast.OptDecl(decl) -> declaration decl
266 | Ast.UniqueDecl(decl) -> declaration decl in
267 declfn all_functions k d
268
269 and initialiser i =
270 let k i =
271 match Ast.unwrap i with
272 Ast.InitExpr(exp) -> expression exp
273 | Ast.InitList(lb,initlist,rb,whencode) ->
274 multibind
275 [string_mcode lb;
276 multibind (List.map initialiser initlist);
277 string_mcode rb;
278 multibind (List.map initialiser whencode)]
279 | Ast.InitGccDotName(dot,name,eq,ini) ->
280 multibind
281 [string_mcode dot; ident name; string_mcode eq; initialiser ini]
282 | Ast.InitGccName(name,eq,ini) ->
283 multibind [ident name; string_mcode eq; initialiser ini]
284 | Ast.InitGccIndex(lb,exp,rb,eq,ini) ->
285 multibind
286 [string_mcode lb; expression exp; string_mcode rb;
287 string_mcode eq; initialiser ini]
288 | Ast.InitGccRange(lb,exp1,dots,exp2,rb,eq,ini) ->
289 multibind
290 [string_mcode lb; expression exp1; string_mcode dots;
291 expression exp2; string_mcode rb; string_mcode eq;
292 initialiser ini]
293 | Ast.IComma(cm) -> string_mcode cm
294 | Ast.OptIni(i) -> initialiser i
295 | Ast.UniqueIni(i) -> initialiser i in
296 initfn all_functions k i
297
298 and parameterTypeDef p =
299 let k p =
300 match Ast.unwrap p with
301 Ast.VoidParam(ty) -> fullType ty
302 | Ast.Param(ty,Some id) -> named_type ty id
303 | Ast.Param(ty,None) -> fullType ty
304 | Ast.MetaParam(name,_,_) -> meta_mcode name
305 | Ast.MetaParamList(name,_,_,_) -> meta_mcode name
306 | Ast.PComma(cm) -> string_mcode cm
307 | Ast.Pdots(dots) -> string_mcode dots
308 | Ast.Pcircles(dots) -> string_mcode dots
309 | Ast.OptParam(param) -> parameterTypeDef param
310 | Ast.UniqueParam(param) -> parameterTypeDef param in
311 paramfn all_functions k p
312
313 and rule_elem re =
314 let k re =
315 match Ast.unwrap re with
316 Ast.FunHeader(_,_,fi,name,lp,params,rp) ->
317 multibind
318 ((List.map fninfo fi) @
319 [ident name;string_mcode lp;parameter_dots params;
320 string_mcode rp])
321 | Ast.Decl(_,_,decl) -> declaration decl
322 | Ast.SeqStart(brace) -> string_mcode brace
323 | Ast.SeqEnd(brace) -> string_mcode brace
324 | Ast.ExprStatement(exp,sem) ->
325 bind (expression exp) (string_mcode sem)
326 | Ast.IfHeader(iff,lp,exp,rp) ->
327 multibind [string_mcode iff; string_mcode lp; expression exp;
328 string_mcode rp]
329 | Ast.Else(els) -> string_mcode els
330 | Ast.WhileHeader(whl,lp,exp,rp) ->
331 multibind [string_mcode whl; string_mcode lp; expression exp;
332 string_mcode rp]
333 | Ast.DoHeader(d) -> string_mcode d
334 | Ast.WhileTail(whl,lp,exp,rp,sem) ->
335 multibind [string_mcode whl; string_mcode lp; expression exp;
336 string_mcode rp; string_mcode sem]
337 | Ast.ForHeader(fr,lp,e1,sem1,e2,sem2,e3,rp) ->
338 multibind [string_mcode fr; string_mcode lp;
339 get_option expression e1; string_mcode sem1;
340 get_option expression e2; string_mcode sem2;
341 get_option expression e3; string_mcode rp]
342 | Ast.IteratorHeader(nm,lp,args,rp) ->
343 multibind [ident nm; string_mcode lp;
344 expression_dots args; string_mcode rp]
345 | Ast.SwitchHeader(switch,lp,exp,rp) ->
346 multibind [string_mcode switch; string_mcode lp; expression exp;
347 string_mcode rp]
348 | Ast.Break(br,sem) -> bind (string_mcode br) (string_mcode sem)
349 | Ast.Continue(cont,sem) -> bind (string_mcode cont) (string_mcode sem)
350 | Ast.Label(l,dd) -> bind (ident l) (string_mcode dd)
351 | Ast.Goto(goto,l,sem) ->
352 bind (string_mcode goto) (bind (ident l) (string_mcode sem))
353 | Ast.Return(ret,sem) -> bind (string_mcode ret) (string_mcode sem)
354 | Ast.ReturnExpr(ret,exp,sem) ->
355 multibind [string_mcode ret; expression exp; string_mcode sem]
356 | Ast.MetaStmt(name,_,_,_) -> meta_mcode name
357 | Ast.MetaStmtList(name,_,_) -> meta_mcode name
358 | Ast.MetaRuleElem(name,_,_) -> meta_mcode name
359 | Ast.Exp(exp) -> expression exp
360 | Ast.TopExp(exp) -> expression exp
361 | Ast.Ty(ty) -> fullType ty
362 | Ast.Include(inc,name) -> bind (string_mcode inc) (inc_file_mcode name)
363 | Ast.DefineHeader(def,id,params) ->
364 multibind [string_mcode def; ident id; define_parameters params]
365 | Ast.Default(def,colon) -> bind (string_mcode def) (string_mcode colon)
366 | Ast.Case(case,exp,colon) ->
367 multibind [string_mcode case; expression exp; string_mcode colon]
368 | Ast.DisjRuleElem(res) -> multibind (List.map rule_elem res) in
369 rulefn all_functions k re
370
371 (* not parameterizable for now... *)
372 and define_parameters p =
373 let k p =
374 match Ast.unwrap p with
375 Ast.NoParams -> option_default
376 | Ast.DParams(lp,params,rp) ->
377 multibind
378 [string_mcode lp; define_param_dots params; string_mcode rp] in
379 k p
380
381 and define_param_dots d =
382 let k d =
383 match Ast.unwrap d with
384 Ast.DOTS(l) | Ast.CIRCLES(l) | Ast.STARS(l) ->
385 multibind (List.map define_param l) in
386 k d
387
388 and define_param p =
389 let k p =
390 match Ast.unwrap p with
391 Ast.DParam(id) -> ident id
392 | Ast.DPComma(comma) -> string_mcode comma
393 | Ast.DPdots(d) -> string_mcode d
394 | Ast.DPcircles(c) -> string_mcode c
395 | Ast.OptDParam(dp) -> define_param dp
396 | Ast.UniqueDParam(dp) -> define_param dp in
397 k p
398
399 (* discard the result, because the statement is assumed to be already
400 represented elsewhere in the code *)
401 and process_bef_aft s =
402 match Ast.get_dots_bef_aft s with
403 Ast.NoDots -> ()
404 | Ast.DroppingBetweenDots(stm,ind) -> let _ = statement stm in ()
405 | Ast.AddingBetweenDots(stm,ind) -> let _ = statement stm in ()
406
407 and statement s =
408 process_bef_aft s;
409 let k s =
410 match Ast.unwrap s with
411 Ast.Seq(lbrace,decls,body,rbrace) ->
412 multibind [rule_elem lbrace; statement_dots decls;
413 statement_dots body; rule_elem rbrace]
414 | Ast.IfThen(header,branch,_) ->
415 multibind [rule_elem header; statement branch]
416 | Ast.IfThenElse(header,branch1,els,branch2,_) ->
417 multibind [rule_elem header; statement branch1; rule_elem els;
418 statement branch2]
419 | Ast.While(header,body,_) ->
420 multibind [rule_elem header; statement body]
421 | Ast.Do(header,body,tail) ->
422 multibind [rule_elem header; statement body; rule_elem tail]
423 | Ast.For(header,body,_) -> multibind [rule_elem header; statement body]
424 | Ast.Iterator(header,body,_) ->
425 multibind [rule_elem header; statement body]
426 | Ast.Switch(header,lb,cases,rb) ->
427 multibind [rule_elem header;rule_elem lb;
428 multibind (List.map case_line cases);
429 rule_elem rb]
430 | Ast.Atomic(re) -> rule_elem re
431 | Ast.Disj(stmt_dots_list) ->
432 multibind (List.map statement_dots stmt_dots_list)
433 | Ast.Nest(stmt_dots,whn,_,_,_) ->
434 bind (statement_dots stmt_dots)
435 (multibind (List.map (whencode statement_dots statement) whn))
436 | Ast.FunDecl(header,lbrace,decls,body,rbrace) ->
437 multibind [rule_elem header; rule_elem lbrace;
438 statement_dots decls; statement_dots body;
439 rule_elem rbrace]
440 | Ast.Define(header,body) ->
441 bind (rule_elem header) (statement_dots body)
442 | Ast.Dots(d,whn,_,_) | Ast.Circles(d,whn,_,_) | Ast.Stars(d,whn,_,_) ->
443 bind (string_mcode d)
444 (multibind (List.map (whencode statement_dots statement) whn))
445 | Ast.OptStm(stmt) | Ast.UniqueStm(stmt) ->
446 statement stmt in
447 stmtfn all_functions k s
448
449 and fninfo = function
450 Ast.FStorage(stg) -> storage_mcode stg
451 | Ast.FType(ty) -> fullType ty
452 | Ast.FInline(inline) -> string_mcode inline
453 | Ast.FAttr(attr) -> string_mcode attr
454
455 and whencode notfn alwaysfn = function
456 Ast.WhenNot a -> notfn a
457 | Ast.WhenAlways a -> alwaysfn a
458 | Ast.WhenModifier(_) -> option_default
459
460 and case_line c =
461 let k c =
462 match Ast.unwrap c with
463 Ast.CaseLine(header,code) ->
464 bind (rule_elem header) (statement_dots code)
465 | Ast.OptCase(case) -> case_line case in
466 casefn all_functions k c
467
468 and top_level t =
469 let k t =
470 match Ast.unwrap t with
471 Ast.FILEINFO(old_file,new_file) ->
472 bind (string_mcode old_file) (string_mcode new_file)
473 | Ast.DECL(stmt) -> statement stmt
474 | Ast.CODE(stmt_dots) -> statement_dots stmt_dots
475 | Ast.ERRORWORDS(exps) -> multibind (List.map expression exps) in
476 topfn all_functions k t
477
478 and anything a =
479 let k = function
480 (*in many cases below, the thing is not even mcode, so we do nothing*)
481 Ast.FullTypeTag(ft) -> fullType ft
482 | Ast.BaseTypeTag(bt) -> option_default
483 | Ast.StructUnionTag(su) -> option_default
484 | Ast.SignTag(sgn) -> option_default
485 | Ast.IdentTag(id) -> ident id
486 | Ast.ExpressionTag(exp) -> expression exp
487 | Ast.ConstantTag(cst) -> option_default
488 | Ast.UnaryOpTag(unop) -> option_default
489 | Ast.AssignOpTag(asgnop) -> option_default
490 | Ast.FixOpTag(fixop) -> option_default
491 | Ast.BinaryOpTag(binop) -> option_default
492 | Ast.ArithOpTag(arithop) -> option_default
493 | Ast.LogicalOpTag(logop) -> option_default
494 | Ast.DeclarationTag(decl) -> declaration decl
495 | Ast.InitTag(ini) -> initialiser ini
496 | Ast.StorageTag(stg) -> option_default
497 | Ast.IncFileTag(stg) -> option_default
498 | Ast.Rule_elemTag(rule) -> rule_elem rule
499 | Ast.StatementTag(rule) -> statement rule
500 | Ast.CaseLineTag(case) -> case_line case
501 | Ast.ConstVolTag(cv) -> option_default
502 | Ast.Token(tok,info) -> option_default
503 | Ast.Code(cd) -> top_level cd
504 | Ast.ExprDotsTag(ed) -> expression_dots ed
505 | Ast.ParamDotsTag(pd) -> parameter_dots pd
506 | Ast.StmtDotsTag(sd) -> statement_dots sd
507 | Ast.DeclDotsTag(sd) -> declaration_dots sd
508 | Ast.TypeCTag(ty) -> typeC ty
509 | Ast.ParamTag(param) -> parameterTypeDef param
510 | Ast.SgrepStartTag(tok) -> option_default
511 | Ast.SgrepEndTag(tok) -> option_default in
512 anyfn all_functions k a
513
514 and all_functions =
515 {combiner_ident = ident;
516 combiner_expression = expression;
517 combiner_fullType = fullType;
518 combiner_typeC = typeC;
519 combiner_declaration = declaration;
520 combiner_initialiser = initialiser;
521 combiner_parameter = parameterTypeDef;
522 combiner_parameter_list = parameter_dots;
523 combiner_rule_elem = rule_elem;
524 combiner_statement = statement;
525 combiner_case_line = case_line;
526 combiner_top_level = top_level;
527 combiner_anything = anything;
528 combiner_expression_dots = expression_dots;
529 combiner_statement_dots = statement_dots;
530 combiner_declaration_dots = declaration_dots} in
531 all_functions
532
533 (* ---------------------------------------------------------------------- *)
534
535 type 'a inout = 'a -> 'a (* for specifying the type of rebuilder *)
536
537 type rebuilder =
538 {rebuilder_ident : Ast.ident inout;
539 rebuilder_expression : Ast.expression inout;
540 rebuilder_fullType : Ast.fullType inout;
541 rebuilder_typeC : Ast.typeC inout;
542 rebuilder_declaration : Ast.declaration inout;
543 rebuilder_initialiser : Ast.initialiser inout;
544 rebuilder_parameter : Ast.parameterTypeDef inout;
545 rebuilder_parameter_list : Ast.parameter_list inout;
546 rebuilder_statement : Ast.statement inout;
547 rebuilder_case_line : Ast.case_line inout;
548 rebuilder_rule_elem : Ast.rule_elem inout;
549 rebuilder_top_level : Ast.top_level inout;
550 rebuilder_expression_dots : Ast.expression Ast.dots inout;
551 rebuilder_statement_dots : Ast.statement Ast.dots inout;
552 rebuilder_declaration_dots : Ast.declaration Ast.dots inout;
553 rebuilder_define_param_dots : Ast.define_param Ast.dots inout;
554 rebuilder_define_param : Ast.define_param inout;
555 rebuilder_define_parameters : Ast.define_parameters inout;
556 rebuilder_anything : Ast.anything inout}
557
558 type 'mc rmcode = 'mc Ast.mcode inout
559 type 'cd rcode = rebuilder -> ('cd inout) -> 'cd inout
560
561
562 let rebuilder
563 meta_mcode string_mcode const_mcode assign_mcode fix_mcode unary_mcode
564 binary_mcode cv_mcode base_mcode sign_mcode struct_mcode storage_mcode
565 inc_file_mcode
566 expdotsfn paramdotsfn stmtdotsfn decldotsfn
567 identfn exprfn ftfn tyfn initfn paramfn declfn rulefn stmtfn casefn
568 topfn anyfn =
569 let get_option f = function
570 Some x -> Some (f x)
571 | None -> None in
572 let rec expression_dots d =
573 let k d =
574 Ast.rewrap d
575 (match Ast.unwrap d with
576 Ast.DOTS(l) -> Ast.DOTS(List.map expression l)
577 | Ast.CIRCLES(l) -> Ast.CIRCLES(List.map expression l)
578 | Ast.STARS(l) -> Ast.STARS(List.map expression l)) in
579 expdotsfn all_functions k d
580
581 and parameter_dots d =
582 let k d =
583 Ast.rewrap d
584 (match Ast.unwrap d with
585 Ast.DOTS(l) -> Ast.DOTS(List.map parameterTypeDef l)
586 | Ast.CIRCLES(l) -> Ast.CIRCLES(List.map parameterTypeDef l)
587 | Ast.STARS(l) -> Ast.STARS(List.map parameterTypeDef l)) in
588 paramdotsfn all_functions k d
589
590 and statement_dots d =
591 let k d =
592 Ast.rewrap d
593 (match Ast.unwrap d with
594 Ast.DOTS(l) -> Ast.DOTS(List.map statement l)
595 | Ast.CIRCLES(l) -> Ast.CIRCLES(List.map statement l)
596 | Ast.STARS(l) -> Ast.STARS(List.map statement l)) in
597 stmtdotsfn all_functions k d
598
599 and declaration_dots d =
600 let k d =
601 Ast.rewrap d
602 (match Ast.unwrap d with
603 Ast.DOTS(l) -> Ast.DOTS(List.map declaration l)
604 | Ast.CIRCLES(l) -> Ast.CIRCLES(List.map declaration l)
605 | Ast.STARS(l) -> Ast.STARS(List.map declaration l)) in
606 decldotsfn all_functions k d
607
608 and ident i =
609 let k i =
610 Ast.rewrap i
611 (match Ast.unwrap i with
612 Ast.Id(name) -> Ast.Id(string_mcode name)
613 | Ast.MetaId(name,constraints,keep,inherited) ->
614 Ast.MetaId(meta_mcode name,constraints,keep,inherited)
615 | Ast.MetaFunc(name,constraints,keep,inherited) ->
616 Ast.MetaFunc(meta_mcode name,constraints,keep,inherited)
617 | Ast.MetaLocalFunc(name,constraints,keep,inherited) ->
618 Ast.MetaLocalFunc(meta_mcode name,constraints,keep,inherited)
619 | Ast.OptIdent(id) -> Ast.OptIdent(ident id)
620 | Ast.UniqueIdent(id) -> Ast.UniqueIdent(ident id)) in
621 identfn all_functions k i
622
623 and expression e =
624 let k e =
625 Ast.rewrap e
626 (match Ast.unwrap e with
627 Ast.Ident(id) -> Ast.Ident(ident id)
628 | Ast.Constant(const) -> Ast.Constant(const_mcode const)
629 | Ast.FunCall(fn,lp,args,rp) ->
630 Ast.FunCall(expression fn, string_mcode lp, expression_dots args,
631 string_mcode rp)
632 | Ast.Assignment(left,op,right,simple) ->
633 Ast.Assignment(expression left, assign_mcode op, expression right,
634 simple)
635 | Ast.CondExpr(exp1,why,exp2,colon,exp3) ->
636 Ast.CondExpr(expression exp1, string_mcode why,
637 get_option expression exp2, string_mcode colon,
638 expression exp3)
639 | Ast.Postfix(exp,op) -> Ast.Postfix(expression exp,fix_mcode op)
640 | Ast.Infix(exp,op) -> Ast.Infix(expression exp,fix_mcode op)
641 | Ast.Unary(exp,op) -> Ast.Unary(expression exp,unary_mcode op)
642 | Ast.Binary(left,op,right) ->
643 Ast.Binary(expression left, binary_mcode op, expression right)
644 | Ast.Nested(left,op,right) ->
645 Ast.Nested(expression left, binary_mcode op, expression right)
646 | Ast.Paren(lp,exp,rp) ->
647 Ast.Paren(string_mcode lp, expression exp, string_mcode rp)
648 | Ast.ArrayAccess(exp1,lb,exp2,rb) ->
649 Ast.ArrayAccess(expression exp1, string_mcode lb, expression exp2,
650 string_mcode rb)
651 | Ast.RecordAccess(exp,pt,field) ->
652 Ast.RecordAccess(expression exp, string_mcode pt, ident field)
653 | Ast.RecordPtAccess(exp,ar,field) ->
654 Ast.RecordPtAccess(expression exp, string_mcode ar, ident field)
655 | Ast.Cast(lp,ty,rp,exp) ->
656 Ast.Cast(string_mcode lp, fullType ty, string_mcode rp,
657 expression exp)
658 | Ast.SizeOfExpr(szf,exp) ->
659 Ast.SizeOfExpr(string_mcode szf, expression exp)
660 | Ast.SizeOfType(szf,lp,ty,rp) ->
661 Ast.SizeOfType(string_mcode szf,string_mcode lp, fullType ty,
662 string_mcode rp)
663 | Ast.TypeExp(ty) -> Ast.TypeExp(fullType ty)
664 | Ast.MetaErr(name,constraints,keep,inherited) ->
665 Ast.MetaErr(meta_mcode name,constraints,keep,inherited)
666 | Ast.MetaExpr(name,constraints,keep,ty,form,inherited) ->
667 Ast.MetaExpr(meta_mcode name,constraints,keep,ty,form,inherited)
668 | Ast.MetaExprList(name,lenname_inh,keep,inherited) ->
669 Ast.MetaExprList(meta_mcode name,lenname_inh,keep,inherited)
670 | Ast.EComma(cm) -> Ast.EComma(string_mcode cm)
671 | Ast.DisjExpr(exp_list) -> Ast.DisjExpr(List.map expression exp_list)
672 | Ast.NestExpr(expr_dots,whencode,multi) ->
673 Ast.NestExpr(expression_dots expr_dots,
674 get_option expression whencode,multi)
675 | Ast.Edots(dots,whencode) ->
676 Ast.Edots(string_mcode dots,get_option expression whencode)
677 | Ast.Ecircles(dots,whencode) ->
678 Ast.Ecircles(string_mcode dots,get_option expression whencode)
679 | Ast.Estars(dots,whencode) ->
680 Ast.Estars(string_mcode dots,get_option expression whencode)
681 | Ast.OptExp(exp) -> Ast.OptExp(expression exp)
682 | Ast.UniqueExp(exp) -> Ast.UniqueExp(expression exp)) in
683 exprfn all_functions k e
684
685 and fullType ft =
686 let k ft =
687 Ast.rewrap ft
688 (match Ast.unwrap ft with
689 Ast.Type(cv,ty) -> Ast.Type (get_option cv_mcode cv, typeC ty)
690 | Ast.DisjType(types) -> Ast.DisjType(List.map fullType types)
691 | Ast.OptType(ty) -> Ast.OptType(fullType ty)
692 | Ast.UniqueType(ty) -> Ast.UniqueType(fullType ty)) in
693 ftfn all_functions k ft
694
695 and typeC ty =
696 let k ty =
697 Ast.rewrap ty
698 (match Ast.unwrap ty with
699 Ast.BaseType(ty,sgn) ->
700 Ast.BaseType (base_mcode ty,get_option sign_mcode sgn)
701 | Ast.ImplicitInt(sgn) -> Ast.ImplicitInt (sign_mcode sgn)
702 | Ast.Pointer(ty,star) ->
703 Ast.Pointer (fullType ty, string_mcode star)
704 | Ast.FunctionPointer(ty,lp1,star,rp1,lp2,params,rp2) ->
705 Ast.FunctionPointer(fullType ty,string_mcode lp1,string_mcode star,
706 string_mcode rp1,string_mcode lp2,
707 parameter_dots params,
708 string_mcode rp2)
709 | Ast.FunctionType(allminus,ty,lp,params,rp) ->
710 Ast.FunctionType(allminus,get_option fullType ty,string_mcode lp,
711 parameter_dots params,string_mcode rp)
712 | Ast.Array(ty,lb,size,rb) ->
713 Ast.Array(fullType ty, string_mcode lb,
714 get_option expression size, string_mcode rb)
715 | Ast.StructUnionName(kind,name) ->
716 Ast.StructUnionName (struct_mcode kind, get_option ident name)
717 | Ast.StructUnionDef(ty,lb,decls,rb) ->
718 Ast.StructUnionDef (fullType ty,
719 string_mcode lb, declaration_dots decls,
720 string_mcode rb)
721 | Ast.TypeName(name) -> Ast.TypeName(string_mcode name)
722 | Ast.MetaType(name,keep,inherited) ->
723 Ast.MetaType(meta_mcode name,keep,inherited)) in
724 tyfn all_functions k ty
725
726 and declaration d =
727 let k d =
728 Ast.rewrap d
729 (match Ast.unwrap d with
730 Ast.Init(stg,ty,id,eq,ini,sem) ->
731 Ast.Init(get_option storage_mcode stg, fullType ty, ident id,
732 string_mcode eq, initialiser ini, string_mcode sem)
733 | Ast.UnInit(stg,ty,id,sem) ->
734 Ast.UnInit(get_option storage_mcode stg, fullType ty, ident id,
735 string_mcode sem)
736 | Ast.MacroDecl(name,lp,args,rp,sem) ->
737 Ast.MacroDecl(ident name, string_mcode lp, expression_dots args,
738 string_mcode rp,string_mcode sem)
739 | Ast.TyDecl(ty,sem) -> Ast.TyDecl(fullType ty, string_mcode sem)
740 | Ast.Typedef(stg,ty,id,sem) ->
741 Ast.Typedef(string_mcode stg, fullType ty, typeC id,
742 string_mcode sem)
743 | Ast.DisjDecl(decls) -> Ast.DisjDecl(List.map declaration decls)
744 | Ast.Ddots(dots,whencode) ->
745 Ast.Ddots(string_mcode dots, get_option declaration whencode)
746 | Ast.MetaDecl(name,keep,inherited) ->
747 Ast.MetaDecl(meta_mcode name,keep,inherited)
748 | Ast.OptDecl(decl) -> Ast.OptDecl(declaration decl)
749 | Ast.UniqueDecl(decl) -> Ast.UniqueDecl(declaration decl)) in
750 declfn all_functions k d
751
752 and initialiser i =
753 let k i =
754 Ast.rewrap i
755 (match Ast.unwrap i with
756 Ast.InitExpr(exp) -> Ast.InitExpr(expression exp)
757 | Ast.InitList(lb,initlist,rb,whencode) ->
758 Ast.InitList(string_mcode lb, List.map initialiser initlist,
759 string_mcode rb, List.map initialiser whencode)
760 | Ast.InitGccDotName(dot,name,eq,ini) ->
761 Ast.InitGccDotName
762 (string_mcode dot, ident name, string_mcode eq, initialiser ini)
763 | Ast.InitGccName(name,eq,ini) ->
764 Ast.InitGccName(ident name, string_mcode eq, initialiser ini)
765 | Ast.InitGccIndex(lb,exp,rb,eq,ini) ->
766 Ast.InitGccIndex
767 (string_mcode lb, expression exp, string_mcode rb,
768 string_mcode eq, initialiser ini)
769 | Ast.InitGccRange(lb,exp1,dots,exp2,rb,eq,ini) ->
770 Ast.InitGccRange
771 (string_mcode lb, expression exp1, string_mcode dots,
772 expression exp2, string_mcode rb, string_mcode eq,
773 initialiser ini)
774 | Ast.IComma(cm) -> Ast.IComma(string_mcode cm)
775 | Ast.OptIni(i) -> Ast.OptIni(initialiser i)
776 | Ast.UniqueIni(i) -> Ast.UniqueIni(initialiser i)) in
777 initfn all_functions k i
778
779 and parameterTypeDef p =
780 let k p =
781 Ast.rewrap p
782 (match Ast.unwrap p with
783 Ast.VoidParam(ty) -> Ast.VoidParam(fullType ty)
784 | Ast.Param(ty,id) -> Ast.Param(fullType ty, get_option ident id)
785 | Ast.MetaParam(name,keep,inherited) ->
786 Ast.MetaParam(meta_mcode name,keep,inherited)
787 | Ast.MetaParamList(name,lenname_inh,keep,inherited) ->
788 Ast.MetaParamList(meta_mcode name,lenname_inh,keep,inherited)
789 | Ast.PComma(cm) -> Ast.PComma(string_mcode cm)
790 | Ast.Pdots(dots) -> Ast.Pdots(string_mcode dots)
791 | Ast.Pcircles(dots) -> Ast.Pcircles(string_mcode dots)
792 | Ast.OptParam(param) -> Ast.OptParam(parameterTypeDef param)
793 | Ast.UniqueParam(param) -> Ast.UniqueParam(parameterTypeDef param)) in
794 paramfn all_functions k p
795
796 and rule_elem re =
797 let k re =
798 Ast.rewrap re
799 (match Ast.unwrap re with
800 Ast.FunHeader(bef,allminus,fi,name,lp,params,rp) ->
801 Ast.FunHeader(bef,allminus,List.map fninfo fi,ident name,
802 string_mcode lp, parameter_dots params,
803 string_mcode rp)
804 | Ast.Decl(bef,allminus,decl) ->
805 Ast.Decl(bef,allminus,declaration decl)
806 | Ast.SeqStart(brace) -> Ast.SeqStart(string_mcode brace)
807 | Ast.SeqEnd(brace) -> Ast.SeqEnd(string_mcode brace)
808 | Ast.ExprStatement(exp,sem) ->
809 Ast.ExprStatement (expression exp, string_mcode sem)
810 | Ast.IfHeader(iff,lp,exp,rp) ->
811 Ast.IfHeader(string_mcode iff, string_mcode lp, expression exp,
812 string_mcode rp)
813 | Ast.Else(els) -> Ast.Else(string_mcode els)
814 | Ast.WhileHeader(whl,lp,exp,rp) ->
815 Ast.WhileHeader(string_mcode whl, string_mcode lp, expression exp,
816 string_mcode rp)
817 | Ast.DoHeader(d) -> Ast.DoHeader(string_mcode d)
818 | Ast.WhileTail(whl,lp,exp,rp,sem) ->
819 Ast.WhileTail(string_mcode whl, string_mcode lp, expression exp,
820 string_mcode rp, string_mcode sem)
821 | Ast.ForHeader(fr,lp,e1,sem1,e2,sem2,e3,rp) ->
822 Ast.ForHeader(string_mcode fr, string_mcode lp,
823 get_option expression e1, string_mcode sem1,
824 get_option expression e2, string_mcode sem2,
825 get_option expression e3, string_mcode rp)
826 | Ast.IteratorHeader(whl,lp,args,rp) ->
827 Ast.IteratorHeader(ident whl, string_mcode lp,
828 expression_dots args, string_mcode rp)
829 | Ast.SwitchHeader(switch,lp,exp,rp) ->
830 Ast.SwitchHeader(string_mcode switch, string_mcode lp,
831 expression exp, string_mcode rp)
832 | Ast.Break(br,sem) ->
833 Ast.Break(string_mcode br, string_mcode sem)
834 | Ast.Continue(cont,sem) ->
835 Ast.Continue(string_mcode cont, string_mcode sem)
836 | Ast.Label(l,dd) -> Ast.Label(ident l, string_mcode dd)
837 | Ast.Goto(goto,l,sem) ->
838 Ast.Goto(string_mcode goto,ident l,string_mcode sem)
839 | Ast.Return(ret,sem) ->
840 Ast.Return(string_mcode ret, string_mcode sem)
841 | Ast.ReturnExpr(ret,exp,sem) ->
842 Ast.ReturnExpr(string_mcode ret, expression exp, string_mcode sem)
843 | Ast.MetaStmt(name,keep,seqible,inherited) ->
844 Ast.MetaStmt(meta_mcode name,keep,seqible,inherited)
845 | Ast.MetaStmtList(name,keep,inherited) ->
846 Ast.MetaStmtList(meta_mcode name,keep,inherited)
847 | Ast.MetaRuleElem(name,keep,inherited) ->
848 Ast.MetaRuleElem(meta_mcode name,keep,inherited)
849 | Ast.Exp(exp) -> Ast.Exp(expression exp)
850 | Ast.TopExp(exp) -> Ast.TopExp(expression exp)
851 | Ast.Ty(ty) -> Ast.Ty(fullType ty)
852 | Ast.Include(inc,name) ->
853 Ast.Include(string_mcode inc,inc_file_mcode name)
854 | Ast.DefineHeader(def,id,params) ->
855 Ast.DefineHeader(string_mcode def,ident id,
856 define_parameters params)
857 | Ast.Default(def,colon) ->
858 Ast.Default(string_mcode def,string_mcode colon)
859 | Ast.Case(case,exp,colon) ->
860 Ast.Case(string_mcode case,expression exp,string_mcode colon)
861 | Ast.DisjRuleElem(res) -> Ast.DisjRuleElem(List.map rule_elem res)) in
862 rulefn all_functions k re
863
864 (* not parameterizable for now... *)
865 and define_parameters p =
866 let k p =
867 Ast.rewrap p
868 (match Ast.unwrap p with
869 Ast.NoParams -> Ast.NoParams
870 | Ast.DParams(lp,params,rp) ->
871 Ast.DParams(string_mcode lp,define_param_dots params,
872 string_mcode rp)) in
873 k p
874
875 and define_param_dots d =
876 let k d =
877 Ast.rewrap d
878 (match Ast.unwrap d with
879 Ast.DOTS(l) -> Ast.DOTS(List.map define_param l)
880 | Ast.CIRCLES(l) -> Ast.CIRCLES(List.map define_param l)
881 | Ast.STARS(l) -> Ast.STARS(List.map define_param l)) in
882 k d
883
884 and define_param p =
885 let k p =
886 Ast.rewrap p
887 (match Ast.unwrap p with
888 Ast.DParam(id) -> Ast.DParam(ident id)
889 | Ast.DPComma(comma) -> Ast.DPComma(string_mcode comma)
890 | Ast.DPdots(d) -> Ast.DPdots(string_mcode d)
891 | Ast.DPcircles(c) -> Ast.DPcircles(string_mcode c)
892 | Ast.OptDParam(dp) -> Ast.OptDParam(define_param dp)
893 | Ast.UniqueDParam(dp) -> Ast.UniqueDParam(define_param dp)) in
894 k p
895
896 and process_bef_aft s =
897 Ast.set_dots_bef_aft
898 (match Ast.get_dots_bef_aft s with
899 Ast.NoDots -> Ast.NoDots
900 | Ast.DroppingBetweenDots(stm,ind) ->
901 Ast.DroppingBetweenDots(statement stm,ind)
902 | Ast.AddingBetweenDots(stm,ind) ->
903 Ast.AddingBetweenDots(statement stm,ind))
904 s
905
906 and statement s =
907 let k s =
908 Ast.rewrap s
909 (match Ast.unwrap s with
910 Ast.Seq(lbrace,decls,body,rbrace) ->
911 Ast.Seq(rule_elem lbrace, statement_dots decls,
912 statement_dots body, rule_elem rbrace)
913 | Ast.IfThen(header,branch,aft) ->
914 Ast.IfThen(rule_elem header, statement branch,aft)
915 | Ast.IfThenElse(header,branch1,els,branch2,aft) ->
916 Ast.IfThenElse(rule_elem header, statement branch1, rule_elem els,
917 statement branch2, aft)
918 | Ast.While(header,body,aft) ->
919 Ast.While(rule_elem header, statement body, aft)
920 | Ast.Do(header,body,tail) ->
921 Ast.Do(rule_elem header, statement body, rule_elem tail)
922 | Ast.For(header,body,aft) ->
923 Ast.For(rule_elem header, statement body, aft)
924 | Ast.Iterator(header,body,aft) ->
925 Ast.Iterator(rule_elem header, statement body, aft)
926 | Ast.Switch(header,lb,cases,rb) ->
927 Ast.Switch(rule_elem header,rule_elem lb,
928 List.map case_line cases,rule_elem rb)
929 | Ast.Atomic(re) -> Ast.Atomic(rule_elem re)
930 | Ast.Disj(stmt_dots_list) ->
931 Ast.Disj (List.map statement_dots stmt_dots_list)
932 | Ast.Nest(stmt_dots,whn,multi,bef,aft) ->
933 Ast.Nest(statement_dots stmt_dots,
934 List.map (whencode statement_dots statement) whn,
935 multi,bef,aft)
936 | Ast.FunDecl(header,lbrace,decls,body,rbrace) ->
937 Ast.FunDecl(rule_elem header,rule_elem lbrace,
938 statement_dots decls,
939 statement_dots body, rule_elem rbrace)
940 | Ast.Define(header,body) ->
941 Ast.Define(rule_elem header,statement_dots body)
942 | Ast.Dots(d,whn,bef,aft) ->
943 Ast.Dots(string_mcode d,
944 List.map (whencode statement_dots statement) whn,bef,aft)
945 | Ast.Circles(d,whn,bef,aft) ->
946 Ast.Circles(string_mcode d,
947 List.map (whencode statement_dots statement) whn,
948 bef,aft)
949 | Ast.Stars(d,whn,bef,aft) ->
950 Ast.Stars(string_mcode d,
951 List.map (whencode statement_dots statement) whn,bef,aft)
952 | Ast.OptStm(stmt) -> Ast.OptStm(statement stmt)
953 | Ast.UniqueStm(stmt) -> Ast.UniqueStm(statement stmt)) in
954 let s = stmtfn all_functions k s in
955 (* better to do this after, in case there is an equality test on the whole
956 statement, eg in free_vars. equality test would require that this
957 subterm not already be changed *)
958 process_bef_aft s
959
960 and fninfo = function
961 Ast.FStorage(stg) -> Ast.FStorage(storage_mcode stg)
962 | Ast.FType(ty) -> Ast.FType(fullType ty)
963 | Ast.FInline(inline) -> Ast.FInline(string_mcode inline)
964 | Ast.FAttr(attr) -> Ast.FAttr(string_mcode attr)
965
966 and whencode notfn alwaysfn = function
967 Ast.WhenNot a -> Ast.WhenNot (notfn a)
968 | Ast.WhenAlways a -> Ast.WhenAlways (alwaysfn a)
969 | Ast.WhenModifier(x) -> Ast.WhenModifier(x)
970
971 and case_line c =
972 let k c =
973 Ast.rewrap c
974 (match Ast.unwrap c with
975 Ast.CaseLine(header,code) ->
976 Ast.CaseLine(rule_elem header,statement_dots code)
977 | Ast.OptCase(case) -> Ast.OptCase(case_line case)) in
978 casefn all_functions k c
979
980 and top_level t =
981 let k t =
982 Ast.rewrap t
983 (match Ast.unwrap t with
984 Ast.FILEINFO(old_file,new_file) ->
985 Ast.FILEINFO (string_mcode old_file, string_mcode new_file)
986 | Ast.DECL(stmt) -> Ast.DECL(statement stmt)
987 | Ast.CODE(stmt_dots) -> Ast.CODE(statement_dots stmt_dots)
988 | Ast.ERRORWORDS(exps) -> Ast.ERRORWORDS (List.map expression exps)) in
989 topfn all_functions k t
990
991 and anything a =
992 let k = function
993 (*in many cases below, the thing is not even mcode, so we do nothing*)
994 Ast.FullTypeTag(ft) -> Ast.FullTypeTag(fullType ft)
995 | Ast.BaseTypeTag(bt) as x -> x
996 | Ast.StructUnionTag(su) as x -> x
997 | Ast.SignTag(sgn) as x -> x
998 | Ast.IdentTag(id) -> Ast.IdentTag(ident id)
999 | Ast.ExpressionTag(exp) -> Ast.ExpressionTag(expression exp)
1000 | Ast.ConstantTag(cst) as x -> x
1001 | Ast.UnaryOpTag(unop) as x -> x
1002 | Ast.AssignOpTag(asgnop) as x -> x
1003 | Ast.FixOpTag(fixop) as x -> x
1004 | Ast.BinaryOpTag(binop) as x -> x
1005 | Ast.ArithOpTag(arithop) as x -> x
1006 | Ast.LogicalOpTag(logop) as x -> x
1007 | Ast.InitTag(decl) -> Ast.InitTag(initialiser decl)
1008 | Ast.DeclarationTag(decl) -> Ast.DeclarationTag(declaration decl)
1009 | Ast.StorageTag(stg) as x -> x
1010 | Ast.IncFileTag(stg) as x -> x
1011 | Ast.Rule_elemTag(rule) -> Ast.Rule_elemTag(rule_elem rule)
1012 | Ast.StatementTag(rule) -> Ast.StatementTag(statement rule)
1013 | Ast.CaseLineTag(case) -> Ast.CaseLineTag(case_line case)
1014 | Ast.ConstVolTag(cv) as x -> x
1015 | Ast.Token(tok,info) as x -> x
1016 | Ast.Code(cd) -> Ast.Code(top_level cd)
1017 | Ast.ExprDotsTag(ed) -> Ast.ExprDotsTag(expression_dots ed)
1018 | Ast.ParamDotsTag(pd) -> Ast.ParamDotsTag(parameter_dots pd)
1019 | Ast.StmtDotsTag(sd) -> Ast.StmtDotsTag(statement_dots sd)
1020 | Ast.DeclDotsTag(sd) -> Ast.DeclDotsTag(declaration_dots sd)
1021 | Ast.TypeCTag(ty) -> Ast.TypeCTag(typeC ty)
1022 | Ast.ParamTag(param) -> Ast.ParamTag(parameterTypeDef param)
1023 | Ast.SgrepStartTag(tok) as x -> x
1024 | Ast.SgrepEndTag(tok) as x -> x in
1025 anyfn all_functions k a
1026
1027 and all_functions =
1028 {rebuilder_ident = ident;
1029 rebuilder_expression = expression;
1030 rebuilder_fullType= fullType;
1031 rebuilder_typeC = typeC;
1032 rebuilder_declaration = declaration;
1033 rebuilder_initialiser = initialiser;
1034 rebuilder_parameter = parameterTypeDef;
1035 rebuilder_parameter_list = parameter_dots;
1036 rebuilder_rule_elem = rule_elem;
1037 rebuilder_statement = statement;
1038 rebuilder_case_line = case_line;
1039 rebuilder_top_level = top_level;
1040 rebuilder_expression_dots = expression_dots;
1041 rebuilder_statement_dots = statement_dots;
1042 rebuilder_declaration_dots = declaration_dots;
1043 rebuilder_define_param_dots = define_param_dots;
1044 rebuilder_define_param = define_param;
1045 rebuilder_define_parameters = define_parameters;
1046 rebuilder_anything = anything} in
1047 all_functions
1048