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