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