138 |
138 |
139 abbreviation (input) |
139 abbreviation (input) |
140 lst_inj_vals ("\<lfloor>_\<rfloor>\<^sub>l" 1000) |
140 lst_inj_vals ("\<lfloor>_\<rfloor>\<^sub>l" 1000) |
141 where "\<lfloor>es\<rfloor>\<^sub>l == In3 es" |
141 where "\<lfloor>es\<rfloor>\<^sub>l == In3 es" |
142 |
142 |
143 constdefs |
143 definition undefined3 :: "('al + 'ar, 'b, 'c) sum3 \<Rightarrow> vals" where |
144 undefined3 :: "('al + 'ar, 'b, 'c) sum3 \<Rightarrow> vals" |
|
145 "undefined3 \<equiv> sum3_case (In1 \<circ> sum_case (\<lambda>x. undefined) (\<lambda>x. Unit)) |
144 "undefined3 \<equiv> sum3_case (In1 \<circ> sum_case (\<lambda>x. undefined) (\<lambda>x. Unit)) |
146 (\<lambda>x. In2 undefined) (\<lambda>x. In3 undefined)" |
145 (\<lambda>x. In2 undefined) (\<lambda>x. In3 undefined)" |
147 |
146 |
148 lemma [simp]: "undefined3 (In1l x) = In1 undefined" |
147 lemma [simp]: "undefined3 (In1l x) = In1 undefined" |
149 by (simp add: undefined3_def) |
148 by (simp add: undefined3_def) |
158 by (simp add: undefined3_def) |
157 by (simp add: undefined3_def) |
159 |
158 |
160 |
159 |
161 section "exception throwing and catching" |
160 section "exception throwing and catching" |
162 |
161 |
163 constdefs |
162 definition throw :: "val \<Rightarrow> abopt \<Rightarrow> abopt" where |
164 throw :: "val \<Rightarrow> abopt \<Rightarrow> abopt" |
|
165 "throw a' x \<equiv> abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" |
163 "throw a' x \<equiv> abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" |
166 |
164 |
167 lemma throw_def2: |
165 lemma throw_def2: |
168 "throw a' x = abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" |
166 "throw a' x = abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" |
169 apply (unfold throw_def) |
167 apply (unfold throw_def) |
170 apply (simp (no_asm)) |
168 apply (simp (no_asm)) |
171 done |
169 done |
172 |
170 |
173 constdefs |
171 definition fits :: "prog \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ty \<Rightarrow> bool" ("_,_\<turnstile>_ fits _"[61,61,61,61]60) where |
174 fits :: "prog \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ty \<Rightarrow> bool" ("_,_\<turnstile>_ fits _"[61,61,61,61]60) |
|
175 "G,s\<turnstile>a' fits T \<equiv> (\<exists>rt. T=RefT rt) \<longrightarrow> a'=Null \<or> G\<turnstile>obj_ty(lookup_obj s a')\<preceq>T" |
172 "G,s\<turnstile>a' fits T \<equiv> (\<exists>rt. T=RefT rt) \<longrightarrow> a'=Null \<or> G\<turnstile>obj_ty(lookup_obj s a')\<preceq>T" |
176 |
173 |
177 lemma fits_Null [simp]: "G,s\<turnstile>Null fits T" |
174 lemma fits_Null [simp]: "G,s\<turnstile>Null fits T" |
178 by (simp add: fits_def) |
175 by (simp add: fits_def) |
179 |
176 |
193 apply (case_tac "a' = Null") |
190 apply (case_tac "a' = Null") |
194 apply simp_all |
191 apply simp_all |
195 apply iprover |
192 apply iprover |
196 done |
193 done |
197 |
194 |
198 constdefs |
195 definition catch :: "prog \<Rightarrow> state \<Rightarrow> qtname \<Rightarrow> bool" ("_,_\<turnstile>catch _"[61,61,61]60) where |
199 catch ::"prog \<Rightarrow> state \<Rightarrow> qtname \<Rightarrow> bool" ("_,_\<turnstile>catch _"[61,61,61]60) |
|
200 "G,s\<turnstile>catch C\<equiv>\<exists>xc. abrupt s=Some (Xcpt xc) \<and> |
196 "G,s\<turnstile>catch C\<equiv>\<exists>xc. abrupt s=Some (Xcpt xc) \<and> |
201 G,store s\<turnstile>Addr (the_Loc xc) fits Class C" |
197 G,store s\<turnstile>Addr (the_Loc xc) fits Class C" |
202 |
198 |
203 lemma catch_Norm [simp]: "\<not>G,Norm s\<turnstile>catch tn" |
199 lemma catch_Norm [simp]: "\<not>G,Norm s\<turnstile>catch tn" |
204 apply (unfold catch_def) |
200 apply (unfold catch_def) |
219 lemma catch_Error [simp]: "\<not>G,(Some (Error e),s)\<turnstile>catch tn" |
215 lemma catch_Error [simp]: "\<not>G,(Some (Error e),s)\<turnstile>catch tn" |
220 apply (unfold catch_def) |
216 apply (unfold catch_def) |
221 apply (simp (no_asm)) |
217 apply (simp (no_asm)) |
222 done |
218 done |
223 |
219 |
224 constdefs |
220 definition new_xcpt_var :: "vname \<Rightarrow> state \<Rightarrow> state" where |
225 new_xcpt_var :: "vname \<Rightarrow> state \<Rightarrow> state" |
|
226 "new_xcpt_var vn \<equiv> |
221 "new_xcpt_var vn \<equiv> |
227 \<lambda>(x,s). Norm (lupd(VName vn\<mapsto>Addr (the_Loc (the_Xcpt (the x)))) s)" |
222 \<lambda>(x,s). Norm (lupd(VName vn\<mapsto>Addr (the_Loc (the_Xcpt (the x)))) s)" |
228 |
223 |
229 lemma new_xcpt_var_def2 [simp]: |
224 lemma new_xcpt_var_def2 [simp]: |
230 "new_xcpt_var vn (x,s) = |
225 "new_xcpt_var vn (x,s) = |
235 |
230 |
236 |
231 |
237 |
232 |
238 section "misc" |
233 section "misc" |
239 |
234 |
240 constdefs |
235 definition assign :: "('a \<Rightarrow> state \<Rightarrow> state) \<Rightarrow> 'a \<Rightarrow> state \<Rightarrow> state" where |
241 |
|
242 assign :: "('a \<Rightarrow> state \<Rightarrow> state) \<Rightarrow> 'a \<Rightarrow> state \<Rightarrow> state" |
|
243 "assign f v \<equiv> \<lambda>(x,s). let (x',s') = (if x = None then f v else id) (x,s) |
236 "assign f v \<equiv> \<lambda>(x,s). let (x',s') = (if x = None then f v else id) (x,s) |
244 in (x',if x' = None then s' else s)" |
237 in (x',if x' = None then s' else s)" |
245 |
238 |
246 (* |
239 (* |
247 lemma assign_Norm_Norm [simp]: |
240 lemma assign_Norm_Norm [simp]: |
298 apply (case_tac "abrupt s = None") |
291 apply (case_tac "abrupt s = None") |
299 apply auto |
292 apply auto |
300 done |
293 done |
301 *) |
294 *) |
302 |
295 |
303 constdefs |
296 definition init_comp_ty :: "ty \<Rightarrow> stmt" where |
304 |
|
305 init_comp_ty :: "ty \<Rightarrow> stmt" |
|
306 "init_comp_ty T \<equiv> if (\<exists>C. T = Class C) then Init (the_Class T) else Skip" |
297 "init_comp_ty T \<equiv> if (\<exists>C. T = Class C) then Init (the_Class T) else Skip" |
307 |
298 |
308 lemma init_comp_ty_PrimT [simp]: "init_comp_ty (PrimT pt) = Skip" |
299 lemma init_comp_ty_PrimT [simp]: "init_comp_ty (PrimT pt) = Skip" |
309 apply (unfold init_comp_ty_def) |
300 apply (unfold init_comp_ty_def) |
310 apply (simp (no_asm)) |
301 apply (simp (no_asm)) |
311 done |
302 done |
312 |
303 |
313 constdefs |
304 definition invocation_class :: "inv_mode \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ref_ty \<Rightarrow> qtname" where |
314 |
|
315 invocation_class :: "inv_mode \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ref_ty \<Rightarrow> qtname" |
|
316 "invocation_class m s a' statT |
305 "invocation_class m s a' statT |
317 \<equiv> (case m of |
306 \<equiv> (case m of |
318 Static \<Rightarrow> if (\<exists> statC. statT = ClassT statC) |
307 Static \<Rightarrow> if (\<exists> statC. statT = ClassT statC) |
319 then the_Class (RefT statT) |
308 then the_Class (RefT statT) |
320 else Object |
309 else Object |
321 | SuperM \<Rightarrow> the_Class (RefT statT) |
310 | SuperM \<Rightarrow> the_Class (RefT statT) |
322 | IntVir \<Rightarrow> obj_class (lookup_obj s a'))" |
311 | IntVir \<Rightarrow> obj_class (lookup_obj s a'))" |
323 |
312 |
324 invocation_declclass::"prog \<Rightarrow> inv_mode \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ref_ty \<Rightarrow> sig \<Rightarrow> qtname" |
313 definition invocation_declclass::"prog \<Rightarrow> inv_mode \<Rightarrow> st \<Rightarrow> val \<Rightarrow> ref_ty \<Rightarrow> sig \<Rightarrow> qtname" where |
325 "invocation_declclass G m s a' statT sig |
314 "invocation_declclass G m s a' statT sig |
326 \<equiv> declclass (the (dynlookup G statT |
315 \<equiv> declclass (the (dynlookup G statT |
327 (invocation_class m s a' statT) |
316 (invocation_class m s a' statT) |
328 sig))" |
317 sig))" |
329 |
318 |
339 "invocation_class Static s a' statT = (if (\<exists> statC. statT = ClassT statC) |
328 "invocation_class Static s a' statT = (if (\<exists> statC. statT = ClassT statC) |
340 then the_Class (RefT statT) |
329 then the_Class (RefT statT) |
341 else Object)" |
330 else Object)" |
342 by (simp add: invocation_class_def) |
331 by (simp add: invocation_class_def) |
343 |
332 |
344 constdefs |
333 definition init_lvars :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> inv_mode \<Rightarrow> val \<Rightarrow> val list \<Rightarrow> |
345 init_lvars :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> inv_mode \<Rightarrow> val \<Rightarrow> val list \<Rightarrow> |
334 state \<Rightarrow> state" where |
346 state \<Rightarrow> state" |
|
347 "init_lvars G C sig mode a' pvs |
335 "init_lvars G C sig mode a' pvs |
348 \<equiv> \<lambda> (x,s). |
336 \<equiv> \<lambda> (x,s). |
349 let m = mthd (the (methd G C sig)); |
337 let m = mthd (the (methd G C sig)); |
350 l = \<lambda> k. |
338 l = \<lambda> k. |
351 (case k of |
339 (case k of |
374 (if mode = Static then x else np a' x,s)" |
362 (if mode = Static then x else np a' x,s)" |
375 apply (unfold init_lvars_def) |
363 apply (unfold init_lvars_def) |
376 apply (simp (no_asm) add: Let_def) |
364 apply (simp (no_asm) add: Let_def) |
377 done |
365 done |
378 |
366 |
379 constdefs |
367 definition body :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> expr" where |
380 body :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> expr" |
|
381 "body G C sig \<equiv> let m = the (methd G C sig) |
368 "body G C sig \<equiv> let m = the (methd G C sig) |
382 in Body (declclass m) (stmt (mbody (mthd m)))" |
369 in Body (declclass m) (stmt (mbody (mthd m)))" |
383 |
370 |
384 lemma body_def2: --{* better suited for simplification *} |
371 lemma body_def2: --{* better suited for simplification *} |
385 "body G C sig = Body (declclass (the (methd G C sig))) |
372 "body G C sig = Body (declclass (the (methd G C sig))) |
388 apply auto |
375 apply auto |
389 done |
376 done |
390 |
377 |
391 section "variables" |
378 section "variables" |
392 |
379 |
393 constdefs |
380 definition lvar :: "lname \<Rightarrow> st \<Rightarrow> vvar" where |
394 |
|
395 lvar :: "lname \<Rightarrow> st \<Rightarrow> vvar" |
|
396 "lvar vn s \<equiv> (the (locals s vn), \<lambda>v. supd (lupd(vn\<mapsto>v)))" |
381 "lvar vn s \<equiv> (the (locals s vn), \<lambda>v. supd (lupd(vn\<mapsto>v)))" |
397 |
382 |
398 fvar :: "qtname \<Rightarrow> bool \<Rightarrow> vname \<Rightarrow> val \<Rightarrow> state \<Rightarrow> vvar \<times> state" |
383 definition fvar :: "qtname \<Rightarrow> bool \<Rightarrow> vname \<Rightarrow> val \<Rightarrow> state \<Rightarrow> vvar \<times> state" where |
399 "fvar C stat fn a' s |
384 "fvar C stat fn a' s |
400 \<equiv> let (oref,xf) = if stat then (Stat C,id) |
385 \<equiv> let (oref,xf) = if stat then (Stat C,id) |
401 else (Heap (the_Addr a'),np a'); |
386 else (Heap (the_Addr a'),np a'); |
402 n = Inl (fn,C); |
387 n = Inl (fn,C); |
403 f = (\<lambda>v. supd (upd_gobj oref n v)) |
388 f = (\<lambda>v. supd (upd_gobj oref n v)) |
404 in ((the (values (the (globs (store s) oref)) n),f),abupd xf s)" |
389 in ((the (values (the (globs (store s) oref)) n),f),abupd xf s)" |
405 |
390 |
406 avar :: "prog \<Rightarrow> val \<Rightarrow> val \<Rightarrow> state \<Rightarrow> vvar \<times> state" |
391 definition avar :: "prog \<Rightarrow> val \<Rightarrow> val \<Rightarrow> state \<Rightarrow> vvar \<times> state" where |
407 "avar G i' a' s |
392 "avar G i' a' s |
408 \<equiv> let oref = Heap (the_Addr a'); |
393 \<equiv> let oref = Heap (the_Addr a'); |
409 i = the_Intg i'; |
394 i = the_Intg i'; |
410 n = Inr i; |
395 n = Inr i; |
411 (T,k,cs) = the_Arr (globs (store s) oref); |
396 (T,k,cs) = the_Arr (globs (store s) oref); |
444 s)" |
429 s)" |
445 apply (unfold avar_def) |
430 apply (unfold avar_def) |
446 apply (simp (no_asm) add: Let_def split_beta) |
431 apply (simp (no_asm) add: Let_def split_beta) |
447 done |
432 done |
448 |
433 |
449 constdefs |
434 definition check_field_access :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> vname \<Rightarrow> bool \<Rightarrow> val \<Rightarrow> state \<Rightarrow> state" where |
450 check_field_access:: |
|
451 "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> vname \<Rightarrow> bool \<Rightarrow> val \<Rightarrow> state \<Rightarrow> state" |
|
452 "check_field_access G accC statDeclC fn stat a' s |
435 "check_field_access G accC statDeclC fn stat a' s |
453 \<equiv> let oref = if stat then Stat statDeclC |
436 \<equiv> let oref = if stat then Stat statDeclC |
454 else Heap (the_Addr a'); |
437 else Heap (the_Addr a'); |
455 dynC = case oref of |
438 dynC = case oref of |
456 Heap a \<Rightarrow> obj_class (the (globs (store s) oref)) |
439 Heap a \<Rightarrow> obj_class (the (globs (store s) oref)) |
459 in abupd |
442 in abupd |
460 (error_if (\<not> G\<turnstile>Field fn (statDeclC,f) in dynC dyn_accessible_from accC) |
443 (error_if (\<not> G\<turnstile>Field fn (statDeclC,f) in dynC dyn_accessible_from accC) |
461 AccessViolation) |
444 AccessViolation) |
462 s" |
445 s" |
463 |
446 |
464 constdefs |
447 definition check_method_access :: "prog \<Rightarrow> qtname \<Rightarrow> ref_ty \<Rightarrow> inv_mode \<Rightarrow> sig \<Rightarrow> val \<Rightarrow> state \<Rightarrow> state" where |
465 check_method_access:: |
|
466 "prog \<Rightarrow> qtname \<Rightarrow> ref_ty \<Rightarrow> inv_mode \<Rightarrow> sig \<Rightarrow> val \<Rightarrow> state \<Rightarrow> state" |
|
467 "check_method_access G accC statT mode sig a' s |
448 "check_method_access G accC statT mode sig a' s |
468 \<equiv> let invC = invocation_class mode (store s) a' statT; |
449 \<equiv> let invC = invocation_class mode (store s) a' statT; |
469 dynM = the (dynlookup G statT invC sig) |
450 dynM = the (dynlookup G statT invC sig) |
470 in abupd |
451 in abupd |
471 (error_if (\<not> G\<turnstile>Methd sig dynM in invC dyn_accessible_from accC) |
452 (error_if (\<not> G\<turnstile>Methd sig dynM in invC dyn_accessible_from accC) |