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