author | schirmer |
Thu, 31 Oct 2002 18:27:10 +0100 | |
changeset 13688 | a0b16d42d489 |
parent 13601 | fd3e3d6b37b2 |
child 14025 | d9b155757dc8 |
permissions | -rw-r--r-- |
12857 | 1 |
(* Title: HOL/Bali/WellForm.thy |
12854 | 2 |
ID: $Id$ |
12925
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12893
diff
changeset
|
3 |
Author: David von Oheimb and Norbert Schirmer |
12858 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
12854 | 5 |
*) |
6 |
||
7 |
header {* Well-formedness of Java programs *} |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
8 |
theory WellForm = DefiniteAssignment: |
12854 | 9 |
|
10 |
text {* |
|
11 |
For static checks on expressions and statements, see WellType.thy |
|
12 |
||
13 |
improvements over Java Specification 1.0 (cf. 8.4.6.3, 8.4.6.4, 9.4.1): |
|
14 |
\begin{itemize} |
|
15 |
\item a method implementing or overwriting another method may have a result |
|
16 |
type that widens to the result type of the other method |
|
17 |
(instead of identical type) |
|
18 |
\item if a method hides another method (both methods have to be static!) |
|
19 |
there are no restrictions to the result type |
|
20 |
since the methods have to be static and there is no dynamic binding of |
|
21 |
static methods |
|
22 |
\item if an interface inherits more than one method with the same signature, the |
|
23 |
methods need not have identical return types |
|
24 |
\end{itemize} |
|
25 |
simplifications: |
|
26 |
\begin{itemize} |
|
27 |
\item Object and standard exceptions are assumed to be declared like normal |
|
28 |
classes |
|
29 |
\end{itemize} |
|
30 |
*} |
|
31 |
||
32 |
section "well-formed field declarations" |
|
12925
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12893
diff
changeset
|
33 |
text {* well-formed field declaration (common part for classes and interfaces), |
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12893
diff
changeset
|
34 |
cf. 8.3 and (9.3) *} |
12854 | 35 |
|
36 |
constdefs |
|
37 |
wf_fdecl :: "prog \<Rightarrow> pname \<Rightarrow> fdecl \<Rightarrow> bool" |
|
38 |
"wf_fdecl G P \<equiv> \<lambda>(fn,f). is_acc_type G P (type f)" |
|
39 |
||
40 |
lemma wf_fdecl_def2: "\<And>fd. wf_fdecl G P fd = is_acc_type G P (type (snd fd))" |
|
41 |
apply (unfold wf_fdecl_def) |
|
42 |
apply simp |
|
43 |
done |
|
44 |
||
45 |
||
46 |
||
47 |
section "well-formed method declarations" |
|
48 |
(*well-formed method declaration,cf. 8.4, 8.4.1, 8.4.3, 8.4.5, 14.3.2, (9.4)*) |
|
49 |
(* cf. 14.15, 15.7.2, for scope issues cf. 8.4.1 and 14.3.2 *) |
|
50 |
||
51 |
text {* |
|
52 |
A method head is wellformed if: |
|
53 |
\begin{itemize} |
|
54 |
\item the signature and the method head agree in the number of parameters |
|
55 |
\item all types of the parameters are visible |
|
56 |
\item the result type is visible |
|
57 |
\item the parameter names are unique |
|
58 |
\end{itemize} |
|
59 |
*} |
|
60 |
constdefs |
|
61 |
wf_mhead :: "prog \<Rightarrow> pname \<Rightarrow> sig \<Rightarrow> mhead \<Rightarrow> bool" |
|
62 |
"wf_mhead G P \<equiv> \<lambda> sig mh. length (parTs sig) = length (pars mh) \<and> |
|
63 |
\<spacespace> ( \<forall>T\<in>set (parTs sig). is_acc_type G P T) \<and> |
|
64 |
is_acc_type G P (resTy mh) \<and> |
|
12893 | 65 |
\<spacespace> distinct (pars mh)" |
12854 | 66 |
|
67 |
||
68 |
text {* |
|
69 |
A method declaration is wellformed if: |
|
70 |
\begin{itemize} |
|
71 |
\item the method head is wellformed |
|
72 |
\item the names of the local variables are unique |
|
73 |
\item the types of the local variables must be accessible |
|
74 |
\item the local variables don't shadow the parameters |
|
75 |
\item the class of the method is defined |
|
76 |
\item the body statement is welltyped with respect to the |
|
77 |
modified environment of local names, were the local variables, |
|
78 |
the parameters the special result variable (Res) and This are assoziated |
|
79 |
with there types. |
|
80 |
\end{itemize} |
|
81 |
*} |
|
82 |
||
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
83 |
constdefs callee_lcl:: "qtname \<Rightarrow> sig \<Rightarrow> methd \<Rightarrow> lenv" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
84 |
"callee_lcl C sig m |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
85 |
\<equiv> \<lambda> k. (case k of |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
86 |
EName e |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
87 |
\<Rightarrow> (case e of |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
88 |
VNam v |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
89 |
\<Rightarrow>(table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
90 |
| Res \<Rightarrow> Some (resTy m)) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
91 |
| This \<Rightarrow> if is_static m then None else Some (Class C))" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
92 |
|
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
93 |
constdefs parameters :: "methd \<Rightarrow> lname set" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
94 |
"parameters m \<equiv> set (map (EName \<circ> VNam) (pars m)) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
95 |
\<union> (if (static m) then {} else {This})" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
96 |
|
12854 | 97 |
constdefs |
98 |
wf_mdecl :: "prog \<Rightarrow> qtname \<Rightarrow> mdecl \<Rightarrow> bool" |
|
99 |
"wf_mdecl G C \<equiv> |
|
100 |
\<lambda>(sig,m). |
|
101 |
wf_mhead G (pid C) sig (mhead m) \<and> |
|
102 |
unique (lcls (mbody m)) \<and> |
|
103 |
(\<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T) \<and> |
|
104 |
(\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None) \<and> |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
105 |
jumpNestingOkS {Ret} (stmt (mbody m)) \<and> |
12854 | 106 |
is_class G C \<and> |
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
107 |
\<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd> \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
108 |
(\<exists> A. \<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
109 |
\<turnstile> parameters m \<guillemotright>\<langle>stmt (mbody m)\<rangle>\<guillemotright> A |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
110 |
\<and> Result \<in> nrm A)" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
111 |
|
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
112 |
lemma callee_lcl_VNam_simp [simp]: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
113 |
"callee_lcl C sig m (EName (VNam v)) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
114 |
= (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
115 |
by (simp add: callee_lcl_def) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
116 |
|
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
117 |
lemma callee_lcl_Res_simp [simp]: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
118 |
"callee_lcl C sig m (EName Res) = Some (resTy m)" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
119 |
by (simp add: callee_lcl_def) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
120 |
|
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
121 |
lemma callee_lcl_This_simp [simp]: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
122 |
"callee_lcl C sig m (This) = (if is_static m then None else Some (Class C))" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
123 |
by (simp add: callee_lcl_def) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
124 |
|
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
125 |
lemma callee_lcl_This_static_simp: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
126 |
"is_static m \<Longrightarrow> callee_lcl C sig m (This) = None" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
127 |
by simp |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
128 |
|
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
129 |
lemma callee_lcl_This_not_static_simp: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
130 |
"\<not> is_static m \<Longrightarrow> callee_lcl C sig m (This) = Some (Class C)" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
131 |
by simp |
12854 | 132 |
|
133 |
lemma wf_mheadI: |
|
134 |
"\<lbrakk>length (parTs sig) = length (pars m); \<forall>T\<in>set (parTs sig). is_acc_type G P T; |
|
12893 | 135 |
is_acc_type G P (resTy m); distinct (pars m)\<rbrakk> \<Longrightarrow> |
12854 | 136 |
wf_mhead G P sig m" |
137 |
apply (unfold wf_mhead_def) |
|
138 |
apply (simp (no_asm_simp)) |
|
139 |
done |
|
140 |
||
141 |
lemma wf_mdeclI: "\<lbrakk> |
|
142 |
wf_mhead G (pid C) sig (mhead m); unique (lcls (mbody m)); |
|
143 |
(\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None); |
|
144 |
\<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T; |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
145 |
jumpNestingOkS {Ret} (stmt (mbody m)); |
12854 | 146 |
is_class G C; |
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
147 |
\<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
148 |
(\<exists> A. \<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr> \<turnstile> parameters m \<guillemotright>\<langle>stmt (mbody m)\<rangle>\<guillemotright> A |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
149 |
\<and> Result \<in> nrm A) |
12854 | 150 |
\<rbrakk> \<Longrightarrow> |
151 |
wf_mdecl G C (sig,m)" |
|
152 |
apply (unfold wf_mdecl_def) |
|
153 |
apply simp |
|
154 |
done |
|
155 |
||
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
156 |
lemma wf_mdeclE [consumes 1]: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
157 |
"\<lbrakk>wf_mdecl G C (sig,m); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
158 |
\<lbrakk>wf_mhead G (pid C) sig (mhead m); unique (lcls (mbody m)); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
159 |
\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
160 |
\<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
161 |
jumpNestingOkS {Ret} (stmt (mbody m)); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
162 |
is_class G C; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
163 |
\<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
164 |
(\<exists> A. \<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr>\<turnstile> parameters m \<guillemotright>\<langle>stmt (mbody m)\<rangle>\<guillemotright> A |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
165 |
\<and> Result \<in> nrm A) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
166 |
\<rbrakk> \<Longrightarrow> P |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
167 |
\<rbrakk> \<Longrightarrow> P" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
168 |
by (unfold wf_mdecl_def) simp |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
169 |
|
12854 | 170 |
|
171 |
lemma wf_mdeclD1: |
|
172 |
"wf_mdecl G C (sig,m) \<Longrightarrow> |
|
173 |
wf_mhead G (pid C) sig (mhead m) \<and> unique (lcls (mbody m)) \<and> |
|
174 |
(\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None) \<and> |
|
175 |
(\<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T)" |
|
176 |
apply (unfold wf_mdecl_def) |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
177 |
apply simp |
12854 | 178 |
done |
179 |
||
180 |
lemma wf_mdecl_bodyD: |
|
181 |
"wf_mdecl G C (sig,m) \<Longrightarrow> |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
182 |
(\<exists>T. \<lparr>prg=G,cls=C,lcl=callee_lcl C sig m\<rparr>\<turnstile>Body C (stmt (mbody m))\<Colon>-T \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
183 |
G\<turnstile>T\<preceq>(resTy m))" |
12854 | 184 |
apply (unfold wf_mdecl_def) |
185 |
apply clarify |
|
186 |
apply (rule_tac x="(resTy m)" in exI) |
|
187 |
apply (unfold wf_mhead_def) |
|
188 |
apply (auto simp add: wf_mhead_def is_acc_type_def intro: wt.Body ) |
|
189 |
done |
|
190 |
||
191 |
||
192 |
(* |
|
193 |
lemma static_Object_methodsE [elim!]: |
|
194 |
"\<lbrakk>wf_mdecl G Object (sig, m);static m\<rbrakk> \<Longrightarrow> R" |
|
195 |
apply (unfold wf_mdecl_def) |
|
196 |
apply auto |
|
197 |
done |
|
198 |
*) |
|
199 |
||
200 |
lemma rT_is_acc_type: |
|
201 |
"wf_mhead G P sig m \<Longrightarrow> is_acc_type G P (resTy m)" |
|
202 |
apply (unfold wf_mhead_def) |
|
203 |
apply auto |
|
204 |
done |
|
205 |
||
206 |
section "well-formed interface declarations" |
|
207 |
(* well-formed interface declaration, cf. 9.1, 9.1.2.1, 9.1.3, 9.4 *) |
|
208 |
||
209 |
text {* |
|
210 |
A interface declaration is wellformed if: |
|
211 |
\begin{itemize} |
|
212 |
\item the interface hierarchy is wellstructured |
|
213 |
\item there is no class with the same name |
|
214 |
\item the method heads are wellformed and not static and have Public access |
|
215 |
\item the methods are uniquely named |
|
216 |
\item all superinterfaces are accessible |
|
217 |
\item the result type of a method overriding a method of Object widens to the |
|
218 |
result type of the overridden method. |
|
219 |
Shadowing static methods is forbidden. |
|
220 |
\item the result type of a method overriding a set of methods defined in the |
|
221 |
superinterfaces widens to each of the corresponding result types |
|
222 |
\end{itemize} |
|
223 |
*} |
|
224 |
constdefs |
|
225 |
wf_idecl :: "prog \<Rightarrow> idecl \<Rightarrow> bool" |
|
226 |
"wf_idecl G \<equiv> |
|
227 |
\<lambda>(I,i). |
|
228 |
ws_idecl G I (isuperIfs i) \<and> |
|
229 |
\<not>is_class G I \<and> |
|
230 |
(\<forall>(sig,mh)\<in>set (imethods i). wf_mhead G (pid I) sig mh \<and> |
|
231 |
\<not>is_static mh \<and> |
|
232 |
accmodi mh = Public) \<and> |
|
233 |
unique (imethods i) \<and> |
|
234 |
(\<forall> J\<in>set (isuperIfs i). is_acc_iface G (pid I) J) \<and> |
|
235 |
(table_of (imethods i) |
|
236 |
hiding (methd G Object) |
|
237 |
under (\<lambda> new old. accmodi old \<noteq> Private) |
|
238 |
entails (\<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old \<and> |
|
239 |
is_static new = is_static old)) \<and> |
|
240 |
(o2s \<circ> table_of (imethods i) |
|
241 |
hidings Un_tables((\<lambda>J.(imethds G J))`set (isuperIfs i)) |
|
242 |
entails (\<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old))" |
|
243 |
||
244 |
lemma wf_idecl_mhead: "\<lbrakk>wf_idecl G (I,i); (sig,mh)\<in>set (imethods i)\<rbrakk> \<Longrightarrow> |
|
245 |
wf_mhead G (pid I) sig mh \<and> \<not>is_static mh \<and> accmodi mh = Public" |
|
246 |
apply (unfold wf_idecl_def) |
|
247 |
apply auto |
|
248 |
done |
|
249 |
||
250 |
lemma wf_idecl_hidings: |
|
251 |
"wf_idecl G (I, i) \<Longrightarrow> |
|
252 |
(\<lambda>s. o2s (table_of (imethods i) s)) |
|
253 |
hidings Un_tables ((\<lambda>J. imethds G J) ` set (isuperIfs i)) |
|
254 |
entails \<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old" |
|
255 |
apply (unfold wf_idecl_def o_def) |
|
256 |
apply simp |
|
257 |
done |
|
258 |
||
259 |
lemma wf_idecl_hiding: |
|
260 |
"wf_idecl G (I, i) \<Longrightarrow> |
|
261 |
(table_of (imethods i) |
|
262 |
hiding (methd G Object) |
|
263 |
under (\<lambda> new old. accmodi old \<noteq> Private) |
|
264 |
entails (\<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old \<and> |
|
265 |
is_static new = is_static old))" |
|
266 |
apply (unfold wf_idecl_def) |
|
267 |
apply simp |
|
268 |
done |
|
269 |
||
270 |
lemma wf_idecl_supD: |
|
271 |
"\<lbrakk>wf_idecl G (I,i); J \<in> set (isuperIfs i)\<rbrakk> |
|
272 |
\<Longrightarrow> is_acc_iface G (pid I) J \<and> (J, I) \<notin> (subint1 G)^+" |
|
273 |
apply (unfold wf_idecl_def ws_idecl_def) |
|
274 |
apply auto |
|
275 |
done |
|
276 |
||
277 |
section "well-formed class declarations" |
|
278 |
(* well-formed class declaration, cf. 8.1, 8.1.2.1, 8.1.2.2, 8.1.3, 8.1.4 and |
|
279 |
class method declaration, cf. 8.4.3.3, 8.4.6.1, 8.4.6.2, 8.4.6.3, 8.4.6.4 *) |
|
280 |
||
281 |
text {* |
|
282 |
A class declaration is wellformed if: |
|
283 |
\begin{itemize} |
|
284 |
\item there is no interface with the same name |
|
285 |
\item all superinterfaces are accessible and for all methods implementing |
|
286 |
an interface method the result type widens to the result type of |
|
287 |
the interface method, the method is not static and offers at least |
|
288 |
as much access |
|
289 |
(this actually means that the method has Public access, since all |
|
290 |
interface methods have public access) |
|
291 |
\item all field declarations are wellformed and the field names are unique |
|
292 |
\item all method declarations are wellformed and the method names are unique |
|
293 |
\item the initialization statement is welltyped |
|
294 |
\item the classhierarchy is wellstructured |
|
295 |
\item Unless the class is Object: |
|
296 |
\begin{itemize} |
|
297 |
\item the superclass is accessible |
|
298 |
\item for all methods overriding another method (of a superclass )the |
|
299 |
result type widens to the result type of the overridden method, |
|
300 |
the access modifier of the new method provides at least as much |
|
301 |
access as the overwritten one. |
|
302 |
\item for all methods hiding a method (of a superclass) the hidden |
|
303 |
method must be static and offer at least as much access rights. |
|
304 |
Remark: In contrast to the Java Language Specification we don't |
|
305 |
restrict the result types of the method |
|
306 |
(as in case of overriding), because there seems to be no reason, |
|
307 |
since there is no dynamic binding of static methods. |
|
308 |
(cf. 8.4.6.3 vs. 15.12.1). |
|
309 |
Stricly speaking the restrictions on the access rights aren't |
|
310 |
necessary to, since the static type and the access rights |
|
311 |
together determine which method is to be called statically. |
|
312 |
But if a class gains more then one static method with the |
|
313 |
same signature due to inheritance, it is confusing when the |
|
314 |
method selection depends on the access rights only: |
|
315 |
e.g. |
|
316 |
Class C declares static public method foo(). |
|
317 |
Class D is subclass of C and declares static method foo() |
|
318 |
with default package access. |
|
319 |
D.foo() ? if this call is in the same package as D then |
|
320 |
foo of class D is called, otherwise foo of class C. |
|
321 |
\end{itemize} |
|
322 |
||
323 |
\end{itemize} |
|
324 |
*} |
|
325 |
(* to Table *) |
|
326 |
constdefs entails:: "('a,'b) table \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> bool" |
|
327 |
("_ entails _" 20) |
|
328 |
"t entails P \<equiv> \<forall>k. \<forall> x \<in> t k: P x" |
|
329 |
||
330 |
lemma entailsD: |
|
331 |
"\<lbrakk>t entails P; t k = Some x\<rbrakk> \<Longrightarrow> P x" |
|
332 |
by (simp add: entails_def) |
|
333 |
||
334 |
lemma empty_entails[simp]: "empty entails P" |
|
335 |
by (simp add: entails_def) |
|
336 |
||
337 |
constdefs |
|
338 |
wf_cdecl :: "prog \<Rightarrow> cdecl \<Rightarrow> bool" |
|
339 |
"wf_cdecl G \<equiv> |
|
340 |
\<lambda>(C,c). |
|
341 |
\<not>is_iface G C \<and> |
|
342 |
(\<forall>I\<in>set (superIfs c). is_acc_iface G (pid C) I \<and> |
|
343 |
(\<forall>s. \<forall> im \<in> imethds G I s. |
|
344 |
(\<exists> cm \<in> methd G C s: G\<turnstile>resTy cm\<preceq>resTy im \<and> |
|
345 |
\<not> is_static cm \<and> |
|
346 |
accmodi im \<le> accmodi cm))) \<and> |
|
347 |
(\<forall>f\<in>set (cfields c). wf_fdecl G (pid C) f) \<and> unique (cfields c) \<and> |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
348 |
(\<forall>m\<in>set (methods c). wf_mdecl G C m) \<and> unique (methods c) \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
349 |
jumpNestingOkS {} (init c) \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
350 |
(\<exists> A. \<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile> {} \<guillemotright>\<langle>init c\<rangle>\<guillemotright> A) \<and> |
12854 | 351 |
\<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>(init c)\<Colon>\<surd> \<and> ws_cdecl G C (super c) \<and> |
352 |
(C \<noteq> Object \<longrightarrow> |
|
353 |
(is_acc_class G (pid C) (super c) \<and> |
|
354 |
(table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) |
|
355 |
entails (\<lambda> new. \<forall> old sig. |
|
356 |
(G,sig\<turnstile>new overrides\<^sub>S old |
|
357 |
\<longrightarrow> (G\<turnstile>resTy new\<preceq>resTy old \<and> |
|
358 |
accmodi old \<le> accmodi new \<and> |
|
359 |
\<not>is_static old)) \<and> |
|
360 |
(G,sig\<turnstile>new hides old |
|
361 |
\<longrightarrow> (accmodi old \<le> accmodi new \<and> |
|
362 |
is_static old)))) |
|
363 |
))" |
|
364 |
||
365 |
(* |
|
366 |
constdefs |
|
367 |
wf_cdecl :: "prog \<Rightarrow> cdecl \<Rightarrow> bool" |
|
368 |
"wf_cdecl G \<equiv> |
|
369 |
\<lambda>(C,c). |
|
370 |
\<not>is_iface G C \<and> |
|
371 |
(\<forall>I\<in>set (superIfs c). is_acc_iface G (pid C) I \<and> |
|
372 |
(\<forall>s. \<forall> im \<in> imethds G I s. |
|
373 |
(\<exists> cm \<in> methd G C s: G\<turnstile>resTy (mthd cm)\<preceq>resTy (mthd im) \<and> |
|
374 |
\<not> is_static cm \<and> |
|
375 |
accmodi im \<le> accmodi cm))) \<and> |
|
376 |
(\<forall>f\<in>set (cfields c). wf_fdecl G (pid C) f) \<and> unique (cfields c) \<and> |
|
377 |
(\<forall>m\<in>set (methods c). wf_mdecl G C m) \<and> unique (methods c) \<and> |
|
378 |
\<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>(init c)\<Colon>\<surd> \<and> ws_cdecl G C (super c) \<and> |
|
379 |
(C \<noteq> Object \<longrightarrow> |
|
380 |
(is_acc_class G (pid C) (super c) \<and> |
|
381 |
(table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) |
|
382 |
hiding methd G (super c) |
|
383 |
under (\<lambda> new old. G\<turnstile>new overrides old) |
|
384 |
entails (\<lambda> new old. |
|
385 |
(G\<turnstile>resTy (mthd new)\<preceq>resTy (mthd old) \<and> |
|
386 |
accmodi old \<le> accmodi new \<and> |
|
387 |
\<not> is_static old))) \<and> |
|
388 |
(table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) |
|
389 |
hiding methd G (super c) |
|
390 |
under (\<lambda> new old. G\<turnstile>new hides old) |
|
391 |
entails (\<lambda> new old. is_static old \<and> |
|
392 |
accmodi old \<le> accmodi new)) \<and> |
|
393 |
(table_of (cfields c) hiding accfield G C (super c) |
|
394 |
entails (\<lambda> newF oldF. accmodi oldF \<le> access newF))))" |
|
395 |
*) |
|
396 |
||
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
397 |
lemma wf_cdeclE [consumes 1]: |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
398 |
"\<lbrakk>wf_cdecl G (C,c); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
399 |
\<lbrakk>\<not>is_iface G C; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
400 |
(\<forall>I\<in>set (superIfs c). is_acc_iface G (pid C) I \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
401 |
(\<forall>s. \<forall> im \<in> imethds G I s. |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
402 |
(\<exists> cm \<in> methd G C s: G\<turnstile>resTy cm\<preceq>resTy im \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
403 |
\<not> is_static cm \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
404 |
accmodi im \<le> accmodi cm))); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
405 |
\<forall>f\<in>set (cfields c). wf_fdecl G (pid C) f; unique (cfields c); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
406 |
\<forall>m\<in>set (methods c). wf_mdecl G C m; unique (methods c); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
407 |
jumpNestingOkS {} (init c); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
408 |
\<exists> A. \<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile> {} \<guillemotright>\<langle>init c\<rangle>\<guillemotright> A; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
409 |
\<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>(init c)\<Colon>\<surd>; |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
410 |
ws_cdecl G C (super c); |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
411 |
(C \<noteq> Object \<longrightarrow> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
412 |
(is_acc_class G (pid C) (super c) \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
413 |
(table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
414 |
entails (\<lambda> new. \<forall> old sig. |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
415 |
(G,sig\<turnstile>new overrides\<^sub>S old |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
416 |
\<longrightarrow> (G\<turnstile>resTy new\<preceq>resTy old \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
417 |
accmodi old \<le> accmodi new \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
418 |
\<not>is_static old)) \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
419 |
(G,sig\<turnstile>new hides old |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
420 |
\<longrightarrow> (accmodi old \<le> accmodi new \<and> |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
421 |
is_static old)))) |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
422 |
))\<rbrakk> \<Longrightarrow> P |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
423 |
\<rbrakk> \<Longrightarrow> P" |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
424 |
by (unfold wf_cdecl_def) simp |
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
425 |
|
12854 | 426 |
lemma wf_cdecl_unique: |
427 |
"wf_cdecl G (C,c) \<Longrightarrow> unique (cfields c) \<and> unique (methods c)" |
|
428 |
apply (unfold wf_cdecl_def) |
|
429 |
apply auto |
|
430 |
done |
|
431 |
||
432 |
lemma wf_cdecl_fdecl: |
|
433 |
"\<lbrakk>wf_cdecl G (C,c); f\<in>set (cfields c)\<rbrakk> \<Longrightarrow> wf_fdecl G (pid C) f" |
|
434 |
apply (unfold wf_cdecl_def) |
|
435 |
apply auto |
|
436 |
done |
|
437 |
||
438 |
lemma wf_cdecl_mdecl: |
|
439 |
"\<lbrakk>wf_cdecl G (C,c); m\<in>set (methods c)\<rbrakk> \<Longrightarrow> wf_mdecl G C m" |
|
440 |
apply (unfold wf_cdecl_def) |
|
441 |
apply auto |
|
442 |
done |
|
443 |
||
444 |
lemma wf_cdecl_impD: |
|
445 |
"\<lbrakk>wf_cdecl G (C,c); I\<in>set (superIfs c)\<rbrakk> |
|
446 |
\<Longrightarrow> is_acc_iface G (pid C) I \<and> |
|
447 |
(\<forall>s. \<forall>im \<in> imethds G I s. |
|
448 |
(\<exists>cm \<in> methd G C s: G\<turnstile>resTy cm\<preceq>resTy im \<and> \<not>is_static cm \<and> |
|
449 |
accmodi im \<le> accmodi cm))" |
|
450 |
apply (unfold wf_cdecl_def) |
|
451 |
apply auto |
|
452 |
done |
|
453 |
||
454 |
lemma wf_cdecl_supD: |
|
455 |
"\<lbrakk>wf_cdecl G (C,c); C \<noteq> Object\<rbrakk> \<Longrightarrow> |
|
456 |
is_acc_class G (pid C) (super c) \<and> (super c,C) \<notin> (subcls1 G)^+ \<and> |
|
457 |
(table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) |
|
458 |
entails (\<lambda> new. \<forall> old sig. |
|
459 |
(G,sig\<turnstile>new overrides\<^sub>S old |
|
460 |
\<longrightarrow> (G\<turnstile>resTy new\<preceq>resTy old \<and> |
|
461 |
accmodi old \<le> accmodi new \<and> |
|
462 |
\<not>is_static old)) \<and> |
|
463 |
(G,sig\<turnstile>new hides old |
|
464 |
\<longrightarrow> (accmodi old \<le> accmodi new \<and> |
|
465 |
is_static old))))" |
|
466 |
apply (unfold wf_cdecl_def ws_cdecl_def) |
|
467 |
apply auto |
|
468 |
done |
|
469 |
||
470 |
||
471 |
lemma wf_cdecl_overrides_SomeD: |
|
472 |
"\<lbrakk>wf_cdecl G (C,c); C \<noteq> Object; table_of (methods c) sig = Some newM; |
|
473 |
G,sig\<turnstile>(C,newM) overrides\<^sub>S old |
|
474 |
\<rbrakk> \<Longrightarrow> G\<turnstile>resTy newM\<preceq>resTy old \<and> |
|
475 |
accmodi old \<le> accmodi newM \<and> |
|
476 |
\<not> is_static old" |
|
477 |
apply (drule (1) wf_cdecl_supD) |
|
478 |
apply (clarify) |
|
479 |
apply (drule entailsD) |
|
480 |
apply (blast intro: table_of_map_SomeI) |
|
481 |
apply (drule_tac x="old" in spec) |
|
482 |
apply (auto dest: overrides_eq_sigD simp add: msig_def) |
|
483 |
done |
|
484 |
||
485 |
lemma wf_cdecl_hides_SomeD: |
|
486 |
"\<lbrakk>wf_cdecl G (C,c); C \<noteq> Object; table_of (methods c) sig = Some newM; |
|
487 |
G,sig\<turnstile>(C,newM) hides old |
|
488 |
\<rbrakk> \<Longrightarrow> accmodi old \<le> access newM \<and> |
|
489 |
is_static old" |
|
490 |
apply (drule (1) wf_cdecl_supD) |
|
491 |
apply (clarify) |
|
492 |
apply (drule entailsD) |
|
493 |
apply (blast intro: table_of_map_SomeI) |
|
494 |
apply (drule_tac x="old" in spec) |
|
495 |
apply (auto dest: hides_eq_sigD simp add: msig_def) |
|
496 |
done |
|
497 |
||
498 |
lemma wf_cdecl_wt_init: |
|
499 |
"wf_cdecl G (C, c) \<Longrightarrow> \<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>init c\<Colon>\<surd>" |
|
500 |
apply (unfold wf_cdecl_def) |
|
501 |
apply auto |
|
502 |
done |
|
503 |
||
504 |
||
505 |
section "well-formed programs" |
|
506 |
(* well-formed program, cf. 8.1, 9.1 *) |
|
507 |
||
508 |
text {* |
|
509 |
A program declaration is wellformed if: |
|
510 |
\begin{itemize} |
|
511 |
\item the class ObjectC of Object is defined |
|
512 |
\item every method of has an access modifier distinct from Package. This is |
|
513 |
necessary since every interface automatically inherits from Object. |
|
514 |
We must know, that every time a Object method is "overriden" by an |
|
515 |
interface method this is also overriden by the class implementing the |
|
516 |
the interface (see @{text "implement_dynmethd and class_mheadsD"}) |
|
517 |
\item all standard Exceptions are defined |
|
518 |
\item all defined interfaces are wellformed |
|
519 |
\item all defined classes are wellformed |
|
520 |
\end{itemize} |
|
521 |
*} |
|
522 |
constdefs |
|
523 |
wf_prog :: "prog \<Rightarrow> bool" |
|
524 |
"wf_prog G \<equiv> let is = ifaces G; cs = classes G in |
|
525 |
ObjectC \<in> set cs \<and> |
|
526 |
(\<forall> m\<in>set Object_mdecls. accmodi m \<noteq> Package) \<and> |
|
527 |
(\<forall>xn. SXcptC xn \<in> set cs) \<and> |
|
528 |
(\<forall>i\<in>set is. wf_idecl G i) \<and> unique is \<and> |
|
529 |
(\<forall>c\<in>set cs. wf_cdecl G c) \<and> unique cs" |
|
530 |
||
531 |
lemma wf_prog_idecl: "\<lbrakk>iface G I = Some i; wf_prog G\<rbrakk> \<Longrightarrow> wf_idecl G (I,i)" |
|
532 |
apply (unfold wf_prog_def Let_def) |
|
533 |
apply simp |
|
534 |
apply (fast dest: map_of_SomeD) |
|
535 |
done |
|
536 |
||
537 |
lemma wf_prog_cdecl: "\<lbrakk>class G C = Some c; wf_prog G\<rbrakk> \<Longrightarrow> wf_cdecl G (C,c)" |
|
538 |
apply (unfold wf_prog_def Let_def) |
|
539 |
apply simp |
|
540 |
apply (fast dest: map_of_SomeD) |
|
541 |
done |
|
542 |
||
543 |
lemma wf_prog_Object_mdecls: |
|
544 |
"wf_prog G \<Longrightarrow> (\<forall> m\<in>set Object_mdecls. accmodi m \<noteq> Package)" |
|
545 |
apply (unfold wf_prog_def Let_def) |
|
546 |
apply simp |
|
547 |
done |
|
548 |
||
549 |
lemma wf_prog_acc_superD: |
|
550 |
"\<lbrakk>wf_prog G; class G C = Some c; C \<noteq> Object \<rbrakk> |
|
551 |
\<Longrightarrow> is_acc_class G (pid C) (super c)" |
|
552 |
by (auto dest: wf_prog_cdecl wf_cdecl_supD) |
|
553 |
||
554 |
lemma wf_ws_prog [elim!,simp]: "wf_prog G \<Longrightarrow> ws_prog G" |
|
555 |
apply (unfold wf_prog_def Let_def) |
|
556 |
apply (rule ws_progI) |
|
557 |
apply (simp_all (no_asm)) |
|
558 |
apply (auto simp add: is_acc_class_def is_acc_iface_def |
|
559 |
dest!: wf_idecl_supD wf_cdecl_supD )+ |
|
560 |
done |
|
561 |
||
562 |
lemma class_Object [simp]: |
|
563 |
"wf_prog G \<Longrightarrow> |
|
564 |
class G Object = Some \<lparr>access=Public,cfields=[],methods=Object_mdecls, |
|
565 |
init=Skip,super=arbitrary,superIfs=[]\<rparr>" |
|
566 |
apply (unfold wf_prog_def Let_def ObjectC_def) |
|
567 |
apply (fast dest!: map_of_SomeI) |
|
568 |
done |
|
569 |
||
570 |
lemma methd_Object[simp]: "wf_prog G \<Longrightarrow> methd G Object = |
|
571 |
table_of (map (\<lambda>(s,m). (s, Object, m)) Object_mdecls)" |
|
572 |
apply (subst methd_rec) |
|
573 |
apply (auto simp add: Let_def) |
|
574 |
done |
|
575 |
||
576 |
lemma wf_prog_Object_methd: |
|
577 |
"\<lbrakk>wf_prog G; methd G Object sig = Some m\<rbrakk> \<Longrightarrow> accmodi m \<noteq> Package" |
|
578 |
by (auto dest!: wf_prog_Object_mdecls) (auto dest!: map_of_SomeD) |
|
579 |
||
580 |
lemma wf_prog_Object_is_public[intro]: |
|
581 |
"wf_prog G \<Longrightarrow> is_public G Object" |
|
582 |
by (auto simp add: is_public_def dest: class_Object) |
|
583 |
||
584 |
lemma class_SXcpt [simp]: |
|
585 |
"wf_prog G \<Longrightarrow> |
|
586 |
class G (SXcpt xn) = Some \<lparr>access=Public,cfields=[],methods=SXcpt_mdecls, |
|
587 |
init=Skip, |
|
588 |
super=if xn = Throwable then Object |
|
589 |
else SXcpt Throwable, |
|
590 |
superIfs=[]\<rparr>" |
|
591 |
apply (unfold wf_prog_def Let_def SXcptC_def) |
|
592 |
apply (fast dest!: map_of_SomeI) |
|
593 |
done |
|
594 |
||
595 |
lemma wf_ObjectC [simp]: |
|
596 |
"wf_cdecl G ObjectC = (\<not>is_iface G Object \<and> Ball (set Object_mdecls) |
|
597 |
(wf_mdecl G Object) \<and> unique Object_mdecls)" |
|
598 |
apply (unfold wf_cdecl_def ws_cdecl_def ObjectC_def) |
|
13688
a0b16d42d489
"Definite Assignment Analysis" included, with proof of correctness. Large adjustments of type safety proof and soundness proof of the axiomatic semantics were necessary. Completeness proof of the loop rule of the axiomatic semantic was altered. So the additional polymorphic variants of some rules could be removed.
schirmer
parents:
13601
diff
changeset
|
599 |
apply (auto intro: da.Skip) |
12854 | 600 |
done |
601 |
||
602 |
lemma Object_is_class [simp,elim!]: "wf_prog G \<Longrightarrow> is_class G Object" |
|
603 |
apply (simp (no_asm_simp)) |
|
604 |
done |
|
605 |
||
606 |
lemma Object_is_acc_class [simp,elim!]: "wf_prog G \<Longrightarrow> is_acc_class G S Object" |
|
607 |
apply (simp (no_asm_simp) add: is_acc_class_def is_public_def |
|
608 |
accessible_in_RefT_simp) |
|
609 |
done |
|
610 |
||
611 |
lemma SXcpt_is_class [simp,elim!]: "wf_prog G \<Longrightarrow> is_class G (SXcpt xn)" |
|
612 |
apply (simp (no_asm_simp)) |
|
613 |
done |
|
614 |
||
615 |
lemma SXcpt_is_acc_class [simp,elim!]: |
|
616 |
"wf_prog G \<Longrightarrow> is_acc_class G S (SXcpt xn)" |
|
617 |
apply (simp (no_asm_simp) add: is_acc_class_def is_public_def |
|
618 |
accessible_in_RefT_simp) |
|
619 |
done |
|
620 |
||
621 |
lemma fields_Object [simp]: "wf_prog G \<Longrightarrow> DeclConcepts.fields G Object = []" |
|
622 |
by (force intro: fields_emptyI) |
|
623 |
||
624 |
lemma accfield_Object [simp]: |
|
625 |
"wf_prog G \<Longrightarrow> accfield G S Object = empty" |
|
626 |
apply (unfold accfield_def) |
|
627 |
apply (simp (no_asm_simp) add: Let_def) |
|
628 |
done |
|
629 |
||
630 |
lemma fields_Throwable [simp]: |
|
631 |
"wf_prog G \<Longrightarrow> DeclConcepts.fields G (SXcpt Throwable) = []" |
|
632 |
by (force intro: fields_emptyI) |
|
633 |
||
634 |
lemma fields_SXcpt [simp]: "wf_prog G \<Longrightarrow> DeclConcepts.fields G (SXcpt xn) = []" |
|
635 |
apply (case_tac "xn = Throwable") |
|
636 |
apply (simp (no_asm_simp)) |
|
637 |
by (force intro: fields_emptyI) |
|
638 |
||
639 |
lemmas widen_trans = ws_widen_trans [OF _ _ wf_ws_prog, elim] |
|
640 |
lemma widen_trans2 [elim]: "\<lbrakk>G\<turnstile>U\<preceq>T; G\<turnstile>S\<preceq>U; wf_prog G\<rbrakk> \<Longrightarrow> G\<turnstile>S\<preceq>T" |
|
641 |
apply (erule (2) widen_trans) |
|
642 |
done |
|
643 |
||
644 |
lemma Xcpt_subcls_Throwable [simp]: |
|
645 |
"wf_prog G \<Longrightarrow> G\<turnstile>SXcpt xn\<preceq>\<^sub>C SXcpt Throwable" |
|
646 |
apply (rule SXcpt_subcls_Throwable_lemma) |
|
647 |
apply auto |
|
648 |
done |
|
649 |
||
650 |
lemma unique_fields: |
|
651 |
"\<lbrakk>is_class G C; wf_prog G\<rbrakk> \<Longrightarrow> unique (DeclConcepts.fields G C)" |
|
652 |
apply (erule ws_unique_fields) |
|
653 |
apply (erule wf_ws_prog) |
|
654 |
apply (erule (1) wf_prog_cdecl [THEN wf_cdecl_unique [THEN conjunct1]]) |
|
655 |
done |
|
656 |
||
657 |
lemma fields_mono: |
|
658 |
"\<lbrakk>table_of (DeclConcepts.fields G C) fn = Some f; G\<turnstile>D\<preceq>\<^sub>C C; |
|
659 |
is_class G D; wf_prog G\<rbrakk> |
|
660 |
\<Longrightarrow> table_of (DeclConcepts.fields G D) fn = Some f" |
|
661 |
apply (rule map_of_SomeI) |
|
662 |
apply (erule (1) unique_fields) |
|
663 |
apply (erule (1) map_of_SomeD [THEN fields_mono_lemma]) |
|
664 |
apply (erule wf_ws_prog) |
|
665 |
done |
|
666 |
||
667 |
||
668 |
lemma fields_is_type [elim]: |
|
669 |
"\<lbrakk>table_of (DeclConcepts.fields G C) m = Some f; wf_prog G; is_class G C\<rbrakk> \<Longrightarrow> |
|
670 |
is_type G (type f)" |
|
671 |
apply (frule wf_ws_prog) |
|
672 |
apply (force dest: fields_declC [THEN conjunct1] |
|
673 |
wf_prog_cdecl [THEN wf_cdecl_fdecl] |
|
674 |
simp add: wf_fdecl_def2 is_acc_type_def) |
|
675 |
done |
|
676 |
||
677 |
lemma imethds_wf_mhead [rule_format (no_asm)]: |
|
678 |
"\<lbrakk>m \<in> imethds G I sig; wf_prog G; is_iface G I\<rbrakk> \<Longrightarrow> |
|
679 |
wf_mhead G (pid (decliface m)) sig (mthd m) \<and> |
|
680 |
\<not> is_static m \<and> accmodi m = Public" |
|
681 |
apply (frule wf_ws_prog) |
|
682 |
apply (drule (2) imethds_declI [THEN conjunct1]) |
|
683 |
apply clarify |
|
684 |
apply (frule_tac I="(decliface m)" in wf_prog_idecl,assumption) |
|
685 |
apply (drule wf_idecl_mhead) |
|
686 |
apply (erule map_of_SomeD) |
|
687 |
apply (cases m, simp) |
|
688 |
done |
|
689 |
||
690 |
lemma methd_wf_mdecl: |
|
691 |
"\<lbrakk>methd G C sig = Some m; wf_prog G; class G C = Some y\<rbrakk> \<Longrightarrow> |
|
692 |
G\<turnstile>C\<preceq>\<^sub>C (declclass m) \<and> is_class G (declclass m) \<and> |
|
693 |
wf_mdecl G (declclass m) (sig,(mthd m))" |
|
694 |
apply (frule wf_ws_prog) |
|
695 |
apply (drule (1) methd_declC) |
|
696 |
apply fast |
|
697 |
apply clarsimp |
|
698 |
apply (frule (1) wf_prog_cdecl, erule wf_cdecl_mdecl, erule map_of_SomeD) |
|
699 |
done |
|
700 |
||
701 |
(* |
|
702 |
This lemma doesn't hold! |
|
703 |
lemma methd_rT_is_acc_type: |
|
704 |
"\<lbrakk>wf_prog G;methd G C C sig = Some (D,m); |
|
705 |
class G C = Some y\<rbrakk> |
|
706 |
\<Longrightarrow> is_acc_type G (pid C) (resTy m)" |
|
707 |
The result Type is only visible in the scope of defining class D |
|
708 |
"is_vis_type G (pid D) (resTy m)" but not necessarily in scope of class C! |
|
709 |
(The same is true for the type of pramaters of a method) |
|
710 |
*) |
|
711 |
||
712 |
||
713 |
lemma methd_rT_is_type: |
|
714 |
"\<lbrakk>wf_prog G;methd G C sig = Some m; |
|
715 |
class G C = Some y\<rbrakk> |
|
716 |
\<Longrightarrow> is_type G (resTy m)" |
|
717 |
apply (drule (2) methd_wf_mdecl) |
|
718 |
apply clarify |
|
719 |
apply (drule wf_mdeclD1) |
|
720 |
apply clarify |
|
721 |
apply (drule rT_is_acc_type) |
|
722 |
apply (cases m, simp add: is_acc_type_def) |
|
723 |
done |
|
724 |
||
725 |
lemma accmethd_rT_is_type: |
|
726 |
"\<lbrakk>wf_prog G;accmethd G S C sig = Some m; |
|
727 |
class G C = Some y\<rbrakk> |
|
728 |
\<Longrightarrow> is_type G (resTy m)" |
|
729 |
by (auto simp add: accmethd_def |
|
730 |
intro: methd_rT_is_type) |
|
731 |
||
732 |
lemma methd_Object_SomeD: |
|
733 |
"\<lbrakk>wf_prog G;methd G Object sig = Some m\<rbrakk> |
|
734 |
\<Longrightarrow> declclass m = Object" |
|
735 |
by (auto dest: class_Object simp add: methd_rec ) |
|
736 |
||
737 |
lemma wf_imethdsD: |
|
738 |
"\<lbrakk>im \<in> imethds G I sig;wf_prog G; is_iface G I\<rbrakk> |
|
739 |
\<Longrightarrow> \<not>is_static im \<and> accmodi im = Public" |
|
740 |
proof - |
|
741 |
assume asm: "wf_prog G" "is_iface G I" "im \<in> imethds G I sig" |
|
742 |
have "wf_prog G \<longrightarrow> |
|
743 |
(\<forall> i im. iface G I = Some i \<longrightarrow> im \<in> imethds G I sig |
|
744 |
\<longrightarrow> \<not>is_static im \<and> accmodi im = Public)" (is "?P G I") |
|
745 |
proof (rule iface_rec.induct,intro allI impI) |
|
746 |
fix G I i im |
|
747 |
assume hyp: "\<forall> J i. J \<in> set (isuperIfs i) \<and> ws_prog G \<and> iface G I = Some i |
|
748 |
\<longrightarrow> ?P G J" |
|
749 |
assume wf: "wf_prog G" and if_I: "iface G I = Some i" and |
|
750 |
im: "im \<in> imethds G I sig" |
|
751 |
show "\<not>is_static im \<and> accmodi im = Public" |
|
752 |
proof - |
|
753 |
let ?inherited = "Un_tables (imethds G ` set (isuperIfs i))" |
|
754 |
let ?new = "(o2s \<circ> table_of (map (\<lambda>(s, mh). (s, I, mh)) (imethods i)))" |
|
755 |
from if_I wf im have imethds:"im \<in> (?inherited \<oplus>\<oplus> ?new) sig" |
|
756 |
by (simp add: imethds_rec) |
|
757 |
from wf if_I have |
|
758 |
wf_supI: "\<forall> J. J \<in> set (isuperIfs i) \<longrightarrow> (\<exists> j. iface G J = Some j)" |
|
759 |
by (blast dest: wf_prog_idecl wf_idecl_supD is_acc_ifaceD) |
|
760 |
from wf if_I have |
|
761 |
"\<forall> im \<in> set (imethods i). \<not> is_static im \<and> accmodi im = Public" |
|
762 |
by (auto dest!: wf_prog_idecl wf_idecl_mhead) |
|
763 |
then have new_ok: "\<forall> im. table_of (imethods i) sig = Some im |
|
764 |
\<longrightarrow> \<not> is_static im \<and> accmodi im = Public" |
|
765 |
by (auto dest!: table_of_Some_in_set) |
|
766 |
show ?thesis |
|
767 |
proof (cases "?new sig = {}") |
|
768 |
case True |
|
769 |
from True wf wf_supI if_I imethds hyp |
|
770 |
show ?thesis by (auto simp del: split_paired_All) |
|
771 |
next |
|
772 |
case False |
|
773 |
from False wf wf_supI if_I imethds new_ok hyp |
|
774 |
show ?thesis by (auto dest: wf_idecl_hidings hidings_entailsD) |
|
775 |
qed |
|
776 |
qed |
|
777 |
qed |
|
778 |
with asm show ?thesis by (auto simp del: split_paired_All) |
|
779 |
qed |
|
780 |
||
781 |
lemma wf_prog_hidesD: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
782 |
assumes hides: "G \<turnstile>new hides old" and wf: "wf_prog G" |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
783 |
shows |
12854 | 784 |
"accmodi old \<le> accmodi new \<and> |
785 |
is_static old" |
|
786 |
proof - |
|
787 |
from hides |
|
788 |
obtain c where |
|
789 |
clsNew: "class G (declclass new) = Some c" and |
|
790 |
neqObj: "declclass new \<noteq> Object" |
|
791 |
by (auto dest: hidesD declared_in_classD) |
|
792 |
with hides obtain newM oldM where |
|
793 |
newM: "table_of (methods c) (msig new) = Some newM" and |
|
794 |
new: "new = (declclass new,(msig new),newM)" and |
|
795 |
old: "old = (declclass old,(msig old),oldM)" and |
|
796 |
"msig new = msig old" |
|
797 |
by (cases new,cases old) |
|
798 |
(auto dest: hidesD |
|
799 |
simp add: cdeclaredmethd_def declared_in_def) |
|
800 |
with hides |
|
801 |
have hides': |
|
802 |
"G,(msig new)\<turnstile>(declclass new,newM) hides (declclass old,oldM)" |
|
803 |
by auto |
|
804 |
from clsNew wf |
|
805 |
have "wf_cdecl G (declclass new,c)" by (blast intro: wf_prog_cdecl) |
|
806 |
note wf_cdecl_hides_SomeD [OF this neqObj newM hides'] |
|
807 |
with new old |
|
808 |
show ?thesis |
|
809 |
by (cases new, cases old) auto |
|
810 |
qed |
|
811 |
||
812 |
text {* Compare this lemma about static |
|
813 |
overriding @{term "G \<turnstile>new overrides\<^sub>S old"} with the definition of |
|
814 |
dynamic overriding @{term "G \<turnstile>new overrides old"}. |
|
815 |
Conforming result types and restrictions on the access modifiers of the old |
|
816 |
and the new method are not part of the predicate for static overriding. But |
|
817 |
they are enshured in a wellfromed program. Dynamic overriding has |
|
818 |
no restrictions on the access modifiers but enforces confrom result types |
|
819 |
as precondition. But with some efford we can guarantee the access modifier |
|
820 |
restriction for dynamic overriding, too. See lemma |
|
821 |
@{text wf_prog_dyn_override_prop}. |
|
822 |
*} |
|
823 |
lemma wf_prog_stat_overridesD: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
824 |
assumes stat_override: "G \<turnstile>new overrides\<^sub>S old" and wf: "wf_prog G" |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
825 |
shows |
12854 | 826 |
"G\<turnstile>resTy new\<preceq>resTy old \<and> |
827 |
accmodi old \<le> accmodi new \<and> |
|
828 |
\<not> is_static old" |
|
829 |
proof - |
|
830 |
from stat_override |
|
831 |
obtain c where |
|
832 |
clsNew: "class G (declclass new) = Some c" and |
|
833 |
neqObj: "declclass new \<noteq> Object" |
|
834 |
by (auto dest: stat_overrides_commonD declared_in_classD) |
|
835 |
with stat_override obtain newM oldM where |
|
836 |
newM: "table_of (methods c) (msig new) = Some newM" and |
|
837 |
new: "new = (declclass new,(msig new),newM)" and |
|
838 |
old: "old = (declclass old,(msig old),oldM)" and |
|
839 |
"msig new = msig old" |
|
840 |
by (cases new,cases old) |
|
841 |
(auto dest: stat_overrides_commonD |
|
842 |
simp add: cdeclaredmethd_def declared_in_def) |
|
843 |
with stat_override |
|
844 |
have stat_override': |
|
845 |
"G,(msig new)\<turnstile>(declclass new,newM) overrides\<^sub>S (declclass old,oldM)" |
|
846 |
by auto |
|
847 |
from clsNew wf |
|
848 |
have "wf_cdecl G (declclass new,c)" by (blast intro: wf_prog_cdecl) |
|
849 |
note wf_cdecl_overrides_SomeD [OF this neqObj newM stat_override'] |
|
850 |
with new old |
|
851 |
show ?thesis |
|
852 |
by (cases new, cases old) auto |
|
853 |
qed |
|
854 |
||
855 |
lemma static_to_dynamic_overriding: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
856 |
assumes stat_override: "G\<turnstile>new overrides\<^sub>S old" and wf : "wf_prog G" |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
857 |
shows "G\<turnstile>new overrides old" |
12854 | 858 |
proof - |
859 |
from stat_override |
|
860 |
show ?thesis (is "?Overrides new old") |
|
861 |
proof (induct) |
|
862 |
case (Direct new old superNew) |
|
863 |
then have stat_override:"G\<turnstile>new overrides\<^sub>S old" |
|
864 |
by (rule stat_overridesR.Direct) |
|
865 |
from stat_override wf |
|
866 |
have resTy_widen: "G\<turnstile>resTy new\<preceq>resTy old" and |
|
867 |
not_static_old: "\<not> is_static old" |
|
868 |
by (auto dest: wf_prog_stat_overridesD) |
|
869 |
have not_private_new: "accmodi new \<noteq> Private" |
|
870 |
proof - |
|
871 |
from stat_override |
|
872 |
have "accmodi old \<noteq> Private" |
|
873 |
by (rule no_Private_stat_override) |
|
874 |
moreover |
|
875 |
from stat_override wf |
|
876 |
have "accmodi old \<le> accmodi new" |
|
877 |
by (auto dest: wf_prog_stat_overridesD) |
|
878 |
ultimately |
|
879 |
show ?thesis |
|
880 |
by (auto dest: acc_modi_bottom) |
|
881 |
qed |
|
882 |
with Direct resTy_widen not_static_old |
|
883 |
show "?Overrides new old" |
|
12962
a24ffe84a06a
Cleaning up the definition of static overriding.
schirmer
parents:
12937
diff
changeset
|
884 |
by (auto intro: overridesR.Direct stat_override_declclasses_relation) |
12854 | 885 |
next |
886 |
case (Indirect inter new old) |
|
887 |
then show "?Overrides new old" |
|
888 |
by (blast intro: overridesR.Indirect) |
|
889 |
qed |
|
890 |
qed |
|
891 |
||
892 |
lemma non_Package_instance_method_inheritance: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
893 |
assumes old_inheritable: "G\<turnstile>Method old inheritable_in (pid C)" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
894 |
accmodi_old: "accmodi old \<noteq> Package" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
895 |
instance_method: "\<not> is_static old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
896 |
subcls: "G\<turnstile>C \<prec>\<^sub>C declclass old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
897 |
old_declared: "G\<turnstile>Method old declared_in (declclass old)" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
898 |
wf: "wf_prog G" |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
899 |
shows "G\<turnstile>Method old member_of C \<or> |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
900 |
(\<exists> new. G\<turnstile> new overrides\<^sub>S old \<and> G\<turnstile>Method new member_of C)" |
12854 | 901 |
proof - |
902 |
from wf have ws: "ws_prog G" by auto |
|
903 |
from old_declared have iscls_declC_old: "is_class G (declclass old)" |
|
904 |
by (auto simp add: declared_in_def cdeclaredmethd_def) |
|
905 |
from subcls have iscls_C: "is_class G C" |
|
906 |
by (blast dest: subcls_is_class) |
|
907 |
from iscls_C ws old_inheritable subcls |
|
908 |
show ?thesis (is "?P C old") |
|
909 |
proof (induct rule: ws_class_induct') |
|
910 |
case Object |
|
911 |
assume "G\<turnstile>Object\<prec>\<^sub>C declclass old" |
|
912 |
then show "?P Object old" |
|
913 |
by blast |
|
914 |
next |
|
915 |
case (Subcls C c) |
|
916 |
assume cls_C: "class G C = Some c" and |
|
917 |
neq_C_Obj: "C \<noteq> Object" and |
|
918 |
hyp: "\<lbrakk>G \<turnstile>Method old inheritable_in pid (super c); |
|
919 |
G\<turnstile>super c\<prec>\<^sub>C declclass old\<rbrakk> \<Longrightarrow> ?P (super c) old" and |
|
920 |
inheritable: "G \<turnstile>Method old inheritable_in pid C" and |
|
921 |
subclsC: "G\<turnstile>C\<prec>\<^sub>C declclass old" |
|
922 |
from cls_C neq_C_Obj |
|
923 |
have super: "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 super c" |
|
924 |
by (rule subcls1I) |
|
925 |
from wf cls_C neq_C_Obj |
|
926 |
have accessible_super: "G\<turnstile>(Class (super c)) accessible_in (pid C)" |
|
927 |
by (auto dest: wf_prog_cdecl wf_cdecl_supD is_acc_classD) |
|
928 |
{ |
|
929 |
fix old |
|
930 |
assume member_super: "G\<turnstile>Method old member_of (super c)" |
|
931 |
assume inheritable: "G \<turnstile>Method old inheritable_in pid C" |
|
932 |
assume instance_method: "\<not> is_static old" |
|
933 |
from member_super |
|
934 |
have old_declared: "G\<turnstile>Method old declared_in (declclass old)" |
|
935 |
by (cases old) (auto dest: member_of_declC) |
|
936 |
have "?P C old" |
|
937 |
proof (cases "G\<turnstile>mid (msig old) undeclared_in C") |
|
938 |
case True |
|
939 |
with inheritable super accessible_super member_super |
|
940 |
have "G\<turnstile>Method old member_of C" |
|
941 |
by (cases old) (auto intro: members.Inherited) |
|
942 |
then show ?thesis |
|
943 |
by auto |
|
944 |
next |
|
945 |
case False |
|
946 |
then obtain new_member where |
|
947 |
"G\<turnstile>new_member declared_in C" and |
|
948 |
"mid (msig old) = memberid new_member" |
|
949 |
by (auto dest: not_undeclared_declared) |
|
950 |
then obtain new where |
|
951 |
new: "G\<turnstile>Method new declared_in C" and |
|
952 |
eq_sig: "msig old = msig new" and |
|
953 |
declC_new: "declclass new = C" |
|
954 |
by (cases new_member) auto |
|
955 |
then have member_new: "G\<turnstile>Method new member_of C" |
|
956 |
by (cases new) (auto intro: members.Immediate) |
|
957 |
from declC_new super member_super |
|
958 |
have subcls_new_old: "G\<turnstile>declclass new \<prec>\<^sub>C declclass old" |
|
959 |
by (auto dest!: member_of_subclseq_declC |
|
960 |
dest: r_into_trancl intro: trancl_rtrancl_trancl) |
|
961 |
show ?thesis |
|
962 |
proof (cases "is_static new") |
|
963 |
case False |
|
964 |
with eq_sig declC_new new old_declared inheritable |
|
965 |
super member_super subcls_new_old |
|
966 |
have "G\<turnstile>new overrides\<^sub>S old" |
|
967 |
by (auto intro!: stat_overridesR.Direct) |
|
968 |
with member_new show ?thesis |
|
969 |
by blast |
|
970 |
next |
|
971 |
case True |
|
972 |
with eq_sig declC_new subcls_new_old new old_declared inheritable |
|
973 |
have "G\<turnstile>new hides old" |
|
974 |
by (auto intro: hidesI) |
|
975 |
with wf |
|
976 |
have "is_static old" |
|
977 |
by (blast dest: wf_prog_hidesD) |
|
978 |
with instance_method |
|
979 |
show ?thesis |
|
980 |
by (contradiction) |
|
981 |
qed |
|
982 |
qed |
|
983 |
} note hyp_member_super = this |
|
984 |
from subclsC cls_C |
|
985 |
have "G\<turnstile>(super c)\<preceq>\<^sub>C declclass old" |
|
986 |
by (rule subcls_superD) |
|
987 |
then |
|
988 |
show "?P C old" |
|
989 |
proof (cases rule: subclseq_cases) |
|
990 |
case Eq |
|
991 |
assume "super c = declclass old" |
|
992 |
with old_declared |
|
993 |
have "G\<turnstile>Method old member_of (super c)" |
|
994 |
by (cases old) (auto intro: members.Immediate) |
|
995 |
with inheritable instance_method |
|
996 |
show ?thesis |
|
997 |
by (blast dest: hyp_member_super) |
|
998 |
next |
|
999 |
case Subcls |
|
1000 |
assume "G\<turnstile>super c\<prec>\<^sub>C declclass old" |
|
1001 |
moreover |
|
1002 |
from inheritable accmodi_old |
|
1003 |
have "G \<turnstile>Method old inheritable_in pid (super c)" |
|
1004 |
by (cases "accmodi old") (auto simp add: inheritable_in_def) |
|
1005 |
ultimately |
|
1006 |
have "?P (super c) old" |
|
1007 |
by (blast dest: hyp) |
|
1008 |
then show ?thesis |
|
1009 |
proof |
|
1010 |
assume "G \<turnstile>Method old member_of super c" |
|
1011 |
with inheritable instance_method |
|
1012 |
show ?thesis |
|
1013 |
by (blast dest: hyp_member_super) |
|
1014 |
next |
|
1015 |
assume "\<exists>new. G \<turnstile> new overrides\<^sub>S old \<and> G \<turnstile>Method new member_of super c" |
|
1016 |
then obtain super_new where |
|
1017 |
super_new_override: "G \<turnstile> super_new overrides\<^sub>S old" and |
|
1018 |
super_new_member: "G \<turnstile>Method super_new member_of super c" |
|
1019 |
by blast |
|
1020 |
from super_new_override wf |
|
1021 |
have "accmodi old \<le> accmodi super_new" |
|
1022 |
by (auto dest: wf_prog_stat_overridesD) |
|
1023 |
with inheritable accmodi_old |
|
1024 |
have "G \<turnstile>Method super_new inheritable_in pid C" |
|
1025 |
by (auto simp add: inheritable_in_def |
|
1026 |
split: acc_modi.splits |
|
1027 |
dest: acc_modi_le_Dests) |
|
1028 |
moreover |
|
1029 |
from super_new_override |
|
1030 |
have "\<not> is_static super_new" |
|
1031 |
by (auto dest: stat_overrides_commonD) |
|
1032 |
moreover |
|
1033 |
note super_new_member |
|
1034 |
ultimately have "?P C super_new" |
|
1035 |
by (auto dest: hyp_member_super) |
|
1036 |
then show ?thesis |
|
1037 |
proof |
|
1038 |
assume "G \<turnstile>Method super_new member_of C" |
|
1039 |
with super_new_override |
|
1040 |
show ?thesis |
|
1041 |
by blast |
|
1042 |
next |
|
1043 |
assume "\<exists>new. G \<turnstile> new overrides\<^sub>S super_new \<and> |
|
1044 |
G \<turnstile>Method new member_of C" |
|
1045 |
with super_new_override show ?thesis |
|
1046 |
by (blast intro: stat_overridesR.Indirect) |
|
1047 |
qed |
|
1048 |
qed |
|
1049 |
qed |
|
1050 |
qed |
|
1051 |
qed |
|
1052 |
||
1053 |
lemma non_Package_instance_method_inheritance_cases [consumes 6, |
|
1054 |
case_names Inheritance Overriding]: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1055 |
assumes old_inheritable: "G\<turnstile>Method old inheritable_in (pid C)" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1056 |
accmodi_old: "accmodi old \<noteq> Package" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1057 |
instance_method: "\<not> is_static old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1058 |
subcls: "G\<turnstile>C \<prec>\<^sub>C declclass old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1059 |
old_declared: "G\<turnstile>Method old declared_in (declclass old)" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1060 |
wf: "wf_prog G" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1061 |
inheritance: "G\<turnstile>Method old member_of C \<Longrightarrow> P" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1062 |
overriding: "\<And> new. |
12854 | 1063 |
\<lbrakk>G\<turnstile> new overrides\<^sub>S old;G\<turnstile>Method new member_of C\<rbrakk> |
1064 |
\<Longrightarrow> P" |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1065 |
shows P |
12854 | 1066 |
proof - |
1067 |
from old_inheritable accmodi_old instance_method subcls old_declared wf |
|
1068 |
inheritance overriding |
|
1069 |
show ?thesis |
|
1070 |
by (auto dest: non_Package_instance_method_inheritance) |
|
1071 |
qed |
|
1072 |
||
1073 |
lemma dynamic_to_static_overriding: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1074 |
assumes dyn_override: "G\<turnstile> new overrides old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1075 |
accmodi_old: "accmodi old \<noteq> Package" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1076 |
wf: "wf_prog G" |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1077 |
shows "G\<turnstile> new overrides\<^sub>S old" |
12854 | 1078 |
proof - |
1079 |
from dyn_override accmodi_old |
|
1080 |
show ?thesis (is "?Overrides new old") |
|
1081 |
proof (induct rule: overridesR.induct) |
|
1082 |
case (Direct new old) |
|
1083 |
assume new_declared: "G\<turnstile>Method new declared_in declclass new" |
|
1084 |
assume eq_sig_new_old: "msig new = msig old" |
|
1085 |
assume subcls_new_old: "G\<turnstile>declclass new \<prec>\<^sub>C declclass old" |
|
1086 |
assume "G \<turnstile>Method old inheritable_in pid (declclass new)" and |
|
1087 |
"accmodi old \<noteq> Package" and |
|
1088 |
"\<not> is_static old" and |
|
1089 |
"G\<turnstile>declclass new\<prec>\<^sub>C declclass old" and |
|
1090 |
"G\<turnstile>Method old declared_in declclass old" |
|
1091 |
from this wf |
|
1092 |
show "?Overrides new old" |
|
1093 |
proof (cases rule: non_Package_instance_method_inheritance_cases) |
|
1094 |
case Inheritance |
|
1095 |
assume "G \<turnstile>Method old member_of declclass new" |
|
1096 |
then have "G\<turnstile>mid (msig old) undeclared_in declclass new" |
|
1097 |
proof cases |
|
1098 |
case Immediate |
|
1099 |
with subcls_new_old wf show ?thesis |
|
1100 |
by (auto dest: subcls_irrefl) |
|
1101 |
next |
|
1102 |
case Inherited |
|
1103 |
then show ?thesis |
|
1104 |
by (cases old) auto |
|
1105 |
qed |
|
1106 |
with eq_sig_new_old new_declared |
|
1107 |
show ?thesis |
|
1108 |
by (cases old,cases new) (auto dest!: declared_not_undeclared) |
|
1109 |
next |
|
1110 |
case (Overriding new') |
|
1111 |
assume stat_override_new': "G \<turnstile> new' overrides\<^sub>S old" |
|
1112 |
then have "msig new' = msig old" |
|
1113 |
by (auto dest: stat_overrides_commonD) |
|
1114 |
with eq_sig_new_old have eq_sig_new_new': "msig new=msig new'" |
|
1115 |
by simp |
|
1116 |
assume "G \<turnstile>Method new' member_of declclass new" |
|
1117 |
then show ?thesis |
|
1118 |
proof (cases) |
|
1119 |
case Immediate |
|
1120 |
then have declC_new: "declclass new' = declclass new" |
|
1121 |
by auto |
|
1122 |
from Immediate |
|
1123 |
have "G\<turnstile>Method new' declared_in declclass new" |
|
1124 |
by (cases new') auto |
|
1125 |
with new_declared eq_sig_new_new' declC_new |
|
1126 |
have "new=new'" |
|
1127 |
by (cases new, cases new') (auto dest: unique_declared_in) |
|
1128 |
with stat_override_new' |
|
1129 |
show ?thesis |
|
1130 |
by simp |
|
1131 |
next |
|
1132 |
case Inherited |
|
1133 |
then have "G\<turnstile>mid (msig new') undeclared_in declclass new" |
|
1134 |
by (cases new') (auto) |
|
1135 |
with eq_sig_new_new' new_declared |
|
1136 |
show ?thesis |
|
1137 |
by (cases new,cases new') (auto dest!: declared_not_undeclared) |
|
1138 |
qed |
|
1139 |
qed |
|
1140 |
next |
|
1141 |
case (Indirect inter new old) |
|
1142 |
assume accmodi_old: "accmodi old \<noteq> Package" |
|
1143 |
assume "accmodi old \<noteq> Package \<Longrightarrow> G \<turnstile> inter overrides\<^sub>S old" |
|
1144 |
with accmodi_old |
|
1145 |
have stat_override_inter_old: "G \<turnstile> inter overrides\<^sub>S old" |
|
1146 |
by blast |
|
1147 |
moreover |
|
1148 |
assume hyp_inter: "accmodi inter \<noteq> Package \<Longrightarrow> G \<turnstile> new overrides\<^sub>S inter" |
|
1149 |
moreover |
|
1150 |
have "accmodi inter \<noteq> Package" |
|
1151 |
proof - |
|
1152 |
from stat_override_inter_old wf |
|
1153 |
have "accmodi old \<le> accmodi inter" |
|
1154 |
by (auto dest: wf_prog_stat_overridesD) |
|
1155 |
with stat_override_inter_old accmodi_old |
|
1156 |
show ?thesis |
|
1157 |
by (auto dest!: no_Private_stat_override |
|
1158 |
split: acc_modi.splits |
|
1159 |
dest: acc_modi_le_Dests) |
|
1160 |
qed |
|
1161 |
ultimately show "?Overrides new old" |
|
1162 |
by (blast intro: stat_overridesR.Indirect) |
|
1163 |
qed |
|
1164 |
qed |
|
1165 |
||
1166 |
lemma wf_prog_dyn_override_prop: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1167 |
assumes dyn_override: "G \<turnstile> new overrides old" and |
12854 | 1168 |
wf: "wf_prog G" |
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1169 |
shows "accmodi old \<le> accmodi new" |
12854 | 1170 |
proof (cases "accmodi old = Package") |
1171 |
case True |
|
1172 |
note old_Package = this |
|
1173 |
show ?thesis |
|
1174 |
proof (cases "accmodi old \<le> accmodi new") |
|
1175 |
case True then show ?thesis . |
|
1176 |
next |
|
1177 |
case False |
|
1178 |
with old_Package |
|
1179 |
have "accmodi new = Private" |
|
1180 |
by (cases "accmodi new") (auto simp add: le_acc_def less_acc_def) |
|
1181 |
with dyn_override |
|
1182 |
show ?thesis |
|
1183 |
by (auto dest: overrides_commonD) |
|
1184 |
qed |
|
1185 |
next |
|
1186 |
case False |
|
1187 |
with dyn_override wf |
|
1188 |
have "G \<turnstile> new overrides\<^sub>S old" |
|
1189 |
by (blast intro: dynamic_to_static_overriding) |
|
1190 |
with wf |
|
1191 |
show ?thesis |
|
1192 |
by (blast dest: wf_prog_stat_overridesD) |
|
1193 |
qed |
|
1194 |
||
1195 |
lemma overrides_Package_old: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1196 |
assumes dyn_override: "G \<turnstile> new overrides old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1197 |
accmodi_new: "accmodi new = Package" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1198 |
wf: "wf_prog G " |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1199 |
shows "accmodi old = Package" |
12854 | 1200 |
proof (cases "accmodi old") |
1201 |
case Private |
|
1202 |
with dyn_override show ?thesis |
|
1203 |
by (simp add: no_Private_override) |
|
1204 |
next |
|
1205 |
case Package |
|
1206 |
then show ?thesis . |
|
1207 |
next |
|
1208 |
case Protected |
|
1209 |
with dyn_override wf |
|
1210 |
have "G \<turnstile> new overrides\<^sub>S old" |
|
1211 |
by (auto intro: dynamic_to_static_overriding) |
|
1212 |
with wf |
|
1213 |
have "accmodi old \<le> accmodi new" |
|
1214 |
by (auto dest: wf_prog_stat_overridesD) |
|
1215 |
with Protected accmodi_new |
|
1216 |
show ?thesis |
|
1217 |
by (simp add: less_acc_def le_acc_def) |
|
1218 |
next |
|
1219 |
case Public |
|
1220 |
with dyn_override wf |
|
1221 |
have "G \<turnstile> new overrides\<^sub>S old" |
|
1222 |
by (auto intro: dynamic_to_static_overriding) |
|
1223 |
with wf |
|
1224 |
have "accmodi old \<le> accmodi new" |
|
1225 |
by (auto dest: wf_prog_stat_overridesD) |
|
1226 |
with Public accmodi_new |
|
1227 |
show ?thesis |
|
1228 |
by (simp add: less_acc_def le_acc_def) |
|
1229 |
qed |
|
1230 |
||
1231 |
lemma dyn_override_Package: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1232 |
assumes dyn_override: "G \<turnstile> new overrides old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1233 |
accmodi_old: "accmodi old = Package" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1234 |
accmodi_new: "accmodi new = Package" and |
12854 | 1235 |
wf: "wf_prog G" |
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1236 |
shows "pid (declclass old) = pid (declclass new)" |
12854 | 1237 |
proof - |
1238 |
from dyn_override accmodi_old accmodi_new |
|
1239 |
show ?thesis (is "?EqPid old new") |
|
1240 |
proof (induct rule: overridesR.induct) |
|
1241 |
case (Direct new old) |
|
1242 |
assume "accmodi old = Package" |
|
1243 |
"G \<turnstile>Method old inheritable_in pid (declclass new)" |
|
1244 |
then show "pid (declclass old) = pid (declclass new)" |
|
1245 |
by (auto simp add: inheritable_in_def) |
|
1246 |
next |
|
1247 |
case (Indirect inter new old) |
|
1248 |
assume accmodi_old: "accmodi old = Package" and |
|
1249 |
accmodi_new: "accmodi new = Package" |
|
1250 |
assume "G \<turnstile> new overrides inter" |
|
1251 |
with accmodi_new wf |
|
1252 |
have "accmodi inter = Package" |
|
1253 |
by (auto intro: overrides_Package_old) |
|
1254 |
with Indirect |
|
1255 |
show "pid (declclass old) = pid (declclass new)" |
|
1256 |
by auto |
|
1257 |
qed |
|
1258 |
qed |
|
1259 |
||
1260 |
lemma dyn_override_Package_escape: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1261 |
assumes dyn_override: "G \<turnstile> new overrides old" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1262 |
accmodi_old: "accmodi old = Package" and |
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1263 |
outside_pack: "pid (declclass old) \<noteq> pid (declclass new)" and |
12854 | 1264 |
wf: "wf_prog G" |
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1265 |
shows "\<exists> inter. G \<turnstile> new overrides inter \<and> G \<turnstile> inter overrides old \<and> |
12854 | 1266 |
pid (declclass old) = pid (declclass inter) \<and> |
1267 |
Protected \<le> accmodi inter" |
|
1268 |
proof - |
|
1269 |
from dyn_override accmodi_old outside_pack |
|
1270 |
show ?thesis (is "?P new old") |
|
1271 |
proof (induct rule: overridesR.induct) |
|
1272 |
case (Direct new old) |
|
1273 |
assume accmodi_old: "accmodi old = Package" |
|
1274 |
assume outside_pack: "pid (declclass old) \<noteq> pid (declclass new)" |
|
1275 |
assume "G \<turnstile>Method old inheritable_in pid (declclass new)" |
|
1276 |
with accmodi_old |
|
1277 |
have "pid (declclass old) = pid (declclass new)" |
|
1278 |
by (simp add: inheritable_in_def) |
|
1279 |
with outside_pack |
|
1280 |
show "?P new old" |
|
1281 |
by (contradiction) |
|
1282 |
next |
|
1283 |
case (Indirect inter new old) |
|
1284 |
assume accmodi_old: "accmodi old = Package" |
|
1285 |
assume outside_pack: "pid (declclass old) \<noteq> pid (declclass new)" |
|
1286 |
assume override_new_inter: "G \<turnstile> new overrides inter" |
|
1287 |
assume override_inter_old: "G \<turnstile> inter overrides old" |
|
1288 |
assume hyp_new_inter: "\<lbrakk>accmodi inter = Package; |
|
1289 |
pid (declclass inter) \<noteq> pid (declclass new)\<rbrakk> |
|
1290 |
\<Longrightarrow> ?P new inter" |
|
1291 |
assume hyp_inter_old: "\<lbrakk>accmodi old = Package; |
|
1292 |
pid (declclass old) \<noteq> pid (declclass inter)\<rbrakk> |
|
1293 |
\<Longrightarrow> ?P inter old" |
|
1294 |
show "?P new old" |
|
1295 |
proof (cases "pid (declclass old) = pid (declclass inter)") |
|
1296 |
case True |
|
1297 |
note same_pack_old_inter = this |
|
1298 |
show ?thesis |
|
1299 |
proof (cases "pid (declclass inter) = pid (declclass new)") |
|
1300 |
case True |
|
1301 |
with same_pack_old_inter outside_pack |
|
1302 |
show ?thesis |
|
1303 |
by auto |
|
1304 |
next |
|
1305 |
case False |
|
1306 |
note diff_pack_inter_new = this |
|
1307 |
show ?thesis |
|
1308 |
proof (cases "accmodi inter = Package") |
|
1309 |
case True |
|
1310 |
with diff_pack_inter_new hyp_new_inter |
|
1311 |
obtain newinter where |
|
1312 |
over_new_newinter: "G \<turnstile> new overrides newinter" and |
|
1313 |
over_newinter_inter: "G \<turnstile> newinter overrides inter" and |
|
1314 |
eq_pid: "pid (declclass inter) = pid (declclass newinter)" and |
|
1315 |
accmodi_newinter: "Protected \<le> accmodi newinter" |
|
1316 |
by auto |
|
1317 |
from over_newinter_inter override_inter_old |
|
1318 |
have "G\<turnstile>newinter overrides old" |
|
1319 |
by (rule overridesR.Indirect) |
|
1320 |
moreover |
|
1321 |
from eq_pid same_pack_old_inter |
|
1322 |
have "pid (declclass old) = pid (declclass newinter)" |
|
1323 |
by simp |
|
1324 |
moreover |
|
1325 |
note over_new_newinter accmodi_newinter |
|
1326 |
ultimately show ?thesis |
|
1327 |
by blast |
|
1328 |
next |
|
1329 |
case False |
|
1330 |
with override_new_inter |
|
1331 |
have "Protected \<le> accmodi inter" |
|
1332 |
by (cases "accmodi inter") (auto dest: no_Private_override) |
|
1333 |
with override_new_inter override_inter_old same_pack_old_inter |
|
1334 |
show ?thesis |
|
1335 |
by blast |
|
1336 |
qed |
|
1337 |
qed |
|
1338 |
next |
|
1339 |
case False |
|
1340 |
with accmodi_old hyp_inter_old |
|
1341 |
obtain newinter where |
|
1342 |
over_inter_newinter: "G \<turnstile> inter overrides newinter" and |
|
1343 |
over_newinter_old: "G \<turnstile> newinter overrides old" and |
|
1344 |
eq_pid: "pid (declclass old) = pid (declclass newinter)" and |
|
1345 |
accmodi_newinter: "Protected \<le> accmodi newinter" |
|
1346 |
by auto |
|
1347 |
from override_new_inter over_inter_newinter |
|
1348 |
have "G \<turnstile> new overrides newinter" |
|
1349 |
by (rule overridesR.Indirect) |
|
1350 |
with eq_pid over_newinter_old accmodi_newinter |
|
1351 |
show ?thesis |
|
1352 |
by blast |
|
1353 |
qed |
|
1354 |
qed |
|
1355 |
qed |
|
1356 |
||
1357 |
lemma declclass_widen[rule_format]: |
|
1358 |
"wf_prog G |
|
1359 |
\<longrightarrow> (\<forall>c m. class G C = Some c \<longrightarrow> methd G C sig = Some m |
|
1360 |
\<longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m)" (is "?P G C") |
|
1361 |
proof (rule class_rec.induct,intro allI impI) |
|
1362 |
fix G C c m |
|
1363 |
assume Hyp: "\<forall>c. C \<noteq> Object \<and> ws_prog G \<and> class G C = Some c |
|
1364 |
\<longrightarrow> ?P G (super c)" |
|
1365 |
assume wf: "wf_prog G" and cls_C: "class G C = Some c" and |
|
1366 |
m: "methd G C sig = Some m" |
|
1367 |
show "G\<turnstile>C\<preceq>\<^sub>C declclass m" |
|
1368 |
proof (cases "C=Object") |
|
1369 |
case True |
|
1370 |
with wf m show ?thesis by (simp add: methd_Object_SomeD) |
|
1371 |
next |
|
1372 |
let ?filter="filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m)" |
|
1373 |
let ?table = "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c))" |
|
1374 |
case False |
|
1375 |
with cls_C wf m |
|
1376 |
have methd_C: "(?filter (methd G (super c)) ++ ?table) sig = Some m " |
|
1377 |
by (simp add: methd_rec) |
|
1378 |
show ?thesis |
|
1379 |
proof (cases "?table sig") |
|
1380 |
case None |
|
1381 |
from this methd_C have "?filter (methd G (super c)) sig = Some m" |
|
1382 |
by simp |
|
1383 |
moreover |
|
1384 |
from wf cls_C False obtain sup where "class G (super c) = Some sup" |
|
1385 |
by (blast dest: wf_prog_cdecl wf_cdecl_supD is_acc_class_is_class) |
|
12925
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12893
diff
changeset
|
1386 |
moreover note wf False cls_C |
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12893
diff
changeset
|
1387 |
ultimately have "G\<turnstile>super c \<preceq>\<^sub>C declclass m" |
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12893
diff
changeset
|
1388 |
by (auto intro: Hyp [rule_format]) |
12854 | 1389 |
moreover from cls_C False have "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 super c" by (rule subcls1I) |
1390 |
ultimately show ?thesis by - (rule rtrancl_into_rtrancl2) |
|
1391 |
next |
|
1392 |
case Some |
|
1393 |
from this wf False cls_C methd_C show ?thesis by auto |
|
1394 |
qed |
|
1395 |
qed |
|
1396 |
qed |
|
1397 |
||
1398 |
lemma declclass_methd_Object: |
|
1399 |
"\<lbrakk>wf_prog G; methd G Object sig = Some m\<rbrakk> \<Longrightarrow> declclass m = Object" |
|
1400 |
by auto |
|
1401 |
||
1402 |
lemma methd_declaredD: |
|
1403 |
"\<lbrakk>wf_prog G; is_class G C;methd G C sig = Some m\<rbrakk> |
|
1404 |
\<Longrightarrow> G\<turnstile>(mdecl (sig,mthd m)) declared_in (declclass m)" |
|
1405 |
proof - |
|
1406 |
assume wf: "wf_prog G" |
|
1407 |
then have ws: "ws_prog G" .. |
|
1408 |
assume clsC: "is_class G C" |
|
1409 |
from clsC ws |
|
1410 |
show "methd G C sig = Some m |
|
1411 |
\<Longrightarrow> G\<turnstile>(mdecl (sig,mthd m)) declared_in (declclass m)" |
|
1412 |
(is "PROP ?P C") |
|
1413 |
proof (induct ?P C rule: ws_class_induct') |
|
1414 |
case Object |
|
1415 |
assume "methd G Object sig = Some m" |
|
1416 |
with wf show ?thesis |
|
1417 |
by - (rule method_declared_inI, auto) |
|
1418 |
next |
|
1419 |
case Subcls |
|
1420 |
fix C c |
|
1421 |
assume clsC: "class G C = Some c" |
|
1422 |
and m: "methd G C sig = Some m" |
|
1423 |
and hyp: "methd G (super c) sig = Some m \<Longrightarrow> ?thesis" |
|
1424 |
let ?newMethods = "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c))" |
|
1425 |
show ?thesis |
|
1426 |
proof (cases "?newMethods sig") |
|
1427 |
case None |
|
1428 |
from None ws clsC m hyp |
|
1429 |
show ?thesis by (auto intro: method_declared_inI simp add: methd_rec) |
|
1430 |
next |
|
1431 |
case Some |
|
1432 |
from Some ws clsC m |
|
1433 |
show ?thesis by (auto intro: method_declared_inI simp add: methd_rec) |
|
1434 |
qed |
|
1435 |
qed |
|
1436 |
qed |
|
1437 |
||
1438 |
lemma methd_rec_Some_cases [consumes 4, case_names NewMethod InheritedMethod]: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
1439 |
assumes methd_C: "methd G C sig = Some m" and |