(********************************************  Max length gfs field_at load store: semax_max_path_field_load_nth_ram. semax_max_path_field_cast_load_nth_ram. semax_max_path_field_store_nth_ram.  ********************************************)
Section LOADSTORE_FIELD_AT.
Context {cs: compspecs}.

(* Specifications: *)
Lemma self_ramify_trans: forall {A} `{SepLog A} (g m l: A), g |-- m * TT -> m |-- l * TT -> g |-- l * TT.
Lemma semax_load_nth_ram_field_at :
forall {Espec: OracleKind}{cs: compspecs} n (Delta: tycontext) sh id P Q R e1 Pre
t_id t_root gfs (p v_val: val) (v_reptype: reptype (nested_field_type t_root gfs)),
typeof e1 = nested_field_type t_root gfs ->
typeof_temp Delta id = Some t_id ->
is_neutral_cast (nested_field_type t_root gfs) t_id = true ->
type_is_volatile (nested_field_type t_root gfs) = false ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfs p)) (eval_lvalue e1)) ->
nth_error R n = Some Pre ->
readable_share sh ->
Pre |-- field_at sh t_root gfs v_reptype p * TT ->
JMeq v_reptype v_val ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_lvalue Delta e1) && local (`(tc_val (nested_field_type t_root gfs) v_val)) ->
@semax cs Espec Delta (|> PROPx P (LOCALx Q (SEPx R)))
(Sset id e1)
(normal_ret_assert
(PROPx P
(LOCALx (temp id v_val :: remove_localdef_temp id Q)
(SEPx R)))).
(* TODO: delete it *)
Lemma semax_max_path_field_load_nth_ram:
forall {Espec: OracleKind},
forall n Delta sh id P Q R (e1: expr) Pre
(t t_root: type) (efs: list efield) (gfs: list gfield) (tts: list type)
(p v : val) (v' : reptype (nested_field_type t_root gfs)) lr,
typeof_temp Delta id = Some t ->
is_neutral_cast (typeof (nested_efield e1 efs tts)) t = true ->
readable_share sh ->
LR_of_type t_root = lr ->
type_is_volatile (typeof (nested_efield e1 efs tts)) = false ->
legal_nested_efield t_root e1 gfs tts lr = true ->
JMeq v' v ->
nth_error R n = Some Pre ->
Pre |-- field_at sh t_root gfs v' p * TT ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq p) (eval_LR e1 lr)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_LR Delta e1 lr) &&
(tc_efield Delta efs) &&
local (efield_denote efs gfs) &&
local `(tc_val (typeof (nested_efield e1 efs tts)) v) ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sset id (nested_efield e1 efs tts))
(normal_ret_assert
(PROPx P
(LOCALx (temp id v :: remove_localdef_temp id Q)
(SEPx R)))).
(* TODO: delete it *)
Lemma semax_max_path_field_load_nth_ram':
forall {Espec: OracleKind},
forall n Delta sh id P Q R (e: expr) Pre
(t t_root: type) (gfs: list gfield)
(p v : val) (v' : reptype (nested_field_type t_root gfs)),
typeof_temp Delta id = Some t ->
is_neutral_cast (typeof e) t = true ->
typeof e = nested_field_type t_root gfs ->
readable_share sh ->
type_is_volatile (typeof e) = false ->
JMeq v' v ->
nth_error R n = Some Pre ->
Pre |-- field_at sh t_root gfs v' p * TT ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfs p)) (eval_lvalue e)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_lvalue Delta e) &&
local `(tc_val (typeof e) v) ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sset id e)
(normal_ret_assert
(PROPx P
(LOCALx (temp id v :: remove_localdef_temp id Q)
(SEPx R)))).
(* TODO: delete it *)
Lemma semax_max_path_field_load_nth_ram'':
forall {Espec: OracleKind},
forall n Delta sh id P Q R (e1: expr) Pre
(t t_root: type) (efs: list efield) (gfsA gfsB: list gfield) (tts: list type)
(a v : val) (v' : reptype (nested_field_type t_root (gfsB ++ gfsA))) lr,
typeof_temp Delta id = Some t ->
is_neutral_cast (typeof (nested_efield e1 efs tts)) t = true ->
readable_share sh ->
LR_of_type (nested_field_type t_root gfsA) = lr ->
type_is_volatile (typeof (nested_efield e1 efs tts)) = false ->
legal_nested_efield (nested_field_type t_root gfsA) e1 gfsB tts lr = true ->
JMeq v' v ->
nth_error R n = Some Pre ->
Pre |-- field_at sh t_root (gfsB ++ gfsA) v' a * TT ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfsA a)) (eval_LR e1 lr)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_LR Delta e1 lr) &&
(tc_efield Delta efs) &&
local (efield_denote efs gfsB) &&
local `(tc_val (typeof (nested_efield e1 efs tts)) v) ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sset id (nested_efield e1 efs tts))
(normal_ret_assert
(PROPx P
(LOCALx (temp id v :: remove_localdef_temp id Q)
(SEPx R)))).
Lemma semax_cast_load_nth_ram_field_at :
forall {Espec: OracleKind}{cs: compspecs} n (Delta: tycontext) sh id P Q R e1 Pre
t_to t_root gfs (p v_val: val) (v_reptype: reptype (nested_field_type t_root gfs)),
typeof e1 = nested_field_type t_root gfs ->
type_is_by_value (nested_field_type t_root gfs) = true ->
type_is_volatile (nested_field_type t_root gfs) = false ->
typeof_temp Delta id = Some t_to ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfs p)) (eval_lvalue e1)) ->
nth_error R n = Some Pre ->
cast_pointer_to_bool (nested_field_type t_root gfs) t_to = false ->
readable_share sh ->
Pre |-- field_at sh t_root gfs v_reptype p * TT ->
JMeq v_reptype v_val ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_lvalue Delta e1) && local (`(tc_val t_to (eval_cast (nested_field_type t_root gfs) t_to v_val))) ->
@semax cs Espec Delta (|> PROPx P (LOCALx Q (SEPx R)))
(Sset id (Ecast e1 t_to))
(normal_ret_assert
(PROPx P
(LOCALx (temp id (eval_cast (nested_field_type t_root gfs) t_to v_val) :: remove_localdef_temp id Q)
(SEPx R)))).
(* TODO: delete it *)
Lemma semax_max_path_field_cast_load_nth_ram:
forall {Espec: OracleKind},
forall n Delta sh id P Q R (e1: expr) Pre
(t t_root: type) (efs: list efield) (gfs: list gfield) (tts: list type)
(p v: val) (v' : reptype (nested_field_type t_root gfs)) lr,
typeof_temp Delta id = Some t ->
type_is_by_value (typeof (nested_efield e1 efs tts)) = true ->
cast_pointer_to_bool (typeof (nested_efield e1 efs tts)) t = false ->
readable_share sh ->
LR_of_type t_root = lr ->
type_is_volatile (typeof (nested_efield e1 efs tts)) = false ->
legal_nested_efield t_root e1 gfs tts lr = true ->
JMeq v' v ->
nth_error R n = Some Pre ->
Pre |-- field_at sh t_root gfs v' p * TT ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq p) (eval_LR e1 lr)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_LR Delta e1 lr) &&
(tc_efield Delta efs) &&
local (efield_denote efs gfs) &&
local `(tc_val t (eval_cast (typeof (nested_efield e1 efs tts)) t v)) ->
semax Delta (|> PROPx P (LOCALx Q (SEPx R)))
(Sset id (Ecast (nested_efield e1 efs tts) t))
(normal_ret_assert
(PROPx P
(LOCALx (temp id (eval_cast (typeof (nested_efield e1 efs tts)) t v) :: remove_localdef_temp id Q)
(SEPx R)))).
Lemma lower_andp_lifted_val:
forall (P Q: val->mpred) v,
(`(P && Q) v) = (`P v && `Q v).
Lemma semax_store_nth_ram_field_at:
forall {Espec: OracleKind} {cs: compspecs} n Delta sh P Q R e1 e2 Pre Post
t_root gfs (p v_val: val) (v_reptype: reptype (nested_field_type t_root gfs)),
typeof e1 = nested_field_type t_root gfs ->
type_is_by_value (nested_field_type t_root gfs) = true ->
type_is_volatile (nested_field_type t_root gfs) = false ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfs p)) (eval_lvalue e1)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq v_val) (eval_expr (Ecast e2 (nested_field_type t_root gfs)))) ->
JMeq v_val v_reptype ->
nth_error R n = Some Pre ->
writable_share sh ->
Pre |-- field_at_ sh t_root gfs p * (field_at sh t_root gfs v_reptype p -* Post) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_lvalue Delta e1) && (tc_expr Delta (Ecast e2 (nested_field_type t_root gfs))) ->
semax Delta
(|> PROPx P (LOCALx Q (SEPx R)))
(Sassign e1 e2)
(normal_ret_assert
(PROPx P (LOCALx Q (SEPx (replace_nth n R Post))))).
(* TODO: delete it *)
Lemma semax_max_path_field_store_nth_ram:
forall {Espec: OracleKind},
forall n Delta sh P Q R (e1 e2 : expr) Pre Post
(t_root: type) (efs: list efield) (gfs: list gfield) (tts: list type)
(p v : val) (v' : reptype (nested_field_type t_root gfs)) lr,
type_is_by_value (typeof (nested_efield e1 efs tts)) = true ->
writable_share sh ->
LR_of_type t_root = lr ->
type_is_volatile (typeof (nested_efield e1 efs tts)) = false ->
legal_nested_efield t_root e1 gfs tts lr = true ->
JMeq v v' ->
nth_error R n = Some Pre ->
Pre |-- field_at_ sh t_root gfs p *
(field_at sh t_root gfs v' p -* Post) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq p) (eval_LR e1 lr)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq v) (eval_expr (Ecast e2 (typeof (nested_efield e1 efs tts))))) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_LR Delta e1 lr) &&
(tc_efield Delta efs) &&
local (efield_denote efs gfs) &&
(tc_expr Delta (Ecast e2 (typeof (nested_efield e1 efs tts)))) ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sassign (nested_efield e1 efs tts) e2)
(normal_ret_assert
(PROPx P
(LOCALx Q
(SEPx
(replace_nth n R Post))))).
(* TODO: delete it *)
Lemma semax_partial_path_field_store_nth_ram:
forall {Espec: OracleKind},
forall n Delta sh P Q R (e1 e2 : expr) Pre Post
(t_root: type) (efs: list efield) (gfsA gfsB: list gfield) (tts: list type)
(a v : val) (v' : reptype (nested_field_type t_root (gfsB ++ gfsA))) lr,
type_is_by_value (typeof (nested_efield e1 efs tts)) = true ->
writable_share sh ->
LR_of_type (nested_field_type t_root gfsA) = lr ->
type_is_volatile (typeof (nested_efield e1 efs tts)) = false ->
JMeq v v' ->
nth_error R n = Some Pre ->
Pre |-- field_at_ sh t_root (gfsB ++ gfsA) a *
(field_at sh t_root (gfsB ++ gfsA) v' a -* Post) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfsA a)) (eval_LR e1 lr)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq v) (eval_expr (Ecast e2 (typeof (nested_efield e1 efs tts))))) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_LR Delta e1 lr) &&
(tc_efield Delta efs) &&
local (efield_denote efs gfsB) &&
(tc_expr Delta (Ecast e2 (typeof (nested_efield e1 efs tts)))) ->
legal_nested_efield (nested_field_type t_root gfsA) e1 gfsB tts lr = true ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sassign (nested_efield e1 efs tts) e2)
(normal_ret_assert
(PROPx P
(LOCALx Q
(SEPx
(replace_nth n R Post))))).
(* TODO: delete it *)
Lemma semax_no_path_field_store_nth_ram:
forall {Espec: OracleKind},
forall n Delta sh P Q R (e1 e2 : expr) Pre Post
(t_root: type) (gfs: list gfield)
(a v : val) (v' : reptype (nested_field_type t_root gfs)),
type_is_by_value (typeof e1) = true ->
writable_share sh ->
type_is_volatile (typeof e1) = false ->
typeof e1 = nested_field_type t_root gfs ->
JMeq v v' ->
nth_error R n = Some Pre ->
Pre |-- field_at_ sh t_root gfs a *
(field_at sh t_root gfs v' a -* Post) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq (field_address t_root gfs a)) (eval_lvalue e1)) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
local (`(eq v) (eval_expr (Ecast e2 (typeof e1)))) ->
ENTAIL Delta, PROPx P (LOCALx Q (SEPx R)) |--
(tc_lvalue Delta e1) &&
(tc_expr Delta (Ecast e2 (typeof e1))) ->
semax Delta (|>PROPx P (LOCALx Q (SEPx R)))
(Sassign e1 e2)
(normal_ret_assert
(PROPx P
(LOCALx Q
(SEPx
(replace_nth n R Post))))).