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 (* --------------------------------------------------------------------- *)
51 match Ast.unwrap s
with
53 (match Ast.unwrap ast
with
54 Ast.ExprStatement
(_
,_
) -> Past.Term ast
55 | Ast.Exp
(_
) -> Past.Term ast
56 | Ast.Decl
(_
,_
,_
) -> Past.Term ast
57 | _
-> failwith
"complex statements not supported")
58 | Ast.Disj
(stm1
::stm2
::stmts
) ->
62 Past.Or
(Past.Seq
(prev
,Past.Empty
),stm_list cur
))
63 (Past.Or
(stm_list stm1
,stm_list stm2
)) stmts
64 | Ast.Dots
(dots
,whencodes
,_
,_
) ->
66 [Ast.WhenNot
(a
)] -> Past.DInfo
(Past.When
(Past.Dots
,stm_list a
),[],[])
67 | _
-> failwith
"only one when != supported")
68 | Ast.Nest
(stmt_dots
,whencodes
,false,_
,_
) ->
69 let nest = Past.Nest
(stm_list stmt_dots
) in
71 [Ast.WhenNot
(a
)] -> Past.DInfo
(Past.When
(nest,stm_list a
),[],[])
72 | _
-> failwith
"only when != supported")
73 | Ast.While
(header
,body
,(_
,_
,_
,aft
)) | Ast.For
(header
,body
,(_
,_
,_
,aft
)) ->
74 (* only allowed if only the header is significant *)
75 (match (Ast.unwrap body
,aft
) with
76 (Ast.Atomic
(re
),Ast.CONTEXT
(_
,Ast.NOTHING
)) ->
77 (match Ast.unwrap re
with
78 Ast.MetaStmt
(_
,Type_cocci.Unitary
,_
,false) -> Past.Term header
79 | _
-> failwith
"unsupported statement1")
80 | _
-> failwith
"unsupported statement2")
82 Pretty_print_cocci.statement
"" s
;
83 failwith
"unsupported statement3"
86 match Ast.unwrap s
with
89 (function cur
-> function rest
-> Past.Seq
(stm cur
, rest
))
91 | _
-> failwith
"only DOTS handled"
94 match Ast.unwrap s
with
95 Ast.CODE
(stmt_dots
) -> stm_list stmt_dots
96 | _
-> failwith
"only CODE handled"