author | haftmann |
Mon, 01 Mar 2010 13:40:23 +0100 | |
changeset 35416 | d8d7d1b785af |
parent 35102 | cc7a0b9f938c |
child 39758 | b8a53e3a0ee2 |
permissions | -rw-r--r-- |
12519 | 1 |
(* Title: HOL/MicroJava/JVM/JVMExceptions.thy |
2 |
Author: Gerwin Klein, Martin Strecker |
|
3 |
Copyright 2001 Technische Universitaet Muenchen |
|
4 |
*) |
|
5 |
||
12911 | 6 |
header {* \isaheader{Exception handling in the JVM} *} |
12519 | 7 |
|
16417 | 8 |
theory JVMExceptions imports JVMInstructions begin |
12519 | 9 |
|
35416
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
haftmann
parents:
35102
diff
changeset
|
10 |
definition match_exception_entry :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_entry \<Rightarrow> bool" where |
12519 | 11 |
"match_exception_entry G cn pc ee == |
12 |
let (start_pc, end_pc, handler_pc, catch_type) = ee in |
|
13 |
start_pc <= pc \<and> pc < end_pc \<and> G\<turnstile> cn \<preceq>C catch_type" |
|
14 |
||
15 |
||
16 |
consts |
|
17 |
match_exception_table :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_table |
|
18 |
\<Rightarrow> p_count option" |
|
19 |
primrec |
|
20 |
"match_exception_table G cn pc [] = None" |
|
21 |
"match_exception_table G cn pc (e#es) = (if match_exception_entry G cn pc e |
|
22 |
then Some (fst (snd (snd e))) |
|
23 |
else match_exception_table G cn pc es)" |
|
24 |
||
35102 | 25 |
abbreviation |
12519 | 26 |
ex_table_of :: "jvm_method \<Rightarrow> exception_table" |
35102 | 27 |
where "ex_table_of m == snd (snd (snd m))" |
12519 | 28 |
|
29 |
||
30 |
consts |
|
31 |
find_handler :: "jvm_prog \<Rightarrow> val option \<Rightarrow> aheap \<Rightarrow> frame list \<Rightarrow> jvm_state" |
|
32 |
primrec |
|
33 |
"find_handler G xcpt hp [] = (xcpt, hp, [])" |
|
34 |
"find_handler G xcpt hp (fr#frs) = |
|
35 |
(case xcpt of |
|
36 |
None \<Rightarrow> (None, hp, fr#frs) |
|
37 |
| Some xc \<Rightarrow> |
|
38 |
let (stk,loc,C,sig,pc) = fr in |
|
39 |
(case match_exception_table G (cname_of hp xc) pc |
|
40 |
(ex_table_of (snd(snd(the(method (G,C) sig))))) of |
|
41 |
None \<Rightarrow> find_handler G (Some xc) hp frs |
|
42 |
| Some handler_pc \<Rightarrow> (None, hp, ([xc], loc, C, sig, handler_pc)#frs)))" |
|
43 |
||
44 |
||
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
45 |
text {* |
13052 | 46 |
System exceptions are allocated in all heaps: |
12545
7319d384d0d3
removed preallocated heaps axiom (now in type safety invariant)
kleing
parents:
12519
diff
changeset
|
47 |
*} |
13052 | 48 |
|
13065 | 49 |
|
50 |
text {* |
|
51 |
Only program counters that are mentioned in the exception table |
|
52 |
can be returned by @{term match_exception_table}: |
|
53 |
*} |
|
54 |
lemma match_exception_table_in_et: |
|
55 |
"match_exception_table G C pc et = Some pc' \<Longrightarrow> \<exists>e \<in> set et. pc' = fst (snd (snd e))" |
|
56 |
by (induct et) (auto split: split_if_asm) |
|
57 |
||
58 |
||
12519 | 59 |
end |