src/HOL/Bali/TypeSafe.thy
author wenzelm
Wed Jun 13 18:30:11 2007 +0200 (2007-06-13)
changeset 23373 ead82c82da9e
parent 23350 50c5b0912a0c
child 24019 67bde7cfcf10
permissions -rw-r--r--
tuned proofs: avoid implicit prems;
wenzelm@12857
     1
(*  Title:      HOL/Bali/TypeSafe.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12925
     3
    Author:     David von Oheimb and Norbert Schirmer
schirmer@12854
     4
*)
schirmer@12854
     5
header {* The type soundness proof for Java *}
schirmer@12854
     6
haftmann@23019
     7
theory TypeSafe
haftmann@23019
     8
imports DefiniteAssignmentCorrect Conform
haftmann@23019
     9
begin
schirmer@12854
    10
schirmer@12925
    11
section "error free"
schirmer@12925
    12
 
haftmann@23019
    13
hide const field
haftmann@23019
    14
schirmer@12925
    15
lemma error_free_halloc:
wenzelm@12937
    16
  assumes halloc: "G\<turnstile>s0 \<midarrow>halloc oi\<succ>a\<rightarrow> s1" and
schirmer@12925
    17
          error_free_s0: "error_free s0"
wenzelm@12937
    18
  shows "error_free s1"
schirmer@12925
    19
proof -
schirmer@12925
    20
  from halloc error_free_s0
schirmer@12925
    21
  obtain abrupt0 store0 abrupt1 store1
schirmer@12925
    22
    where eqs: "s0=(abrupt0,store0)" "s1=(abrupt1,store1)" and
schirmer@12925
    23
          halloc': "G\<turnstile>(abrupt0,store0) \<midarrow>halloc oi\<succ>a\<rightarrow> (abrupt1,store1)" and
schirmer@12925
    24
          error_free_s0': "error_free (abrupt0,store0)"
schirmer@12925
    25
    by (cases s0,cases s1) auto
schirmer@12925
    26
  from halloc' error_free_s0'
schirmer@12925
    27
  have "error_free (abrupt1,store1)"
schirmer@12925
    28
  proof (induct)
schirmer@12925
    29
    case Abrupt 
schirmer@13688
    30
    then show ?case .
schirmer@12925
    31
  next
schirmer@12925
    32
    case New
schirmer@12925
    33
    then show ?case
schirmer@12925
    34
      by (auto split: split_if_asm)
schirmer@12925
    35
  qed
schirmer@12925
    36
  with eqs 
schirmer@12925
    37
  show ?thesis
schirmer@12925
    38
    by simp
schirmer@12925
    39
qed
schirmer@12925
    40
schirmer@12925
    41
lemma error_free_sxalloc:
wenzelm@12937
    42
  assumes sxalloc: "G\<turnstile>s0 \<midarrow>sxalloc\<rightarrow> s1" and error_free_s0: "error_free s0"
wenzelm@12937
    43
  shows "error_free s1"
schirmer@12925
    44
proof -
schirmer@12925
    45
  from sxalloc error_free_s0
schirmer@12925
    46
  obtain abrupt0 store0 abrupt1 store1
schirmer@12925
    47
    where eqs: "s0=(abrupt0,store0)" "s1=(abrupt1,store1)" and
schirmer@12925
    48
          sxalloc': "G\<turnstile>(abrupt0,store0) \<midarrow>sxalloc\<rightarrow> (abrupt1,store1)" and
schirmer@12925
    49
          error_free_s0': "error_free (abrupt0,store0)"
schirmer@12925
    50
    by (cases s0,cases s1) auto
schirmer@12925
    51
  from sxalloc' error_free_s0'
schirmer@12925
    52
  have "error_free (abrupt1,store1)"
schirmer@12925
    53
  proof (induct)
schirmer@12925
    54
  qed (auto)
schirmer@12925
    55
  with eqs 
schirmer@12925
    56
  show ?thesis 
schirmer@12925
    57
    by simp
schirmer@12925
    58
qed
schirmer@12925
    59
schirmer@12925
    60
lemma error_free_check_field_access_eq:
schirmer@12925
    61
 "error_free (check_field_access G accC statDeclC fn stat a s)
schirmer@12925
    62
 \<Longrightarrow> (check_field_access G accC statDeclC fn stat a s) = s"
schirmer@12925
    63
apply (cases s)
schirmer@12925
    64
apply (auto simp add: check_field_access_def Let_def error_free_def 
schirmer@12925
    65
                      abrupt_if_def 
schirmer@12925
    66
            split: split_if_asm)
schirmer@12925
    67
done
schirmer@12925
    68
schirmer@12925
    69
lemma error_free_check_method_access_eq:
schirmer@12925
    70
