Commit | Line | Data |
---|---|---|
9f8e26f4 C |
1 | (* |
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. | |
5 | * | |
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. | |
9 | * | |
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. | |
14 | * | |
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/>. | |
17 | * | |
18 | * The authors reserve the right to distribute this or future versions of | |
19 | * Coccinelle under other licenses. | |
20 | *) | |
21 | ||
22 | ||
951c7801 C |
23 | module Ast = Ast_cocci |
24 | module Past = Ast_popl | |
25 | ||
26 | (* --------------------------------------------------------------------- *) | |
27 | ||
28 | let rec stm s = | |
29 | match Ast.unwrap s with | |
30 | Ast.Atomic(ast) -> | |
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) -> | |
37 | List.fold_left | |
38 | (function prev -> | |
39 | function cur -> | |
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,_,_) -> | |
43 | (match whencodes with | |
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 | |
48 | (match whencodes with | |
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") | |
59 | | _ -> | |
60 | Pretty_print_cocci.statement "" s; | |
61 | failwith "unsupported statement3" | |
62 | ||
63 | and stm_list s = | |
64 | match Ast.unwrap s with | |
65 | Ast.DOTS(d) -> | |
66 | List.fold_right | |
67 | (function cur -> function rest -> Past.Seq(stm cur, rest)) | |
68 | d Past.Empty | |
69 | | _ -> failwith "only DOTS handled" | |
70 | ||
71 | let top s = | |
72 | match Ast.unwrap s with | |
73 | Ast.CODE(stmt_dots) -> stm_list stmt_dots | |
74 | | _ -> failwith "only CODE handled" |