src/HOL/MicroJava/JVM/JVMExceptions.thy
author haftmann
Fri, 17 Jun 2005 16:12:49 +0200
changeset 16417 9bc16273c2d4
parent 13674 f4c64597fb02
child 35102 cc7a0b9f938c
permissions -rw-r--r--
migrated theory headers to new format
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/JVM/JVMExceptions.thy
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     2
    ID:         $Id$
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     3
    Author:     Gerwin Klein, Martin Strecker
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     4
    Copyright   2001 Technische Universitaet Muenchen
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     5
*)
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     6
12911
704713ca07ea new document
kleing
parents: 12545
diff changeset
     7
header {* \isaheader{Exception handling in the JVM} *}
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
     8
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 13674
diff changeset
     9
theory JVMExceptions imports JVMInstructions begin
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    10
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    11
constdefs
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    12
  match_exception_entry :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_entry \<Rightarrow> bool"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    13
  "match_exception_entry G cn pc ee == 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    14
                 let (start_pc, end_pc, handler_pc, catch_type) = ee in
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    15
                 start_pc <= pc \<and> pc < end_pc \<and> G\<turnstile> cn \<preceq>C catch_type"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    16
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    17
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    18
consts
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    19
  match_exception_table :: "jvm_prog \<Rightarrow> cname \<Rightarrow> p_count \<Rightarrow> exception_table
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    20
                          \<Rightarrow> p_count option"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    21
primrec
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    22
  "match_exception_table G cn pc []     = None"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    23
  "match_exception_table G cn pc (e#es) = (if match_exception_entry G cn pc e
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    24
                                           then Some (fst (snd (snd e))) 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    25
                                           else match_exception_table G cn pc es)"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    26
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    27
consts
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    28
  ex_table_of :: "jvm_method \<Rightarrow> exception_table"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    29
translations
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    30
  "ex_table_of m" == "snd (snd (snd m))"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    31
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    32
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    33
consts
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    34
  find_handler :: "jvm_prog \<Rightarrow> val option \<Rightarrow> aheap \<Rightarrow> frame list \<Rightarrow> jvm_state"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    35
primrec
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    36
  "find_handler G xcpt hp [] = (xcpt, hp, [])"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    37
  "find_handler G xcpt hp (fr#frs) = 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    38
      (case xcpt of
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    39
         None \<Rightarrow> (None, hp, fr#frs)
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    40
       | Some xc \<Rightarrow> 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    41
       let (stk,loc,C,sig,pc) = fr in
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    42
       (case match_exception_table G (cname_of hp xc) pc 
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    43
              (ex_table_of (snd(snd(the(method (G,C) sig))))) of
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    44
          None \<Rightarrow> find_handler G (Some xc) hp frs
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    45
        | Some handler_pc \<Rightarrow> (None, hp, ([xc], loc, C, sig, handler_pc)#frs)))"
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    46
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    47
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12519
diff changeset
    48
text {*
13052
3bf41c474a88 canonical start state
kleing
parents: 12911
diff changeset
    49
  System exceptions are allocated in all heaps:
12545
7319d384d0d3 removed preallocated heaps axiom (now in type safety invariant)
kleing
parents: 12519
diff changeset
    50
*}
13052
3bf41c474a88 canonical start state
kleing
parents: 12911
diff changeset
    51
13065
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    52
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    53
text {*
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    54
  Only program counters that are mentioned in the exception table
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    55
  can be returned by @{term match_exception_table}:
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    56
*}
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    57
lemma match_exception_table_in_et:
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    58
  "match_exception_table G C pc et = Some pc' \<Longrightarrow> \<exists>e \<in> set et. pc' = fst (snd (snd e))"
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    59
  by (induct et) (auto split: split_if_asm)
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    60
d6585b32412b more about match_exception_table
kleing
parents: 13052
diff changeset
    61
12519
a955fe2879ba exception merge + cleanup
kleing
parents:
diff changeset
    62
end