"error_free (check_method_access G accC statT mode sig a' s)
schirmer@12925
    71
 \<Longrightarrow> (check_method_access G accC statT mode sig a' s) = s"
schirmer@12925
    72
apply (cases s)
schirmer@12925
    73
apply (auto simp add: check_method_access_def Let_def error_free_def 
schirmer@12925
    74
                      abrupt_if_def 
schirmer@12925
    75
            split: split_if_asm)
schirmer@12925
    76
done
schirmer@12925
    77
schirmer@12925
    78
lemma error_free_FVar_lemma: 
schirmer@12925
    79
     "error_free s 
schirmer@12925
    80
       \<Longrightarrow> error_free (abupd (if stat then id else np a) s)"
schirmer@12925
    81
  by (case_tac s) (auto split: split_if) 
schirmer@12925
    82
schirmer@12925
    83
lemma error_free_init_lvars [simp,intro]:
schirmer@12925
    84
"error_free s \<Longrightarrow> 
schirmer@12925
    85
  error_free (init_lvars G C sig mode a pvs s)"
schirmer@12925
    86
by (cases s) (auto simp add: init_lvars_def Let_def split: split_if)
schirmer@12925
    87
schirmer@12925
    88
lemma error_free_LVar_lemma:   
schirmer@12925
    89
"error_free s \<Longrightarrow> error_free (assign (\<lambda>v. supd lupd(vn\<mapsto>v)) w s)"
schirmer@12925
    90
by (cases s) simp
schirmer@12925
    91
schirmer@12925
    92
lemma error_free_throw [simp,intro]:
schirmer@12925
    93
  "error_free s \<Longrightarrow> error_free (abupd (throw x) s)"
schirmer@12925
    94
by (cases s) (simp add: throw_def)
schirmer@12925
    95
schirmer@12854
    96
schirmer@12854
    97
section "result conformance"
schirmer@12854
    98
schirmer@12854
    99
constdefs
schirmer@12854
   100
  assign_conforms :: "st \<Rightarrow> (val \<Rightarrow> state \<Rightarrow> state) \<Rightarrow> ty \<Rightarrow> env_ \<Rightarrow> bool"
schirmer@12854
   101
          ("_\<le>|_\<preceq>_\<Colon>\<preceq>_"                                        [71,71,71,71] 70)
schirmer@12925
   102
"s\<le>|f\<preceq>T\<Colon>\<preceq>E \<equiv>
schirmer@12925
   103
 (\<forall>s' w. Norm s'\<Colon>\<preceq>E \<longrightarrow> fst E,s'\<turnstile>w\<Colon>\<preceq>T \<longrightarrow> s\<le>|s' \<longrightarrow> assign f w (Norm s')\<Colon>\<preceq>E) \<and>
schirmer@12925
   104
 (\<forall>s' w. error_free s' \<longrightarrow> (error_free (assign f w s')))"      
schirmer@12854
   105
schirmer@13688
   106
schirmer@13688
   107
constdefs
schirmer@12854
   108
  rconf :: "prog \<Rightarrow> lenv \<Rightarrow> st \<Rightarrow> term \<Rightarrow> vals \<Rightarrow> tys \<Rightarrow> bool"
schirmer@12854
   109
          ("_,_,_\<turnstile>_\<succ>_\<Colon>\<preceq>_"                               [71,71,71,71,71,71] 70)
schirmer@12854
   110
  "G,L,s\<turnstile>t\<succ>v\<Colon>\<preceq>T 
schirmer@12854
   111
    \<equiv> case T of
schirmer@13688
   112
        Inl T  \<Rightarrow> if (\<exists> var. t=In2 var)
schirmer@13688
   113
                  then (\<forall> n. (the_In2 t) = LVar n 
schirmer@13688
   114
                         \<longrightarrow> (fst (the_In2 v) = the (locals s n)) \<and>
schirmer@13688
   115
                             (locals s n \<noteq> None \<longrightarrow> G,s\<turnstile>fst (the_In2 v)\<Colon>\<preceq>T)) \<and>
schirmer@13688
   116
                      (\<not> (\<exists> n. the_In2 t=LVar n) \<longrightarrow> (G,s\<turnstile>fst (the_In2 v)\<Colon>\<preceq>T))\<and>
schirmer@13688
   117
                      (s\<le>|snd (the_In2 v)\<preceq>T\<Colon>\<preceq>(G,L))
schirmer@12854
   118
                  else G,s\<turnstile>the_In1 v\<Colon>\<preceq>T
schirmer@12854
   119
      | Inr Ts \<Rightarrow> list_all2 (conf G s) (the_In3 v) Ts"
schirmer@12854
   120
schirmer@13688
   121
text {*
schirmer@13688
   122
 With @{term rconf} we describe the conformance of the result value of a term.
schirmer@13688
   123
 This definition gets rather complicated because of the relations between the
schirmer@13688
   124
 injections of the different terms, types and values. The main case distinction
schirmer@13688
   125
 is between single values and value lists. In case of value lists, every 
schirmer@13688
   126
 value has to conform to its type. For single values we have to do a further
schirmer@13688
   127
 case distinction, between values of variables @{term "\<exists>var. t=In2 var" } and
schirmer@13688
   128
 ordinary values. Values of variables are modelled as pairs consisting of the
schirmer@13688
   129
 current value and an update function which will perform an assignment to the
schirmer@13688
   130
 variable. This stems form the decision, that we only have one evaluation rule
schirmer@13688
   131
 for each kind of variable. The decision if we read or write to the 
schirmer@13688
   132
 variable is made by syntactic enclosing rules. So conformance of 
schirmer@13688
   133
 variable-values must ensure that both the current value and an update will 
schirmer@13688
   134
 conform to the type. With the introduction of definite assignment of local
schirmer@13688
   135
 variables we have to do another case distinction. For the notion of conformance
schirmer@13688
   136
 local variables are allowed to be @{term None}, since the definedness is not 
schirmer@13688
   137
 ensured by conformance but by definite assignment. Field and array variables 
schirmer@13688
   138
 must contain a value. 
schirmer@13688
   139
*}
schirmer@13688
   140
 
schirmer@13688
   141
schirmer@13688
   142
schirmer@12854
   143
lemma rconf_In1 [simp]: 
schirmer@12854
   144
 "G,L,s\<turnstile>In1 ec\<succ>In1 v \<Colon>\<preceq>Inl T  =  G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
   145
apply (unfold rconf_def)
schirmer@12854
   146
apply (simp (no_asm))
schirmer@12854
   147
done
schirmer@12854
   148
schirmer@13688
   149
lemma rconf_In2_no_LVar [simp]: 
schirmer@13688
   150
 "\<forall> n. va\<noteq>LVar n \<Longrightarrow> 
schirmer@13688
   151
   G,L,s\<turnstile>In2 va\<succ>In2 vf\<Colon>\<preceq>Inl T  = (G,s\<turnstile>fst vf\<Colon>\<preceq>T \<and> s\<le>|snd vf\<preceq>T\<Colon>\<preceq>(G,L))"
schirmer@12854
   152
apply (unfold rconf_def)
schirmer@13688
   153
apply auto
schirmer@12854
   154
done
schirmer@12854
   155
schirmer@13688
   156
lemma rconf_In2_LVar [simp]: 
schirmer@13688
   157
 "va=LVar n \<Longrightarrow> 
schirmer@13688
   158
   G,L,s\<turnstile>In2 va\<succ>In2 vf\<Colon>\<preceq>Inl T  
schirmer@13688
   159
    = ((fst vf = the (locals s n)) \<and>
schirmer@13688
   160
       (locals s n \<noteq> None \<longrightarrow> G,s\<turnstile>fst vf\<Colon>\<preceq>T) \<and> s\<le>|snd vf\<preceq>T\<Colon>\<preceq>(G,L))"
schirmer@13688
   161
apply (unfold rconf_def)
schirmer@13688
   162
by simp
schirmer@13688
   163
schirmer@12854
   164
lemma rconf_In3 [simp]: 
schirmer@12854
   165
 "G,L,s\<turnstile>In3 es\<succ>In3 vs\<Colon>\<preceq>Inr Ts = list_all2 (\<lambda>v T. G,s\<turnstile>v\<Colon>\<preceq>T) vs Ts"
schirmer@12854
   166
apply (unfold rconf_def)
schirmer@12854
   167
apply (simp (no_asm))
schirmer@12854
   168
done
schirmer@12854
   169
schirmer@12854
   170
section "fits and conf"
schirmer@12854
   171
schirmer@12854
   172
(* unused *)
schirmer@12854
   173
lemma conf_fits: "G,s\<turnstile>v\<Colon>\<preceq>T \<Longrightarrow> G,s\<turnstile>v fits T"
schirmer@12854
   174
apply (unfold fits_def)
schirmer@12854
   175
apply clarify
wenzelm@18585
   176
apply (erule contrapos_np, simp (no_asm_use))
schirmer@12854
   177
apply (drule conf_RefTD)
schirmer@12854
   178
apply auto
schirmer@12854
   179
done
schirmer@12854
   180
schirmer@12854
   181
lemma fits_conf: 
schirmer@12854
   182
  "\<lbrakk>G,s\<turnstile>v\<Colon>\<preceq>T; G\<turnstile>T\<preceq>? T'; G,s\<turnstile>v fits T'; ws_prog G\<rbrakk> \<Longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>T'"
schirmer@12854
   183
apply (auto dest!: fitsD cast_PrimT2 cast_RefT2)
schirmer@12854
   184
apply (force dest: conf_RefTD intro: conf_AddrI)
schirmer@12854
   185
done
schirmer@12854
   186
schirmer@12854
   187
lemma fits_Array: 
schirmer@12854
   188
 "\<lbrakk>G,s\<turnstile>v\<Colon>\<preceq>T; G\<turnstile>T'.[]\<preceq>T.[]; G,s\<turnstile>v fits T'; ws_prog G\<rbrakk> \<Longrightarrow> G,s\<turnstile>v\<Colon>\<preceq>T'"
schirmer@12854
   189
apply (auto dest!: fitsD widen_ArrayPrimT widen_ArrayRefT)
schirmer@12854
   190
apply (force dest: conf_RefTD intro: conf_AddrI)
schirmer@12854
   191
done
schirmer@12854
   192
schirmer@12854
   193
schirmer@12854
   194
schirmer@12854
   195
section "gext"
schirmer@12854
   196
schirmer@12854
   197
lemma halloc_gext: "\<And>s1 s2. G\<turnstile>s1 \<midarrow>halloc oi\<succ>a\<rightarrow> s2 \<Longrightarrow> snd s1\<le>|snd s2"
schirmer@12854
   198
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   199
apply (erule halloc.induct)
schirmer@12854
   200
apply  (auto dest!: new_AddrD)
schirmer@12854
   201
done
schirmer@12854
   202
schirmer@12854
   203
lemma sxalloc_gext: "\<And>s1 s2. G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2 \<Longrightarrow> snd s1\<le>|snd s2"
schirmer@12854
   204
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   205
apply (erule sxalloc.induct)
schirmer@12854
   206
apply   (auto dest!: halloc_gext)
schirmer@12854
   207
done
schirmer@12854
   208
schirmer@12854
   209
lemma eval_gext_lemma [rule_format (no_asm)]: 
schirmer@12854
   210
 "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w,s') \<Longrightarrow> snd s\<le>|snd s' \<and> (case w of  
schirmer@12854
   211
    In1 v \<Rightarrow> True  
schirmer@12854
   212
  | In2 vf \<Rightarrow> normal s \<longrightarrow> (\<forall>v x s. s\<le>|snd (assign (snd vf) v (x,s)))  
schirmer@12854
   213
  | In3 vs \<Rightarrow> True)"
schirmer@12854
   214
apply (erule eval_induct)
schirmer@13337
   215
prefer 26 
schirmer@12854
   216
  apply (case_tac "inited C (globs s0)", clarsimp, erule thin_rl) (* Init *)
schirmer@12854
   217
apply (auto del: conjI  dest!: not_initedD gext_new sxalloc_gext halloc_gext
schirmer@12925
   218
 simp  add: lvar_def fvar_def2 avar_def2 init_lvars_def2 
schirmer@12925
   219
            check_field_access_def check_method_access_def Let_def
schirmer@12854
   220
 split del: split_if_asm split add: sum3.split)
schirmer@12854
   221
(* 6 subgoals *)
schirmer@12854
   222
apply force+
schirmer@12854
   223
done
schirmer@12854
   224
schirmer@12854
   225
lemma evar_gext_f: 
schirmer@12854
   226
  "G\<turnstile>Norm s1 \<midarrow>e=\<succ>vf \<rightarrow> s2 \<Longrightarrow> s\<le>|snd (assign (snd vf) v (x,s))"
schirmer@12854
   227
apply (drule eval_gext_lemma [THEN conjunct2])
schirmer@12854
   228
apply auto
schirmer@12854
   229
done
schirmer@12854
   230
schirmer@12854
   231
lemmas eval_gext = eval_gext_lemma [THEN conjunct1]
schirmer@12854
   232
berghofe@21765
   233
lemma eval_gext': "G\<turnstile>(x1,s1) \<midarrow>t\<succ>\<rightarrow> (w,(x2,s2)) \<Longrightarrow> s1\<le>|s2"
schirmer@12854
   234
apply (drule eval_gext)
schirmer@12854
   235
apply auto
schirmer@12854
   236
done
schirmer@12854
   237
schirmer@12854
   238
lemma init_yields_initd: "G\<turnstile>Norm s1 \<midarrow>Init C\<rightarrow> s2 \<Longrightarrow> initd C s2"
schirmer@12854
   239
apply (erule eval_cases , auto split del: split_if_asm)
schirmer@12854
   240
apply (case_tac "inited C (globs s1)")
schirmer@12854
   241
apply  (clarsimp split del: split_if_asm)+
schirmer@12854
   242
apply (drule eval_gext')+
schirmer@12854
   243
apply (drule init_class_obj_inited)
schirmer@12854
   244
apply (erule inited_gext)
schirmer@12854
   245
apply (simp (no_asm_use))
schirmer@12854
   246
done
schirmer@12854
   247
schirmer@12854
   248
schirmer@12854
   249
section "Lemmas"
schirmer@12854
   250
schirmer@12854
   251
lemma obj_ty_obj_class1: 
schirmer@12854
   252
 "\<lbrakk>wf_prog G; is_type G (obj_ty obj)\<rbrakk> \<Longrightarrow> is_class G (obj_class obj)"
schirmer@12854
   253
apply (case_tac "tag obj")
schirmer@12854
   254
apply (auto simp add: obj_ty_def obj_class_def)
schirmer@12854
   255
done
schirmer@12854
   256
schirmer@12854
   257
lemma oconf_init_obj: 
schirmer@12854
   258
 "\<lbrakk>wf_prog G;  
schirmer@12854
   259
 (case r of Heap a \<Rightarrow> is_type G (obj_ty obj) | Stat C \<Rightarrow> is_class G C)
schirmer@12854
   260
\<rbrakk> \<Longrightarrow> G,s\<turnstile>obj \<lparr>values:=init_vals (var_tys G (tag obj) r)\<rparr>\<Colon>\<preceq>\<surd>r"
schirmer@12854
   261
apply (auto intro!: oconf_init_obj_lemma unique_fields)
schirmer@12854
   262
done
schirmer@12854
   263
schirmer@12854
   264
lemma conforms_newG: "\<lbrakk>globs s oref = None; (x, s)\<Colon>\<preceq>(G,L);   
schirmer@12854
   265
  wf_prog G; case oref of Heap a \<Rightarrow> is_type G (obj_ty \<lparr>tag=oi,values=vs\<rparr>)  
schirmer@12854
   266
                        | Stat C \<Rightarrow> is_class G C\<rbrakk> \<Longrightarrow>  
schirmer@12854
   267
  (x, init_obj G oi oref s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   268
apply (unfold init_obj_def)
schirmer@12854
   269
apply (auto elim!: conforms_gupd dest!: oconf_init_obj 
schirmer@15217
   270
            )
schirmer@12854
   271
done
schirmer@12854
   272
schirmer@12854
   273
lemma conforms_init_class_obj: 
schirmer@12854
   274
 "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L); wf_prog G; class G C=Some y; \<not> inited C (globs s)\<rbrakk> \<Longrightarrow> 
schirmer@12854
   275
  (x,init_class_obj G C s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   276
apply (rule not_initedD [THEN conforms_newG])
schirmer@12854
   277
apply    (auto)
schirmer@12854
   278
done
schirmer@12854
   279
schirmer@12854
   280
schirmer@12854
   281
lemma fst_init_lvars[simp]: 
schirmer@12854
   282
 "fst (init_lvars G C sig (invmode m e) a' pvs (x,s)) = 
schirmer@12925
   283
  (if is_static m then x else (np a') x)"
schirmer@12854
   284
apply (simp (no_asm) add: init_lvars_def2)
schirmer@12854
   285
done
schirmer@12854
   286
schirmer@12854
   287
schirmer@12854
   288
lemma halloc_conforms: "\<And>s1. \<lbrakk>G\<turnstile>s1 \<midarrow>halloc oi\<succ>a\<rightarrow> s2; wf_prog G; s1\<Colon>\<preceq>(G, L); 
schirmer@12854
   289
  is_type G (obj_ty \<lparr>tag=oi,values=fs\<rparr>)\<rbrakk> \<Longrightarrow> s2\<Colon>\<preceq>(G, L)"
schirmer@12854
   290
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   291
apply (case_tac "aa")
schirmer@12854
   292
apply  (auto elim!: halloc_elim_cases dest!: new_AddrD 
schirmer@12854
   293
       intro!: conforms_newG [THEN conforms_xconf] conf_AddrI)
schirmer@12854
   294
done
schirmer@12854
   295
schirmer@12925
   296
lemma halloc_type_sound: 
schirmer@12925
   297
"\<And>s1. \<lbrakk>G\<turnstile>s1 \<midarrow>halloc oi\<succ>a\<rightarrow> (x,s); wf_prog G; s1\<Colon>\<preceq>(G, L);
schirmer@12854
   298
  T = obj_ty \<lparr>tag=oi,values=fs\<rparr>; is_type G T\<rbrakk> \<Longrightarrow>  
schirmer@12854
   299
  (x,s)\<Colon>\<preceq>(G, L) \<and> (x = None \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq>T)"
schirmer@12854
   300
apply (auto elim!: halloc_conforms)
schirmer@12854
   301
apply (case_tac "aa")
schirmer@12854
   302
apply (subst obj_ty_eq)
schirmer@12854
   303
apply  (auto elim!: halloc_elim_cases dest!: new_AddrD intro!: conf_AddrI)
schirmer@12854
   304
done
schirmer@12854
   305
schirmer@12854
   306
lemma sxalloc_type_sound: 
schirmer@13688
   307
 "\<And>s1 s2. \<lbrakk>G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2; wf_prog G\<rbrakk> \<Longrightarrow> 
schirmer@13688
   308
  case fst s1 of  
schirmer@13688
   309
    None \<Rightarrow> s2 = s1 
schirmer@13688
   310
  | Some abr \<Rightarrow> (case abr of
schirmer@13688
   311
                   Xcpt x \<Rightarrow> (\<exists>a. fst s2 = Some(Xcpt (Loc a)) \<and> 
schirmer@13688
   312
                                  (\<forall>L. s1\<Colon>\<preceq>(G,L) \<longrightarrow> s2\<Colon>\<preceq>(G,L)))
schirmer@13688
   313
                 | Jump j \<Rightarrow> s2 = s1
schirmer@13688
   314
                 | Error e \<Rightarrow> s2 = s1)"
schirmer@12854
   315
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   316
apply (erule sxalloc.induct)
schirmer@12854
   317
apply   auto
schirmer@12854
   318
apply (rule halloc_conforms [THEN conforms_xconf])
schirmer@12854
   319
apply     (auto elim!: halloc_elim_cases dest!: new_AddrD intro!: conf_AddrI)
schirmer@12854
   320
done
schirmer@12854
   321
schirmer@12854
   322
lemma wt_init_comp_ty: 
schirmer@12854
   323
"is_acc_type G (pid C) T \<Longrightarrow> \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>init_comp_ty T\<Colon>\<surd>"
schirmer@12854
   324
apply (unfold init_comp_ty_def)
schirmer@12854
   325
apply (clarsimp simp add: accessible_in_RefT_simp 
schirmer@12854
   326
                          is_acc_type_def is_acc_class_def)
schirmer@12854
   327
done
schirmer@12854
   328
schirmer@12854
   329
schirmer@12854
   330
declare fun_upd_same [simp]
schirmer@12854
   331
schirmer@12854
   332
declare fun_upd_apply [simp del]
schirmer@12854
   333
schirmer@12854
   334
schirmer@12854
   335
constdefs
schirmer@12854
   336
  DynT_prop::"[prog,inv_mode,qtname,ref_ty] \<Rightarrow> bool" 
schirmer@12854
   337
                                              ("_\<turnstile>_\<rightarrow>_\<preceq>_"[71,71,71,71]70)
schirmer@12854
   338
 "G\<turnstile>mode\<rightarrow>D\<preceq>t \<equiv> mode = IntVir \<longrightarrow> is_class G D \<and> 
schirmer@12854
   339
                     (if (\<exists>T. t=ArrayT T) then D=Object else G\<turnstile>Class D\<preceq>RefT t)"
schirmer@12854
   340
schirmer@12854
   341
lemma DynT_propI: 
schirmer@12854
   342
 "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L); G,s\<turnstile>a'\<Colon>\<preceq>RefT statT; wf_prog G; mode = IntVir \<longrightarrow> a' \<noteq> Null\<rbrakk> 
schirmer@12854
   343
  \<Longrightarrow>  G\<turnstile>mode\<rightarrow>invocation_class mode s a' statT\<preceq>statT"
schirmer@12854
   344
proof (unfold DynT_prop_def)
schirmer@12854
   345
  assume state_conform: "(x,s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   346
     and      statT_a': "G,s\<turnstile>a'\<Colon>\<preceq>RefT statT"
schirmer@12854
   347
     and            wf: "wf_prog G"
schirmer@12854
   348
     and          mode: "mode = IntVir \<longrightarrow> a' \<noteq> Null"
schirmer@12854
   349
  let ?invCls = "(invocation_class mode s a' statT)"
schirmer@12854
   350
  let ?IntVir = "mode = IntVir"
schirmer@12854
   351
  let ?Concl  = "\<lambda>invCls. is_class G invCls \<and>
schirmer@12854
   352
                          (if \<exists>T. statT = ArrayT T
schirmer@12854
   353
                                  then invCls = Object
schirmer@12854
   354
                                  else G\<turnstile>Class invCls\<preceq>RefT statT)"
schirmer@12854
   355
  show "?IntVir \<longrightarrow> ?Concl ?invCls"
schirmer@12854
   356
  proof  
schirmer@12854
   357
    assume modeIntVir: ?IntVir 
schirmer@12854
   358
    with mode have not_Null: "a' \<noteq> Null" ..
schirmer@12854
   359
    from statT_a' not_Null state_conform 
schirmer@12854
   360
    obtain a obj 
schirmer@12854
   361
      where obj_props:  "a' = Addr a" "globs s (Inl a) = Some obj"   
schirmer@12854
   362
                        "G\<turnstile>obj_ty obj\<preceq>RefT statT" "is_type G (obj_ty obj)"
schirmer@12854
   363
      by (blast dest: conforms_RefTD)
schirmer@12854
   364
    show "?Concl ?invCls"
schirmer@12854
   365
    proof (cases "tag obj")
schirmer@12854
   366
      case CInst
schirmer@12854
   367
      with modeIntVir obj_props
schirmer@12854
   368
      show ?thesis 
schirmer@12854
   369
	by (auto dest!: widen_Array2 split add: split_if)
schirmer@12854
   370
    next
schirmer@12854
   371
      case Arr
schirmer@12854
   372
      from Arr obtain T where "obj_ty obj = T.[]" by (blast dest: obj_ty_Arr1)
schirmer@12854
   373
      moreover from Arr have "obj_class obj = Object" 
schirmer@12854
   374
	by (blast dest: obj_class_Arr1)
schirmer@12854
   375
      moreover note modeIntVir obj_props wf 
schirmer@12854
   376
      ultimately show ?thesis by (auto dest!: widen_Array )
schirmer@12854
   377
    qed
schirmer@12854
   378
  qed
schirmer@12854
   379
qed
schirmer@12854
   380
schirmer@12854
   381
lemma invocation_methd:
schirmer@12854
   382
"\<lbrakk>wf_prog G; statT \<noteq> NullT; 
schirmer@12854
   383
 (\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC);
schirmer@12854
   384
 (\<forall>     I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> mode \<noteq> SuperM);
schirmer@12854
   385
 (\<forall>     T. statT = ArrayT T \<longrightarrow> mode \<noteq> SuperM);
schirmer@12854
   386
 G\<turnstile>mode\<rightarrow>invocation_class mode s a' statT\<preceq>statT;  
schirmer@12854
   387
 dynlookup G statT (invocation_class mode s a' statT) sig = Some m \<rbrakk> 
schirmer@12854
   388
\<Longrightarrow> methd G (invocation_declclass G mode s a' statT sig) sig = Some m"
schirmer@12854
   389
proof -
schirmer@12854
   390
  assume         wf: "wf_prog G"
schirmer@12854
   391
     and  not_NullT: "statT \<noteq> NullT"
schirmer@12854
   392
     and statC_prop: "(\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC)"
schirmer@12854
   393
     and statI_prop: "(\<forall> I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> mode \<noteq> SuperM)"
schirmer@12854
   394
     and statA_prop: "(\<forall>     T. statT = ArrayT T \<longrightarrow> mode \<noteq> SuperM)"
schirmer@12854
   395
     and  invC_prop: "G\<turnstile>mode\<rightarrow>invocation_class mode s a' statT\<preceq>statT"
schirmer@12854
   396
     and  dynlookup: "dynlookup G statT (invocation_class mode s a' statT) sig 
schirmer@12854
   397
                      = Some m"
schirmer@12854
   398
  show ?thesis
schirmer@12854
   399
  proof (cases statT)
schirmer@12854
   400
    case NullT
schirmer@12854
   401
    with not_NullT show ?thesis by simp
schirmer@12854
   402
  next
schirmer@12854
   403
    case IfaceT
schirmer@12854
   404
    with statI_prop obtain I 
schirmer@12854
   405
      where    statI: "statT = IfaceT I" and 
schirmer@12854
   406
            is_iface: "is_iface G I"     and
schirmer@12854
   407
          not_SuperM: "mode \<noteq> SuperM" by blast            
schirmer@12854
   408
    
schirmer@12854
   409
    show ?thesis 
schirmer@12854
   410
    proof (cases mode)
schirmer@12854
   411
      case Static
schirmer@12854
   412
      with wf dynlookup statI is_iface 
schirmer@12854
   413
      show ?thesis
schirmer@12854
   414
	by (auto simp add: invocation_declclass_def dynlookup_def 
schirmer@12854
   415
                           dynimethd_def dynmethd_C_C 
schirmer@12854
   416
	            intro: dynmethd_declclass
schirmer@12854
   417
	            dest!: wf_imethdsD
schirmer@12854
   418
                     dest: table_of_map_SomeI
schirmer@12854
   419
                    split: split_if_asm)
schirmer@12854
   420
    next	
schirmer@12854
   421
      case SuperM
schirmer@12854
   422
      with not_SuperM show ?thesis ..
schirmer@12854
   423
    next
schirmer@12854
   424
      case IntVir
schirmer@12854
   425
      with wf dynlookup IfaceT invC_prop show ?thesis 
schirmer@12854
   426
	by (auto simp add: invocation_declclass_def dynlookup_def dynimethd_def
schirmer@12854
   427
                           DynT_prop_def
schirmer@12854
   428
	            intro: methd_declclass dynmethd_declclass
schirmer@12854
   429
	            split: split_if_asm)
schirmer@12854
   430
    qed
schirmer@12854
   431
  next
schirmer@12854
   432
    case ClassT
schirmer@12854
   433
    show ?thesis
schirmer@12854
   434
    proof (cases mode)
schirmer@12854
   435
      case Static
schirmer@12854
   436
      with wf ClassT dynlookup statC_prop 
schirmer@12854
   437
      show ?thesis by (auto simp add: invocation_declclass_def dynlookup_def
schirmer@12854
   438
                               intro: dynmethd_declclass)
schirmer@12854
   439
    next
schirmer@12854
   440
      case SuperM
schirmer@12854
   441
      with wf ClassT dynlookup statC_prop 
schirmer@12854
   442
      show ?thesis by (auto simp add: invocation_declclass_def dynlookup_def
schirmer@12854
   443
                               intro: dynmethd_declclass)
schirmer@12854
   444
    next
schirmer@12854
   445
      case IntVir
schirmer@12854
   446
      with wf ClassT dynlookup statC_prop invC_prop 
schirmer@12854
   447
      show ?thesis
schirmer@12854
   448
	by (auto simp add: invocation_declclass_def dynlookup_def dynimethd_def
schirmer@12854
   449
                           DynT_prop_def
schirmer@12854
   450
	            intro: dynmethd_declclass)
schirmer@12854
   451
    qed
schirmer@12854
   452
  next
schirmer@12854
   453
    case ArrayT
schirmer@12854
   454
    show ?thesis
schirmer@12854
   455
    proof (cases mode)
schirmer@12854
   456
      case Static
schirmer@12854
   457
      with wf ArrayT dynlookup show ?thesis
schirmer@12854
   458
	by (auto simp add: invocation_declclass_def dynlookup_def 
schirmer@12854
   459
                           dynimethd_def dynmethd_C_C
schirmer@12854
   460
                    intro: dynmethd_declclass
schirmer@12854
   461
                     dest: table_of_map_SomeI)
schirmer@12854
   462
    next
schirmer@12854
   463
      case SuperM
schirmer@12854
   464
      with ArrayT statA_prop show ?thesis by blast
schirmer@12854
   465
    next
schirmer@12854
   466
      case IntVir
schirmer@12854
   467
      with wf ArrayT dynlookup invC_prop show ?thesis
schirmer@12854
   468
	by (auto simp add: invocation_declclass_def dynlookup_def dynimethd_def
schirmer@12854
   469
                           DynT_prop_def dynmethd_C_C
schirmer@12854
   470
                    intro: dynmethd_declclass
schirmer@12854
   471
                     dest: table_of_map_SomeI)
schirmer@12854
   472
    qed
schirmer@12854
   473
  qed
schirmer@12854
   474
qed
schirmer@12925
   475
schirmer@12854
   476
lemma DynT_mheadsD: 
schirmer@12925
   477
"\<lbrakk>G\<turnstile>invmode sm e\<rightarrow>invC\<preceq>statT; 
schirmer@12854
   478
  wf_prog G; \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT; 
schirmer@12925
   479
  (statDeclT,sm) \<in> mheads G C statT sig; 
schirmer@12925
   480
  invC = invocation_class (invmode sm e) s a' statT;
schirmer@12925
   481
  declC =invocation_declclass G (invmode sm e) s a' statT sig
schirmer@12854
   482
 \<rbrakk> \<Longrightarrow> 
schirmer@12854
   483
  \<exists> dm. 
schirmer@12925
   484
  methd G declC sig = Some dm \<and> dynlookup G statT invC sig = Some dm  \<and> 
schirmer@12925
   485
  G\<turnstile>resTy (mthd dm)\<preceq>resTy sm \<and> 
schirmer@12854
   486
  wf_mdecl G declC (sig, mthd dm) \<and>
schirmer@12854
   487
  declC = declclass dm \<and>
schirmer@12854
   488
  is_static dm = is_static sm \<and>  
schirmer@12854
   489
  is_class G invC \<and> is_class G declC  \<and> G\<turnstile>invC\<preceq>\<^sub>C declC \<and>  
schirmer@12925
   490
  (if invmode sm e = IntVir
schirmer@12854
   491
      then (\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)
schirmer@12854
   492
      else (  (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   493
            \<or> (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object)) \<and> 
schirmer@12925
   494
            statDeclT = ClassT (declclass dm))"
schirmer@12854
   495
proof -
schirmer@12925
   496
  assume invC_prop: "G\<turnstile>invmode sm e\<rightarrow>invC\<preceq>statT" 
schirmer@12854
   497
     and        wf: "wf_prog G" 
schirmer@12854
   498
     and      wt_e: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT"
schirmer@12925
   499
     and        sm: "(statDeclT,sm) \<in> mheads G C statT sig" 
schirmer@12925
   500
     and      invC: "invC = invocation_class (invmode sm e) s a' statT"
schirmer@12854
   501
     and     declC: "declC = 
schirmer@12925
   502
                    invocation_declclass G (invmode sm e) s a' statT sig"
schirmer@12854
   503
  from wt_e wf have type_statT: "is_type G (RefT statT)"
schirmer@12854
   504
    by (auto dest: ty_expr_is_type)
schirmer@12854
   505
  from sm have not_Null: "statT \<noteq> NullT" by auto
schirmer@12854
   506
  from type_statT 
schirmer@12854
   507
  have wf_C: "(\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC)"
schirmer@12854
   508
    by (auto)
schirmer@12854
   509
  from type_statT wt_e 
schirmer@12854
   510
  have wf_I: "(\<forall>I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> 
schirmer@12925
   511
                                        invmode sm e \<noteq> SuperM)"
schirmer@12854
   512
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   513
  from wt_e
schirmer@12925
   514
  have wf_A: "(\<forall>     T. statT = ArrayT T \<longrightarrow> invmode sm e \<noteq> SuperM)"
schirmer@12854
   515
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   516
  show ?thesis
schirmer@12925
   517
  proof (cases "invmode sm e = IntVir")
schirmer@12854
   518
    case True
schirmer@12854
   519
    with invC_prop not_Null
schirmer@12854
   520
    have invC_prop': " is_class G invC \<and> 
schirmer@12854
   521
                      (if (\<exists>T. statT=ArrayT T) then invC=Object 
schirmer@12854
   522
                                              else G\<turnstile>Class invC\<preceq>RefT statT)"
schirmer@12854
   523
      by (auto simp add: DynT_prop_def) 
schirmer@12854
   524
    from True 
schirmer@12854
   525
    have "\<not> is_static sm"
schirmer@12925
   526
      by (simp add: invmode_IntVir_eq member_is_static_simp)
schirmer@12854
   527
    with invC_prop' not_Null
schirmer@12854
   528
    have "G,statT \<turnstile> invC valid_lookup_cls_for (is_static sm)"
schirmer@12854
   529
      by (cases statT) auto
schirmer@12854
   530
    with sm wf type_statT obtain dm where
schirmer@12854
   531
           dm: "dynlookup G statT invC sig = Some dm" and
schirmer@12925
   532
      resT_dm: "G\<turnstile>resTy (mthd dm)\<preceq>resTy sm"      and
schirmer@12854
   533
       static: "is_static dm = is_static sm"
schirmer@12925
   534
      by  - (drule dynamic_mheadsD,force+)
schirmer@12854
   535
    with declC invC not_Null 
schirmer@12854
   536
    have declC': "declC = (declclass dm)" 
schirmer@12854
   537
      by (auto simp add: invocation_declclass_def)
schirmer@12854
   538
    with wf invC declC not_Null wf_C wf_I wf_A invC_prop dm 
schirmer@12854
   539
    have dm': "methd G declC sig = Some dm"
schirmer@12854
   540
      by - (drule invocation_methd,auto)
schirmer@12854
   541
    from wf dm invC_prop' declC' type_statT 
schirmer@12854
   542
    have declC_prop: "G\<turnstile>invC \<preceq>\<^sub>C declC \<and> is_class G declC"
schirmer@12854
   543
      by (auto dest: dynlookup_declC)
schirmer@12854
   544
    from wf dm' declC_prop declC' 
schirmer@12854
   545
    have wf_dm: "wf_mdecl G declC (sig,(mthd dm))"
schirmer@12854
   546
      by (auto dest: methd_wf_mdecl)
schirmer@12854
   547
    from invC_prop' 
schirmer@12854
   548
    have statC_prop: "(\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)"
schirmer@12854
   549
      by auto
schirmer@12854
   550
    from True dm' resT_dm wf_dm invC_prop' declC_prop statC_prop declC' static
schirmer@12925
   551
         dm
schirmer@12854
   552
    show ?thesis by auto
schirmer@12854
   553
  next
schirmer@12854
   554
    case False
schirmer@12854
   555
    with type_statT wf invC not_Null wf_I wf_A
schirmer@12854
   556
    have invC_prop': "is_class G invC \<and>  
schirmer@12854
   557
                     ((\<exists> statC. statT=ClassT statC \<and> invC=statC) \<or>
schirmer@12925
   558
                      (\<forall> statC. statT\<noteq>ClassT statC \<and> invC=Object))"
schirmer@12854
   559
        by (case_tac "statT") (auto simp add: invocation_class_def 
schirmer@12854
   560
                                       split: inv_mode.splits)
schirmer@12854
   561
    with not_Null wf
schirmer@12854
   562
    have dynlookup_static: "dynlookup G statT invC sig = methd G invC sig"
schirmer@12854
   563
      by (case_tac "statT") (auto simp add: dynlookup_def dynmethd_C_C
schirmer@12854
   564
                                            dynimethd_def)
schirmer@12854
   565
    from sm wf wt_e not_Null False invC_prop' obtain "dm" where
schirmer@12854
   566
                    dm: "methd G invC sig = Some dm"          and
schirmer@12925
   567
	eq_declC_sm_dm:"statDeclT = ClassT (declclass dm)"  and
schirmer@12925
   568
	     eq_mheads:"sm=mhead (mthd dm) "
schirmer@12925
   569
      by - (drule static_mheadsD, (force dest: accmethd_SomeD)+)
schirmer@12925
   570
    then have static: "is_static dm = is_static sm" by - (auto)
schirmer@12854
   571
    with declC invC dynlookup_static dm
schirmer@12854
   572
    have declC': "declC = (declclass dm)"  
schirmer@12854
   573
      by (auto simp add: invocation_declclass_def)
schirmer@12854
   574
    from invC_prop' wf declC' dm 
schirmer@12854
   575
    have dm': "methd G declC sig = Some dm"
schirmer@12854
   576
      by (auto intro: methd_declclass)
schirmer@12925
   577
    from dynlookup_static dm 
schirmer@12925
   578
    have dm'': "dynlookup G statT invC sig = Some dm"
schirmer@12925
   579
      by simp
schirmer@12854
   580
    from wf dm invC_prop' declC' type_statT 
schirmer@12854
   581
    have declC_prop: "G\<turnstile>invC \<preceq>\<^sub>C declC \<and> is_class G declC"
schirmer@12854
   582
      by (auto dest: methd_declC )
schirmer@12854
   583
    then have declC_prop1: "invC=Object \<longrightarrow> declC=Object"  by auto
schirmer@12854
   584
    from wf dm' declC_prop declC' 
schirmer@12854
   585
    have wf_dm: "wf_mdecl G declC (sig,(mthd dm))"
schirmer@12854
   586
      by (auto dest: methd_wf_mdecl)
schirmer@12854
   587
    from invC_prop' declC_prop declC_prop1
schirmer@12854
   588
    have statC_prop: "(   (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   589
                       \<or>  (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object))" 
schirmer@12854
   590
      by auto
schirmer@12925
   591
    from False dm' dm'' wf_dm invC_prop' declC_prop statC_prop declC' 
schirmer@12854
   592
         eq_declC_sm_dm eq_mheads static
schirmer@12854
   593
    show ?thesis by auto
schirmer@12854
   594
  qed
schirmer@13688
   595
qed
schirmer@13688
   596
schirmer@13688
   597
corollary DynT_mheadsE [consumes 7]: 
schirmer@13688
   598
--{* Same as @{text DynT_mheadsD} but better suited for application in 
schirmer@13688
   599
typesafety proof   *}
schirmer@13688
   600
 assumes invC_compatible: "G\<turnstile>mode\<rightarrow>invC\<preceq>statT" 
schirmer@13688
   601
     and wf: "wf_prog G" 
schirmer@13688
   602
     and wt_e: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT"
schirmer@13688
   603
     and mheads: "(statDeclT,sm) \<in> mheads G C statT sig"
schirmer@13688
   604
     and mode: "mode=invmode sm e" 
schirmer@13688
   605
     and invC: "invC = invocation_class mode s a' statT"
schirmer@13688
   606
     and declC: "declC =invocation_declclass G mode s a' statT sig"
schirmer@13688
   607
     and dm: "\<And> dm. \<lbrakk>methd G declC sig = Some dm; 
schirmer@13688
   608
                      dynlookup G statT invC sig = Some dm; 
schirmer@13688
   609
                      G\<turnstile>resTy (mthd dm)\<preceq>resTy sm; 
schirmer@13688
   610
                      wf_mdecl G declC (sig, mthd dm);
schirmer@13688
   611
                      declC = declclass dm;
schirmer@13688
   612
                      is_static dm = is_static sm;  
schirmer@13688
   613
                      is_class G invC; is_class G declC; G\<turnstile>invC\<preceq>\<^sub>C declC;  
schirmer@13688
   614
                      (if invmode sm e = IntVir
schirmer@13688
   615
                      then (\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)
schirmer@13688
   616
                      else (  (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@13688
   617
                             \<or> (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object)) \<and>
schirmer@13688
   618
                             statDeclT = ClassT (declclass dm))\<rbrakk> \<Longrightarrow> P"
schirmer@13688
   619
   shows "P"
schirmer@13688
   620
proof -
schirmer@13688
   621
    from invC_compatible mode have "G\<turnstile>invmode sm e\<rightarrow>invC\<preceq>statT" by simp 
schirmer@13688
   622
    moreover note wf wt_e mheads
schirmer@13688
   623
    moreover from invC mode 
schirmer@13688
   624
    have "invC = invocation_class (invmode sm e) s a' statT" by simp
schirmer@13688
   625
    moreover from declC mode 
schirmer@13688
   626
    have "declC =invocation_declclass G (invmode sm e) s a' statT sig" by simp
schirmer@13688
   627
    ultimately show ?thesis
schirmer@13688
   628
      by (rule DynT_mheadsD [THEN exE,rule_format])
schirmer@13688
   629
         (elim conjE,rule dm)
schirmer@13688
   630
qed
schirmer@13688
   631
   
schirmer@12854
   632
schirmer@12854
   633
lemma DynT_conf: "\<lbrakk>G\<turnstile>invocation_class mode s a' statT \<preceq>\<^sub>C declC; wf_prog G;
schirmer@12854
   634
 isrtype G (statT);
schirmer@12854
   635
 G,s\<turnstile>a'\<Colon>\<preceq>RefT statT; mode = IntVir \<longrightarrow> a' \<noteq> Null;  
schirmer@12854
   636
  mode \<noteq> IntVir \<longrightarrow>    (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   637
                    \<or>  (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object)\<rbrakk> 
schirmer@12854
   638
 \<Longrightarrow>G,s\<turnstile>a'\<Colon>\<preceq> Class declC"
schirmer@12854
   639
apply (case_tac "mode = IntVir")
schirmer@12854
   640
apply (drule conf_RefTD)
schirmer@12854
   641
apply (force intro!: conf_AddrI 
schirmer@12854
   642
            simp add: obj_class_def split add: obj_tag.split_asm)
schirmer@12854
   643
apply  clarsimp
schirmer@12854
   644
apply  safe
schirmer@12854
   645
apply    (erule (1) widen.subcls [THEN conf_widen])
schirmer@12854
   646
apply    (erule wf_ws_prog)
schirmer@12854
   647
schirmer@12854
   648
apply    (frule widen_Object) apply (erule wf_ws_prog)
schirmer@12854
   649
apply    (erule (1) conf_widen) apply (erule wf_ws_prog)
schirmer@12854
   650
done
schirmer@12854
   651
schirmer@12925
   652
lemma Ass_lemma:
schirmer@12925
   653
"\<lbrakk> G\<turnstile>Norm s0 \<midarrow>var=\<succ>(w, f)\<rightarrow> Norm s1; G\<turnstile>Norm s1 \<midarrow>e-\<succ>v\<rightarrow> Norm s2;
schirmer@12925
   654
   G,s2\<turnstile>v\<Colon>\<preceq>eT;s1\<le>|s2 \<longrightarrow> assign f v (Norm s2)\<Colon>\<preceq>(G, L)\<rbrakk>
schirmer@12925
   655
\<Longrightarrow> assign f v (Norm s2)\<Colon>\<preceq>(G, L) \<and>
schirmer@12925
   656
      (normal (assign f v (Norm s2)) \<longrightarrow> G,store (assign f v (Norm s2))\<turnstile>v\<Colon>\<preceq>eT)"
schirmer@12854
   657
apply (drule_tac x = "None" and s = "s2" and v = "v" in evar_gext_f)
schirmer@12854
   658
apply (drule eval_gext', clarsimp)
schirmer@12854
   659
apply (erule conf_gext)
schirmer@12854
   660
apply simp
schirmer@12854
   661
done
schirmer@12854
   662
schirmer@12854
   663
lemma Throw_lemma: "\<lbrakk>G\<turnstile>tn\<preceq>\<^sub>C SXcpt Throwable; wf_prog G; (x1,s1)\<Colon>\<preceq>(G, L);  
schirmer@12854
   664
    x1 = None \<longrightarrow> G,s1\<turnstile>a'\<Colon>\<preceq> Class tn\<rbrakk> \<Longrightarrow> (throw a' x1, s1)\<Colon>\<preceq>(G, L)"
schirmer@12854
   665
apply (auto split add: split_abrupt_if simp add: throw_def2)
schirmer@12854
   666
apply (erule conforms_xconf)
schirmer@12854
   667
apply (frule conf_RefTD)
schirmer@12854
   668
apply (auto elim: widen.subcls [THEN conf_widen])
schirmer@12854
   669
done
schirmer@12854
   670
schirmer@12854
   671
lemma Try_lemma: "\<lbrakk>G\<turnstile>obj_ty (the (globs s1' (Heap a)))\<preceq> Class tn; 
schirmer@12854
   672
 (Some (Xcpt (Loc a)), s1')\<Colon>\<preceq>(G, L); wf_prog G\<rbrakk> 
schirmer@12854
   673
 \<Longrightarrow> Norm (lupd(vn\<mapsto>Addr a) s1')\<Colon>\<preceq>(G, L(vn\<mapsto>Class tn))"
schirmer@12854
   674
apply (rule conforms_allocL)
schirmer@12854
   675
apply  (erule conforms_NormI)
schirmer@12854
   676
apply (drule conforms_XcptLocD [THEN conf_RefTD],rule HOL.refl)
schirmer@12854
   677
apply (auto intro!: conf_AddrI)
schirmer@12854
   678
done
schirmer@12854
   679
schirmer@12854
   680
lemma Fin_lemma: 
schirmer@13688
   681
"\<lbrakk>G\<turnstile>Norm s1 \<midarrow>c2\<rightarrow> (x2,s2); wf_prog G; (Some a, s1)\<Colon>\<preceq>(G, L); (x2,s2)\<Colon>\<preceq>(G, L);
schirmer@13688
   682
  dom (locals s1) \<subseteq> dom (locals s2)\<rbrakk> 
schirmer@12854
   683
\<Longrightarrow>  (abrupt_if True (Some a) x2, s2)\<Colon>\<preceq>(G, L)"
schirmer@13688
   684
apply (auto elim: eval_gext' conforms_xgext split add: split_abrupt_if)
schirmer@12854
   685
done
schirmer@12854
   686
schirmer@12925
   687
lemma FVar_lemma1: 
schirmer@12925
   688
"\<lbrakk>table_of (DeclConcepts.fields G statC) (fn, statDeclC) = Some f ; 
schirmer@12925
   689
  x2 = None \<longrightarrow> G,s2\<turnstile>a\<Colon>\<preceq> Class statC; wf_prog G; G\<turnstile>statC\<preceq>\<^sub>C statDeclC; 
schirmer@12925
   690
  statDeclC \<noteq> Object; 
schirmer@12925
   691
  class G statDeclC = Some y; (x2,s2)\<Colon>\<preceq>(G, L); s1\<le>|s2; 
schirmer@12925
   692
  inited statDeclC (globs s1); 
schirmer@12854
   693
  (if static f then id else np a) x2 = None\<rbrakk> 
schirmer@12854
   694
 \<Longrightarrow>  
schirmer@12925
   695
  \<exists>obj. globs s2 (if static f then Inr statDeclC else Inl (the_Addr a)) 
schirmer@12925
   696
                  = Some obj \<and> 
schirmer@12925
   697
  var_tys G (tag obj)  (if static f then Inr statDeclC else Inl(the_Addr a)) 
schirmer@12925
   698
          (Inl(fn,statDeclC)) = Some (type f)"
schirmer@12854
   699
apply (drule initedD)
schirmer@12854
   700
apply (frule subcls_is_class2, simp (no_asm_simp))
schirmer@12854
   701
apply (case_tac "static f")
schirmer@12854
   702
apply  clarsimp
schirmer@12854
   703
apply  (drule (1) rev_gext_objD, clarsimp)
schirmer@12854
   704
apply  (frule fields_declC, erule wf_ws_prog, simp (no_asm_simp))
schirmer@12854
   705
apply  (rule var_tys_Some_eq [THEN iffD2])
schirmer@12854
   706
apply  clarsimp
schirmer@12854
   707
apply  (erule fields_table_SomeI, simp (no_asm))
schirmer@12854
   708
apply clarsimp
schirmer@12854
   709
apply (drule conf_RefTD, clarsimp, rule var_tys_Some_eq [THEN iffD2])
schirmer@12854
   710
apply (auto dest!: widen_Array split add: obj_tag.split)
schirmer@12854
   711
apply (rule fields_table_SomeI)
schirmer@12854
   712
apply (auto elim!: fields_mono subcls_is_class2)
schirmer@12854
   713
done
schirmer@12854
   714
schirmer@12925
   715
lemma FVar_lemma2: "error_free state
schirmer@12925
   716
       \<Longrightarrow> error_free
schirmer@12925
   717
           (assign
schirmer@12925
   718
             (\<lambda>v. supd
schirmer@12925
   719
                   (upd_gobj
schirmer@12925
   720
                     (if static field then Inr statDeclC
schirmer@12925
   721
                      else Inl (the_Addr a))
schirmer@12925
   722
                     (Inl (fn, statDeclC)) v))
schirmer@12925
   723
             w state)"
schirmer@12925
   724
proof -
schirmer@12925
   725
  assume error_free: "error_free state"
schirmer@12925
   726
  obtain a s where "state=(a,s)"
wenzelm@23350
   727
    by (cases state)
schirmer@12925
   728
  with error_free
schirmer@12925
   729
  show ?thesis
schirmer@12925
   730
    by (cases a) auto
schirmer@12925
   731
qed
schirmer@12925
   732
schirmer@12925
   733
declare split_paired_All [simp del] split_paired_Ex [simp del] 
schirmer@12925
   734
declare split_if     [split del] split_if_asm     [split del] 
schirmer@12925
   735
        option.split [split del] option.split_asm [split del]
schirmer@12925
   736
ML_setup {*
wenzelm@17876
   737
change_simpset (fn ss => ss delloop "split_all_tac");
wenzelm@17876
   738
change_claset (fn cs => cs delSWrapper "split_all_tac");
schirmer@12925
   739
*}
schirmer@12854
   740
lemma FVar_lemma: 
schirmer@12925
   741
"\<lbrakk>((v, f), Norm s2') = fvar statDeclC (static field) fn a (x2, s2); 
schirmer@12925
   742
  G\<turnstile>statC\<preceq>\<^sub>C statDeclC;  
schirmer@12925
   743
  table_of (DeclConcepts.fields G statC) (fn, statDeclC) = Some field; 
schirmer@12925
   744
  wf_prog G;   
schirmer@12925
   745
  x2 = None \<longrightarrow> G,s2\<turnstile>a\<Colon>\<preceq>Class statC; 
schirmer@12925
   746
  statDeclC \<noteq> Object; class G statDeclC = Some y;   
schirmer@12925
   747
  (x2, s2)\<Colon>\<preceq>(G, L); s1\<le>|s2; inited statDeclC (globs s1)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   748
  G,s2'\<turnstile>v\<Colon>\<preceq>type field \<and> s2'\<le>|f\<preceq>type field\<Colon>\<preceq>(G, L)"
schirmer@12854
   749
apply (unfold assign_conforms_def)
schirmer@12854
   750
apply (drule sym)
schirmer@12854
   751
apply (clarsimp simp add: fvar_def2)
schirmer@12854
   752
apply (drule (9) FVar_lemma1)
schirmer@12854
   753
apply (clarsimp)
schirmer@12854
   754
apply (drule (2) conforms_globsD [THEN oconf_lconf, THEN lconfD])
schirmer@12854
   755
apply clarsimp
schirmer@12925
   756
apply (rule conjI)
schirmer@12925
   757
apply   clarsimp
schirmer@12925
   758
apply   (drule (1) rev_gext_objD)
schirmer@12925
   759
apply   (force elim!: conforms_upd_gobj)
schirmer@12925
   760
schirmer@12925
   761
apply   (blast intro: FVar_lemma2)
schirmer@12854
   762
done
schirmer@12925
   763
declare split_paired_All [simp] split_paired_Ex [simp] 
schirmer@12925
   764
declare split_if     [split] split_if_asm     [split] 
schirmer@12925
   765
        option.split [split] option.split_asm [split]
schirmer@12925
   766
ML_setup {*
wenzelm@17876
   767
change_claset (fn cs => cs addSbefore ("split_all_tac", split_all_tac));
wenzelm@17876
   768
change_simpset (fn ss => ss addloop ("split_all_tac", split_all_tac));
schirmer@12925
   769
*}
schirmer@12854
   770
schirmer@12854
   771
schirmer@12854
   772
lemma AVar_lemma1: "\<lbrakk>globs s (Inl a) = Some obj;tag obj=Arr ty i; 
schirmer@12854
   773
 the_Intg i' in_bounds i; wf_prog G; G\<turnstile>ty.[]\<preceq>Tb.[]; Norm s\<Colon>\<preceq>(G, L)
schirmer@12854
   774
\<rbrakk> \<Longrightarrow> G,s\<turnstile>the ((values obj) (Inr (the_Intg i')))\<Colon>\<preceq>Tb"
schirmer@12854
   775
apply (erule widen_Array_Array [THEN conf_widen])
schirmer@12854
   776
apply  (erule_tac [2] wf_ws_prog)
schirmer@12854
   777
apply (drule (1) conforms_globsD [THEN oconf_lconf, THEN lconfD])
schirmer@12854
   778
defer apply assumption
schirmer@12854
   779
apply (force intro: var_tys_Some_eq [THEN iffD2])
schirmer@12854
   780
done
schirmer@12854
   781
schirmer@14700
   782
lemma obj_split: "\<exists> t vs. obj = \<lparr>tag=t,values=vs\<rparr>"
schirmer@14700
   783
  by (cases obj) auto
schirmer@12854
   784
 
schirmer@12925
   785
lemma AVar_lemma2: "error_free state 
schirmer@12925
   786
       \<Longrightarrow> error_free
schirmer@12925
   787
           (assign
schirmer@12925
   788
             (\<lambda>v (x, s').
schirmer@12925
   789
                 ((raise_if (\<not> G,s'\<turnstile>v fits T) ArrStore) x,
schirmer@12925
   790
                  upd_gobj (Inl a) (Inr (the_Intg i)) v s'))
schirmer@12925
   791
             w state)"
schirmer@12925
   792
proof -
schirmer@12925
   793
  assume error_free: "error_free state"
schirmer@12925
   794
  obtain a s where "state=(a,s)"
wenzelm@23350
   795
    by (cases state)
schirmer@12925
   796
  with error_free
schirmer@12925
   797
  show ?thesis
schirmer@12925
   798
    by (cases a) auto
schirmer@12925
   799
qed
schirmer@12925
   800
schirmer@12854
   801
lemma AVar_lemma: "\<lbrakk>wf_prog G; G\<turnstile>(x1, s1) \<midarrow>e2-\<succ>i\<rightarrow> (x2, s2);  
schirmer@12854
   802
  ((v,f), Norm s2') = avar G i a (x2, s2); x1 = None \<longrightarrow> G,s1\<turnstile>a\<Colon>\<preceq>Ta.[];  
schirmer@12854
   803
  (x2, s2)\<Colon>\<preceq>(G, L); s1\<le>|s2\<rbrakk> \<Longrightarrow> G,s2'\<turnstile>v\<Colon>\<preceq>Ta \<and> s2'\<le>|f\<preceq>Ta\<Colon>\<preceq>(G, L)"
schirmer@12854
   804
apply (unfold assign_conforms_def)
schirmer@12854
   805
apply (drule sym)
schirmer@12854
   806
apply (clarsimp simp add: avar_def2)
schirmer@12854
   807
apply (drule (1) conf_gext)
schirmer@12854
   808
apply (drule conf_RefTD, clarsimp)
schirmer@12854
   809
apply (subgoal_tac "\<exists> t vs. obj = \<lparr>tag=t,values=vs\<rparr>")
schirmer@12854
   810
defer
schirmer@12854
   811
apply   (rule obj_split)
schirmer@12854
   812
apply clarify
schirmer@12854
   813
apply (frule obj_ty_widenD)
schirmer@12854
   814
apply (auto dest!: widen_Class)
schirmer@12925
   815
apply   (force dest: AVar_lemma1)
schirmer@12925
   816
schirmer@12925
   817
apply   (force elim!: fits_Array dest: gext_objD 
schirmer@12925
   818
         intro: var_tys_Some_eq [THEN iffD2] conforms_upd_gobj)
schirmer@12854
   819
done
schirmer@12854
   820
schirmer@13688
   821
schirmer@12925
   822
section "Call"
schirmer@12854
   823
schirmer@12854
   824
lemma conforms_init_lvars_lemma: "\<lbrakk>wf_prog G;  
schirmer@13688
   825
  wf_mhead G P sig mh;
schirmer@12854
   826
  list_all2 (conf G s) pvs pTsa; G\<turnstile>pTsa[\<preceq>](parTs sig)\<rbrakk> \<Longrightarrow>  
schirmer@13688
   827
  G,s\<turnstile>empty (pars mh[\<mapsto>]pvs)
schirmer@13688
   828
      [\<sim>\<Colon>\<preceq>]table_of lvars(pars mh[\<mapsto>]parTs sig)"
schirmer@12854
   829
apply (unfold wf_mhead_def)
schirmer@12854
   830
apply clarify
schirmer@13688
   831
apply (erule (1) wlconf_empty_vals [THEN wlconf_ext_list])
schirmer@12854
   832
apply (drule wf_ws_prog)
schirmer@12854
   833
apply (erule (2) conf_list_widen)
schirmer@12854
   834
done
schirmer@12854
   835
schirmer@12854
   836
schirmer@12854
   837
lemma lconf_map_lname [simp]: 
schirmer@12854
   838
  "G,s\<turnstile>(lname_case l1 l2)[\<Colon>\<preceq>](lname_case L1 L2)
schirmer@12854
   839
   =
schirmer@12854
   840
  (G,s\<turnstile>l1[\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>(\<lambda>x::unit . l2)[\<Colon>\<preceq>](\<lambda>x::unit. L2))"
schirmer@12854
   841
apply (unfold lconf_def)
schirmer@13688
   842
apply (auto split add: lname.splits)
schirmer@13688
   843
done
schirmer@13688
   844
schirmer@13688
   845
lemma wlconf_map_lname [simp]: 
schirmer@13688
   846
  "G,s\<turnstile>(lname_case l1 l2)[\<sim>\<Colon>\<preceq>](lname_case L1 L2)
schirmer@13688
   847
   =
schirmer@13688
   848
  (G,s\<turnstile>l1[\<sim>\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>(\<lambda>x::unit . l2)[\<sim>\<Colon>\<preceq>](\<lambda>x::unit. L2))"
schirmer@13688
   849
apply (unfold wlconf_def)
schirmer@13688
   850
apply (auto split add: lname.splits)
schirmer@12854
   851
done
schirmer@12854
   852
schirmer@12854
   853
lemma lconf_map_ename [simp]:
schirmer@12854
   854
  "G,s\<turnstile>(ename_case l1 l2)[\<Colon>\<preceq>](ename_case L1 L2)
schirmer@12854
   855
   =
schirmer@12854
   856
  (G,s\<turnstile>l1[\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>(\<lambda>x::unit. l2)[\<Colon>\<preceq>](\<lambda>x::unit. L2))"
schirmer@12854
   857
apply (unfold lconf_def)
schirmer@13688
   858
apply (auto split add: ename.splits)
schirmer@12854
   859
done
schirmer@12854
   860
schirmer@13688
   861
lemma wlconf_map_ename [simp]:
schirmer@13688
   862
  "G,s\<turnstile>(ename_case l1 l2)[\<sim>\<Colon>\<preceq>](ename_case L1 L2)
schirmer@13688
   863
   =
schirmer@13688
   864
  (G,s\<turnstile>l1[\<sim>\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>(\<lambda>x::unit. l2)[\<sim>\<Colon>\<preceq>](\<lambda>x::unit. L2))"
schirmer@13688
   865
apply (unfold wlconf_def)
schirmer@13688
   866
apply (auto split add: ename.splits)
schirmer@13688
   867
done
schirmer@13688
   868
schirmer@13688
   869
schirmer@12854
   870
schirmer@12854
   871
lemma defval_conf1 [rule_format (no_asm), elim]: 
schirmer@12854
   872
  "is_type G T \<longrightarrow> (\<exists>v\<in>Some (default_val T): G,s\<turnstile>v\<Colon>\<preceq>T)"
schirmer@12854
   873
apply (unfold conf_def)
schirmer@12854
   874
apply (induct "T")
schirmer@12854
   875
apply (auto intro: prim_ty.induct)
schirmer@12854
   876
done
schirmer@12854
   877
schirmer@13688
   878
lemma np_no_jump: "x\<noteq>Some (Jump j) \<Longrightarrow> (np a') x \<noteq> Some (Jump j)"
schirmer@13688
   879
by (auto simp add: abrupt_if_def)
schirmer@13688
   880
schirmer@12925
   881
declare split_paired_All [simp del] split_paired_Ex [simp del] 
schirmer@12925
   882
declare split_if     [split del] split_if_asm     [split del] 
schirmer@12925
   883
        option.split [split del] option.split_asm [split del]
schirmer@12925
   884
ML_setup {*
wenzelm@17876
   885
change_simpset (fn ss => ss delloop "split_all_tac");
wenzelm@17876
   886
change_claset (fn cs => cs delSWrapper "split_all_tac");
schirmer@12925
   887
*}
schirmer@12854
   888
lemma conforms_init_lvars: 
schirmer@12854
   889
"\<lbrakk>wf_mhead G (pid declC) sig (mhead (mthd dm)); wf_prog G;  
schirmer@12854
   890
  list_all2 (conf G s) pvs pTsa; G\<turnstile>pTsa[\<preceq>](parTs sig);  
schirmer@12854
   891
  (x, s)\<Colon>\<preceq>(G, L); 
schirmer@12854
   892
  methd G declC sig = Some dm;  
schirmer@12854
   893
  isrtype G statT;
schirmer@12854
   894
  G\<turnstile>invC\<preceq>\<^sub>C declC; 
schirmer@12854
   895
  G,s\<turnstile>a'\<Colon>\<preceq>RefT statT;  
schirmer@12854
   896
  invmode (mhd sm) e = IntVir \<longrightarrow> a' \<noteq> Null; 
schirmer@12854
   897
  invmode (mhd sm) e \<noteq> IntVir \<longrightarrow>  
schirmer@12854
   898
       (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   899
    \<or>  (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object);
schirmer@12854
   900
  invC  = invocation_class (invmode (mhd sm) e) s a' statT;
schirmer@12854
   901
  declC = invocation_declclass G (invmode (mhd sm) e) s a' statT sig;
schirmer@13688
   902
  x\<noteq>Some (Jump Ret) 
schirmer@12854
   903
 \<rbrakk> \<Longrightarrow>  
schirmer@12854
   904
  init_lvars G declC sig (invmode (mhd sm) e) a'  
schirmer@12854
   905
  pvs (x,s)\<Colon>\<preceq>(G,\<lambda> k. 
schirmer@12854
   906
                (case k of
schirmer@12854
   907
                   EName e \<Rightarrow> (case e of 
schirmer@12854
   908
                                 VNam v 
schirmer@12854
   909
                                  \<Rightarrow> (table_of (lcls (mbody (mthd dm)))
schirmer@12854
   910
                                        (pars (mthd dm)[\<mapsto>]parTs sig)) v
schirmer@12854
   911
                               | Res \<Rightarrow> Some (resTy (mthd dm)))
schirmer@12925
   912
                 | This \<Rightarrow> if (is_static (mthd sm)) 
schirmer@12854
   913
                              then None else Some (Class declC)))"
schirmer@12854
   914
apply (simp add: init_lvars_def2)
schirmer@12854
   915
apply (rule conforms_set_locals)
schirmer@12854
   916
apply  (simp (no_asm_simp) split add: split_if)
schirmer@12854
   917
apply (drule  (4) DynT_conf)
schirmer@12854
   918
apply clarsimp
schirmer@12854
   919
(* apply intro *)
schirmer@13688
   920
apply (drule (3) conforms_init_lvars_lemma 
schirmer@13688
   921
                 [where ?lvars="(lcls (mbody (mthd dm)))"])
schirmer@12854
   922
apply (case_tac "dm",simp)
schirmer@12854
   923
apply (rule conjI)
schirmer@13688
   924
apply (unfold wlconf_def, clarify)
schirmer@13688
   925
apply   (clarsimp simp add: wf_mhead_def is_acc_type_def)
schirmer@13688
   926
apply   (case_tac "is_static sm")
schirmer@13688
   927
apply     simp
schirmer@13688
   928
apply     simp
schirmer@13688
   929
schirmer@13688
   930
apply   simp
schirmer@13688
   931
apply   (case_tac "is_static sm")
schirmer@13688
   932
apply     simp
schirmer@13688
   933
apply     (simp add: np_no_jump)
schirmer@12854
   934
done
schirmer@12925
   935
declare split_paired_All [simp] split_paired_Ex [simp] 
schirmer@12925
   936
declare split_if     [split] split_if_asm     [split] 
schirmer@12925
   937
        option.split [split] option.split_asm [split]
schirmer@12925
   938
ML_setup {*
wenzelm@17876
   939
change_claset (fn cs => cs addSbefore ("split_all_tac", split_all_tac));
wenzelm@17876
   940
change_simpset (fn ss => ss addloop ("split_all_tac", split_all_tac));
schirmer@12925
   941
*}
schirmer@12854
   942
schirmer@12854
   943
schirmer@12854
   944
subsection "accessibility"
schirmer@12854
   945
schirmer@12854
   946
theorem dynamic_field_access_ok:
wenzelm@12937
   947
  assumes wf: "wf_prog G" and
wenzelm@12937
   948
    not_Null: "\<not> stat \<longrightarrow> a\<noteq>Null" and
wenzelm@12937
   949
   conform_a: "G,(store s)\<turnstile>a\<Colon>\<preceq> Class statC" and
wenzelm@12937
   950
   conform_s: "s\<Colon>\<preceq>(G, L)" and 
wenzelm@12937
   951
    normal_s: "normal s" and
wenzelm@12937
   952
        wt_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e\<Colon>-Class statC" and
wenzelm@12937
   953
           f: "accfield G accC statC fn = Some f" and
wenzelm@12937
   954
        dynC: "if stat then dynC=declclass f  
wenzelm@12937
   955
                       else dynC=obj_class (lookup_obj (store s) a)" and
wenzelm@12937
   956
        stat: "if stat then (is_static f) else (\<not> is_static f)"
schirmer@13688
   957
  shows "table_of (DeclConcepts.fields G dynC) (fn,declclass f) = Some (fld f)\<and>
schirmer@13688
   958
         G\<turnstile>Field fn f in dynC dyn_accessible_from accC"
schirmer@12854
   959
proof (cases "stat")
schirmer@12854
   960
  case True
schirmer@12925
   961
  with stat have static: "(is_static f)" by simp
schirmer@12925
   962
  from True dynC 
schirmer@12925
   963
  have dynC': "dynC=declclass f" by simp
schirmer@12854
   964
  with f
schirmer@12925
   965
  have "table_of (DeclConcepts.fields G statC) (fn,declclass f) = Some (fld f)"
schirmer@12854
   966
    by (auto simp add: accfield_def Let_def intro!: table_of_remap_SomeD)
schirmer@12925
   967
  moreover
schirmer@12925
   968
  from wt_e wf have "is_class G statC"
schirmer@12925
   969
    by (auto dest!: ty_expr_is_type)
schirmer@12925
   970
  moreover note wf dynC'
schirmer@12925
   971
  ultimately have
schirmer@12925
   972
     "table_of (DeclConcepts.fields G dynC) (fn,declclass f) = Some (fld f)"
schirmer@12925
   973
    by (auto dest: fields_declC)
schirmer@12925
   974
  with dynC' f static wf
schirmer@12854
   975
  show ?thesis
schirmer@12925
   976
    by (auto dest: static_to_dynamic_accessible_from_static
schirmer@12925
   977
            dest!: accfield_accessibleD )
schirmer@12854
   978
next
schirmer@12854
   979
  case False
schirmer@12925
   980
  with wf conform_a not_Null conform_s dynC
schirmer@12854
   981
  obtain subclseq: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and
schirmer@12854
   982
    "is_class G dynC"
schirmer@12925
   983
    by (auto dest!: conforms_RefTD [of _ _ _ _ "(fst s)" L]
schirmer@12854
   984
              dest: obj_ty_obj_class1
schirmer@12854
   985
          simp add: obj_ty_obj_class )
schirmer@12854
   986
  with wf f
schirmer@12854
   987
  have "table_of (DeclConcepts.fields G dynC) (fn,declclass f) = Some (fld f)"
schirmer@12854
   988
    by (auto simp add: accfield_def Let_def
schirmer@12854
   989
                 dest: fields_mono
schirmer@12854
   990
                dest!: table_of_remap_SomeD)
schirmer@12854
   991
  moreover
schirmer@12854
   992
  from f subclseq
schirmer@12854
   993
  have "G\<turnstile>Field fn f in dynC dyn_accessible_from accC"
wenzelm@23350
   994
    by (auto intro!: static_to_dynamic_accessible_from wf
schirmer@12854
   995
               dest: accfield_accessibleD)
schirmer@12854
   996
  ultimately show ?thesis
schirmer@12854
   997
    by blast
schirmer@12854
   998
qed
schirmer@12854
   999
schirmer@12925
  1000
lemma error_free_field_access:
wenzelm@12937
  1001
  assumes accfield: "accfield G accC statC fn = Some (statDeclC, f)" and
schirmer@12925
  1002
              wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-Class statC" and
schirmer@12925
  1003
         eval_init: "G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<rightarrow> s1" and
schirmer@12925
  1004
            eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2" and
schirmer@12925
  1005
           conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@12925
  1006
            conf_a: "normal s2 \<Longrightarrow> G, store s2\<turnstile>a\<Colon>\<preceq>Class statC" and
schirmer@12925
  1007
              fvar: "(v,s2')=fvar statDeclC (is_static f) fn a s2" and
schirmer@12925
  1008
                wf: "wf_prog G"   
wenzelm@12937
  1009
  shows "check_field_access G accC statDeclC fn (is_static f) a s2' = s2'"
schirmer@12925
  1010
proof -
schirmer@12925
  1011
  from fvar
schirmer@12925
  1012
  have store_s2': "store s2'=store s2"
schirmer@12925
  1013
    by (cases s2) (simp add: fvar_def2)
schirmer@12925
  1014
  with fvar conf_s2 
schirmer@12925
  1015
  have conf_s2': "s2'\<Colon>\<preceq>(G, L)"
schirmer@12925
  1016
    by (cases s2,cases "is_static f") (auto simp add: fvar_def2)
schirmer@12925
  1017
  from eval_init 
schirmer@12925
  1018
  have initd_statDeclC_s1: "initd statDeclC s1"
schirmer@12925
  1019
    by (rule init_yields_initd)
schirmer@12925
  1020
  with eval_e store_s2'
schirmer@12925
  1021
  have initd_statDeclC_s2': "initd statDeclC s2'"
schirmer@12925
  1022
    by (auto dest: eval_gext intro: inited_gext)
schirmer@12925
  1023
  show ?thesis
schirmer@12925
  1024
  proof (cases "normal s2'")
schirmer@12925
  1025
    case False
schirmer@12925
  1026
    then show ?thesis 
schirmer@12925
  1027
      by (auto simp add: check_field_access_def Let_def)
schirmer@12925
  1028
  next
schirmer@12925
  1029
    case True
schirmer@12925
  1030
    with fvar store_s2' 
schirmer@12925
  1031
    have not_Null: "\<not> (is_static f) \<longrightarrow> a\<noteq>Null" 
schirmer@12925
  1032
      by (cases s2) (auto simp add: fvar_def2)
schirmer@12925
  1033
    from True fvar store_s2'
schirmer@12925
  1034
    have "normal s2"
schirmer@12925
  1035
      by (cases s2,cases "is_static f") (auto simp add: fvar_def2)
schirmer@12925
  1036
    with conf_a store_s2'
schirmer@12925
  1037
    have conf_a': "G,store s2'\<turnstile>a\<Colon>\<preceq>Class statC"
schirmer@12925
  1038
      by simp
schirmer@12925
  1039
    from conf_a' conf_s2' True initd_statDeclC_s2' 
schirmer@12925
  1040
      dynamic_field_access_ok [OF wf not_Null conf_a' conf_s2' 
schirmer@12925
  1041
                                   True wt_e accfield ] 
schirmer@12925
  1042
    show ?thesis
schirmer@12925
  1043
      by  (cases "is_static f")
schirmer@12925
  1044
          (auto dest!: initedD
schirmer@12925
  1045
           simp add: check_field_access_def Let_def)
schirmer@12925
  1046
  qed
schirmer@12925
  1047
qed
schirmer@12925
  1048
schirmer@12925
  1049
lemma call_access_ok:
wenzelm@12937
  1050
  assumes invC_prop: "G\<turnstile>invmode statM e\<rightarrow>invC\<preceq>statT" 
wenzelm@12937
  1051
      and        wf: "wf_prog G" 
wenzelm@12937
  1052
      and      wt_e: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT"
wenzelm@12937
  1053
      and     statM: "(statDeclT,statM) \<in> mheads G accC statT sig" 
wenzelm@12937
  1054
      and      invC: "invC = invocation_class (invmode statM e) s a statT"
wenzelm@12937
  1055
  shows "\<exists> dynM. dynlookup G statT invC sig = Some dynM \<and>
schirmer@12854
  1056
  G\<turnstile>Methd sig dynM in invC dyn_accessible_from accC"
schirmer@12854
  1057
proof -
schirmer@12854
  1058
  from wt_e wf have type_statT: "is_type G (RefT statT)"
schirmer@12854
  1059
    by (auto dest: ty_expr_is_type)
schirmer@12854
  1060
  from statM have not_Null: "statT \<noteq> NullT" by auto
schirmer@12854
  1061
  from type_statT wt_e 
schirmer@12854
  1062
  have wf_I: "(\<forall>I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> 
schirmer@12925
  1063
                                        invmode statM e \<noteq> SuperM)"
schirmer@12854
  1064
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
  1065
  from wt_e
schirmer@12925
  1066
  have wf_A: "(\<forall>     T. statT = ArrayT T \<longrightarrow> invmode statM e \<noteq> SuperM)"
schirmer@12854
  1067
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
  1068
  show ?thesis
schirmer@12925
  1069
  proof (cases "invmode statM e = IntVir")
schirmer@12854
  1070
    case True
schirmer@12854
  1071
    with invC_prop not_Null
schirmer@12854
  1072
    have invC_prop': "is_class G invC \<and>  
schirmer@12854
  1073
                      (if (\<exists>T. statT=ArrayT T) then invC=Object 
schirmer@12854
  1074
                                              else G\<turnstile>Class invC\<preceq>RefT statT)"
schirmer@12854
  1075
      by (auto simp add: DynT_prop_def)
schirmer@12854
  1076
    with True not_Null
schirmer@12854
  1077
    have "G,statT \<turnstile> invC valid_lookup_cls_for is_static statM"
schirmer@12925
  1078
     by (cases statT) (auto simp add: invmode_def) 
schirmer@12854
  1079
    with statM type_statT wf 
schirmer@12854
  1080
    show ?thesis
schirmer@12854
  1081
      by - (rule dynlookup_access,auto)
schirmer@12854
  1082
  next
schirmer@12854
  1083
    case False
schirmer@12854
  1084
    with type_statT wf invC not_Null wf_I wf_A
schirmer@12854
  1085
    have invC_prop': " is_class G invC \<and>
schirmer@12854
  1086
                      ((\<exists> statC. statT=ClassT statC \<and> invC=statC) \<or>
schirmer@12854
  1087
                      (\<forall> statC. statT\<noteq>ClassT statC \<and> invC=Object)) "
schirmer@12854
  1088
        by (case_tac "statT") (auto simp add: invocation_class_def 
schirmer@12854
  1089
                                       split: inv_mode.splits)
schirmer@12854
  1090
    with not_Null wf
schirmer@12854
  1091
    have dynlookup_static: "dynlookup G statT invC sig = methd G invC sig"
schirmer@12854
  1092
      by (case_tac "statT") (auto simp add: dynlookup_def dynmethd_C_C
schirmer@12854
  1093
                                            dynimethd_def)
schirmer@12854
  1094
   from statM wf wt_e not_Null False invC_prop' obtain dynM where
schirmer@12854
  1095
                "accmethd G accC invC sig = Some dynM" 
schirmer@12854
  1096
     by (auto dest!: static_mheadsD)
schirmer@12854
  1097
   from invC_prop' False not_Null wf_I
schirmer@12854
  1098
   have "G,statT \<turnstile> invC valid_lookup_cls_for is_static statM"
schirmer@12925
  1099
     by (cases statT) (auto simp add: invmode_def) 
schirmer@12854
  1100
   with statM type_statT wf 
schirmer@12854
  1101
    show ?thesis
schirmer@12854
  1102
      by - (rule dynlookup_access,auto)
schirmer@12854
  1103
  qed
schirmer@12854
  1104
qed
schirmer@12854
  1105
schirmer@12925
  1106
lemma error_free_call_access:
wenzelm@12937
  1107
  assumes
schirmer@12925
  1108
   eval_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2" and
schirmer@12925
  1109
        wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-(RefT statT)" and  
schirmer@12925
  1110
       statM: "max_spec G accC statT \<lparr>name = mn, parTs = pTs\<rparr> 
schirmer@12925
  1111
               = {((statDeclT, statM), pTs')}" and
schirmer@12925
  1112
     conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@12925
  1113
      conf_a: "normal s1 \<Longrightarrow> G, store s1\<turnstile>a\<Colon>\<preceq>RefT statT" and
schirmer@12925
  1114
     invProp: "normal s3 \<Longrightarrow>
schirmer@12925
  1115
                G\<turnstile>invmode statM e\<rightarrow>invC\<preceq>statT" and
schirmer@12925
  1116
          s3: "s3=init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> 
schirmer@12925
  1117
                        (invmode statM e) a vs s2" and
schirmer@12925
  1118
        invC: "invC = invocation_class (invmode statM e) (store s2) a statT"and
schirmer@12925
  1119
    invDeclC: "invDeclC = invocation_declclass G (invmode statM e) (store s2) 
schirmer@12925
  1120
                             a statT \<lparr>name = mn, parTs = pTs'\<rparr>" and
schirmer@12925
  1121
          wf: "wf_prog G"
wenzelm@12937
  1122
  shows "check_method_access G accC statT (invmode statM e) \<lparr>name=mn,parTs=pTs'\<rparr> a s3
schirmer@12925
  1123
   = s3"
schirmer@12925
  1124
proof (cases "normal s2")
schirmer@12925
  1125
  case False
schirmer@12925
  1126
  with s3 
schirmer@12925
  1127
  have "abrupt s3 = abrupt s2"  
schirmer@12925
  1128
    by (auto simp add: init_lvars_def2)
schirmer@12925
  1129
  with False
schirmer@12925
  1130
  show ?thesis
schirmer@12925
  1131
    by (auto simp add: check_method_access_def Let_def)
schirmer@12925
  1132
next
schirmer@12925
  1133
  case True
schirmer@12925
  1134
  note normal_s2 = True
schirmer@12925
  1135
  with eval_args
schirmer@12925
  1136
  have normal_s1: "normal s1"
schirmer@12925
  1137
    by (cases "normal s1") auto
schirmer@12925
  1138
  with conf_a eval_args 
schirmer@12925
  1139
  have conf_a_s2: "G, store s2\<turnstile>a\<Colon>\<preceq>RefT statT"
schirmer@12925
  1140
    by (auto dest: eval_gext intro: conf_gext)
schirmer@12925
  1141
  show ?thesis
schirmer@12925
  1142
  proof (cases "a=Null \<longrightarrow> (is_static statM)")
schirmer@12925
  1143
    case False
schirmer@12925
  1144
    then obtain "\<not> is_static statM" "a=Null" 
schirmer@12925
  1145
      by blast
schirmer@12925
  1146
    with normal_s2 s3
schirmer@12925
  1147
    have "abrupt s3 = Some (Xcpt (Std NullPointer))" 
schirmer@12925
  1148
      by (auto simp add: init_lvars_def2)
schirmer@12925
  1149
    then show ?thesis
schirmer@12925
  1150
      by (auto simp add: check_method_access_def Let_def)
schirmer@12925
  1151
  next
schirmer@12925
  1152
    case True
schirmer@12925
  1153
    from statM 
schirmer@12925
  1154
    obtain
schirmer@12925
  1155
      statM': "(statDeclT,statM)\<in>mheads G accC statT \<lparr>name=mn,parTs=pTs'\<rparr>" 
schirmer@12925
  1156
      by (blast dest: max_spec2mheads)
schirmer@12925
  1157
    from True normal_s2 s3
schirmer@12925
  1158
    have "normal s3"
schirmer@12925
  1159
      by (auto simp add: init_lvars_def2)
schirmer@12925
  1160
    then have "G\<turnstile>invmode statM e\<rightarrow>invC\<preceq>statT"
schirmer@12925
  1161
      by (rule invProp)
schirmer@12925
  1162
    with wt_e statM' wf invC
schirmer@12925
  1163
    obtain dynM where 
schirmer@12925
  1164
      dynM: "dynlookup G statT invC  \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@12925
  1165
      acc_dynM: "G \<turnstile>Methd  \<lparr>name=mn,parTs=pTs'\<rparr> dynM 
schirmer@12925
  1166
                          in invC dyn_accessible_from accC"
schirmer@12925
  1167
      by (force dest!: call_access_ok)
schirmer@12925
  1168
    moreover
schirmer@12925
  1169
    from s3 invC
schirmer@12925
  1170
    have invC': "invC=(invocation_class (invmode statM e) (store s3) a statT)"
schirmer@12925
  1171
      by (cases s2,cases "invmode statM e") 
schirmer@12925
  1172
         (simp add: init_lvars_def2 del: invmode_Static_eq)+
schirmer@12925
  1173
    ultimately
schirmer@12925
  1174
    show ?thesis
schirmer@12925
  1175
      by (auto simp add: check_method_access_def Let_def)
schirmer@12925
  1176
  qed
schirmer@12925
  1177
qed
schirmer@12925
  1178
schirmer@13688
  1179
lemma map_upds_eq_length_append_simp:
schirmer@13688
  1180
  "\<And> tab qs. length ps = length qs \<Longrightarrow>  tab(ps[\<mapsto>]qs@zs) = tab(ps[\<mapsto>]qs)"
schirmer@13688
  1181
proof (induct ps) 
schirmer@13688
  1182
  case Nil thus ?case by simp
schirmer@13688
  1183
next
schirmer@13688
  1184
  case (Cons p ps tab qs)
wenzelm@23350
  1185
  from `length (p#ps) = length qs`
wenzelm@23350
  1186
  obtain q qs' where qs: "qs=q#qs'" and eq_length: "length ps=length qs'"
schirmer@13688
  1187
    by (cases qs) auto
schirmer@13688
  1188
  from eq_length have "(tab(p\<mapsto>q))(ps[\<mapsto>]qs'@zs)=(tab(p\<mapsto>q))(ps[\<mapsto>]qs')"
schirmer@13688
  1189
    by (rule Cons.hyps)
schirmer@13688
  1190
  with qs show ?case 
schirmer@13688
  1191
    by simp
schirmer@13688
  1192
qed
schirmer@13688
  1193
schirmer@13688
  1194
lemma map_upds_upd_eq_length_simp:
schirmer@13688
  1195
  "\<And> tab qs x y. length ps = length qs 
schirmer@13688
  1196
                  \<Longrightarrow> tab(ps[\<mapsto>]qs)(x\<mapsto>y) = tab(ps@[x][\<mapsto>]qs@[y])"
schirmer@13688
  1197
proof (induct "ps")
schirmer@13688
  1198
  case Nil thus ?case by simp
schirmer@13688
  1199
next
schirmer@13688
  1200
  case (Cons p ps tab qs x y)
wenzelm@23350
  1201
  from `length (p#ps) = length qs`
wenzelm@23350
  1202
  obtain q qs' where qs: "qs=q#qs'" and eq_length: "length ps=length qs'"
schirmer@13688
  1203
    by (cases qs) auto
schirmer@13688
  1204
  from eq_length 
schirmer@13688
  1205
  have "(tab(p\<mapsto>q))(ps[\<mapsto>]qs')(x\<mapsto>y) = (tab(p\<mapsto>q))(ps@[x][\<mapsto>]qs'@[y])"
schirmer@13688
  1206
    by (rule Cons.hyps)
schirmer@13688
  1207
  with qs show ?case
schirmer@13688
  1208
    by simp
schirmer@13688
  1209
qed
schirmer@13688
  1210
schirmer@13688
  1211
schirmer@13688
  1212
lemma map_upd_cong: "tab=tab'\<Longrightarrow> tab(x\<mapsto>y) = tab'(x\<mapsto>y)"
schirmer@13688
  1213
by simp
schirmer@13688
  1214
schirmer@13688
  1215
lemma map_upd_cong_ext: "tab z=tab' z\<Longrightarrow> (tab(x\<mapsto>y)) z = (tab'(x\<mapsto>y)) z"
schirmer@13688
  1216
by (simp add: fun_upd_def)
schirmer@13688
  1217
schirmer@13688
  1218
lemma map_upds_cong: "tab=tab'\<Longrightarrow> tab(xs[\<mapsto>]ys) = tab'(xs[\<mapsto>]ys)"
schirmer@13688
  1219
by (cases xs) simp+
schirmer@13688
  1220
schirmer@13688
  1221
lemma map_upds_cong_ext: 
schirmer@13688
  1222
 "\<And> tab tab' ys. tab z=tab' z \<Longrightarrow> (tab(xs[\<mapsto>]ys)) z = (tab'(xs[\<mapsto>]ys)) z"
schirmer@13688
  1223
proof (induct xs)
schirmer@13688
  1224
  case Nil thus ?case by simp
schirmer@13688
  1225
next
schirmer@13688
  1226
  case (Cons x xs tab tab' ys)
schirmer@14030
  1227
  note Hyps = this
schirmer@14030
  1228
  show ?case
schirmer@14030
  1229
  proof (cases ys)
schirmer@14030
  1230
    case Nil
wenzelm@23350
  1231
    with Hyps
wenzelm@23350
  1232
    show ?thesis by simp
schirmer@14030
  1233
  next
schirmer@14030
  1234
    case (Cons y ys')
schirmer@14030
  1235
    have "(tab(x\<mapsto>y)(xs[\<mapsto>]ys')) z = (tab'(x\<mapsto>y)(xs[\<mapsto>]ys')) z"
nipkow@17589
  1236
      by (iprover intro: Hyps map_upd_cong_ext)
schirmer@14030
  1237
    with Cons show ?thesis
schirmer@14030
  1238
      by simp
schirmer@14030
  1239
  qed
schirmer@13688
  1240
qed
schirmer@13688
  1241
   
schirmer@13688
  1242
lemma map_upd_override: "(tab(x\<mapsto>y)) x = (tab'(x\<mapsto>y)) x"
schirmer@13688
  1243
  by simp
schirmer@13688
  1244
schirmer@13688
  1245
lemma map_upds_eq_length_suffix: "\<And> tab qs. 
schirmer@13688
  1246
        length ps = length qs \<Longrightarrow> tab(ps@xs[\<mapsto>]qs) = tab(ps[\<mapsto>]qs)(xs[\<mapsto>][])"
schirmer@13688
  1247
proof (induct ps)
schirmer@13688
  1248
  case Nil thus ?case by simp
schirmer@13688
  1249
next
schirmer@13688
  1250
  case (Cons p ps tab qs)
schirmer@13688
  1251
  then obtain q qs' where qs: "qs=q#qs'" and eq_length: "length ps=length qs'"
schirmer@13688
  1252
    by (cases qs) auto
schirmer@13688
  1253
  from eq_length
schirmer@13688
  1254
  have "tab(p\<mapsto>q)(ps @ xs[\<mapsto>]qs') = tab(p\<mapsto>q)(ps[\<mapsto>]qs')(xs[\<mapsto>][])"
schirmer@13688
  1255
    by (rule Cons.hyps)
schirmer@13688
  1256
  with qs show ?case 
schirmer@13688
  1257
    by simp
schirmer@13688
  1258
qed
schirmer@13688
  1259
  
schirmer@13688
  1260
  
schirmer@13688
  1261
lemma map_upds_upds_eq_length_prefix_simp:
schirmer@13688
  1262
  "\<And> tab qs. length ps = length qs
schirmer@13688
  1263
              \<Longrightarrow> tab(ps[\<mapsto>]qs)(xs[\<mapsto>]ys) = tab(ps@xs[\<mapsto>]qs@ys)"
schirmer@13688
  1264
proof (induct ps)
schirmer@13688
  1265
  case Nil thus ?case by simp
schirmer@13688
  1266
next
schirmer@13688
  1267
  case (Cons p ps tab qs)
schirmer@13688
  1268
  then obtain q qs' where qs: "qs=q#qs'" and eq_length: "length ps=length qs'"
schirmer@13688
  1269
    by (cases qs) auto
schirmer@13688
  1270
  from eq_length 
schirmer@13688
  1271
  have "tab(p\<mapsto>q)(ps[\<mapsto>]qs')(xs[\<mapsto>]ys) = tab(p\<mapsto>q)(ps @ xs[\<mapsto>](qs' @ ys))"
schirmer@13688
  1272
    by (rule Cons.hyps)
schirmer@13688
  1273
  with qs 
schirmer@13688
  1274
  show ?case by simp
schirmer@13688
  1275
qed
schirmer@13688
  1276
schirmer@13688
  1277
lemma map_upd_cut_irrelevant:
schirmer@13688
  1278
"\<lbrakk>(tab(x\<mapsto>y)) vn = Some el; (tab'(x\<mapsto>y)) vn = None\<rbrakk>
schirmer@13688
  1279
    \<Longrightarrow> tab vn = Some el"
schirmer@13688
  1280
by (cases "tab' vn = None") (simp add: fun_upd_def)+
schirmer@13688
  1281
schirmer@13688
  1282
lemma map_upd_Some_expand:
schirmer@13688
  1283
"\<lbrakk>tab vn = Some z\<rbrakk>
schirmer@13688
  1284
    \<Longrightarrow> \<exists> z. (tab(x\<mapsto>y)) vn = Some z"
schirmer@13688
  1285
by (simp add: fun_upd_def)
schirmer@13688
  1286
schirmer@13688
  1287
lemma map_upds_Some_expand:
schirmer@13688
  1288
"\<And> tab ys z. \<lbrakk>tab vn = Some z\<rbrakk>
schirmer@13688
  1289
    \<Longrightarrow> \<exists> z. (tab(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1290
proof (induct xs)
schirmer@13688
  1291
  case Nil thus ?case by simp
schirmer@13688
  1292
next
schirmer@13688
  1293
  case (Cons x xs tab ys z)
wenzelm@23350
  1294
  note z = `tab vn = Some z`
schirmer@14030
  1295
  show ?case
schirmer@14030
  1296
  proof (cases ys)
schirmer@14030
  1297
    case Nil
schirmer@14030
  1298
    with z show ?thesis by simp
schirmer@14030
  1299
  next
schirmer@14030
  1300
    case (Cons y ys')
wenzelm@23350
  1301
    note ys = `ys = y#ys'`
schirmer@14030
  1302
    from z obtain z' where "(tab(x\<mapsto>y)) vn = Some z'"
schirmer@14030
  1303
      by (rule map_upd_Some_expand [of tab,elim_format]) blast
schirmer@14030
  1304
    hence "\<exists>z. ((tab(x\<mapsto>y))(xs[\<mapsto>]ys')) vn = Some z"
schirmer@14030
  1305
      by (rule Cons.hyps)
schirmer@14030
  1306
    with ys show ?thesis
schirmer@14030
  1307
      by simp
schirmer@14030
  1308
  qed
schirmer@13688
  1309
qed
schirmer@13688
  1310
schirmer@13688
  1311
schirmer@13688
  1312
lemma map_upd_Some_swap:
schirmer@13688
  1313
 "(tab(r\<mapsto>w)(u\<mapsto>v)) vn = Some z \<Longrightarrow> \<exists> z. (tab(u\<mapsto>v)(r\<mapsto>w)) vn = Some z"
schirmer@13688
  1314
by (simp add: fun_upd_def)
schirmer@13688
  1315
schirmer@13688
  1316
lemma map_upd_None_swap:
schirmer@13688
  1317
 "(tab(r\<mapsto>w)(u\<mapsto>v)) vn = None \<Longrightarrow> (tab(u\<mapsto>v)(r\<mapsto>w)) vn = None"
schirmer@13688
  1318
by (simp add: fun_upd_def)
schirmer@13688
  1319
schirmer@13688
  1320
schirmer@13688
  1321
lemma map_eq_upd_eq: "tab vn = tab' vn \<Longrightarrow> (tab(x\<mapsto>y)) vn = (tab'(x\<mapsto>y)) vn"
schirmer@13688
  1322
by (simp add: fun_upd_def)
schirmer@13688
  1323
schirmer@13688
  1324
lemma map_upd_in_expansion_map_swap:
schirmer@13688
  1325
 "\<lbrakk>(tab(x\<mapsto>y)) vn = Some z;tab vn \<noteq> Some z\<rbrakk> 
schirmer@13688
  1326
                 \<Longrightarrow>  (tab'(x\<mapsto>y)) vn = Some z"
schirmer@13688
  1327
by (simp add: fun_upd_def)
schirmer@13688
  1328
schirmer@13688
  1329
lemma map_upds_in_expansion_map_swap:
schirmer@13688
  1330
 "\<And>tab tab' ys z. \<lbrakk>(tab(xs[\<mapsto>]ys)) vn = Some z;tab vn \<noteq> Some z\<rbrakk> 
schirmer@13688
  1331
                 \<Longrightarrow>  (tab'(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1332
proof (induct xs)
schirmer@13688
  1333
  case Nil thus ?case by simp
schirmer@13688
  1334
next
schirmer@13688
  1335
  case (Cons x xs tab tab' ys z)
wenzelm@23350
  1336
  note some = `(tab(x # xs[\<mapsto>]ys)) vn = Some z`
wenzelm@23350
  1337
  note tab_not_z = `tab vn \<noteq> Some z`
schirmer@13688
  1338
  show ?case
wenzelm@23350
  1339
  proof (cases ys)
schirmer@14030
  1340
    case Nil with some tab_not_z show ?thesis by simp
schirmer@13688
  1341
  next
schirmer@14030
  1342
    case (Cons y tl)
wenzelm@23350
  1343
    note ys = `ys = y#tl`
schirmer@14030
  1344
    show ?thesis
schirmer@14030
  1345
    proof (cases "(tab(x\<mapsto>y)) vn \<noteq> Some z")
schirmer@14030
  1346
      case True
schirmer@14030
  1347
      with some ys have "(tab'(x\<mapsto>y)(xs[\<mapsto>]tl)) vn = Some z"
schirmer@14030
  1348
	by (fastsimp intro: Cons.hyps)
schirmer@14030
  1349
      with ys show ?thesis 
schirmer@14030
  1350
	by simp
schirmer@14030
  1351
    next
schirmer@14030
  1352
      case False
schirmer@14030
  1353
      hence tabx_z: "(tab(x\<mapsto>y)) vn = Some z" by blast
schirmer@14030
  1354
      moreover
schirmer@14030
  1355
      from tabx_z tab_not_z
schirmer@14030
  1356
      have "(tab'(x\<mapsto>y)) vn = Some z" 
schirmer@14030
  1357
	by (rule map_upd_in_expansion_map_swap)
schirmer@14030
  1358
      ultimately
schirmer@14030
  1359
      have "(tab(x\<mapsto>y)) vn =(tab'(x\<mapsto>y)) vn"
schirmer@14030
  1360
	by simp
schirmer@14030
  1361
      hence "(tab(x\<mapsto>y)(xs[\<mapsto>]tl)) vn = (tab'(x\<mapsto>y)(xs[\<mapsto>]tl)) vn"
schirmer@14030
  1362
	by (rule map_upds_cong_ext)
schirmer@14030
  1363
      with some ys
schirmer@14030
  1364
      show ?thesis 
schirmer@14030
  1365
	by simp
schirmer@14030
  1366
    qed
schirmer@13688
  1367
  qed
schirmer@13688
  1368
qed
schirmer@13688
  1369
   
schirmer@13688
  1370
lemma map_upds_Some_swap: 
schirmer@13688
  1371
 assumes r_u: "(tab(r\<mapsto>w)(u\<mapsto>v)(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1372
    shows "\<exists> z. (tab(u\<mapsto>v)(r\<mapsto>w)(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1373
proof (cases "(tab(r\<mapsto>w)(u\<mapsto>v)) vn = Some z")
schirmer@13688
  1374
  case True
schirmer@13688
  1375
  then obtain z' where "(tab(u\<mapsto>v)(r\<mapsto>w)) vn = Some z'"
schirmer@13688
  1376
    by (rule map_upd_Some_swap [elim_format]) blast
schirmer@13688
  1377
  thus "\<exists> z. (tab(u\<mapsto>v)(r\<mapsto>w)(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1378
    by (rule map_upds_Some_expand)
schirmer@13688
  1379
next
schirmer@13688
  1380
  case False
schirmer@13688
  1381
  with r_u
schirmer@13688
  1382
  have "(tab(u\<mapsto>v)(r\<mapsto>w)(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1383
    by (rule map_upds_in_expansion_map_swap)
schirmer@13688
  1384
  thus ?thesis
schirmer@13688
  1385
    by simp
schirmer@13688
  1386
qed
schirmer@13688
  1387
 
schirmer@13688
  1388
lemma map_upds_Some_insert:
schirmer@13688
  1389
  assumes z: "(tab(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1390
    shows "\<exists> z. (tab(u\<mapsto>v)(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1391
proof (cases "\<exists> z. tab vn = Some z")
schirmer@13688
  1392
  case True
schirmer@13688
  1393
  then obtain z' where "tab vn = Some z'" by blast
schirmer@13688
  1394
  then obtain z'' where "(tab(u\<mapsto>v)) vn = Some z''"
schirmer@13688
  1395
    by (rule map_upd_Some_expand [elim_format]) blast
schirmer@13688
  1396
  thus ?thesis
schirmer@13688
  1397
    by (rule map_upds_Some_expand)
schirmer@13688
  1398
next
schirmer@13688
  1399
  case False
schirmer@13688
  1400
  hence "tab vn \<noteq> Some z" by simp
schirmer@13688
  1401
  with z
schirmer@13688
  1402
  have "(tab(u\<mapsto>v)(xs[\<mapsto>]ys)) vn = Some z"
schirmer@13688
  1403
    by (rule map_upds_in_expansion_map_swap)
schirmer@13688
  1404
  thus ?thesis ..
schirmer@13688
  1405
qed
schirmer@13688
  1406
   
schirmer@13688
  1407
lemma map_upds_None_cut:
schirmer@13688
  1408
assumes expand_None: "(tab(xs[\<mapsto>]ys)) vn = None"
schirmer@13688
  1409
  shows "tab vn = None"
schirmer@13688
  1410
proof (cases "tab vn = None")
schirmer@13688
  1411
  case True thus ?thesis by simp
schirmer@13688
  1412
next
schirmer@13688
  1413
  case False then obtain z where "tab vn = Some z" by blast
schirmer@13688
  1414
  then obtain z' where "(tab(xs[\<mapsto>]ys)) vn = Some z'"
schirmer@13688
  1415
    by (rule map_upds_Some_expand [where  ?tab="tab",elim_format]) blast
schirmer@13688
  1416
  with expand_None show ?thesis
schirmer@13688
  1417
    by simp
schirmer@13688
  1418
qed
schirmer@13688
  1419
    
schirmer@13688
  1420
schirmer@13688
  1421
lemma map_upds_cut_irrelevant:
schirmer@13688
  1422
"\<And> tab tab' ys. \<lbrakk>(tab(xs[\<mapsto>]ys)) vn = Some el; (tab'(xs[\<mapsto>]ys)) vn = None\<rbrakk>
schirmer@13688
  1423
                  \<Longrightarrow> tab vn = Some el"
schirmer@13688
  1424
proof  (induct "xs")
schirmer@13688
  1425
  case Nil thus ?case by simp
schirmer@13688
  1426
next
schirmer@13688
  1427
  case (Cons x xs tab tab' ys)
wenzelm@23350
  1428
  note tab_vn = `(tab(x # xs[\<mapsto>]ys)) vn = Some el`
wenzelm@23350
  1429
  note tab'_vn = `(tab'(x # xs[\<mapsto>]ys)) vn = None`
schirmer@14030
  1430
  show ?case
schirmer@14030
  1431
  proof (cases ys)
schirmer@14030
  1432
    case Nil
schirmer@14030
  1433
    with tab_vn show ?thesis by simp
schirmer@14030
  1434
  next
schirmer@14030
  1435
    case (Cons y tl)
wenzelm@23350
  1436
    note ys = `ys=y#tl`
schirmer@14030
  1437
    with tab_vn tab'_vn 
schirmer@14030
  1438
    have "(tab(x\<mapsto>y)) vn = Some el"
schirmer@14030
  1439
      by - (rule Cons.hyps,auto)
schirmer@14030
  1440
    moreover from tab'_vn ys
schirmer@14030
  1441
    have "(tab'(x\<mapsto>y)(xs[\<mapsto>]tl)) vn = None" 
schirmer@14030
  1442
      by simp
schirmer@14030
  1443
    hence "(tab'(x\<mapsto>y)) vn = None"
schirmer@14030
  1444
      by (rule map_upds_None_cut)
schirmer@14030
  1445
    ultimately show "tab vn = Some el" 
schirmer@14030
  1446
      by (rule map_upd_cut_irrelevant)
schirmer@14030
  1447
  qed
schirmer@13688
  1448
qed
schirmer@14030
  1449
schirmer@13688
  1450
   
schirmer@13688
  1451
lemma dom_vname_split:
schirmer@13688
  1452
 "dom (lname_case (ename_case (tab(x\<mapsto>y)(xs[\<mapsto>]ys)) a) b)
schirmer@13688
  1453
   = dom (lname_case (ename_case (tab(x\<mapsto>y)) a) b) \<union> 
schirmer@13688
  1454
     dom (lname_case (ename_case (tab(xs[\<mapsto>]ys)) a) b)"
schirmer@13688
  1455
  (is "?List x xs y ys = ?Hd x y \<union> ?Tl xs ys")
schirmer@13688
  1456
proof 
schirmer@13688
  1457
  show "?List x xs y ys \<subseteq> ?Hd x y \<union> ?Tl xs ys"
schirmer@13688
  1458
  proof 
schirmer@13688
  1459
    fix el 
schirmer@13688
  1460
    assume el_in_list: "el \<in> ?List x xs y ys"
schirmer@13688
  1461
    show "el \<in>  ?Hd x y \<union> ?Tl xs ys"
schirmer@13688
  1462
    proof (cases el)
schirmer@13688
  1463
      case This
schirmer@13688
  1464
      with el_in_list show ?thesis by (simp add: dom_def)
schirmer@13688
  1465
    next
schirmer@13688
  1466
      case (EName en)
schirmer@13688
  1467
      show ?thesis
schirmer@13688
  1468
      proof (cases en)
schirmer@13688
  1469
	case Res
schirmer@13688
  1470
	with EName el_in_list show ?thesis by (simp add: dom_def)
schirmer@13688
  1471
      next
schirmer@13688
  1472
	case (VNam vn)
schirmer@13688
  1473
	with EName el_in_list show ?thesis 
nipkow@18576
  1474
	  by (auto simp add: dom_def dest: map_upds_cut_irrelevant)
schirmer@13688
  1475
      qed
schirmer@13688
  1476
    qed
schirmer@13688
  1477
  qed
schirmer@13688
  1478
next
schirmer@13688
  1479
  show "?Hd x y \<union> ?Tl xs ys  \<subseteq> ?List x xs y ys" 
paulson@15102
  1480
  proof (rule subsetI)
schirmer@13688
  1481
    fix el 
schirmer@13688
  1482
    assume  el_in_hd_tl: "el \<in>  ?Hd x y \<union> ?Tl xs ys"
schirmer@13688
  1483
    show "el \<in> ?List x xs y ys"
schirmer@13688
  1484
    proof (cases el)
schirmer@13688
  1485
      case This
schirmer@13688
  1486
      with el_in_hd_tl show ?thesis by (simp add: dom_def)
schirmer@13688
  1487
    next
schirmer@13688
  1488
      case (EName en)
schirmer@13688
  1489
      show ?thesis
schirmer@13688
  1490
      proof (cases en)
schirmer@13688
  1491
	case Res
schirmer@13688
  1492
	with EName el_in_hd_tl show ?thesis by (simp add: dom_def)
schirmer@13688
  1493
      next
schirmer@13688
  1494
	case (VNam vn)
schirmer@13688
  1495
	with EName el_in_hd_tl show ?thesis 
schirmer@13688
  1496
	  by (auto simp add: dom_def intro: map_upds_Some_expand 
schirmer@13688
  1497
                                            map_upds_Some_insert)
schirmer@13688
  1498
      qed
schirmer@13688
  1499
    qed
schirmer@13688
  1500
  qed
schirmer@13688
  1501
qed
schirmer@13688
  1502
schirmer@13688
  1503
lemma dom_map_upd: "\<And> tab. dom (tab(x\<mapsto>y)) = dom tab \<union> {x}"
schirmer@13688
  1504
by (auto simp add: dom_def fun_upd_def)
schirmer@13688
  1505
schirmer@14030
  1506
lemma dom_map_upds: "\<And> tab ys. length xs = length ys 
schirmer@14030
  1507
  \<Longrightarrow> dom (tab(xs[\<mapsto>]ys)) = dom tab \<union> set xs"
schirmer@13688
  1508
proof (induct xs)
schirmer@13688
  1509
  case Nil thus ?case by (simp add: dom_def)
schirmer@13688
  1510
next
schirmer@13688
  1511
  case (Cons x xs tab ys)
schirmer@14030
  1512
  note Hyp = Cons.hyps
wenzelm@23350
  1513
  note len = `length (x#xs)=length ys`
schirmer@13688
  1514
  show ?case
schirmer@14030
  1515
  proof (cases ys)
schirmer@14030
  1516
    case Nil with len show ?thesis by simp
schirmer@14030
  1517
  next
schirmer@14030
  1518
    case (Cons y tl)
schirmer@14030
  1519
    with len have "dom (tab(x\<mapsto>y)(xs[\<mapsto>]tl)) = dom (tab(x\<mapsto>y)) \<union> set xs"
schirmer@14030
  1520
      by - (rule Hyp,simp)
schirmer@14030
  1521
    moreover 
schirmer@14030
  1522
    have "dom (tab(x\<mapsto>hd ys)) = dom tab \<union> {x}"
schirmer@14030
  1523
      by (rule dom_map_upd)
schirmer@14030
  1524
    ultimately
schirmer@14030
  1525
    show ?thesis using Cons
schirmer@14030
  1526
      by simp
schirmer@14030
  1527
  qed
schirmer@13688
  1528
qed
schirmer@13688
  1529
 
schirmer@13688
  1530
lemma dom_ename_case_None_simp:
schirmer@13688
  1531
 "dom (ename_case vname_tab None) = VNam ` (dom vname_tab)"
schirmer@13688
  1532
  apply (auto simp add: dom_def image_def )
schirmer@13688
  1533
  apply (case_tac "x")
schirmer@13688
  1534
  apply auto
schirmer@13688
  1535
  done
schirmer@13688
  1536
schirmer@13688
  1537
lemma dom_ename_case_Some_simp:
schirmer@13688
  1538
 "dom (ename_case vname_tab (Some a)) = VNam ` (dom vname_tab) \<union> {Res}"
schirmer@13688
  1539
  apply (auto simp add: dom_def image_def )
schirmer@13688
  1540
  apply (case_tac "x")
schirmer@13688
  1541
  apply auto
schirmer@13688
  1542
  done
schirmer@13688
  1543
schirmer@13688
  1544
lemma dom_lname_case_None_simp:
schirmer@13688
  1545
  "dom (lname_case ename_tab None) = EName ` (dom ename_tab)"
schirmer@13688
  1546
  apply (auto simp add: dom_def image_def )
schirmer@13688
  1547
  apply (case_tac "x")
schirmer@13688
  1548
  apply auto
schirmer@13688
  1549
  done
schirmer@13688
  1550
schirmer@13688
  1551
lemma dom_lname_case_Some_simp:
schirmer@13688
  1552
 "dom (lname_case ename_tab (Some a)) = EName ` (dom ename_tab) \<union> {This}"
schirmer@13688
  1553
  apply (auto simp add: dom_def image_def)
schirmer@13688
  1554
  apply (case_tac "x")
schirmer@13688
  1555
  apply auto
schirmer@13688
  1556
  done
schirmer@13688
  1557
schirmer@13688
  1558
lemmas dom_lname_ename_case_simps =  
schirmer@13688
  1559
     dom_ename_case_None_simp dom_ename_case_Some_simp 
schirmer@13688
  1560
     dom_lname_case_None_simp dom_lname_case_Some_simp
schirmer@13688
  1561
schirmer@13688
  1562
lemma image_comp: 
schirmer@13688
  1563
 "f ` g ` A = (f \<circ> g) ` A"
schirmer@13688
  1564
by (auto simp add: image_def)
schirmer@13688
  1565
schirmer@14030
  1566
schirmer@13688
  1567
lemma dom_locals_init_lvars: 
schirmer@13688
  1568
  assumes m: "m=(mthd (the (methd G C sig)))"  
schirmer@14030
  1569
  assumes len: "length (pars m) = length pvs"
schirmer@13688
  1570
  shows "dom (locals (store (init_lvars G C sig (invmode m e) a pvs s)))  
schirmer@13688
  1571
           = parameters m"
schirmer@13688
  1572
proof -
schirmer@13688
  1573
  from m
schirmer@13688
  1574
  have static_m': "is_static m = static m"
schirmer@13688
  1575
    by simp
schirmer@14030
  1576
  from len
schirmer@13688
  1577
  have dom_vnames: "dom (empty(pars m[\<mapsto>]pvs))=set (pars m)"
schirmer@13688
  1578
    by (simp add: dom_map_upds)
schirmer@13688
  1579
  show ?thesis
schirmer@13688
  1580
  proof (cases "static m")
schirmer@13688
  1581
    case True
schirmer@13688
  1582
    with static_m' dom_vnames m
schirmer@13688
  1583
    show ?thesis
schirmer@13688
  1584
      by (cases s) (simp add: init_lvars_def Let_def parameters_def
schirmer@13688
  1585
                              dom_lname_ename_case_simps image_comp)
schirmer@13688
  1586
  next
schirmer@13688
  1587
    case False
schirmer@13688
  1588
    with static_m' dom_vnames m
schirmer@13688
  1589
    show ?thesis
schirmer@13688
  1590
      by (cases s) (simp add: init_lvars_def Let_def parameters_def
schirmer@13688
  1591
                              dom_lname_ename_case_simps image_comp)
schirmer@13688
  1592
  qed
schirmer@13688
  1593
qed
schirmer@13688
  1594
schirmer@14030
  1595
schirmer@13688
  1596
lemma da_e2_BinOp:
schirmer@13688
  1597
  assumes da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1598
                  \<turnstile>dom (locals (store s0)) \<guillemotright>\<langle>BinOp binop e1 e2\<rangle>\<^sub>e\<guillemotright> A"
schirmer@13688
  1599
    and wt_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e1\<Colon>-e1T"
schirmer@13688
  1600
    and wt_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>e2\<Colon>-e2T" 
schirmer@13688
  1601
    and wt_binop: "wt_binop G binop e1T e2T" 
schirmer@13688
  1602
    and conf_s0: "s0\<Colon>\<preceq>(G,L)"  
schirmer@13688
  1603
    and normal_s1: "normal s1"
schirmer@13688
  1604
    and	eval_e1: "G\<turnstile>s0 \<midarrow>e1-\<succ>v1\<rightarrow> s1"
schirmer@13688
  1605
    and conf_v1: "G,store s1\<turnstile>v1\<Colon>\<preceq>e1T"
schirmer@13688
  1606
    and wf: "wf_prog G"
schirmer@13688
  1607
  shows "\<exists> E2. \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) 
schirmer@13688
  1608
         \<guillemotright>(if need_second_arg binop v1 then \<langle>e2\<rangle>\<^sub>e else \<langle>Skip\<rangle>\<^sub>s)\<guillemotright> E2"
schirmer@13688
  1609
proof -
schirmer@13688
  1610
  note inj_term_simps [simp]
schirmer@13688
  1611
  from da obtain E1 where
schirmer@13688
  1612
    da_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr> \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e1\<rangle>\<^sub>e\<guillemotright> E1"
schirmer@13688
  1613
    by cases simp+
schirmer@13688
  1614
  obtain E2 where
schirmer@13688
  1615
    "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store s1)) 
schirmer@13688
  1616
      \<guillemotright>(if need_second_arg binop v1 then \<langle>e2\<rangle>\<^sub>e else \<langle>Skip\<rangle>\<^sub>s)\<guillemotright> E2"
schirmer@13688
  1617
  proof (cases "need_second_arg binop v1")
schirmer@13688
  1618
    case False
schirmer@13688
  1619
    obtain S where
schirmer@13688
  1620
      daSkip: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1621
                  \<turnstile> dom (locals (store s1)) \<guillemotright>\<langle>Skip\<rangle>\<^sub>s\<guillemotright> S"
schirmer@13688
  1622
      by (auto intro: da_Skip [simplified] assigned.select_convs)
schirmer@13688
  1623
    thus ?thesis
schirmer@13688
  1624
      using that by (simp add: False)
schirmer@13688
  1625
  next
schirmer@13688
  1626
    case True
schirmer@13688
  1627
    from eval_e1 have 
schirmer@13688
  1628
      s0_s1:"dom (locals (store s0)) \<subseteq> dom (locals (store s1))"
schirmer@13688
  1629
      by (rule dom_locals_eval_mono_elim)
schirmer@13688
  1630
    {
schirmer@13688
  1631
      assume condAnd: "binop=CondAnd"
schirmer@13688
  1632
      have ?thesis
schirmer@13688
  1633
      proof -
schirmer@13688
  1634
	from da obtain E2' where
schirmer@13688
  1635
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1636
             \<turnstile> dom (locals (store s0)) \<union> assigns_if True e1 \<guillemotright>\<langle>e2\<rangle>\<^sub>e\<guillemotright> E2'"
schirmer@13688
  1637
	  by cases (simp add: condAnd)+
schirmer@13688
  1638
	moreover
schirmer@13688
  1639
	have "dom (locals (store s0)) 
schirmer@13688
  1640
          \<union> assigns_if True e1 \<subseteq> dom (locals (store s1))"
schirmer@13688
  1641
	proof -
schirmer@13688
  1642
	  from condAnd wt_binop have e1T: "e1T=PrimT Boolean"
schirmer@13688
  1643
	    by simp
schirmer@13688
  1644
	  with normal_s1 conf_v1 obtain b where "v1=Bool b"
schirmer@13688
  1645
	    by (auto dest: conf_Boolean)
schirmer@13688
  1646
	  with True condAnd
schirmer@13688
  1647
	  have v1: "v1=Bool True"
schirmer@13688
  1648
	    by simp
schirmer@13688
  1649
	  from eval_e1 normal_s1 
schirmer@13688
  1650
	  have "assigns_if True e1 \<subseteq> dom (locals (store s1))"
schirmer@13688
  1651
	    by (rule assigns_if_good_approx' [elim_format])
schirmer@13688
  1652
	       (insert wt_e1, simp_all add: e1T v1)
schirmer@13688
  1653
	  with s0_s1 show ?thesis by (rule Un_least)
schirmer@13688
  1654
	qed
schirmer@13688
  1655
	ultimately
schirmer@13688
  1656
	show ?thesis
schirmer@13688
  1657
	  using that by (cases rule: da_weakenE) (simp add: True)
schirmer@13688
  1658
      qed
schirmer@13688
  1659
    }
schirmer@13688
  1660
    moreover
schirmer@13688
  1661
    { 
schirmer@13688
  1662
      assume condOr: "binop=CondOr"
schirmer@13688
  1663
      have ?thesis
schirmer@13688
  1664
	(* Beweis durch Analogie/Example/Pattern?, True\<rightarrow>False; And\<rightarrow>Or *)
schirmer@13688
  1665
      proof -
schirmer@13688
  1666
	from da obtain E2' where
schirmer@13688
  1667
	  "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1668
              \<turnstile> dom (locals (store s0)) \<union> assigns_if False e1 \<guillemotright>\<langle>e2\<rangle>\<^sub>e\<guillemotright> E2'"
schirmer@13688
  1669
	  by cases (simp add: condOr)+
schirmer@13688
  1670
	moreover
schirmer@13688
  1671
	have "dom (locals (store s0)) 
schirmer@13688
  1672
                     \<union> assigns_if False e1 \<subseteq> dom (locals (store s1))"
schirmer@13688
  1673
	proof -
schirmer@13688
  1674
	  from condOr wt_binop have e1T: "e1T=PrimT Boolean"
schirmer@13688
  1675
	    by simp
schirmer@13688
  1676
	  with normal_s1 conf_v1 obtain b where "v1=Bool b"
schirmer@13688
  1677
	    by (auto dest: conf_Boolean)
schirmer@13688
  1678
	  with True condOr
schirmer@13688
  1679
	  have v1: "v1=Bool False"
schirmer@13688
  1680
	    by simp
schirmer@13688
  1681
	  from eval_e1 normal_s1 
schirmer@13688
  1682
	  have "assigns_if False e1 \<subseteq> dom (locals (store s1))"
schirmer@13688
  1683
	    by (rule assigns_if_good_approx' [elim_format])
schirmer@13688
  1684
	       (insert wt_e1, simp_all add: e1T v1)
schirmer@13688
  1685
	  with s0_s1 show ?thesis by (rule Un_least)
schirmer@13688
  1686
	qed
schirmer@13688
  1687
	ultimately
schirmer@13688
  1688
	show ?thesis
schirmer@13688
  1689
	  using that by (rule da_weakenE) (simp add: True)
schirmer@13688
  1690
      qed
schirmer@13688
  1691
    }
schirmer@13688
  1692
    moreover
schirmer@13688
  1693
    {
schirmer@13688
  1694
      assume notAndOr: "binop\<noteq>CondAnd" "binop\<noteq>CondOr"
schirmer@13688
  1695
      have ?thesis
schirmer@13688
  1696
      proof -
schirmer@13688
  1697
	from da notAndOr obtain E1' where
schirmer@13688
  1698
          da_e1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>
schirmer@13688
  1699
                  \<turnstile> dom (locals (store s0)) \<guillemotright>\<langle>e1\<rangle>\<^sub>e\<guillemotright> E1'"
schirmer@13688
  1700
	  and da_e2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> nrm E1' \<guillemotright>In1l e2\<guillemotright> A"
schirmer@13688
  1701
	  by cases simp+
schirmer@13688
  1702
	from eval_e1 wt_e1 da_e1 wf normal_s1 
schirmer@13688
  1703
	have "nrm E1' \<subseteq> dom (locals (store s1))"
nipkow@17589
  1704
	  by (cases rule: da_good_approxE') iprover
schirmer@13688
  1705
	with da_e2 show ?thesis
schirmer@13688
  1706
	  using that by (rule da_weakenE) (simp add: True)
schirmer@13688
  1707
      qed
schirmer@13688
  1708
    }
schirmer@13688
  1709
    ultimately show ?thesis
schirmer@13688
  1710
      by (cases binop) auto
schirmer@13688
  1711
  qed
schirmer@13688
  1712
  thus ?thesis ..
schirmer@13688
  1713
qed
schirmer@13688
  1714
schirmer@12854
  1715
section "main proof of type safety"
schirmer@13688
  1716
    
schirmer@12925
  1717
lemma eval_type_sound:
schirmer@13688
  1718
  assumes  eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" 
schirmer@13688
  1719
   and      wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T" 
schirmer@13688
  1720
   and      da: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>t\<guillemotright>A"
schirmer@13688
  1721
   and      wf: "wf_prog G" 
schirmer@13688
  1722
   and conf_s0: "s0\<Colon>\<preceq>(G,L)"           
wenzelm@12937
  1723
  shows "s1\<Colon>\<preceq>(G,L) \<and>  (normal s1 \<longrightarrow> G,L,store s1\<turnstile>t\<succ>v\<Colon>\<preceq>T) \<and> 
schirmer@12925
  1724
         (error_free s0 = error_free s1)"
schirmer@12925
  1725
proof -
schirmer@13688
  1726
  note inj_term_simps [simp]
schirmer@13688
  1727
  let ?TypeSafeObj = "\<lambda> s0 s1 t v. 
schirmer@13688
  1728
          \<forall>  L accC T A. s0\<Colon>\<preceq>(G,L) \<longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T
schirmer@13688
  1729
                      \<longrightarrow> \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>t\<guillemotright>A  
schirmer@13688
  1730
                      \<longrightarrow> s1\<Colon>\<preceq>(G,L) \<and> (normal s1 \<longrightarrow> G,L,store s1\<turnstile>t\<succ>v\<Colon>\<preceq>T)
schirmer@13688
  1731
                          \<and> (error_free s0 = error_free s1)"
schirmer@12925
  1732
  from eval 
schirmer@13688
  1733
  have "\<And> L accC T A. \<lbrakk>s0\<Colon>\<preceq>(G,L);\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T;
schirmer@13688
  1734
                      \<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>dom (locals (store s0))\<guillemotright>t\<guillemotright>A\<rbrakk>  
schirmer@12925
  1735
        \<Longrightarrow> s1\<Colon>\<preceq>(G,L) \<and> (normal s1 \<longrightarrow> G,L,store s1\<turnstile>t\<succ>v\<Colon>\<preceq>T)
schirmer@12925
  1736
            \<and> (error_free s0 = error_free s1)"
schirmer@12925
  1737
   (is "PROP ?TypeSafe s0 s1 t v"
schirmer@13688
  1738
    is "\<And> L accC T A. ?Conform L s0 \<Longrightarrow> ?WellTyped L accC T t  
schirmer@13688
  1739
                 \<Longrightarrow> ?DefAss L accC s0 t A 
schirmer@12925
  1740
                 \<Longrightarrow> ?Conform L s1 \<and> ?ValueTyped L T s1 t v \<and>
schirmer@12925
  1741
                     ?ErrorFree s0 s1")
schirmer@12925
  1742
  proof (induct)
berghofe@21765
  1743
    case (Abrupt xc s t L accC T A) 
wenzelm@23350
  1744
    from `(Some xc, s)\<Colon>\<preceq>(G,L)`
wenzelm@23350
  1745
    show "(Some xc, s)\<Colon>\<preceq>(G,L) \<and> 
schirmer@12925
  1746
      (normal (Some xc, s) 
schirmer@12925
  1747
      \<longrightarrow> G,L,store (Some xc,s)\<turnstile>t\<succ>arbitrary3 t\<Colon>\<preceq>T) \<and> 
schirmer@12925
  1748
      (error_free (Some xc, s) = error_free (Some xc, s))"
wenzelm@23350
  1749
      by simp
schirmer@12925
  1750
  next
schirmer@13688
  1751
    case (Skip s L accC T A)
wenzelm@23350
  1752
    from `Norm s\<Colon>\<preceq>(G, L)` and
wenzelm@23350
  1753
      `\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r Skip\<Colon>T`
wenzelm@23350
  1754
    show "Norm s\<Colon>\<preceq>(G, L) \<and>
schirmer@12925
  1755
              (normal (Norm s) \<longrightarrow> G,L,store (Norm s)\<turnstile>In1r Skip\<succ>\<diamondsuit>\<Colon>\<preceq>T) \<and> 
schirmer@12925
  1756
              (error_free (Norm s) = error_free (Norm s))"
wenzelm@23350
  1757
      by simp
schirmer@12925
  1758
  next
berghofe@21765
  1759
    case (Expr s0 e v s1 L accC T A)
wenzelm@23350
  1760
    note `G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<rightarrow> s1`
wenzelm@23350
  1761
    note hyp = `PROP ?TypeSafe (Norm s0) s1 (In1l e) (In1 v)`
wenzelm@23350
  1762
    note conf_s0 = `Norm s0\<Colon>\<preceq>(G, L)`
schirmer@13688
  1763
    moreover
wenzelm@23350
  1764
    note wt = `\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (Expr e)\<Colon>T`
schirmer@12925
  1765
    then obtain eT 
schirmer@12925
  1766
      where "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1l e\<Colon>eT"
wenzelm@23350
  1767
      by (rule wt_elim_cases) blast
schirmer@13688
  1768
    moreover
schirmer@13688
  1769
    from Expr.prems obtain E where
schirmer@13688
  1770
      "\<lparr>prg=G,cls=accC, lcl=L\<rparr>\<turnstile>dom (locals (store ((Norm s0)::state)))\<guillemotright>In1l e\<guillemotright>E"
schirmer@13688
  1771
      by (elim da_elim_cases) simp
schirmer@13688
  1772
    ultimately 
schirmer@12925
  1773
    obtain "s1\<Colon>\<preceq>(G, L)" and "error_free s1"
schirmer@13688
  1774
      by (rule hyp [elim_format]) simp
schirmer@12925
  1775
    with wt
schirmer@12925
  1776
    show "s1\<Colon>\<preceq>(G, L) \<and>
schirmer@12925
  1777
          (normal s1 \<longrightarrow> G,L,store s1\<turnstile>In1r (Expr e)\<succ>\<diamondsuit>\<Colon>\<preceq>T) \<and> 
schirmer@12925
  1778
          (error_free (Norm s0) = error_free s1)"
schirmer@12925
  1779
      by (simp)
schirmer@12925
  1780
  next
berghofe@21765
  1781
    case (Lab s0 c s1 l L accC T A)
wenzelm@23350
  1782
    note hyp = `PROP ?TypeSafe (Norm s0) s1 (In1r c) \<diamondsuit>`
wenzelm@23350
  1783
    note conf_s0 = `Norm s0\<Colon>\<preceq>(G, L)`
schirmer@13688
  1784
    moreover
wenzelm@23350
  1785
    note wt = `\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (l\<bullet> c)\<Colon>T`
schirmer@12925
  1786
    then have "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c\<Colon>\<surd>"
wenzelm@23350
  1787
      by (rule wt_elim_cases) blast
schirmer@13688
  1788
    moreover from Lab.prems obtain C where
schirmer@13688
  1789
     "\<lparr>prg=G,cls=accC, lcl=L\<rparr>\<turnstile>dom (locals (store ((Norm s0)::state)))\<guillemotright>In1r c\<guillemotright>C"
schirmer@13688
  1790
      by (elim da_elim_cases) simp
schirmer@13688
  1791
    ultimately
schirmer@12925
  1792
    obtain       conf_s1: "s1\<Colon>\<preceq>(G, L)" and 
schirmer@12925
  1793
           error_free_s1: "error_free s1" 
schirmer@13688
  1794
      by (rule hyp [elim_format]) simp
schirmer@13337
  1795
    from conf_s1 have "abupd (absorb l) s1\<Colon>\<preceq>(G, L)"
schirmer@12925
  1796
      by (cases s1) (auto intro: conforms_absorb)
schirmer@12925
  1797
    with wt error_free_s1
schirmer@13337
  1798
    show "abupd (absorb l) s1\<Colon>\<preceq>(G, L) \<and>
schirmer@13337
  1799
          (normal (abupd (absorb l) s1)
schirmer@13337
  1800
           \<longrightarrow> G,L,store (abupd (absorb l) s1)\<turnstile>In1r (l\<bullet> c)\<succ>\<diamondsuit>\<Colon>\<preceq>T) \<and>
schirmer@13337
  1801
          (error_free (Norm s0) = error_free (abupd (absorb l) s1))"
schirmer@12925
  1802
      by (simp)
schirmer@12925
  1803
  next
berghofe@21765
  1804
    case (Comp s0 c1 s1 c2 s2 L accC T A)
wenzelm@23350
  1805
    note eval_c1 = `G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1`
wenzelm@23350
  1806
    note eval_c2 = `G\<turnstile>s1 \<midarrow>c2\<rightarrow> s2`
wenzelm@23350
  1807
    note hyp_c1 = `PROP ?TypeSafe (Norm s0) s1 (In1r c1) \<diamondsuit>`
wenzelm@23350
  1808
    note hyp_c2 = `PROP ?TypeSafe s1        s2 (In1r c2) \<diamondsuit>`
wenzelm@23350
  1809
    note conf_s0 = `Norm s0\<Colon>\<preceq>(G, L)`
wenzelm@23350
  1810
    note wt = `\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (c1;; c2)\<Colon>T`
schirmer@12925
  1811
    then obtain wt_c1: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c1\<Colon>\<surd>" and
schirmer@12925
  1812
                wt_c2: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c2\<Colon>\<surd>"
wenzelm@23350
  1813
      by (rule wt_elim_cases) blast
schirmer@13688
  1814
    from Comp.prems
schirmer@13688
  1815
    obtain C1 C2
schirmer@13688
  1816
      where da_c1: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile> 
schirmer@13688
  1817
                      dom (locals (store ((Norm s0)::state))) \<guillemotright>In1r c1\<guillemotright> C1" and 
schirmer@13688
  1818
            da_c2: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>  nrm C1 \<guillemotright>In1r c2\<guillemotright> C2" 
schirmer@13688
  1819
      by (elim da_elim_cases) simp
schirmer@13688
  1820
    from conf_s0 wt_c1 da_c1
schirmer@13688
  1821
    obtain conf_s1: "s1\<Colon>\<preceq>(G, L)" and 
schirmer@13688
  1822
           error_free_s1: "error_free s1"
schirmer@13688
  1823
      by (rule hyp_c1 [elim_format]) simp
schirmer@12925
  1824
    show "s2\<Colon>\<preceq>(G, L) \<and>
schirmer@12925
  1825
          (normal s2 \<longrightarrow> G,L,store s2\<turnstile>In1r (c1;; c2)\<succ>\<diamondsuit>\<Colon>\<preceq>T) \<and>
schirmer@12925
  1826
          (error_free (Norm s0) = error_free s2)"
schirmer@13688
  1827
    proof (cases "normal s1")
schirmer@13688
  1828
      case False
schirmer@13688
  1829
      with eval_c2 have "s2=s1" by auto
schirmer@13688
  1830
      with conf_s1 error_free_s1 False wt show ?thesis
schirmer@13688
  1831
	by simp
schirmer@13688
  1832
    next
schirmer@13688
  1833
      case True
schirmer@13688
  1834
      obtain C2' where 
schirmer@13688
  1835
	"\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile> dom (locals (store s1)) \<guillemotright>In1r c2\<guillemotright> C2'"
schirmer@13688
  1836
      proof -
schirmer@13688
  1837
	from eval_c1 wt_c1 da_c1 wf True
schirmer@13688
  1838
	have "nrm C1 \<subseteq> dom (locals (store s1))"
nipkow@17589
  1839
	  by (cases rule: da_good_approxE') iprover
wenzelm@23350
  1840
	with da_c2 show thesis
wenzelm@23350
  1841
	  by (rule da_weakenE) (rule that)
schirmer@13688
  1842
      qed
schirmer@13688
  1843
      with conf_s1 wt_c2 
schirmer@13688
  1844
      obtain "s2\<Colon>\<preceq>(G, L)" and "error_free s2"
schirmer@13688
  1845
	by (rule hyp_c2 [elim_format]) (simp add: error_free_s1)
schirmer@13688
  1846
      thus ?thesis
schirmer@13688
  1847
	using wt by simp
schirmer@13688
  1848
    qed
schirmer@12925
  1849
  next
berghofe@21765
  1850
    case (If s0 e b s1 c1 c2 s2 L accC T A)
wenzelm@23350
  1851
    note eval_e = `G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1`
wenzelm@23350
  1852
    note eval_then_else = `G\<turnstile>s1 \<midarrow>(if the_Bool b then c1 else c2)\<rightarrow> s2`
wenzelm@23350
  1853
    note hyp_e = `PROP ?TypeSafe (Norm s0) s1 (In1l e) (In1 b)`
wenzelm@23350
  1854
    note hyp_then_else =
wenzelm@23350
  1855
      `PROP ?TypeSafe s1 s2 (In1r (if the_Bool b then c1 else c2)) \<diamondsuit>`
wenzelm@23350
  1856
    note conf_s0 = `Norm s0\<Colon>\<preceq>(G, L)`
wenzelm@23350
  1857
    note wt = `\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (If(e) c1 Else c2)\<Colon>T`
schirmer@13688
  1858
    then obtain 
schirmer@13688
  1859
              wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-PrimT Boolean" and
schirmer@13688
  1860
      wt_then_else: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>(if the_Bool b then c1 else c2)\<Colon>\<surd>"
schirmer@13688
  1861
      (*
schirmer@13688
  1862
                wt_c1: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>c1\<Colon>\<surd>" and
schirmer@13688
  1863
                wt_c2: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>c2\<Colon>\<surd>"*)
schirmer@12925
  1864
      by (rule wt_elim_cases) (auto split add: split_if)
schirmer@13688
  1865
    from If.prems obtain E C where
schirmer@13688
  1866
      da_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> dom (locals (store ((Norm s0)::state))) 
schirmer@13688
  1867
                                       \<guillemotright>In1l e\<guillemotright> E" and
schirmer@13688
  1868
      da_then_else: 
schirmer@13688
  1869
      "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> 
schirmer@13688
  1870
         (dom (locals (store ((Norm s0)::state))) \<union> assigns_if (the_Bool b) e)
schirmer@13688
  1871
          \<guillemotright>In1r (if the_Bool b then c1 else c2)\<guillemotright> C"
schirmer@13688
  1872
     (*
schirmer@13688
  1873
     da_c1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> (dom (locals (store ((Norm s0)::state))) 
schirmer@13688
  1874
                                      \<union> assigns_if True e) \<guillemotright>In1r c1\<guillemotright> C1" and
schirmer@13688
  1875
     da_c2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> (dom (locals (store ((Norm s0)::state))) 
schirmer@13688
  1876
                                       \<union> assigns_if False e) \<guillemotright>In1r c2\<guillemotright> C2" *)
schirmer@13688
  1877
      by (elim da_elim_cases) (cases "the_Bool b",auto)
schirmer@13688
  1878
    from conf_s0 wt_e da_e  
schirmer@13688
  1879
    obtain conf_s1: "s1\<Colon>\<preceq>(G, L)" and error_free_s1: "error_free s1"
schirmer@13688
  1880
      by (rule hyp_e [elim_format]) simp
schirmer@12925
  1881
    show "s2\<Colon>\<preceq>(G, L) \<and>
schirmer@12925
  1882
           (normal s2 \<longrightarrow> G,L,store s2\<turnstile>In1r (If(e) c1 Else c2)\<succ>\<diamondsuit>\<Colon>\<preceq>T) \<and>
schirmer@12925
  1883
           (error_free (Norm s0) = error_free s2)"
schirmer@13688
  1884
    proof (cases "normal s1")
schirmer@13688
  1885
      case False
schirmer@13688
  1886
      with eval_then_else have "s2=s1" by auto
schirmer@13688
  1887
      with conf_s1 error_free_s1 False wt show ?thesis
schirmer@13688
  1888
	by simp
schirmer@13688
  1889
    next
schirmer@13688
  1890
      case True
schirmer@13688
  1891
      obtain C' where
schirmer@13688
  1892
	"\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> 
schirmer@13688
  1893
          (dom (locals (store s1)))\<guillemotright>In1r (if the_Bool b then c1 else c2)\<guillemotright> C'"
schirmer@13688
  1894
      proof -
schirmer@13688
  1895
	from eval_e have 
schirmer@13688
  1896
	  "dom (locals (store ((Norm s0)::state))) \<subseteq> dom (locals (store s1))"
schirmer@13688
  1897
	  by (rule dom_locals_eval_mono_elim)
schirmer@13688
  1898
        moreover
schirmer@13688
  1899
	from eval_e True wt_e 
schirmer@13688
  1900
	have "assigns_if (the_Bool b) e \<subseteq> dom (locals (store s1))"
schirmer@13688
  1901
	  by (rule assigns_if_good_approx')
schirmer@13688
  1902
	ultimately 
schirmer@13688
  1903
	have "dom (locals (store ((Norm s0)::state))) 
schirmer@13688
  1904
                \<union> assigns_if (the_Bool b) e \<subseteq> dom (locals (store s1))"
schirmer@13688
  1905
	  by (rule Un_least)
wenzelm@23350
  1906
	with da_then_else show thesis
wenzelm@23350
  1907
	  by (rule da_weakenE) (rule that)
schirmer@13688
  1908
      qed
schirmer@13688
  1909
      with conf_s1 wt_then_else  
schirmer@13688
  1910
      obtain "s2\<Colon>\<preceq>(G, L)" and "error_free s2"
schirmer@13688
  1911
	by (rule hyp_then_else [elim_format]) (simp add: error_free_s1)
schirmer@13688
  1912
      with wt show ?thesis
schirmer@13688
  1913
	by simp
schirmer@13688
  1914
    qed
schirmer@13688
  1915
    -- {* Note that we don't have to show that @{term b} really is a boolean 
schirmer@13688
  1916
          value. With @{term the_Bool} we enforce to get a value of boolean 
schirmer@13688
  1917
          type. So execution will be type safe, even if b would be
schirmer@13688
  1918
          a string, for example. We might not expect such a behaviour to be
schirmer@13688
  1919
          called type safe. To remedy the situation we would have to change
schirmer@13688
  1920
          the evaulation rule, so that it only has a type safe evaluation if
schirmer@13688
  1921
          we actually get a boolean value for the condition. That b is actually
schirmer@13688
  1922
          a boolean value is part of @{term hyp_e}. See also Loop 
schirmer@13688
  1923
       *}
schirmer@12925
  1924
  next
berghofe@21765
  1925
    case (Loop s0 e b s1 c s2 l s3 L accC T A)
wenzelm@23350
  1926
    note eval_e = `G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1`
wenzelm@23350
  1927
    note hyp_e = `PROP ?TypeSafe (Norm s0) s1 (In1l e) (In1 b)`
wenzelm@23350
  1928
    note conf_s0 = `Norm s0\<Colon>\<preceq>(G, L)`
wenzelm@23350
  1929
    note wt = `\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (l\<bullet> While(e) c)\<Colon>T`
schirmer@12925
  1930
    then obtain wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-PrimT Boolean" and
schirmer@12925
  1931
                wt_c: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c\<Colon>\<surd>"
wenzelm@23350
  1932
      by (rule wt_elim_cases) blast
wenzelm@23350
  1933
    note da = `\<lparr>prg=G, cls=accC, lcl=L\<rparr>
wenzelm@23350
  1934
            \<turnstile> dom (locals(store ((Norm s0)::state))) \<guillemotright>In1r (l\<bullet> While(e) c)\<guillemotright> A`
schirmer@13688
  1935
    then
schirmer@13688
  1936
    obtain E C where
schirmer@13688
  1937
      da_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>
schirmer@13688
  1938
              \<turnstile> dom (locals (store ((Norm s0)::state))) \<guillemotright>In1l e\<guillemotright> E" and
schirmer@13688
  1939
      da_c: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>
schirmer@13688
  1940
              \<turnstile> (dom (locals (store ((Norm s0)::state))) 
schirmer@13688
  1941
                   \<union> assigns_if True e) \<guillemotright>In1r c\<guillemotright> C" 
schirmer@13688
  1942
      by (rule da_elim_cases) simp
wenzelm@23350
  1943
    from conf_s0 wt_e da_e
schirmer@12925
  1944
    obtain conf_s1: "s1\<Colon>\<preceq>(G, L)" and error_free_s1: "error_free s1"
schirmer@13688
  1945
      by (rule hyp_e [elim_format]) simp
schirmer@12925
  1946
    show "s3\<Colon>\<preceq>(G, L) \<and>
schirmer@12925
  1947
          (normal s3 \<longrightarrow> G,L,store s3\<turnstile>In1r (l\<bullet> While(e) c)\<succ>\<diamondsuit>\<Colon>\<preceq>T) \<and>
schirmer@12925
  1948
          (error_free (Norm s0) = error_free s3)"
schirmer@13688
  1949
    proof (cases "normal s1")
schirmer@12925
  1950
      case True
schirmer@13688
  1951
      note normal_s1 = this
schirmer@12925
  1952
      show ?thesis
schirmer@13688
  1953
      proof (cases "the_Bool b")
schirmer@13688
  1954
	case True
schirmer@13688
  1955
	with Loop.hyps  obtain
schirmer@13688
  1956
          eval_c: "G\<turnstile>s1 \<midarrow>c\<rightarrow> s2" and 
schirmer@13688
  1957
          eval_while: "G\<turnstile>abupd (absorb (Cont l)) s2 \<midarrow>l\<bullet> While(e) c\<rightarrow> s3"
schirmer@13688
  1958
	  by simp 
schirmer@13688
  1959
	have "?TypeSafeObj s1 s2 (In1r c) \<diamondsuit>"
schirmer@13688
  1960
	  using Loop.hyps True by simp
schirmer@13688
  1961
	note hyp_c = this [rule_format]
schirmer@13688
  1962
	have "?TypeSafeObj (abupd (absorb (Cont l)) s2)
schirmer@13688
  1963
          s3 (In1r (l\<bullet> While(e) c)) \<diamondsuit>"
schirmer@13688
  1964
	  using Loop.hyps True by simp
schirmer@13688
  1965
	note hyp_w = this [rule_format]
schirmer@13688
  1966
	from eval_e have 
schirmer@13688
  1967
	  s0_s1: "dom (locals (store ((Norm s0)::state)))
schirmer@13688
  1968
                    \<subseteq> dom (locals (store s1))"
schirmer@13688
  1969
	  by (rule dom_locals_eval_mono_elim)
schirmer@13688
  1970
	obtain C' where
schirmer@13688
  1971
	  "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>(dom (locals (store s1)))\<guillemotright>In1r c\<guillemotright> C'" 
schirmer@13688
  1972
	proof -
schirmer@13688
  1973
	  note s0_s1
schirmer@13688
  1974
          moreover
schirmer@13688
  1975
	  from eval_e normal_s1 wt_e 
schirmer@13688
  1976
	  have "assigns_if True e \<subseteq> dom (locals (store s1))"
schirmer@13688
  1977
	    by (rule assigns_if_good_approx' [elim_format]) (simp add: True)
schirmer@13688
  1978
	  ultimately 
schirmer@13688
  1979
	  have "dom (locals (store ((Norm s0)::state))) 
schirmer@13688
  1980
                 \<union> assigns_if True e \<subseteq> dom (locals (store s1))"
schirmer@13688
  1981
	    by (rule Un_least)
wenzelm@23350
  1982
	  with da_c show thesis
wenzelm@23350
  1983
	    by (rule da_weakenE) (rule that)
schirmer@13688
  1984
	qed
schirmer@13688
  1985
	with conf_s1 wt_c  
schirmer@13688
  1986
	obtain conf_s2:  "s2\<Colon>\<preceq>(G, L)" and error_free_s2: "error_free s2"
schirmer@13688
  1987
	  by (rule hyp_c [elim_format]) (simp add: error_free_s1)
schirmer@13688
  1988
	from error_free_s2 
schirmer@13688
  1989
	have error_free_ab_s2: "error_free (abupd (absorb (Cont l)) s2)"
schirmer@13688
  1990
	  by simp
schirmer@13688
  1991
	from conf_s2 have "abupd (absorb (Cont l)) s2 \<Colon>\<preceq>(G, L)"
schirmer@13688
  1992
	  by (cases s2) (auto intro: conforms_absorb)
schirmer@13688
  1993
	moreover note wt
schirmer@13688
  1994
	moreover
schirmer@13688
  1995
	obtain A' where 
schirmer@13688
  1996
          "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile> 
schirmer@13688
  1997
              dom (locals(store (abupd (absorb (Cont l)) s2)))
schirmer@13688
  1998
                \<guillemotright>In1r (l\<bullet> While(e) c)\<guillemotright> A'"
schirmer@13688
  1999
	proof -
schirmer@13688
  2000
	  note s0_s1