src/HOL/Bali/TypeSafe.thy
author schirmer
Mon Jan 28 17:00:19 2002 +0100 (2002-01-28)
changeset 12854 00d4a435777f
child 12857 a4386cc9b1c3
permissions -rw-r--r--
Isabelle/Bali sources;
schirmer@12854
     1
(*  Title:      isabelle/Bali/TypeSafe.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
schirmer@12854
     4
    Copyright   1997 Technische Universitaet Muenchen
schirmer@12854
     5
*)
schirmer@12854
     6
header {* The type soundness proof for Java *}
schirmer@12854
     7
schirmer@12854
     8
schirmer@12854
     9
theory TypeSafe = Eval + WellForm + Conform:
schirmer@12854
    10
schirmer@12854
    11
section "result conformance"
schirmer@12854
    12
schirmer@12854
    13
constdefs
schirmer@12854
    14
  assign_conforms :: "st \<Rightarrow> (val \<Rightarrow> state \<Rightarrow> state) \<Rightarrow> ty \<Rightarrow> env_ \<Rightarrow> bool"
schirmer@12854
    15
          ("_\<le>|_\<preceq>_\<Colon>\<preceq>_"                                        [71,71,71,71] 70)
schirmer@12854
    16
 "s\<le>|f\<preceq>T\<Colon>\<preceq>E \<equiv>
schirmer@12854
    17
  \<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"
schirmer@12854
    18
schirmer@12854
    19
  rconf :: "prog \<Rightarrow> lenv \<Rightarrow> st \<Rightarrow> term \<Rightarrow> vals \<Rightarrow> tys \<Rightarrow> bool"
schirmer@12854
    20
          ("_,_,_\<turnstile>_\<succ>_\<Colon>\<preceq>_"                               [71,71,71,71,71,71] 70)
schirmer@12854
    21
  "G,L,s\<turnstile>t\<succ>v\<Colon>\<preceq>T 
schirmer@12854
    22
    \<equiv> case T of
schirmer@12854
    23
        Inl T  \<Rightarrow> if (\<exists>vf. t=In2 vf)
schirmer@12854
    24
                  then G,s\<turnstile>fst (the_In2 v)\<Colon>\<preceq>T \<and> s\<le>|snd (the_In2 v)\<preceq>T\<Colon>\<preceq>(G,L)
schirmer@12854
    25
                  else G,s\<turnstile>the_In1 v\<Colon>\<preceq>T
schirmer@12854
    26
      | Inr Ts \<Rightarrow> list_all2 (conf G s) (the_In3 v) Ts"
schirmer@12854
    27
schirmer@12854
    28
lemma rconf_In1 [simp]: 
schirmer@12854
    29
 "G,L,s\<turnstile>In1 ec\<succ>In1 v \<Colon>\<preceq>Inl T  =  G,s\<turnstile>v\<Colon>\<preceq>T"
schirmer@12854
    30
apply (unfold rconf_def)
schirmer@12854
    31
apply (simp (no_asm))
schirmer@12854
    32
done
schirmer@12854
    33
schirmer@12854
    34
lemma rconf_In2 [simp]: 
schirmer@12854
    35
 "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
    36
apply (unfold rconf_def)
schirmer@12854
    37
apply (simp (no_asm))
schirmer@12854
    38
done
schirmer@12854
    39
schirmer@12854
    40
lemma rconf_In3 [simp]: 
schirmer@12854
    41
 "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
    42
apply (unfold rconf_def)
schirmer@12854
    43
apply (simp (no_asm))
schirmer@12854
    44
done
schirmer@12854
    45
schirmer@12854
    46
section "fits and conf"
schirmer@12854
    47
schirmer@12854
    48
(* unused *)
schirmer@12854
    49
lemma conf_fits: "G,s\<turnstile>v\<Colon>\<preceq>T \<Longrightarrow> G,s\<turnstile>v fits T"
schirmer@12854
    50
apply (unfold fits_def)
schirmer@12854
    51
apply clarify
schirmer@12854
    52
apply (erule swap, simp (no_asm_use))
schirmer@12854
    53
apply (drule conf_RefTD)
schirmer@12854
    54
apply auto
schirmer@12854
    55
done
schirmer@12854
    56
schirmer@12854
    57
lemma fits_conf: 
schirmer@12854
    58
  "\<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
    59
apply (auto dest!: fitsD cast_PrimT2 cast_RefT2)
schirmer@12854
    60
apply (force dest: conf_RefTD intro: conf_AddrI)
schirmer@12854
    61
done
schirmer@12854
    62
schirmer@12854
    63
lemma fits_Array: 
schirmer@12854
    64
 "\<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
    65
apply (auto dest!: fitsD widen_ArrayPrimT widen_ArrayRefT)
schirmer@12854
    66
apply (force dest: conf_RefTD intro: conf_AddrI)
schirmer@12854
    67
done
schirmer@12854
    68
schirmer@12854
    69
schirmer@12854
    70
schirmer@12854
    71
section "gext"
schirmer@12854
    72
schirmer@12854
    73
lemma halloc_gext: "\<And>s1 s2. G\<turnstile>s1 \<midarrow>halloc oi\<succ>a\<rightarrow> s2 \<Longrightarrow> snd s1\<le>|snd s2"
schirmer@12854
    74
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
    75
apply (erule halloc.induct)
schirmer@12854
    76
apply  (auto dest!: new_AddrD)
schirmer@12854
    77
done
schirmer@12854
    78
schirmer@12854
    79
lemma sxalloc_gext: "\<And>s1 s2. G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2 \<Longrightarrow> snd s1\<le>|snd s2"
schirmer@12854
    80
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
    81
apply (erule sxalloc.induct)
schirmer@12854
    82
apply   (auto dest!: halloc_gext)
schirmer@12854
    83
done
schirmer@12854
    84
schirmer@12854
    85
lemma eval_gext_lemma [rule_format (no_asm)]: 
schirmer@12854
    86
 "G\<turnstile>s \<midarrow>t\<succ>\<rightarrow> (w,s') \<Longrightarrow> snd s\<le>|snd s' \<and> (case w of  
schirmer@12854
    87
    In1 v \<Rightarrow> True  
schirmer@12854
    88
  | In2 vf \<Rightarrow> normal s \<longrightarrow> (\<forall>v x s. s\<le>|snd (assign (snd vf) v (x,s)))  
schirmer@12854
    89
  | In3 vs \<Rightarrow> True)"
schirmer@12854
    90
apply (erule eval_induct)
schirmer@12854
    91
prefer 24 
schirmer@12854
    92
  apply (case_tac "inited C (globs s0)", clarsimp, erule thin_rl) (* Init *)
schirmer@12854
    93
apply (auto del: conjI  dest!: not_initedD gext_new sxalloc_gext halloc_gext
schirmer@12854
    94
 simp  add: lvar_def fvar_def2 avar_def2 init_lvars_def2
schirmer@12854
    95
 split del: split_if_asm split add: sum3.split)
schirmer@12854
    96
(* 6 subgoals *)
schirmer@12854
    97
apply force+
schirmer@12854
    98
done
schirmer@12854
    99
schirmer@12854
   100
lemma evar_gext_f: 
schirmer@12854
   101
  "G\<turnstile>Norm s1 \<midarrow>e=\<succ>vf \<rightarrow> s2 \<Longrightarrow> s\<le>|snd (assign (snd vf) v (x,s))"
schirmer@12854
   102
apply (drule eval_gext_lemma [THEN conjunct2])
schirmer@12854
   103
apply auto
schirmer@12854
   104
done
schirmer@12854
   105
schirmer@12854
   106
lemmas eval_gext = eval_gext_lemma [THEN conjunct1]
schirmer@12854
   107
schirmer@12854
   108
lemma eval_gext': "G\<turnstile>(x1,s1) \<midarrow>t\<succ>\<rightarrow> (w,x2,s2) \<Longrightarrow> s1\<le>|s2"
schirmer@12854
   109
apply (drule eval_gext)
schirmer@12854
   110
apply auto
schirmer@12854
   111
done
schirmer@12854
   112
schirmer@12854
   113
lemma init_yields_initd: "G\<turnstile>Norm s1 \<midarrow>Init C\<rightarrow> s2 \<Longrightarrow> initd C s2"
schirmer@12854
   114
apply (erule eval_cases , auto split del: split_if_asm)
schirmer@12854
   115
apply (case_tac "inited C (globs s1)")
schirmer@12854
   116
apply  (clarsimp split del: split_if_asm)+
schirmer@12854
   117
