src/HOL/MicroJava/BV/Effect.thy
author nipkow
Wed, 17 Aug 2005 08:06:12 +0200
changeset 17088 3f797ec16f02
parent 15481 fc075ae929e4
child 17090 603f23d71ada
permissions -rw-r--r--
list_all_conv -> iff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
     1
(*  Title:      HOL/MicroJava/BV/Effect.thy
d09d0f160888 exceptions
kleing
parents:
diff changeset
     2
    ID:         $Id$
d09d0f160888 exceptions
kleing
parents:
diff changeset
     3
    Author:     Gerwin Klein
d09d0f160888 exceptions
kleing
parents:
diff changeset
     4
    Copyright   2000 Technische Universitaet Muenchen
d09d0f160888 exceptions
kleing
parents:
diff changeset
     5
*)
d09d0f160888 exceptions
kleing
parents:
diff changeset
     6
12911
704713ca07ea new document
kleing
parents: 12772
diff changeset
     7
header {* \isaheader{Effect of Instructions on the State Type} *}
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
     8
15481
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 13717
diff changeset
     9
theory Effect 
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 13717
diff changeset
    10
imports JVMType "../JVM/JVMExceptions"
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 13717
diff changeset
    11
begin
fc075ae929e4 the new subst tactic, by Lucas Dixon
paulson
parents: 13717
diff changeset
    12
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    13
d09d0f160888 exceptions
kleing
parents:
diff changeset
    14
types
d09d0f160888 exceptions
kleing
parents:
diff changeset
    15
  succ_type = "(p_count \<times> state_type option) list"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    16
d09d0f160888 exceptions
kleing
parents:
diff changeset
    17
text {* Program counter of successor instructions: *}
d09d0f160888 exceptions
kleing
parents:
diff changeset
    18
consts
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
    19
  succs :: "instr \<Rightarrow> p_count \<Rightarrow> p_count list"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    20
primrec 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    21
  "succs (Load idx) pc         = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    22
  "succs (Store idx) pc        = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    23
  "succs (LitPush v) pc        = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    24
  "succs (Getfield F C) pc     = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    25
  "succs (Putfield F C) pc     = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    26
  "succs (New C) pc            = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    27
  "succs (Checkcast C) pc      = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    28
  "succs Pop pc                = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    29
  "succs Dup pc                = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    30
  "succs Dup_x1 pc             = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    31
  "succs Dup_x2 pc             = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    32
  "succs Swap pc               = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    33
  "succs IAdd pc               = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    34
  "succs (Ifcmpeq b) pc        = [pc+1, nat (int pc + b)]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    35
  "succs (Goto b) pc           = [nat (int pc + b)]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    36
  "succs Return pc             = [pc]"  
d09d0f160888 exceptions
kleing
parents:
diff changeset
    37
  "succs (Invoke C mn fpTs) pc = [pc+1]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    38
  "succs Throw pc              = [pc]"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    39
d09d0f160888 exceptions
kleing
parents:
diff changeset
    40
text "Effect of instruction on the state type:"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    41
consts 
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
    42
eff' :: "instr \<times> jvm_prog \<times> state_type \<Rightarrow> state_type"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    43
d09d0f160888 exceptions
kleing
parents:
diff changeset
    44
