Release coccinelle-0.2.0
[bpt/coccinelle.git] / engine / isomorphisms_c_c.ml
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
23 open Common
24
25 (* When in a semantic patch there is f(X) ... f(X) we want to force
26 * the two X to be equal in the concrete code, but we would like that
27 * there be equal modulo some isomorphisms, so that the following
28 * concrete code also match: f(a && b) g(); f(b && a)
29
30 * Maybe would be easier to transform ast_c in ast_cocci and call the
31 * iso engine of julia. *)
32
33 open Ast_c
34
35 let rec (iso_e_e: expression -> expression -> bool) = fun a b ->
36 raise Todo
37 (*
38 let rec (=~=) a b =
39 match (a, b) with
40 | (Ident a, typa, iia), (Ident b, typb, iib) -> a = b
41 | (Constant a, typa, iia), (Constant b, typb, iib) -> a = b
42 | (FunCall (ea, eas), typa, iia), (FunCall (eb, ebs), typb, iib) ->
43 ea =~= eb &&
44 List.length eas = List.length ebs &&
45 List.for_all (fun (a, b) ->
46 match (a, b) with
47 | (Left ea, iia), (Left eb, iib) -> ea =~= eb
48 | _ -> raise Todo
49 )
50 (zip eas ebs)
51 | (Binary (ea1,Logical AndLog,ea2),typa, iia), (Binary (eb1,Logical AndLog, eb2), typb, iib) ->
52 (ea1 =~= eb1 && ea2 =~= eb2)
53 ||
54 (ea1 =~= eb2 && ea2 =~= eb1)
55
56 | _ -> raise Todo
57 in
58 a =~= b
59 *)
60
61 and (iso_st_st: statement -> statement -> bool) = fun a b ->
62 raise Todo
63 and (iso_t_t: fullType -> fullType -> bool) = fun a b ->
64 raise Todo
65
66
67 (*
68 let _ = assert (iso_e_e
69 (cexpression_of_string "a&&b")
70 (cexpression_of_string "b&&a")
71 *)
72