(*Require Import VST.floyd.fieldlist.*)
(*Require Import VST.floyd.aggregate_type.*)
Require Export VST.floyd.fieldlist.
Require Export VST.floyd.aggregate_type.
Open Scope Z.
Open Scope logic.
(******************************************  Definition and lemmas about rangespec  ******************************************)
Fixpoint rangespec (lo: Z) (n: nat) (P: Z -> val -> mpred): val -> mpred :=
match n with
| O => fun _ => emp
| S n' => P lo * rangespec (Z.succ lo) n' P
end.
Fixpoint fold_range' {A: Type} (f: Z -> A -> A) (zero: A) (lo: Z) (n: nat) : A :=
match n with
| O => zero
| S n' => f lo (fold_range' f  zero (Z.succ lo) n')
end.
Definition fold_range {A: Type} (f: Z -> A -> A) (zero: A) (lo hi: Z) : A :=
fold_range' f zero lo (Z.to_nat (hi-lo)).
Inductive Forallz {A} (P: Z -> A->Prop) : Z -> list A -> Prop :=
| Forallz_nil : forall i, Forallz P i nil
| Forallz_cons : forall i x l, P i x -> Forallz P (Z.succ i) l -> Forallz P i (x::l).
(******************************************  Definition of aggregate predicates.  ******************************************)
Definition array_pred {A: Type}{d: Inhabitant A}  (lo hi: Z) (P: Z -> A -> val -> mpred) (v: list A) (p: val) : mpred :=
!! (Zlength v = hi - lo) &&
rangespec lo (Z.to_nat (hi-lo)) (fun i => P i (Znth (i-lo) v)) p.
Definition struct_pred (m: members) {A: ident * type -> Type} (P: forall it, A it -> val -> mpred) (v: compact_prod (map A m)) (p: val): mpred.
Opaque member_dec.

Lemma union_pred_ramif: forall m {A} (P: forall it, A it -> val -> mpred) (i: ident) v p d,
(forall i' (v': A (i', field_type i' m)), in_members i' m -> P _ v' p |-- P _ d p) ->
in_members i m ->
members_no_replicate m = true ->
union_pred m P v p |--
P _ (proj_union i m v d) p *
(ALL v0: _, P _ v0 p -* union_pred m P (upd_union i m v v0) p).