recdef eff' "{}"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    45
"eff' (Load idx,  G, (ST, LT))          = (ok_val (LT ! idx) # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    46
"eff' (Store idx, G, (ts#ST, LT))       = (ST, LT[idx:= OK ts])"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    47
"eff' (LitPush v, G, (ST, LT))           = (the (typeof (\<lambda>v. None) v) # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    48
"eff' (Getfield F C, G, (oT#ST, LT))    = (snd (the (field (G,C) F)) # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    49
"eff' (Putfield F C, G, (vT#oT#ST, LT)) = (ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    50
"eff' (New C, G, (ST,LT))               = (Class C # ST, LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    51
"eff' (Checkcast C, G, (RefT rt#ST,LT)) = (Class C # ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    52
"eff' (Pop, G, (ts#ST,LT))              = (ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    53
"eff' (Dup, G, (ts#ST,LT))              = (ts#ts#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    54
"eff' (Dup_x1, G, (ts1#ts2#ST,LT))      = (ts1#ts2#ts1#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    55
"eff' (Dup_x2, G, (ts1#ts2#ts3#ST,LT))  = (ts1#ts2#ts3#ts1#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    56
"eff' (Swap, G, (ts1#ts2#ST,LT))        = (ts2#ts1#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    57
"eff' (IAdd, G, (PrimT Integer#PrimT Integer#ST,LT)) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    58
                                         = (PrimT Integer#ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    59
"eff' (Ifcmpeq b, G, (ts1#ts2#ST,LT))   = (ST,LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    60
"eff' (Goto b, G, s)                    = s"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    61
  -- "Return has no successor instruction in the same method"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    62
"eff' (Return, G, s)                    = s" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    63
  -- "Throw always terminates abruptly"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    64
"eff' (Throw, G, s)                     = s"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    65
"eff' (Invoke C mn fpTs, G, (ST,LT))    = (let ST' = drop (length fpTs) ST 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    66
  in  (fst (snd (the (method (G,C) (mn,fpTs))))#(tl ST'),LT))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    67
d09d0f160888 exceptions
kleing
parents:
diff changeset
    68
d09d0f160888 exceptions
kleing
parents:
diff changeset
    69
consts
d09d0f160888 exceptions
kleing
parents:
diff changeset
    70
  match_any :: "jvm_prog \<Rightarrow> p_count \<Rightarrow> exception_table \<Rightarrow> cname list"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    71
primrec
d09d0f160888 exceptions
kleing
parents:
diff changeset
    72
  "match_any G pc [] = []"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    73
  "match_any G pc (e#es) = (let (start_pc, end_pc, handler_pc, catch_type) = e;
d09d0f160888 exceptions
kleing
parents:
diff changeset
    74
                                es' = match_any G pc es 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    75
                            in 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    76
                            if start_pc <= pc \<and> pc < end_pc then catch_type#es' else es')"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    77
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    78
consts
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    79
  match :: "jvm_prog \<Rightarrow> xcpt \<Rightarrow> p_count \<Rightarrow> exception_table \<Rightarrow> cname list"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    80
primrec
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    81
  "match G X pc [] = []"
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    82
  "match G X pc (e#es) = 
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    83
  (if match_exception_entry G (Xcpt X) pc e then [Xcpt X] else match G X pc es)"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    84
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    85
lemma match_some_entry:
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    86
  "match G X pc et = (if \<exists>e \<in> set et. match_exception_entry G (Xcpt X) pc e then [Xcpt X] else [])"
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
    87
  by (induct et) auto
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    88
d09d0f160888 exceptions
kleing
parents:
diff changeset
    89
consts
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
    90
  xcpt_names :: "instr \<times> jvm_prog \<times> p_count \<times> exception_table \<Rightarrow> cname list" 
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    91
recdef xcpt_names "{}"
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    92
  "xcpt_names (Getfield F C, G, pc, et) = match G NullPointer pc et" 
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    93
  "xcpt_names (Putfield F C, G, pc, et) = match G NullPointer pc et" 
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    94
  "xcpt_names (New C, G, pc, et)        = match G OutOfMemory pc et"
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
    95
  "xcpt_names (Checkcast C, G, pc, et)  = match G ClassCast pc et"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
    96
  "xcpt_names (Throw, G, pc, et)        = match_any G pc et"
d09d0f160888 exceptions
kleing
parents:
diff changeset
    97
  "xcpt_names (Invoke C m p, G, pc, et) = match_any G pc et" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    98
  "xcpt_names (i, G, pc, et)            = []" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
    99
d09d0f160888 exceptions
kleing
parents:
diff changeset
   100
d09d0f160888 exceptions
kleing
parents:
diff changeset
   101
constdefs
d09d0f160888 exceptions
kleing
parents:
diff changeset
   102
  xcpt_eff :: "instr \<Rightarrow> jvm_prog \<Rightarrow> p_count \<Rightarrow> state_type option \<Rightarrow> exception_table \<Rightarrow> succ_type"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   103
  "xcpt_eff i G pc s et == 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   104
   map (\<lambda>C. (the (match_exception_table G C pc et), case s of None \<Rightarrow> None | Some s' \<Rightarrow> Some ([Class C], snd s'))) 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   105
       (xcpt_names (i,G,pc,et))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   106
d09d0f160888 exceptions
kleing
parents:
diff changeset
   107
  norm_eff :: "instr \<Rightarrow> jvm_prog \<Rightarrow> state_type option \<Rightarrow> state_type option"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   108
  "norm_eff i G == option_map (\<lambda>s. eff' (i,G,s))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   109
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   110
  eff :: "instr \<Rightarrow> jvm_prog \<Rightarrow> p_count \<Rightarrow> exception_table \<Rightarrow> state_type option \<Rightarrow> succ_type"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   111
  "eff i G pc et s == (map (\<lambda>pc'. (pc',norm_eff i G s)) (succs i pc)) @ (xcpt_eff i G pc s et)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   112
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   113
constdefs
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   114
  isPrimT :: "ty \<Rightarrow> bool"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   115
  "isPrimT T == case T of PrimT T' \<Rightarrow> True | RefT T' \<Rightarrow> False"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   116
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   117
  isRefT :: "ty \<Rightarrow> bool"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   118
  "isRefT T == case T of PrimT T' \<Rightarrow> False | RefT T' \<Rightarrow> True"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   119
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   120
lemma isPrimT [simp]:
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   121
  "isPrimT T = (\<exists>T'. T = PrimT T')" by (simp add: isPrimT_def split: ty.splits)
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   122
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   123
lemma isRefT [simp]:
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   124
  "isRefT T = (\<exists>T'. T = RefT T')" by (simp add: isRefT_def split: ty.splits)
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   125
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   126
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   127
lemma "list_all2 P a b \<Longrightarrow> \<forall>(x,y) \<in> set (zip a b). P x y"
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   128
  by (simp add: list_all2_def) 
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   129
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   130
d09d0f160888 exceptions
kleing
parents:
diff changeset
   131
text "Conditions under which eff is applicable:"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   132
consts
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   133
app' :: "instr \<times> jvm_prog \<times> p_count \<times> nat \<times> ty \<times> state_type \<Rightarrow> bool"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   134
d09d0f160888 exceptions
kleing
parents:
diff changeset
   135
recdef app' "{}"
12974
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   136
"app' (Load idx, G, pc, maxs, rT, s) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   137
  (idx < length (snd s) \<and> (snd s) ! idx \<noteq> Err \<and> length (fst s) < maxs)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   138
"app' (Store idx, G, pc, maxs, rT, (ts#ST, LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   139
  (idx < length LT)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   140
"app' (LitPush v, G, pc, maxs, rT, s) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   141
  (length (fst s) < maxs \<and> typeof (\<lambda>t. None) v \<noteq> None)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   142
"app' (Getfield F C, G, pc, maxs, rT, (oT#ST, LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   143
  (is_class G C \<and> field (G,C) F \<noteq> None \<and> fst (the (field (G,C) F)) = C \<and> 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   144
  G \<turnstile> oT \<preceq> (Class C))"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   145
"app' (Putfield F C, G, pc, maxs, rT, (vT#oT#ST, LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   146
  (is_class G C \<and> field (G,C) F \<noteq> None \<and> fst (the (field (G,C) F)) = C \<and>
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   147
  G \<turnstile> oT \<preceq> (Class C) \<and> G \<turnstile> vT \<preceq> (snd (the (field (G,C) F))))" 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   148
"app' (New C, G, pc, maxs, rT, s) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   149
  (is_class G C \<and> length (fst s) < maxs)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   150
"app' (Checkcast C, G, pc, maxs, rT, (RefT rt#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   151
  (is_class G C)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   152
"app' (Pop, G, pc, maxs, rT, (ts#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   153
  True"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   154
"app' (Dup, G, pc, maxs, rT, (ts#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   155
  (1+length ST < maxs)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   156
"app' (Dup_x1, G, pc, maxs, rT, (ts1#ts2#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   157
  (2+length ST < maxs)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   158
"app' (Dup_x2, G, pc, maxs, rT, (ts1#ts2#ts3#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   159
  (3+length ST < maxs)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   160
"app' (Swap, G, pc, maxs, rT, (ts1#ts2#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   161
  True"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   162
"app' (IAdd, G, pc, maxs, rT, (PrimT Integer#PrimT Integer#ST,LT)) =
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   163
  True"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   164
"app' (Ifcmpeq b, G, pc, maxs, rT, (ts#ts'#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   165
  (0 \<le> int pc + b \<and> (isPrimT ts \<and> ts' = ts \<or> isRefT ts \<and> isRefT ts'))"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   166
"app' (Goto b, G, pc, maxs, rT, s) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   167
  (0 \<le> int pc + b)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   168
"app' (Return, G, pc, maxs, rT, (T#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   169
  (G \<turnstile> T \<preceq> rT)"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   170
"app' (Throw, G, pc, maxs, rT, (T#ST,LT)) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   171
  isRefT T"
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   172
"app' (Invoke C mn fpTs, G, pc, maxs, rT, s) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   173
  (length fpTs < length (fst s) \<and> 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   174
  (let apTs = rev (take (length fpTs) (fst s));
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   175
       X    = hd (drop (length fpTs) (fst s)) 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   176
   in  
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   177
       G \<turnstile> X \<preceq> Class C \<and> is_class G C \<and> method (G,C) (mn,fpTs) \<noteq> None \<and>
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   178
       list_all2 (\<lambda>x y. G \<turnstile> x \<preceq> y) apTs fpTs))"
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   179
  
12974
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   180
"app' (i,G, pc,maxs,rT,s) = False"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   181
d09d0f160888 exceptions
kleing
parents:
diff changeset
   182
constdefs
d09d0f160888 exceptions
kleing
parents:
diff changeset
   183
  xcpt_app :: "instr \<Rightarrow> jvm_prog \<Rightarrow> nat \<Rightarrow> exception_table \<Rightarrow> bool"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   184
  "xcpt_app i G pc et \<equiv> \<forall>C\<in>set(xcpt_names (i,G,pc,et)). is_class G C"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   185
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   186
  app :: "instr \<Rightarrow> jvm_prog \<Rightarrow> nat \<Rightarrow> ty \<Rightarrow> nat \<Rightarrow> exception_table \<Rightarrow> state_type option \<Rightarrow> bool"
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   187
  "app i G maxs rT pc et s == case s of None \<Rightarrow> True | Some t \<Rightarrow> app' (i,G,pc,maxs,rT,t) \<and> xcpt_app i G pc et"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   188
d09d0f160888 exceptions
kleing
parents:
diff changeset
   189
13066
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   190
lemma match_any_match_table:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   191
  "C \<in> set (match_any G pc et) \<Longrightarrow> match_exception_table G C pc et \<noteq> None"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   192
  apply (induct et)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   193
   apply simp
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   194
  apply simp
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   195
  apply clarify
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   196
  apply (simp split: split_if_asm)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   197
  apply (auto simp add: match_exception_entry_def)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   198
  done
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   199
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   200
lemma match_X_match_table:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   201
  "C \<in> set (match G X pc et) \<Longrightarrow> match_exception_table G C pc et \<noteq> None"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   202
  apply (induct et)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   203
   apply simp
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   204
  apply (simp split: split_if_asm)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   205
  done
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   206
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   207
lemma xcpt_names_in_et:
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   208
  "C \<in> set (xcpt_names (i,G,pc,et)) \<Longrightarrow> 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   209
  \<exists>e \<in> set et. the (match_exception_table G C pc et) = fst (snd (snd e))"
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   210
  apply (cases i)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   211
  apply (auto dest!: match_any_match_table match_X_match_table 
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   212
              dest: match_exception_table_in_et)
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   213
  done
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   214
b57d926d1de2 cleanup + simpler monotonicity
kleing
parents: 13006
diff changeset
   215
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   216
lemma 1: "2 < length a \<Longrightarrow> (\<exists>l l' l'' ls. a = l#l'#l''#ls)"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   217
proof (cases a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   218
  fix x xs assume "a = x#xs" "2 < length a"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   219
  thus ?thesis by - (cases xs, simp, cases "tl xs", auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   220
qed auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
   221
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   222
lemma 2: "\<not>(2 < length a) \<Longrightarrow> a = [] \<or> (\<exists> l. a = [l]) \<or> (\<exists> l l'. a = [l,l'])"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   223
proof -;
d09d0f160888 exceptions
kleing
parents:
diff changeset
   224
  assume "\<not>(2 < length a)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   225
  hence "length a < (Suc (Suc (Suc 0)))" by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   226
  hence * : "length a = 0 \<or> length a = Suc 0 \<or> length a = Suc (Suc 0)" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   227
    by (auto simp add: less_Suc_eq)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   228
d09d0f160888 exceptions
kleing
parents:
diff changeset
   229
  { 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   230
    fix x 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   231
    assume "length x = Suc 0"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   232
    hence "\<exists> l. x = [l]"  by - (cases x, auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   233
  } note 0 = this
d09d0f160888 exceptions
kleing
parents:
diff changeset
   234
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   235
  have "length a = Suc (Suc 0) \<Longrightarrow> \<exists>l l'. a = [l,l']" by (cases a, auto dest: 0)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   236
  with * show ?thesis by (auto dest: 0)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   237
qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
   238
d09d0f160888 exceptions
kleing
parents:
diff changeset
   239
lemmas [simp] = app_def xcpt_app_def
d09d0f160888 exceptions
kleing
parents:
diff changeset
   240
d09d0f160888 exceptions
kleing
parents:
diff changeset
   241
text {* 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   242
\medskip
d09d0f160888 exceptions
kleing
parents:
diff changeset
   243
simp rules for @{term app}
d09d0f160888 exceptions
kleing
parents:
diff changeset
   244
*}
d09d0f160888 exceptions
kleing
parents:
diff changeset
   245
lemma appNone[simp]: "app i G maxs rT pc et None = True" by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   246
d09d0f160888 exceptions
kleing
parents:
diff changeset
   247
d09d0f160888 exceptions
kleing
parents:
diff changeset
   248
lemma appLoad[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   249
"(app (Load idx) G maxs rT pc et (Some s)) = (\<exists>ST LT. s = (ST,LT) \<and> idx < length LT \<and> LT!idx \<noteq> Err \<and> length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   250
  by (cases s, simp)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   251
d09d0f160888 exceptions
kleing
parents:
diff changeset
   252
lemma appStore[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   253
"(app (Store idx) G maxs rT pc et (Some s)) = (\<exists>ts ST LT. s = (ts#ST,LT) \<and> idx < length LT)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   254
  by (cases s, cases "2 < length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   255
d09d0f160888 exceptions
kleing
parents:
diff changeset
   256
lemma appLitPush[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   257
"(app (LitPush v) G maxs rT pc et (Some s)) = (\<exists>ST LT. s = (ST,LT) \<and> length ST < maxs \<and> typeof (\<lambda>v. None) v \<noteq> None)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   258
  by (cases s, simp)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   259
d09d0f160888 exceptions
kleing
parents:
diff changeset
   260
lemma appGetField[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   261
"(app (Getfield F C) G maxs rT pc et (Some s)) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   262
 (\<exists> oT vT ST LT. s = (oT#ST, LT) \<and> is_class G C \<and>  
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
   263
  field (G,C) F = Some (C,vT) \<and> G \<turnstile> oT \<preceq> (Class C) \<and> (\<forall>x \<in> set (match G NullPointer pc et). is_class G x))"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   264
  by (cases s, cases "2 <length (fst s)", auto dest!: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   265
d09d0f160888 exceptions
kleing
parents:
diff changeset
   266
lemma appPutField[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   267
"(app (Putfield F C) G maxs rT pc et (Some s)) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   268
 (\<exists> vT vT' oT ST LT. s = (vT#oT#ST, LT) \<and> is_class G C \<and> 
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   269
  field (G,C) F = Some (C, vT') \<and> G \<turnstile> oT \<preceq> (Class C) \<and> G \<turnstile> vT \<preceq> vT' \<and>
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
   270
  (\<forall>x \<in> set (match G NullPointer pc et). is_class G x))"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   271
  by (cases s, cases "2 <length (fst s)", auto dest!: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   272
d09d0f160888 exceptions
kleing
parents:
diff changeset
   273
lemma appNew[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   274
  "(app (New C) G maxs rT pc et (Some s)) = 
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   275
  (\<exists>ST LT. s=(ST,LT) \<and> is_class G C \<and> length ST < maxs \<and>
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
   276
  (\<forall>x \<in> set (match G OutOfMemory pc et). is_class G x))"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   277
  by (cases s, simp)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   278
d09d0f160888 exceptions
kleing
parents:
diff changeset
   279
lemma appCheckcast[simp]: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   280
  "(app (Checkcast C) G maxs rT pc et (Some s)) =  
12951
a9fdcb71d252 introduces SystemClasses and BVExample
kleing
parents: 12911
diff changeset
   281
  (\<exists>rT ST LT. s = (RefT rT#ST,LT) \<and> is_class G C \<and>
13717
78f91fcdf560 beautified "match"
kleing
parents: 13066
diff changeset
   282
  (\<forall>x \<in> set (match G ClassCast pc et). is_class G x))"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   283
  by (cases s, cases "fst s", simp add: app_def) (cases "hd (fst s)", auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   284
d09d0f160888 exceptions
kleing
parents:
diff changeset
   285
lemma appPop[simp]: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   286
"(app Pop G maxs rT pc et (Some s)) = (\<exists>ts ST LT. s = (ts#ST,LT))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   287
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   288
d09d0f160888 exceptions
kleing
parents:
diff changeset
   289
d09d0f160888 exceptions
kleing
parents:
diff changeset
   290
lemma appDup[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   291
"(app Dup G maxs rT pc et (Some s)) = (\<exists>ts ST LT. s = (ts#ST,LT) \<and> 1+length ST < maxs)" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   292
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   293
d09d0f160888 exceptions
kleing
parents:
diff changeset
   294
d09d0f160888 exceptions
kleing
parents:
diff changeset
   295
lemma appDup_x1[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   296
"(app Dup_x1 G maxs rT pc et (Some s)) = (\<exists>ts1 ts2 ST LT. s = (ts1#ts2#ST,LT) \<and> 2+length ST < maxs)" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   297
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   298
d09d0f160888 exceptions
kleing
parents:
diff changeset
   299
d09d0f160888 exceptions
kleing
parents:
diff changeset
   300
lemma appDup_x2[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   301
"(app Dup_x2 G maxs rT pc et (Some s)) = (\<exists>ts1 ts2 ts3 ST LT. s = (ts1#ts2#ts3#ST,LT) \<and> 3+length ST < maxs)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   302
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   303
d09d0f160888 exceptions
kleing
parents:
diff changeset
   304
d09d0f160888 exceptions
kleing
parents:
diff changeset
   305
lemma appSwap[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   306
"app Swap G maxs rT pc et (Some s) = (\<exists>ts1 ts2 ST LT. s = (ts1#ts2#ST,LT))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   307
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   308
d09d0f160888 exceptions
kleing
parents:
diff changeset
   309
d09d0f160888 exceptions
kleing
parents:
diff changeset
   310
lemma appIAdd[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   311
"app IAdd G maxs rT pc et (Some s) = (\<exists> ST LT. s = (PrimT Integer#PrimT Integer#ST,LT))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   312
  (is "?app s = ?P s")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   313
proof (cases (open) s)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   314
  case Pair
d09d0f160888 exceptions
kleing
parents:
diff changeset
   315
  have "?app (a,b) = ?P (a,b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   316
  proof (cases "a")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   317
    fix t ts assume a: "a = t#ts"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   318
    show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   319
    proof (cases t)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   320
      fix p assume p: "t = PrimT p"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   321
      show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   322
      proof (cases p)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   323
        assume ip: "p = Integer"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   324
        show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   325
        proof (cases ts)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   326
          fix t' ts' assume t': "ts = t' # ts'"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   327
          show ?thesis
d09d0f160888 exceptions
kleing
parents:
diff changeset
   328
          proof (cases t')
d09d0f160888 exceptions
kleing
parents:
diff changeset
   329
            fix p' assume "t' = PrimT p'"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   330
            with t' ip p a
d09d0f160888 exceptions
kleing
parents:
diff changeset
   331
            show ?thesis by - (cases p', auto)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   332
          qed (auto simp add: a p ip t')
d09d0f160888 exceptions
kleing
parents:
diff changeset
   333
        qed (auto simp add: a p ip)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   334
      qed (auto simp add: a p)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   335
    qed (auto simp add: a)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   336
  qed auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
   337
  with Pair show ?thesis by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   338
qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
   339
d09d0f160888 exceptions
kleing
parents:
diff changeset
   340
d09d0f160888 exceptions
kleing
parents:
diff changeset
   341
lemma appIfcmpeq[simp]:
12974
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   342
"app (Ifcmpeq b) G maxs rT pc et (Some s) = 
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   343
  (\<exists>ts1 ts2 ST LT. s = (ts1#ts2#ST,LT) \<and> 0 \<le> int pc + b \<and>
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   344
  ((\<exists> p. ts1 = PrimT p \<and> ts2 = PrimT p) \<or> (\<exists>r r'. ts1 = RefT r \<and> ts2 = RefT r')))" 
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   345
  by (cases s, cases "2 <length (fst s)", auto dest!: 1 2)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   346
d09d0f160888 exceptions
kleing
parents:
diff changeset
   347
lemma appReturn[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   348
"app Return G maxs rT pc et (Some s) = (\<exists>T ST LT. s = (T#ST,LT) \<and> (G \<turnstile> T \<preceq> rT))" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   349
  by (cases s, cases "2 <length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   350
d09d0f160888 exceptions
kleing
parents:
diff changeset
   351
lemma appGoto[simp]:
12974
7acfab8361d1 enforce positive branch targets
kleing
parents: 12951
diff changeset
   352
"app (Goto b) G maxs rT pc et (Some s) = (0 \<le> int pc + b)"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   353
  by simp
d09d0f160888 exceptions
kleing
parents:
diff changeset
   354
d09d0f160888 exceptions
kleing
parents:
diff changeset
   355
lemma appThrow[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   356
  "app Throw G maxs rT pc et (Some s) = 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   357
  (\<exists>T ST LT r. s=(T#ST,LT) \<and> T = RefT r \<and> (\<forall>C \<in> set (match_any G pc et). is_class G C))"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   358
  by (cases s, cases "2 < length (fst s)", auto dest: 1 2)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   359
d09d0f160888 exceptions
kleing
parents:
diff changeset
   360
lemma appInvoke[simp]:
d09d0f160888 exceptions
kleing
parents:
diff changeset
   361
"app (Invoke C mn fpTs) G maxs rT pc et (Some s) = (\<exists>apTs X ST LT mD' rT' b'.
d09d0f160888 exceptions
kleing
parents:
diff changeset
   362
  s = ((rev apTs) @ (X # ST), LT) \<and> length apTs = length fpTs \<and> is_class G C \<and>
d09d0f160888 exceptions
kleing
parents:
diff changeset
   363
  G \<turnstile> X \<preceq> Class C \<and> (\<forall>(aT,fT)\<in>set(zip apTs fpTs). G \<turnstile> aT \<preceq> fT) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   364
  method (G,C) (mn,fpTs) = Some (mD', rT', b') \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   365
  (\<forall>C \<in> set (match_any G pc et). is_class G C))" (is "?app s = ?P s")
d09d0f160888 exceptions
kleing
parents:
diff changeset
   366
proof (cases (open) s)
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   367
  note list_all2_def [simp]
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   368
  case Pair
13006
51c5f3f11d16 symbolized
kleing
parents: 12974
diff changeset
   369
  have "?app (a,b) \<Longrightarrow> ?P (a,b)"
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   370
  proof -
d09d0f160888 exceptions
kleing
parents:
diff changeset
   371
    assume app: "?app (a,b)"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   372
    hence "a = (rev (rev (take (length fpTs) a))) @ (drop (length fpTs) a) \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   373
           length fpTs < length a" (is "?a \<and> ?l") 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   374
      by (auto simp add: app_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   375
    hence "?a \<and> 0 < length (drop (length fpTs) a)" (is "?a \<and> ?l") 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   376
      by auto
d09d0f160888 exceptions
kleing
parents:
diff changeset
   377
    hence "?a \<and> ?l \<and> length (rev (take (length fpTs) a)) = length fpTs" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   378
      by (auto simp add: min_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   379
    hence "\<exists>apTs ST. a = rev apTs @ ST \<and> length apTs = length fpTs \<and> 0 < length ST" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   380
      by blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   381
    hence "\<exists>apTs ST. a = rev apTs @ ST \<and> length apTs = length fpTs \<and> ST \<noteq> []" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   382
      by blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   383
    hence "\<exists>apTs ST. a = rev apTs @ ST \<and> length apTs = length fpTs \<and> 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   384
           (\<exists>X ST'. ST = X#ST')" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   385
      by (simp add: neq_Nil_conv)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   386
    hence "\<exists>apTs X ST. a = rev apTs @ X # ST \<and> length apTs = length fpTs" 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   387
      by blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   388
    with app
d09d0f160888 exceptions
kleing
parents:
diff changeset
   389
    show ?thesis by (unfold app_def, clarsimp) blast
d09d0f160888 exceptions
kleing
parents:
diff changeset
   390
  qed
d09d0f160888 exceptions
kleing
parents:
diff changeset
   391
  with Pair 
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   392
  have "?app s \<Longrightarrow> ?P s" by (simp only:)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   393
  moreover
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   394
  have "?P s \<Longrightarrow> ?app s" by (unfold app_def) (clarsimp simp add: min_def)
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   395
  ultimately
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   396
  show ?thesis by (rule iffI) 
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   397
qed 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   398
d09d0f160888 exceptions
kleing
parents:
diff changeset
   399
lemma effNone: 
d09d0f160888 exceptions
kleing
parents:
diff changeset
   400
  "(pc', s') \<in> set (eff i G pc et None) \<Longrightarrow> s' = None"
d09d0f160888 exceptions
kleing
parents:
diff changeset
   401
  by (auto simp add: eff_def xcpt_eff_def norm_eff_def)
d09d0f160888 exceptions
kleing
parents:
diff changeset
   402
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   403
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   404
text {* some helpers to make the specification directly executable: *}
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   405
declare list_all2_Nil [code]
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   406
declare list_all2_Cons [code]
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   407
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   408
lemma xcpt_app_lemma [code]:
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   409
  "xcpt_app i G pc et = list_all (is_class G) (xcpt_names (i, G, pc, et))"
17088
3f797ec16f02 list_all_conv -> iff
nipkow
parents: 15481
diff changeset
   410
  by (simp add: list_all_iff)
12772
7b7051ae49a0 tuned for directly executable definitions
kleing
parents: 12516
diff changeset
   411
12516
d09d0f160888 exceptions
kleing
parents:
diff changeset
   412
lemmas [simp del] = app_def xcpt_app_def
d09d0f160888 exceptions
kleing
parents:
diff changeset
   413
d09d0f160888 exceptions
kleing
parents:
diff changeset
   414
end