2 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
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.
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.
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/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
23 module Ast0
= Ast0_cocci
24 module Ast
= Ast_cocci
26 (* --------------------------------------------------------------------- *)
27 (* Generic traversal: combiner *)
30 treatment of: mcode, identifiers, expressions, fullTypes, types,
31 declarations, statements, toplevels
32 default value for options *)
35 {combiner_ident
: Ast.ident
-> 'a
;
36 combiner_expression
: Ast.expression
-> 'a
;
37 combiner_fullType
: Ast.fullType
-> 'a
;
38 combiner_typeC
: Ast.typeC
-> 'a
;
39 combiner_declaration
: Ast.declaration
-> 'a
;
40 combiner_initialiser
: Ast.initialiser
-> 'a
;
41 combiner_parameter
: Ast.parameterTypeDef
-> 'a
;
42 combiner_parameter_list
: Ast.parameter_list
-> 'a
;
43 combiner_rule_elem
: Ast.rule_elem
-> 'a
;
44 combiner_statement
: Ast.statement
-> 'a
;
45 combiner_case_line
: Ast.case_line
-> 'a
;
46 combiner_top_level
: Ast.top_level
-> 'a
;
47 combiner_anything
: Ast.anything
-> 'a
;
48 combiner_expression_dots
: Ast.expression
Ast.dots
-> 'a
;
49 combiner_statement_dots
: Ast.statement
Ast.dots
-> 'a
;
50 combiner_declaration_dots
: Ast.declaration
Ast.dots
-> 'a
}
52 type ('mc
,'a
) cmcode
= 'a combiner
-> 'mc
Ast_cocci.mcode
-> 'a
53 type ('cd
,'a
) ccode
= 'a combiner
-> ('cd
-> 'a
) -> 'cd
-> 'a
56 let combiner bind option_default
57 meta_mcodefn string_mcodefn const_mcodefn assign_mcodefn fix_mcodefn
58 unary_mcodefn binary_mcodefn
59 cv_mcodefn sign_mcodefn struct_mcodefn storage_mcodefn
61 expdotsfn paramdotsfn stmtdotsfn decldotsfn
62 identfn exprfn ftfn tyfn initfn paramfn declfn rulefn stmtfn casefn
65 let rec loop = function
68 | x
::xs
-> bind x
(loop xs
) in
70 let get_option f
= function
72 | None
-> option_default
in
74 let rec meta_mcode x
= meta_mcodefn all_functions x
75 and string_mcode x
= string_mcodefn all_functions x
76 and const_mcode x
= const_mcodefn all_functions x
77 and assign_mcode x
= assign_mcodefn all_functions x
78 and fix_mcode x
= fix_mcodefn all_functions x
79 and unary_mcode x
= unary_mcodefn all_functions x
80 and binary_mcode x
= binary_mcodefn all_functions x
81 and cv_mcode x
= cv_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
87 and expression_dots 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
94 and parameter_dots 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
101 and statement_dots 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
108 and declaration_dots 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
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
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
;
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
;
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
) ->
151 [expression exp1
; string_mcode lb
; expression exp2
;
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
) ->
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
) ->
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
) ->
178 exprfn all_functions
k e
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
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 *)
192 ([fullType ty
; string_mcode lp1
; string_mcode star
] @ extra
@
194 string_mcode lp2
; parameter_dots params
; string_mcode rp2
])
196 and function_type
(ty
,lp1
,params
,rp1
) extra
=
197 (* have to put the treatment of the identifier into the right position *)
199 ([get_option fullType ty
] @ extra
@
200 [string_mcode lp1
; parameter_dots params
; string_mcode rp1
])
202 and array_type
(ty
,lb
,size
,rb
) extra
=
204 ([fullType ty
] @ extra
@
205 [string_mcode lb
; get_option expression size
; string_mcode rb
])
209 match Ast.unwrap ty
with
210 Ast.BaseType
(ty
,strings
) -> multibind (List.map string_mcode strings
)
211 | Ast.SignedT
(sgn
,ty
) -> bind
(sign_mcode sgn
) (get_option typeC ty
)
212 | Ast.Pointer
(ty
,star
) ->
213 bind
(fullType ty
) (string_mcode star
)
214 | Ast.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
215 function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) []
216 | Ast.FunctionType
(_
,ty
,lp1
,params
,rp1
) ->
217 function_type
(ty
,lp1
,params
,rp1
) []
218 | Ast.Array
(ty
,lb
,size
,rb
) -> array_type
(ty
,lb
,size
,rb
) []
219 | Ast.EnumName
(kind
,name
) -> bind
(string_mcode kind
) (ident name
)
220 | Ast.StructUnionName
(kind
,name
) ->
221 bind
(struct_mcode kind
) (get_option ident name
)
222 | Ast.StructUnionDef
(ty
,lb
,decls
,rb
) ->
224 [fullType ty
; string_mcode lb
; declaration_dots decls
;
226 | Ast.TypeName
(name
) -> string_mcode name
227 | Ast.MetaType
(name
,_
,_
) -> meta_mcode name
in
228 tyfn all_functions
k ty
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
)
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
)
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
) ->
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
271 match Ast.unwrap i
with
272 Ast.MetaInit
(name
,_
,_
) -> meta_mcode name
273 | Ast.InitExpr
(exp
) -> expression exp
274 | Ast.InitList
(lb
,initlist
,rb
,whencode
) ->
277 multibind (List.map initialiser initlist
);
279 multibind (List.map initialiser whencode
)]
280 | Ast.InitGccName
(name
,eq
,ini
) ->
281 multibind [ident name
; string_mcode eq
; initialiser ini
]
282 | Ast.InitGccExt
(designators
,eq
,ini
) ->
284 ((List.map designator designators
) @
285 [string_mcode eq
; initialiser ini
])
286 | Ast.IComma
(cm
) -> string_mcode cm
287 | Ast.OptIni
(i
) -> initialiser i
288 | Ast.UniqueIni
(i
) -> initialiser i
in
289 initfn all_functions
k i
291 and designator
= function
292 Ast.DesignatorField
(dot
,id
) -> bind
(string_mcode dot
) (ident id
)
293 | Ast.DesignatorIndex
(lb
,exp
,rb
) ->
294 bind
(string_mcode lb
) (bind
(expression exp
) (string_mcode rb
))
295 | Ast.DesignatorRange
(lb
,min
,dots
,max
,rb
) ->
297 [string_mcode lb
; expression min
; string_mcode dots
;
298 expression max
; string_mcode rb
]
300 and parameterTypeDef p
=
302 match Ast.unwrap p
with
303 Ast.VoidParam
(ty
) -> fullType ty
304 | Ast.Param
(ty
,Some id
) -> named_type ty id
305 | Ast.Param
(ty
,None
) -> fullType ty
306 | Ast.MetaParam
(name
,_
,_
) -> meta_mcode name
307 | Ast.MetaParamList
(name
,_
,_
,_
) -> meta_mcode name
308 | Ast.PComma
(cm
) -> string_mcode cm
309 | Ast.Pdots
(dots
) -> string_mcode dots
310 | Ast.Pcircles
(dots
) -> string_mcode dots
311 | Ast.OptParam
(param
) -> parameterTypeDef param
312 | Ast.UniqueParam
(param
) -> parameterTypeDef param
in
313 paramfn all_functions
k p
317 match Ast.unwrap re
with
318 Ast.FunHeader
(_
,_
,fi
,name
,lp
,params
,rp
) ->
320 ((List.map fninfo fi
) @
321 [ident name
;string_mcode lp
;parameter_dots params
;
323 | Ast.Decl
(_
,_
,decl
) -> declaration decl
324 | Ast.SeqStart
(brace
) -> string_mcode brace
325 | Ast.SeqEnd
(brace
) -> string_mcode brace
326 | Ast.ExprStatement
(exp
,sem
) ->
327 bind
(expression exp
) (string_mcode sem
)
328 | Ast.IfHeader
(iff
,lp
,exp
,rp
) ->
329 multibind [string_mcode iff
; string_mcode lp
; expression exp
;
331 | Ast.Else
(els
) -> string_mcode els
332 | Ast.WhileHeader
(whl
,lp
,exp
,rp
) ->
333 multibind [string_mcode whl
; string_mcode lp
; expression exp
;
335 | Ast.DoHeader
(d
) -> string_mcode d
336 | Ast.WhileTail
(whl
,lp
,exp
,rp
,sem
) ->
337 multibind [string_mcode whl
; string_mcode lp
; expression exp
;
338 string_mcode rp
; string_mcode sem
]
339 | Ast.ForHeader
(fr
,lp
,e1
,sem1
,e2
,sem2
,e3
,rp
) ->
340 multibind [string_mcode fr
; string_mcode lp
;
341 get_option expression e1
; string_mcode sem1
;
342 get_option expression e2
; string_mcode sem2
;
343 get_option expression e3
; string_mcode rp
]
344 | Ast.IteratorHeader
(nm
,lp
,args
,rp
) ->
345 multibind [ident nm
; string_mcode lp
;
346 expression_dots args
; string_mcode rp
]
347 | Ast.SwitchHeader
(switch
,lp
,exp
,rp
) ->
348 multibind [string_mcode switch
; string_mcode lp
; expression exp
;
350 | Ast.Break
(br
,sem
) -> bind
(string_mcode br
) (string_mcode sem
)
351 | Ast.Continue
(cont
,sem
) -> bind
(string_mcode cont
) (string_mcode sem
)
352 | Ast.Label
(l
,dd
) -> bind
(ident l
) (string_mcode dd
)
353 | Ast.Goto
(goto
,l
,sem
) ->
354 bind
(string_mcode goto
) (bind
(ident l
) (string_mcode sem
))
355 | Ast.Return
(ret
,sem
) -> bind
(string_mcode ret
) (string_mcode sem
)
356 | Ast.ReturnExpr
(ret
,exp
,sem
) ->
357 multibind [string_mcode ret
; expression exp
; string_mcode sem
]
358 | Ast.MetaStmt
(name
,_
,_
,_
) -> meta_mcode name
359 | Ast.MetaStmtList
(name
,_
,_
) -> meta_mcode name
360 | Ast.MetaRuleElem
(name
,_
,_
) -> meta_mcode name
361 | Ast.Exp
(exp
) -> expression exp
362 | Ast.TopExp
(exp
) -> expression exp
363 | Ast.Ty
(ty
) -> fullType ty
364 | Ast.TopInit
(init
) -> initialiser init
365 | Ast.Include
(inc
,name
) -> bind
(string_mcode inc
) (inc_file_mcode name
)
366 | Ast.DefineHeader
(def
,id
,params
) ->
367 multibind [string_mcode def
; ident id
; define_parameters params
]
368 | Ast.Default
(def
,colon
) -> bind
(string_mcode def
) (string_mcode colon
)
369 | Ast.Case
(case
,exp
,colon
) ->
370 multibind [string_mcode case
; expression exp
; string_mcode colon
]
371 | Ast.DisjRuleElem
(res
) -> multibind (List.map rule_elem res
) in
372 rulefn all_functions
k re
374 (* not parameterizable for now... *)
375 and define_parameters p
=
377 match Ast.unwrap p
with
378 Ast.NoParams
-> option_default
379 | Ast.DParams
(lp
,params
,rp
) ->
381 [string_mcode lp
; define_param_dots params
; string_mcode rp
] in
384 and define_param_dots d
=
386 match Ast.unwrap d
with
387 Ast.DOTS
(l
) | Ast.CIRCLES
(l
) | Ast.STARS
(l
) ->
388 multibind (List.map define_param l
) in
393 match Ast.unwrap p
with
394 Ast.DParam
(id
) -> ident id
395 | Ast.DPComma
(comma
) -> string_mcode comma
396 | Ast.DPdots
(d
) -> string_mcode d
397 | Ast.DPcircles
(c
) -> string_mcode c
398 | Ast.OptDParam
(dp
) -> define_param dp
399 | Ast.UniqueDParam
(dp
) -> define_param dp
in
402 (* discard the result, because the statement is assumed to be already
403 represented elsewhere in the code *)
404 and process_bef_aft s
=
405 match Ast.get_dots_bef_aft s
with
407 | Ast.DroppingBetweenDots
(stm
,ind
) -> let _ = statement stm
in ()
408 | Ast.AddingBetweenDots
(stm
,ind
) -> let _ = statement stm
in ()
413 match Ast.unwrap s
with
414 Ast.Seq
(lbrace
,body
,rbrace
) ->
415 multibind [rule_elem lbrace
;
416 statement_dots body
; rule_elem rbrace
]
417 | Ast.IfThen
(header
,branch
,_) ->
418 multibind [rule_elem header
; statement branch
]
419 | Ast.IfThenElse
(header
,branch1
,els
,branch2
,_) ->
420 multibind [rule_elem header
; statement branch1
; rule_elem els
;
422 | Ast.While
(header
,body
,_) ->
423 multibind [rule_elem header
; statement body
]
424 | Ast.Do
(header
,body
,tail
) ->
425 multibind [rule_elem header
; statement body
; rule_elem tail
]
426 | Ast.For
(header
,body
,_) -> multibind [rule_elem header
; statement body
]
427 | Ast.Iterator
(header
,body
,_) ->
428 multibind [rule_elem header
; statement body
]
429 | Ast.Switch
(header
,lb
,decls
,cases
,rb
) ->
430 multibind [rule_elem header
;rule_elem lb
;
431 statement_dots decls
;
432 multibind (List.map case_line cases
);
434 | Ast.Atomic
(re
) -> rule_elem re
435 | Ast.Disj
(stmt_dots_list
) ->
436 multibind (List.map statement_dots stmt_dots_list
)
437 | Ast.Nest
(stmt_dots
,whn
,_,_,_) ->
438 bind
(statement_dots stmt_dots
)
439 (multibind (List.map
(whencode statement_dots statement
) whn
))
440 | Ast.FunDecl
(header
,lbrace
,body
,rbrace
) ->
441 multibind [rule_elem header
; rule_elem lbrace
;
442 statement_dots body
; rule_elem rbrace
]
443 | Ast.Define
(header
,body
) ->
444 bind
(rule_elem header
) (statement_dots body
)
445 | Ast.Dots
(d
,whn
,_,_) | Ast.Circles
(d
,whn
,_,_) | Ast.Stars
(d
,whn
,_,_) ->
446 bind
(string_mcode d
)
447 (multibind (List.map
(whencode statement_dots statement
) whn
))
448 | Ast.OptStm
(stmt
) | Ast.UniqueStm
(stmt
) ->
450 stmtfn all_functions
k s
452 and fninfo
= function
453 Ast.FStorage
(stg
) -> storage_mcode stg
454 | Ast.FType
(ty
) -> fullType ty
455 | Ast.FInline
(inline
) -> string_mcode inline
456 | Ast.FAttr
(attr
) -> string_mcode attr
458 and whencode notfn alwaysfn
= function
459 Ast.WhenNot a
-> notfn a
460 | Ast.WhenAlways a
-> alwaysfn a
461 | Ast.WhenModifier
(_) -> option_default
462 | Ast.WhenNotTrue
(e
) -> rule_elem e
463 | Ast.WhenNotFalse
(e
) -> rule_elem e
467 match Ast.unwrap c
with
468 Ast.CaseLine
(header
,code
) ->
469 bind
(rule_elem header
) (statement_dots code
)
470 | Ast.OptCase
(case
) -> case_line case
in
471 casefn all_functions
k c
475 match Ast.unwrap t
with
476 Ast.FILEINFO
(old_file
,new_file
) ->
477 bind
(string_mcode old_file
) (string_mcode new_file
)
478 | Ast.DECL
(stmt
) -> statement stmt
479 | Ast.CODE
(stmt_dots
) -> statement_dots stmt_dots
480 | Ast.ERRORWORDS
(exps
) -> multibind (List.map expression exps
) in
481 topfn all_functions
k t
485 (*in many cases below, the thing is not even mcode, so we do nothing*)
486 Ast.FullTypeTag
(ft
) -> fullType ft
487 | Ast.BaseTypeTag
(bt
) -> option_default
488 | Ast.StructUnionTag
(su
) -> option_default
489 | Ast.SignTag
(sgn
) -> option_default
490 | Ast.IdentTag
(id
) -> ident id
491 | Ast.ExpressionTag
(exp
) -> expression exp
492 | Ast.ConstantTag
(cst
) -> option_default
493 | Ast.UnaryOpTag
(unop
) -> option_default
494 | Ast.AssignOpTag
(asgnop
) -> option_default
495 | Ast.FixOpTag
(fixop
) -> option_default
496 | Ast.BinaryOpTag
(binop
) -> option_default
497 | Ast.ArithOpTag
(arithop
) -> option_default
498 | Ast.LogicalOpTag
(logop
) -> option_default
499 | Ast.DeclarationTag
(decl
) -> declaration decl
500 | Ast.InitTag
(ini
) -> initialiser ini
501 | Ast.StorageTag
(stg
) -> option_default
502 | Ast.IncFileTag
(stg
) -> option_default
503 | Ast.Rule_elemTag
(rule
) -> rule_elem rule
504 | Ast.StatementTag
(rule
) -> statement rule
505 | Ast.CaseLineTag
(case
) -> case_line case
506 | Ast.ConstVolTag
(cv
) -> option_default
507 | Ast.Token
(tok
,info
) -> option_default
508 | Ast.Pragma
(str
) -> option_default
509 | Ast.Code
(cd
) -> top_level cd
510 | Ast.ExprDotsTag
(ed
) -> expression_dots ed
511 | Ast.ParamDotsTag
(pd
) -> parameter_dots pd
512 | Ast.StmtDotsTag
(sd
) -> statement_dots sd
513 | Ast.DeclDotsTag
(sd
) -> declaration_dots sd
514 | Ast.TypeCTag
(ty
) -> typeC ty
515 | Ast.ParamTag
(param
) -> parameterTypeDef param
516 | Ast.SgrepStartTag
(tok
) -> option_default
517 | Ast.SgrepEndTag
(tok
) -> option_default
in
518 anyfn all_functions
k a
521 {combiner_ident
= ident
;
522 combiner_expression
= expression
;
523 combiner_fullType
= fullType
;
524 combiner_typeC
= typeC
;
525 combiner_declaration
= declaration
;
526 combiner_initialiser
= initialiser
;
527 combiner_parameter
= parameterTypeDef
;
528 combiner_parameter_list
= parameter_dots
;
529 combiner_rule_elem
= rule_elem
;
530 combiner_statement
= statement
;
531 combiner_case_line
= case_line
;
532 combiner_top_level
= top_level
;
533 combiner_anything
= anything
;
534 combiner_expression_dots
= expression_dots
;
535 combiner_statement_dots
= statement_dots
;
536 combiner_declaration_dots
= declaration_dots
} in
539 (* ---------------------------------------------------------------------- *)
541 type 'a inout
= 'a
-> 'a
(* for specifying the type of rebuilder *)
544 {rebuilder_ident
: Ast.ident inout
;
545 rebuilder_expression
: Ast.expression inout
;
546 rebuilder_fullType
: Ast.fullType inout
;
547 rebuilder_typeC
: Ast.typeC inout
;
548 rebuilder_declaration
: Ast.declaration inout
;
549 rebuilder_initialiser
: Ast.initialiser inout
;
550 rebuilder_parameter
: Ast.parameterTypeDef inout
;
551 rebuilder_parameter_list
: Ast.parameter_list inout
;
552 rebuilder_statement
: Ast.statement inout
;
553 rebuilder_case_line
: Ast.case_line inout
;
554 rebuilder_rule_elem
: Ast.rule_elem inout
;
555 rebuilder_top_level
: Ast.top_level inout
;
556 rebuilder_expression_dots
: Ast.expression
Ast.dots inout
;
557 rebuilder_statement_dots
: Ast.statement
Ast.dots inout
;
558 rebuilder_declaration_dots
: Ast.declaration
Ast.dots inout
;
559 rebuilder_define_param_dots
: Ast.define_param
Ast.dots inout
;
560 rebuilder_define_param
: Ast.define_param inout
;
561 rebuilder_define_parameters
: Ast.define_parameters inout
;
562 rebuilder_anything
: Ast.anything inout
}
564 type 'mc rmcode
= 'mc
Ast.mcode inout
565 type 'cd rcode
= rebuilder
-> ('cd inout
) -> 'cd inout
569 meta_mcode string_mcode const_mcode assign_mcode fix_mcode unary_mcode
570 binary_mcode cv_mcode sign_mcode struct_mcode storage_mcode
572 expdotsfn paramdotsfn stmtdotsfn decldotsfn
573 identfn exprfn ftfn tyfn initfn paramfn declfn rulefn stmtfn casefn
575 let get_option f
= function
578 let rec expression_dots d
=
581 (match Ast.unwrap d
with
582 Ast.DOTS
(l
) -> Ast.DOTS
(List.map expression l
)
583 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map expression l
)
584 | Ast.STARS
(l
) -> Ast.STARS
(List.map expression l
)) in
585 expdotsfn all_functions
k d
587 and parameter_dots d
=
590 (match Ast.unwrap d
with
591 Ast.DOTS
(l
) -> Ast.DOTS
(List.map parameterTypeDef l
)
592 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map parameterTypeDef l
)
593 | Ast.STARS
(l
) -> Ast.STARS
(List.map parameterTypeDef l
)) in
594 paramdotsfn all_functions
k d
596 and statement_dots d
=
599 (match Ast.unwrap d
with
600 Ast.DOTS
(l
) -> Ast.DOTS
(List.map statement l
)
601 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map statement l
)
602 | Ast.STARS
(l
) -> Ast.STARS
(List.map statement l
)) in
603 stmtdotsfn all_functions
k d
605 and declaration_dots d
=
608 (match Ast.unwrap d
with
609 Ast.DOTS
(l
) -> Ast.DOTS
(List.map declaration l
)
610 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map declaration l
)
611 | Ast.STARS
(l
) -> Ast.STARS
(List.map declaration l
)) in
612 decldotsfn all_functions
k d
617 (match Ast.unwrap i
with
618 Ast.Id
(name
) -> Ast.Id
(string_mcode name
)
619 | Ast.MetaId
(name
,constraints
,keep
,inherited
) ->
620 Ast.MetaId
(meta_mcode name
,constraints
,keep
,inherited
)
621 | Ast.MetaFunc
(name
,constraints
,keep
,inherited
) ->
622 Ast.MetaFunc
(meta_mcode name
,constraints
,keep
,inherited
)
623 | Ast.MetaLocalFunc
(name
,constraints
,keep
,inherited
) ->
624 Ast.MetaLocalFunc
(meta_mcode name
,constraints
,keep
,inherited
)
625 | Ast.OptIdent
(id
) -> Ast.OptIdent
(ident id
)
626 | Ast.UniqueIdent
(id
) -> Ast.UniqueIdent
(ident id
)) in
627 identfn all_functions
k i
632 (match Ast.unwrap e
with
633 Ast.Ident
(id
) -> Ast.Ident
(ident id
)
634 | Ast.Constant
(const
) -> Ast.Constant
(const_mcode const
)
635 | Ast.FunCall
(fn
,lp
,args
,rp
) ->
636 Ast.FunCall
(expression fn
, string_mcode lp
, expression_dots args
,
638 | Ast.Assignment
(left
,op
,right
,simple
) ->
639 Ast.Assignment
(expression left
, assign_mcode op
, expression right
,
641 | Ast.CondExpr
(exp1
,why
,exp2
,colon
,exp3
) ->
642 Ast.CondExpr
(expression exp1
, string_mcode why
,
643 get_option expression exp2
, string_mcode colon
,
645 | Ast.Postfix
(exp
,op
) -> Ast.Postfix
(expression exp
,fix_mcode op
)
646 | Ast.Infix
(exp
,op
) -> Ast.Infix
(expression exp
,fix_mcode op
)
647 | Ast.Unary
(exp
,op
) -> Ast.Unary
(expression exp
,unary_mcode op
)
648 | Ast.Binary
(left
,op
,right
) ->
649 Ast.Binary
(expression left
, binary_mcode op
, expression right
)
650 | Ast.Nested
(left
,op
,right
) ->
651 Ast.Nested
(expression left
, binary_mcode op
, expression right
)
652 | Ast.Paren
(lp
,exp
,rp
) ->
653 Ast.Paren
(string_mcode lp
, expression exp
, string_mcode rp
)
654 | Ast.ArrayAccess
(exp1
,lb
,exp2
,rb
) ->
655 Ast.ArrayAccess
(expression exp1
, string_mcode lb
, expression exp2
,
657 | Ast.RecordAccess
(exp
,pt
,field
) ->
658 Ast.RecordAccess
(expression exp
, string_mcode pt
, ident field
)
659 | Ast.RecordPtAccess
(exp
,ar
,field
) ->
660 Ast.RecordPtAccess
(expression exp
, string_mcode ar
, ident field
)
661 | Ast.Cast
(lp
,ty
,rp
,exp
) ->
662 Ast.Cast
(string_mcode lp
, fullType ty
, string_mcode rp
,
664 | Ast.SizeOfExpr
(szf
,exp
) ->
665 Ast.SizeOfExpr
(string_mcode szf
, expression exp
)
666 | Ast.SizeOfType
(szf
,lp
,ty
,rp
) ->
667 Ast.SizeOfType
(string_mcode szf
,string_mcode lp
, fullType ty
,
669 | Ast.TypeExp
(ty
) -> Ast.TypeExp
(fullType ty
)
670 | Ast.MetaErr
(name
,constraints
,keep
,inherited
) ->
671 Ast.MetaErr
(meta_mcode name
,constraints
,keep
,inherited
)
672 | Ast.MetaExpr
(name
,constraints
,keep
,ty
,form
,inherited
) ->
673 Ast.MetaExpr
(meta_mcode name
,constraints
,keep
,ty
,form
,inherited
)
674 | Ast.MetaExprList
(name
,lenname_inh
,keep
,inherited
) ->
675 Ast.MetaExprList
(meta_mcode name
,lenname_inh
,keep
,inherited
)
676 | Ast.EComma
(cm
) -> Ast.EComma
(string_mcode cm
)
677 | Ast.DisjExpr
(exp_list
) -> Ast.DisjExpr
(List.map expression exp_list
)
678 | Ast.NestExpr
(expr_dots
,whencode
,multi
) ->
679 Ast.NestExpr
(expression_dots expr_dots
,
680 get_option expression whencode
,multi
)
681 | Ast.Edots
(dots
,whencode
) ->
682 Ast.Edots
(string_mcode dots
,get_option expression whencode
)
683 | Ast.Ecircles
(dots
,whencode
) ->
684 Ast.Ecircles
(string_mcode dots
,get_option expression whencode
)
685 | Ast.Estars
(dots
,whencode
) ->
686 Ast.Estars
(string_mcode dots
,get_option expression whencode
)
687 | Ast.OptExp
(exp
) -> Ast.OptExp
(expression exp
)
688 | Ast.UniqueExp
(exp
) -> Ast.UniqueExp
(expression exp
)) in
689 exprfn all_functions
k e
694 (match Ast.unwrap ft
with
695 Ast.Type
(cv
,ty
) -> Ast.Type
(get_option cv_mcode cv
, typeC ty
)
696 | Ast.DisjType
(types
) -> Ast.DisjType
(List.map fullType types
)
697 | Ast.OptType
(ty
) -> Ast.OptType
(fullType ty
)
698 | Ast.UniqueType
(ty
) -> Ast.UniqueType
(fullType ty
)) in
699 ftfn all_functions
k ft
704 (match Ast.unwrap ty
with
705 Ast.BaseType
(ty
,strings
) ->
706 Ast.BaseType
(ty
, List.map string_mcode strings
)
707 | Ast.SignedT
(sgn
,ty
) ->
708 Ast.SignedT
(sign_mcode sgn
,get_option typeC ty
)
709 | Ast.Pointer
(ty
,star
) ->
710 Ast.Pointer
(fullType ty
, string_mcode star
)
711 | Ast.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
712 Ast.FunctionPointer
(fullType ty
,string_mcode lp1
,string_mcode star
,
713 string_mcode rp1
,string_mcode lp2
,
714 parameter_dots params
,
716 | Ast.FunctionType
(allminus
,ty
,lp
,params
,rp
) ->
717 Ast.FunctionType
(allminus
,get_option fullType ty
,string_mcode lp
,
718 parameter_dots params
,string_mcode rp
)
719 | Ast.Array
(ty
,lb
,size
,rb
) ->
720 Ast.Array
(fullType ty
, string_mcode lb
,
721 get_option expression size
, string_mcode rb
)
722 | Ast.EnumName
(kind
,name
) ->
723 Ast.EnumName
(string_mcode kind
, ident name
)
724 | Ast.StructUnionName
(kind
,name
) ->
725 Ast.StructUnionName
(struct_mcode kind
, get_option ident name
)
726 | Ast.StructUnionDef
(ty
,lb
,decls
,rb
) ->
727 Ast.StructUnionDef
(fullType ty
,
728 string_mcode lb
, declaration_dots decls
,
730 | Ast.TypeName
(name
) -> Ast.TypeName
(string_mcode name
)
731 | Ast.MetaType
(name
,keep
,inherited
) ->
732 Ast.MetaType
(meta_mcode name
,keep
,inherited
)) in
733 tyfn all_functions
k ty
738 (match Ast.unwrap d
with
739 Ast.Init
(stg
,ty
,id
,eq
,ini
,sem
) ->
740 Ast.Init
(get_option storage_mcode stg
, fullType ty
, ident id
,
741 string_mcode eq
, initialiser ini
, string_mcode sem
)
742 | Ast.UnInit
(stg
,ty
,id
,sem
) ->
743 Ast.UnInit
(get_option storage_mcode stg
, fullType ty
, ident id
,
745 | Ast.MacroDecl
(name
,lp
,args
,rp
,sem
) ->
746 Ast.MacroDecl
(ident name
, string_mcode lp
, expression_dots args
,
747 string_mcode rp
,string_mcode sem
)
748 | Ast.TyDecl
(ty
,sem
) -> Ast.TyDecl
(fullType ty
, string_mcode sem
)
749 | Ast.Typedef
(stg
,ty
,id
,sem
) ->
750 Ast.Typedef
(string_mcode stg
, fullType ty
, typeC id
,
752 | Ast.DisjDecl
(decls
) -> Ast.DisjDecl
(List.map declaration decls
)
753 | Ast.Ddots
(dots
,whencode
) ->
754 Ast.Ddots
(string_mcode dots
, get_option declaration whencode
)
755 | Ast.MetaDecl
(name
,keep
,inherited
) ->
756 Ast.MetaDecl
(meta_mcode name
,keep
,inherited
)
757 | Ast.OptDecl
(decl
) -> Ast.OptDecl
(declaration decl
)
758 | Ast.UniqueDecl
(decl
) -> Ast.UniqueDecl
(declaration decl
)) in
759 declfn all_functions
k d
764 (match Ast.unwrap i
with
765 Ast.MetaInit
(name
,keep
,inherited
) ->
766 Ast.MetaInit
(meta_mcode name
,keep
,inherited
)
767 | Ast.InitExpr
(exp
) -> Ast.InitExpr
(expression exp
)
768 | Ast.InitList
(lb
,initlist
,rb
,whencode
) ->
769 Ast.InitList
(string_mcode lb
, List.map initialiser initlist
,
770 string_mcode rb
, List.map initialiser whencode
)
771 | Ast.InitGccName
(name
,eq
,ini
) ->
772 Ast.InitGccName
(ident name
, string_mcode eq
, initialiser ini
)
773 | Ast.InitGccExt
(designators
,eq
,ini
) ->
775 (List.map designator designators
, string_mcode eq
,
777 | Ast.IComma
(cm
) -> Ast.IComma
(string_mcode cm
)
778 | Ast.OptIni
(i
) -> Ast.OptIni
(initialiser i
)
779 | Ast.UniqueIni
(i
) -> Ast.UniqueIni
(initialiser i
)) in
780 initfn all_functions
k i
782 and designator
= function
783 Ast.DesignatorField
(dot
,id
) ->
784 Ast.DesignatorField
(string_mcode dot
,ident id
)
785 | Ast.DesignatorIndex
(lb
,exp
,rb
) ->
786 Ast.DesignatorIndex
(string_mcode lb
,expression exp
,string_mcode rb
)
787 | Ast.DesignatorRange
(lb
,min
,dots
,max
,rb
) ->
788 Ast.DesignatorRange
(string_mcode lb
,expression min
,string_mcode dots
,
789 expression max
,string_mcode rb
)
791 and parameterTypeDef p
=
794 (match Ast.unwrap p
with
795 Ast.VoidParam
(ty
) -> Ast.VoidParam
(fullType ty
)
796 | Ast.Param
(ty
,id
) -> Ast.Param
(fullType ty
, get_option ident id
)
797 | Ast.MetaParam
(name
,keep
,inherited
) ->
798 Ast.MetaParam
(meta_mcode name
,keep
,inherited
)
799 | Ast.MetaParamList
(name
,lenname_inh
,keep
,inherited
) ->
800 Ast.MetaParamList
(meta_mcode name
,lenname_inh
,keep
,inherited
)
801 | Ast.PComma
(cm
) -> Ast.PComma
(string_mcode cm
)
802 | Ast.Pdots
(dots
) -> Ast.Pdots
(string_mcode dots
)
803 | Ast.Pcircles
(dots
) -> Ast.Pcircles
(string_mcode dots
)
804 | Ast.OptParam
(param
) -> Ast.OptParam
(parameterTypeDef param
)
805 | Ast.UniqueParam
(param
) -> Ast.UniqueParam
(parameterTypeDef param
)) in
806 paramfn all_functions
k p
811 (match Ast.unwrap re
with
812 Ast.FunHeader
(bef
,allminus
,fi
,name
,lp
,params
,rp
) ->
813 Ast.FunHeader
(bef
,allminus
,List.map fninfo fi
,ident name
,
814 string_mcode lp
, parameter_dots params
,
816 | Ast.Decl
(bef
,allminus
,decl
) ->
817 Ast.Decl
(bef
,allminus
,declaration decl
)
818 | Ast.SeqStart
(brace
) -> Ast.SeqStart
(string_mcode brace
)
819 | Ast.SeqEnd
(brace
) -> Ast.SeqEnd
(string_mcode brace
)
820 | Ast.ExprStatement
(exp
,sem
) ->
821 Ast.ExprStatement
(expression exp
, string_mcode sem
)
822 | Ast.IfHeader
(iff
,lp
,exp
,rp
) ->
823 Ast.IfHeader
(string_mcode iff
, string_mcode lp
, expression exp
,
825 | Ast.Else
(els
) -> Ast.Else
(string_mcode els
)
826 | Ast.WhileHeader
(whl
,lp
,exp
,rp
) ->
827 Ast.WhileHeader
(string_mcode whl
, string_mcode lp
, expression exp
,
829 | Ast.DoHeader
(d
) -> Ast.DoHeader
(string_mcode d
)
830 | Ast.WhileTail
(whl
,lp
,exp
,rp
,sem
) ->
831 Ast.WhileTail
(string_mcode whl
, string_mcode lp
, expression exp
,
832 string_mcode rp
, string_mcode sem
)
833 | Ast.ForHeader
(fr
,lp
,e1
,sem1
,e2
,sem2
,e3
,rp
) ->
834 Ast.ForHeader
(string_mcode fr
, string_mcode lp
,
835 get_option expression e1
, string_mcode sem1
,
836 get_option expression e2
, string_mcode sem2
,
837 get_option expression e3
, string_mcode rp
)
838 | Ast.IteratorHeader
(whl
,lp
,args
,rp
) ->
839 Ast.IteratorHeader
(ident whl
, string_mcode lp
,
840 expression_dots args
, string_mcode rp
)
841 | Ast.SwitchHeader
(switch
,lp
,exp
,rp
) ->
842 Ast.SwitchHeader
(string_mcode switch
, string_mcode lp
,
843 expression exp
, string_mcode rp
)
844 | Ast.Break
(br
,sem
) ->
845 Ast.Break
(string_mcode br
, string_mcode sem
)
846 | Ast.Continue
(cont
,sem
) ->
847 Ast.Continue
(string_mcode cont
, string_mcode sem
)
848 | Ast.Label
(l
,dd
) -> Ast.Label
(ident l
, string_mcode dd
)
849 | Ast.Goto
(goto
,l
,sem
) ->
850 Ast.Goto
(string_mcode goto
,ident l
,string_mcode sem
)
851 | Ast.Return
(ret
,sem
) ->
852 Ast.Return
(string_mcode ret
, string_mcode sem
)
853 | Ast.ReturnExpr
(ret
,exp
,sem
) ->
854 Ast.ReturnExpr
(string_mcode ret
, expression exp
, string_mcode sem
)
855 | Ast.MetaStmt
(name
,keep
,seqible
,inherited
) ->
856 Ast.MetaStmt
(meta_mcode name
,keep
,seqible
,inherited
)
857 | Ast.MetaStmtList
(name
,keep
,inherited
) ->
858 Ast.MetaStmtList
(meta_mcode name
,keep
,inherited
)
859 | Ast.MetaRuleElem
(name
,keep
,inherited
) ->
860 Ast.MetaRuleElem
(meta_mcode name
,keep
,inherited
)
861 | Ast.Exp
(exp
) -> Ast.Exp
(expression exp
)
862 | Ast.TopExp
(exp
) -> Ast.TopExp
(expression exp
)
863 | Ast.Ty
(ty
) -> Ast.Ty
(fullType ty
)
864 | Ast.TopInit
(init
) -> Ast.TopInit
(initialiser init
)
865 | Ast.Include
(inc
,name
) ->
866 Ast.Include
(string_mcode inc
,inc_file_mcode name
)
867 | Ast.DefineHeader
(def
,id
,params
) ->
868 Ast.DefineHeader
(string_mcode def
,ident id
,
869 define_parameters params
)
870 | Ast.Default
(def
,colon
) ->
871 Ast.Default
(string_mcode def
,string_mcode colon
)
872 | Ast.Case
(case
,exp
,colon
) ->
873 Ast.Case
(string_mcode case
,expression exp
,string_mcode colon
)
874 | Ast.DisjRuleElem
(res
) -> Ast.DisjRuleElem
(List.map rule_elem res
)) in
875 rulefn all_functions
k re
877 (* not parameterizable for now... *)
878 and define_parameters p
=
881 (match Ast.unwrap p
with
882 Ast.NoParams
-> Ast.NoParams
883 | Ast.DParams
(lp
,params
,rp
) ->
884 Ast.DParams
(string_mcode lp
,define_param_dots params
,
888 and define_param_dots d
=
891 (match Ast.unwrap d
with
892 Ast.DOTS
(l
) -> Ast.DOTS
(List.map define_param l
)
893 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map define_param l
)
894 | Ast.STARS
(l
) -> Ast.STARS
(List.map define_param l
)) in
900 (match Ast.unwrap p
with
901 Ast.DParam
(id
) -> Ast.DParam
(ident id
)
902 | Ast.DPComma
(comma
) -> Ast.DPComma
(string_mcode comma
)
903 | Ast.DPdots
(d
) -> Ast.DPdots
(string_mcode d
)
904 | Ast.DPcircles
(c
) -> Ast.DPcircles
(string_mcode c
)
905 | Ast.OptDParam
(dp
) -> Ast.OptDParam
(define_param dp
)
906 | Ast.UniqueDParam
(dp
) -> Ast.UniqueDParam
(define_param dp
)) in
909 and process_bef_aft s
=
911 (match Ast.get_dots_bef_aft s
with
912 Ast.NoDots
-> Ast.NoDots
913 | Ast.DroppingBetweenDots
(stm
,ind
) ->
914 Ast.DroppingBetweenDots
(statement stm
,ind
)
915 | Ast.AddingBetweenDots
(stm
,ind
) ->
916 Ast.AddingBetweenDots
(statement stm
,ind
))
922 (match Ast.unwrap s
with
923 Ast.Seq
(lbrace
,body
,rbrace
) ->
924 Ast.Seq
(rule_elem lbrace
,
925 statement_dots body
, rule_elem rbrace
)
926 | Ast.IfThen
(header
,branch
,aft
) ->
927 Ast.IfThen
(rule_elem header
, statement branch
,aft
)
928 | Ast.IfThenElse
(header
,branch1
,els
,branch2
,aft
) ->
929 Ast.IfThenElse
(rule_elem header
, statement branch1
, rule_elem els
,
930 statement branch2
, aft
)
931 | Ast.While
(header
,body
,aft
) ->
932 Ast.While
(rule_elem header
, statement body
, aft
)
933 | Ast.Do
(header
,body
,tail
) ->
934 Ast.Do
(rule_elem header
, statement body
, rule_elem tail
)
935 | Ast.For
(header
,body
,aft
) ->
936 Ast.For
(rule_elem header
, statement body
, aft
)
937 | Ast.Iterator
(header
,body
,aft
) ->
938 Ast.Iterator
(rule_elem header
, statement body
, aft
)
939 | Ast.Switch
(header
,lb
,decls
,cases
,rb
) ->
940 Ast.Switch
(rule_elem header
,rule_elem lb
,
941 statement_dots decls
,
942 List.map case_line cases
,rule_elem rb
)
943 | Ast.Atomic
(re
) -> Ast.Atomic
(rule_elem re
)
944 | Ast.Disj
(stmt_dots_list
) ->
945 Ast.Disj
(List.map statement_dots stmt_dots_list
)
946 | Ast.Nest
(stmt_dots
,whn
,multi
,bef
,aft
) ->
947 Ast.Nest
(statement_dots stmt_dots
,
948 List.map
(whencode statement_dots statement
) whn
,
950 | Ast.FunDecl
(header
,lbrace
,body
,rbrace
) ->
951 Ast.FunDecl
(rule_elem header
,rule_elem lbrace
,
952 statement_dots body
, rule_elem rbrace
)
953 | Ast.Define
(header
,body
) ->
954 Ast.Define
(rule_elem header
,statement_dots body
)
955 | Ast.Dots
(d
,whn
,bef
,aft
) ->
956 Ast.Dots
(string_mcode d
,
957 List.map
(whencode statement_dots statement
) whn
,bef
,aft
)
958 | Ast.Circles
(d
,whn
,bef
,aft
) ->
959 Ast.Circles
(string_mcode d
,
960 List.map
(whencode statement_dots statement
) whn
,
962 | Ast.Stars
(d
,whn
,bef
,aft
) ->
963 Ast.Stars
(string_mcode d
,
964 List.map
(whencode statement_dots statement
) whn
,bef
,aft
)
965 | Ast.OptStm
(stmt
) -> Ast.OptStm
(statement stmt
)
966 | Ast.UniqueStm
(stmt
) -> Ast.UniqueStm
(statement stmt
)) in
967 let s = stmtfn all_functions
k s in
968 (* better to do this after, in case there is an equality test on the whole
969 statement, eg in free_vars. equality test would require that this
970 subterm not already be changed *)
973 and fninfo
= function
974 Ast.FStorage
(stg
) -> Ast.FStorage
(storage_mcode stg
)
975 | Ast.FType
(ty
) -> Ast.FType
(fullType ty
)
976 | Ast.FInline
(inline
) -> Ast.FInline
(string_mcode inline
)
977 | Ast.FAttr
(attr
) -> Ast.FAttr
(string_mcode attr
)
979 and whencode notfn alwaysfn
= function
980 Ast.WhenNot a
-> Ast.WhenNot
(notfn a
)
981 | Ast.WhenAlways a
-> Ast.WhenAlways
(alwaysfn a
)
982 | Ast.WhenModifier
(x
) -> Ast.WhenModifier
(x
)
983 | Ast.WhenNotTrue
(e
) -> Ast.WhenNotTrue
(rule_elem e
)
984 | Ast.WhenNotFalse
(e
) -> Ast.WhenNotFalse
(rule_elem e
)
989 (match Ast.unwrap c
with
990 Ast.CaseLine
(header
,code
) ->
991 Ast.CaseLine
(rule_elem header
,statement_dots code
)
992 | Ast.OptCase
(case
) -> Ast.OptCase
(case_line case
)) in
993 casefn all_functions
k c
998 (match Ast.unwrap t
with
999 Ast.FILEINFO
(old_file
,new_file
) ->
1000 Ast.FILEINFO
(string_mcode old_file
, string_mcode new_file
)
1001 | Ast.DECL
(stmt
) -> Ast.DECL
(statement stmt
)
1002 | Ast.CODE
(stmt_dots
) -> Ast.CODE
(statement_dots stmt_dots
)
1003 | Ast.ERRORWORDS
(exps
) -> Ast.ERRORWORDS
(List.map expression exps
)) in
1004 topfn all_functions
k t
1008 (*in many cases below, the thing is not even mcode, so we do nothing*)
1009 Ast.FullTypeTag
(ft
) -> Ast.FullTypeTag
(fullType ft
)
1010 | Ast.BaseTypeTag
(bt
) as x
-> x
1011 | Ast.StructUnionTag
(su
) as x
-> x
1012 | Ast.SignTag
(sgn
) as x
-> x
1013 | Ast.IdentTag
(id
) -> Ast.IdentTag
(ident id
)
1014 | Ast.ExpressionTag
(exp
) -> Ast.ExpressionTag
(expression exp
)
1015 | Ast.ConstantTag
(cst
) as x
-> x
1016 | Ast.UnaryOpTag
(unop
) as x
-> x
1017 | Ast.AssignOpTag
(asgnop
) as x
-> x
1018 | Ast.FixOpTag
(fixop
) as x
-> x
1019 | Ast.BinaryOpTag
(binop
) as x
-> x
1020 | Ast.ArithOpTag
(arithop
) as x
-> x
1021 | Ast.LogicalOpTag
(logop
) as x
-> x
1022 | Ast.InitTag
(decl
) -> Ast.InitTag
(initialiser decl
)
1023 | Ast.DeclarationTag
(decl
) -> Ast.DeclarationTag
(declaration decl
)
1024 | Ast.StorageTag
(stg
) as x
-> x
1025 | Ast.IncFileTag
(stg
) as x
-> x
1026 | Ast.Rule_elemTag
(rule
) -> Ast.Rule_elemTag
(rule_elem rule
)
1027 | Ast.StatementTag
(rule
) -> Ast.StatementTag
(statement rule
)
1028 | Ast.CaseLineTag
(case
) -> Ast.CaseLineTag
(case_line case
)
1029 | Ast.ConstVolTag
(cv
) as x
-> x
1030 | Ast.Token
(tok
,info
) as x
-> x
1031 | Ast.Pragma
(str
) as x
-> x
1032 | Ast.Code
(cd
) -> Ast.Code
(top_level cd
)
1033 | Ast.ExprDotsTag
(ed
) -> Ast.ExprDotsTag
(expression_dots ed
)
1034 | Ast.ParamDotsTag
(pd
) -> Ast.ParamDotsTag
(parameter_dots pd
)
1035 | Ast.StmtDotsTag
(sd
) -> Ast.StmtDotsTag
(statement_dots sd
)
1036 | Ast.DeclDotsTag
(sd
) -> Ast.DeclDotsTag
(declaration_dots sd
)
1037 | Ast.TypeCTag
(ty
) -> Ast.TypeCTag
(typeC ty
)
1038 | Ast.ParamTag
(param
) -> Ast.ParamTag
(parameterTypeDef param
)
1039 | Ast.SgrepStartTag
(tok
) as x
-> x
1040 | Ast.SgrepEndTag
(tok
) as x
-> x
in
1041 anyfn all_functions
k a
1044 {rebuilder_ident
= ident
;
1045 rebuilder_expression
= expression
;
1046 rebuilder_fullType
= fullType
;
1047 rebuilder_typeC
= typeC
;
1048 rebuilder_declaration
= declaration
;
1049 rebuilder_initialiser
= initialiser
;
1050 rebuilder_parameter
= parameterTypeDef
;
1051 rebuilder_parameter_list
= parameter_dots
;
1052 rebuilder_rule_elem
= rule_elem
;
1053 rebuilder_statement
= statement
;
1054 rebuilder_case_line
= case_line
;
1055 rebuilder_top_level
= top_level
;
1056 rebuilder_expression_dots
= expression_dots;
1057 rebuilder_statement_dots
= statement_dots
;
1058 rebuilder_declaration_dots
= declaration_dots
;
1059 rebuilder_define_param_dots
= define_param_dots
;
1060 rebuilder_define_param
= define_param
;
1061 rebuilder_define_parameters
= define_parameters
;
1062 rebuilder_anything
= anything
} in