Require Import Relations.
Require Import Coqlib.
Require Import LibPos.
Require Import Maps.
Require Import LibLists.
Require Import Cppsem.
Require Import Cplusconcepts.
Require Import CplusWf.
Require Import Events.
Require Import Invariant.
Require Import SubobjectOrdering.
Require Import ConstrSubobjectOrdering.
Load Param.
Open Scope nat_scope.
Lemma constructed_sibling_before_not_bases_constructed :
forall a1 a2,
constructed_sibling_before a1 a2 ->
(
a1 =
Some BasesConstructed \/
a1 =
Some StartedDestructing) ->
(
a2 =
Some BasesConstructed \/
a2 =
Some StartedDestructing) ->
False.
Proof.
Lemma constructed_base_child_of_not_bases_constructed :
forall a1 a2,
constructed_base_child_of a2 a1 ->
(
a1 =
Some BasesConstructed \/
a1 =
Some StartedDestructing) ->
(
a2 =
Some BasesConstructed \/
a2 =
Some StartedDestructing) ->
False.
Proof.
Section DynamicType.
Variable A :
ATOM.t.
Open Scope Z_scope.
Section Get_dynamic_type.
Variable hierarchy :
PTree.t (
Class.t A).
Variable heap :
PTree.t Object.t.
Variable construction_states :
list ((
ident * (
array_path A *
Z * (
Class.Inheritance.t *
list ident))) *
construction_state).
Variable obj :
ident.
Variable ar :
array_path A.
Variable i :
Z.
Inductive get_dynamic_type :
Class.Inheritance.t ->
list ident ->
Prop :=
|
get_dynamic_type_most_derived_constructed
(
o :
_)
(
_ : (
heap) !
obj =
Some o)
(
ato :
_) (
zto :
_)
(
_ :
valid_array_path (
hierarchy )
ato zto (
Object.class o) (
Object.arraysize o)
ar)
(
_ : 0 <=
i <
zto)
(
_ :
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
Class.Inheritance.Repeated,
ato ::
nil))) (
construction_states) =
Some Constructed) :
get_dynamic_type
Class.Inheritance.Repeated
(
ato ::
nil)
|
get_dynamic_type_constructing_or_destructing
(
o :
_)
(
_ : (
heap) !
obj =
Some o)
(
ato :
_) (
zto :
_)
(
_ :
valid_array_path (
hierarchy )
ato zto (
Object.class o) (
Object.arraysize o)
ar)
(
_ : 0 <=
i <
zto)
(
mdto :
_) (
mdh :
_) (
mdp :
_)
(
_ :
path (
hierarchy )
mdto mdp ato mdh)
(
mdcs :
_)
(
_ :
mdcs =
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
mdh,
mdp))) (
construction_states))
(
_ :
mdcs =
Some BasesConstructed \/
mdcs =
Some StartedDestructing)
:
get_dynamic_type
mdh
mdp
.
Lemma dynamic_type_get_dynamic_type :
forall h p h1 p1 h2 p2,
dynamic_type hierarchy heap construction_states obj ar i h p h1 p1 h2 p2 ->
get_dynamic_type h1 p1.
Proof.
inversion 1; subst.
eleft; eauto.
eright; eauto.
Qed.
Lemma get_dynamic_type_dynamic_type :
forall h1 p1,
get_dynamic_type h1 p1 ->
forall cn,
last p1 =
Some cn ->
forall to h2 p2,
path hierarchy to p2 cn h2 ->
forall h'
p', (
h',
p') =
concat (
h1,
p1) (
h2,
p2) ->
dynamic_type hierarchy heap construction_states obj ar i h'
p'
h1 p1 h2 p2.
Proof.
inversion 1;
subst.
injection 1;
intros;
subst.
erewrite concat_trivial_left in H7.
injection H7;
intros;
subst.
eleft;
eauto.
eassumption.
rewrite (
path_last H3).
injection 1;
intros;
subst.
eright;
eauto.
Qed.
Lemma get_dynamic_type_prop :
forall h1 p1,
get_dynamic_type h1 p1 ->
exists o,
(
heap) !
obj =
Some o /\
exists ato,
exists zto,
valid_array_path (
hierarchy )
ato zto (
Object.class o) (
Object.arraysize o)
ar /\
0 <=
i <
zto /\
(
((
h1,
p1) = (
Class.Inheritance.Repeated,
ato ::
nil) /\
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
h1,
p1)))
construction_states =
Some Constructed)
\/
exists mdto,
path (
hierarchy )
mdto p1 ato h1
/\
(
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
h1,
p1))) (
construction_states) =
Some BasesConstructed \/
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
h1,
p1))) (
construction_states) =
Some StartedDestructing
)
).
Proof.
inversion 1; subst; eauto 10.
Qed.
End Get_dynamic_type.
Variable nativeop :
Type.
Variable sem :
semparam A nativeop.
Variable prog :
Program.t A nativeop.
Hypothesis hierarchy_wf :
Well_formed_hierarchy.prop (
Program.hierarchy prog).
Variable state :
State.t A nativeop.
Variable Hinv:
invariant prog state.
Variable obj :
ident.
Variable ar :
array_path A.
Variable i :
Z.
Lemma bases_constructed_unique :
forall
(
o :
_)
(
_ : (
Globals.heap (
State.global state)) !
obj =
Some o)
(
ato :
_) (
zto :
_)
(
_ :
valid_array_path (
Program.hierarchy prog)
ato zto (
Object.class o) (
Object.arraysize o)
ar)
(
_ : 0 <=
i <
zto)
(
mdh1 :
_) (
mdp1 :
_) (
to1 :
_) (
_ :
path (
Program.hierarchy prog)
to1 mdp1 ato mdh1)
(
mdcs1 :
_)
(
_ :
mdcs1 =
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
mdh1,
mdp1))) (
State.construction_states state))
(
_ :
mdcs1 =
Some BasesConstructed \/
mdcs1 =
Some StartedDestructing)
(
mdh2 :
_) (
mdp2 :
_) (
to2 :
_) (
_ :
path (
Program.hierarchy prog)
to2 mdp2 ato mdh2)
(
mdcs2 :
_)
(
_ :
mdcs2 =
assoc (@
pointer_eq_dec _) (
obj, (
ar,
i, (
mdh2,
mdp2))) (
State.construction_states state))
(
_ :
mdcs2 =
Some BasesConstructed \/
mdcs2 =
Some StartedDestructing)
,
(
mdh1,
mdp1) = (
mdh2,
mdp2)
.
Proof.
Corollary get_dynamic_type_unique :
forall
mdh1 mdp1,
get_dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i mdh1 mdp1 ->
forall mdh2 mdp2,
get_dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i mdh2 mdp2 ->
(
mdh1,
mdp1) = (
mdh2,
mdp2).
Proof.
Corollary dynamic_type_unique_very_strong :
forall
h1 p1 mdh1 mdp1 mdh'1
mdp'1,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h1 p1 mdh1 mdp1 mdh'1
mdp'1 ->
forall h2 p2 mdh2 mdp2 mdh'2
mdp'2,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h2 p2 mdh2 mdp2 mdh'2
mdp'2 ->
(
mdh1,
mdp1) = (
mdh2,
mdp2).
Proof.
Section Dynamic_type_unique.
Variable h:
Class.Inheritance.t.
Variable p:
list ident.
Lemma dynamic_type_same_complement :
forall mdh mdp mdh'
mdp',
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh mdp mdh'
mdp' ->
forall mdh'2
mdp'2,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh mdp mdh'2
mdp'2 ->
(
mdh',
mdp') = (
mdh'2,
mdp'2).
Proof.
POPL 2012 submission: Theorem 17
Corollary dynamic_type_unique :
forall
mdh1 mdp1 mdh'1
mdp'1,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh1 mdp1 mdh'1
mdp'1 ->
forall mdh2 mdp2 mdh'2
mdp'2,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh2 mdp2 mdh'2
mdp'2 ->
(
mdh1,
mdp1) = (
mdh2,
mdp2).
Proof.
Corollary dynamic_type_unique_strong :
forall
mdh1 mdp1 mdh'1
mdp'1,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh1 mdp1 mdh'1
mdp'1 ->
forall mdh2 mdp2 mdh'2
mdp'2,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh2 mdp2 mdh'2
mdp'2 ->
(
mdh1,
mdp1,
mdh'1,
mdp'1) = (
mdh2,
mdp2,
mdh'2,
mdp'2).
Proof.
Lemma dynamic_type_not_deallocated :
forall
mdh1 mdp1 mdh'1
mdp'1,
dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i h p mdh1 mdp1 mdh'1
mdp'1 ->
In obj (
State.deallocated_objects state) ->
False.
Proof.
End Dynamic_type_unique.
Corollary get_dynamic_type_not_deallocated :
forall
mdh1 mdp1,
get_dynamic_type (
Program.hierarchy prog) (
Globals.heap (
State.global state)) (
State.construction_states state)
obj ar i mdh1 mdp1 ->
In obj (
State.deallocated_objects state) ->
False.
Proof.
End DynamicType.