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