2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
45 module Ast
= Ast_cocci
46 module Past
= Ast_popl
48 (* --------------------------------------------------------------------- *)
52 Pretty_print_cocci.statement
"" s
;
53 Format.print_newline
();
54 failwith
"complex statements not supported" in
55 match Ast.unwrap s
with
57 (match Ast.unwrap ast
with
58 Ast.ExprStatement
(_
,_
) -> Past.Atomic ast
59 | Ast.Exp
(_
) -> Past.Atomic ast
60 | Ast.Decl
(_
,_
,_
) -> Past.Atomic ast
61 | Ast.ReturnExpr
(_
,_
,_
) -> Past.Atomic ast
62 | Ast.MetaStmt
(_
,_
,_
,_
) when inif
-> Past.Atomic ast
63 | Ast.DisjRuleElem
(_
) -> Past.Atomic ast
68 match Ast.unwrap s
with
69 Ast.Atomic
(ast
) -> Past.Term
(term s
false,dots_bef_aft s
false)
70 | Ast.IfThen
(header
,body
,aft
) ->
72 Past.IfThen
(Past.Atomic header
,term body
true,aft
),
74 | Ast.Disj
(stm1
::stm2
::stmts
) ->
78 Past.Or
(Past.Seq
(prev
,Past.Empty
),stm_list cur
))
79 (Past.Or
(stm_list stm1
,stm_list stm2
)) stmts
80 | Ast.Dots
(dots
,whencodes
,_
,_
) ->
85 Ast.WhenNot
(a
) -> Past.When
(prev
,stm_list a
)
86 | _
-> failwith
"only when != supported")
88 | Ast.Nest
(starter
,stmt_dots
,ender
,whencodes
,false,_
,_
) ->
89 (match Ast.get_mcodekind starter
with
90 Ast.MINUS _
-> failwith
"only context nests supported"
92 let nest = Past.Nest
(stm_list stmt_dots
) in
97 Ast.WhenNot
(a
) -> Past.When
(prev
,stm_list a
)
98 | _
-> failwith
"only when != supported")
101 Pretty_print_cocci.statement
"" s
;
102 failwith
"unsupported statement3"
104 and dots_bef_aft s inif
=
105 match Ast.get_dots_bef_aft s
with
106 Ast.AddingBetweenDots
(brace_term
,n
) ->
107 Past.AddingBetweenDots
(term brace_term inif
,n
)
108 | Ast.DroppingBetweenDots
(brace_term
,n
) ->
109 Past.DroppingBetweenDots
(term brace_term inif
,n
)
110 | Ast.NoDots
-> Past.NoDots
113 match Ast.unwrap s
with
116 (function cur
-> function rest
-> Past.Seq
(stm cur
, rest
))
118 | _
-> failwith
"only DOTS handled"
121 match Ast.unwrap s
with
122 Ast.CODE
(stmt_dots
) -> stm_list stmt_dots
123 | _
-> failwith
"only CODE handled"