Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / engine / isomorphisms_c_c.ml
1 (*
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.
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
23 (*
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.
27 *
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.
31 *
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.
36 *
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/>.
39 *
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
42 *)
43
44
45 open Common
46
47 (* When in a semantic patch there is f(X) ... f(X) we want to force
48 * the two X to be equal in the concrete code, but we would like that
49 * there be equal modulo some isomorphisms, so that the following
50 * concrete code also match: f(a && b) g(); f(b && a)
51
52 * Maybe would be easier to transform ast_c in ast_cocci and call the
53 * iso engine of julia. *)
54
55 open Ast_c
56
57 let rec (iso_e_e: expression -> expression -> bool) = fun a b ->
58 raise Todo
59 (*
60 let rec (=~=) a b =
61 match (a, b) with
62 | (Ident a, typa, iia), (Ident b, typb, iib) -> a = b
63 | (Constant a, typa, iia), (Constant b, typb, iib) -> a = b
64 | (FunCall (ea, eas), typa, iia), (FunCall (eb, ebs), typb, iib) ->
65 ea =~= eb &&
66 List.length eas = List.length ebs &&
67 List.for_all (fun (a, b) ->
68 match (a, b) with
69 | (Left ea, iia), (Left eb, iib) -> ea =~= eb
70 | _ -> raise Todo
71 )
72 (zip eas ebs)
73 | (Binary (ea1,Logical AndLog,ea2),typa, iia), (Binary (eb1,Logical AndLog, eb2), typb, iib) ->
74 (ea1 =~= eb1 && ea2 =~= eb2)
75 ||
76 (ea1 =~= eb2 && ea2 =~= eb1)
77
78 | _ -> raise Todo
79 in
80 a =~= b
81 *)
82
83 and (iso_st_st: statement -> statement -> bool) = fun a b ->
84 raise Todo
85 and (iso_t_t: fullType -> fullType -> bool) = fun a b ->
86 raise Todo
87
88
89 (*
90 let _ = assert (iso_e_e
91 (cexpression_of_string "a&&b")
92 (cexpression_of_string "b&&a")
93 *)
94