530560dbacb2f2cb7ed1d7fc4a2eacff082d5729
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 Ast
= Ast_cocci
26 module Past
= Ast_popl
28 (* --------------------------------------------------------------------- *)
32 Pretty_print_cocci.statement
"" s
;
33 Format.print_newline
();
34 failwith
"complex statements not supported" in
35 match Ast.unwrap s
with
37 (match Ast.unwrap ast
with
38 Ast.ExprStatement
(_
,_
) -> Past.Atomic ast
39 | Ast.Exp
(_
) -> Past.Atomic ast
40 | Ast.Decl
(_
,_
,_
) -> Past.Atomic ast
41 | Ast.ReturnExpr
(_
,_
,_
) -> Past.Atomic ast
42 | Ast.MetaStmt
(_
,_
,_
,_
) when inif
-> Past.Atomic ast
43 | Ast.DisjRuleElem
(_
) -> Past.Atomic ast
48 match Ast.unwrap s
with
49 Ast.Atomic
(ast
) -> Past.Term
(term s
false,dots_bef_aft s
false)
50 | Ast.IfThen
(header
,body
,aft
) ->
52 Past.IfThen
(Past.Atomic header
,term body
true,aft
),
54 | Ast.Disj
(stm1
::stm2
::stmts
) ->
58 Past.Or
(Past.Seq
(prev
,Past.Empty
),stm_list cur
))
59 (Past.Or
(stm_list stm1
,stm_list stm2
)) stmts
60 | Ast.Dots
(dots
,whencodes
,_
,_
) ->
65 Ast.WhenNot
(a
) -> Past.When
(prev
,stm_list a
)
66 | _
-> failwith
"only when != supported")
68 | Ast.Nest
(starter
,stmt_dots
,ender
,whencodes
,false,_
,_
) ->
69 (match Ast.get_mcodekind starter
with
70 Ast.MINUS _
-> failwith
"only context nests supported"
72 let nest = Past.Nest
(stm_list stmt_dots
) in
77 Ast.WhenNot
(a
) -> Past.When
(prev
,stm_list a
)
78 | _
-> failwith
"only when != supported")
81 Pretty_print_cocci.statement
"" s
;
82 failwith
"unsupported statement3"
84 and dots_bef_aft s inif
=
85 match Ast.get_dots_bef_aft s
with
86 Ast.AddingBetweenDots
(brace_term
,n
) ->
87 Past.AddingBetweenDots
(term brace_term inif
,n
)
88 | Ast.DroppingBetweenDots
(brace_term
,n
) ->
89 Past.DroppingBetweenDots
(term brace_term inif
,n
)
90 | Ast.NoDots
-> Past.NoDots
93 match Ast.unwrap s
with
96 (function cur
-> function rest
-> Past.Seq
(stm cur
, rest
))
98 | _
-> failwith
"only DOTS handled"
101 match Ast.unwrap s
with
102 Ast.CODE
(stmt_dots
) -> stm_list stmt_dots
103 | _
-> failwith
"only CODE handled"