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