Commit f9999594 authored by Erwan Jahier's avatar Erwan Jahier

Be more permissive in the RIF reader, converting data when sensible, and truncating

too big integers. Also, set the default min and max for vars to biggers values.
parent 460b996f
......@@ -14,8 +14,8 @@ open Constraint
let output_msg msg =
output_string stdout msg;
flush stdout
output_string stderr msg;
flush stderr
(** [lookup input pre vn] looks up the value of vn in [pre] and [input] *)
......@@ -451,15 +451,25 @@ and
)
)
| Some(N(F(f))) ->
output_msg "\n*** Type error.\n*** ";
output_msg "\n*** Warning : type error, ";
output_msg ((string_of_float f)
^ " is a float, but an int is expected.\n");
exit 2
let i = int_of_float f in
(Gne.make
(Ne.make "" (I i))
(Bdd.dtrue !bdd_manager)
true
)
| Some(B(f)) ->
output_msg "\n*** Type error.\n*** ";
output_msg "\n*** Warning : type error, ";
output_msg ((string_of_bool f)
^ " is a bool, but an int is expected.\n");
exit 2
^ " is a bool, but an int is expected. " ^
"Continuing with 0.\n");
(Gne.make
(Ne.make "" (I 0))
(Bdd.dtrue !bdd_manager)
true
)
)
| Fvar(v) ->
......@@ -489,15 +499,23 @@ and
)
)
| Some(N(I(i))) ->
output_msg "\n*** Type error.\n*** ";
output_msg "\n*** Warning: type error, ";
output_msg ((string_of_int i)
^ " is an int, but a float is expected.\n");
exit 2
(Gne.make
(Ne.make str (F(float_of_int i)))
(Bdd.dtrue !bdd_manager)
false
)
| Some(B(f)) ->
output_msg "\n*** Type error.\n*** ";
output_msg "\n*** Warning: type error, ";
output_msg ((string_of_bool f)
^ " is a bool, but a float is expected.\n");
exit 2
(Gne.make
(Ne.make str (F(0.0)))
(Bdd.dtrue !bdd_manager)
false
)
)
| Ival(i) ->
......
......@@ -53,6 +53,23 @@ let get_string () =
(* The lexer *)
(* Avoid crashing if int are too big *)
let my_int_of_string str =
try int_of_string str
with _ ->
let i64 = Int64.of_string str in
let i = if i64 > (Int64.of_int max_int) then
max_int / 2
else if i64 < (Int64.of_int min_int) then
min_int / 2
else
Int64.to_int i64 (* deadcode IMHO *)
in
Printf.eprintf "Warning: The integer %s is too big: truncate it to %i\n" str i;
flush stderr;
i
let make_lexer keywords =
let kwd_table = Hashtbl.create 17 in
List.iter (fun s -> Hashtbl.add kwd_table s "dummy") keywords;
......@@ -144,7 +161,9 @@ let make_lexer keywords =
Stream.junk strm__; let s = strm__ in store 'E'; exponent_part s
| _ ->
let s = (get_string ()) in
Some (Int ((debut,(Stream.count strm__)), (int_of_string s)))
Some (Int ((debut,(Stream.count strm__)),
(my_int_of_string s)
))
and decimal_part (strm__ : _ Stream.t) =
let debut = Stream.count strm__ in
match Stream.peek strm__ with
......
......@@ -130,18 +130,19 @@ let (get_untouched_var : t' -> Exp.var list) =
XXX ougth to be modifiable from the outside.
nb : if those values are too big, sim2chro crashes ....
*)
let default_min_float = -10000.
let default_max_float = 10000.
let default_max_int = 10000
let default_min_int = -10000
(* let default_min_float = -10000. *)
(* let default_max_float = 10000. *)
(* let default_max_int = 10000 *)
(* let default_min_int = -10000 *)
(*
XXX What should be the default values ???
Too big values migth break other tools (e.g., sim2chro...)
*)
(* let default_max_float = *)
let default_max_float = float_of_int (max_int/2)
(* (float_of_int max_int) /. 2.**(float_of_int (!Util.precision + 1)) *)
(* let default_max_int = max_int/10 *)
(* let default_min_int = min_int/10 *)
let default_min_float = -. default_max_float
let default_max_int = max_int/2
let default_min_int = min_int/2
(* exported *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment