2 * Copyright 2012, INRIA
3 * Julia Lawall, Gilles Muller
4 * Copyright 2010-2011, INRIA, University of Copenhagen
5 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
6 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
7 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
8 * This file is part of Coccinelle.
10 * Coccinelle is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, according to version 2 of the License.
14 * Coccinelle is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
22 * The authors reserve the right to distribute this or future versions of
23 * Coccinelle under other licenses.
27 (* This phase sets the safe_for_multi_decls field, which is normally false,
28 to true for transformations on declarations where the only change is on the
29 declared variable. This is the only kind of change on such a declaration
30 that can safely be done without splitting the declaration. *)
32 module Ast
= Ast_cocci
33 module V
= Visitor_ast
35 let mcode _
(_
,_
,kind
,_
) =
37 Ast.MINUS
(_
,_
,_
,_
) -> true
38 | Ast.PLUS _
-> failwith
"not possible"
39 | Ast.CONTEXT
(_
,info
) -> not
(info
= Ast.NOTHING
)
42 let bind x y
= x
or y
in
43 let option_default = false in
44 let do_nothing r k e
= k e
in
45 let rule_elem r k re
=
47 match Ast.unwrap re
with
48 Ast.FunHeader
(bef
,_
,fninfo
,name
,lp
,params
,rp
) ->
49 bind (mcode r
((),(),bef
,[])) res
50 | Ast.Decl
(bef
,_
,decl
) -> bind (mcode r
((),(),bef
,[])) res
54 match Ast.unwrap i
with
55 Ast.StrInitList
(allminus
,_
,_
,_
,_
) -> allminus
or res
58 V.combiner
bind option_default
59 mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
60 do_nothing do_nothing do_nothing do_nothing do_nothing
61 do_nothing do_nothing do_nothing do_nothing init do_nothing
62 do_nothing rule_elem do_nothing do_nothing do_nothing do_nothing in
63 recursor.V.combiner_fullType
67 match Ast.unwrap
e with
68 Ast.Init
(stg
,ty
,_
,_
,_
,sem
)
69 | Ast.UnInit
(stg
,ty
,_
,sem
) ->
72 Some stg
-> mcode () stg
74 let ft_modif = contains_modif ty
in
75 let sem_modif = mcode () sem
in
76 if not
(stg_modif or ft_modif or sem_modif)
77 then {e with Ast.safe_for_multi_decls
= true}
81 let donothing r k
e = k
e
85 mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode mcode
86 donothing donothing donothing donothing donothing
87 donothing donothing donothing donothing
88 donothing donothing decl donothing
89 donothing donothing donothing donothing in
90 List.map
fn.V.rebuilder_top_level
92 let safe_for_multi_decls rules
=
98 | Ast.InitialScriptRule _
| Ast.FinalScriptRule _
-> r
99 | Ast.CocciRule
(nm
, rule_info
, r
, is_exp
,ruletype
) ->
100 Ast.CocciRule
(nm
, rule_info
,process r
,is_exp
,ruletype
)))