From a969314873d3fd5be55a3e5b1e134c5e5a061ee0 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Thu, 28 Aug 2008 11:20:11 +0200
Subject: [PATCH] Better error message when using an undefined ident as a clock
 in node profiles.

---
 src/TODO                              |  7 -------
 src/evalClock.ml                      | 16 +++++++---------
 src/evalClock.mli                     |  4 ++--
 src/lazyCompiler.ml                   | 19 +++++++++++++------
 src/split.ml                          |  4 ++--
 src/test/should_fail/clock/bad_id.lus |  7 +++++++
 src/test/test.res.exp                 | 10 +++++++++-
 7 files changed, 40 insertions(+), 27 deletions(-)
 create mode 100644 src/test/should_fail/clock/bad_id.lus

diff --git a/src/TODO b/src/TODO
index 4f416b8b..f706890a 100644
--- a/src/TODO
+++ b/src/TODO
@@ -88,13 +88,6 @@ est evalu
   devrait être multi-horloge également. Et peut-etre d'autres encore...
 
 
-* Que faire des itérateurs imbriqués ? style :
-
-        fill<< fill<< incremental ; L >> ; H >>( iacc );
-
-lus2lic les accepte, mais pas lic2loc. Faut-il étendre lic2loc,
-ou faire en sorte que lus2lic invente un noeud alias intermédiaire ?
-
 *********************************************************************
 *********************************************************************
 *** questions pour bibi
diff --git a/src/evalClock.ml b/src/evalClock.ml
index 622e59af..3b268817 100644
--- a/src/evalClock.ml
+++ b/src/evalClock.ml
@@ -1,4 +1,4 @@
-(** Time-stamp: <modified the 28/08/2008 (at 10:26) by Erwan Jahier> *)
+(** Time-stamp: <modified the 28/08/2008 (at 11:17) by Erwan Jahier> *)
  
   
 open Predef
@@ -193,14 +193,14 @@ let tabulate_res vef clock_eff_list =
 (*   flush stdout; *)
   Hashtbl.add val_exp_eff_clk_tab vef clock_eff_list
 
-let (val_exp_eff : val_exp_eff -> clock_eff list) =
+let (get_val_exp_eff : val_exp_eff -> clock_eff list) =
   fun vef -> 
     try 
       let res = Hashtbl.find val_exp_eff_clk_tab vef in
       let var_clock_to_base = function
-        (* Some expressions migth be infered to be a variable clock
-           (e.g., constants). In that case, it is ok to consider that such
-           expression are on the base clock.*)
+          (* Some expressions migth be infered to be a variable clock
+             (e.g., constants). In that case, it is ok to consider that such
+             expressions are on the base clock.*)
         | ClockVar _ 
         | On(_,ClockVar _) -> BaseEff
         | x -> x
@@ -213,8 +213,6 @@ let (val_exp_eff : val_exp_eff -> clock_eff list) =
       flush stdout;
       assert false
 
-
-
 (******************************************************************************)
 (** Now we can go on and define [f].  *)
 
@@ -227,7 +225,7 @@ let rec (f : id_solver -> subst -> val_exp_eff -> clock_eff list * subst) =
     let s = snd res in
       (* during the inner call to f_aux, some intermediary clock variables
          may remain. *)