apply (drule eval_gext')+
schirmer@12854
   118
apply (drule init_class_obj_inited)
schirmer@12854
   119
apply (erule inited_gext)
schirmer@12854
   120
apply (simp (no_asm_use))
schirmer@12854
   121
done
schirmer@12854
   122
schirmer@12854
   123
schirmer@12854
   124
section "Lemmas"
schirmer@12854
   125
schirmer@12854
   126
lemma obj_ty_obj_class1: 
schirmer@12854
   127
 "\<lbrakk>wf_prog G; is_type G (obj_ty obj)\<rbrakk> \<Longrightarrow> is_class G (obj_class obj)"
schirmer@12854
   128
apply (case_tac "tag obj")
schirmer@12854
   129
apply (auto simp add: obj_ty_def obj_class_def)
schirmer@12854
   130
done
schirmer@12854
   131
schirmer@12854
   132
lemma oconf_init_obj: 
schirmer@12854
   133
 "\<lbrakk>wf_prog G;  
schirmer@12854
   134
 (case r of Heap a \<Rightarrow> is_type G (obj_ty obj) | Stat C \<Rightarrow> is_class G C)
schirmer@12854
   135
\<rbrakk> \<Longrightarrow> G,s\<turnstile>obj \<lparr>values:=init_vals (var_tys G (tag obj) r)\<rparr>\<Colon>\<preceq>\<surd>r"
schirmer@12854
   136
apply (auto intro!: oconf_init_obj_lemma unique_fields)
schirmer@12854
   137
done
schirmer@12854
   138
schirmer@12854
   139
(*
schirmer@12854
   140
lemma obj_split: "P obj = (\<forall> oi vs. obj = \<lparr>tag=oi,values=vs\<rparr> \<longrightarrow> ?P \<lparr>tag=oi,values=vs\<rparr>)"
schirmer@12854
   141
apply auto
schirmer@12854
   142
apply (case_tac "obj")
schirmer@12854
   143
apply auto
schirmer@12854
   144
*)
schirmer@12854
   145
schirmer@12854
   146
lemma conforms_newG: "\<lbrakk>globs s oref = None; (x, s)\<Colon>\<preceq>(G,L);   
schirmer@12854
   147
  wf_prog G; case oref of Heap a \<Rightarrow> is_type G (obj_ty \<lparr>tag=oi,values=vs\<rparr>)  
schirmer@12854
   148
                        | Stat C \<Rightarrow> is_class G C\<rbrakk> \<Longrightarrow>  
schirmer@12854
   149
  (x, init_obj G oi oref s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   150
apply (unfold init_obj_def)
schirmer@12854
   151
apply (auto elim!: conforms_gupd dest!: oconf_init_obj 
schirmer@12854
   152
            simp add: obj.update_defs)
schirmer@12854
   153
done
schirmer@12854
   154
schirmer@12854
   155
lemma conforms_init_class_obj: 
schirmer@12854
   156
 "\<lbrakk>(x,s)\<Colon>\<preceq>(G, L); wf_prog G; class G C=Some y; \<not> inited C (globs s)\<rbrakk> \<Longrightarrow> 
schirmer@12854
   157
  (x,init_class_obj G C s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   158
apply (rule not_initedD [THEN conforms_newG])
schirmer@12854
   159
apply    (auto)
schirmer@12854
   160
done
schirmer@12854
   161
schirmer@12854
   162
schirmer@12854
   163
lemma fst_init_lvars[simp]: 
schirmer@12854
   164
 "fst (init_lvars G C sig (invmode m e) a' pvs (x,s)) = 
schirmer@12854
   165
  (if static m then x else (np a') x)"
schirmer@12854
   166
apply (simp (no_asm) add: init_lvars_def2)
schirmer@12854
   167
done
schirmer@12854
   168
schirmer@12854
   169
schirmer@12854
   170
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
   171
  is_type G (obj_ty \<lparr>tag=oi,values=fs\<rparr>)\<rbrakk> \<Longrightarrow> s2\<Colon>\<preceq>(G, L)"
schirmer@12854
   172
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   173
apply (case_tac "aa")
schirmer@12854
   174
apply  (auto elim!: halloc_elim_cases dest!: new_AddrD 
schirmer@12854
   175
       intro!: conforms_newG [THEN conforms_xconf] conf_AddrI)
schirmer@12854
   176
done
schirmer@12854
   177
schirmer@12854
   178
lemma halloc_type_sound: "\<And>s1. \<lbrakk>G\<turnstile>s1 \<midarrow>halloc oi\<succ>a\<rightarrow> (x,s); wf_prog G; s1\<Colon>\<preceq>(G, L);
schirmer@12854
   179
  T = obj_ty \<lparr>tag=oi,values=fs\<rparr>; is_type G T\<rbrakk> \<Longrightarrow>  
schirmer@12854
   180
  (x,s)\<Colon>\<preceq>(G, L) \<and> (x = None \<longrightarrow> G,s\<turnstile>Addr a\<Colon>\<preceq>T)"
schirmer@12854
   181
apply (auto elim!: halloc_conforms)
schirmer@12854
   182
apply (case_tac "aa")
schirmer@12854
   183
apply (subst obj_ty_eq)
schirmer@12854
   184
apply  (auto elim!: halloc_elim_cases dest!: new_AddrD intro!: conf_AddrI)
schirmer@12854
   185
done
schirmer@12854
   186
schirmer@12854
   187
lemma sxalloc_type_sound: 
schirmer@12854
   188
 "\<And>s1 s2. \<lbrakk>G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2; wf_prog G\<rbrakk> \<Longrightarrow> case fst s1 of  
schirmer@12854
   189
  None \<Rightarrow> s2 = s1 | Some x \<Rightarrow>  
schirmer@12854
   190
  (\<exists>a. fst s2 = Some(Xcpt (Loc a)) \<and> (\<forall>L. s1\<Colon>\<preceq>(G,L) \<longrightarrow> s2\<Colon>\<preceq>(G,L)))"
schirmer@12854
   191
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12854
   192
apply (erule sxalloc.induct)
schirmer@12854
   193
apply   auto
schirmer@12854
   194
apply (rule halloc_conforms [THEN conforms_xconf])
schirmer@12854
   195
apply     (auto elim!: halloc_elim_cases dest!: new_AddrD intro!: conf_AddrI)
schirmer@12854
   196
done
schirmer@12854
   197
schirmer@12854
   198
lemma wt_init_comp_ty: 
schirmer@12854
   199
"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
   200
apply (unfold init_comp_ty_def)
schirmer@12854
   201
apply (clarsimp simp add: accessible_in_RefT_simp 
schirmer@12854
   202
                          is_acc_type_def is_acc_class_def)
schirmer@12854
   203
done
schirmer@12854
   204
schirmer@12854
   205
schirmer@12854
   206
declare fun_upd_same [simp]
schirmer@12854
   207
schirmer@12854
   208
declare fun_upd_apply [simp del]
schirmer@12854
   209
schirmer@12854
   210
schirmer@12854
   211
constdefs
schirmer@12854
   212
  DynT_prop::"[prog,inv_mode,qtname,ref_ty] \<Rightarrow> bool" 
schirmer@12854
   213
                                              ("_\<turnstile>_\<rightarrow>_\<preceq>_"[71,71,71,71]70)
schirmer@12854
   214
 "G\<turnstile>mode\<rightarrow>D\<preceq>t \<equiv> mode = IntVir \<longrightarrow> is_class G D \<and> 
schirmer@12854
   215
                     (if (\<exists>T. t=ArrayT T) then D=Object else G\<turnstile>Class D\<preceq>RefT t)"
schirmer@12854
   216
schirmer@12854
   217
lemma DynT_propI: 
schirmer@12854
   218
 "\<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
   219
  \<Longrightarrow>  G\<turnstile>mode\<rightarrow>invocation_class mode s a' statT\<preceq>statT"
schirmer@12854
   220
proof (unfold DynT_prop_def)
schirmer@12854
   221
  assume state_conform: "(x,s)\<Colon>\<preceq>(G, L)"
schirmer@12854
   222
     and      statT_a': "G,s\<turnstile>a'\<Colon>\<preceq>RefT statT"
schirmer@12854
   223
     and            wf: "wf_prog G"
schirmer@12854
   224
     and          mode: "mode = IntVir \<longrightarrow> a' \<noteq> Null"
schirmer@12854
   225
  let ?invCls = "(invocation_class mode s a' statT)"
schirmer@12854
   226
  let ?IntVir = "mode = IntVir"
schirmer@12854
   227
  let ?Concl  = "\<lambda>invCls. is_class G invCls \<and>
schirmer@12854
   228
                          (if \<exists>T. statT = ArrayT T
schirmer@12854
   229
                                  then invCls = Object
schirmer@12854
   230
                                  else G\<turnstile>Class invCls\<preceq>RefT statT)"
schirmer@12854
   231
  show "?IntVir \<longrightarrow> ?Concl ?invCls"
schirmer@12854
   232
  proof  
schirmer@12854
   233
    assume modeIntVir: ?IntVir 
schirmer@12854
   234
    with mode have not_Null: "a' \<noteq> Null" ..
schirmer@12854
   235
    from statT_a' not_Null state_conform 
schirmer@12854
   236
    obtain a obj 
schirmer@12854
   237
      where obj_props:  "a' = Addr a" "globs s (Inl a) = Some obj"   
schirmer@12854
   238
                        "G\<turnstile>obj_ty obj\<preceq>RefT statT" "is_type G (obj_ty obj)"
schirmer@12854
   239
      by (blast dest: conforms_RefTD)
schirmer@12854
   240
    show "?Concl ?invCls"
schirmer@12854
   241
    proof (cases "tag obj")
schirmer@12854
   242
      case CInst
schirmer@12854
   243
      with modeIntVir obj_props
schirmer@12854
   244
      show ?thesis 
schirmer@12854
   245
	by (auto dest!: widen_Array2 split add: split_if)
schirmer@12854
   246
    next
schirmer@12854
   247
      case Arr
schirmer@12854
   248
      from Arr obtain T where "obj_ty obj = T.[]" by (blast dest: obj_ty_Arr1)
schirmer@12854
   249
      moreover from Arr have "obj_class obj = Object" 
schirmer@12854
   250
	by (blast dest: obj_class_Arr1)
schirmer@12854
   251
      moreover note modeIntVir obj_props wf 
schirmer@12854
   252
      ultimately show ?thesis by (auto dest!: widen_Array )
schirmer@12854
   253
    qed
schirmer@12854
   254
  qed
schirmer@12854
   255
qed
schirmer@12854
   256
schirmer@12854
   257
lemma invocation_methd:
schirmer@12854
   258
"\<lbrakk>wf_prog G; statT \<noteq> NullT; 
schirmer@12854
   259
 (\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC);
schirmer@12854
   260
 (\<forall>     I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> mode \<noteq> SuperM);
schirmer@12854
   261
 (\<forall>     T. statT = ArrayT T \<longrightarrow> mode \<noteq> SuperM);
schirmer@12854
   262
 G\<turnstile>mode\<rightarrow>invocation_class mode s a' statT\<preceq>statT;  
schirmer@12854
   263
 dynlookup G statT (invocation_class mode s a' statT) sig = Some m \<rbrakk> 
schirmer@12854
   264
\<Longrightarrow> methd G (invocation_declclass G mode s a' statT sig) sig = Some m"
schirmer@12854
   265
proof -
schirmer@12854
   266
  assume         wf: "wf_prog G"
schirmer@12854
   267
     and  not_NullT: "statT \<noteq> NullT"
schirmer@12854
   268
     and statC_prop: "(\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC)"
schirmer@12854
   269
     and statI_prop: "(\<forall> I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> mode \<noteq> SuperM)"
schirmer@12854
   270
     and statA_prop: "(\<forall>     T. statT = ArrayT T \<longrightarrow> mode \<noteq> SuperM)"
schirmer@12854
   271
     and  invC_prop: "G\<turnstile>mode\<rightarrow>invocation_class mode s a' statT\<preceq>statT"
schirmer@12854
   272
     and  dynlookup: "dynlookup G statT (invocation_class mode s a' statT) sig 
schirmer@12854
   273
                      = Some m"
schirmer@12854
   274
  show ?thesis
schirmer@12854
   275
  proof (cases statT)
schirmer@12854
   276
    case NullT
schirmer@12854
   277
    with not_NullT show ?thesis by simp
schirmer@12854
   278
  next
schirmer@12854
   279
    case IfaceT
schirmer@12854
   280
    with statI_prop obtain I 
schirmer@12854
   281
      where    statI: "statT = IfaceT I" and 
schirmer@12854
   282
            is_iface: "is_iface G I"     and
schirmer@12854
   283
          not_SuperM: "mode \<noteq> SuperM" by blast            
schirmer@12854
   284
    
schirmer@12854
   285
    show ?thesis 
schirmer@12854
   286
    proof (cases mode)
schirmer@12854
   287
      case Static
schirmer@12854
   288
      with wf dynlookup statI is_iface 
schirmer@12854
   289
      show ?thesis
schirmer@12854
   290
	by (auto simp add: invocation_declclass_def dynlookup_def 
schirmer@12854
   291
                           dynimethd_def dynmethd_C_C 
schirmer@12854
   292
	            intro: dynmethd_declclass
schirmer@12854
   293
	            dest!: wf_imethdsD
schirmer@12854
   294
                     dest: table_of_map_SomeI
schirmer@12854
   295
                    split: split_if_asm)
schirmer@12854
   296
    next	
schirmer@12854
   297
      case SuperM
schirmer@12854
   298
      with not_SuperM show ?thesis ..
schirmer@12854
   299
    next
schirmer@12854
   300
      case IntVir
schirmer@12854
   301
      with wf dynlookup IfaceT invC_prop show ?thesis 
schirmer@12854
   302
	by (auto simp add: invocation_declclass_def dynlookup_def dynimethd_def
schirmer@12854
   303
                           DynT_prop_def
schirmer@12854
   304
	            intro: methd_declclass dynmethd_declclass
schirmer@12854
   305
	            split: split_if_asm)
schirmer@12854
   306
    qed
schirmer@12854
   307
  next
schirmer@12854
   308
    case ClassT
schirmer@12854
   309
    show ?thesis
schirmer@12854
   310
    proof (cases mode)
schirmer@12854
   311
      case Static
schirmer@12854
   312
      with wf ClassT dynlookup statC_prop 
schirmer@12854
   313
      show ?thesis by (auto simp add: invocation_declclass_def dynlookup_def
schirmer@12854
   314
                               intro: dynmethd_declclass)
schirmer@12854
   315
    next
schirmer@12854
   316
      case SuperM
schirmer@12854
   317
      with wf ClassT dynlookup statC_prop 
schirmer@12854
   318
      show ?thesis by (auto simp add: invocation_declclass_def dynlookup_def
schirmer@12854
   319
                               intro: dynmethd_declclass)
schirmer@12854
   320
    next
schirmer@12854
   321
      case IntVir
schirmer@12854
   322
      with wf ClassT dynlookup statC_prop invC_prop 
schirmer@12854
   323
      show ?thesis
schirmer@12854
   324
	by (auto simp add: invocation_declclass_def dynlookup_def dynimethd_def
schirmer@12854
   325
                           DynT_prop_def
schirmer@12854
   326
	            intro: dynmethd_declclass)
schirmer@12854
   327
    qed
schirmer@12854
   328
  next
schirmer@12854
   329
    case ArrayT
schirmer@12854
   330
    show ?thesis
schirmer@12854
   331
    proof (cases mode)
schirmer@12854
   332
      case Static
schirmer@12854
   333
      with wf ArrayT dynlookup show ?thesis
schirmer@12854
   334
	by (auto simp add: invocation_declclass_def dynlookup_def 
schirmer@12854
   335
                           dynimethd_def dynmethd_C_C
schirmer@12854
   336
                    intro: dynmethd_declclass
schirmer@12854
   337
                     dest: table_of_map_SomeI)
schirmer@12854
   338
    next
schirmer@12854
   339
      case SuperM
schirmer@12854
   340
      with ArrayT statA_prop show ?thesis by blast
schirmer@12854
   341
    next
schirmer@12854
   342
      case IntVir
schirmer@12854
   343
      with wf ArrayT dynlookup invC_prop show ?thesis
schirmer@12854
   344
	by (auto simp add: invocation_declclass_def dynlookup_def dynimethd_def
schirmer@12854
   345
                           DynT_prop_def dynmethd_C_C
schirmer@12854
   346
                    intro: dynmethd_declclass
schirmer@12854
   347
                     dest: table_of_map_SomeI)
schirmer@12854
   348
    qed
schirmer@12854
   349
  qed
schirmer@12854
   350
qed
schirmer@12854
   351
   
schirmer@12854
   352
declare split_paired_All [simp del] split_paired_Ex [simp del] 
schirmer@12854
   353
ML_setup {*
schirmer@12854
   354
simpset_ref() := simpset() delloop "split_all_tac";
schirmer@12854
   355
claset_ref () := claset () delSWrapper "split_all_tac"
schirmer@12854
   356
*}
schirmer@12854
   357
lemma DynT_mheadsD: 
schirmer@12854
   358
"\<lbrakk>G\<turnstile>invmode (mhd sm) e\<rightarrow>invC\<preceq>statT; 
schirmer@12854
   359
  wf_prog G; \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT; 
schirmer@12854
   360
  sm \<in> mheads G C statT sig; 
schirmer@12854
   361
  invC = invocation_class (invmode (mhd sm) e) s a' statT;
schirmer@12854
   362
  declC =invocation_declclass G (invmode (mhd sm) e) s a' statT sig
schirmer@12854
   363
 \<rbrakk> \<Longrightarrow> 
schirmer@12854
   364
  \<exists> dm. 
schirmer@12854
   365
  methd G declC sig = Some dm  \<and> G\<turnstile>resTy (mthd dm)\<preceq>resTy (mhd sm) \<and> 
schirmer@12854
   366
  wf_mdecl G declC (sig, mthd dm) \<and>
schirmer@12854
   367
  declC = declclass dm \<and>
schirmer@12854
   368
  is_static dm = is_static sm \<and>  
schirmer@12854
   369
  is_class G invC \<and> is_class G declC  \<and> G\<turnstile>invC\<preceq>\<^sub>C declC \<and>  
schirmer@12854
   370
  (if invmode (mhd sm) e = IntVir
schirmer@12854
   371
      then (\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)
schirmer@12854
   372
      else (  (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   373
            \<or> (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object)) \<and> 
schirmer@12854
   374
           (declrefT sm) = ClassT (declclass dm))"
schirmer@12854
   375
proof -
schirmer@12854
   376
  assume invC_prop: "G\<turnstile>invmode (mhd sm) e\<rightarrow>invC\<preceq>statT" 
schirmer@12854
   377
     and        wf: "wf_prog G" 
schirmer@12854
   378
     and      wt_e: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT"
schirmer@12854
   379
     and        sm: "sm \<in> mheads G C statT sig" 
schirmer@12854
   380
     and      invC: "invC = invocation_class (invmode (mhd sm) e) s a' statT"
schirmer@12854
   381
     and     declC: "declC = 
schirmer@12854
   382
                    invocation_declclass G (invmode (mhd sm) e) s a' statT sig"
schirmer@12854
   383
  from wt_e wf have type_statT: "is_type G (RefT statT)"
schirmer@12854
   384
    by (auto dest: ty_expr_is_type)
schirmer@12854
   385
  from sm have not_Null: "statT \<noteq> NullT" by auto
schirmer@12854
   386
  from type_statT 
schirmer@12854
   387
  have wf_C: "(\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC)"
schirmer@12854
   388
    by (auto)
schirmer@12854
   389
  from type_statT wt_e 
schirmer@12854
   390
  have wf_I: "(\<forall>I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> 
schirmer@12854
   391
                                        invmode (mhd sm) e \<noteq> SuperM)"
schirmer@12854
   392
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   393
  from wt_e
schirmer@12854
   394
  have wf_A: "(\<forall>     T. statT = ArrayT T \<longrightarrow> invmode (mhd sm) e \<noteq> SuperM)"
schirmer@12854
   395
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   396
  show ?thesis
schirmer@12854
   397
  proof (cases "invmode (mhd sm) e = IntVir")
schirmer@12854
   398
    case True
schirmer@12854
   399
    with invC_prop not_Null
schirmer@12854
   400
    have invC_prop': " is_class G invC \<and> 
schirmer@12854
   401
                      (if (\<exists>T. statT=ArrayT T) then invC=Object 
schirmer@12854
   402
                                              else G\<turnstile>Class invC\<preceq>RefT statT)"
schirmer@12854
   403
      by (auto simp add: DynT_prop_def) 
schirmer@12854
   404
    from True 
schirmer@12854
   405
    have "\<not> is_static sm"
schirmer@12854
   406
      by (simp add: invmode_IntVir_eq)
schirmer@12854
   407
    with invC_prop' not_Null
schirmer@12854
   408
    have "G,statT \<turnstile> invC valid_lookup_cls_for (is_static sm)"
schirmer@12854
   409
      by (cases statT) auto
schirmer@12854
   410
    with sm wf type_statT obtain dm where
schirmer@12854
   411
           dm: "dynlookup G statT invC sig = Some dm" and
schirmer@12854
   412
      resT_dm: "G\<turnstile>resTy (mthd dm)\<preceq>resTy (mhd sm)"      and
schirmer@12854
   413
       static: "is_static dm = is_static sm"
schirmer@12854
   414
      by - (drule dynamic_mheadsD,auto)
schirmer@12854
   415
    with declC invC not_Null 
schirmer@12854
   416
    have declC': "declC = (declclass dm)" 
schirmer@12854
   417
      by (auto simp add: invocation_declclass_def)
schirmer@12854
   418
    with wf invC declC not_Null wf_C wf_I wf_A invC_prop dm 
schirmer@12854
   419
    have dm': "methd G declC sig = Some dm"
schirmer@12854
   420
      by - (drule invocation_methd,auto)
schirmer@12854
   421
    from wf dm invC_prop' declC' type_statT 
schirmer@12854
   422
    have declC_prop: "G\<turnstile>invC \<preceq>\<^sub>C declC \<and> is_class G declC"
schirmer@12854
   423
      by (auto dest: dynlookup_declC)
schirmer@12854
   424
    from wf dm' declC_prop declC' 
schirmer@12854
   425
    have wf_dm: "wf_mdecl G declC (sig,(mthd dm))"
schirmer@12854
   426
      by (auto dest: methd_wf_mdecl)
schirmer@12854
   427
    from invC_prop' 
schirmer@12854
   428
    have statC_prop: "(\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)"
schirmer@12854
   429
      by auto
schirmer@12854
   430
    from True dm' resT_dm wf_dm invC_prop' declC_prop statC_prop declC' static
schirmer@12854
   431
    show ?thesis by auto
schirmer@12854
   432
  next
schirmer@12854
   433
    case False
schirmer@12854
   434
    with type_statT wf invC not_Null wf_I wf_A
schirmer@12854
   435
    have invC_prop': "is_class G invC \<and>  
schirmer@12854
   436
                     ((\<exists> statC. statT=ClassT statC \<and> invC=statC) \<or>
schirmer@12854
   437
                      (\<forall> statC. statT\<noteq>ClassT statC \<and> invC=Object)) "
schirmer@12854
   438
        by (case_tac "statT") (auto simp add: invocation_class_def 
schirmer@12854
   439
                                       split: inv_mode.splits)
schirmer@12854
   440
    with not_Null wf
schirmer@12854
   441
    have dynlookup_static: "dynlookup G statT invC sig = methd G invC sig"
schirmer@12854
   442
      by (case_tac "statT") (auto simp add: dynlookup_def dynmethd_C_C
schirmer@12854
   443
                                            dynimethd_def)
schirmer@12854
   444
    from sm wf wt_e not_Null False invC_prop' obtain "dm" where
schirmer@12854
   445
                    dm: "methd G invC sig = Some dm"          and
schirmer@12854
   446
	eq_declC_sm_dm:"declrefT sm = ClassT (declclass dm)"  and
schirmer@12854
   447
	     eq_mheads:"mhd sm=mhead (mthd dm) "
schirmer@12854
   448
      by - (drule static_mheadsD, auto dest: accmethd_SomeD)
schirmer@12854
   449
    then have static: "is_static dm = is_static sm" by - (case_tac "sm",auto)
schirmer@12854
   450
    with declC invC dynlookup_static dm
schirmer@12854
   451
    have declC': "declC = (declclass dm)"  
schirmer@12854
   452
      by (auto simp add: invocation_declclass_def)
schirmer@12854
   453
    from invC_prop' wf declC' dm 
schirmer@12854
   454
    have dm': "methd G declC sig = Some dm"
schirmer@12854
   455
      by (auto intro: methd_declclass)
schirmer@12854
   456
    from wf dm invC_prop' declC' type_statT 
schirmer@12854
   457
    have declC_prop: "G\<turnstile>invC \<preceq>\<^sub>C declC \<and> is_class G declC"
schirmer@12854
   458
      by (auto dest: methd_declC )
schirmer@12854
   459
    then have declC_prop1: "invC=Object \<longrightarrow> declC=Object"  by auto
schirmer@12854
   460
    from wf dm' declC_prop declC' 
schirmer@12854
   461
    have wf_dm: "wf_mdecl G declC (sig,(mthd dm))"
schirmer@12854
   462
      by (auto dest: methd_wf_mdecl)
schirmer@12854
   463
    from invC_prop' declC_prop declC_prop1
schirmer@12854
   464
    have statC_prop: "(   (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   465
                       \<or>  (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object))" 
schirmer@12854
   466
      by auto
schirmer@12854
   467
    from False dm' wf_dm invC_prop' declC_prop statC_prop declC' 
schirmer@12854
   468
         eq_declC_sm_dm eq_mheads static
schirmer@12854
   469
    show ?thesis by auto
schirmer@12854
   470
  qed
schirmer@12854
   471
qed
schirmer@12854
   472
schirmer@12854
   473
(*
schirmer@12854
   474
lemma DynT_mheadsD: 
schirmer@12854
   475
"\<lbrakk>G\<turnstile>invmode (mhd sm) e\<rightarrow>invC\<preceq>statT; 
schirmer@12854
   476
  wf_prog G; \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT; 
schirmer@12854
   477
  sm \<in> mheads G C statT sig; 
schirmer@12854
   478
  invC = invocation_class (invmode (mhd sm) e) s a' statT;
schirmer@12854
   479
  declC =invocation_declclass G (invmode (mhd sm) e) s a' statT sig
schirmer@12854
   480
 \<rbrakk> \<Longrightarrow> 
schirmer@12854
   481
  \<exists> dm. 
schirmer@12854
   482
  methd G declC sig = Some dm  \<and> G\<turnstile>resTy (mthd dm)\<preceq>resTy (mhd sm) \<and> 
schirmer@12854
   483
  wf_mdecl G declC (sig, mthd dm) \<and>  
schirmer@12854
   484
  is_class G invC \<and> is_class G declC  \<and> G\<turnstile>invC\<preceq>\<^sub>C declC \<and>  
schirmer@12854
   485
  (if invmode (mhd sm) e = IntVir
schirmer@12854
   486
      then (\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)
schirmer@12854
   487
      else (\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>statC \<preceq>\<^sub>C declC) \<and> 
schirmer@12854
   488
           (declrefT sm) = ClassT (declclass dm))"
schirmer@12854
   489
proof -
schirmer@12854
   490
  assume invC_prop: "G\<turnstile>invmode (mhd sm) e\<rightarrow>invC\<preceq>statT" 
schirmer@12854
   491
     and        wf: "wf_prog G" 
schirmer@12854
   492
     and      wt_e: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT"
schirmer@12854
   493
     and        sm: "sm \<in> mheads G C statT sig" 
schirmer@12854
   494
     and      invC: "invC = invocation_class (invmode (mhd sm) e) s a' statT"
schirmer@12854
   495
     and     declC: "declC = 
schirmer@12854
   496
                    invocation_declclass G (invmode (mhd sm) e) s a' statT sig"
schirmer@12854
   497
  from wt_e wf have type_statT: "is_type G (RefT statT)"
schirmer@12854
   498
    by (auto dest: ty_expr_is_type)
schirmer@12854
   499
  from sm have not_Null: "statT \<noteq> NullT" by auto
schirmer@12854
   500
  from type_statT 
schirmer@12854
   501
  have wf_C: "(\<forall> statC. statT = ClassT statC \<longrightarrow> is_class G statC)"
schirmer@12854
   502
    by (auto)
schirmer@12854
   503
  from type_statT wt_e 
schirmer@12854
   504
  have wf_I: "(\<forall>I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> 
schirmer@12854
   505
                                        invmode (mhd sm) e \<noteq> SuperM)"
schirmer@12854
   506
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   507
  from wt_e
schirmer@12854
   508
  have wf_A: "(\<forall>     T. statT = ArrayT T \<longrightarrow> invmode (mhd sm) e \<noteq> SuperM)"
schirmer@12854
   509
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   510
  show ?thesis
schirmer@12854
   511
  proof (cases "invmode (mhd sm) e = IntVir")
schirmer@12854
   512
    case True
schirmer@12854
   513
    with invC_prop not_Null
schirmer@12854
   514
    have invC_prop': "is_class G invC \<and>  
schirmer@12854
   515
                      (if (\<exists>T. statT=ArrayT T) then invC=Object 
schirmer@12854
   516
                                              else G\<turnstile>Class invC\<preceq>RefT statT)"
schirmer@12854
   517
      by (auto simp add: DynT_prop_def) 
schirmer@12854
   518
    with sm wf type_statT not_Null obtain dm where
schirmer@12854
   519
           dm: "dynlookup G statT invC sig = Some dm" and
schirmer@12854
   520
      resT_dm: "G\<turnstile>resTy (mthd dm)\<preceq>resTy (mhd sm)"
schirmer@12854
   521
      by - (clarify,drule dynamic_mheadsD,auto)
schirmer@12854
   522
    with declC invC not_Null 
schirmer@12854
   523
    have declC': "declC = (declclass dm)" 
schirmer@12854
   524
      by (auto simp add: invocation_declclass_def)
schirmer@12854
   525
    with wf invC declC not_Null wf_C wf_I wf_A invC_prop dm 
schirmer@12854
   526
    have dm': "methd G declC sig = Some dm"
schirmer@12854
   527
      by - (drule invocation_methd,auto)
schirmer@12854
   528
    from wf dm invC_prop' declC' type_statT 
schirmer@12854
   529
    have declC_prop: "G\<turnstile>invC \<preceq>\<^sub>C declC \<and> is_class G declC"
schirmer@12854
   530
      by (auto dest: dynlookup_declC)
schirmer@12854
   531
    from wf dm' declC_prop declC' 
schirmer@12854
   532
    have wf_dm: "wf_mdecl G declC (sig,(mthd dm))"
schirmer@12854
   533
      by (auto dest: methd_wf_mdecl)
schirmer@12854
   534
    from invC_prop' 
schirmer@12854
   535
    have statC_prop: "(\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>invC \<preceq>\<^sub>C statC)"
schirmer@12854
   536
      by auto
schirmer@12854
   537
    from True dm' resT_dm wf_dm invC_prop' declC_prop statC_prop
schirmer@12854
   538
    show ?thesis by auto
schirmer@12854
   539
  next
schirmer@12854
   540
    case False
schirmer@12854
   541
    
schirmer@12854
   542
    with type_statT wf invC not_Null wf_I wf_A
schirmer@12854
   543
    have invC_prop': "is_class G invC \<and>  
schirmer@12854
   544
                     ((\<exists> statC. statT=ClassT statC \<and> invC=statC) \<or>
schirmer@12854
   545
                      (\<forall> statC. statT\<noteq>ClassT statC \<and> invC=Object)) "
schirmer@12854
   546
        
schirmer@12854
   547
        by (case_tac "statT") (auto simp add: invocation_class_def 
schirmer@12854
   548
                                       split: inv_mode.splits)
schirmer@12854
   549
    with not_Null 
schirmer@12854
   550
    have dynlookup_static: "dynlookup G statT invC sig = methd G invC sig"
schirmer@12854
   551
      by (case_tac "statT") (auto simp add: dynlookup_def dynmethd_def 
schirmer@12854
   552
                                            dynimethd_def)
schirmer@12854
   553
    from sm wf wt_e not_Null False invC_prop' obtain "dm" where
schirmer@12854
   554
                    dm: "methd G invC sig = Some dm"          and
schirmer@12854
   555
	eq_declC_sm_dm:"declrefT sm = ClassT (declclass dm)"  and
schirmer@12854
   556
	     eq_mheads:"mhd sm=mhead (mthd dm) "
schirmer@12854
   557
      by - (drule static_mheadsD, auto dest: accmethd_SomeD)
schirmer@12854
   558
    with declC invC dynlookup_static dm
schirmer@12854
   559
    have declC': "declC = (declclass dm)"  
schirmer@12854
   560
      by (auto simp add: invocation_declclass_def)
schirmer@12854
   561
    from invC_prop' wf declC' dm 
schirmer@12854
   562
    have dm': "methd G declC sig = Some dm"
schirmer@12854
   563
      by (auto intro: methd_declclass)
schirmer@12854
   564
    from wf dm invC_prop' declC' type_statT 
schirmer@12854
   565
    have declC_prop: "G\<turnstile>invC \<preceq>\<^sub>C declC \<and> is_class G declC"
schirmer@12854
   566
      by (auto dest: methd_declC )   
schirmer@12854
   567
    from wf dm' declC_prop declC' 
schirmer@12854
   568
    have wf_dm: "wf_mdecl G declC (sig,(mthd dm))"
schirmer@12854
   569
      by (auto dest: methd_wf_mdecl)
schirmer@12854
   570
    from invC_prop' declC_prop
schirmer@12854
   571
    have statC_prop: "(\<forall> statC. statT=ClassT statC \<longrightarrow> G\<turnstile>statC \<preceq>\<^sub>C declC)" 
schirmer@12854
   572
      by auto
schirmer@12854
   573
    from False dm' wf_dm invC_prop' declC_prop statC_prop 
schirmer@12854
   574
         eq_declC_sm_dm eq_mheads
schirmer@12854
   575
    show ?thesis by auto
schirmer@12854
   576
  qed
schirmer@12854
   577
qed	
schirmer@12854
   578
*)
schirmer@12854
   579
schirmer@12854
   580
declare split_paired_All [simp del] split_paired_Ex [simp del] 
schirmer@12854
   581
declare split_if     [split del] split_if_asm     [split del] 
schirmer@12854
   582
        option.split [split del] option.split_asm [split del]
schirmer@12854
   583
ML_setup {*
schirmer@12854
   584
simpset_ref() := simpset() delloop "split_all_tac";
schirmer@12854
   585
claset_ref () := claset () delSWrapper "split_all_tac"
schirmer@12854
   586
*}
schirmer@12854
   587
schirmer@12854
   588
lemma DynT_conf: "\<lbrakk>G\<turnstile>invocation_class mode s a' statT \<preceq>\<^sub>C declC; wf_prog G;
schirmer@12854
   589
 isrtype G (statT);
schirmer@12854
   590
 G,s\<turnstile>a'\<Colon>\<preceq>RefT statT; mode = IntVir \<longrightarrow> a' \<noteq> Null;  
schirmer@12854
   591
  mode \<noteq> IntVir \<longrightarrow>    (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   592
                    \<or>  (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object)\<rbrakk> 
schirmer@12854
   593
 \<Longrightarrow>G,s\<turnstile>a'\<Colon>\<preceq> Class declC"
schirmer@12854
   594
apply (case_tac "mode = IntVir")
schirmer@12854
   595
apply (drule conf_RefTD)
schirmer@12854
   596
apply (force intro!: conf_AddrI 
schirmer@12854
   597
            simp add: obj_class_def split add: obj_tag.split_asm)
schirmer@12854
   598
apply  clarsimp
schirmer@12854
   599
apply  safe
schirmer@12854
   600
apply    (erule (1) widen.subcls [THEN conf_widen])
schirmer@12854
   601
apply    (erule wf_ws_prog)
schirmer@12854
   602
schirmer@12854
   603
apply    (frule widen_Object) apply (erule wf_ws_prog)
schirmer@12854
   604
apply    (erule (1) conf_widen) apply (erule wf_ws_prog)
schirmer@12854
   605
done
schirmer@12854
   606
schirmer@12854
   607
schirmer@12854
   608
lemma Ass_lemma: 
schirmer@12854
   609
 "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(w, f)\<rightarrow> Norm s1; G\<turnstile>Norm s1 \<midarrow>e-\<succ>v\<rightarrow> Norm s2; G,s2\<turnstile>v\<Colon>\<preceq>T'; 
schirmer@12854
   610
   s1\<le>|s2 \<longrightarrow> assign f v (Norm s2)\<Colon>\<preceq>(G, L)
schirmer@12854
   611
  \<rbrakk> \<Longrightarrow> assign f v (Norm s2)\<Colon>\<preceq>(G, L) \<and> 
schirmer@12854
   612
        (\<lambda>(x',s'). x' = None \<longrightarrow> G,s'\<turnstile>v\<Colon>\<preceq>T') (assign f v (Norm s2))"
schirmer@12854
   613
apply (drule_tac x = "None" and s = "s2" and v = "v" in evar_gext_f)
schirmer@12854
   614
apply (drule eval_gext', clarsimp)
schirmer@12854
   615
apply (erule conf_gext)
schirmer@12854
   616
apply simp
schirmer@12854
   617
done
schirmer@12854
   618
schirmer@12854
   619
lemma Throw_lemma: "\<lbrakk>G\<turnstile>tn\<preceq>\<^sub>C SXcpt Throwable; wf_prog G; (x1,s1)\<Colon>\<preceq>(G, L);  
schirmer@12854
   620
    x1 = None \<longrightarrow> G,s1\<turnstile>a'\<Colon>\<preceq> Class tn\<rbrakk> \<Longrightarrow> (throw a' x1, s1)\<Colon>\<preceq>(G, L)"
schirmer@12854
   621
apply (auto split add: split_abrupt_if simp add: throw_def2)
schirmer@12854
   622
apply (erule conforms_xconf)
schirmer@12854
   623
apply (frule conf_RefTD)
schirmer@12854
   624
apply (auto elim: widen.subcls [THEN conf_widen])
schirmer@12854
   625
done
schirmer@12854
   626
schirmer@12854
   627
lemma Try_lemma: "\<lbrakk>G\<turnstile>obj_ty (the (globs s1' (Heap a)))\<preceq> Class tn; 
schirmer@12854
   628
 (Some (Xcpt (Loc a)), s1')\<Colon>\<preceq>(G, L); wf_prog G\<rbrakk> 
schirmer@12854
   629
 \<Longrightarrow> Norm (lupd(vn\<mapsto>Addr a) s1')\<Colon>\<preceq>(G, L(vn\<mapsto>Class tn))"
schirmer@12854
   630
apply (rule conforms_allocL)
schirmer@12854
   631
apply  (erule conforms_NormI)
schirmer@12854
   632
apply (drule conforms_XcptLocD [THEN conf_RefTD],rule HOL.refl)
schirmer@12854
   633
apply (auto intro!: conf_AddrI)
schirmer@12854
   634
done
schirmer@12854
   635
schirmer@12854
   636
lemma Fin_lemma: 
schirmer@12854
   637
"\<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)\<rbrakk> 
schirmer@12854
   638
\<Longrightarrow>  (abrupt_if True (Some a) x2, s2)\<Colon>\<preceq>(G, L)"
schirmer@12854
   639
apply (force elim: eval_gext' conforms_xgext split add: split_abrupt_if)
schirmer@12854
   640
done
schirmer@12854
   641
schirmer@12854
   642
lemma FVar_lemma1: "\<lbrakk>table_of (DeclConcepts.fields G Ca) (fn, C) = Some f ; 
schirmer@12854
   643
  x2 = None \<longrightarrow> G,s2\<turnstile>a\<Colon>\<preceq> Class Ca; wf_prog G; G\<turnstile>Ca\<preceq>\<^sub>C C; C \<noteq> Object; 
schirmer@12854
   644
  class G C = Some y; (x2,s2)\<Colon>\<preceq>(G, L); s1\<le>|s2; inited C (globs s1); 
schirmer@12854
   645
  (if static f then id else np a) x2 = None\<rbrakk> 
schirmer@12854
   646
 \<Longrightarrow>  
schirmer@12854
   647
  \<exists>obj. globs s2 (if static f then Inr C else Inl (the_Addr a)) = Some obj \<and> 
schirmer@12854
   648
  var_tys G (tag obj)  (if static f then Inr C else Inl(the_Addr a)) 
schirmer@12854
   649
          (Inl(fn,C)) = Some (type f)"
schirmer@12854
   650
apply (drule initedD)
schirmer@12854
   651
apply (frule subcls_is_class2, simp (no_asm_simp))
schirmer@12854
   652
apply (case_tac "static f")
schirmer@12854
   653
apply  clarsimp
schirmer@12854
   654
apply  (drule (1) rev_gext_objD, clarsimp)
schirmer@12854
   655
apply  (frule fields_declC, erule wf_ws_prog, simp (no_asm_simp))
schirmer@12854
   656
apply  (rule var_tys_Some_eq [THEN iffD2])
schirmer@12854
   657
apply  clarsimp
schirmer@12854
   658
apply  (erule fields_table_SomeI, simp (no_asm))
schirmer@12854
   659
apply clarsimp
schirmer@12854
   660
apply (drule conf_RefTD, clarsimp, rule var_tys_Some_eq [THEN iffD2])
schirmer@12854
   661
apply (auto dest!: widen_Array split add: obj_tag.split)
schirmer@12854
   662
apply (rotate_tac -1) (* to front: tag obja = CInst pid_field_type to enable
schirmer@12854
   663
                         conditional rewrite *)
schirmer@12854
   664
apply (rule fields_table_SomeI)
schirmer@12854
   665
apply (auto elim!: fields_mono subcls_is_class2)
schirmer@12854
   666
done
schirmer@12854
   667
schirmer@12854
   668
lemma FVar_lemma: 
schirmer@12854
   669
"\<lbrakk>((v, f), Norm s2') = fvar C (static field) fn a (x2, s2); G\<turnstile>Ca\<preceq>\<^sub>C C;  
schirmer@12854
   670
  table_of (DeclConcepts.fields G Ca) (fn, C) = Some field; wf_prog G;   
schirmer@12854
   671
  x2 = None \<longrightarrow> G,s2\<turnstile>a\<Colon>\<preceq>Class Ca; C \<noteq> Object; class G C = Some y;   
schirmer@12854
   672
  (x2, s2)\<Colon>\<preceq>(G, L); s1\<le>|s2; inited C (globs s1)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   673
  G,s2'\<turnstile>v\<Colon>\<preceq>type field \<and> s2'\<le>|f\<preceq>type field\<Colon>\<preceq>(G, L)"
schirmer@12854
   674
apply (unfold assign_conforms_def)
schirmer@12854
   675
apply (drule sym)
schirmer@12854
   676
apply (clarsimp simp add: fvar_def2)
schirmer@12854
   677
apply (drule (9) FVar_lemma1)
schirmer@12854
   678
apply (clarsimp)
schirmer@12854
   679
apply (drule (2) conforms_globsD [THEN oconf_lconf, THEN lconfD])
schirmer@12854
   680
apply clarsimp
schirmer@12854
   681
apply (drule (1) rev_gext_objD)
schirmer@12854
   682
apply (auto elim!: conforms_upd_gobj)
schirmer@12854
   683
done
schirmer@12854
   684
schirmer@12854
   685
schirmer@12854
   686
lemma AVar_lemma1: "\<lbrakk>globs s (Inl a) = Some obj;tag obj=Arr ty i; 
schirmer@12854
   687
 the_Intg i' in_bounds i; wf_prog G; G\<turnstile>ty.[]\<preceq>Tb.[]; Norm s\<Colon>\<preceq>(G, L)
schirmer@12854
   688
\<rbrakk> \<Longrightarrow> G,s\<turnstile>the ((values obj) (Inr (the_Intg i')))\<Colon>\<preceq>Tb"
schirmer@12854
   689
apply (erule widen_Array_Array [THEN conf_widen])
schirmer@12854
   690
apply  (erule_tac [2] wf_ws_prog)
schirmer@12854
   691
apply (drule (1) conforms_globsD [THEN oconf_lconf, THEN lconfD])
schirmer@12854
   692
defer apply assumption
schirmer@12854
   693
apply (force intro: var_tys_Some_eq [THEN iffD2])
schirmer@12854
   694
done
schirmer@12854
   695
schirmer@12854
   696
lemma obj_split: "\<And> obj. \<exists> t vs. obj = \<lparr>tag=t,values=vs\<rparr>"
schirmer@12854
   697
proof record_split
schirmer@12854
   698
  fix tag values more
schirmer@12854
   699
  show "\<exists>t vs. \<lparr>tag = tag, values = values, \<dots> = more\<rparr> = \<lparr>tag = t, values = vs\<rparr>"
schirmer@12854
   700
    by auto
schirmer@12854
   701
qed
schirmer@12854
   702
 
schirmer@12854
   703
lemma AVar_lemma: "\<lbrakk>wf_prog G; G\<turnstile>(x1, s1) \<midarrow>e2-\<succ>i\<rightarrow> (x2, s2);  
schirmer@12854
   704
  ((v,f), Norm s2') = avar G i a (x2, s2); x1 = None \<longrightarrow> G,s1\<turnstile>a\<Colon>\<preceq>Ta.[];  
schirmer@12854
   705
  (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
   706
apply (unfold assign_conforms_def)
schirmer@12854
   707
apply (drule sym)
schirmer@12854
   708
apply (clarsimp simp add: avar_def2)
schirmer@12854
   709
apply (drule (1) conf_gext)
schirmer@12854
   710
apply (drule conf_RefTD, clarsimp)
schirmer@12854
   711
apply (subgoal_tac "\<exists> t vs. obj = \<lparr>tag=t,values=vs\<rparr>")
schirmer@12854
   712
defer
schirmer@12854
   713
apply   (rule obj_split)
schirmer@12854
   714
apply clarify
schirmer@12854
   715
apply (frule obj_ty_widenD)
schirmer@12854
   716
apply (auto dest!: widen_Class)
schirmer@12854
   717
apply  (force dest: AVar_lemma1)
schirmer@12854
   718
apply (auto split add: split_if)
schirmer@12854
   719
apply (force elim!: fits_Array dest: gext_objD 
schirmer@12854
   720
       intro: var_tys_Some_eq [THEN iffD2] conforms_upd_gobj)
schirmer@12854
   721
done
schirmer@12854
   722
schirmer@12854
   723
schirmer@12854
   724
section "Call"
schirmer@12854
   725
lemma conforms_init_lvars_lemma: "\<lbrakk>wf_prog G;  
schirmer@12854
   726
  wf_mhead G P sig mh; 
schirmer@12854
   727
  Ball (set lvars) (split (\<lambda>vn. is_type G)); 
schirmer@12854
   728
  list_all2 (conf G s) pvs pTsa; G\<turnstile>pTsa[\<preceq>](parTs sig)\<rbrakk> \<Longrightarrow>  
schirmer@12854
   729
  G,s\<turnstile>init_vals (table_of lvars)(pars mh[\<mapsto>]pvs)
schirmer@12854
   730
      [\<Colon>\<preceq>]table_of lvars(pars mh[\<mapsto>]parTs sig)"
schirmer@12854
   731
apply (unfold wf_mhead_def)
schirmer@12854
   732
apply clarify
schirmer@12854
   733
apply (erule (2) Ball_set_table [THEN lconf_init_vals, THEN lconf_ext_list])
schirmer@12854
   734
apply (drule wf_ws_prog)
schirmer@12854
   735
apply (erule (2) conf_list_widen)
schirmer@12854
   736
done
schirmer@12854
   737
schirmer@12854
   738
schirmer@12854
   739
lemma lconf_map_lname [simp]: 
schirmer@12854
   740
  "G,s\<turnstile>(lname_case l1 l2)[\<Colon>\<preceq>](lname_case L1 L2)
schirmer@12854
   741
   =
schirmer@12854
   742
  (G,s\<turnstile>l1[\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>(\<lambda>x::unit . l2)[\<Colon>\<preceq>](\<lambda>x::unit. L2))"
schirmer@12854
   743
apply (unfold lconf_def)
schirmer@12854
   744
apply safe
schirmer@12854
   745
apply (case_tac "n")
schirmer@12854
   746
apply (force split add: lname.split)+
schirmer@12854
   747
done
schirmer@12854
   748
schirmer@12854
   749
lemma lconf_map_ename [simp]:
schirmer@12854
   750
  "G,s\<turnstile>(ename_case l1 l2)[\<Colon>\<preceq>](ename_case L1 L2)
schirmer@12854
   751
   =
schirmer@12854
   752
  (G,s\<turnstile>l1[\<Colon>\<preceq>]L1 \<and> G,s\<turnstile>(\<lambda>x::unit. l2)[\<Colon>\<preceq>](\<lambda>x::unit. L2))"
schirmer@12854
   753
apply (unfold lconf_def)
schirmer@12854
   754
apply safe
schirmer@12854
   755
apply (force split add: ename.split)+
schirmer@12854
   756
done
schirmer@12854
   757
schirmer@12854
   758
schirmer@12854
   759
lemma defval_conf1 [rule_format (no_asm), elim]: 
schirmer@12854
   760
  "is_type G T \<longrightarrow> (\<exists>v\<in>Some (default_val T): G,s\<turnstile>v\<Colon>\<preceq>T)"
schirmer@12854
   761
apply (unfold conf_def)
schirmer@12854
   762
apply (induct "T")
schirmer@12854
   763
apply (auto intro: prim_ty.induct)
schirmer@12854
   764
done
schirmer@12854
   765
schirmer@12854
   766
schirmer@12854
   767
lemma conforms_init_lvars: 
schirmer@12854
   768
"\<lbrakk>wf_mhead G (pid declC) sig (mhead (mthd dm)); wf_prog G;  
schirmer@12854
   769
  list_all2 (conf G s) pvs pTsa; G\<turnstile>pTsa[\<preceq>](parTs sig);  
schirmer@12854
   770
  (x, s)\<Colon>\<preceq>(G, L); 
schirmer@12854
   771
  methd G declC sig = Some dm;  
schirmer@12854
   772
  isrtype G statT;
schirmer@12854
   773
  G\<turnstile>invC\<preceq>\<^sub>C declC; 
schirmer@12854
   774
  G,s\<turnstile>a'\<Colon>\<preceq>RefT statT;  
schirmer@12854
   775
  invmode (mhd sm) e = IntVir \<longrightarrow> a' \<noteq> Null; 
schirmer@12854
   776
  invmode (mhd sm) e \<noteq> IntVir \<longrightarrow>  
schirmer@12854
   777
       (\<exists> statC. statT=ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C declC)
schirmer@12854
   778
    \<or>  (\<forall> statC. statT\<noteq>ClassT statC \<and> declC=Object);
schirmer@12854
   779
  invC  = invocation_class (invmode (mhd sm) e) s a' statT;
schirmer@12854
   780
  declC = invocation_declclass G (invmode (mhd sm) e) s a' statT sig;
schirmer@12854
   781
  Ball (set (lcls (mbody (mthd dm)))) 
schirmer@12854
   782
       (split (\<lambda>vn. is_type G)) 
schirmer@12854
   783
 \<rbrakk> \<Longrightarrow>  
schirmer@12854
   784
  init_lvars G declC sig (invmode (mhd sm) e) a'  
schirmer@12854
   785
  pvs (x,s)\<Colon>\<preceq>(G,\<lambda> k. 
schirmer@12854
   786
                (case k of
schirmer@12854
   787
                   EName e \<Rightarrow> (case e of 
schirmer@12854
   788
                                 VNam v 
schirmer@12854
   789
                                  \<Rightarrow> (table_of (lcls (mbody (mthd dm)))
schirmer@12854
   790
                                        (pars (mthd dm)[\<mapsto>]parTs sig)) v
schirmer@12854
   791
                               | Res \<Rightarrow> Some (resTy (mthd dm)))
schirmer@12854
   792
                 | This \<Rightarrow> if (static (mthd sm)) 
schirmer@12854
   793
                              then None else Some (Class declC)))"
schirmer@12854
   794
apply (simp add: init_lvars_def2)
schirmer@12854
   795
apply (rule conforms_set_locals)
schirmer@12854
   796
apply  (simp (no_asm_simp) split add: split_if)
schirmer@12854
   797
apply (drule  (4) DynT_conf)
schirmer@12854
   798
apply clarsimp
schirmer@12854
   799
(* apply intro *)
schirmer@12854
   800
apply (drule (4) conforms_init_lvars_lemma)
schirmer@12854
   801
apply (case_tac "dm",simp)
schirmer@12854
   802
apply (rule conjI)
schirmer@12854
   803
apply (unfold lconf_def, clarify)
schirmer@12854
   804
apply (rule defval_conf1)
schirmer@12854
   805
apply (clarsimp simp add: wf_mhead_def is_acc_type_def)
schirmer@12854
   806
apply (case_tac "is_static sm")
schirmer@12854
   807
apply simp_all
schirmer@12854
   808
done
schirmer@12854
   809
schirmer@12854
   810
schirmer@12854
   811
lemma Call_type_sound: "\<lbrakk>wf_prog G; G\<turnstile>(x1, s1) \<midarrow>ps\<doteq>\<succ>pvs\<rightarrow> (x2, s2);  
schirmer@12854
   812
 declC 
schirmer@12854
   813
 = invocation_declclass G (invmode (mhd esm) e) s2 a' statT \<lparr>name=mn,parTs=pTs\<rparr>;
schirmer@12854
   814
s2'=init_lvars G declC \<lparr>name=mn,parTs=pTs\<rparr> (invmode (mhd esm) e) a' pvs (x2,s2);
schirmer@12854
   815
 G\<turnstile>s2' \<midarrow>Methd declC \<lparr>name=mn,parTs=pTs\<rparr>-\<succ>v\<rightarrow> (x3, s3);    
schirmer@12854
   816
 \<forall>L. s2'\<Colon>\<preceq>(G, L) 
schirmer@12854
   817
     \<longrightarrow> (\<forall>T. \<lparr>prg=G,cls=declC,lcl=L\<rparr>\<turnstile> Methd declC \<lparr>name=mn,parTs=pTs\<rparr>\<Colon>-T 
schirmer@12854
   818
     \<longrightarrow> (x3, s3)\<Colon>\<preceq>(G, L) \<and> (x3 = None \<longrightarrow> G,s3\<turnstile>v\<Colon>\<preceq>T));  
schirmer@12854
   819
 Norm s0\<Colon>\<preceq>(G, L); 
schirmer@12854
   820
 \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT; \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>ps\<Colon>\<doteq>pTsa;  
schirmer@12854
   821
 max_spec G C statT \<lparr>name=mn,parTs=pTsa\<rparr> = {(esm, pTs)}; 
schirmer@12854
   822
 (x1, s1)\<Colon>\<preceq>(G, L); 
schirmer@12854
   823
 x1 = None \<longrightarrow> G,s1\<turnstile>a'\<Colon>\<preceq>RefT statT; (x2, s2)\<Colon>\<preceq>(G, L);  
schirmer@12854
   824
 x2 = None \<longrightarrow> list_all2 (conf G s2) pvs pTsa;
schirmer@12854
   825
 sm=(mhd esm)\<rbrakk> \<Longrightarrow>     
schirmer@12854
   826
 (x3, set_locals (locals s2) s3)\<Colon>\<preceq>(G, L) \<and> 
schirmer@12854
   827
 (x3 = None \<longrightarrow> G,s3\<turnstile>v\<Colon>\<preceq>resTy sm)"
schirmer@12854
   828
apply clarify
schirmer@12854
   829
apply (case_tac "x2")
schirmer@12854
   830
defer
schirmer@12854
   831
apply  (clarsimp split add: split_if_asm simp add: init_lvars_def2)
schirmer@12854
   832
apply (case_tac "a' = Null \<and> \<not> (static (mhd esm)) \<and> e \<noteq> Super")
schirmer@12854
   833
apply  (clarsimp simp add: init_lvars_def2)
schirmer@12854
   834
apply clarsimp
schirmer@12854
   835
apply (drule eval_gext')
schirmer@12854
   836
apply (frule (1) conf_gext)
schirmer@12854
   837
apply (drule max_spec2mheads, clarsimp)
schirmer@12854
   838
apply (subgoal_tac "invmode (mhd esm) e = IntVir \<longrightarrow> a' \<noteq> Null")
schirmer@12854
   839
defer  
schirmer@12854
   840
apply  (clarsimp simp add: invmode_IntVir_eq)
schirmer@12854
   841
apply (frule (6) DynT_mheadsD [OF DynT_propI,of _ "s2"],(rule HOL.refl)+)
schirmer@12854
   842
apply clarify
schirmer@12854
   843
apply (drule wf_mdeclD1, clarsimp) 
schirmer@12854
   844
apply (frule  ty_expr_is_type) apply simp
schirmer@12854
   845
apply (frule (2) conforms_init_lvars)
schirmer@12854
   846
apply   simp
schirmer@12854
   847
apply   assumption+
schirmer@12854
   848
apply   simp
schirmer@12854
   849
apply   assumption+
schirmer@12854
   850
apply   clarsimp
schirmer@12854
   851
apply   (rule HOL.refl)
schirmer@12854
   852
apply   simp
schirmer@12854
   853
apply   (rule Ball_weaken)
schirmer@12854
   854
apply     assumption
schirmer@12854
   855
apply     (force simp add: is_acc_type_def)
schirmer@12854
   856
apply (tactic "smp_tac 1 1")
schirmer@12854
   857
apply (frule (2) wt_MethdI, clarsimp)
schirmer@12854
   858
apply (subgoal_tac "is_static dm = (static (mthd esm))") 
schirmer@12854
   859
apply   (simp only:)
schirmer@12854
   860
apply   (tactic "smp_tac 1 1")
schirmer@12854
   861
apply   (rule conjI)
schirmer@12854
   862
apply     (erule  conforms_return)
schirmer@12854
   863
apply     blast
schirmer@12854
   864
schirmer@12854
   865
apply     (force dest!: eval_gext del: impCE simp add: init_lvars_def2)
schirmer@12854
   866
apply     clarsimp
schirmer@12854
   867
apply     (drule (2) widen_trans, erule (1) conf_widen)
schirmer@12854
   868
apply     (erule wf_ws_prog)
schirmer@12854
   869
schirmer@12854
   870
apply   auto
schirmer@12854
   871
done
schirmer@12854
   872
schirmer@12854
   873
schirmer@12854
   874
subsection "accessibility"
schirmer@12854
   875
schirmer@12854
   876
theorem dynamic_field_access_ok:
schirmer@12854
   877
  (assumes wf: "wf_prog G" and
schirmer@12854
   878
       eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2" and
schirmer@12854
   879
     not_Null: "a\<noteq>Null" and
schirmer@12854
   880
    conform_a: "G,(store s2)\<turnstile>a\<Colon>\<preceq> Class statC" and
schirmer@12854
   881
   conform_s2: "s2\<Colon>\<preceq>(G, L)" and 
schirmer@12854
   882
    normal_s2: "normal s2" and
schirmer@12854
   883
         wt_e: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>,dt\<Turnstile>e\<Colon>-Class statC" and
schirmer@12854
   884
            f: "accfield G accC statC fn = Some f" and
schirmer@12854
   885
         dynC: "if stat then dynC=statC  
schirmer@12854
   886
                        else dynC=obj_class (lookup_obj (store s2) a)"
schirmer@12854
   887
  ) "table_of (DeclConcepts.fields G dynC) (fn,declclass f) = Some (fld f) \<and> 
schirmer@12854
   888
     G\<turnstile>Field fn f in dynC dyn_accessible_from accC"
schirmer@12854
   889
proof (cases "stat")
schirmer@12854
   890
  case True
schirmer@12854
   891
  with dynC 
schirmer@12854
   892
  have dynC': "dynC=statC" by simp
schirmer@12854
   893
  with f
schirmer@12854
   894
  have "table_of (DeclConcepts.fields G dynC) (fn,declclass f) = Some (fld f)"
schirmer@12854
   895
    by (auto simp add: accfield_def Let_def intro!: table_of_remap_SomeD)
schirmer@12854
   896
  with dynC' f
schirmer@12854
   897
  show ?thesis
schirmer@12854
   898
    by (auto intro!: static_to_dynamic_accessible_from
schirmer@12854
   899
         dest: accfield_accessibleD accessible_from_commonD)
schirmer@12854
   900
next
schirmer@12854
   901
  case False
schirmer@12854
   902
  with wf conform_a not_Null conform_s2 dynC
schirmer@12854
   903
  obtain subclseq: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and
schirmer@12854
   904
    "is_class G dynC"
schirmer@12854
   905
    by (auto dest!: conforms_RefTD [of _ _ _ _ "(fst s2)" L]
schirmer@12854
   906
              dest: obj_ty_obj_class1
schirmer@12854
   907
          simp add: obj_ty_obj_class )
schirmer@12854
   908
  with wf f
schirmer@12854
   909
  have "table_of (DeclConcepts.fields G dynC) (fn,declclass f) = Some (fld f)"
schirmer@12854
   910
    by (auto simp add: accfield_def Let_def
schirmer@12854
   911
                 dest: fields_mono
schirmer@12854
   912
                dest!: table_of_remap_SomeD)
schirmer@12854
   913
  moreover
schirmer@12854
   914
  from f subclseq
schirmer@12854
   915
  have "G\<turnstile>Field fn f in dynC dyn_accessible_from accC"
schirmer@12854
   916
    by (auto intro!: static_to_dynamic_accessible_from 
schirmer@12854
   917
               dest: accfield_accessibleD)
schirmer@12854
   918
  ultimately show ?thesis
schirmer@12854
   919
    by blast
schirmer@12854
   920
qed
schirmer@12854
   921
schirmer@12854
   922
lemma call_access_ok: 
schirmer@12854
   923
(assumes invC_prop: "G\<turnstile>invmode (mhd statM) e\<rightarrow>invC\<preceq>statT" 
schirmer@12854
   924
     and        wf: "wf_prog G" 
schirmer@12854
   925
     and      wt_e: "\<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT"
schirmer@12854
   926
     and     statM: "statM \<in> mheads G accC statT sig" 
schirmer@12854
   927
     and      invC: "invC = invocation_class (invmode (mhd statM) e) s a statT"
schirmer@12854
   928
)"\<exists> dynM. dynlookup G statT invC sig = Some dynM \<and>
schirmer@12854
   929
  G\<turnstile>Methd sig dynM in invC dyn_accessible_from accC"
schirmer@12854
   930
proof -
schirmer@12854
   931
  from wt_e wf have type_statT: "is_type G (RefT statT)"
schirmer@12854
   932
    by (auto dest: ty_expr_is_type)
schirmer@12854
   933
  from statM have not_Null: "statT \<noteq> NullT" by auto
schirmer@12854
   934
  from type_statT wt_e 
schirmer@12854
   935
  have wf_I: "(\<forall>I. statT = IfaceT I \<longrightarrow> is_iface G I \<and> 
schirmer@12854
   936
                                        invmode (mhd statM) e \<noteq> SuperM)"
schirmer@12854
   937
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   938
  from wt_e
schirmer@12854
   939
  have wf_A: "(\<forall>     T. statT = ArrayT T \<longrightarrow> invmode (mhd statM) e \<noteq> SuperM)"
schirmer@12854
   940
    by (auto dest: invocationTypeExpr_noClassD)
schirmer@12854
   941
  show ?thesis
schirmer@12854
   942
  proof (cases "invmode (mhd statM) e = IntVir")
schirmer@12854
   943
    case True
schirmer@12854
   944
    with invC_prop not_Null
schirmer@12854
   945
    have invC_prop': "is_class G invC \<and>  
schirmer@12854
   946
                      (if (\<exists>T. statT=ArrayT T) then invC=Object 
schirmer@12854
   947
                                              else G\<turnstile>Class invC\<preceq>RefT statT)"
schirmer@12854
   948
      by (auto simp add: DynT_prop_def)
schirmer@12854
   949
    with True not_Null
schirmer@12854
   950
    have "G,statT \<turnstile> invC valid_lookup_cls_for is_static statM"
schirmer@12854
   951
     by (cases statT) (auto simp add: invmode_def 
schirmer@12854
   952
                         split: split_if split_if_asm) (*  was deleted above *)
schirmer@12854
   953
    with statM type_statT wf 
schirmer@12854
   954
    show ?thesis
schirmer@12854
   955
      by - (rule dynlookup_access,auto)
schirmer@12854
   956
  next
schirmer@12854
   957
    case False
schirmer@12854
   958
    with type_statT wf invC not_Null wf_I wf_A
schirmer@12854
   959
    have invC_prop': " is_class G invC \<and>
schirmer@12854
   960
                      ((\<exists> statC. statT=ClassT statC \<and> invC=statC) \<or>
schirmer@12854
   961
                      (\<forall> statC. statT\<noteq>ClassT statC \<and> invC=Object)) "
schirmer@12854
   962
        by (case_tac "statT") (auto simp add: invocation_class_def 
schirmer@12854
   963
                                       split: inv_mode.splits)
schirmer@12854
   964
    with not_Null wf
schirmer@12854
   965
    have dynlookup_static: "dynlookup G statT invC sig = methd G invC sig"
schirmer@12854
   966
      by (case_tac "statT") (auto simp add: dynlookup_def dynmethd_C_C
schirmer@12854
   967
                                            dynimethd_def)
schirmer@12854
   968
   from statM wf wt_e not_Null False invC_prop' obtain dynM where
schirmer@12854
   969
                "accmethd G accC invC sig = Some dynM" 
schirmer@12854
   970
     by (auto dest!: static_mheadsD)
schirmer@12854
   971
   from invC_prop' False not_Null wf_I
schirmer@12854
   972
   have "G,statT \<turnstile> invC valid_lookup_cls_for is_static statM"
schirmer@12854
   973
     by (cases statT) (auto simp add: invmode_def
schirmer@12854
   974
                        split: split_if split_if_asm) (*  was deleted above *)
schirmer@12854
   975
   with statM type_statT wf 
schirmer@12854
   976
    show ?thesis
schirmer@12854
   977
      by - (rule dynlookup_access,auto)
schirmer@12854
   978
  qed
schirmer@12854
   979
qed
schirmer@12854
   980
schirmer@12854
   981
section "main proof of type safety"
schirmer@12854
   982
schirmer@12854
   983
ML {*
schirmer@12854
   984
val forward_hyp_tac = EVERY' [smp_tac 1,
schirmer@12854
   985
	FIRST'[mp_tac,etac exI,smp_tac 2,smp_tac 1,EVERY'[etac impE,etac exI]],
schirmer@12854
   986
	REPEAT o (etac conjE)];
schirmer@12854
   987
val typD_tac = eresolve_tac (thms "wt_elim_cases") THEN_ALL_NEW 
schirmer@12854
   988
	EVERY' [full_simp_tac (simpset() setloop (K no_tac)), 
schirmer@12854
   989
         clarify_tac(claset() addSEs[])]
schirmer@12854
   990
*}
schirmer@12854
   991
schirmer@12854
   992
lemma conforms_locals [rule_format]: 
schirmer@12854
   993
  "(a,b)\<Colon>\<preceq>(G, L) \<longrightarrow> L x = Some T \<longrightarrow> G,b\<turnstile>the (locals b x)\<Colon>\<preceq>T"
schirmer@12854
   994
apply (force simp: conforms_def Let_def lconf_def)
schirmer@12854
   995
done
schirmer@12854
   996
schirmer@12854
   997
lemma eval_type_sound [rule_format (no_asm)]: 
schirmer@12854
   998
 "wf_prog G \<Longrightarrow> G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1) \<Longrightarrow> (\<forall>L. s0\<Colon>\<preceq>(G,L) \<longrightarrow>    
schirmer@12854
   999
  (\<forall>C T. \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>t\<Colon>T \<longrightarrow> s1\<Colon>\<preceq>(G,L) \<and>  
schirmer@12854
  1000
  (let (x,s) = s1 in x = None \<longrightarrow> G,L,s\<turnstile>t\<succ>v\<Colon>\<preceq>T)))"
schirmer@12854
  1001
apply (erule eval_induct)
schirmer@12854
  1002
schirmer@12854
  1003
(* 29 subgoals *)
schirmer@12854
  1004
(* Xcpt, Inst, Methd, Nil, Skip, Expr, Comp *)
schirmer@12854
  1005
apply         (simp_all (no_asm_use) add: Let_def body_def)
schirmer@12854
  1006
apply       (tactic "ALLGOALS (EVERY'[Clarify_tac, TRY o typD_tac, 
schirmer@12854
  1007
                     TRY o forward_hyp_tac])")
schirmer@12854
  1008
apply      (tactic"ALLGOALS(EVERY'[asm_simp_tac(simpset()),TRY o Clarify_tac])")
schirmer@12854
  1009
schirmer@12854
  1010
(* 20 subgoals *)
schirmer@12854
  1011
schirmer@12854
  1012
(* Break *)
schirmer@12854
  1013
apply (erule conforms_absorb)
schirmer@12854
  1014
schirmer@12854
  1015
(* Cons *)
schirmer@12854
  1016
apply (erule_tac V = "G\<turnstile>Norm s0 \<midarrow>?ea\<succ>\<rightarrow> ?vs1" in thin_rl)
schirmer@12854
  1017
apply (frule eval_gext')
schirmer@12854
  1018
apply force
schirmer@12854
  1019
schirmer@12854
  1020
(* LVar *)
schirmer@12854
  1021
apply (force elim: conforms_localD [THEN lconfD] conforms_lupd 
schirmer@12854
  1022
       simp add: assign_conforms_def lvar_def)
schirmer@12854
  1023
schirmer@12854
  1024
(* Cast *)
schirmer@12854
  1025
apply (force dest: fits_conf)
schirmer@12854
  1026
schirmer@12854
  1027
(* Lit *)
schirmer@12854
  1028
apply (rule conf_litval)
schirmer@12854
  1029
apply (simp add: empty_dt_def)
schirmer@12854
  1030
schirmer@12854
  1031
(* Super *)
schirmer@12854
  1032
apply (rule conf_widen)
schirmer@12854
  1033
apply   (erule (1) subcls_direct [THEN widen.subcls])
schirmer@12854
  1034
apply  (erule (1) conforms_localD [THEN lconfD])
schirmer@12854
  1035
apply (erule wf_ws_prog)
schirmer@12854
  1036
schirmer@12854
  1037
(* Acc *)
schirmer@12854
  1038
apply fast
schirmer@12854
  1039
schirmer@12854
  1040
(* Body *)
schirmer@12854
  1041
apply (rule conjI)
schirmer@12854
  1042
apply (rule conforms_absorb)
schirmer@12854
  1043
apply (fast)
schirmer@12854
  1044
apply (fast intro: conforms_locals)
schirmer@12854
  1045
schirmer@12854
  1046
(* Cond *)
schirmer@12854
  1047
apply (simp split: split_if_asm)
schirmer@12854
  1048
apply  (tactic "forward_hyp_tac 1", force)
schirmer@12854
  1049
apply (tactic "forward_hyp_tac 1", force)
schirmer@12854
  1050
schirmer@12854
  1051
(* If *)
schirmer@12854
  1052
apply (force split add: split_if_asm)
schirmer@12854
  1053
schirmer@12854
  1054
(* Loop *)
schirmer@12854
  1055
apply (drule (1) wt.Loop)
schirmer@12854
  1056
apply (clarsimp split: split_if_asm)
schirmer@12854
  1057
apply (fast intro: conforms_absorb)
schirmer@12854
  1058
schirmer@12854
  1059
(* Fin *)
schirmer@12854
  1060
apply (case_tac "x1", force)
schirmer@12854
  1061
apply (drule spec, erule impE, erule conforms_NormI)
schirmer@12854
  1062
apply (erule impE)
schirmer@12854
  1063
apply   blast
schirmer@12854
  1064
apply (clarsimp)
schirmer@12854
  1065
apply (erule (3) Fin_lemma)
schirmer@12854
  1066
schirmer@12854
  1067
(* Throw *)
schirmer@12854
  1068
apply (erule (3) Throw_lemma)
schirmer@12854
  1069
schirmer@12854
  1070
(* NewC *)
schirmer@12854
  1071
apply (clarsimp simp add: is_acc_class_def)
schirmer@12854
  1072
apply (drule (1) halloc_type_sound,blast, rule HOL.refl, simp, simp)
schirmer@12854
  1073
schirmer@12854
  1074
(* NewA *)
schirmer@12854
  1075
apply (tactic "smp_tac 1 1",frule wt_init_comp_ty,erule impE,blast)
schirmer@12854
  1076
apply (tactic "forward_hyp_tac 1")
schirmer@12854
  1077
apply (case_tac "check_neg i' ab")
schirmer@12854
  1078
apply  (clarsimp simp add: is_acc_type_def)
schirmer@12854
  1079
apply  (drule (2) halloc_type_sound, rule HOL.refl, simp, simp)
schirmer@12854
  1080
apply force
schirmer@12854
  1081
schirmer@12854
  1082
(* Level 34, 6 subgoals *)
schirmer@12854
  1083
schirmer@12854
  1084
(* Init *)
schirmer@12854
  1085
apply (case_tac "inited C (globs s0)")
schirmer@12854
  1086
apply  (clarsimp)
schirmer@12854
  1087
apply (clarsimp)
schirmer@12854
  1088
apply (frule (1) wf_prog_cdecl)
schirmer@12854
  1089
apply (drule spec, erule impE, erule (3) conforms_init_class_obj)
schirmer@12854
  1090
apply (drule_tac "psi" = "class G C = ?x" in asm_rl,erule impE,
schirmer@12854
  1091
      force dest!: wf_cdecl_supD split add: split_if simp add: is_acc_class_def)
schirmer@12854
  1092
apply (drule spec, erule impE, erule conforms_set_locals, rule lconf_empty)
schirmer@12854
  1093
apply (erule impE) apply (rule exI) apply (erule wf_cdecl_wt_init)
schirmer@12854
  1094
apply (drule (1) conforms_return, force dest: eval_gext', assumption)
schirmer@12854
  1095
schirmer@12854
  1096
schirmer@12854
  1097
(* Ass *)
schirmer@12854
  1098
apply (tactic "forward_hyp_tac 1")
schirmer@12854
  1099
apply (rename_tac x1 s1 x2 s2 v va w L C Ta T', case_tac x1)
schirmer@12854
  1100
prefer 2 apply force
schirmer@12854
  1101
apply (case_tac x2)
schirmer@12854
  1102
prefer 2 apply force
schirmer@12854
  1103
apply (simp, drule conjunct2)
schirmer@12854
  1104
apply (drule (1) conf_widen)
schirmer@12854
  1105
apply  (erule wf_ws_prog)
schirmer@12854
  1106
apply (erule (2) Ass_lemma)
schirmer@12854
  1107
apply (clarsimp simp add: assign_conforms_def)
schirmer@12854
  1108
schirmer@12854
  1109
(* Try *)
schirmer@12854
  1110
apply (drule (1) sxalloc_type_sound, simp (no_asm_use))
schirmer@12854
  1111
apply (case_tac a)
schirmer@12854
  1112
apply  clarsimp
schirmer@12854
  1113
apply clarsimp
schirmer@12854
  1114
apply (tactic "smp_tac 1 1")
schirmer@12854
  1115
apply (simp split add: split_if_asm)
schirmer@12854
  1116
apply (fast dest: conforms_deallocL Try_lemma)
schirmer@12854
  1117
schirmer@12854
  1118
(* FVar *)
schirmer@12854
  1119
schirmer@12854
  1120
apply (frule accfield_fields)
schirmer@12854
  1121
apply (frule ty_expr_is_type [THEN type_is_class],simp)
schirmer@12854
  1122
apply simp
schirmer@12854
  1123
apply (frule wf_ws_prog)
schirmer@12854
  1124
apply (frule (1) fields_declC,simp)
schirmer@12854
  1125
apply clarsimp 
schirmer@12854
  1126
(*b y EVERY'[datac cfield_defpl_is_class 2, Clarsimp_tac] 1; not useful here*)
schirmer@12854
  1127
apply (tactic "smp_tac 1 1")
schirmer@12854
  1128
apply (tactic "forward_hyp_tac 1")
schirmer@12854
  1129
apply (rule conjI, force split add: split_if simp add: fvar_def2)
schirmer@12854
  1130
apply (drule init_yields_initd, frule eval_gext')
schirmer@12854
  1131
apply clarsimp
schirmer@12854
  1132
apply (case_tac "C=Object")
schirmer@12854
  1133
apply  clarsimp
schirmer@12854
  1134
apply (erule (9) FVar_lemma)
schirmer@12854
  1135
schirmer@12854
  1136
(* AVar *)
schirmer@12854
  1137
apply (tactic "forward_hyp_tac 1")
schirmer@12854
  1138
apply (erule_tac V = "G\<turnstile>Norm s0 \<midarrow>?e1-\<succ>?a'\<rightarrow> (?x1 1, ?s1)" in thin_rl, 
schirmer@12854
  1139
         frule eval_gext')
schirmer@12854
  1140
apply (rule conjI)
schirmer@12854
  1141
apply  (clarsimp simp add: avar_def2)
schirmer@12854
  1142
apply clarsimp
schirmer@12854
  1143
apply (erule (5) AVar_lemma)
schirmer@12854
  1144
schirmer@12854
  1145
(* Call *)
schirmer@12854
  1146
apply (tactic "forward_hyp_tac 1")
schirmer@12854
  1147
apply (rule Call_type_sound)
schirmer@12854
  1148
apply auto
schirmer@12854
  1149
done
schirmer@12854
  1150
schirmer@12854
  1151
schirmer@12854
  1152
declare fun_upd_apply [simp]
schirmer@12854
  1153
declare split_paired_All [simp] split_paired_Ex [simp]
schirmer@12854
  1154
declare split_if     [split] split_if_asm     [split] 
schirmer@12854
  1155
        option.split [split] option.split_asm [split]
schirmer@12854
  1156
ML_setup {* 
schirmer@12854
  1157
simpset_ref() := simpset() addloop ("split_all_tac", split_all_tac);
schirmer@12854
  1158
claset_ref()  := claset () addSbefore ("split_all_tac", split_all_tac)
schirmer@12854
  1159
*}
schirmer@12854
  1160
schirmer@12854
  1161
theorem eval_ts: 
schirmer@12854
  1162
 "\<lbrakk>G\<turnstile>s \<midarrow>e-\<succ>v \<rightarrow> (x',s'); wf_prog G; s\<Colon>\<preceq>(G,L); \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>e\<Colon>-T\<rbrakk> 
schirmer@12854
  1163
\<Longrightarrow>  (x',s')\<Colon>\<preceq>(G,L) \<and> (x'=None \<longrightarrow> G,s'\<turnstile>v\<Colon>\<preceq>T)"
schirmer@12854
  1164
apply (drule (3) eval_type_sound)
schirmer@12854
  1165
apply (unfold Let_def)
schirmer@12854
  1166
apply clarsimp
schirmer@12854
  1167
done
schirmer@12854
  1168
schirmer@12854
  1169
theorem evals_ts: 
schirmer@12854
  1170
"\<lbrakk>G\<turnstile>s \<midarrow>es\<doteq>\<succ>vs\<rightarrow> (x',s'); wf_prog G; s\<Colon>\<preceq>(G,L); \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>es\<Colon>\<doteq>Ts\<rbrakk> 
schirmer@12854
  1171
\<Longrightarrow>  (x',s')\<Colon>\<preceq>(G,L) \<and> (x'=None \<longrightarrow> list_all2 (conf G s') vs Ts)"
schirmer@12854
  1172
apply (drule (3) eval_type_sound)
schirmer@12854
  1173
apply (unfold Let_def)
schirmer@12854
  1174
apply clarsimp
schirmer@12854
  1175
done
schirmer@12854
  1176
schirmer@12854
  1177
theorem evar_ts: 
schirmer@12854
  1178
"\<lbrakk>G\<turnstile>s \<midarrow>v=\<succ>vf\<rightarrow> (x',s'); wf_prog G; s\<Colon>\<preceq>(G,L); \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>v\<Colon>=T\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1179
  (x',s')\<Colon>\<preceq>(G,L) \<and> (x'=None \<longrightarrow> G,L,s'\<turnstile>In2 v\<succ>In2 vf\<Colon>\<preceq>Inl T)"
schirmer@12854
  1180
apply (drule (3) eval_type_sound)
schirmer@12854
  1181
apply (unfold Let_def)
schirmer@12854
  1182
apply clarsimp
schirmer@12854
  1183
done
schirmer@12854
  1184
schirmer@12854
  1185
theorem exec_ts: 
schirmer@12854
  1186
"\<lbrakk>G\<turnstile>s \<midarrow>s0\<rightarrow> s'; wf_prog G; s\<Colon>\<preceq>(G,L); \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>s0\<Colon>\<surd>\<rbrakk> \<Longrightarrow> s'\<Colon>\<preceq>(G,L)"
schirmer@12854
  1187
apply (drule (3) eval_type_sound)
schirmer@12854
  1188
apply (unfold Let_def)
schirmer@12854
  1189
apply clarsimp
schirmer@12854
  1190
done
schirmer@12854
  1191
schirmer@12854
  1192
(*
schirmer@12854
  1193
theorem dyn_methods_understood: 
schirmer@12854
  1194
 "\<And>s. \<lbrakk>wf_prog G; \<lparr>prg=G,cls=C,lcl=L\<rparr>\<turnstile>{t,md,IntVir}e..mn({pTs'}ps)\<Colon>-rT;  
schirmer@12854
  1195
  s\<Colon>\<preceq>(G,L); G\<turnstile>s \<midarrow>e-\<succ>a'\<rightarrow> Norm s'; a' \<noteq> Null\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1196
  \<exists>a obj. a'=Addr a \<and> heap s' a = Some obj \<and> 
schirmer@12854
  1197
  cmethd G (obj_class obj) (mn, pTs') \<noteq> None"
schirmer@12854
  1198
apply (erule wt_elim_cases)
schirmer@12854
  1199
apply (drule max_spec2mheads)
schirmer@12854
  1200
apply (drule (3) eval_ts)
schirmer@12854
  1201
apply (clarsimp split del: split_if split_if_asm)
schirmer@12854
  1202
apply (drule (2) DynT_propI)
schirmer@12854
  1203
apply  (simp (no_asm_simp))
schirmer@12854
  1204
apply (tactic *) (* {* exhaust_cmethd_tac "the (cmethd G (target (invmode m e) s' a' md) (mn, pTs'))" 1 *} *)(*)
schirmer@12854
  1205
apply (drule (4) DynT_mheadsD [THEN conjunct1], rule HOL.refl)
schirmer@12854
  1206
apply (drule conf_RefTD)
schirmer@12854
  1207
apply clarsimp
schirmer@12854
  1208
done 
schirmer@12854
  1209
*)
schirmer@12854
  1210
schirmer@12854
  1211
end