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