Skip to content
Snippets Groups Projects
Commit a3084f08 authored by Julien Signoles's avatar Julien Signoles
Browse files

[translate] add a few assertions

parent 2a3171cf
No related branches found
No related tags found
No related merge requests found
...@@ -210,8 +210,8 @@ let conditional_to_exp ?(name="if") loc t_opt e1 (e2, env2) (e3, env3) = ...@@ -210,8 +210,8 @@ let conditional_to_exp ?(name="if") loc t_opt e1 (e2, env2) (e3, env3) =
let lv = Cil.var v in let lv = Cil.var v in
let ty = Cil.typeOf ev in let ty = Cil.typeOf ev in
let init_set = let init_set =
(* TODO RATIONAL: how is it possible to get a real here? *) assert (not (Real.is_t ty));
if Real.is_t ty then Real.init_set else Gmp.init_set Gmp.init_set
in in
let affect e = init_set ~loc lv ev e in let affect e = init_set ~loc lv ev e in
let then_block, _ = let then_block, _ =
...@@ -340,12 +340,10 @@ and context_insensitive_term_to_exp kf env t = ...@@ -340,12 +340,10 @@ and context_insensitive_term_to_exp kf env t =
else if Real.is_t ty then else if Real.is_t ty then
let e, env = Real.binop ~loc bop e1 e2 env (Some t) in let e, env = Real.binop ~loc bop e1 e2 env (Some t) in
e, env, C_number, "" e, env, C_number, ""
else else begin
if Logic_typing.is_integral_type t.term_type then assert (Logic_typing.is_integral_type t.term_type);
Cil.new_exp ~loc (BinOp(bop, e1, e2, ty)), env, C_number, "" Cil.new_exp ~loc (BinOp(bop, e1, e2, ty)), env, C_number, ""
else end
(* TODO RATIONAL: why question mark? *)
not_yet env "floating-point context (?)"
| TBinOp(Div | Mod as bop, t1, t2) -> | TBinOp(Div | Mod as bop, t1, t2) ->
let ty = Typing.get_typ t in let ty = Typing.get_typ t in
let e1, env = term_to_exp kf env t1 in let e1, env = term_to_exp kf env t1 in
...@@ -368,19 +366,19 @@ and context_insensitive_term_to_exp kf env t = ...@@ -368,19 +366,19 @@ and context_insensitive_term_to_exp kf env t =
~loc kf env Typing.gmpz ~e1:e2 ~name Eq t2 zero t ~loc kf env Typing.gmpz ~e1:e2 ~name Eq t2 zero t
in in
let mk_stmts _v e = let mk_stmts _v e =
assert (Gmp.Z.is_t ty); assert (Gmp.Z.is_t ty);
let vis = Env.get_visitor env in let vis = Env.get_visitor env in
let kf = Extlib.the vis#current_kf in let kf = Extlib.the vis#current_kf in
let cond = let cond =
Misc.mk_e_acsl_guard Misc.mk_e_acsl_guard
(Env.annotation_kind env) (Env.annotation_kind env)
kf kf
guard guard
(Logic_const.prel ~loc (Req, t2, zero)) (Logic_const.prel ~loc (Req, t2, zero))
in in
Env.add_assert env cond (Logic_const.prel (Rneq, t2, zero)); Env.add_assert env cond (Logic_const.prel (Rneq, t2, zero));
let instr = Misc.mk_call ~loc name [ e; e1; e2 ] in let instr = Misc.mk_call ~loc name [ e; e1; e2 ] in
[ cond; instr ] [ cond; instr ]
in in
let name = Misc.name_of_binop bop in let name = Misc.name_of_binop bop in
let _, e, env = Env.new_var_and_mpz_init ~loc ~name env t mk_stmts in let _, e, env = Env.new_var_and_mpz_init ~loc ~name env t mk_stmts in
...@@ -388,13 +386,11 @@ and context_insensitive_term_to_exp kf env t = ...@@ -388,13 +386,11 @@ and context_insensitive_term_to_exp kf env t =
else if Real.is_t ty then else if Real.is_t ty then
let e, env = Real.binop ~loc bop e1 e2 env (Some t) in let e, env = Real.binop ~loc bop e1 e2 env (Some t) in
e, env, C_number, "" e, env, C_number, ""
else else begin
assert (Logic_typing.is_integral_type t.term_type);
(* no guard required since RTEs are generated separately *) (* no guard required since RTEs are generated separately *)
if Logic_typing.is_integral_type t.term_type then
Cil.new_exp ~loc (BinOp(bop, e1, e2, ty)), env, C_number, "" Cil.new_exp ~loc (BinOp(bop, e1, e2, ty)), env, C_number, ""
else end
(* TODO RATIONAL: why question mark? *)
not_yet env "floating-point context (?)"
| TBinOp(Lt | Gt | Le | Ge | Eq | Ne as bop, t1, t2) -> | TBinOp(Lt | Gt | Le | Ge | Eq | Ne as bop, t1, t2) ->
(* comparison operators *) (* comparison operators *)
let ity = Typing.get_integer_op t in let ity = Typing.get_integer_op t in
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment