Release coccinelle-0.2.4
[bpt/coccinelle.git] / engine / isomorphisms_c_c.ml
CommitLineData
9bc82bae
C
1(*
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.
7 *
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.
11 *
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.
16 *
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/>.
19 *
20 * The authors reserve the right to distribute this or future versions of
21 * Coccinelle under other licenses.
22 *)
23
24
c491d8ee
C
25(*
26 * Copyright 2010, INRIA, University of Copenhagen
27 * Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
28 * Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
29 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
30 * This file is part of Coccinelle.
31 *
32 * Coccinelle is free software: you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation, according to version 2 of the License.
35 *
36 * Coccinelle is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 * GNU General Public License for more details.
40 *
41 * You should have received a copy of the GNU General Public License
42 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
43 *
44 * The authors reserve the right to distribute this or future versions of
45 * Coccinelle under other licenses.
46 *)
47
48
34e49164
C
49open Common
50
51(* When in a semantic patch there is f(X) ... f(X) we want to force
52 * the two X to be equal in the concrete code, but we would like that
53 * there be equal modulo some isomorphisms, so that the following
54 * concrete code also match: f(a && b) g(); f(b && a)
55
56 * Maybe would be easier to transform ast_c in ast_cocci and call the
57 * iso engine of julia. *)
58
59open Ast_c
60
ae4735db 61let rec (iso_e_e: expression -> expression -> bool) = fun a b ->
34e49164
C
62 raise Todo
63 (*
ae4735db 64 let rec (=~=) a b =
34e49164
C
65 match (a, b) with
66 | (Ident a, typa, iia), (Ident b, typb, iib) -> a = b
67 | (Constant a, typa, iia), (Constant b, typb, iib) -> a = b
ae4735db 68 | (FunCall (ea, eas), typa, iia), (FunCall (eb, ebs), typb, iib) ->
34e49164 69 ea =~= eb &&
ae4735db
C
70 List.length eas = List.length ebs &&
71 List.for_all (fun (a, b) ->
34e49164
C
72 match (a, b) with
73 | (Left ea, iia), (Left eb, iib) -> ea =~= eb
74 | _ -> raise Todo
75 )
76 (zip eas ebs)
ae4735db
C
77 | (Binary (ea1,Logical AndLog,ea2),typa, iia), (Binary (eb1,Logical AndLog, eb2), typb, iib) ->
78 (ea1 =~= eb1 && ea2 =~= eb2)
34e49164
C
79 ||
80 (ea1 =~= eb2 && ea2 =~= eb1)
81
82 | _ -> raise Todo
83 in
84 a =~= b
85 *)
86
ae4735db 87and (iso_st_st: statement -> statement -> bool) = fun a b ->
34e49164 88 raise Todo
ae4735db 89and (iso_t_t: fullType -> fullType -> bool) = fun a b ->
34e49164
C
90 raise Todo
91
ae4735db 92
34e49164 93(*
ae4735db 94let _ = assert (iso_e_e
34e49164
C
95 (cexpression_of_string "a&&b")
96 (cexpression_of_string "b&&a")
97*)
98