Local Open Scope logic.
Section NESTED_RAMIF.
Context {cs: compspecs}.

(* Specifications: *)
Lemma reptype_Tarray_JMeq_constr0: forall t gfs t0 n a (v: reptype (nested_field_type t gfs)),
legal_nested_field t gfs ->
nested_field_type t gfs = Tarray t0 n a ->
{v': list (reptype (nested_field_type t (ArraySubsc 0 :: gfs))) |
JMeq v v'}.
Lemma reptype_Tarray_JMeq_constr1: forall t gfs t0 n a i (v: reptype (nested_field_type t (ArraySubsc i :: gfs))),
legal_nested_field t gfs ->
nested_field_type t gfs = Tarray t0 n a ->
{v': reptype (gfield_type (nested_field_type t gfs) (ArraySubsc i)) |
JMeq v v'}.
Lemma reptype_Tarray_JMeq_constr2: forall t gfs t0 n a i (v': reptype (nested_field_type t (ArraySubsc i :: gfs))),
legal_nested_field t gfs ->
nested_field_type t gfs = Tarray t0 n a ->
{v: reptype (nested_field_type t (ArraySubsc 0 :: gfs)) |
JMeq v' v}.
Lemma reptype_Tstruct_JMeq_constr0: forall t gfs id a (v: reptype (nested_field_type t gfs)),
legal_nested_field t gfs ->
nested_field_type t gfs = Tstruct id a ->
{v' : nested_reptype_structlist t gfs (co_members (get_co id)) |
JMeq v v'}.
Lemma reptype_Tunion_JMeq_constr0: forall t gfs id a (v: reptype (nested_field_type t gfs)),
legal_nested_field t gfs ->
nested_field_type t gfs = Tunion id a ->
{v' : nested_reptype_unionlist t gfs (co_members (get_co id)) |
JMeq v v'}.
(* This lemma is mainly dealing with all JMeq subtle issues and combine 3 ramif lemmas together. *)
Lemma gfield_ramif: forall sh t gfs gf v v0 p,
JMeq (proj_gfield_reptype (nested_field_type t gfs) gf v) v0 ->
field_compatible t (gf :: gfs) p ->
field_at sh t gfs v p |-- field_at sh t (gf :: gfs) v0 p *
(ALL v0': _,
(field_at sh t (gf :: gfs) v0' p -*
field_at sh t gfs
(upd_gfield_reptype (nested_field_type t gfs) gf v
(eq_rect_r reptype v0' (eq_sym (nested_field_type_ind t _))))
p)).
Lemma nested_field_ramif: forall sh t gfs0 gfs1 v v0 p,
JMeq (proj_reptype (nested_field_type t gfs0) gfs1 v) v0 ->
field_compatible t (gfs1 ++ gfs0) p ->
field_at sh t gfs0 v p |--
field_at sh t (gfs1 ++ gfs0) v0 p *
(ALL v0': _, ALL v0'': _, !! JMeq v0' v0'' -->
(field_at sh t (gfs1 ++ gfs0) v0' p -*
field_at sh t gfs0 (upd_reptype (nested_field_type t gfs0) gfs1 v v0'') p)).
Lemma nested_field_ramif_load: forall sh t gfs0 gfs1 (v_reptype: reptype (nested_field_type t gfs0)) (v_val: val) p,
field_compatible t (gfs1 ++ gfs0) p ->
JMeq (proj_reptype (nested_field_type t gfs0) gfs1 v_reptype) v_val ->
exists v_reptype',
JMeq v_reptype' v_val /\
field_at sh t gfs0 v_reptype p |--
field_at sh t (gfs1 ++ gfs0) v_reptype' p * TT.
Lemma nested_field_ramif_store: forall sh t gfs0 gfs1 (v_reptype: reptype (nested_field_type t gfs0)) (v0_reptype: reptype (nested_field_type (nested_field_type t gfs0) gfs1)) (v_val: val) p,
field_compatible t (gfs1 ++ gfs0) p ->
JMeq v0_reptype v_val ->
exists v0_reptype',
JMeq v0_reptype' v_val /\
field_at sh t gfs0 v_reptype p |--
field_at_ sh t (gfs1 ++ gfs0) p *
(field_at sh t (gfs1 ++ gfs0) v0_reptype' p -*
field_at sh t gfs0 (upd_reptype (nested_field_type t gfs0) gfs1 v_reptype v0_reptype) p).
Lemma nested_field_ramif': forall sh t gfs0 gfs1 v v0 p,
JMeq (proj_reptype (nested_field_type t gfs0) gfs1 v) v0 ->
legal_nested_field t (gfs1 ++ gfs0) ->
field_at sh t gfs0 v p |--
field_at sh t (gfs1 ++ gfs0) v0 p *
(ALL v0': _, ALL v0'': _, !! JMeq v0' v0'' -->
(field_at sh t (gfs1 ++ gfs0) v0' p -*
field_at sh t gfs0 (upd_reptype (nested_field_type t gfs0) gfs1 v v0'') p)).
Lemma nested_field_ramif'': forall sh t gfs0 gfs1 v v0 p,
JMeq (proj_reptype (nested_field_type t gfs0) gfs1 v) v0 ->
legal_nested_field (nested_field_type t gfs0) gfs1 ->
field_at sh t gfs0 v p |--
field_at sh t (gfs1 ++ gfs0) v0 p *
(ALL v0': _, ALL v0'': _, !! JMeq v0' v0'' -->
(field_at sh t (gfs1 ++ gfs0) v0' p -*
field_at sh t gfs0 (upd_reptype (nested_field_type t gfs0) gfs1 v v0'') p)).