author | wenzelm |
Thu, 21 Apr 2005 22:10:12 +0200 | |
changeset 15805 | 1e8017f1e971 |
parent 14981 | e73f8140af78 |
child 16417 | 9bc16273c2d4 |
permissions | -rw-r--r-- |
12857 | 1 |
(* Title: HOL/Bali/Decl.thy |
12854 | 2 |
ID: $Id$ |
12925
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12859
diff
changeset
|
3 |
Author: David von Oheimb and Norbert Schirmer |
12854 | 4 |
*) |
5 |
header {* Field, method, interface, and class declarations, whole Java programs |
|
6 |
*} |
|
7 |
||
8 |
(** order is significant, because of clash for "var" **) |
|
9 |
theory Decl = Term + Table: |
|
10 |
||
11 |
text {* |
|
12 |
improvements: |
|
13 |
\begin{itemize} |
|
14 |
\item clarification and correction of some aspects of the package/access concept |
|
15 |
(Also submitted as bug report to the Java Bug Database: |
|
16 |
Bug Id: 4485402 and Bug Id: 4493343 |
|
17 |
http://developer.java.sun.com/developer/bugParade/index.jshtml |
|
18 |
) |
|
19 |
\end{itemize} |
|
20 |
simplifications: |
|
21 |
\begin{itemize} |
|
22 |
\item the only field and method modifiers are static and the access modifiers |
|
23 |
\item no constructors, which may be simulated by new + suitable methods |
|
24 |
\item there is just one global initializer per class, which can simulate all |
|
25 |
others |
|
26 |
||
27 |
\item no throws clause |
|
28 |
\item a void method is replaced by one that returns Unit (of dummy type Void) |
|
29 |
||
30 |
\item no interface fields |
|
31 |
||
32 |
\item every class has an explicit superclass (unused for Object) |
|
33 |
\item the (standard) methods of Object and of standard exceptions are not |
|
34 |
specified |
|
35 |
||
36 |
\item no main method |
|
37 |
\end{itemize} |
|
38 |
*} |
|
39 |
||
40 |
subsection {* Modifier*} |
|
41 |
||
42 |
subsubsection {* Access modifier *} |
|
43 |
||
44 |
datatype acc_modi (* access modifier *) |
|
45 |
= Private | Package | Protected | Public |
|
46 |
||
47 |
text {* |
|
48 |
We can define a linear order for the access modifiers. With Private yielding the |
|
49 |
most restrictive access and public the most liberal access policy: |
|
50 |
Private < Package < Protected < Public |
|
51 |
*} |
|
52 |
||
12859 | 53 |
instance acc_modi:: ord .. |
12854 | 54 |
|
55 |
defs (overloaded) |
|
56 |
less_acc_def: |
|
57 |
"a < (b::acc_modi) |
|
58 |
\<equiv> (case a of |
|
59 |
Private \<Rightarrow> (b=Package \<or> b=Protected \<or> b=Public) |
|
60 |
| Package \<Rightarrow> (b=Protected \<or> b=Public) |
|
61 |
| Protected \<Rightarrow> (b=Public) |
|
62 |
| Public \<Rightarrow> False)" |
|
63 |
le_acc_def: |
|
64 |
"a \<le> (b::acc_modi) \<equiv> (a = b) \<or> (a < b)" |
|
65 |
||
66 |
instance acc_modi:: order |
|
12859 | 67 |
proof |
12854 | 68 |
fix x y z::acc_modi |
69 |
{ |
|
70 |
show "x \<le> x" \<spacespace>\<spacespace> -- reflexivity |
|
71 |
by (auto simp add: le_acc_def) |
|
72 |
next |
|
73 |
assume "x \<le> y" "y \<le> z" -- transitivity |
|
74 |
thus "x \<le> z" |
|
75 |
by (auto simp add: le_acc_def less_acc_def split add: acc_modi.split) |
|
76 |
next |
|
77 |
assume "x \<le> y" "y \<le> x" -- antisymmetry |
|
78 |
thus "x = y" |
|
79 |
proof - |
|
80 |
have "\<forall> x y. x < (y::acc_modi) \<and> y < x \<longrightarrow> False" |
|
81 |
by (auto simp add: less_acc_def split add: acc_modi.split) |
|
82 |
with prems show ?thesis |
|
13601 | 83 |
by (unfold le_acc_def) rules |
12854 | 84 |
qed |
85 |
next |
|
86 |
show "(x < y) = (x \<le> y \<and> x \<noteq> y)" |
|
87 |
by (auto simp add: le_acc_def less_acc_def split add: acc_modi.split) |
|
88 |
} |
|
89 |
qed |
|
90 |
||
91 |
instance acc_modi:: linorder |
|
12859 | 92 |
proof |
12854 | 93 |
fix x y:: acc_modi |
94 |
show "x \<le> y \<or> y \<le> x" |
|
95 |
by (auto simp add: less_acc_def le_acc_def split add: acc_modi.split) |
|
96 |
qed |
|
97 |
||
98 |
lemma acc_modi_top [simp]: "Public \<le> a \<Longrightarrow> a = Public" |
|
99 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
100 |
||
101 |
lemma acc_modi_top1 [simp, intro!]: "a \<le> Public" |
|
102 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
103 |
||
104 |
lemma acc_modi_le_Public: |
|
105 |
"a \<le> Public \<Longrightarrow> a=Private \<or> a = Package \<or> a=Protected \<or> a=Public" |
|
106 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
107 |
||
108 |
lemma acc_modi_bottom: "a \<le> Private \<Longrightarrow> a = Private" |
|
109 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
110 |
||
111 |
lemma acc_modi_Private_le: |
|
112 |
"Private \<le> a \<Longrightarrow> a=Private \<or> a = Package \<or> a=Protected \<or> a=Public" |
|
113 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
114 |
||
115 |
lemma acc_modi_Package_le: |
|
116 |
"Package \<le> a \<Longrightarrow> a = Package \<or> a=Protected \<or> a=Public" |
|
117 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.split) |
|
118 |
||
119 |
lemma acc_modi_le_Package: |
|
120 |
"a \<le> Package \<Longrightarrow> a=Private \<or> a = Package" |
|
121 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
122 |
||
123 |
lemma acc_modi_Protected_le: |
|
124 |
"Protected \<le> a \<Longrightarrow> a=Protected \<or> a=Public" |
|
125 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
126 |
||
127 |
lemma acc_modi_le_Protected: |
|
128 |
"a \<le> Protected \<Longrightarrow> a=Private \<or> a = Package \<or> a = Protected" |
|
129 |
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits) |
|
130 |
||
131 |
||
132 |
lemmas acc_modi_le_Dests = acc_modi_top acc_modi_le_Public |
|
133 |
acc_modi_Private_le acc_modi_bottom |
|
134 |
acc_modi_Package_le acc_modi_le_Package |
|
135 |
acc_modi_Protected_le acc_modi_le_Protected |
|
136 |
||
137 |
lemma acc_modi_Package_le_cases |
|
138 |
[consumes 1,case_names Package Protected Public]: |
|
139 |
"Package \<le> m \<Longrightarrow> ( m = Package \<Longrightarrow> P m) \<Longrightarrow> (m=Protected \<Longrightarrow> P m) \<Longrightarrow> |
|
140 |
(m=Public \<Longrightarrow> P m) \<Longrightarrow> P m" |
|
141 |
by (auto dest: acc_modi_Package_le) |
|
142 |
||
143 |
||
144 |
subsubsection {* Static Modifier *} |
|
145 |
types stat_modi = bool (* modifier: static *) |
|
146 |
||
147 |
subsection {* Declaration (base "class" for member,interface and class |
|
148 |
declarations *} |
|
149 |
||
150 |
record decl = |
|
151 |
access :: acc_modi |
|
152 |
||
153 |
translations |
|
154 |
"decl" <= (type) "\<lparr>access::acc_modi\<rparr>" |
|
155 |
"decl" <= (type) "\<lparr>access::acc_modi,\<dots>::'a\<rparr>" |
|
156 |
||
157 |
subsection {* Member (field or method)*} |
|
158 |
record member = decl + |
|
159 |
static :: stat_modi |
|
160 |
||
161 |
translations |
|
162 |
"member" <= (type) "\<lparr>access::acc_modi,static::bool\<rparr>" |
|
163 |
"member" <= (type) "\<lparr>access::acc_modi,static::bool,\<dots>::'a\<rparr>" |
|
164 |
||
165 |
subsection {* Field *} |
|
166 |
||
167 |
record field = member + |
|
168 |
type :: ty |
|
169 |
translations |
|
170 |
"field" <= (type) "\<lparr>access::acc_modi, static::bool, type::ty\<rparr>" |
|
171 |
"field" <= (type) "\<lparr>access::acc_modi, static::bool, type::ty,\<dots>::'a\<rparr>" |
|
172 |
||
173 |
types |
|
174 |
fdecl (* field declaration, cf. 8.3 *) |
|
175 |
= "vname \<times> field" |
|
176 |
||
177 |
||
178 |
translations |
|
179 |
"fdecl" <= (type) "vname \<times> field" |
|
180 |
||
181 |
subsection {* Method *} |
|
182 |
||
183 |
record mhead = member + (* method head (excluding signature) *) |
|
184 |
pars ::"vname list" (* parameter names *) |
|
185 |
resT ::ty (* result type *) |
|
186 |
||
187 |
record mbody = (* method body *) |
|
188 |
lcls:: "(vname \<times> ty) list" (* local variables *) |
|
189 |
stmt:: stmt (* the body statement *) |
|
190 |
||
191 |
record methd = mhead + (* method in a class *) |
|
192 |
mbody::mbody |
|
193 |
||
194 |
types mdecl = "sig \<times> methd" (* method declaration in a class *) |
|
195 |
||
196 |
||
197 |
translations |
|
198 |
"mhead" <= (type) "\<lparr>access::acc_modi, static::bool, |
|
199 |
pars::vname list, resT::ty\<rparr>" |
|
200 |
"mhead" <= (type) "\<lparr>access::acc_modi, static::bool, |
|
201 |
pars::vname list, resT::ty,\<dots>::'a\<rparr>" |
|
202 |
"mbody" <= (type) "\<lparr>lcls::(vname \<times> ty) list,stmt::stmt\<rparr>" |
|
203 |
"mbody" <= (type) "\<lparr>lcls::(vname \<times> ty) list,stmt::stmt,\<dots>::'a\<rparr>" |
|
204 |
"methd" <= (type) "\<lparr>access::acc_modi, static::bool, |
|
205 |
pars::vname list, resT::ty,mbody::mbody\<rparr>" |
|
206 |
"methd" <= (type) "\<lparr>access::acc_modi, static::bool, |
|
207 |
pars::vname list, resT::ty,mbody::mbody,\<dots>::'a\<rparr>" |
|
208 |
"mdecl" <= (type) "sig \<times> methd" |
|
209 |
||
210 |
||
211 |
constdefs |
|
212 |
mhead::"methd \<Rightarrow> mhead" |
|
213 |
"mhead m \<equiv> \<lparr>access=access m, static=static m, pars=pars m, resT=resT m\<rparr>" |
|
214 |
||
215 |
lemma access_mhead [simp]:"access (mhead m) = access m" |
|
216 |
by (simp add: mhead_def) |
|
217 |
||
218 |
lemma static_mhead [simp]:"static (mhead m) = static m" |
|
219 |
by (simp add: mhead_def) |
|
220 |
||
221 |
lemma pars_mhead [simp]:"pars (mhead m) = pars m" |
|
222 |
by (simp add: mhead_def) |
|
223 |
||
224 |
lemma resT_mhead [simp]:"resT (mhead m) = resT m" |
|
225 |
by (simp add: mhead_def) |
|
226 |
||
227 |
text {* To be able to talk uniformaly about field and method declarations we |
|
228 |
introduce the notion of a member declaration (e.g. useful to define |
|
229 |
accessiblity ) *} |
|
230 |
||
231 |
datatype memberdecl = fdecl fdecl | mdecl mdecl |
|
232 |
||
233 |
datatype memberid = fid vname | mid sig |
|
234 |
||
235 |
axclass has_memberid < "type" |
|
236 |
consts |
|
237 |
memberid :: "'a::has_memberid \<Rightarrow> memberid" |
|
238 |
||
12859 | 239 |
instance memberdecl::has_memberid .. |
12854 | 240 |
|
241 |
defs (overloaded) |
|
242 |
memberdecl_memberid_def: |
|
243 |
"memberid m \<equiv> (case m of |
|
244 |
fdecl (vn,f) \<Rightarrow> fid vn |
|
245 |
| mdecl (sig,m) \<Rightarrow> mid sig)" |
|
246 |
||
247 |
lemma memberid_fdecl_simp[simp]: "memberid (fdecl (vn,f)) = fid vn" |
|
248 |
by (simp add: memberdecl_memberid_def) |
|
249 |
||
250 |
lemma memberid_fdecl_simp1: "memberid (fdecl f) = fid (fst f)" |
|
251 |
by (cases f) (simp add: memberdecl_memberid_def) |
|
252 |
||
253 |
lemma memberid_mdecl_simp[simp]: "memberid (mdecl (sig,m)) = mid sig" |
|
254 |
by (simp add: memberdecl_memberid_def) |
|
255 |
||
256 |
lemma memberid_mdecl_simp1: "memberid (mdecl m) = mid (fst m)" |
|
257 |
by (cases m) (simp add: memberdecl_memberid_def) |
|
258 |
||
12859 | 259 |
instance * :: (type, has_memberid) has_memberid .. |
12854 | 260 |
|
261 |
defs (overloaded) |
|
262 |
pair_memberid_def: |
|
263 |
"memberid p \<equiv> memberid (snd p)" |
|
264 |
||
265 |
lemma memberid_pair_simp[simp]: "memberid (c,m) = memberid m" |
|
266 |
by (simp add: pair_memberid_def) |
|
267 |
||
268 |
lemma memberid_pair_simp1: "memberid p = memberid (snd p)" |
|
269 |
by (simp add: pair_memberid_def) |
|
270 |
||
271 |
constdefs is_field :: "qtname \<times> memberdecl \<Rightarrow> bool" |
|
272 |
"is_field m \<equiv> \<exists> declC f. m=(declC,fdecl f)" |
|
273 |
||
274 |
lemma is_fieldD: "is_field m \<Longrightarrow> \<exists> declC f. m=(declC,fdecl f)" |
|
275 |
by (simp add: is_field_def) |
|
276 |
||
277 |
lemma is_fieldI: "is_field (C,fdecl f)" |
|
278 |
by (simp add: is_field_def) |
|
279 |
||
280 |
constdefs is_method :: "qtname \<times> memberdecl \<Rightarrow> bool" |
|
281 |
"is_method membr \<equiv> \<exists> declC m. membr=(declC,mdecl m)" |
|
282 |
||
283 |
lemma is_methodD: "is_method membr \<Longrightarrow> \<exists> declC m. membr=(declC,mdecl m)" |
|
284 |
by (simp add: is_method_def) |
|
285 |
||
286 |
lemma is_methodI: "is_method (C,mdecl m)" |
|
287 |
by (simp add: is_method_def) |
|
288 |
||
289 |
||
290 |
subsection {* Interface *} |
|
291 |
||
292 |
||
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
|
293 |
record ibody = decl + --{* interface body *} |
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
|
294 |
imethods :: "(sig \<times> mhead) list" --{* method heads *} |
12854 | 295 |
|
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
|
296 |
record iface = ibody + --{* interface *} |
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
|
297 |
isuperIfs:: "qtname list" --{* superinterface list *} |
12854 | 298 |
types |
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
|
299 |
idecl --{* interface declaration, cf. 9.1 *} |
12854 | 300 |
= "qtname \<times> iface" |
301 |
||
302 |
translations |
|
303 |
"ibody" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list\<rparr>" |
|
304 |
"ibody" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list,\<dots>::'a\<rparr>" |
|
305 |
"iface" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list, |
|
306 |
isuperIfs::qtname list\<rparr>" |
|
307 |
"iface" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list, |
|
308 |
isuperIfs::qtname list,\<dots>::'a\<rparr>" |
|
309 |
"idecl" <= (type) "qtname \<times> iface" |
|
310 |
||
311 |
constdefs |
|
312 |
ibody :: "iface \<Rightarrow> ibody" |
|
313 |
"ibody i \<equiv> \<lparr>access=access i,imethods=imethods i\<rparr>" |
|
314 |
||
315 |
lemma access_ibody [simp]: "(access (ibody i)) = access i" |
|
316 |
by (simp add: ibody_def) |
|
317 |
||
318 |
lemma imethods_ibody [simp]: "(imethods (ibody i)) = imethods i" |
|
319 |
by (simp add: ibody_def) |
|
320 |
||
321 |
subsection {* Class *} |
|
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
|
322 |
record cbody = decl + --{* class body *} |
12854 | 323 |
cfields:: "fdecl list" |
324 |
methods:: "mdecl list" |
|
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
|
325 |
init :: "stmt" --{* initializer *} |
12854 | 326 |
|
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
|
327 |
record class = cbody + --{* class *} |
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
|
328 |
super :: "qtname" --{* superclass *} |
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
|
329 |
superIfs:: "qtname list" --{* implemented interfaces *} |
12854 | 330 |
types |
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
|
331 |
cdecl --{* class declaration, cf. 8.1 *} |
12854 | 332 |
= "qtname \<times> class" |
333 |
||
334 |
translations |
|
335 |
"cbody" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list, |
|
336 |
methods::mdecl list,init::stmt\<rparr>" |
|
337 |
"cbody" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list, |
|
338 |
methods::mdecl list,init::stmt,\<dots>::'a\<rparr>" |
|
339 |
"class" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list, |
|
340 |
methods::mdecl list,init::stmt, |
|
341 |
super::qtname,superIfs::qtname list\<rparr>" |
|
342 |
"class" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list, |
|
343 |
methods::mdecl list,init::stmt, |
|
344 |
super::qtname,superIfs::qtname list,\<dots>::'a\<rparr>" |
|
345 |
"cdecl" <= (type) "qtname \<times> class" |
|
346 |
||
347 |
constdefs |
|
348 |
cbody :: "class \<Rightarrow> cbody" |
|
349 |
"cbody c \<equiv> \<lparr>access=access c, cfields=cfields c,methods=methods c,init=init c\<rparr>" |
|
350 |
||
351 |
lemma access_cbody [simp]:"access (cbody c) = access c" |
|
352 |
by (simp add: cbody_def) |
|
353 |
||
354 |
lemma cfields_cbody [simp]:"cfields (cbody c) = cfields c" |
|
355 |
by (simp add: cbody_def) |
|
356 |
||
357 |
lemma methods_cbody [simp]:"methods (cbody c) = methods c" |
|
358 |
by (simp add: cbody_def) |
|
359 |
||
360 |
lemma init_cbody [simp]:"init (cbody c) = init c" |
|
361 |
by (simp add: cbody_def) |
|
362 |
||
363 |
||
364 |
section "standard classes" |
|
365 |
||
366 |
consts |
|
367 |
||
14674 | 368 |
Object_mdecls :: "mdecl list" --{* methods of Object *} |
369 |
SXcpt_mdecls :: "mdecl list" --{* methods of SXcpts *} |
|
370 |
ObjectC :: "cdecl" --{* declaration of root class *} |
|
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
|
371 |
SXcptC ::"xname \<Rightarrow> cdecl" --{* declarations of throwable classes *} |
12854 | 372 |
|
373 |
defs |
|
374 |
||
375 |
||
376 |
ObjectC_def:"ObjectC \<equiv> (Object,\<lparr>access=Public,cfields=[],methods=Object_mdecls, |
|
377 |
init=Skip,super=arbitrary,superIfs=[]\<rparr>)" |
|
378 |
SXcptC_def:"SXcptC xn\<equiv> (SXcpt xn,\<lparr>access=Public,cfields=[],methods=SXcpt_mdecls, |
|
379 |
init=Skip, |
|
380 |
super=if xn = Throwable then Object |
|
381 |
else SXcpt Throwable, |
|
382 |
superIfs=[]\<rparr>)" |
|
383 |
||
384 |
lemma ObjectC_neq_SXcptC [simp]: "ObjectC \<noteq> SXcptC xn" |
|
385 |
by (simp add: ObjectC_def SXcptC_def Object_def SXcpt_def) |
|
386 |
||
387 |
lemma SXcptC_inject [simp]: "(SXcptC xn = SXcptC xm) = (xn = xm)" |
|
388 |
apply (simp add: SXcptC_def) |
|
389 |
apply auto |
|
390 |
done |
|
391 |
||
392 |
constdefs standard_classes :: "cdecl list" |
|
393 |
"standard_classes \<equiv> [ObjectC, SXcptC Throwable, |
|
394 |
SXcptC NullPointer, SXcptC OutOfMemory, SXcptC ClassCast, |
|
395 |
SXcptC NegArrSize , SXcptC IndOutBound, SXcptC ArrStore]" |
|
396 |
||
397 |
||
398 |
section "programs" |
|
399 |
||
400 |
record prog = |
|
401 |
ifaces ::"idecl list" |
|
402 |
"classes"::"cdecl list" |
|
403 |
||
404 |
translations |
|
405 |
"prog"<= (type) "\<lparr>ifaces::idecl list,classes::cdecl list\<rparr>" |
|
406 |
"prog"<= (type) "\<lparr>ifaces::idecl list,classes::cdecl list,\<dots>::'a\<rparr>" |
|
407 |
||
408 |
syntax |
|
409 |
iface :: "prog \<Rightarrow> (qtname, iface) table" |
|
410 |
class :: "prog \<Rightarrow> (qtname, class) table" |
|
411 |
is_iface :: "prog \<Rightarrow> qtname \<Rightarrow> bool" |
|
412 |
is_class :: "prog \<Rightarrow> qtname \<Rightarrow> bool" |
|
413 |
||
414 |
translations |
|
415 |
"iface G I" == "table_of (ifaces G) I" |
|
416 |
"class G C" == "table_of (classes G) C" |
|
417 |
"is_iface G I" == "iface G I \<noteq> None" |
|
418 |
"is_class G C" == "class G C \<noteq> None" |
|
419 |
||
420 |
||
421 |
section "is type" |
|
422 |
||
423 |
consts |
|
424 |
is_type :: "prog \<Rightarrow> ty \<Rightarrow> bool" |
|
425 |
isrtype :: "prog \<Rightarrow> ref_ty \<Rightarrow> bool" |
|
426 |
||
427 |
primrec "is_type G (PrimT pt) = True" |
|
428 |
"is_type G (RefT rt) = isrtype G rt" |
|
429 |
"isrtype G (NullT ) = True" |
|
430 |
"isrtype G (IfaceT tn) = is_iface G tn" |
|
431 |
"isrtype G (ClassT tn) = is_class G tn" |
|
432 |
"isrtype G (ArrayT T ) = is_type G T" |
|
433 |
||
434 |
lemma type_is_iface: "is_type G (Iface I) \<Longrightarrow> is_iface G I" |
|
435 |
by auto |
|
436 |
||
437 |
lemma type_is_class: "is_type G (Class C) \<Longrightarrow> is_class G C" |
|
438 |
by auto |
|
439 |
||
440 |
||
441 |
section "subinterface and subclass relation, in anticipation of TypeRel.thy" |
|
442 |
||
443 |
consts |
|
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
|
444 |
subint1 :: "prog \<Rightarrow> (qtname \<times> qtname) set" --{* direct subinterface *} |
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
|
445 |
subcls1 :: "prog \<Rightarrow> (qtname \<times> qtname) set" --{* direct subclass *} |
12854 | 446 |
|
447 |
defs |
|
448 |
subint1_def: "subint1 G \<equiv> {(I,J). \<exists>i\<in>iface G I: J\<in>set (isuperIfs i)}" |
|
449 |
subcls1_def: "subcls1 G \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c\<in>class G C: super c = D)}" |
|
450 |
||
451 |
syntax |
|
452 |
"@subcls1" :: "prog => [qtname, qtname] => bool" ("_|-_<:C1_" [71,71,71] 70) |
|
453 |
"@subclseq":: "prog => [qtname, qtname] => bool" ("_|-_<=:C _"[71,71,71] 70) |
|
454 |
"@subcls" :: "prog => [qtname, qtname] => bool" ("_|-_<:C _"[71,71,71] 70) |
|
455 |
||
456 |
syntax (xsymbols) |
|
457 |
"@subcls1" :: "prog \<Rightarrow> [qtname, qtname] \<Rightarrow> bool" ("_\<turnstile>_\<prec>\<^sub>C\<^sub>1_" [71,71,71] 70) |
|
458 |
"@subclseq":: "prog \<Rightarrow> [qtname, qtname] \<Rightarrow> bool" ("_\<turnstile>_\<preceq>\<^sub>C _" [71,71,71] 70) |
|
459 |
"@subcls" :: "prog \<Rightarrow> [qtname, qtname] \<Rightarrow> bool" ("_\<turnstile>_\<prec>\<^sub>C _" [71,71,71] 70) |
|
460 |
||
461 |
translations |
|
462 |
"G\<turnstile>C \<prec>\<^sub>C\<^sub>1 D" == "(C,D) \<in> subcls1 G" |
|
463 |
"G\<turnstile>C \<preceq>\<^sub>C D" == "(C,D) \<in>(subcls1 G)^*" (* cf. 8.1.3 *) |
|
464 |
"G\<turnstile>C \<prec>\<^sub>C D" == "(C,D) \<in>(subcls1 G)^+" |
|
465 |
||
466 |
||
467 |
lemma subint1I: "\<lbrakk>iface G I = Some i; J \<in> set (isuperIfs i)\<rbrakk> |
|
468 |
\<Longrightarrow> (I,J) \<in> subint1 G" |
|
469 |
apply (simp add: subint1_def) |
|
470 |
done |
|
471 |
||
472 |
lemma subcls1I:"\<lbrakk>class G C = Some c; C \<noteq> Object\<rbrakk> \<Longrightarrow> (C,(super c)) \<in> subcls1 G" |
|
473 |
apply (simp add: subcls1_def) |
|
474 |
done |
|
475 |
||
476 |
||
477 |
lemma subint1D: "(I,J)\<in>subint1 G\<Longrightarrow> \<exists>i\<in>iface G I: J\<in>set (isuperIfs i)" |
|
478 |
by (simp add: subint1_def) |
|
479 |
||
480 |
lemma subcls1D: |
|
481 |
"(C,D)\<in>subcls1 G \<Longrightarrow> C\<noteq>Object \<and> (\<exists>c. class G C = Some c \<and> (super c = D))" |
|
482 |
apply (simp add: subcls1_def) |
|
483 |
apply auto |
|
484 |
done |
|
485 |
||
486 |
lemma subint1_def2: |
|
14952
47455995693d
removal of x-symbol syntax <Sigma> for dependent products
paulson
parents:
14674
diff
changeset
|
487 |
"subint1 G = (SIGMA I: {I. is_iface G I}. set (isuperIfs (the (iface G I))))" |
12854 | 488 |
apply (unfold subint1_def) |
489 |
apply auto |
|
490 |
done |
|
491 |
||
492 |
lemma subcls1_def2: |
|
14952
47455995693d
removal of x-symbol syntax <Sigma> for dependent products
paulson
parents:
14674
diff
changeset
|
493 |
"subcls1 G = |
47455995693d
removal of x-symbol syntax <Sigma> for dependent products
paulson
parents:
14674
diff
changeset
|
494 |
(SIGMA C: {C. is_class G C}. {D. C\<noteq>Object \<and> super (the(class G C))=D})" |
12854 | 495 |
apply (unfold subcls1_def) |
496 |
apply auto |
|
497 |
done |
|
498 |
||
499 |
lemma subcls_is_class: |
|
500 |
"\<lbrakk>G\<turnstile>C \<prec>\<^sub>C D\<rbrakk> \<Longrightarrow> \<exists> c. class G C = Some c" |
|
501 |
by (auto simp add: subcls1_def dest: tranclD) |
|
502 |
||
503 |
lemma no_subcls1_Object:"G\<turnstile>Object\<prec>\<^sub>C\<^sub>1 D \<Longrightarrow> P" |
|
504 |
by (auto simp add: subcls1_def) |
|
505 |
||
506 |
lemma no_subcls_Object: "G\<turnstile>Object\<prec>\<^sub>C D \<Longrightarrow> P" |
|
507 |
apply (erule trancl_induct) |
|
508 |
apply (auto intro: no_subcls1_Object) |
|
509 |
done |
|
510 |
||
511 |
section "well-structured programs" |
|
512 |
||
513 |
constdefs |
|
514 |
ws_idecl :: "prog \<Rightarrow> qtname \<Rightarrow> qtname list \<Rightarrow> bool" |
|
515 |
"ws_idecl G I si \<equiv> \<forall>J\<in>set si. is_iface G J \<and> (J,I)\<notin>(subint1 G)^+" |
|
516 |
||
517 |
ws_cdecl :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool" |
|
518 |
"ws_cdecl G C sc \<equiv> C\<noteq>Object \<longrightarrow> is_class G sc \<and> (sc,C)\<notin>(subcls1 G)^+" |
|
519 |
||
520 |
ws_prog :: "prog \<Rightarrow> bool" |
|
521 |
"ws_prog G \<equiv> (\<forall>(I,i)\<in>set (ifaces G). ws_idecl G I (isuperIfs i)) \<and> |
|
522 |
(\<forall>(C,c)\<in>set (classes G). ws_cdecl G C (super c))" |
|
523 |
||
524 |
||
525 |
lemma ws_progI: |
|
526 |
"\<lbrakk>\<forall>(I,i)\<in>set (ifaces G). \<forall>J\<in>set (isuperIfs i). is_iface G J \<and> |
|
527 |
(J,I) \<notin> (subint1 G)^+; |
|
528 |
\<forall>(C,c)\<in>set (classes G). C\<noteq>Object \<longrightarrow> is_class G (super c) \<and> |
|
529 |
((super c),C) \<notin> (subcls1 G)^+ |
|
530 |
\<rbrakk> \<Longrightarrow> ws_prog G" |
|
531 |
apply (unfold ws_prog_def ws_idecl_def ws_cdecl_def) |
|
532 |
apply (erule_tac conjI) |
|
533 |
apply blast |
|
534 |
done |
|
535 |
||
536 |
lemma ws_prog_ideclD: |
|
537 |
"\<lbrakk>iface G I = Some i; J\<in>set (isuperIfs i); ws_prog G\<rbrakk> \<Longrightarrow> |
|
538 |
is_iface G J \<and> (J,I)\<notin>(subint1 G)^+" |
|
539 |
apply (unfold ws_prog_def ws_idecl_def) |
|
540 |
apply clarify |
|
541 |
apply (drule_tac map_of_SomeD) |
|
542 |
apply auto |
|
543 |
done |
|
544 |
||
545 |
lemma ws_prog_cdeclD: |
|
546 |
"\<lbrakk>class G C = Some c; C\<noteq>Object; ws_prog G\<rbrakk> \<Longrightarrow> |
|
547 |
is_class G (super c) \<and> (super c,C)\<notin>(subcls1 G)^+" |
|
548 |
apply (unfold ws_prog_def ws_cdecl_def) |
|
549 |
apply clarify |
|
550 |
apply (drule_tac map_of_SomeD) |
|
551 |
apply auto |
|
552 |
done |
|
553 |
||
554 |
||
555 |
section "well-foundedness" |
|
556 |
||
557 |
lemma finite_is_iface: "finite {I. is_iface G I}" |
|
558 |
apply (fold dom_def) |
|
559 |
apply (rule_tac finite_dom_map_of) |
|
560 |
done |
|
561 |
||
562 |
lemma finite_is_class: "finite {C. is_class G C}" |
|
563 |
apply (fold dom_def) |
|
564 |
apply (rule_tac finite_dom_map_of) |
|
565 |
done |
|
566 |
||
567 |
lemma finite_subint1: "finite (subint1 G)" |
|
568 |
apply (subst subint1_def2) |
|
569 |
apply (rule finite_SigmaI) |
|
570 |
apply (rule finite_is_iface) |
|
571 |
apply (simp (no_asm)) |
|
572 |
done |
|
573 |
||
574 |
lemma finite_subcls1: "finite (subcls1 G)" |
|
575 |
apply (subst subcls1_def2) |
|
576 |
apply (rule finite_SigmaI) |
|
577 |
apply (rule finite_is_class) |
|
578 |
apply (rule_tac B = "{super (the (class G C))}" in finite_subset) |
|
579 |
apply auto |
|
580 |
done |
|
581 |
||
582 |
lemma subint1_irrefl_lemma1: |
|
583 |
"ws_prog G \<Longrightarrow> (subint1 G)^-1 \<inter> (subint1 G)^+ = {}" |
|
584 |
apply (force dest: subint1D ws_prog_ideclD conjunct2) |
|
585 |
done |
|
586 |
||
587 |
lemma subcls1_irrefl_lemma1: |
|
588 |
"ws_prog G \<Longrightarrow> (subcls1 G)^-1 \<inter> (subcls1 G)^+ = {}" |
|
589 |
apply (force dest: subcls1D ws_prog_cdeclD conjunct2) |
|
590 |
done |
|
591 |
||
592 |
lemmas subint1_irrefl_lemma2 = subint1_irrefl_lemma1 [THEN irrefl_tranclI'] |
|
593 |
lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI'] |
|
594 |
||
595 |
lemma subint1_irrefl: "\<lbrakk>(x, y) \<in> subint1 G; ws_prog G\<rbrakk> \<Longrightarrow> x \<noteq> y" |
|
596 |
apply (rule irrefl_trancl_rD) |
|
597 |
apply (rule subint1_irrefl_lemma2) |
|
598 |
apply auto |
|
599 |
done |
|
600 |
||
601 |
lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1 G; ws_prog G\<rbrakk> \<Longrightarrow> x \<noteq> y" |
|
602 |
apply (rule irrefl_trancl_rD) |
|
603 |
apply (rule subcls1_irrefl_lemma2) |
|
604 |
apply auto |
|
605 |
done |
|
606 |
||
607 |
lemmas subint1_acyclic = subint1_irrefl_lemma2 [THEN acyclicI, standard] |
|
608 |
lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI, standard] |
|
609 |
||
610 |
||
611 |
lemma wf_subint1: "ws_prog G \<Longrightarrow> wf ((subint1 G)\<inverse>)" |
|
612 |
by (auto intro: finite_acyclic_wf_converse finite_subint1 subint1_acyclic) |
|
613 |
||
614 |
lemma wf_subcls1: "ws_prog G \<Longrightarrow> wf ((subcls1 G)\<inverse>)" |
|
615 |
by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic) |
|
616 |
||
617 |
||
618 |
lemma subint1_induct: |
|
619 |
"\<lbrakk>ws_prog G; \<And>x. \<forall>y. (x, y) \<in> subint1 G \<longrightarrow> P y \<Longrightarrow> P x\<rbrakk> \<Longrightarrow> P a" |
|
620 |
apply (frule wf_subint1) |
|
621 |
apply (erule wf_induct) |
|
622 |
apply (simp (no_asm_use) only: converse_iff) |
|
623 |
apply blast |
|
624 |
done |
|
625 |
||
626 |
lemma subcls1_induct [consumes 1]: |
|
627 |
"\<lbrakk>ws_prog G; \<And>x. \<forall>y. (x, y) \<in> subcls1 G \<longrightarrow> P y \<Longrightarrow> P x\<rbrakk> \<Longrightarrow> P a" |
|
628 |
apply (frule wf_subcls1) |
|
629 |
apply (erule wf_induct) |
|
630 |
apply (simp (no_asm_use) only: converse_iff) |
|
631 |
apply blast |
|
632 |
done |
|
633 |
||
634 |
lemma ws_subint1_induct: |
|
635 |
"\<lbrakk>is_iface G I; ws_prog G; \<And>I i. \<lbrakk>iface G I = Some i \<and> |
|
636 |
(\<forall>J \<in> set (isuperIfs i). (I,J)\<in>subint1 G \<and> P J \<and> is_iface G J)\<rbrakk> \<Longrightarrow> P I |
|
637 |
\<rbrakk> \<Longrightarrow> P I" |
|
638 |
apply (erule make_imp) |
|
639 |
apply (rule subint1_induct) |
|
640 |
apply assumption |
|
641 |
apply safe |
|
642 |
apply (fast dest: subint1I ws_prog_ideclD) |
|
643 |
done |
|
644 |
||
645 |
||
646 |
lemma ws_subcls1_induct: "\<lbrakk>is_class G C; ws_prog G; |
|
647 |
\<And>C c. \<lbrakk>class G C = Some c; |
|
648 |
(C \<noteq> Object \<longrightarrow> (C,(super c))\<in>subcls1 G \<and> |
|
649 |
P (super c) \<and> is_class G (super c))\<rbrakk> \<Longrightarrow> P C |
|
650 |
\<rbrakk> \<Longrightarrow> P C" |
|
651 |
apply (erule make_imp) |
|
652 |
apply (rule subcls1_induct) |
|
653 |
apply assumption |
|
654 |
apply safe |
|
655 |
apply (fast dest: subcls1I ws_prog_cdeclD) |
|
656 |
done |
|
657 |
||
658 |
lemma ws_class_induct [consumes 2, case_names Object Subcls]: |
|
659 |
"\<lbrakk>class G C = Some c; ws_prog G; |
|
660 |
\<And> co. class G Object = Some co \<Longrightarrow> P Object; |
|
661 |
\<And> C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C |
|
662 |
\<rbrakk> \<Longrightarrow> P C" |
|
663 |
proof - |
|
664 |
assume clsC: "class G C = Some c" |
|
665 |
and init: "\<And> co. class G Object = Some co \<Longrightarrow> P Object" |
|
666 |
and step: "\<And> C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C" |
|
667 |
assume ws: "ws_prog G" |
|
668 |
then have "is_class G C \<Longrightarrow> P C" |
|
669 |
proof (induct rule: subcls1_induct) |
|
670 |
fix C |
|
671 |
assume hyp:"\<forall> S. G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S \<longrightarrow> is_class G S \<longrightarrow> P S" |
|
672 |
and iscls:"is_class G C" |
|
673 |
show "P C" |
|
674 |
proof (cases "C=Object") |
|
675 |
case True with iscls init show "P C" by auto |
|
676 |
next |
|
677 |
case False with ws step hyp iscls |
|
678 |
show "P C" by (auto dest: subcls1I ws_prog_cdeclD) |
|
679 |
qed |
|
680 |
qed |
|
681 |
with clsC show ?thesis by simp |
|
682 |
qed |
|
683 |
||
684 |
lemma ws_class_induct' [consumes 2, case_names Object Subcls]: |
|
685 |
"\<lbrakk>is_class G C; ws_prog G; |
|
686 |
\<And> co. class G Object = Some co \<Longrightarrow> P Object; |
|
687 |
\<And> C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C |
|
688 |
\<rbrakk> \<Longrightarrow> P C" |
|
689 |
by (blast intro: ws_class_induct) |
|
690 |
||
691 |
lemma ws_class_induct'' [consumes 2, case_names Object Subcls]: |
|
692 |
"\<lbrakk>class G C = Some c; ws_prog G; |
|
693 |
\<And> co. class G Object = Some co \<Longrightarrow> P Object co; |
|
694 |
\<And> C c sc. \<lbrakk>class G C = Some c; class G (super c) = Some sc; |
|
695 |
C \<noteq> Object; P (super c) sc\<rbrakk> \<Longrightarrow> P C c |
|
696 |
\<rbrakk> \<Longrightarrow> P C c" |
|
697 |
proof - |
|
698 |
assume clsC: "class G C = Some c" |
|
699 |
and init: "\<And> co. class G Object = Some co \<Longrightarrow> P Object co" |
|
700 |
and step: "\<And> C c sc . \<lbrakk>class G C = Some c; class G (super c) = Some sc; |
|
701 |
C \<noteq> Object; P (super c) sc\<rbrakk> \<Longrightarrow> P C c" |
|
702 |
assume ws: "ws_prog G" |
|
703 |
then have "\<And> c. class G C = Some c\<Longrightarrow> P C c" |
|
704 |
proof (induct rule: subcls1_induct) |
|
705 |
fix C c |
|
706 |
assume hyp:"\<forall> S. G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S \<longrightarrow> (\<forall> s. class G S = Some s \<longrightarrow> P S s)" |
|
707 |
and iscls:"class G C = Some c" |
|
708 |
show "P C c" |
|
709 |
proof (cases "C=Object") |
|
710 |
case True with iscls init show "P C c" by auto |
|
711 |
next |
|
712 |
case False |
|
713 |
with ws iscls obtain sc where |
|
714 |
sc: "class G (super c) = Some sc" |
|
715 |
by (auto dest: ws_prog_cdeclD) |
|
716 |
from iscls False have "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 (super c)" by (rule subcls1I) |
|
717 |
with False ws step hyp iscls sc |
|
718 |
show "P C c" |
|
719 |
by (auto) |
|
720 |
qed |
|
721 |
qed |
|
722 |
with clsC show "P C c" by auto |
|
723 |
qed |
|
724 |
||
725 |
lemma ws_interface_induct [consumes 2, case_names Step]: |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
726 |
assumes is_if_I: "is_iface G I" and |
12854 | 727 |
ws: "ws_prog G" and |
728 |
hyp_sub: "\<And>I i. \<lbrakk>iface G I = Some i; |
|
729 |
\<forall> J \<in> set (isuperIfs i). |
|
730 |
(I,J)\<in>subint1 G \<and> P J \<and> is_iface G J\<rbrakk> \<Longrightarrow> P I" |
|
12937
0c4fd7529467
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm
parents:
12925
diff
changeset
|
731 |
shows "P I" |
12854 | 732 |
proof - |
733 |
from is_if_I ws |
|
734 |
show "P I" |
|
735 |
proof (rule ws_subint1_induct) |
|
736 |
fix I i |
|
737 |
assume hyp: "iface G I = Some i \<and> |
|
738 |
(\<forall>J\<in>set (isuperIfs i). (I,J) \<in>subint1 G \<and> P J \<and> is_iface G J)" |
|
739 |
then have if_I: "iface G I = Some i" |
|
740 |
by blast |
|
741 |
show "P I" |
|
742 |
proof (cases "isuperIfs i") |
|
743 |
case Nil |
|
744 |
with if_I hyp_sub |
|
745 |
show "P I" |
|
746 |
by auto |
|
747 |
next |
|
748 |
case (Cons hd tl) |
|
749 |
with hyp if_I hyp_sub |
|
750 |
show "P I" |
|
751 |
by auto |
|
752 |
qed |
|
753 |
qed |
|
754 |
qed |
|
755 |
||
756 |
section "general recursion operators for the interface and class hiearchies" |
|
757 |
||
758 |
consts |
|
759 |
iface_rec :: "prog \<times> qtname \<Rightarrow> \<spacespace> (qtname \<Rightarrow> iface \<Rightarrow> 'a set \<Rightarrow> 'a) \<Rightarrow> 'a" |
|
760 |
class_rec :: "prog \<times> qtname \<Rightarrow> 'a \<Rightarrow> (qtname \<Rightarrow> class \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> 'a" |
|
761 |
||
762 |
recdef iface_rec "same_fst ws_prog (\<lambda>G. (subint1 G)^-1)" |
|
763 |
"iface_rec (G,I) = |
|
764 |
(\<lambda>f. case iface G I of |
|
765 |
None \<Rightarrow> arbitrary |
|
766 |
| Some i \<Rightarrow> if ws_prog G |
|
767 |
then f I i |
|
768 |
((\<lambda>J. iface_rec (G,J) f)`set (isuperIfs i)) |
|
769 |
else arbitrary)" |
|
770 |
(hints recdef_wf: wf_subint1 intro: subint1I) |
|
771 |
declare iface_rec.simps [simp del] |
|
772 |
||
773 |
lemma iface_rec: |
|
774 |
"\<lbrakk>iface G I = Some i; ws_prog G\<rbrakk> \<Longrightarrow> |
|
775 |
iface_rec (G,I) f = f I i ((\<lambda>J. iface_rec (G,J) f)`set (isuperIfs i))" |
|
776 |
apply (subst iface_rec.simps) |
|
777 |
apply simp |
|
778 |
done |
|
779 |
||
780 |
recdef class_rec "same_fst ws_prog (\<lambda>G. (subcls1 G)^-1)" |
|
781 |
"class_rec(G,C) = |
|
782 |
(\<lambda>t f. case class G C of |
|
783 |
None \<Rightarrow> arbitrary |
|
784 |
| Some c \<Rightarrow> if ws_prog G |
|
785 |
then f C c |
|
786 |
(if C = Object then t |
|
787 |
else class_rec (G,super c) t f) |
|
788 |
else arbitrary)" |
|
789 |
(hints recdef_wf: wf_subcls1 intro: subcls1I) |
|
790 |
declare class_rec.simps [simp del] |
|
791 |
||
792 |
lemma class_rec: "\<lbrakk>class G C = Some c; ws_prog G\<rbrakk> \<Longrightarrow> |
|
793 |
class_rec (G,C) t f = |
|
794 |
f C c (if C = Object then t else class_rec (G,super c) t f)" |
|
795 |
apply (rule class_rec.simps [THEN trans [THEN fun_cong [THEN fun_cong]]]) |
|
796 |
apply simp |
|
797 |
done |
|
798 |
||
799 |
constdefs |
|
800 |
imethds:: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables" |
|
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
|
801 |
--{* methods of an interface, with overriding and inheritance, cf. 9.2 *} |
12854 | 802 |
"imethds G I |
803 |
\<equiv> iface_rec (G,I) |
|
804 |
(\<lambda>I i ts. (Un_tables ts) \<oplus>\<oplus> |
|
805 |
(o2s \<circ> table_of (map (\<lambda>(s,m). (s,I,m)) (imethods i))))" |
|
806 |
||
807 |
||
808 |
||
809 |
end |