-      Hashtbl.iter 
+      Hashtbl.iter
         (fun ve cel -> 
            let cel2 = List.map (apply_subst2 s) cel in
              if cel <> cel2 then
@@ -235,7 +233,7 @@ let rec (f : id_solver -> subst -> val_exp_eff -> clock_eff list * subst) =
         val_exp_eff_clk_tab;
       res
 
-      
+
 and f_aux id_solver s ve =
   let cel, s = 
     match ve with
diff --git a/src/evalClock.mli b/src/evalClock.mli
index 484caf63..c604d44d 100644
--- a/src/evalClock.mli
+++ b/src/evalClock.mli
@@ -1,4 +1,4 @@
-(** Time-stamp: <modified the 19/08/2008 (at 15:17) by Erwan Jahier> *)
+(** Time-stamp: <modified the 28/08/2008 (at 10:43) by Erwan Jahier> *)
 
 open CompiledData
 open UnifyClock
@@ -35,4 +35,4 @@ val check_res : Lxm.t -> subst -> left_eff list -> clock_eff list -> unit
 (* Returns the clock of an expression. Note that this function uses
    an internal table, and therefore it should not be called before
    the clock checking has been done (by the function f above).*)
-val val_exp_eff : val_exp_eff -> clock_eff list
+val get_val_exp_eff : val_exp_eff -> clock_eff list
diff --git a/src/lazyCompiler.ml b/src/lazyCompiler.ml
index 2fbecf86..df7dcd32 100644
--- a/src/lazyCompiler.ml
+++ b/src/lazyCompiler.ml
@@ -1,4 +1,4 @@
-(** Time-stamp: <modified the 28/08/2008 (at 10:28) by Erwan Jahier> *)
+(** Time-stamp: <modified the 28/08/2008 (at 11:12) by Erwan Jahier> *)
 
 
 open Lxm
@@ -538,6 +538,7 @@ and (node_check_do: t -> CompiledData.node_key -> Lxm.t -> SymbolTab.t ->
       bool -> Ident.pack_name -> SyntaxTreeCore.node_info srcflagged -> 
       CompiledData.node_exp_eff) =
   fun this nk lxm symbols provide_flag pack_name node_def ->
+    let lxm = node_def.src in
     let local_env = make_local_env nk in
     let node_id_solver = {
       (* a [node_id_solver] is a [id_solver] where we begin to look
@@ -577,13 +578,19 @@ and (node_check_do: t -> CompiledData.node_key -> Lxm.t -> SymbolTab.t ->
       symbols  = symbols;
     }
     in
+    let find_var_info lxm vars id =
+      try Hashtbl.find vars.vartable id
+      with Not_found -> 
+        raise (Compile_error 
+                 (lxm,"\n*** Unknown ident: " ^ (Ident.to_string id)))
+    in
     let make_node_eff node_def_eff =
       (* building not aliased nodes *)
       match node_def.it.vars with
         | None -> assert false (* a node with a body should have a profile *)
         | Some vars ->
             let type_args id =
-              let vi = Hashtbl.find vars.vartable id in
+              let vi = find_var_info lxm vars id in
               let t_eff = GetEff.typ node_id_solver vi.it.var_type in
               let c_eff = GetEff.clock node_id_solver vi.it in
               let vi_eff = {
@@ -603,14 +610,14 @@ and (node_check_do: t -> CompiledData.node_key -> Lxm.t -> SymbolTab.t ->
                 (* I cannot use List.sort as I only have a partial order on vars
                  -> hence I perform a topological sort *)
                 let rec depends_on v1 v2 =
-                  match (Hashtbl.find vars.vartable v1).it.var_clock with
+                  match (find_var_info lxm vars v1).it.var_clock with
                     | Base -> false
                     | NamedClock {it=v1clk} -> v1clk = v2 || depends_on v1clk v2
                 in
                 let rec aux acc l = match l with
                   | [] -> acc
                   | v::tail -> (
-                      match (Hashtbl.find vars.vartable v).it.var_clock with
+                      match (find_var_info lxm vars v).it.var_clock with
                         | Base -> 
                             if List.mem v acc then 
                               aux acc tail 
@@ -765,8 +772,8 @@ and (node_check_do: t -> CompiledData.node_key -> Lxm.t -> SymbolTab.t ->
               | None -> alias_node
               | Some vars ->
                   let vi_il, vi_ol = 
-                    List.map (fun id -> Hashtbl.find vars.vartable id) vars.inlist,
-                    List.map (fun id -> Hashtbl.find vars.vartable id) vars.outlist
+                    List.map (fun id -> find_var_info lxm vars id) vars.inlist,
+                    List.map (fun id -> find_var_info lxm vars id) vars.outlist
                   in
                   let aux vi = GetEff.typ node_id_solver vi.it.var_type
                   in
diff --git a/src/split.ml b/src/split.ml
index d717ba7f..3fa17785 100644
--- a/src/split.ml
+++ b/src/split.ml
@@ -1,4 +1,4 @@
-(** Time-stamp: <modified the 25/08/2008 (at 10:18) by Erwan Jahier> *)
+(** Time-stamp: <modified the 28/08/2008 (at 10:43) by Erwan Jahier> *)
 
 
 open Lxm
@@ -80,7 +80,7 @@ and (split_val_exp : bool -> val_exp_eff -> val_exp_eff * split_acc) =
               CallByPosEff(by_pos_op_eff, OperEff vel), (eql, vl) 
             else
               (* create the var for the current call *)
-              let clk_l = EvalClock.val_exp_eff ve in
+              let clk_l = EvalClock.get_val_exp_eff ve in
               let typ_l = EvalType.val_exp_eff ve in 
               let nv_l = List.map2 new_var typ_l clk_l in
 
diff --git a/src/test/should_fail/clock/bad_id.lus b/src/test/should_fail/clock/bad_id.lus
new file mode 100644
index 00000000..e8a54da1
--- /dev/null
+++ b/src/test/should_fail/clock/bad_id.lus
@@ -0,0 +1,7 @@
+
+
+node toto(c: bool; x: int) returns (y: int when b);
+let
+
+  y = 1+1+(x when c);
+tel
\ No newline at end of file
diff --git a/src/test/test.res.exp b/src/test/test.res.exp
index b08a5d0b..86cac852 100644
--- a/src/test/test.res.exp
+++ b/src/test/test.res.exp
@@ -9919,7 +9919,7 @@ returns (
 	clock4_x:bool;
 	clock4_y:bool when clock4_x);
 
-*** oops: an internal error occurred in file evalClock.ml, line 275, column 31
+*** oops: an internal error occurred in file evalClock.ml, line 273, column 31
 *** when compiling lustre program should_work/clock/when_not.lus
 
 ----------------------------------------------------------------------
@@ -18440,6 +18440,14 @@ Opening file should_fail/clock/bad_call02.lus
 
 
 
+----------------------------------------------------------------------
+====> ../lus2lic -vl 2 --compile-all-items should_fail/clock/bad_id.lus
+Opening file should_fail/clock/bad_id.lus
+*** Error in file "should_fail/clock/bad_id.lus", line 3, col 6 to 9, token 'toto':
+*** 
+*** Unknown ident: b
+
+
 ----------------------------------------------------------------------
 ====> ../lus2lic -vl 2 --compile-all-items should_fail/clock/clock.lus
 Opening file should_fail/clock/clock.lus
-- 
GitLab