25 \end{description} |
25 \end{description} |
26 *} |
26 *} |
27 types 'c wf_mb = "'c prog => cname => 'c mdecl => bool" |
27 types 'c wf_mb = "'c prog => cname => 'c mdecl => bool" |
28 |
28 |
29 constdefs |
29 constdefs |
|
30 wf_syscls :: "'c prog => bool" |
|
31 "wf_syscls G == let cs = set G in Object \<in> fst ` cs \<and> (\<forall>x. Xcpt x \<in> fst ` cs)" |
|
32 |
30 wf_fdecl :: "'c prog => fdecl => bool" |
33 wf_fdecl :: "'c prog => fdecl => bool" |
31 "wf_fdecl G == \<lambda>(fn,ft). is_type G ft" |
34 "wf_fdecl G == \<lambda>(fn,ft). is_type G ft" |
32 |
35 |
33 wf_mhead :: "'c prog => sig => ty => bool" |
36 wf_mhead :: "'c prog => sig => ty => bool" |
34 "wf_mhead G == \<lambda>(mn,pTs) rT. (\<forall>T\<in>set pTs. is_type G T) \<and> is_type G rT" |
37 "wf_mhead G == \<lambda>(mn,pTs) rT. (\<forall>T\<in>set pTs. is_type G T) \<and> is_type G rT" |
|
38 |
|
39 ws_cdecl :: "'c prog => 'c cdecl => bool" |
|
40 "ws_cdecl G == |
|
41 \<lambda>(C,(D,fs,ms)). |
|
42 (\<forall>f\<in>set fs. wf_fdecl G f) \<and> unique fs \<and> |
|
43 (\<forall>(sig,rT,mb)\<in>set ms. wf_mhead G sig rT) \<and> unique ms \<and> |
|
44 (C \<noteq> Object \<longrightarrow> is_class G D \<and> \<not>G\<turnstile>D\<preceq>C C)" |
|
45 |
|
46 ws_prog :: "'c prog => bool" |
|
47 "ws_prog G == |
|
48 wf_syscls G \<and> (\<forall>c\<in>set G. ws_cdecl G c) \<and> unique G" |
|
49 |
|
50 wf_mrT :: "'c prog => 'c cdecl => bool" |
|
51 "wf_mrT G == |
|
52 \<lambda>(C,(D,fs,ms)). |
|
53 (C \<noteq> Object \<longrightarrow> (\<forall>(sig,rT,b)\<in>set ms. \<forall>D' rT' b'. |
|
54 method(G,D) sig = Some(D',rT',b') --> G\<turnstile>rT\<preceq>rT'))" |
|
55 |
|
56 wf_cdecl_mdecl :: "'c wf_mb => 'c prog => 'c cdecl => bool" |
|
57 "wf_cdecl_mdecl wf_mb G == |
|
58 \<lambda>(C,(D,fs,ms)). (\<forall>m\<in>set ms. wf_mb G C m)" |
|
59 |
|
60 wf_prog :: "'c wf_mb => 'c prog => bool" |
|
61 "wf_prog wf_mb G == |
|
62 ws_prog G \<and> (\<forall>c\<in> set G. wf_mrT G c \<and> wf_cdecl_mdecl wf_mb G c)" |
35 |
63 |
36 wf_mdecl :: "'c wf_mb => 'c wf_mb" |
64 wf_mdecl :: "'c wf_mb => 'c wf_mb" |
37 "wf_mdecl wf_mb G C == \<lambda>(sig,rT,mb). wf_mhead G sig rT \<and> wf_mb G C (sig,rT,mb)" |
65 "wf_mdecl wf_mb G C == \<lambda>(sig,rT,mb). wf_mhead G sig rT \<and> wf_mb G C (sig,rT,mb)" |
38 |
66 |
39 wf_cdecl :: "'c wf_mb => 'c prog => 'c cdecl => bool" |
67 wf_cdecl :: "'c wf_mb => 'c prog => 'c cdecl => bool" |
43 (\<forall>m\<in>set ms. wf_mdecl wf_mb G C m) \<and> unique ms \<and> |
71 (\<forall>m\<in>set ms. wf_mdecl wf_mb G C m) \<and> unique ms \<and> |
44 (C \<noteq> Object \<longrightarrow> is_class G D \<and> \<not>G\<turnstile>D\<preceq>C C \<and> |
72 (C \<noteq> Object \<longrightarrow> is_class G D \<and> \<not>G\<turnstile>D\<preceq>C C \<and> |
45 (\<forall>(sig,rT,b)\<in>set ms. \<forall>D' rT' b'. |
73 (\<forall>(sig,rT,b)\<in>set ms. \<forall>D' rT' b'. |
46 method(G,D) sig = Some(D',rT',b') --> G\<turnstile>rT\<preceq>rT'))" |
74 method(G,D) sig = Some(D',rT',b') --> G\<turnstile>rT\<preceq>rT'))" |
47 |
75 |
48 wf_syscls :: "'c prog => bool" |
76 lemma wf_cdecl_mrT_cdecl_mdecl: |
49 "wf_syscls G == let cs = set G in Object \<in> fst ` cs \<and> (\<forall>x. Xcpt x \<in> fst ` cs)" |
77 "(wf_cdecl wf_mb G c) = (ws_cdecl G c \<and> wf_mrT G c \<and> wf_cdecl_mdecl wf_mb G c)" |
50 |
78 apply (rule iffI) |
51 wf_prog :: "'c wf_mb => 'c prog => bool" |
79 apply (simp add: wf_cdecl_def ws_cdecl_def wf_mrT_def wf_cdecl_mdecl_def |
52 "wf_prog wf_mb G == |
80 wf_mdecl_def wf_mhead_def split_beta)+ |
53 let cs = set G in wf_syscls G \<and> (\<forall>c\<in>cs. wf_cdecl wf_mb G c) \<and> unique G" |
81 done |
|
82 |
|
83 lemma wf_cdecl_ws_cdecl [intro]: "wf_cdecl wf_mb G cd \<Longrightarrow> ws_cdecl G cd" |
|
84 by (simp add: wf_cdecl_mrT_cdecl_mdecl) |
|
85 |
|
86 lemma wf_prog_ws_prog [intro]: "wf_prog wf_mb G \<Longrightarrow> ws_prog G" |
|
87 by (simp add: wf_prog_def ws_prog_def) |
|
88 |
|
89 lemma wf_prog_wf_mdecl: |
|
90 "\<lbrakk> wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; ((mn,pTs),rT,code) \<in> set mdecls\<rbrakk> |
|
91 \<Longrightarrow> wf_mdecl wf_mb G C ((mn,pTs),rT,code)" |
|
92 by (auto simp add: wf_prog_def ws_prog_def wf_mdecl_def |
|
93 wf_cdecl_mdecl_def ws_cdecl_def) |
54 |
94 |
55 lemma class_wf: |
95 lemma class_wf: |
56 "[|class G C = Some c; wf_prog wf_mb G|] ==> wf_cdecl wf_mb G (C,c)" |
96 "[|class G C = Some c; wf_prog wf_mb G|] |
57 apply (unfold wf_prog_def class_def) |
97 ==> wf_cdecl wf_mb G (C,c) \<and> wf_mrT G (C,c)" |
58 apply (simp) |
98 apply (unfold wf_prog_def ws_prog_def wf_cdecl_def class_def) |
|
99 apply clarify |
|
100 apply (drule_tac x="(C,c)" in bspec, fast dest: map_of_SomeD) |
|
101 apply (drule_tac x="(C,c)" in bspec, fast dest: map_of_SomeD) |
|
102 apply (simp add: wf_cdecl_def ws_cdecl_def wf_mdecl_def |
|
103 wf_cdecl_mdecl_def wf_mrT_def split_beta) |
|
104 done |
|
105 |
|
106 lemma class_wf_struct: |
|
107 "[|class G C = Some c; ws_prog G|] |
|
108 ==> ws_cdecl G (C,c)" |
|
109 apply (unfold ws_prog_def class_def) |
59 apply (fast dest: map_of_SomeD) |
110 apply (fast dest: map_of_SomeD) |
60 done |
111 done |
61 |
112 |
62 lemma class_Object [simp]: |
113 lemma class_Object [simp]: |
63 "wf_prog wf_mb G ==> \<exists>X fs ms. class G Object = Some (X,fs,ms)" |
114 "ws_prog G ==> \<exists>X fs ms. class G Object = Some (X,fs,ms)" |
64 apply (unfold wf_prog_def wf_syscls_def class_def) |
115 apply (unfold ws_prog_def wf_syscls_def class_def) |
65 apply (auto simp: map_of_SomeI) |
116 apply (auto simp: map_of_SomeI) |
66 done |
117 done |
67 |
118 |
68 lemma is_class_Object [simp]: "wf_prog wf_mb G ==> is_class G Object" |
119 lemma class_Object_syscls [simp]: |
|
120 "wf_syscls G ==> unique G \<Longrightarrow> \<exists>X fs ms. class G Object = Some (X,fs,ms)" |
|
121 apply (unfold wf_syscls_def class_def) |
|
122 apply (auto simp: map_of_SomeI) |
|
123 done |
|
124 |
|
125 lemma is_class_Object [simp]: "ws_prog G ==> is_class G Object" |
69 apply (unfold is_class_def) |
126 apply (unfold is_class_def) |
70 apply (simp (no_asm_simp)) |
127 apply (simp (no_asm_simp)) |
71 done |
128 done |
72 |
129 |
73 lemma is_class_xcpt [simp]: "wf_prog wf_mb G \<Longrightarrow> is_class G (Xcpt x)" |
130 lemma is_class_xcpt [simp]: "ws_prog G \<Longrightarrow> is_class G (Xcpt x)" |
74 apply (simp add: wf_prog_def wf_syscls_def) |
131 apply (simp add: ws_prog_def wf_syscls_def) |
75 apply (simp add: is_class_def class_def) |
132 apply (simp add: is_class_def class_def) |
76 apply clarify |
133 apply clarify |
77 apply (erule_tac x = x in allE) |
134 apply (erule_tac x = x in allE) |
78 apply clarify |
135 apply clarify |
79 apply (auto intro!: map_of_SomeI) |
136 apply (auto intro!: map_of_SomeI) |
80 done |
137 done |
81 |
138 |
82 lemma subcls1_wfD: "[|G\<turnstile>C\<prec>C1D; wf_prog wf_mb G|] ==> D \<noteq> C \<and> \<not>(D,C)\<in>(subcls1 G)^+" |
139 lemma subcls1_wfD: "[|G\<turnstile>C\<prec>C1D; ws_prog G|] ==> D \<noteq> C \<and> \<not>(D,C)\<in>(subcls1 G)^+" |
83 apply( frule r_into_trancl) |
140 apply( frule r_into_trancl) |
84 apply( drule subcls1D) |
141 apply( drule subcls1D) |
85 apply(clarify) |
142 apply(clarify) |
86 apply( drule (1) class_wf) |
143 apply( drule (1) class_wf_struct) |
87 apply( unfold wf_cdecl_def) |
144 apply( unfold ws_cdecl_def) |
88 apply(force simp add: reflcl_trancl [THEN sym] simp del: reflcl_trancl) |
145 apply(force simp add: reflcl_trancl [THEN sym] simp del: reflcl_trancl) |
89 done |
146 done |
90 |
147 |
91 lemma wf_cdecl_supD: |
148 lemma wf_cdecl_supD: |
92 "!!r. \<lbrakk>wf_cdecl wf_mb G (C,D,r); C \<noteq> Object\<rbrakk> \<Longrightarrow> is_class G D" |
149 "!!r. \<lbrakk>ws_cdecl G (C,D,r); C \<noteq> Object\<rbrakk> \<Longrightarrow> is_class G D" |
93 apply (unfold wf_cdecl_def) |
150 apply (unfold ws_cdecl_def) |
94 apply (auto split add: option.split_asm) |
151 apply (auto split add: option.split_asm) |
95 done |
152 done |
96 |
153 |
97 lemma subcls_asym: "[|wf_prog wf_mb G; (C,D)\<in>(subcls1 G)^+|] ==> \<not>(D,C)\<in>(subcls1 G)^+" |
154 lemma subcls_asym: "[|ws_prog G; (C,D)\<in>(subcls1 G)^+|] ==> \<not>(D,C)\<in>(subcls1 G)^+" |
98 apply(erule tranclE) |
155 apply(erule tranclE) |
99 apply(fast dest!: subcls1_wfD ) |
156 apply(fast dest!: subcls1_wfD ) |
100 apply(fast dest!: subcls1_wfD intro: trancl_trans) |
157 apply(fast dest!: subcls1_wfD intro: trancl_trans) |
101 done |
158 done |
102 |
159 |
103 lemma subcls_irrefl: "[|wf_prog wf_mb G; (C,D)\<in>(subcls1 G)^+|] ==> C \<noteq> D" |
160 lemma subcls_irrefl: "[|ws_prog G; (C,D)\<in>(subcls1 G)^+|] ==> C \<noteq> D" |
104 apply (erule trancl_trans_induct) |
161 apply (erule trancl_trans_induct) |
105 apply (auto dest: subcls1_wfD subcls_asym) |
162 apply (auto dest: subcls1_wfD subcls_asym) |
106 done |
163 done |
107 |
164 |
108 lemma acyclic_subcls1: "wf_prog wf_mb G ==> acyclic (subcls1 G)" |
165 lemma acyclic_subcls1: "ws_prog G ==> acyclic (subcls1 G)" |
109 apply (unfold acyclic_def) |
166 apply (unfold acyclic_def) |
110 apply (fast dest: subcls_irrefl) |
167 apply (fast dest: subcls_irrefl) |
111 done |
168 done |
112 |
169 |
113 lemma wf_subcls1: "wf_prog wf_mb G ==> wf ((subcls1 G)^-1)" |
170 lemma wf_subcls1: "ws_prog G ==> wf ((subcls1 G)^-1)" |
114 apply (rule finite_acyclic_wf) |
171 apply (rule finite_acyclic_wf) |
115 apply ( subst finite_converse) |
172 apply ( subst finite_converse) |
116 apply ( rule finite_subcls1) |
173 apply ( rule finite_subcls1) |
117 apply (subst acyclic_converse) |
174 apply (subst acyclic_converse) |
118 apply (erule acyclic_subcls1) |
175 apply (erule acyclic_subcls1) |
119 done |
176 done |
|
177 |
120 |
178 |
121 lemma subcls_induct: |
179 lemma subcls_induct: |
122 "[|wf_prog wf_mb G; !!C. \<forall>D. (C,D)\<in>(subcls1 G)^+ --> P D ==> P C|] ==> P C" |
180 "[|wf_prog wf_mb G; !!C. \<forall>D. (C,D)\<in>(subcls1 G)^+ --> P D ==> P C|] ==> P C" |
123 (is "?A \<Longrightarrow> PROP ?P \<Longrightarrow> _") |
181 (is "?A \<Longrightarrow> PROP ?P \<Longrightarrow> _") |
124 proof - |
182 proof - |
125 assume p: "PROP ?P" |
183 assume p: "PROP ?P" |
126 assume ?A thus ?thesis apply - |
184 assume ?A thus ?thesis apply - |
|
185 apply (drule wf_prog_ws_prog) |
127 apply(drule wf_subcls1) |
186 apply(drule wf_subcls1) |
128 apply(drule wf_trancl) |
187 apply(drule wf_trancl) |
129 apply(simp only: trancl_converse) |
188 apply(simp only: trancl_converse) |
130 apply(erule_tac a = C in wf_induct) |
189 apply(erule_tac a = C in wf_induct) |
131 apply(rule p) |
190 apply(rule p) |
153 apply( assumption) |
212 apply( assumption) |
154 apply( rule impI) |
213 apply( rule impI) |
155 apply( case_tac "C = Object") |
214 apply( case_tac "C = Object") |
156 apply( fast) |
215 apply( fast) |
157 apply safe |
216 apply safe |
158 apply( frule (1) class_wf) |
217 apply( frule (1) class_wf) apply (erule conjE)+ |
|
218 apply (frule wf_cdecl_ws_cdecl) |
159 apply( frule (1) wf_cdecl_supD) |
219 apply( frule (1) wf_cdecl_supD) |
160 |
220 |
161 apply( subgoal_tac "G\<turnstile>C\<prec>C1a") |
221 apply( subgoal_tac "G\<turnstile>C\<prec>C1a") |
162 apply( erule_tac [2] subcls1I) |
222 apply( erule_tac [2] subcls1I) |
163 apply( rule p) |
223 apply( rule p) |
164 apply (unfold is_class_def) |
224 apply (unfold is_class_def) |
165 apply auto |
225 apply auto |
166 done |
226 done |
167 qed |
227 qed |
168 |
228 |
|
229 lemma subcls_induct_struct: |
|
230 "[|ws_prog G; !!C. \<forall>D. (C,D)\<in>(subcls1 G)^+ --> P D ==> P C|] ==> P C" |
|
231 (is "?A \<Longrightarrow> PROP ?P \<Longrightarrow> _") |
|
232 proof - |
|
233 assume p: "PROP ?P" |
|
234 assume ?A thus ?thesis apply - |
|
235 apply(drule wf_subcls1) |
|
236 apply(drule wf_trancl) |
|
237 apply(simp only: trancl_converse) |
|
238 apply(erule_tac a = C in wf_induct) |
|
239 apply(rule p) |
|
240 apply(auto) |
|
241 done |
|
242 qed |
|
243 |
|
244 |
|
245 lemma subcls1_induct_struct: |
|
246 "[|is_class G C; ws_prog G; P Object; |
|
247 !!C D fs ms. [|C \<noteq> Object; is_class G C; class G C = Some (D,fs,ms) \<and> |
|
248 ws_cdecl G (C,D,fs,ms) \<and> G\<turnstile>C\<prec>C1D \<and> is_class G D \<and> P D|] ==> P C |
|
249 |] ==> P C" |
|
250 (is "?A \<Longrightarrow> ?B \<Longrightarrow> ?C \<Longrightarrow> PROP ?P \<Longrightarrow> _") |
|
251 proof - |
|
252 assume p: "PROP ?P" |
|
253 assume ?A ?B ?C thus ?thesis apply - |
|
254 apply(unfold is_class_def) |
|
255 apply( rule impE) |
|
256 prefer 2 |
|
257 apply( assumption) |
|
258 prefer 2 |
|
259 apply( assumption) |
|
260 apply( erule thin_rl) |
|
261 apply( rule subcls_induct_struct) |
|
262 apply( assumption) |
|
263 apply( rule impI) |
|
264 apply( case_tac "C = Object") |
|
265 apply( fast) |
|
266 apply safe |
|
267 apply( frule (1) class_wf_struct) |
|
268 apply( frule (1) wf_cdecl_supD) |
|
269 |
|
270 apply( subgoal_tac "G\<turnstile>C\<prec>C1a") |
|
271 apply( erule_tac [2] subcls1I) |
|
272 apply( rule p) |
|
273 apply (unfold is_class_def) |
|
274 apply auto |
|
275 done |
|
276 qed |
|
277 |
169 lemmas method_rec = wf_subcls1 [THEN [2] method_rec_lemma]; |
278 lemmas method_rec = wf_subcls1 [THEN [2] method_rec_lemma]; |
170 |
279 |
171 lemmas fields_rec = wf_subcls1 [THEN [2] fields_rec_lemma]; |
280 lemmas fields_rec = wf_subcls1 [THEN [2] fields_rec_lemma]; |
172 |
281 |
173 lemma field_rec: "\<lbrakk>class G C = Some (D, fs, ms); wf_prog wf_mb G\<rbrakk> |
282 lemma field_rec: "\<lbrakk>class G C = Some (D, fs, ms); ws_prog G\<rbrakk> |
174 \<Longrightarrow> field (G, C) = |
283 \<Longrightarrow> field (G, C) = |
175 (if C = Object then empty else field (G, D)) ++ |
284 (if C = Object then empty else field (G, D)) ++ |
176 map_of (map (\<lambda>(s, f). (s, C, f)) fs)" |
285 map_of (map (\<lambda>(s, f). (s, C, f)) fs)" |
177 apply (simp only: field_def) |
286 apply (simp only: field_def) |
178 apply (frule fields_rec, assumption) |
287 apply (frule fields_rec, assumption) |
181 apply (simp (no_asm_use) |
290 apply (simp (no_asm_use) |
182 add: split_beta split_def o_def map_compose [THEN sym] del: map_compose) |
291 add: split_beta split_def o_def map_compose [THEN sym] del: map_compose) |
183 done |
292 done |
184 |
293 |
185 lemma method_Object [simp]: |
294 lemma method_Object [simp]: |
186 "method (G, Object) sig = Some (D, mh, code) \<Longrightarrow> wf_prog wf_mb G \<Longrightarrow> D = Object" |
295 "method (G, Object) sig = Some (D, mh, code) \<Longrightarrow> ws_prog G \<Longrightarrow> D = Object" |
187 apply (frule class_Object, clarify) |
296 apply (frule class_Object, clarify) |
188 apply (drule method_rec, assumption) |
297 apply (drule method_rec, assumption) |
189 apply (auto dest: map_of_SomeD) |
298 apply (auto dest: map_of_SomeD) |
190 done |
299 done |
191 |
300 |
192 |
301 |
193 lemma fields_Object [simp]: "\<lbrakk> ((vn, C), T) \<in> set (fields (G, Object)); wf_prog wf_mb G \<rbrakk> |
302 lemma fields_Object [simp]: "\<lbrakk> ((vn, C), T) \<in> set (fields (G, Object)); ws_prog G \<rbrakk> |
194 \<Longrightarrow> C = Object" |
303 \<Longrightarrow> C = Object" |
195 apply (frule class_Object) |
304 apply (frule class_Object) |
196 apply clarify |
305 apply clarify |
197 apply (subgoal_tac "fields (G, Object) = map (\<lambda>(fn,ft). ((fn,Object),ft)) fs") |
306 apply (subgoal_tac "fields (G, Object) = map (\<lambda>(fn,ft). ((fn,Object),ft)) fs") |
198 apply (simp add: image_iff split_beta) |
307 apply (simp add: image_iff split_beta) |
236 apply( erule r_into_rtrancl [THEN rtrancl_trans]) |
345 apply( erule r_into_rtrancl [THEN rtrancl_trans]) |
237 apply auto |
346 apply auto |
238 done |
347 done |
239 |
348 |
240 lemma widen_fields_defpl: |
349 lemma widen_fields_defpl: |
241 "[|((fn,fd),fT) \<in> set (fields (G,C)); wf_prog wf_mb G; is_class G C|] ==> |
350 "[|((fn,fd),fT) \<in> set (fields (G,C)); ws_prog G; is_class G C|] ==> |
242 G\<turnstile>C\<preceq>C fd" |
351 G\<turnstile>C\<preceq>C fd" |
243 apply( drule (1) widen_fields_defpl') |
352 apply( drule (1) widen_fields_defpl') |
244 apply (fast) |
353 apply (fast) |
245 done |
354 done |
246 |
355 |
247 lemma unique_fields: |
356 lemma unique_fields: |
248 "[|is_class G C; wf_prog wf_mb G|] ==> unique (fields (G,C))" |
357 "[|is_class G C; ws_prog G|] ==> unique (fields (G,C))" |
249 apply( erule subcls1_induct) |
358 apply( erule subcls1_induct_struct) |
250 apply( assumption) |
359 apply( assumption) |
251 apply( frule class_Object) |
360 apply( frule class_Object) |
252 apply( clarify) |
361 apply( clarify) |
253 apply( frule fields_rec, assumption) |
362 apply( frule fields_rec, assumption) |
254 apply( drule class_wf, assumption) |
363 apply( drule class_wf_struct, assumption) |
255 apply( simp add: wf_cdecl_def) |
364 apply( simp add: ws_cdecl_def) |
256 apply( rule unique_map_inj) |
365 apply( rule unique_map_inj) |
257 apply( simp) |
366 apply( simp) |
258 apply( rule inj_onI) |
367 apply( rule inj_onI) |
259 apply( simp) |
368 apply( simp) |
260 apply( safe dest!: wf_cdecl_supD) |
369 apply( safe dest!: wf_cdecl_supD) |
261 apply( drule subcls1_wfD) |
370 apply( drule subcls1_wfD) |
262 apply( assumption) |
371 apply( assumption) |
263 apply( subst fields_rec) |
372 apply( subst fields_rec) |
264 apply auto |
373 apply auto |
265 apply( rotate_tac -1) |
374 apply( rotate_tac -1) |
266 apply( frule class_wf) |
375 apply( frule class_wf_struct) |
267 apply auto |
376 apply auto |
268 apply( simp add: wf_cdecl_def) |
377 apply( simp add: ws_cdecl_def) |
269 apply( erule unique_append) |
378 apply( erule unique_append) |
270 apply( rule unique_map_inj) |
379 apply( rule unique_map_inj) |
271 apply( clarsimp) |
380 apply( clarsimp) |
272 apply (rule inj_onI) |
381 apply (rule inj_onI) |
273 apply( simp) |
382 apply( simp) |
274 apply(auto dest!: widen_fields_defpl) |
383 apply(auto dest!: widen_fields_defpl) |
275 done |
384 done |
276 |
385 |
277 lemma fields_mono_lemma [rule_format (no_asm)]: |
386 lemma fields_mono_lemma [rule_format (no_asm)]: |
278 "[|wf_prog wf_mb G; (C',C)\<in>(subcls1 G)^*|] ==> |
387 "[|ws_prog G; (C',C)\<in>(subcls1 G)^*|] ==> |
279 x \<in> set (fields (G,C)) --> x \<in> set (fields (G,C'))" |
388 x \<in> set (fields (G,C)) --> x \<in> set (fields (G,C'))" |
280 apply(erule converse_rtrancl_induct) |
389 apply(erule converse_rtrancl_induct) |
281 apply( safe dest!: subcls1D) |
390 apply( safe dest!: subcls1D) |
282 apply(subst fields_rec) |
391 apply(subst fields_rec) |
283 apply( auto) |
392 apply( auto) |
284 done |
393 done |
285 |
394 |
286 lemma fields_mono: |
395 lemma fields_mono: |
287 "\<lbrakk>map_of (fields (G,C)) fn = Some f; G\<turnstile>D\<preceq>C C; is_class G D; wf_prog wf_mb G\<rbrakk> |
396 "\<lbrakk>map_of (fields (G,C)) fn = Some f; G\<turnstile>D\<preceq>C C; is_class G D; ws_prog G\<rbrakk> |
288 \<Longrightarrow> map_of (fields (G,D)) fn = Some f" |
397 \<Longrightarrow> map_of (fields (G,D)) fn = Some f" |
289 apply (rule map_of_SomeI) |
398 apply (rule map_of_SomeI) |
290 apply (erule (1) unique_fields) |
399 apply (erule (1) unique_fields) |
291 apply (erule (1) fields_mono_lemma) |
400 apply (erule (1) fields_mono_lemma) |
292 apply (erule map_of_SomeD) |
401 apply (erule map_of_SomeD) |
293 done |
402 done |
294 |
403 |
295 lemma widen_cfs_fields: |
404 lemma widen_cfs_fields: |
296 "[|field (G,C) fn = Some (fd, fT); G\<turnstile>D\<preceq>C C; wf_prog wf_mb G|]==> |
405 "[|field (G,C) fn = Some (fd, fT); G\<turnstile>D\<preceq>C C; ws_prog G|]==> |
297 map_of (fields (G,D)) (fn, fd) = Some fT" |
406 map_of (fields (G,D)) (fn, fd) = Some fT" |
298 apply (drule field_fields) |
407 apply (drule field_fields) |
299 apply (drule rtranclD) |
408 apply (drule rtranclD) |
300 apply safe |
409 apply safe |
301 apply (frule subcls_is_class) |
410 apply (frule subcls_is_class) |
305 |
414 |
306 lemma method_wf_mdecl [rule_format (no_asm)]: |
415 lemma method_wf_mdecl [rule_format (no_asm)]: |
307 "wf_prog wf_mb G ==> is_class G C \<Longrightarrow> |
416 "wf_prog wf_mb G ==> is_class G C \<Longrightarrow> |
308 method (G,C) sig = Some (md,mh,m) |
417 method (G,C) sig = Some (md,mh,m) |
309 --> G\<turnstile>C\<preceq>C md \<and> wf_mdecl wf_mb G md (sig,(mh,m))" |
418 --> G\<turnstile>C\<preceq>C md \<and> wf_mdecl wf_mb G md (sig,(mh,m))" |
|
419 apply (frule wf_prog_ws_prog) |
310 apply( erule subcls1_induct) |
420 apply( erule subcls1_induct) |
311 apply( assumption) |
421 apply( assumption) |
312 apply( clarify) |
422 apply( clarify) |
313 apply( frule class_Object) |
423 apply( frule class_Object) |
314 apply( clarify) |
424 apply( clarify) |
315 apply( frule method_rec, assumption) |
425 apply( frule method_rec, assumption) |
316 apply( drule class_wf, assumption) |
426 apply( drule class_wf, assumption) |
317 apply( simp add: wf_cdecl_def) |
427 apply( simp add: wf_cdecl_def) |
318 apply( drule map_of_SomeD) |
428 apply( drule map_of_SomeD) |
319 apply( subgoal_tac "md = Object") |
429 apply( subgoal_tac "md = Object") |
320 apply( fastsimp) |
430 apply( fastsimp) |
321 apply( fastsimp) |
431 apply( fastsimp) |
322 apply( clarify) |
432 apply( clarify) |
323 apply( frule_tac C = C in method_rec) |
433 apply( frule_tac C = C in method_rec) |
324 apply( assumption) |
434 apply( assumption) |
325 apply( rotate_tac -1) |
435 apply( rotate_tac -1) |
336 apply( rule r_into_rtrancl) |
446 apply( rule r_into_rtrancl) |
337 apply( fast intro: subcls1I) |
447 apply( fast intro: subcls1I) |
338 done |
448 done |
339 |
449 |
340 |
450 |
341 lemma wf_prog_wf_mhead: "\<lbrakk> wf_prog wf_mb G; (C, D, fds, mths) \<in> set G; |
451 lemma method_wf_mhead [rule_format (no_asm)]: |
342 ((mn, pTs), rT, jmb) \<in> set mths \<rbrakk> |
452 "ws_prog G ==> is_class G C \<Longrightarrow> |
343 \<Longrightarrow> wf_mhead G (mn, pTs) rT" |
453 method (G,C) sig = Some (md,rT,mb) |
344 apply (simp add: wf_prog_def wf_cdecl_def) |
454 --> G\<turnstile>C\<preceq>C md \<and> wf_mhead G sig rT" |
345 apply (erule conjE)+ |
455 apply( erule subcls1_induct_struct) |
346 apply (drule bspec, assumption) |
456 apply( assumption) |
347 apply simp |
457 apply( clarify) |
348 apply (erule conjE)+ |
458 apply( frule class_Object) |
349 apply (drule bspec, assumption) |
459 apply( clarify) |
350 apply (simp add: wf_mdecl_def) |
460 apply( frule method_rec, assumption) |
|
461 apply( drule class_wf_struct, assumption) |
|
462 apply( simp add: ws_cdecl_def) |
|
463 apply( drule map_of_SomeD) |
|
464 apply( subgoal_tac "md = Object") |
|
465 apply( fastsimp) |
|
466 apply( fastsimp) |
|
467 apply( clarify) |
|
468 apply( frule_tac C = C in method_rec) |
|
469 apply( assumption) |
|
470 apply( rotate_tac -1) |
|
471 apply( simp) |
|
472 apply( drule map_add_SomeD) |
|
473 apply( erule disjE) |
|
474 apply( erule_tac V = "?P --> ?Q" in thin_rl) |
|
475 apply (frule map_of_SomeD) |
|
476 apply (clarsimp simp add: ws_cdecl_def) |
|
477 apply blast |
|
478 apply clarify |
|
479 apply( rule rtrancl_trans) |
|
480 prefer 2 |
|
481 apply( assumption) |
|
482 apply( rule r_into_rtrancl) |
|
483 apply( fast intro: subcls1I) |
351 done |
484 done |
352 |
485 |
353 lemma subcls_widen_methd [rule_format (no_asm)]: |
486 lemma subcls_widen_methd [rule_format (no_asm)]: |
354 "[|G\<turnstile>T\<preceq>C T'; wf_prog wf_mb G|] ==> |
487 "[|G\<turnstile>T'\<preceq>C T; wf_prog wf_mb G|] ==> |
355 \<forall>D rT b. method (G,T') sig = Some (D,rT ,b) --> |
488 \<forall>D rT b. method (G,T) sig = Some (D,rT ,b) --> |
356 (\<exists>D' rT' b'. method (G,T) sig = Some (D',rT',b') \<and> G\<turnstile>rT'\<preceq>rT)" |
489 (\<exists>D' rT' b'. method (G,T') sig = Some (D',rT',b') \<and> G\<turnstile>D'\<preceq>C D \<and> G\<turnstile>rT'\<preceq>rT)" |
357 apply( drule rtranclD) |
490 apply( drule rtranclD) |
358 apply( erule disjE) |
491 apply( erule disjE) |
359 apply( fast) |
492 apply( fast) |
360 apply( erule conjE) |
493 apply( erule conjE) |
361 apply( erule trancl_trans_induct) |
494 apply( erule trancl_trans_induct) |
362 prefer 2 |
495 prefer 2 |
363 apply( clarify) |
496 apply( clarify) |
364 apply( drule spec, drule spec, drule spec, erule (1) impE) |
497 apply( drule spec, drule spec, drule spec, erule (1) impE) |
365 apply( fast elim: widen_trans) |
498 apply( fast elim: widen_trans rtrancl_trans) |
366 apply( clarify) |
499 apply( clarify) |
367 apply( drule subcls1D) |
500 apply( drule subcls1D) |
368 apply( clarify) |
501 apply( clarify) |
369 apply( subst method_rec) |
502 apply( subst method_rec) |
370 apply( assumption) |
503 apply( assumption) |
371 apply( unfold map_add_def) |
504 apply( unfold map_add_def) |
372 apply( simp (no_asm_simp) del: split_paired_Ex) |
505 apply( simp (no_asm_simp) add: wf_prog_ws_prog del: split_paired_Ex) |
373 apply( case_tac "\<exists>z. map_of(map (\<lambda>(s,m). (s, ?C, m)) ms) sig = Some z") |
506 apply( case_tac "\<exists>z. map_of(map (\<lambda>(s,m). (s, ?C, m)) ms) sig = Some z") |
374 apply( erule exE) |
507 apply( erule exE) |
375 apply( rotate_tac -1, frule ssubst, erule_tac [2] asm_rl) |
508 apply( rotate_tac -1, frule ssubst, erule_tac [2] asm_rl) |
376 prefer 2 |
509 prefer 2 |
377 apply( rotate_tac -1, frule ssubst, erule_tac [2] asm_rl) |
510 apply( rotate_tac -1, frule ssubst, erule_tac [2] asm_rl) |
378 apply( tactic "asm_full_simp_tac (HOL_ss addsimps [not_None_eq RS sym]) 1") |
511 apply( tactic "asm_full_simp_tac (HOL_ss addsimps [not_None_eq RS sym]) 1") |
379 apply( simp_all (no_asm_simp) del: split_paired_Ex) |
512 apply( simp_all (no_asm_simp) del: split_paired_Ex) |
380 apply( drule (1) class_wf) |
513 apply( frule (1) class_wf) |
381 apply( simp (no_asm_simp) only: split_tupled_all) |
514 apply( simp (no_asm_simp) only: split_tupled_all) |
382 apply( unfold wf_cdecl_def) |
515 apply( unfold wf_cdecl_def) |
383 apply( drule map_of_SomeD) |
516 apply( drule map_of_SomeD) |
384 apply auto |
517 apply (auto simp add: wf_mrT_def) |
385 done |
518 apply (rule rtrancl_trans) |
|
519 defer |
|
520 apply (rule method_wf_mhead [THEN conjunct1]) |
|
521 apply (simp only: wf_prog_def) |
|
522 apply (simp add: is_class_def) |
|
523 apply assumption |
|
524 apply (auto intro: subcls1I) |
|
525 done |
|
526 |
386 |
527 |
387 lemma subtype_widen_methd: |
528 lemma subtype_widen_methd: |
388 "[| G\<turnstile> C\<preceq>C D; wf_prog wf_mb G; |
529 "[| G\<turnstile> C\<preceq>C D; wf_prog wf_mb G; |
389 method (G,D) sig = Some (md, rT, b) |] |
530 method (G,D) sig = Some (md, rT, b) |] |
390 ==> \<exists>mD' rT' b'. method (G,C) sig= Some(mD',rT',b') \<and> G\<turnstile>rT'\<preceq>rT" |
531 ==> \<exists>mD' rT' b'. method (G,C) sig= Some(mD',rT',b') \<and> G\<turnstile>rT'\<preceq>rT" |
391 apply(auto dest: subcls_widen_methd method_wf_mdecl |
532 apply(auto dest: subcls_widen_methd |
392 simp add: wf_mdecl_def wf_mhead_def split_def) |
533 simp add: wf_mdecl_def wf_mhead_def split_def) |
393 done |
534 done |
394 |
535 |
|
536 |
395 lemma method_in_md [rule_format (no_asm)]: |
537 lemma method_in_md [rule_format (no_asm)]: |
396 "wf_prog wf_mb G ==> is_class G C \<Longrightarrow> \<forall>D. method (G,C) sig = Some(D,mh,code) |
538 "ws_prog G ==> is_class G C \<Longrightarrow> \<forall>D. method (G,C) sig = Some(D,mh,code) |
397 --> is_class G D \<and> method (G,D) sig = Some(D,mh,code)" |
539 --> is_class G D \<and> method (G,D) sig = Some(D,mh,code)" |
398 apply (erule (1) subcls1_induct) |
540 apply (erule (1) subcls1_induct_struct) |
399 apply clarify |
541 apply clarify |
400 apply (frule method_Object, assumption) |
542 apply (frule method_Object, assumption) |
401 apply hypsubst |
543 apply hypsubst |
402 apply simp |
544 apply simp |
403 apply (erule conjE) |
545 apply (erule conjE) |
414 apply (assumption) |
556 apply (assumption) |
415 apply (simp add: map_add_def map_of_map split add: option.split) |
557 apply (simp add: map_add_def map_of_map split add: option.split) |
416 done |
558 done |
417 |
559 |
418 |
560 |
|
561 lemma method_in_md_struct [rule_format (no_asm)]: |
|
562 "ws_prog G ==> is_class G C \<Longrightarrow> \<forall>D. method (G,C) sig = Some(D,mh,code) |
|
563 --> is_class G D \<and> method (G,D) sig = Some(D,mh,code)" |
|
564 apply (erule (1) subcls1_induct_struct) |
|
565 apply clarify |
|
566 apply (frule method_Object, assumption) |
|
567 apply hypsubst |
|
568 apply simp |
|
569 apply (erule conjE) |
|
570 apply (subst method_rec) |
|
571 apply (assumption) |
|
572 apply (assumption) |
|
573 apply (clarify) |
|
574 apply (erule_tac "x" = "Da" in allE) |
|
575 apply (clarsimp) |
|
576 apply (simp add: map_of_map) |
|
577 apply (clarify) |
|
578 apply (subst method_rec) |
|
579 apply (assumption) |
|
580 apply (assumption) |
|
581 apply (simp add: map_add_def map_of_map split add: option.split) |
|
582 done |
|
583 |
419 lemma fields_in_fd [rule_format (no_asm)]: "\<lbrakk> wf_prog wf_mb G; is_class G C\<rbrakk> |
584 lemma fields_in_fd [rule_format (no_asm)]: "\<lbrakk> wf_prog wf_mb G; is_class G C\<rbrakk> |
420 \<Longrightarrow> \<forall> vn D T. (((vn,D),T) \<in> set (fields (G,C)) |
585 \<Longrightarrow> \<forall> vn D T. (((vn,D),T) \<in> set (fields (G,C)) |
421 \<longrightarrow> (is_class G D \<and> ((vn,D),T) \<in> set (fields (G,D))))" |
586 \<longrightarrow> (is_class G D \<and> ((vn,D),T) \<in> set (fields (G,D))))" |
422 apply (erule (1) subcls1_induct) |
587 apply (erule (1) subcls1_induct) |
423 |
588 |
424 apply clarify |
589 apply clarify |
|
590 apply (frule wf_prog_ws_prog) |
425 apply (frule fields_Object, assumption+) |
591 apply (frule fields_Object, assumption+) |
426 apply (simp only: is_class_Object) apply simp |
592 apply (simp only: is_class_Object) apply simp |
427 |
593 |
428 apply clarify |
594 apply clarify |
429 apply (frule fields_rec) |
595 apply (frule fields_rec) |
430 apply assumption |
596 apply (simp (no_asm_simp) add: wf_prog_ws_prog) |
431 |
597 |
432 apply (case_tac "Da=C") |
598 apply (case_tac "Da=C") |
433 apply blast (* case Da=C *) |
599 apply blast (* case Da=C *) |
434 |
600 |
435 apply (subgoal_tac "((vn, Da), T) \<in> set (fields (G, D))") apply blast |
601 apply (subgoal_tac "((vn, Da), T) \<in> set (fields (G, D))") apply blast |
493 apply( unfold wf_mdecl_def) |
662 apply( unfold wf_mdecl_def) |
494 apply( unfold is_class_def) |
663 apply( unfold is_class_def) |
495 apply auto |
664 apply auto |
496 done |
665 done |
497 |
666 |
498 |
|
499 lemma fields_is_type_lemma [rule_format (no_asm)]: |
667 lemma fields_is_type_lemma [rule_format (no_asm)]: |
500 "[|is_class G C; wf_prog wf_mb G|] ==> |
668 "[|is_class G C; ws_prog G|] ==> |
501 \<forall>f\<in>set (fields (G,C)). is_type G (snd f)" |
669 \<forall>f\<in>set (fields (G,C)). is_type G (snd f)" |
502 apply( erule (1) subcls1_induct) |
670 apply( erule (1) subcls1_induct_struct) |
503 apply( frule class_Object) |
671 apply( frule class_Object) |
504 apply( clarify) |
672 apply( clarify) |
505 apply( frule fields_rec, assumption) |
673 apply( frule fields_rec, assumption) |
506 apply( drule class_wf, assumption) |
674 apply( drule class_wf_struct, assumption) |
507 apply( simp add: wf_cdecl_def wf_fdecl_def) |
675 apply( simp add: ws_cdecl_def wf_fdecl_def) |
508 apply( fastsimp) |
676 apply( fastsimp) |
509 apply( subst fields_rec) |
677 apply( subst fields_rec) |
510 apply( fast) |
678 apply( fast) |
511 apply( assumption) |
679 apply( assumption) |
512 apply( clarsimp) |
680 apply( clarsimp) |
513 apply( safe) |
681 apply( safe) |
514 prefer 2 |
682 prefer 2 |
515 apply( force) |
683 apply( force) |
516 apply( drule (1) class_wf) |
684 apply( drule (1) class_wf_struct) |
517 apply( unfold wf_cdecl_def) |
685 apply( unfold ws_cdecl_def) |
518 apply( clarsimp) |
686 apply( clarsimp) |
519 apply( drule (1) bspec) |
687 apply( drule (1) bspec) |
520 apply( unfold wf_fdecl_def) |
688 apply( unfold wf_fdecl_def) |
521 apply auto |
689 apply auto |
522 done |
690 done |
523 |
691 |
|
692 |
524 lemma fields_is_type: |
693 lemma fields_is_type: |
525 "[|map_of (fields (G,C)) fn = Some f; wf_prog wf_mb G; is_class G C|] ==> |
694 "[|map_of (fields (G,C)) fn = Some f; ws_prog G; is_class G C|] ==> |
526 is_type G f" |
695 is_type G f" |
527 apply(drule map_of_SomeD) |
696 apply(drule map_of_SomeD) |
528 apply(drule (2) fields_is_type_lemma) |
697 apply(drule (2) fields_is_type_lemma) |
529 apply(auto) |
698 apply(auto) |
530 done |
699 done |
531 |
700 |
|
701 |
|
702 lemma field_is_type: "\<lbrakk> ws_prog G; is_class G C; field (G, C) fn = Some (fd, fT) \<rbrakk> |
|
703 \<Longrightarrow> is_type G fT" |
|
704 apply (frule_tac f="((fn, fd), fT)" in fields_is_type_lemma) |
|
705 apply (auto simp add: field_def dest: map_of_SomeD) |
|
706 done |
|
707 |
|
708 |
532 lemma methd: |
709 lemma methd: |
533 "[| wf_prog wf_mb G; (C,S,fs,mdecls) \<in> set G; (sig,rT,code) \<in> set mdecls |] |
710 "[| ws_prog G; (C,S,fs,mdecls) \<in> set G; (sig,rT,code) \<in> set mdecls |] |
534 ==> method (G,C) sig = Some(C,rT,code) \<and> is_class G C" |
711 ==> method (G,C) sig = Some(C,rT,code) \<and> is_class G C" |
535 proof - |
712 proof - |
536 assume wf: "wf_prog wf_mb G" and C: "(C,S,fs,mdecls) \<in> set G" and |
713 assume wf: "ws_prog G" and C: "(C,S,fs,mdecls) \<in> set G" and |
537 m: "(sig,rT,code) \<in> set mdecls" |
714 m: "(sig,rT,code) \<in> set mdecls" |
538 moreover |
715 moreover |
539 from wf C have "class G C = Some (S,fs,mdecls)" |
716 from wf C have "class G C = Some (S,fs,mdecls)" |
540 by (auto simp add: wf_prog_def class_def is_class_def intro: map_of_SomeI) |
717 by (auto simp add: ws_prog_def class_def is_class_def intro: map_of_SomeI) |
541 moreover |
718 moreover |
542 from wf C |
719 from wf C |
543 have "unique mdecls" by (unfold wf_prog_def wf_cdecl_def) auto |
720 have "unique mdecls" by (unfold ws_prog_def ws_cdecl_def) auto |
544 hence "unique (map (\<lambda>(s,m). (s,C,m)) mdecls)" by (induct mdecls, auto) |
721 hence "unique (map (\<lambda>(s,m). (s,C,m)) mdecls)" by (induct mdecls, auto) |
545 with m |
722 with m |
546 have "map_of (map (\<lambda>(s,m). (s,C,m)) mdecls) sig = Some (C,rT,code)" |
723 have "map_of (map (\<lambda>(s,m). (s,C,m)) mdecls) sig = Some (C,rT,code)" |
547 by (force intro: map_of_SomeI) |
724 by (force intro: map_of_SomeI) |
548 ultimately |
725 ultimately |