2 * Copyright 2010, INRIA, University of Copenhagen
3 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
4 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
5 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
6 * This file is part of Coccinelle.
8 * Coccinelle is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, according to version 2 of the License.
12 * Coccinelle is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
25 module Ast0
= Ast0_cocci
26 module Ast
= Ast_cocci
28 (* --------------------------------------------------------------------- *)
29 (* Generic traversal: combiner *)
32 treatment of: mcode, identifiers, expressions, fullTypes, types,
33 declarations, statements, toplevels
34 default value for options *)
37 {combiner_ident
: Ast.ident
-> 'a
;
38 combiner_expression
: Ast.expression
-> 'a
;
39 combiner_fullType
: Ast.fullType
-> 'a
;
40 combiner_typeC
: Ast.typeC
-> 'a
;
41 combiner_declaration
: Ast.declaration
-> 'a
;
42 combiner_initialiser
: Ast.initialiser
-> 'a
;
43 combiner_parameter
: Ast.parameterTypeDef
-> 'a
;
44 combiner_parameter_list
: Ast.parameter_list
-> 'a
;
45 combiner_rule_elem
: Ast.rule_elem
-> 'a
;
46 combiner_statement
: Ast.statement
-> 'a
;
47 combiner_case_line
: Ast.case_line
-> 'a
;
48 combiner_top_level
: Ast.top_level
-> 'a
;
49 combiner_anything
: Ast.anything
-> 'a
;
50 combiner_expression_dots
: Ast.expression
Ast.dots
-> 'a
;
51 combiner_statement_dots
: Ast.statement
Ast.dots
-> 'a
;
52 combiner_declaration_dots
: Ast.declaration
Ast.dots
-> 'a
;
53 combiner_initialiser_dots
: Ast.initialiser
Ast.dots
-> 'a
}
55 type ('mc
,'a
) cmcode
= 'a combiner
-> 'mc
Ast_cocci.mcode
-> 'a
56 type ('cd
,'a
) ccode
= 'a combiner
-> ('cd
-> 'a
) -> 'cd
-> 'a
59 let combiner bind option_default
60 meta_mcodefn string_mcodefn const_mcodefn assign_mcodefn fix_mcodefn
61 unary_mcodefn binary_mcodefn
62 cv_mcodefn sign_mcodefn struct_mcodefn storage_mcodefn
64 expdotsfn paramdotsfn stmtdotsfn decldotsfn initdotsfn
65 identfn exprfn ftfn tyfn initfn paramfn declfn rulefn stmtfn casefn
68 let rec loop = function
71 | x
::xs
-> bind x
(loop xs
) in
73 let get_option f
= function
75 | None
-> option_default
in
77 let dotsfn param default all_functions arg
=
79 match Ast.unwrap d
with
80 Ast.DOTS
(l
) | Ast.CIRCLES
(l
) | Ast.STARS
(l
) ->
81 multibind (List.map default l
) in
82 param all_functions
k arg
in
84 let rec meta_mcode x
= meta_mcodefn all_functions x
85 and string_mcode x
= string_mcodefn all_functions x
86 and const_mcode x
= const_mcodefn all_functions x
87 and assign_mcode x
= assign_mcodefn all_functions x
88 and fix_mcode x
= fix_mcodefn all_functions x
89 and unary_mcode x
= unary_mcodefn all_functions x
90 and binary_mcode x
= binary_mcodefn all_functions x
91 and cv_mcode x
= cv_mcodefn all_functions x
92 and sign_mcode x
= sign_mcodefn all_functions x
93 and struct_mcode x
= struct_mcodefn all_functions x
94 and storage_mcode x
= storage_mcodefn all_functions x
95 and inc_file_mcode x
= inc_file_mcodefn all_functions x
97 and expression_dots d
= dotsfn expdotsfn expression all_functions d
98 and parameter_dots d
= dotsfn paramdotsfn parameterTypeDef all_functions d
99 and statement_dots d
= dotsfn stmtdotsfn statement all_functions d
100 and declaration_dots d
= dotsfn decldotsfn declaration all_functions d
101 and initialiser_dots d
= dotsfn initdotsfn initialiser all_functions d
105 match Ast.unwrap i
with
106 Ast.Id
(name
) -> string_mcode name
107 | Ast.MetaId
(name
,_
,_
,_
) -> meta_mcode name
108 | Ast.MetaFunc
(name
,_
,_
,_
) -> meta_mcode name
109 | Ast.MetaLocalFunc
(name
,_
,_
,_
) -> meta_mcode name
110 | Ast.OptIdent
(id
) -> ident id
111 | Ast.UniqueIdent
(id
) -> ident id
in
112 identfn all_functions
k i
116 match Ast.unwrap e
with
117 Ast.Ident
(id
) -> ident id
118 | Ast.Constant
(const
) -> const_mcode const
119 | Ast.FunCall
(fn
,lp
,args
,rp
) ->
120 multibind [expression fn
; string_mcode lp
; expression_dots args
;
122 | Ast.Assignment
(left
,op
,right
,simple
) ->
123 multibind [expression left
; assign_mcode op
; expression right
]
124 | Ast.CondExpr
(exp1
,why
,exp2
,colon
,exp3
) ->
125 multibind [expression exp1
; string_mcode why
;
126 get_option expression exp2
; string_mcode colon
;
128 | Ast.Postfix
(exp
,op
) -> bind
(expression exp
) (fix_mcode op
)
129 | Ast.Infix
(exp
,op
) -> bind
(fix_mcode op
) (expression exp
)
130 | Ast.Unary
(exp
,op
) -> bind
(unary_mcode op
) (expression exp
)
131 | Ast.Binary
(left
,op
,right
) ->
132 multibind [expression left
; binary_mcode op
; expression right
]
133 | Ast.Nested
(left
,op
,right
) ->
134 multibind [expression left
; binary_mcode op
; expression right
]
135 | Ast.Paren
(lp
,exp
,rp
) ->
136 multibind [string_mcode lp
; expression exp
; string_mcode rp
]
137 | Ast.ArrayAccess
(exp1
,lb
,exp2
,rb
) ->
139 [expression exp1
; string_mcode lb
; expression exp2
;
141 | Ast.RecordAccess
(exp
,pt
,field
) ->
142 multibind [expression exp
; string_mcode pt
; ident field
]
143 | Ast.RecordPtAccess
(exp
,ar
,field
) ->
144 multibind [expression exp
; string_mcode ar
; ident field
]
145 | Ast.Cast
(lp
,ty
,rp
,exp
) ->
147 [string_mcode lp
; fullType ty
; string_mcode rp
; expression exp
]
148 | Ast.SizeOfExpr
(szf
,exp
) ->
149 multibind [string_mcode szf
; expression exp
]
150 | Ast.SizeOfType
(szf
,lp
,ty
,rp
) ->
152 [string_mcode szf
; string_mcode lp
; fullType ty
; string_mcode rp
]
153 | Ast.TypeExp
(ty
) -> fullType ty
154 | Ast.MetaErr
(name
,_
,_
,_
)
155 | Ast.MetaExpr
(name
,_
,_
,_
,_
,_
)
156 | Ast.MetaExprList
(name
,_
,_
,_
) -> meta_mcode name
157 | Ast.EComma
(cm
) -> string_mcode cm
158 | Ast.DisjExpr
(exp_list
) -> multibind (List.map expression exp_list
)
159 | Ast.NestExpr
(starter
,expr_dots
,ender
,whencode
,multi
) ->
160 bind
(string_mcode starter
)
161 (bind
(expression_dots expr_dots
)
162 (bind
(string_mcode ender
)
163 (get_option expression whencode
)))
164 | Ast.Edots
(dots
,whencode
) | Ast.Ecircles
(dots
,whencode
)
165 | Ast.Estars
(dots
,whencode
) ->
166 bind
(string_mcode dots
) (get_option expression whencode
)
167 | Ast.OptExp
(exp
) | Ast.UniqueExp
(exp
) ->
169 exprfn all_functions
k e
173 match Ast.unwrap ft
with
174 Ast.Type
(cv
,ty
) -> bind
(get_option cv_mcode cv
) (typeC ty
)
175 | Ast.DisjType
(types
) -> multibind (List.map fullType types
)
176 | Ast.OptType
(ty
) -> fullType ty
177 | Ast.UniqueType
(ty
) -> fullType ty
in
178 ftfn all_functions
k ft
180 and function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) extra
=
181 (* have to put the treatment of the identifier into the right position *)
183 ([fullType ty
; string_mcode lp1
; string_mcode star
] @ extra
@
185 string_mcode lp2
; parameter_dots params
; string_mcode rp2
])
187 and function_type
(ty
,lp1
,params
,rp1
) extra
=
188 (* have to put the treatment of the identifier into the right position *)
190 ([get_option fullType ty
] @ extra
@
191 [string_mcode lp1
; parameter_dots params
; string_mcode rp1
])
193 and array_type
(ty
,lb
,size
,rb
) extra
=
195 ([fullType ty
] @ extra
@
196 [string_mcode lb
; get_option expression size
; string_mcode rb
])
200 match Ast.unwrap ty
with
201 Ast.BaseType
(ty
,strings
) -> multibind (List.map string_mcode strings
)
202 | Ast.SignedT
(sgn
,ty
) -> bind
(sign_mcode sgn
) (get_option typeC ty
)
203 | Ast.Pointer
(ty
,star
) ->
204 bind
(fullType ty
) (string_mcode star
)
205 | Ast.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
206 function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) []
207 | Ast.FunctionType
(_
,ty
,lp1
,params
,rp1
) ->
208 function_type
(ty
,lp1
,params
,rp1
) []
209 | Ast.Array
(ty
,lb
,size
,rb
) -> array_type
(ty
,lb
,size
,rb
) []
210 | Ast.EnumName
(kind
,name
) ->
211 bind
(string_mcode kind
) (get_option ident name
)
212 | Ast.EnumDef
(ty
,lb
,ids
,rb
) ->
214 [fullType ty
; string_mcode lb
; expression_dots ids
;
216 | Ast.StructUnionName
(kind
,name
) ->
217 bind
(struct_mcode kind
) (get_option ident name
)
218 | Ast.StructUnionDef
(ty
,lb
,decls
,rb
) ->
220 [fullType ty
; string_mcode lb
; declaration_dots decls
;
222 | Ast.TypeName
(name
) -> string_mcode name
223 | Ast.MetaType
(name
,_
,_
) -> meta_mcode name
in
224 tyfn all_functions
k ty
226 and named_type ty id
=
227 match Ast.unwrap ty
with
228 Ast.Type
(None
,ty1
) ->
229 (match Ast.unwrap ty1
with
230 Ast.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
231 function_pointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) [ident id
]
232 | Ast.FunctionType
(_
,ty
,lp1
,params
,rp1
) ->
233 function_type
(ty
,lp1
,params
,rp1
) [ident id
]
234 | Ast.Array
(ty
,lb
,size
,rb
) -> array_type
(ty
,lb
,size
,rb
) [ident id
]
235 | _
-> bind
(fullType ty
) (ident id
))
236 | _
-> bind
(fullType ty
) (ident id
)
240 match Ast.unwrap d
with
241 Ast.MetaDecl
(name
,_
,_
) | Ast.MetaField
(name
,_
,_
) -> meta_mcode name
242 | Ast.Init
(stg
,ty
,id
,eq
,ini
,sem
) ->
243 bind
(get_option storage_mcode stg
)
244 (bind
(named_type ty id
)
246 [string_mcode eq
; initialiser ini
; string_mcode sem
]))
247 | Ast.UnInit
(stg
,ty
,id
,sem
) ->
248 bind
(get_option storage_mcode stg
)
249 (bind
(named_type ty id
) (string_mcode sem
))
250 | Ast.MacroDecl
(name
,lp
,args
,rp
,sem
) ->
252 [ident name
; string_mcode lp
; expression_dots args
;
253 string_mcode rp
; string_mcode sem
]
254 | Ast.TyDecl
(ty
,sem
) -> bind
(fullType ty
) (string_mcode sem
)
255 | Ast.Typedef
(stg
,ty
,id
,sem
) ->
256 bind
(string_mcode stg
)
257 (bind
(fullType ty
) (bind
(typeC id
) (string_mcode sem
)))
258 | Ast.DisjDecl
(decls
) -> multibind (List.map declaration decls
)
259 | Ast.Ddots
(dots
,whencode
) ->
260 bind
(string_mcode dots
) (get_option declaration whencode
)
261 | Ast.OptDecl
(decl
) -> declaration decl
262 | Ast.UniqueDecl
(decl
) -> declaration decl
in
263 declfn all_functions
k d
267 match Ast.unwrap i
with
268 Ast.MetaInit
(name
,_
,_
) -> meta_mcode name
269 | Ast.InitExpr
(exp
) -> expression exp
270 | Ast.ArInitList
(lb
,initlist
,rb
) ->
272 [string_mcode lb
; initialiser_dots initlist
; string_mcode rb
]
273 | Ast.StrInitList
(allminus
,lb
,initlist
,rb
,whencode
) ->
276 multibind (List.map initialiser initlist
);
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
) ->
283 ((List.map designator designators
) @
284 [string_mcode eq
; initialiser ini
])
285 | Ast.IComma
(cm
) -> string_mcode cm
286 | Ast.Idots
(dots
,whencode
) ->
287 bind
(string_mcode dots
) (get_option initialiser whencode
)
288 | Ast.OptIni
(i
) -> initialiser i
289 | Ast.UniqueIni
(i
) -> initialiser i
in
290 initfn all_functions
k i
292 and designator
= function
293 Ast.DesignatorField
(dot
,id
) -> bind
(string_mcode dot
) (ident id
)
294 | Ast.DesignatorIndex
(lb
,exp
,rb
) ->
295 bind
(string_mcode lb
) (bind
(expression exp
) (string_mcode rb
))
296 | Ast.DesignatorRange
(lb
,min
,dots
,max
,rb
) ->
298 [string_mcode lb
; expression min
; string_mcode dots
;
299 expression max
; string_mcode rb
]
301 and parameterTypeDef p
=
303 match Ast.unwrap p
with
304 Ast.VoidParam
(ty
) -> fullType ty
305 | Ast.Param
(ty
,Some id
) -> named_type ty id
306 | Ast.Param
(ty
,None
) -> fullType ty
307 | Ast.MetaParam
(name
,_
,_
) -> meta_mcode name
308 | Ast.MetaParamList
(name
,_
,_
,_
) -> meta_mcode name
309 | Ast.PComma
(cm
) -> string_mcode cm
310 | Ast.Pdots
(dots
) -> string_mcode dots
311 | Ast.Pcircles
(dots
) -> string_mcode dots
312 | Ast.OptParam
(param
) -> parameterTypeDef param
313 | Ast.UniqueParam
(param
) -> parameterTypeDef param
in
314 paramfn all_functions
k p
318 match Ast.unwrap re
with
319 Ast.FunHeader
(_
,_
,fi
,name
,lp
,params
,rp
) ->
321 ((List.map fninfo fi
) @
322 [ident name
;string_mcode lp
;parameter_dots params
;
324 | Ast.Decl
(_
,_
,decl
) -> declaration decl
325 | Ast.SeqStart
(brace
) -> string_mcode brace
326 | Ast.SeqEnd
(brace
) -> string_mcode brace
327 | Ast.ExprStatement
(exp
,sem
) ->
328 bind
(expression exp
) (string_mcode sem
)
329 | Ast.IfHeader
(iff
,lp
,exp
,rp
) ->
330 multibind [string_mcode iff
; string_mcode lp
; expression exp
;
332 | Ast.Else
(els
) -> string_mcode els
333 | Ast.WhileHeader
(whl
,lp
,exp
,rp
) ->
334 multibind [string_mcode whl
; string_mcode lp
; expression exp
;
336 | Ast.DoHeader
(d
) -> string_mcode d
337 | Ast.WhileTail
(whl
,lp
,exp
,rp
,sem
) ->
338 multibind [string_mcode whl
; string_mcode lp
; expression exp
;
339 string_mcode rp
; string_mcode sem
]
340 | Ast.ForHeader
(fr
,lp
,e1
,sem1
,e2
,sem2
,e3
,rp
) ->
341 multibind [string_mcode fr
; string_mcode lp
;
342 get_option expression e1
; string_mcode sem1
;
343 get_option expression e2
; string_mcode sem2
;
344 get_option expression e3
; string_mcode rp
]
345 | Ast.IteratorHeader
(nm
,lp
,args
,rp
) ->
346 multibind [ident nm
; string_mcode lp
;
347 expression_dots args
; string_mcode rp
]
348 | Ast.SwitchHeader
(switch
,lp
,exp
,rp
) ->
349 multibind [string_mcode switch
; string_mcode lp
; expression exp
;
351 | Ast.Break
(br
,sem
) -> bind
(string_mcode br
) (string_mcode sem
)
352 | Ast.Continue
(cont
,sem
) -> bind
(string_mcode cont
) (string_mcode sem
)
353 | Ast.Label
(l
,dd
) -> bind
(ident l
) (string_mcode dd
)
354 | Ast.Goto
(goto
,l
,sem
) ->
355 bind
(string_mcode goto
) (bind
(ident l
) (string_mcode sem
))
356 | Ast.Return
(ret
,sem
) -> bind
(string_mcode ret
) (string_mcode sem
)
357 | Ast.ReturnExpr
(ret
,exp
,sem
) ->
358 multibind [string_mcode ret
; expression exp
; string_mcode sem
]
359 | Ast.MetaStmt
(name
,_
,_
,_
) -> meta_mcode name
360 | Ast.MetaStmtList
(name
,_
,_
) -> meta_mcode name
361 | Ast.MetaRuleElem
(name
,_
,_
) -> meta_mcode name
362 | Ast.Exp
(exp
) -> expression exp
363 | Ast.TopExp
(exp
) -> expression exp
364 | Ast.Ty
(ty
) -> fullType ty
365 | Ast.TopInit
(init
) -> initialiser init
366 | Ast.Include
(inc
,name
) -> bind
(string_mcode inc
) (inc_file_mcode name
)
367 | Ast.Undef
(def
,id
) ->
368 multibind [string_mcode def
; ident id
]
369 | Ast.DefineHeader
(def
,id
,params
) ->
370 multibind [string_mcode def
; ident id
; define_parameters params
]
371 | Ast.Default
(def
,colon
) -> bind
(string_mcode def
) (string_mcode colon
)
372 | Ast.Case
(case
,exp
,colon
) ->
373 multibind [string_mcode case
; expression exp
; string_mcode colon
]
374 | Ast.DisjRuleElem
(res
) -> multibind (List.map rule_elem res
) in
375 rulefn all_functions
k re
377 (* not parameterizable for now... *)
378 and define_parameters p
=
380 match Ast.unwrap p
with
381 Ast.NoParams
-> option_default
382 | Ast.DParams
(lp
,params
,rp
) ->
384 [string_mcode lp
; define_param_dots params
; string_mcode rp
] in
387 and define_param_dots d
=
389 match Ast.unwrap d
with
390 Ast.DOTS
(l
) | Ast.CIRCLES
(l
) | Ast.STARS
(l
) ->
391 multibind (List.map define_param l
) in
396 match Ast.unwrap p
with
397 Ast.DParam
(id
) -> ident id
398 | Ast.DPComma
(comma
) -> string_mcode comma
399 | Ast.DPdots
(d
) -> string_mcode d
400 | Ast.DPcircles
(c
) -> string_mcode c
401 | Ast.OptDParam
(dp
) -> define_param dp
402 | Ast.UniqueDParam
(dp
) -> define_param dp
in
405 (* discard the result, because the statement is assumed to be already
406 represented elsewhere in the code *)
407 and process_bef_aft s
=
408 match Ast.get_dots_bef_aft s
with
410 | Ast.DroppingBetweenDots
(stm
,ind
) -> let _ = statement stm
in ()
411 | Ast.AddingBetweenDots
(stm
,ind
) -> let _ = statement stm
in ()
416 match Ast.unwrap s
with
417 Ast.Seq
(lbrace
,body
,rbrace
) ->
418 multibind [rule_elem lbrace
;
419 statement_dots body
; rule_elem rbrace
]
420 | Ast.IfThen
(header
,branch
,_) ->
421 multibind [rule_elem header
; statement branch
]
422 | Ast.IfThenElse
(header
,branch1
,els
,branch2
,_) ->
423 multibind [rule_elem header
; statement branch1
; rule_elem els
;
425 | Ast.While
(header
,body
,_) ->
426 multibind [rule_elem header
; statement body
]
427 | Ast.Do
(header
,body
,tail
) ->
428 multibind [rule_elem header
; statement body
; rule_elem tail
]
429 | Ast.For
(header
,body
,_) -> multibind [rule_elem header
; statement body
]
430 | Ast.Iterator
(header
,body
,_) ->
431 multibind [rule_elem header
; statement body
]
432 | Ast.Switch
(header
,lb
,decls
,cases
,rb
) ->
433 multibind [rule_elem header
;rule_elem lb
;
434 statement_dots decls
;
435 multibind (List.map case_line cases
);
437 | Ast.Atomic
(re
) -> rule_elem re
438 | Ast.Disj
(stmt_dots_list
) ->
439 multibind (List.map statement_dots stmt_dots_list
)
440 | Ast.Nest
(starter
,stmt_dots
,ender
,whn
,_,_,_) ->
441 bind
(string_mcode starter
)
442 (bind
(statement_dots stmt_dots
)
443 (bind
(string_mcode ender
)
445 (List.map
(whencode statement_dots statement
) whn
))))
446 | Ast.FunDecl
(header
,lbrace
,body
,rbrace
) ->
447 multibind [rule_elem header
; rule_elem lbrace
;
448 statement_dots body
; rule_elem rbrace
]
449 | Ast.Define
(header
,body
) ->
450 bind
(rule_elem header
) (statement_dots body
)
451 | Ast.Dots
(d
,whn
,_,_) | Ast.Circles
(d
,whn
,_,_) | Ast.Stars
(d
,whn
,_,_) ->
452 bind
(string_mcode d
)
453 (multibind (List.map
(whencode statement_dots statement
) whn
))
454 | Ast.OptStm
(stmt
) | Ast.UniqueStm
(stmt
) ->
456 stmtfn all_functions
k s
458 and fninfo
= function
459 Ast.FStorage
(stg
) -> storage_mcode stg
460 | Ast.FType
(ty
) -> fullType ty
461 | Ast.FInline
(inline
) -> string_mcode inline
462 | Ast.FAttr
(attr
) -> string_mcode attr
464 and whencode notfn alwaysfn
= function
465 Ast.WhenNot a
-> notfn a
466 | Ast.WhenAlways a
-> alwaysfn a
467 | Ast.WhenModifier
(_) -> option_default
468 | Ast.WhenNotTrue
(e
) -> rule_elem e
469 | Ast.WhenNotFalse
(e
) -> rule_elem e
473 match Ast.unwrap c
with
474 Ast.CaseLine
(header
,code
) ->
475 bind
(rule_elem header
) (statement_dots code
)
476 | Ast.OptCase
(case
) -> case_line case
in
477 casefn all_functions
k c
481 match Ast.unwrap t
with
482 Ast.FILEINFO
(old_file
,new_file
) ->
483 bind
(string_mcode old_file
) (string_mcode new_file
)
484 | Ast.DECL
(stmt
) -> statement stmt
485 | Ast.CODE
(stmt_dots
) -> statement_dots stmt_dots
486 | Ast.ERRORWORDS
(exps
) -> multibind (List.map expression exps
) in
487 topfn all_functions
k t
491 (*in many cases below, the thing is not even mcode, so we do nothing*)
492 Ast.FullTypeTag
(ft
) -> fullType ft
493 | Ast.BaseTypeTag
(bt
) -> option_default
494 | Ast.StructUnionTag
(su
) -> option_default
495 | Ast.SignTag
(sgn
) -> option_default
496 | Ast.IdentTag
(id
) -> ident id
497 | Ast.ExpressionTag
(exp
) -> expression exp
498 | Ast.ConstantTag
(cst
) -> option_default
499 | Ast.UnaryOpTag
(unop
) -> option_default
500 | Ast.AssignOpTag
(asgnop
) -> option_default
501 | Ast.FixOpTag
(fixop
) -> option_default
502 | Ast.BinaryOpTag
(binop
) -> option_default
503 | Ast.ArithOpTag
(arithop
) -> option_default
504 | Ast.LogicalOpTag
(logop
) -> option_default
505 | Ast.DeclarationTag
(decl
) -> declaration decl
506 | Ast.InitTag
(ini
) -> initialiser ini
507 | Ast.StorageTag
(stg
) -> option_default
508 | Ast.IncFileTag
(stg
) -> option_default
509 | Ast.Rule_elemTag
(rule
) -> rule_elem rule
510 | Ast.StatementTag
(rule
) -> statement rule
511 | Ast.CaseLineTag
(case
) -> case_line case
512 | Ast.ConstVolTag
(cv
) -> option_default
513 | Ast.Token
(tok
,info
) -> option_default
514 | Ast.Pragma
(str
) -> option_default
515 | Ast.Code
(cd
) -> top_level cd
516 | Ast.ExprDotsTag
(ed
) -> expression_dots ed
517 | Ast.ParamDotsTag
(pd
) -> parameter_dots pd
518 | Ast.StmtDotsTag
(sd
) -> statement_dots sd
519 | Ast.DeclDotsTag
(sd
) -> declaration_dots sd
520 | Ast.TypeCTag
(ty
) -> typeC ty
521 | Ast.ParamTag
(param
) -> parameterTypeDef param
522 | Ast.SgrepStartTag
(tok
) -> option_default
523 | Ast.SgrepEndTag
(tok
) -> option_default
in
524 anyfn all_functions
k a
527 {combiner_ident
= ident
;
528 combiner_expression
= expression
;
529 combiner_fullType
= fullType
;
530 combiner_typeC
= typeC
;
531 combiner_declaration
= declaration
;
532 combiner_initialiser
= initialiser
;
533 combiner_parameter
= parameterTypeDef
;
534 combiner_parameter_list
= parameter_dots
;
535 combiner_rule_elem
= rule_elem
;
536 combiner_statement
= statement
;
537 combiner_case_line
= case_line
;
538 combiner_top_level
= top_level
;
539 combiner_anything
= anything
;
540 combiner_expression_dots
= expression_dots
;
541 combiner_statement_dots
= statement_dots
;
542 combiner_declaration_dots
= declaration_dots
;
543 combiner_initialiser_dots
= initialiser_dots
} in
546 (* ---------------------------------------------------------------------- *)
548 type 'a inout
= 'a
-> 'a
(* for specifying the type of rebuilder *)
551 {rebuilder_ident
: Ast.ident inout
;
552 rebuilder_expression
: Ast.expression inout
;
553 rebuilder_fullType
: Ast.fullType inout
;
554 rebuilder_typeC
: Ast.typeC inout
;
555 rebuilder_declaration
: Ast.declaration inout
;
556 rebuilder_initialiser
: Ast.initialiser inout
;
557 rebuilder_parameter
: Ast.parameterTypeDef inout
;
558 rebuilder_parameter_list
: Ast.parameter_list inout
;
559 rebuilder_statement
: Ast.statement inout
;
560 rebuilder_case_line
: Ast.case_line inout
;
561 rebuilder_rule_elem
: Ast.rule_elem inout
;
562 rebuilder_top_level
: Ast.top_level inout
;
563 rebuilder_expression_dots
: Ast.expression
Ast.dots inout
;
564 rebuilder_statement_dots
: Ast.statement
Ast.dots inout
;
565 rebuilder_declaration_dots
: Ast.declaration
Ast.dots inout
;
566 rebuilder_initialiser_dots
: Ast.initialiser
Ast.dots inout
;
567 rebuilder_define_param_dots
: Ast.define_param
Ast.dots inout
;
568 rebuilder_define_param
: Ast.define_param inout
;
569 rebuilder_define_parameters
: Ast.define_parameters inout
;
570 rebuilder_anything
: Ast.anything inout
}
572 type 'mc rmcode
= 'mc
Ast.mcode inout
573 type 'cd rcode
= rebuilder
-> ('cd inout
) -> 'cd inout
577 meta_mcode string_mcode const_mcode assign_mcode fix_mcode unary_mcode
578 binary_mcode cv_mcode sign_mcode struct_mcode storage_mcode
580 expdotsfn paramdotsfn stmtdotsfn decldotsfn initdotsfn
581 identfn exprfn ftfn tyfn initfn paramfn declfn rulefn stmtfn casefn
583 let get_option f
= function
587 let dotsfn param default all_functions arg
=
590 (match Ast.unwrap d
with
591 Ast.DOTS
(l
) -> Ast.DOTS
(List.map default l
)
592 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map default l
)
593 | Ast.STARS
(l
) -> Ast.STARS
(List.map default l
)) in
594 param all_functions
k arg
in
596 let rec expression_dots d
= dotsfn expdotsfn expression all_functions d
597 and parameter_dots d
= dotsfn paramdotsfn parameterTypeDef all_functions d
598 and statement_dots d
= dotsfn stmtdotsfn statement all_functions d
599 and declaration_dots d
= dotsfn decldotsfn declaration all_functions d
600 and initialiser_dots d
= dotsfn initdotsfn initialiser all_functions d
605 (match Ast.unwrap i
with
606 Ast.Id
(name
) -> Ast.Id
(string_mcode name
)
607 | Ast.MetaId
(name
,constraints
,keep
,inherited
) ->
608 Ast.MetaId
(meta_mcode name
,constraints
,keep
,inherited
)
609 | Ast.MetaFunc
(name
,constraints
,keep
,inherited
) ->
610 Ast.MetaFunc
(meta_mcode name
,constraints
,keep
,inherited
)
611 | Ast.MetaLocalFunc
(name
,constraints
,keep
,inherited
) ->
612 Ast.MetaLocalFunc
(meta_mcode name
,constraints
,keep
,inherited
)
613 | Ast.OptIdent
(id
) -> Ast.OptIdent
(ident id
)
614 | Ast.UniqueIdent
(id
) -> Ast.UniqueIdent
(ident id
)) in
615 identfn all_functions
k i
620 (match Ast.unwrap e
with
621 Ast.Ident
(id
) -> Ast.Ident
(ident id
)
622 | Ast.Constant
(const
) -> Ast.Constant
(const_mcode const
)
623 | Ast.FunCall
(fn
,lp
,args
,rp
) ->
624 Ast.FunCall
(expression fn
, string_mcode lp
, expression_dots args
,
626 | Ast.Assignment
(left
,op
,right
,simple
) ->
627 Ast.Assignment
(expression left
, assign_mcode op
, expression right
,
629 | Ast.CondExpr
(exp1
,why
,exp2
,colon
,exp3
) ->
630 Ast.CondExpr
(expression exp1
, string_mcode why
,
631 get_option expression exp2
, string_mcode colon
,
633 | Ast.Postfix
(exp
,op
) -> Ast.Postfix
(expression exp
,fix_mcode op
)
634 | Ast.Infix
(exp
,op
) -> Ast.Infix
(expression exp
,fix_mcode op
)
635 | Ast.Unary
(exp
,op
) -> Ast.Unary
(expression exp
,unary_mcode op
)
636 | Ast.Binary
(left
,op
,right
) ->
637 Ast.Binary
(expression left
, binary_mcode op
, expression right
)
638 | Ast.Nested
(left
,op
,right
) ->
639 Ast.Nested
(expression left
, binary_mcode op
, expression right
)
640 | Ast.Paren
(lp
,exp
,rp
) ->
641 Ast.Paren
(string_mcode lp
, expression exp
, string_mcode rp
)
642 | Ast.ArrayAccess
(exp1
,lb
,exp2
,rb
) ->
643 Ast.ArrayAccess
(expression exp1
, string_mcode lb
, expression exp2
,
645 | Ast.RecordAccess
(exp
,pt
,field
) ->
646 Ast.RecordAccess
(expression exp
, string_mcode pt
, ident field
)
647 | Ast.RecordPtAccess
(exp
,ar
,field
) ->
648 Ast.RecordPtAccess
(expression exp
, string_mcode ar
, ident field
)
649 | Ast.Cast
(lp
,ty
,rp
,exp
) ->
650 Ast.Cast
(string_mcode lp
, fullType ty
, string_mcode rp
,
652 | Ast.SizeOfExpr
(szf
,exp
) ->
653 Ast.SizeOfExpr
(string_mcode szf
, expression exp
)
654 | Ast.SizeOfType
(szf
,lp
,ty
,rp
) ->
655 Ast.SizeOfType
(string_mcode szf
,string_mcode lp
, fullType ty
,
657 | Ast.TypeExp
(ty
) -> Ast.TypeExp
(fullType ty
)
658 | Ast.MetaErr
(name
,constraints
,keep
,inherited
) ->
659 Ast.MetaErr
(meta_mcode name
,constraints
,keep
,inherited
)
660 | Ast.MetaExpr
(name
,constraints
,keep
,ty
,form
,inherited
) ->
661 Ast.MetaExpr
(meta_mcode name
,constraints
,keep
,ty
,form
,inherited
)
662 | Ast.MetaExprList
(name
,lenname_inh
,keep
,inherited
) ->
663 Ast.MetaExprList
(meta_mcode name
,lenname_inh
,keep
,inherited
)
664 | Ast.EComma
(cm
) -> Ast.EComma
(string_mcode cm
)
665 | Ast.DisjExpr
(exp_list
) -> Ast.DisjExpr
(List.map expression exp_list
)
666 | Ast.NestExpr
(starter
,expr_dots
,ender
,whencode
,multi
) ->
667 Ast.NestExpr
(string_mcode starter
,expression_dots expr_dots
,
669 get_option expression whencode
,multi
)
670 | Ast.Edots
(dots
,whencode
) ->
671 Ast.Edots
(string_mcode dots
,get_option expression whencode
)
672 | Ast.Ecircles
(dots
,whencode
) ->
673 Ast.Ecircles
(string_mcode dots
,get_option expression whencode
)
674 | Ast.Estars
(dots
,whencode
) ->
675 Ast.Estars
(string_mcode dots
,get_option expression whencode
)
676 | Ast.OptExp
(exp
) -> Ast.OptExp
(expression exp
)
677 | Ast.UniqueExp
(exp
) -> Ast.UniqueExp
(expression exp
)) in
678 exprfn all_functions
k e
683 (match Ast.unwrap ft
with
684 Ast.Type
(cv
,ty
) -> Ast.Type
(get_option cv_mcode cv
, typeC ty
)
685 | Ast.DisjType
(types
) -> Ast.DisjType
(List.map fullType types
)
686 | Ast.OptType
(ty
) -> Ast.OptType
(fullType ty
)
687 | Ast.UniqueType
(ty
) -> Ast.UniqueType
(fullType ty
)) in
688 ftfn all_functions
k ft
693 (match Ast.unwrap ty
with
694 Ast.BaseType
(ty
,strings
) ->
695 Ast.BaseType
(ty
, List.map string_mcode strings
)
696 | Ast.SignedT
(sgn
,ty
) ->
697 Ast.SignedT
(sign_mcode sgn
,get_option typeC ty
)
698 | Ast.Pointer
(ty
,star
) ->
699 Ast.Pointer
(fullType ty
, string_mcode star
)
700 | Ast.FunctionPointer
(ty
,lp1
,star
,rp1
,lp2
,params
,rp2
) ->
701 Ast.FunctionPointer
(fullType ty
,string_mcode lp1
,string_mcode star
,
702 string_mcode rp1
,string_mcode lp2
,
703 parameter_dots params
,
705 | Ast.FunctionType
(allminus
,ty
,lp
,params
,rp
) ->
706 Ast.FunctionType
(allminus
,get_option fullType ty
,string_mcode lp
,
707 parameter_dots params
,string_mcode rp
)
708 | Ast.Array
(ty
,lb
,size
,rb
) ->
709 Ast.Array
(fullType ty
, string_mcode lb
,
710 get_option expression size
, string_mcode rb
)
711 | Ast.EnumName
(kind
,name
) ->
712 Ast.EnumName
(string_mcode kind
, get_option ident name
)
713 | Ast.EnumDef
(ty
,lb
,ids
,rb
) ->
714 Ast.EnumDef
(fullType ty
, string_mcode lb
, expression_dots ids
,
716 | Ast.StructUnionName
(kind
,name
) ->
717 Ast.StructUnionName
(struct_mcode kind
, get_option ident name
)
718 | Ast.StructUnionDef
(ty
,lb
,decls
,rb
) ->
719 Ast.StructUnionDef
(fullType ty
,
720 string_mcode lb
, declaration_dots decls
,
722 | Ast.TypeName
(name
) -> Ast.TypeName
(string_mcode name
)
723 | Ast.MetaType
(name
,keep
,inherited
) ->
724 Ast.MetaType
(meta_mcode name
,keep
,inherited
)) in
725 tyfn all_functions
k ty
730 (match Ast.unwrap d
with
731 Ast.MetaDecl
(name
,keep
,inherited
) ->
732 Ast.MetaDecl
(meta_mcode name
,keep
,inherited
)
733 | Ast.MetaField
(name
,keep
,inherited
) ->
734 Ast.MetaField
(meta_mcode name
,keep
,inherited
)
735 | Ast.Init
(stg
,ty
,id
,eq
,ini
,sem
) ->
736 Ast.Init
(get_option storage_mcode stg
, fullType ty
, ident id
,
737 string_mcode eq
, initialiser ini
, string_mcode sem
)
738 | Ast.UnInit
(stg
,ty
,id
,sem
) ->
739 Ast.UnInit
(get_option storage_mcode stg
, fullType ty
, ident id
,
741 | Ast.MacroDecl
(name
,lp
,args
,rp
,sem
) ->
742 Ast.MacroDecl
(ident name
, string_mcode lp
, expression_dots args
,
743 string_mcode rp
,string_mcode sem
)
744 | Ast.TyDecl
(ty
,sem
) -> Ast.TyDecl
(fullType ty
, string_mcode sem
)
745 | Ast.Typedef
(stg
,ty
,id
,sem
) ->
746 Ast.Typedef
(string_mcode stg
, fullType ty
, typeC id
,
748 | Ast.DisjDecl
(decls
) -> Ast.DisjDecl
(List.map declaration decls
)
749 | Ast.Ddots
(dots
,whencode
) ->
750 Ast.Ddots
(string_mcode dots
, get_option declaration whencode
)
751 | Ast.OptDecl
(decl
) -> Ast.OptDecl
(declaration decl
)
752 | Ast.UniqueDecl
(decl
) -> Ast.UniqueDecl
(declaration decl
)) in
753 declfn all_functions
k d
758 (match Ast.unwrap i
with
759 Ast.MetaInit
(name
,keep
,inherited
) ->
760 Ast.MetaInit
(meta_mcode name
,keep
,inherited
)
761 | Ast.InitExpr
(exp
) -> Ast.InitExpr
(expression exp
)
762 | Ast.ArInitList
(lb
,initlist
,rb
) ->
763 Ast.ArInitList
(string_mcode lb
, initialiser_dots initlist
,
765 | Ast.StrInitList
(allminus
,lb
,initlist
,rb
,whencode
) ->
766 Ast.StrInitList
(allminus
,
767 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
) ->
773 (List.map designator designators
, string_mcode eq
,
775 | Ast.IComma
(cm
) -> Ast.IComma
(string_mcode cm
)
776 | Ast.Idots
(dots
,whencode
) ->
777 Ast.Idots
(string_mcode dots
,get_option initialiser whencode
)
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.Undef
(def
,id
) ->
868 Ast.Undef
(string_mcode def
,ident id
)
869 | Ast.DefineHeader
(def
,id
,params
) ->
870 Ast.DefineHeader
(string_mcode def
,ident id
,
871 define_parameters params
)
872 | Ast.Default
(def
,colon
) ->
873 Ast.Default
(string_mcode def
,string_mcode colon
)
874 | Ast.Case
(case
,exp
,colon
) ->
875 Ast.Case
(string_mcode case
,expression exp
,string_mcode colon
)
876 | Ast.DisjRuleElem
(res
) -> Ast.DisjRuleElem
(List.map rule_elem res
)) in
877 rulefn all_functions
k re
879 (* not parameterizable for now... *)
880 and define_parameters p
=
883 (match Ast.unwrap p
with
884 Ast.NoParams
-> Ast.NoParams
885 | Ast.DParams
(lp
,params
,rp
) ->
886 Ast.DParams
(string_mcode lp
,define_param_dots params
,
890 and define_param_dots d
=
893 (match Ast.unwrap d
with
894 Ast.DOTS
(l
) -> Ast.DOTS
(List.map define_param l
)
895 | Ast.CIRCLES
(l
) -> Ast.CIRCLES
(List.map define_param l
)
896 | Ast.STARS
(l
) -> Ast.STARS
(List.map define_param l
)) in
902 (match Ast.unwrap p
with
903 Ast.DParam
(id
) -> Ast.DParam
(ident id
)
904 | Ast.DPComma
(comma
) -> Ast.DPComma
(string_mcode comma
)
905 | Ast.DPdots
(d
) -> Ast.DPdots
(string_mcode d
)
906 | Ast.DPcircles
(c
) -> Ast.DPcircles
(string_mcode c
)
907 | Ast.OptDParam
(dp
) -> Ast.OptDParam
(define_param dp
)
908 | Ast.UniqueDParam
(dp
) -> Ast.UniqueDParam
(define_param dp
)) in
911 and process_bef_aft s
=
913 (match Ast.get_dots_bef_aft s
with
914 Ast.NoDots
-> Ast.NoDots
915 | Ast.DroppingBetweenDots
(stm
,ind
) ->
916 Ast.DroppingBetweenDots
(statement stm
,ind
)
917 | Ast.AddingBetweenDots
(stm
,ind
) ->
918 Ast.AddingBetweenDots
(statement stm
,ind
))
924 (match Ast.unwrap s
with
925 Ast.Seq
(lbrace
,body
,rbrace
) ->
926 Ast.Seq
(rule_elem lbrace
,
927 statement_dots body
, rule_elem rbrace
)
928 | Ast.IfThen
(header
,branch
,aft
) ->
929 Ast.IfThen
(rule_elem header
, statement branch
,aft
)
930 | Ast.IfThenElse
(header
,branch1
,els
,branch2
,aft
) ->
931 Ast.IfThenElse
(rule_elem header
, statement branch1
, rule_elem els
,
932 statement branch2
, aft
)
933 | Ast.While
(header
,body
,aft
) ->
934 Ast.While
(rule_elem header
, statement body
, aft
)
935 | Ast.Do
(header
,body
,tail
) ->
936 Ast.Do
(rule_elem header
, statement body
, rule_elem tail
)
937 | Ast.For
(header
,body
,aft
) ->
938 Ast.For
(rule_elem header
, statement body
, aft
)
939 | Ast.Iterator
(header
,body
,aft
) ->
940 Ast.Iterator
(rule_elem header
, statement body
, aft
)
941 | Ast.Switch
(header
,lb
,decls
,cases
,rb
) ->
942 Ast.Switch
(rule_elem header
,rule_elem lb
,
943 statement_dots decls
,
944 List.map case_line cases
,rule_elem rb
)
945 | Ast.Atomic
(re
) -> Ast.Atomic
(rule_elem re
)
946 | Ast.Disj
(stmt_dots_list
) ->
947 Ast.Disj
(List.map statement_dots stmt_dots_list
)
948 | Ast.Nest
(starter
,stmt_dots
,ender
,whn
,multi
,bef
,aft
) ->
949 Ast.Nest
(string_mcode starter
,statement_dots stmt_dots
,
951 List.map
(whencode statement_dots statement
) whn
,
953 | Ast.FunDecl
(header
,lbrace
,body
,rbrace
) ->
954 Ast.FunDecl
(rule_elem header
,rule_elem lbrace
,
955 statement_dots body
, rule_elem rbrace
)
956 | Ast.Define
(header
,body
) ->
957 Ast.Define
(rule_elem header
,statement_dots body
)
958 | Ast.Dots
(d
,whn
,bef
,aft
) ->
959 Ast.Dots
(string_mcode d
,
960 List.map
(whencode statement_dots statement
) whn
,bef
,aft
)
961 | Ast.Circles
(d
,whn
,bef
,aft
) ->
962 Ast.Circles
(string_mcode d
,
963 List.map
(whencode statement_dots statement
) whn
,
965 | Ast.Stars
(d
,whn
,bef
,aft
) ->
966 Ast.Stars
(string_mcode d
,
967 List.map
(whencode statement_dots statement
) whn
,bef
,aft
)
968 | Ast.OptStm
(stmt
) -> Ast.OptStm
(statement stmt
)
969 | Ast.UniqueStm
(stmt
) -> Ast.UniqueStm
(statement stmt
)) in
970 let s = stmtfn all_functions
k s in
971 (* better to do this after, in case there is an equality test on the whole
972 statement, eg in free_vars. equality test would require that this
973 subterm not already be changed *)
976 and fninfo
= function
977 Ast.FStorage
(stg
) -> Ast.FStorage
(storage_mcode stg
)
978 | Ast.FType
(ty
) -> Ast.FType
(fullType ty
)
979 | Ast.FInline
(inline
) -> Ast.FInline
(string_mcode inline
)
980 | Ast.FAttr
(attr
) -> Ast.FAttr
(string_mcode attr
)
982 and whencode notfn alwaysfn
= function
983 Ast.WhenNot a
-> Ast.WhenNot
(notfn a
)
984 | Ast.WhenAlways a
-> Ast.WhenAlways
(alwaysfn a
)
985 | Ast.WhenModifier
(x
) -> Ast.WhenModifier
(x
)
986 | Ast.WhenNotTrue
(e
) -> Ast.WhenNotTrue
(rule_elem e
)
987 | Ast.WhenNotFalse
(e
) -> Ast.WhenNotFalse
(rule_elem e
)
992 (match Ast.unwrap c
with
993 Ast.CaseLine
(header
,code
) ->
994 Ast.CaseLine
(rule_elem header
,statement_dots code
)
995 | Ast.OptCase
(case
) -> Ast.OptCase
(case_line case
)) in
996 casefn all_functions
k c
1001 (match Ast.unwrap t
with
1002 Ast.FILEINFO
(old_file
,new_file
) ->
1003 Ast.FILEINFO
(string_mcode old_file
, string_mcode new_file
)
1004 | Ast.DECL
(stmt
) -> Ast.DECL
(statement stmt
)
1005 | Ast.CODE
(stmt_dots
) -> Ast.CODE
(statement_dots stmt_dots
)
1006 | Ast.ERRORWORDS
(exps
) -> Ast.ERRORWORDS
(List.map expression exps
)) in
1007 topfn all_functions
k t
1011 (*in many cases below, the thing is not even mcode, so we do nothing*)
1012 Ast.FullTypeTag
(ft
) -> Ast.FullTypeTag
(fullType ft
)
1013 | Ast.BaseTypeTag
(bt
) as x
-> x
1014 | Ast.StructUnionTag
(su
) as x
-> x
1015 | Ast.SignTag
(sgn
) as x
-> x
1016 | Ast.IdentTag
(id
) -> Ast.IdentTag
(ident id
)
1017 | Ast.ExpressionTag
(exp
) -> Ast.ExpressionTag
(expression exp
)
1018 | Ast.ConstantTag
(cst
) as x
-> x
1019 | Ast.UnaryOpTag
(unop
) as x
-> x
1020 | Ast.AssignOpTag
(asgnop
) as x
-> x
1021 | Ast.FixOpTag
(fixop
) as x
-> x
1022 | Ast.BinaryOpTag
(binop
) as x
-> x
1023 | Ast.ArithOpTag
(arithop
) as x
-> x
1024 | Ast.LogicalOpTag
(logop
) as x
-> x
1025 | Ast.InitTag
(decl
) -> Ast.InitTag
(initialiser decl
)
1026 | Ast.DeclarationTag
(decl
) -> Ast.DeclarationTag
(declaration decl
)
1027 | Ast.StorageTag
(stg
) as x
-> x
1028 | Ast.IncFileTag
(stg
) as x
-> x
1029 | Ast.Rule_elemTag
(rule
) -> Ast.Rule_elemTag
(rule_elem rule
)
1030 | Ast.StatementTag
(rule
) -> Ast.StatementTag
(statement rule
)
1031 | Ast.CaseLineTag
(case
) -> Ast.CaseLineTag
(case_line case
)
1032 | Ast.ConstVolTag
(cv
) as x
-> x
1033 | Ast.Token
(tok
,info
) as x
-> x
1034 | Ast.Pragma
(str
) as x
-> x
1035 | Ast.Code
(cd
) -> Ast.Code
(top_level cd
)
1036 | Ast.ExprDotsTag
(ed
) -> Ast.ExprDotsTag
(expression_dots ed
)
1037 | Ast.ParamDotsTag
(pd
) -> Ast.ParamDotsTag
(parameter_dots pd
)
1038 | Ast.StmtDotsTag
(sd
) -> Ast.StmtDotsTag
(statement_dots sd
)
1039 | Ast.DeclDotsTag
(sd
) -> Ast.DeclDotsTag
(declaration_dots sd
)
1040 | Ast.TypeCTag
(ty
) -> Ast.TypeCTag
(typeC ty
)
1041 | Ast.ParamTag
(param
) -> Ast.ParamTag
(parameterTypeDef param
)
1042 | Ast.SgrepStartTag
(tok
) as x
-> x
1043 | Ast.SgrepEndTag
(tok
) as x
-> x
in
1044 anyfn all_functions
k a
1047 {rebuilder_ident
= ident
;
1048 rebuilder_expression
= expression
;
1049 rebuilder_fullType
= fullType
;
1050 rebuilder_typeC
= typeC
;
1051 rebuilder_declaration
= declaration
;
1052 rebuilder_initialiser
= initialiser
;
1053 rebuilder_parameter
= parameterTypeDef
;
1054 rebuilder_parameter_list
= parameter_dots
;
1055 rebuilder_rule_elem
= rule_elem
;
1056 rebuilder_statement
= statement
;
1057 rebuilder_case_line
= case_line
;
1058 rebuilder_top_level
= top_level
;
1059 rebuilder_expression_dots
= expression_dots;
1060 rebuilder_statement_dots
= statement_dots
;
1061 rebuilder_declaration_dots
= declaration_dots
;
1062 rebuilder_initialiser_dots
= initialiser_dots
;
1063 rebuilder_define_param_dots
= define_param_dots
;
1064 rebuilder_define_param
= define_param
;
1065 rebuilder_define_parameters
= define_parameters
;
1066 rebuilder_anything
= anything
} in