From 051d1a17bd8b7cf373ce1e76dccbf94aaf788c43 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <erwan.jahier@univ-grenoble-alpes.fr> Date: Mon, 15 Mar 2021 15:54:16 +0100 Subject: [PATCH] Fix: lv6 -exec was raising a spurious runtime error --- bin/main.ml | 13 ++++++++----- lib/lv6errors.ml | 10 +++++++++- lib/socExecValue.ml | 16 +++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/bin/main.ml b/bin/main.ml index 0388a4e0..4c617b31 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 12/03/2020 (at 11:45) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2021 (at 12:28) by Erwan Jahier> *) open AstV6 open Lxm @@ -324,12 +324,12 @@ could try one the options: -2c, -2c-exec, -exec, -ec, -lic, or -h for more optio | Parse_error -> print_compile_error (Lxm.last_made ()) "Syntax error"; my_exit opt 1 | Unknown_var(lxm,id) -> - print_compile_error lxm ("unknown variable (" ^ (Lv6Id.to_string id) ^")"); + print_runtime_error lxm ("unknown variable (" ^ (Lv6Id.to_string id) ^")"); my_exit opt 1 | Unknown_constant(lxm,str) -> - print_compile_error lxm ("unknown constant (" ^ str ^")"); + print_runtime_error lxm ("unknown constant (" ^ str ^")"); my_exit opt 1 - | Compile_error(lxm,msg) -> print_compile_error lxm msg; my_exit opt 1 + | Compile_error(lxm,msg) -> print_runtime_error lxm msg; my_exit opt 1 | L2lCheckLoops.Error(lxm,msg,lic_prg) -> (* Sometime it helps to see the current state of the faulty program *) LicPrg.to_file opt lic_prg main_node; @@ -337,7 +337,10 @@ could try one the options: -2c, -2c-exec, -exec, -ec, -lic, or -h for more optio print_compile_error lxm msg; my_exit opt 1 | SocExec.AssertViolation lxm -> - print_compile_error lxm "An assertion is violated in the Lustre program"; + print_runtime_error lxm "An assertion is violated in the Lustre program"; + my_exit opt 1 + | Failure msg -> + Printf.eprintf "\nRuntime Error: %s\n" msg; my_exit opt 1 | Assert_failure (file, line, col) -> prerr_string ( diff --git a/lib/lv6errors.ml b/lib/lv6errors.ml index f5c5e2e6..09be7020 100644 --- a/lib/lv6errors.ml +++ b/lib/lv6errors.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 29/08/2019 (at 14:17) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2021 (at 12:22) by Erwan Jahier> *) (** *) @@ -105,6 +105,9 @@ Formatage standard des erreurs de compil let compile_error_string lxm msg = ( Printf.sprintf "\nError: %s:\nError: %s\n" (Lxm.details lxm) msg ) +let runtime_error_string lxm msg = ( + Printf.sprintf "\nRuntime Error: %s:\nError: %s\n" (Lxm.details lxm) msg +) (** --------------------------------------------------------------------- Message d'erreur (associé à un lexeme) sur stderr @@ -114,6 +117,11 @@ let print_compile_error lxm msg = ( flush stderr ) +let print_runtime_error lxm msg = ( + Printf.eprintf "%s\n" (compile_error_string lxm msg); + flush stderr +) + (** --------------------------------------------------------------------- Warning (associé à un lexeme) sur stderr ----------------------------------------------------------------------*) diff --git a/lib/socExecValue.ml b/lib/socExecValue.ml index a800ea55..8a289c25 100644 --- a/lib/socExecValue.ml +++ b/lib/socExecValue.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 06/03/2020 (at 13:30) by Erwan Jahier> *) +(* Time-stamp: <modified the 15/03/2021 (at 15:44) by Erwan Jahier> *) let dbg = (Lv6Verbose.get_flag "exec") @@ -285,11 +285,17 @@ let rec (get_value : ctx -> var_expr -> Data.v) = | Field(ve,fn,_t) -> let s = get_value ctx ve in (match s with - | S fl -> ( - try List.assoc fn fl - with Not_found -> assert false (* should not occur *) + | U -> U + | S fl -> ( + try List.assoc fn fl + with Not_found -> assert false (* should not occur *) ) - | _ -> assert false (* should not occur *) + | _ -> + let msg = Printf.sprintf "'%s' is not a struct\n" + (SocUtils.string_of_filter ve) + in + failwith msg + (* assert false (* should not occur *) *) ) | Index(ve,i,_vt) -> ( let a = get_value ctx ve in -- GitLab