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 module Ast
= Ast_cocci
28 module Past
= Ast_popl
30 (* --------------------------------------------------------------------- *)
34 Pretty_print_cocci.statement
"" s
;
35 Format.print_newline
();
36 failwith
"complex statements not supported" in
37 match Ast.unwrap s
with
39 (match Ast.unwrap ast
with
40 Ast.ExprStatement
(_
,_
) -> Past.Atomic ast
41 | Ast.Exp
(_
) -> Past.Atomic ast
42 | Ast.Decl
(_
,_
,_
) -> Past.Atomic ast
43 | Ast.ReturnExpr
(_
,_
,_
) -> Past.Atomic ast
44 | Ast.MetaStmt
(_
,_
,_
,_
) when inif
-> Past.Atomic ast
45 | Ast.DisjRuleElem
(_
) -> Past.Atomic ast
50 match Ast.unwrap s
with
51 Ast.Atomic
(ast
) -> Past.Term
(term s
false,dots_bef_aft s
false)
52 | Ast.IfThen
(header
,body
,aft
) ->
54 Past.IfThen
(Past.Atomic header
,term body
true,aft
),
56 | Ast.Disj
(stm1
::stm2
::stmts
) ->
60 Past.Or
(Past.Seq
(prev
,Past.Empty
),stm_list cur
))
61 (Past.Or
(stm_list stm1
,stm_list stm2
)) stmts
62 | Ast.Dots
(dots
,whencodes
,_
,_
) ->
67 Ast.WhenNot
(a
) -> Past.When
(prev
,stm_list a
)
68 | _
-> failwith
"only when != supported")
70 | Ast.Nest
(starter
,stmt_dots
,ender
,whencodes
,false,_
,_
) ->
71 (match Ast.get_mcodekind starter
with
72 Ast.MINUS _
-> failwith
"only context nests supported"
74 let nest = Past.Nest
(stm_list stmt_dots
) in
79 Ast.WhenNot
(a
) -> Past.When
(prev
,stm_list a
)
80 | _
-> failwith
"only when != supported")
83 Pretty_print_cocci.statement
"" s
;
84 failwith
"unsupported statement3"
86 and dots_bef_aft s inif
=
87 match Ast.get_dots_bef_aft s
with
88 Ast.AddingBetweenDots
(brace_term
,n
) ->
89 Past.AddingBetweenDots
(term brace_term inif
,n
)
90 | Ast.DroppingBetweenDots
(brace_term
,n
) ->
91 Past.DroppingBetweenDots
(term brace_term inif
,n
)
92 | Ast.NoDots
-> Past.NoDots
95 match Ast.unwrap s
with
98 (function cur
-> function rest
-> Past.Seq
(stm cur
, rest
))
100 | _
-> failwith
"only DOTS handled"
103 match Ast.unwrap s
with
104 Ast.CODE
(stmt_dots
) -> stm_list stmt_dots
105 | _
-> failwith
"only CODE handled"