2 module Ast0
= Ast0_cocci
3 module V0
= Visitor_ast0
4 module VT0
= Visitor_ast0_types
6 (* call set_test_pos on test expressions *)
8 (* The goal of this is to identify test expressions in the SmPL file, so that
9 isomorphisms like X != NULL => X are only applied in a test expression context.
11 There is a related check in cocci_vs_c3.ml that in x || ..., a match
12 without the || is only accepted in a test expression context. This uses
13 the annotations in the C file. *)
15 let rec process_exp e
=
16 let e = Ast0.set_test_pos
e in(* allow test isos *)
17 let e = Ast0.set_test_exp
e in(* require that a test expression is matched *)
18 match Ast0.unwrap
e with
19 Ast0.Paren
(lp
,e1
,rp
) ->
20 Ast0.rewrap
e (Ast0.Paren
(lp
,process_exp e1
,rp
))
24 let expression r k
e =
26 match Ast0.unwrap
e with
27 Ast0.CondExpr
(e1
,q
,e2
,c
,e3
) ->
28 Ast0.rewrap
e (Ast0.CondExpr
(process_exp e1
,q
,e2
,c
,e3
))
29 | Ast0.Binary
(e1
,op
,e2
) ->
30 (match Ast0.unwrap_mcode op
with
31 Ast.Logical
(Ast.AndLog
) | Ast.Logical
(Ast.OrLog
) ->
32 Ast0.rewrap
e (Ast0.Binary
(process_exp e1
,op
,process_exp e2
))
34 | Ast0.Unary
(e1
,op
) ->
35 (match Ast0.unwrap_mcode op
with
36 Ast.Not
-> Ast0.rewrap
e (Ast0.Unary
(process_exp e1
,op
))
40 let process_wc = function
41 Ast0.WhenNotTrue
(e) -> Ast0.WhenNotTrue
(process_exp e)
42 | Ast0.WhenNotFalse
(e) -> Ast0.WhenNotFalse
(process_exp e)
47 match Ast0.unwrap
s with
48 Ast0.IfThen
(i
,lp
,e,rp
,s1
,aft
) ->
49 Ast0.rewrap
s (Ast0.IfThen
(i
,lp
,process_exp e,rp
,s1
,aft
))
50 | Ast0.IfThenElse
(i
,lp
,e,rp
,s1
,e1
,s2
,aft
) ->
51 Ast0.rewrap
s (Ast0.IfThenElse
(i
,lp
,process_exp e,rp
,s1
,e1
,s2
,aft
))
52 | Ast0.While
(i
,lp
,e,rp
,s1
,aft
) ->
53 Ast0.rewrap
s (Ast0.While
(i
,lp
,process_exp e,rp
,s1
,aft
))
54 | Ast0.Do
(d
,s1
,w
,lp
,e,rp
,sc
) ->
55 Ast0.rewrap
s (Ast0.Do
(d
,s1
,w
,lp
,process_exp e,rp
,sc
))
56 | Ast0.For
(f
,lp
,e1
,sc1
,Some e2
,sc2
,e3
,rp
,s1
,aft
) ->
58 (Ast0.For
(f
,lp
,e1
,sc1
,Some
(process_exp e2
),sc2
,e3
,rp
,s1
,aft
))
60 Ast0.rewrap
s (Ast0.Dots
(d
,List.map
process_wc wc
))
61 | Ast0.Nest
(l
,s1
,r
,wc
,m
) ->
62 Ast0.rewrap
s (Ast0.Nest
(l
,s1
,r
,List.map
process_wc wc
,m
))
66 {V0.rebuilder_functions
with
67 VT0.rebuilder_exprfn
= expression; VT0.rebuilder_stmtfn
= statement}
69 let process = List.map
set_test_poss.VT0.rebuilder_rec_top_level
71 let process_anything = set_test_poss.VT0.rebuilder_rec_anything