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