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