author | kleing |
Sun, 07 Jan 2001 18:43:13 +0100 | |
changeset 10812 | ead84e90bfeb |
parent 10797 | 028d22926a41 |
child 10896 | 23386a5b63eb |
permissions | -rw-r--r-- |
10497 | 1 |
(* Title: HOL/BCV/JType.thy |
2 |
ID: $Id$ |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10797
diff
changeset
|
3 |
Author: Tobias Nipkow, Gerwin Klein |
10497 | 4 |
Copyright 2000 TUM |
5 |
*) |
|
6 |
||
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10797
diff
changeset
|
7 |
header "Java Type System as Semilattice" |
10497 | 8 |
|
9 |
theory JType = WellForm + Err: |
|
10 |
||
11 |
constdefs |
|
12 |
is_ref :: "ty => bool" |
|
13 |
"is_ref T == case T of PrimT t => False | RefT r => True" |
|
14 |
||
15 |
sup :: "'c prog => ty => ty => ty err" |
|
16 |
"sup G T1 T2 == |
|
17 |
case T1 of PrimT P1 => (case T2 of PrimT P2 => (if P1 = P2 then OK (PrimT P1) else Err) | RefT R => Err) |
|
18 |
| RefT R1 => (case T2 of PrimT P => Err | RefT R2 => |
|
19 |
(case R1 of NullT => (case R2 of NullT => OK NT | ClassT C => OK (Class C)) |
|
20 |
| ClassT C => (case R2 of NullT => OK (Class C) |
|
21 |
| ClassT D => OK (Class (some_lub ((subcls1 G)^* ) C D)))))" |
|
22 |
||
23 |
subtype :: "'c prog => ty => ty => bool" |
|
24 |
"subtype G T1 T2 == G \<turnstile> T1 \<preceq> T2" |
|
25 |
||
26 |
is_ty :: "'c prog => ty => bool" |
|
27 |
"is_ty G T == case T of PrimT P => True | RefT R => |
|
28 |
(case R of NullT => True | ClassT C => (C,Object):(subcls1 G)^*)" |
|
29 |
||
30 |
translations |
|
31 |
"types G" == "Collect (is_type G)" |
|
32 |
||
33 |
constdefs |
|
34 |
esl :: "'c prog => ty esl" |
|
35 |
"esl G == (types G, subtype G, sup G)" |
|
36 |
||
37 |
lemma PrimT_PrimT: "(G \<turnstile> xb \<preceq> PrimT p) = (xb = PrimT p)" |
|
38 |
by (auto elim: widen.elims) |
|
39 |
||
40 |
lemma PrimT_PrimT2: "(G \<turnstile> PrimT p \<preceq> xb) = (xb = PrimT p)" |
|
41 |
by (auto elim: widen.elims) |
|
42 |
||
43 |
lemma is_tyI: |
|
44 |
"[| is_type G T; wf_prog wf_mb G |] ==> is_ty G T" |
|
10630 | 45 |
by (auto simp add: is_ty_def intro: subcls_C_Object |
10497 | 46 |
split: ty.splits ref_ty.splits) |
47 |
||
48 |
lemma is_type_conv: |
|
49 |
"wf_prog wf_mb G ==> is_type G T = is_ty G T" |
|
50 |
proof |
|
51 |
assume "is_type G T" "wf_prog wf_mb G" |
|
52 |
thus "is_ty G T" |
|
53 |
by (rule is_tyI) |
|
54 |
next |
|
55 |
assume wf: "wf_prog wf_mb G" and |
|
56 |
ty: "is_ty G T" |
|
57 |
||
58 |
show "is_type G T" |
|
59 |
proof (cases T) |
|
60 |
case PrimT |
|
61 |
thus ?thesis by simp |
|
62 |
next |
|
63 |
fix R assume R: "T = RefT R" |
|
64 |
with wf |
|
65 |
have "R = ClassT Object \<Longrightarrow> ?thesis" by simp |
|
66 |
moreover |
|
67 |
from R wf ty |
|
68 |
have "R \<noteq> ClassT Object \<Longrightarrow> ?thesis" |
|
10612
779af7c58743
improved superclass entry for classes and definition status of is_class, class
oheimb
parents:
10592
diff
changeset
|
69 |
by (auto simp add: is_ty_def subcls1_def |
10497 | 70 |
elim: converse_rtranclE |
71 |
split: ref_ty.splits) |
|
72 |
ultimately |
|
73 |
show ?thesis by blast |
|
74 |
qed |
|
75 |
qed |
|
76 |
||
77 |
||
78 |
lemma order_widen: |
|
79 |
"acyclic (subcls1 G) ==> order (subtype G)" |
|
80 |
apply (unfold order_def lesub_def subtype_def) |
|
81 |
apply (auto intro: widen_trans) |
|
82 |
apply (case_tac x) |
|
83 |
apply (case_tac y) |
|
84 |
apply (auto simp add: PrimT_PrimT) |
|
85 |
apply (case_tac y) |
|
86 |
apply simp |
|
87 |
apply simp |
|
88 |
apply (case_tac ref_ty) |
|
89 |
apply (case_tac ref_tya) |
|
90 |
apply simp |
|
91 |
apply simp |
|
92 |
apply (case_tac ref_tya) |
|
93 |
apply simp |
|
94 |
apply simp |
|
95 |
apply (auto dest: acyclic_impl_antisym_rtrancl antisymD) |
|
96 |
done |
|
97 |
||
10592 | 98 |
lemma wf_converse_subcls1_impl_acc_subtype: |
99 |
"wf ((subcls1 G)^-1) ==> acc (subtype G)" |
|
100 |
apply (unfold acc_def lesssub_def) |
|
101 |
apply (drule_tac p = "(subcls1 G)^-1 - Id" in wf_subset) |
|
102 |
apply blast |
|
103 |
apply (drule wf_trancl) |
|
104 |
apply (simp add: wf_eq_minimal) |
|
105 |
apply clarify |
|
106 |
apply (unfold lesub_def subtype_def) |
|
107 |
apply (rename_tac M T) |
|
108 |
apply (case_tac "EX C. Class C : M") |
|
109 |
prefer 2 |
|
110 |
apply (case_tac T) |
|
111 |
apply (fastsimp simp add: PrimT_PrimT2) |
|
112 |
apply simp |
|
113 |
apply (subgoal_tac "ref_ty = NullT") |
|
114 |
apply simp |
|
115 |
apply (rule_tac x = NT in bexI) |
|
116 |
apply (rule allI) |
|
117 |
apply (rule impI, erule conjE) |
|
118 |
apply (drule widen_RefT) |
|
119 |
apply clarsimp |
|
120 |
apply (case_tac t) |
|
121 |
apply simp |
|
122 |
apply simp |
|
123 |
apply simp |
|
124 |
apply (case_tac ref_ty) |
|
125 |
apply simp |
|
126 |
apply simp |
|
127 |
apply (erule_tac x = "{C. Class C : M}" in allE) |
|
128 |
apply auto |
|
129 |
apply (rename_tac D) |
|
130 |
apply (rule_tac x = "Class D" in bexI) |
|
131 |
prefer 2 |
|
132 |
apply assumption |
|
133 |
apply clarify |
|
134 |
apply (frule widen_RefT) |
|
135 |
apply (erule exE) |
|
136 |
apply (case_tac t) |
|
137 |
apply simp |
|
138 |
apply simp |
|
139 |
apply (insert rtrancl_r_diff_Id [symmetric, standard, of "(subcls1 G)"]) |
|
140 |
apply simp |
|
141 |
apply (erule rtranclE) |
|
142 |
apply blast |
|
143 |
apply (drule rtrancl_converseI) |
|
144 |
apply (subgoal_tac "((subcls1 G)-Id)^-1 = ((subcls1 G)^-1 - Id)") |
|
145 |
prefer 2 |
|
146 |
apply blast |
|
147 |
apply simp |
|
148 |
apply (blast intro: rtrancl_into_trancl2) |
|
149 |
done |
|
150 |
||
10497 | 151 |
lemma closed_err_types: |
10797 | 152 |
"[| wf_prog wf_mb G; single_valued (subcls1 G); acyclic (subcls1 G) |] |
10497 | 153 |
==> closed (err (types G)) (lift2 (sup G))" |
154 |
apply (unfold closed_def plussub_def lift2_def sup_def) |
|
155 |
apply (auto split: err.split) |
|
156 |
apply (drule is_tyI, assumption) |
|
157 |
apply (auto simp add: is_ty_def is_type_conv simp del: is_type.simps |
|
158 |
split: ty.split ref_ty.split) |
|
159 |
apply (blast dest!: is_lub_some_lub is_lubD is_ubD intro!: is_ubI) |
|
160 |
done |
|
161 |
||
162 |
||
163 |
lemma err_semilat_JType_esl_lemma: |
|
10797 | 164 |
"[| wf_prog wf_mb G; single_valued (subcls1 G); acyclic (subcls1 G) |] |
10497 | 165 |
==> err_semilat (esl G)" |
166 |
proof - |
|
167 |
assume wf_prog: "wf_prog wf_mb G" |
|
10797 | 168 |
assume single_valued: "single_valued (subcls1 G)" |
10497 | 169 |
assume acyclic: "acyclic (subcls1 G)" |
170 |
||
171 |
hence "order (subtype G)" |
|
172 |
by (rule order_widen) |
|
173 |
moreover |
|
10797 | 174 |
from wf_prog single_valued acyclic |
10497 | 175 |
have "closed (err (types G)) (lift2 (sup G))" |
176 |
by (rule closed_err_types) |
|
177 |
moreover |
|
178 |
||
179 |
{ fix c1 c2 |
|
180 |
assume is_class: "is_class G c1" "is_class G c2" |
|
181 |
with wf_prog |
|
182 |
obtain |
|
183 |
"G \<turnstile> c1 \<preceq>C Object" |
|
184 |
"G \<turnstile> c2 \<preceq>C Object" |
|
185 |
by (blast intro: subcls_C_Object) |
|
10797 | 186 |
with wf_prog single_valued |
10497 | 187 |
obtain u where |
188 |
"is_lub ((subcls1 G)^* ) c1 c2 u" |
|
10797 | 189 |
by (blast dest: single_valued_has_lubs) |
10497 | 190 |
with acyclic |
191 |
have "G \<turnstile> c1 \<preceq>C some_lub ((subcls1 G)^* ) c1 c2" |
|
192 |
by (simp add: some_lub_conv) (blast dest: is_lubD is_ubD) |
|
193 |
} note this [intro] |
|
194 |
||
195 |
{ fix t1 t2 s |
|
196 |
assume "is_type G t1" "is_type G t2" "sup G t1 t2 = OK s" |
|
197 |
hence "subtype G t1 s" |
|
198 |
by (unfold sup_def subtype_def) |
|
199 |
(cases s, auto intro: widen.null |
|
200 |
split: ty.splits ref_ty.splits if_splits) |
|
201 |
} note this [intro] |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10797
diff
changeset
|
202 |
|
10497 | 203 |
have |
204 |
"\<forall>x\<in>err (types G). \<forall>y\<in>err (types G). x <=_(le (subtype G)) x +_(lift2 (sup G)) y" |
|
205 |
by (auto simp add: lesub_def plussub_def le_def lift2_def split: err.split) |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10797
diff
changeset
|
206 |
|
10497 | 207 |
moreover |
208 |
||
209 |
{ fix c1 c2 |
|
210 |
assume "is_class G c1" "is_class G c2" |
|
211 |
with wf_prog |
|
212 |
obtain |
|
213 |
"G \<turnstile> c1 \<preceq>C Object" |
|
214 |
"G \<turnstile> c2 \<preceq>C Object" |
|
215 |
by (blast intro: subcls_C_Object) |
|
10797 | 216 |
with wf_prog single_valued |
10497 | 217 |
obtain u where |
218 |
"is_lub ((subcls1 G)^* ) c2 c1 u" |
|
10797 | 219 |
by (blast dest: single_valued_has_lubs) |
10497 | 220 |
with acyclic |
221 |
have "G \<turnstile> c1 \<preceq>C some_lub ((subcls1 G)^* ) c2 c1" |
|
222 |
by (simp add: some_lub_conv) (blast dest: is_lubD is_ubD) |
|
223 |
} note this [intro] |
|
224 |
||
225 |
have "\<forall>x\<in>err (types G). \<forall>y\<in>err (types G). |
|
226 |
y <=_(le (subtype G)) x +_(lift2 (sup G)) y" |
|
227 |
by (auto simp add: lesub_def plussub_def le_def sup_def subtype_def lift2_def |
|
228 |
split: err.split ty.splits ref_ty.splits if_splits intro: widen.null) |
|
229 |
moreover |
|
230 |
||
231 |
have [intro]: |
|
232 |
"!!a b c. [| G \<turnstile> a \<preceq> c; G \<turnstile> b \<preceq> c; sup G a b = Err |] ==> False" |
|
233 |
by (auto simp add: PrimT_PrimT PrimT_PrimT2 sup_def |
|
234 |
split: ty.splits ref_ty.splits) |
|
235 |
||
236 |
{ fix c1 c2 D |
|
237 |
assume is_class: "is_class G c1" "is_class G c2" |
|
238 |
assume le: "G \<turnstile> c1 \<preceq>C D" "G \<turnstile> c2 \<preceq>C D" |
|
239 |
from wf_prog is_class |
|
240 |
obtain |
|
241 |
"G \<turnstile> c1 \<preceq>C Object" |
|
242 |
"G \<turnstile> c2 \<preceq>C Object" |
|
243 |
by (blast intro: subcls_C_Object) |
|
10797 | 244 |
with wf_prog single_valued |
10497 | 245 |
obtain u where |
246 |
lub: "is_lub ((subcls1 G)^* ) c1 c2 u" |
|
10797 | 247 |
by (blast dest: single_valued_has_lubs) |
10497 | 248 |
with acyclic |
249 |
have "some_lub ((subcls1 G)^* ) c1 c2 = u" |
|
250 |
by (rule some_lub_conv) |
|
251 |
moreover |
|
252 |
from lub le |
|
253 |
have "G \<turnstile> u \<preceq>C D" |
|
254 |
by (simp add: is_lub_def is_ub_def) |
|
255 |
ultimately |
|
256 |
have "G \<turnstile> some_lub ((subcls1 G)\<^sup>*) c1 c2 \<preceq>C D" |
|
257 |
by blast |
|
258 |
} note this [intro] |
|
259 |
||
260 |
have [dest!]: |
|
261 |
"!!C T. G \<turnstile> Class C \<preceq> T ==> \<exists>D. T=Class D \<and> G \<turnstile> C \<preceq>C D" |
|
262 |
by (frule widen_Class, auto) |
|
263 |
||
264 |
{ fix a b c d |
|
265 |
assume "is_type G a" "is_type G b" "is_type G c" and |
|
266 |
"G \<turnstile> a \<preceq> c" "G \<turnstile> b \<preceq> c" and |
|
267 |
"sup G a b = OK d" |
|
268 |
hence "G \<turnstile> d \<preceq> c" |
|
269 |
by (auto simp add: sup_def split: ty.splits ref_ty.splits if_splits) |
|
270 |
} note this [intro] |
|
271 |
||
272 |
have |
|
273 |
"\<forall>x\<in>err (types G). \<forall>y\<in>err (types G). \<forall>z\<in>err (types G). |
|
274 |
x <=_(le (subtype G)) z \<and> y <=_(le (subtype G)) z \<longrightarrow> x +_(lift2 (sup G)) y <=_(le (subtype G)) z" |
|
275 |
by (simp add: lift2_def plussub_def lesub_def subtype_def le_def split: err.splits) blast |
|
276 |
||
277 |
ultimately |
|
278 |
||
279 |
show ?thesis |
|
280 |
by (unfold esl_def semilat_def sl_def) auto |
|
281 |
qed |
|
282 |
||
10797 | 283 |
lemma single_valued_subcls1: |
284 |
"wf_prog wf_mb G ==> single_valued (subcls1 G)" |
|
285 |
by (unfold wf_prog_def unique_def single_valued_def subcls1_def) auto |
|
10497 | 286 |
|
10592 | 287 |
theorem err_semilat_JType_esl: |
288 |
"wf_prog wf_mb G ==> err_semilat (esl G)" |
|
10797 | 289 |
by (frule acyclic_subcls1, frule single_valued_subcls1, rule err_semilat_JType_esl_lemma) |
10497 | 290 |
|
291 |
end |