2 * Copyright 2005-2009, 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.
23 module Ast
= Ast_cocci
24 module Past
= Ast_popl
26 (* --------------------------------------------------------------------- *)
29 match Ast.unwrap s
with
31 (match Ast.unwrap ast
with
32 Ast.ExprStatement
(_
,_
) -> Past.Term ast
33 | Ast.Exp
(_
) -> Past.Term ast
34 | Ast.Decl
(_
,_
,_
) -> Past.Term ast
35 | _
-> failwith
"complex statements not supported")
36 | Ast.Disj
(stm1
::stm2
::stmts
) ->
40 Past.Or
(Past.Seq
(prev
,Past.Empty
),stm_list cur
))
41 (Past.Or
(stm_list stm1
,stm_list stm2
)) stmts
42 | Ast.Dots
(dots
,whencodes
,_
,_
) ->
44 [Ast.WhenNot
(a
)] -> Past.DInfo
(Past.When
(Past.Dots
,stm_list a
),[],[])
45 | _
-> failwith
"only one when != supported")
46 | Ast.Nest
(stmt_dots
,whencodes
,false,_
,_
) ->
47 let nest = Past.Nest
(stm_list stmt_dots
) in
49 [Ast.WhenNot
(a
)] -> Past.DInfo
(Past.When
(nest,stm_list a
),[],[])
50 | _
-> failwith
"only when != supported")
51 | Ast.While
(header
,body
,(_
,_
,_
,aft
)) | Ast.For
(header
,body
,(_
,_
,_
,aft
)) ->
52 (* only allowed if only the header is significant *)
53 (match (Ast.unwrap body
,aft
) with
54 (Ast.Atomic
(re
),Ast.CONTEXT
(_
,Ast.NOTHING
)) ->
55 (match Ast.unwrap re
with
56 Ast.MetaStmt
(_
,Type_cocci.Unitary
,_
,false) -> Past.Term header
57 | _
-> failwith
"unsupported statement1")
58 | _
-> failwith
"unsupported statement2")
60 Pretty_print_cocci.statement
"" s
;
61 failwith
"unsupported statement3"
64 match Ast.unwrap s
with
67 (function cur
-> function rest
-> Past.Seq
(stm cur
, rest
))
69 | _
-> failwith
"only DOTS handled"
72 match Ast.unwrap s
with
73 Ast.CODE
(stmt_dots
) -> stm_list stmt_dots
74 | _
-> failwith
"only CODE handled"