From c1159ec068dc324047bd8315576266716d592c4d Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Tue, 24 Jun 2014 09:54:34 +0200
Subject: [PATCH] Soc2c:  Fix the C code generated for user def structures

nb:  unexpected failures 143->133
---
 src/soc2c.ml      | 62 +++++++++++++++++++++++++++++------------------
 test/lus2lic.sum  | 28 ++++++++++-----------
 test/lus2lic.time |  2 +-
 todo.org          | 52 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 106 insertions(+), 38 deletions(-)

diff --git a/src/soc2c.ml b/src/soc2c.ml
index 5938276c..603965df 100644
--- a/src/soc2c.ml
+++ b/src/soc2c.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 20/06/2014 (at 16:44) by Erwan Jahier> *)
+(* Time-stamp: <modified the 24/06/2014 (at 09:44) by Erwan Jahier> *)
 
 
 (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
@@ -38,8 +38,8 @@ let rec (type_to_string2 : Data.t -> string) =
     let str =
       match v with
         | Bool -> "bool"
-        | Int -> "int"
-        | Real-> "real"
+        | Int  -> "int"
+        | Real -> "real"
         | Extern s -> s
         | Enum  (s, sl) -> id2s s
         | Struct (sid,_) -> (id2s sid)
@@ -49,6 +49,42 @@ let rec (type_to_string2 : Data.t -> string) =
     in
     str
 
+(****************************************************************************)
+let rec (lic_type_to_c: Lic.type_  -> string -> string) =
+  fun t n -> 
+    match t with
+      | Lic.Struct_type_eff (name, fl) ->
+        let field_to_c (id,(tf,_opt)) = 
+          Printf.sprintf "\n   %s;" (type_to_string (Lic2soc.lic_to_data_type tf) (id2s id)) 
+        in
+        ((Printf.sprintf "struct { %s } " 
+            (String.concat "" (List.map field_to_c fl)))^ " " ^ n) 
+      | Enum_type_eff (name, l) -> "_integer"^ " " ^ n
+      | _ -> type_to_string (Lic2soc.lic_to_data_type t) n
+
+
+let rec (lic_type_to_c_old: Lic.type_  -> string -> string) =
+  fun t n -> match t with
+    | Bool_type_eff -> "_boolean"^ " " ^ n
+    | Int_type_eff  -> "_integer"^ " " ^ n
+    | Real_type_eff -> "_real"^ " " ^ n
+    | External_type_eff (name) -> (long2s name)^ " " ^ n
+    | Abstract_type_eff (name, t) -> lic_type_to_c t n
+    | Enum_type_eff (name, l) -> "_integer"^ " " ^ n
+    | Array_type_eff (ty, sz) -> 
+      Printf.sprintf "%s %s[%d]" (lic_type_to_c ty "") n sz
+    | Struct_type_eff (name, fl) ->
+      let field_to_c (id,(tf,_opt)) = 
+        Printf.sprintf "  %s %s;\n" (lic_type_to_c tf "")  (id2s id)
+      in
+      (Printf.sprintf "struct %s { %s }" 
+        (long2s name) 
+        (String.concat "" (List.map field_to_c fl)))^ " " ^ n
+    | TypeVar Any -> assert false
+    | (TypeVar AnyNum) -> assert false
+
+(****************************************************************************)
+
 (* Soc printer *)
 type 'a soc_pp = {
   hfmt:  ('a, unit, string, unit) format4 -> 'a;
@@ -219,26 +255,6 @@ let (type_to_format_string : Data.t -> string) =
     | Array (ty, sz) -> "%s"
     | Alpha nb -> assert false
 
-(****************************************************************************)
-let rec (lic_type_to_c: Lic.type_  -> string -> string) =
-  fun t n -> match t with
-    | Bool_type_eff -> "_boolean"^ " " ^ n
-    | Int_type_eff  -> "_integer"^ " " ^ n
-    | Real_type_eff -> "_real"^ " " ^ n
-    | External_type_eff (name) -> (long2s name)^ " " ^ n
-    | Abstract_type_eff (name, t) -> lic_type_to_c t n
-    | Enum_type_eff (name, l) -> "_integer"^ " " ^ n
-    | Array_type_eff (ty, sz) -> 
-      Printf.sprintf "%s %s[%d]" (lic_type_to_c ty "") n sz
-    | Struct_type_eff (name, fl) ->
-      let field_to_c (id,(tf,_opt)) = 
-        Printf.sprintf "  %s %s;\n" (lic_type_to_c tf "")  (id2s id)
-      in
-      (Printf.sprintf "struct %s { %s }" 
-        (long2s name) 
-        (String.concat "" (List.map field_to_c fl)))^ " " ^ n
-    | TypeVar Any -> assert false
-    | (TypeVar AnyNum) -> assert false
 
 
 (****************************************************************************)
diff --git a/test/lus2lic.sum b/test/lus2lic.sum
index 7587c6ee..a2529e56 100644
--- a/test/lus2lic.sum
+++ b/test/lus2lic.sum
@@ -1,4 +1,4 @@
-Test Run By jahier on Mon Jun 23 16:54:59 2014
+Test Run By jahier on Tue Jun 24 09:50:48 2014
 Native configuration is i686-pc-linux-gnu
 
 		=== lus2lic tests ===
@@ -32,7 +32,7 @@ PASS: ./lus2lic {-ec -o /tmp/normal.ec should_work/normal.lus}
 PASS: ./myec2c {-o /tmp/normal.c /tmp/normal.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/normal.lus
 PASS: ./lus2lic {-2c should_work/normal.lus -n normal}
-FAIL: Check that the generated C code compiles  : gcc normal_normal.c normal_normal_loop.c 
+PASS: gcc normal_normal.c normal_normal_loop.c 
 PASS: ./lus2lic {-o /tmp/nodeparam.lic should_work/nodeparam.lus}
 PASS: ./lus2lic {-ec -o /tmp/nodeparam.ec should_work/nodeparam.lus}
 PASS: ./myec2c {-o /tmp/nodeparam.c /tmp/nodeparam.ec}
@@ -73,7 +73,7 @@ PASS: ./lus2lic {-ec -o /tmp/ELMU.ec should_work/ELMU.lus}
 PASS: ./myec2c {-o /tmp/ELMU.c /tmp/ELMU.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/ELMU.lus
 PASS: ./lus2lic {-2c should_work/ELMU.lus -n ELMU}
-FAIL: Check that the generated C code compiles  : gcc ELMU_ELMU.c ELMU_ELMU_loop.c 
+PASS: gcc ELMU_ELMU.c ELMU_ELMU_loop.c 
 PASS: ./lus2lic {-o /tmp/testPilote.lic should_work/testPilote.lus}
 PASS: ./lus2lic {-ec -o /tmp/testPilote.ec should_work/testPilote.lus}
 PASS: ./myec2c {-o /tmp/testPilote.c /tmp/testPilote.ec}
@@ -162,7 +162,7 @@ PASS: ./lus2lic {-ec -o /tmp/bug2.ec should_work/bug2.lus}
 PASS: ./myec2c {-o /tmp/bug2.c /tmp/bug2.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/bug2.lus
 PASS: ./lus2lic {-2c should_work/bug2.lus -n bug2}
-FAIL: Check that the generated C code compiles  : gcc bug2_bug2.c bug2_bug2_loop.c 
+PASS: gcc bug2_bug2.c bug2_bug2_loop.c 
 PASS: ./lus2lic {-o /tmp/mm.lic should_work/mm.lus}
 PASS: ./lus2lic {-ec -o /tmp/mm.ec should_work/mm.lus}
 PASS: ./myec2c {-o /tmp/mm.c /tmp/mm.ec}
@@ -480,7 +480,7 @@ PASS: ./lus2lic {-ec -o /tmp/shift_ludic.ec should_work/shift_ludic.lus}
 PASS: ./myec2c {-o /tmp/shift_ludic.c /tmp/shift_ludic.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/shift_ludic.lus
 PASS: ./lus2lic {-2c should_work/shift_ludic.lus -n shift_ludic}
-FAIL: Check that the generated C code compiles  : gcc shift_ludic_shift_ludic.c shift_ludic_shift_ludic_loop.c 
+PASS: gcc shift_ludic_shift_ludic.c shift_ludic_shift_ludic_loop.c 
 PASS: ./lus2lic {-o /tmp/pilote-1.0.lic should_work/pilote-1.0.lus}
 PASS: ./lus2lic {-ec -o /tmp/pilote-1.0.ec should_work/pilote-1.0.lus}
 PASS: ./myec2c {-o /tmp/pilote-1.0.c /tmp/pilote-1.0.ec}
@@ -531,7 +531,7 @@ PASS: ./lus2lic {-ec -o /tmp/tri.ec should_work/tri.lus}
 PASS: ./myec2c {-o /tmp/tri.c /tmp/tri.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/tri.lus
 PASS: ./lus2lic {-2c should_work/tri.lus -n tri}
-FAIL: Check that the generated C code compiles  : gcc tri_tri.c tri_tri_loop.c 
+PASS: gcc tri_tri.c tri_tri_loop.c 
 PASS: ./lus2lic {-o /tmp/calculs_max.lic should_work/calculs_max.lus}
 PASS: ./lus2lic {-ec -o /tmp/calculs_max.ec should_work/calculs_max.lus}
 PASS: ./myec2c {-o /tmp/calculs_max.c /tmp/calculs_max.ec}
@@ -729,7 +729,7 @@ PASS: ./lus2lic {-ec -o /tmp/test_const.ec should_work/test_const.lus}
 PASS: ./myec2c {-o /tmp/test_const.c /tmp/test_const.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/test_const.lus
 PASS: ./lus2lic {-2c should_work/test_const.lus -n test_const}
-FAIL: Check that the generated C code compiles  : gcc test_const_test_const.c test_const_test_const_loop.c 
+PASS: gcc test_const_test_const.c test_const_test_const_loop.c 
 PASS: ./lus2lic {-o /tmp/when_tuple.lic should_work/when_tuple.lus}
 PASS: ./lus2lic {-ec -o /tmp/when_tuple.ec should_work/when_tuple.lus}
 FAIL: Try ec2c on the result: ./myec2c {-o /tmp/when_tuple.c /tmp/when_tuple.ec}
@@ -1018,7 +1018,7 @@ PASS: ./lus2lic {-ec -o /tmp/map_red_iter.ec should_work/map_red_iter.lus}
 PASS: ./myec2c {-o /tmp/map_red_iter.c /tmp/map_red_iter.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/map_red_iter.lus
 PASS: ./lus2lic {-2c should_work/map_red_iter.lus -n map_red_iter}
-FAIL: Check that the generated C code compiles  : gcc map_red_iter_map_red_iter.c map_red_iter_map_red_iter_loop.c 
+PASS: gcc map_red_iter_map_red_iter.c map_red_iter_map_red_iter_loop.c 
 PASS: ./lus2lic {-o /tmp/p.lic should_work/p.lus}
 PASS: ./lus2lic {-ec -o /tmp/p.ec should_work/p.lus}
 PASS: ./myec2c {-o /tmp/p.c /tmp/p.ec}
@@ -1178,7 +1178,7 @@ PASS: ./lus2lic {-ec -o /tmp/toto.ec should_work/toto.lus}
 PASS: ./myec2c {-o /tmp/toto.c /tmp/toto.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/toto.lus
 PASS: ./lus2lic {-2c should_work/toto.lus -n toto}
-FAIL: Check that the generated C code compiles  : gcc toto_toto.c toto_toto_loop.c 
+PASS: gcc toto_toto.c toto_toto_loop.c 
 PASS: ./lus2lic {-o /tmp/minmax6.lic should_work/minmax6.lus}
 PASS: ./lus2lic {-ec -o /tmp/minmax6.ec should_work/minmax6.lus}
 PASS: ./myec2c {-o /tmp/minmax6.c /tmp/minmax6.ec}
@@ -1238,7 +1238,7 @@ PASS: ./lus2lic {-ec -o /tmp/triSel.ec should_work/triSel.lus}
 PASS: ./myec2c {-o /tmp/triSel.c /tmp/triSel.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/triSel.lus
 PASS: ./lus2lic {-2c should_work/triSel.lus -n triSel}
-FAIL: Check that the generated C code compiles  : gcc triSel_triSel.c triSel_triSel_loop.c 
+PASS: gcc triSel_triSel.c triSel_triSel_loop.c 
 PASS: ./lus2lic {-o /tmp/redoptest.lic should_work/redoptest.lus}
 PASS: ./lus2lic {-ec -o /tmp/redoptest.ec should_work/redoptest.lus}
 PASS: ./myec2c {-o /tmp/redoptest.c /tmp/redoptest.ec}
@@ -1268,7 +1268,7 @@ PASS: ./lus2lic {-ec -o /tmp/shiftFill_ludic.ec should_work/shiftFill_ludic.lus}
 PASS: ./myec2c {-o /tmp/shiftFill_ludic.c /tmp/shiftFill_ludic.ec}
 PASS: ../utils/test_lus2lic_no_node should_work/shiftFill_ludic.lus
 PASS: ./lus2lic {-2c should_work/shiftFill_ludic.lus -n shiftFill_ludic}
-FAIL: Check that the generated C code compiles  : gcc shiftFill_ludic_shiftFill_ludic.c shiftFill_ludic_shiftFill_ludic_loop.c 
+PASS: gcc shiftFill_ludic_shiftFill_ludic.c shiftFill_ludic_shiftFill_ludic_loop.c 
 PASS: ./lus2lic {-o /tmp/after.lic should_work/after.lus}
 PASS: ./lus2lic {-ec -o /tmp/after.ec should_work/after.lus}
 PASS: ./myec2c {-o /tmp/after.c /tmp/after.ec}
@@ -1482,9 +1482,9 @@ XPASS: Test bad programs (semantics): lus2lic {-o /tmp/bug.lic should_fail/seman
 
 		=== lus2lic Summary ===
 
-# of expected passes		1269
-# of unexpected failures	143
+# of expected passes		1279
+# of unexpected failures	133
 # of unexpected successes	21
 # of expected failures		37
-testcase ./lus2lic.tests/non-reg.exp completed in 130 seconds
+testcase ./lus2lic.tests/non-reg.exp completed in 139 seconds
 testcase ./lus2lic.tests/progression.exp completed in 0 seconds
diff --git a/test/lus2lic.time b/test/lus2lic.time
index 6879740d..4aeb9e74 100644
--- a/test/lus2lic.time
+++ b/test/lus2lic.time
@@ -1,2 +1,2 @@
-testcase ./lus2lic.tests/non-reg.exp completed in 130 seconds
+testcase ./lus2lic.tests/non-reg.exp completed in 139 seconds
 testcase ./lus2lic.tests/progression.exp completed in 0 seconds
diff --git a/todo.org b/todo.org
index 1a40221e..8180560b 100644
--- a/todo.org
+++ b/todo.org
@@ -47,6 +47,58 @@ chez Cedric  Pasteur qui a  une implementation pour optimiser  la maj
 des tableaux
 http://www.di.ens.fr/~pouzet/bib/lctes12.pdf
 
+
+** TODO les programmes qui ne passent pas le test:
+
+
+1. file:test/should_work/Gyroscope2.lus
+2. file:test/should_work/mouse2.lus
+3. file:test/should_work/mappredef.lus
+4. file:test/should_work/predefOp.lus
+5. file:test/should_work/matrice2.lus
+6. file:test/should_work/ply02.lus
+7. file:test/should_work/is.lus
+8. file:test/should_work/onlyroll2.lus
+9. file:test/should_work/morel3.lus
+10. file:test/should_work/ply03.lus
+11. file:test/should_work/plus.lus
+12. file:test/should_work/xx.lus
+13. file:test/should_work/call07.lus
+14. file:test/should_work/morel5.lus
+15. file:test/should_work/test.lus
+16. file:test/should_work/clock.lus
+17. file:test/should_work/morel4.lus
+18. file:test/should_work/bad.lus
+19. file:test/should_work/onlyroll.lus
+20. file:test/should_work/mapinf.lus
+21. file:test/should_work/over2.lus
+22. file:test/should_work/over3.lus
+23. file:test/should_work/test.lus
+24. file:test/should_work/carV2.lus
+25. file:test/should_work/test.lus
+26. file:test/should_work/CURRENT.lus
+27. file:test/should_work/left.lus
+28. file:test/should_work/morel.lus
+29. file:test/should_work/matrice.lus
+30. file:test/should_work/exclusion.lus
+31. file:test/should_work/pack1.lus
+32. file:test/should_work/bob.lus
+33. file:test/should_work/morel2.lus
+34. file:test/should_work/xxx.lus
+35. file:test/should_work/filliter.lus
+36. file:test/should_work/Gyroscope.lus
+37. file:test/should_work/mapdeRed.lus
+38. file:test/should_work/simpleRed.lus
+39. file:test/should_work/hanane.lus
+40. file:test/should_work/ck7.lus
+41. file:test/should_work/redoptest.lus
+42. file:test/should_work/cond01.lus
+43. file:test/should_work/arrays.lus
+44. file:test/should_work/overload.lus
+45. file:test/should_work/simple.lus
+46. file:test/should_work/minus.lus
+
+
 * Packages, modeles, etc.
 ** STARTED Il ne detecte plus les erreurs de type lors d'instanciation de noeuds
    - State "STARTED"    from "TODO"       [2013-01-28 Mon 17:02]
-- 
GitLab