src/HOL/Bali/Evaln.thy
author wenzelm
Mon Feb 25 20:48:14 2002 +0100 (2002-02-25)
changeset 12937 0c4fd7529467
parent 12925 99131847fb93
child 13337 f75dfc606ac7
permissions -rw-r--r--
clarified syntax of ``long'' statements: fixes/assumes/shows;
wenzelm@12857
     1
(*  Title:      HOL/Bali/Evaln.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12925
     3
    Author:     David von Oheimb and Norbert Schirmer
wenzelm@12859
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
schirmer@12854
     5
*)
schirmer@12854
     6
header {* Operational evaluation (big-step) semantics of Java expressions and 
schirmer@12854
     7
          statements
schirmer@12854
     8
*}
schirmer@12854
     9
schirmer@12925
    10
theory Evaln = Eval + TypeSafe:
schirmer@12854
    11
schirmer@12854
    12
text {*
schirmer@12925
    13
Variant of eval relation with counter for bounded recursive depth.
schirmer@12925
    14
Evaln omits the technical accessibility tests @{term check_field_access}
schirmer@12925
    15
and @{term check_method_access}, since we proved the absence of errors for
schirmer@12925
    16
wellformed programs.
schirmer@12854
    17
*}
schirmer@12854
    18
schirmer@12854
    19
consts
schirmer@12854
    20
schirmer@12854
    21
  evaln	:: "prog \<Rightarrow> (state \<times> term \<times> nat \<times> vals \<times> state) set"
schirmer@12854
    22
schirmer@12854
    23
syntax
schirmer@12854
    24
schirmer@12854
    25
  evaln	:: "[prog, state, term,        nat, vals * state] => bool"
schirmer@12854
    26
				("_|-_ -_>-_-> _"   [61,61,80,   61,61] 60)
schirmer@12854
    27
  evarn	:: "[prog, state, var  , vvar        , nat, state] => bool"
schirmer@12854
    28
				("_|-_ -_=>_-_-> _" [61,61,90,61,61,61] 60)
schirmer@12854
    29
  eval_n:: "[prog, state, expr , val         , nat, state] => bool"
schirmer@12854
    30
				("_|-_ -_->_-_-> _" [61,61,80,61,61,61] 60)
schirmer@12854
    31
  evalsn:: "[prog, state, expr list, val list, nat, state] => bool"
schirmer@12854
    32
				("_|-_ -_#>_-_-> _" [61,61,61,61,61,61] 60)
schirmer@12854
    33
  execn	:: "[prog, state, stmt ,               nat, state] => bool"
schirmer@12854
    34
				("_|-_ -_-_-> _"    [61,61,65,   61,61] 60)
schirmer@12854
    35
schirmer@12854
    36
syntax (xsymbols)
schirmer@12854
    37
schirmer@12854
    38
  evaln	:: "[prog, state, term,         nat, vals \<times> state] \<Rightarrow> bool"
schirmer@12854
    39
				("_\<turnstile>_ \<midarrow>_\<succ>\<midarrow>_\<rightarrow> _"   [61,61,80,   61,61] 60)
schirmer@12854
    40
  evarn	:: "[prog, state, var  , vvar         , nat, state] \<Rightarrow> bool"
schirmer@12854
    41
				("_\<turnstile>_ \<midarrow>_=\<succ>_\<midarrow>_\<rightarrow> _" [61,61,90,61,61,61] 60)
schirmer@12854
    42
  eval_n:: "[prog, state, expr , val ,          nat, state] \<Rightarrow> bool"
schirmer@12854
    43
				("_\<turnstile>_ \<midarrow>_-\<succ>_\<midarrow>_\<rightarrow> _" [61,61,80,61,61,61] 60)
schirmer@12854
    44
  evalsn:: "[prog, state, expr list, val  list, nat, state] \<Rightarrow> bool"
schirmer@12854
    45
				("_\<turnstile>_ \<midarrow>_\<doteq>\<succ>_\<midarrow>_\<rightarrow> _" [61,61,61,61,61,61] 60)
schirmer@12854
    46
  execn	:: "[prog, state, stmt ,                nat, state] \<Rightarrow> bool"
schirmer@12854
    47
				("_\<turnstile>_ \<midarrow>_\<midarrow>_\<rightarrow> _"     [61,61,65,   61,61] 60)
schirmer@12854
    48
schirmer@12854
    49
translations
schirmer@12854
    50
schirmer@12854
    51
  "G\<turnstile>s \<midarrow>t    \<succ>\<midarrow>n\<rightarrow>  w___s' " == "(s,t,n,w___s') \<in> evaln G"
schirmer@12854
    52
  "G\<turnstile>s \<midarrow>t    \<succ>\<midarrow>n\<rightarrow> (w,  s')" <= "(s,t,n,w,  s') \<in> evaln G"
schirmer@12854
    53
  "G\<turnstile>s \<midarrow>t    \<succ>\<midarrow>n\<rightarrow> (w,x,s')" <= "(s,t,n,w,x,s') \<in> evaln G"
schirmer@12854
    54
  "G\<turnstile>s \<midarrow>c     \<midarrow>n\<rightarrow> (x,s')" <= "G\<turnstile>s \<midarrow>In1r  c\<succ>\<midarrow>n\<rightarrow> (\<diamondsuit>    ,x,s')"
schirmer@12854
    55
  "G\<turnstile>s \<midarrow>c     \<midarrow>n\<rightarrow>    s' " == "G\<turnstile>s \<midarrow>In1r  c\<succ>\<midarrow>n\<rightarrow> (\<diamondsuit>    ,  s')"
schirmer@12854
    56
  "G\<turnstile>s \<midarrow>e-\<succ>v  \<midarrow>n\<rightarrow> (x,s')" <= "G\<turnstile>s \<midarrow>In1l e\<succ>\<midarrow>n\<rightarrow> (In1 v ,x,s')"
schirmer@12854
    57
  "G\<turnstile>s \<midarrow>e-\<succ>v  \<midarrow>n\<rightarrow>    s' " == "G\<turnstile>s \<midarrow>In1l e\<succ>\<midarrow>n\<rightarrow> (In1 v ,  s')"
schirmer@12854
    58
  "G\<turnstile>s \<midarrow>e=\<succ>vf \<midarrow>n\<rightarrow> (x,s')" <= "G\<turnstile>s \<midarrow>In2  e\<succ>\<midarrow>n\<rightarrow> (In2 vf,x,s')"
schirmer@12854
    59
  "G\<turnstile>s \<midarrow>e=\<succ>vf \<midarrow>n\<rightarrow>    s' " == "G\<turnstile>s \<midarrow>In2  e\<succ>\<midarrow>n\<rightarrow> (In2 vf,  s')"
schirmer@12854
    60
  "G\<turnstile>s \<midarrow>e\<doteq>\<succ>v  \<midarrow>n\<rightarrow> (x,s')" <= "G\<turnstile>s \<midarrow>In3  e\<succ>\<midarrow>n\<rightarrow> (In3 v ,x,s')"
schirmer@12854
    61
  "G\<turnstile>s \<midarrow>e\<doteq>\<succ>v  \<midarrow>n\<rightarrow>    s' " == "G\<turnstile>s \<midarrow>In3  e\<succ>\<midarrow>n\<rightarrow> (In3 v ,  s')"
schirmer@12854
    62
schirmer@12854
    63
schirmer@12854
    64
inductive "evaln G" intros
schirmer@12854
    65
schirmer@12854
    66
(* propagation of abrupt completion *)
schirmer@12854
    67
schirmer@12854
    68
  Abrupt:   "G\<turnstile>(Some xc,s) \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (arbitrary3 t,(Some xc,s))"
schirmer@12854
    69
schirmer@12854
    70
schirmer@12854
    71
(* evaluation of variables *)
schirmer@12854
    72
schirmer@12854
    73
  LVar:	"G\<turnstile>Norm s \<midarrow>LVar vn=\<succ>lvar vn s\<midarrow>n\<rightarrow> Norm s"
schirmer@12854
    74
schirmer@12925
    75
  FVar:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e-\<succ>a'\<midarrow>n\<rightarrow> s2;
schirmer@12925
    76
	  (v,s2') = fvar statDeclC stat fn a' s2\<rbrakk> \<Longrightarrow>
schirmer@12925
    77
	  G\<turnstile>Norm s0 \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>v\<midarrow>n\<rightarrow> s2'"
schirmer@12854
    78
schirmer@12854
    79
  AVar:	"\<lbrakk>G\<turnstile> Norm s0 \<midarrow>e1-\<succ>a\<midarrow>n\<rightarrow> s1 ; G\<turnstile>s1 \<midarrow>e2-\<succ>i\<midarrow>n\<rightarrow> s2; 
schirmer@12854
    80
	  (v,s2') = avar G i a s2\<rbrakk> \<Longrightarrow>
schirmer@12854
    81
	              G\<turnstile>Norm s0 \<midarrow>e1.[e2]=\<succ>v\<midarrow>n\<rightarrow> s2'"
schirmer@12854
    82
schirmer@12854
    83
schirmer@12854
    84
schirmer@12854
    85
schirmer@12854
    86
(* evaluation of expressions *)
schirmer@12854
    87
schirmer@12854
    88
  NewC:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>Init C\<midarrow>n\<rightarrow> s1;
schirmer@12854
    89
	  G\<turnstile>     s1 \<midarrow>halloc (CInst C)\<succ>a\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
    90
	                          G\<turnstile>Norm s0 \<midarrow>NewC C-\<succ>Addr a\<midarrow>n\<rightarrow> s2"
schirmer@12854
    91
schirmer@12854
    92
  NewA:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>init_comp_ty T\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>e-\<succ>i'\<midarrow>n\<rightarrow> s2; 
schirmer@12854
    93
	  G\<turnstile>abupd (check_neg i') s2 \<midarrow>halloc (Arr T (the_Intg i'))\<succ>a\<rightarrow> s3\<rbrakk> \<Longrightarrow>
schirmer@12854
    94
	                        G\<turnstile>Norm s0 \<midarrow>New T[e]-\<succ>Addr a\<midarrow>n\<rightarrow> s3"
schirmer@12854
    95
schirmer@12854
    96
  Cast:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1;
schirmer@12854
    97
	  s2 = abupd (raise_if (\<not>G,snd s1\<turnstile>v fits T) ClassCast) s1\<rbrakk> \<Longrightarrow>
schirmer@12854
    98
			        G\<turnstile>Norm s0 \<midarrow>Cast T e-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@12854
    99
schirmer@12854
   100
  Inst:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1;
schirmer@12854
   101
	  b = (v\<noteq>Null \<and> G,store s1\<turnstile>v fits RefT T)\<rbrakk> \<Longrightarrow>
schirmer@12854
   102
			      G\<turnstile>Norm s0 \<midarrow>e InstOf T-\<succ>Bool b\<midarrow>n\<rightarrow> s1"
schirmer@12854
   103
schirmer@12854
   104
  Lit:			   "G\<turnstile>Norm s \<midarrow>Lit v-\<succ>v\<midarrow>n\<rightarrow> Norm s"
schirmer@12854
   105
schirmer@12854
   106
  Super:		   "G\<turnstile>Norm s \<midarrow>Super-\<succ>val_this s\<midarrow>n\<rightarrow> Norm s"
schirmer@12854
   107
schirmer@12854
   108
  Acc:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(v,f)\<midarrow>n\<rightarrow> s1\<rbrakk> \<Longrightarrow>
schirmer@12854
   109
	                          G\<turnstile>Norm s0 \<midarrow>Acc va-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@12854
   110
schirmer@12854
   111
  Ass:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>va=\<succ>(w,f)\<midarrow>n\<rightarrow> s1;
schirmer@12854
   112
          G\<turnstile>     s1 \<midarrow>e-\<succ>v     \<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
   113
				   G\<turnstile>Norm s0 \<midarrow>va:=e-\<succ>v\<midarrow>n\<rightarrow> assign f v s2"
schirmer@12854
   114
schirmer@12854
   115
  Cond:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e0-\<succ>b\<midarrow>n\<rightarrow> s1;
schirmer@12854
   116
          G\<turnstile>     s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
   117
			    G\<turnstile>Norm s0 \<midarrow>e0 ? e1 : e2-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@12854
   118
schirmer@12854
   119
  Call:	
schirmer@12854
   120
  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<midarrow>n\<rightarrow> s2;
schirmer@12854
   121
    D = invocation_declclass G mode (store s2) a' statT \<lparr>name=mn,parTs=pTs\<rparr>; 
schirmer@12854
   122
    G\<turnstile>init_lvars G D \<lparr>name=mn,parTs=pTs\<rparr> mode a' vs s2
schirmer@12854
   123
            \<midarrow>Methd D \<lparr>name=mn,parTs=pTs\<rparr>-\<succ>v\<midarrow>n\<rightarrow> s3\<rbrakk>
schirmer@12925
   124
   \<Longrightarrow> 
schirmer@12925
   125
    G\<turnstile>Norm s0 \<midarrow>{accC,statT,mode}e\<cdot>mn({pTs}args)-\<succ>v\<midarrow>n\<rightarrow> (restore_lvars s2 s3)"
schirmer@12854
   126
schirmer@12854
   127
  Methd:"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>body G D sig-\<succ>v\<midarrow>n\<rightarrow> s1\<rbrakk> \<Longrightarrow>
schirmer@12854
   128
				G\<turnstile>Norm s0 \<midarrow>Methd D sig-\<succ>v\<midarrow>Suc n\<rightarrow> s1"
schirmer@12854
   129
schirmer@12854
   130
  Body:	"\<lbrakk>G\<turnstile>Norm s0\<midarrow>Init D\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>c\<midarrow>n\<rightarrow> s2\<rbrakk>\<Longrightarrow>
schirmer@12854
   131
 G\<turnstile>Norm s0 \<midarrow>Body D c-\<succ>the (locals (store s2) Result)\<midarrow>n\<rightarrow>abupd (absorb Ret) s2"
schirmer@12854
   132
schirmer@12854
   133
(* evaluation of expression lists *)
schirmer@12854
   134
schirmer@12854
   135
  Nil:
schirmer@12854
   136
				"G\<turnstile>Norm s0 \<midarrow>[]\<doteq>\<succ>[]\<midarrow>n\<rightarrow> Norm s0"
schirmer@12854
   137
schirmer@12854
   138
  Cons:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e -\<succ> v \<midarrow>n\<rightarrow> s1;
schirmer@12854
   139
          G\<turnstile>     s1 \<midarrow>es\<doteq>\<succ>vs\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
   140
			     G\<turnstile>Norm s0 \<midarrow>e#es\<doteq>\<succ>v#vs\<midarrow>n\<rightarrow> s2"
schirmer@12854
   141
schirmer@12854
   142
schirmer@12854
   143
(* execution of statements *)
schirmer@12854
   144
schirmer@12854
   145
  Skip:	 			    "G\<turnstile>Norm s \<midarrow>Skip\<midarrow>n\<rightarrow> Norm s"
schirmer@12854
   146
schirmer@12854
   147
  Expr:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1\<rbrakk> \<Longrightarrow>
schirmer@12854
   148
				  G\<turnstile>Norm s0 \<midarrow>Expr e\<midarrow>n\<rightarrow> s1"
schirmer@12854
   149
schirmer@12854
   150
  Lab:  "\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c \<midarrow>n\<rightarrow> s1\<rbrakk> \<Longrightarrow>
schirmer@12854
   151
                             G\<turnstile>Norm s0 \<midarrow>l\<bullet> c\<midarrow>n\<rightarrow> abupd (absorb (Break l)) s1"
schirmer@12854
   152
schirmer@12854
   153
  Comp:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1 \<midarrow>n\<rightarrow> s1;
schirmer@12854
   154
	  G\<turnstile>     s1 \<midarrow>c2 \<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
   155
				 G\<turnstile>Norm s0 \<midarrow>c1;; c2\<midarrow>n\<rightarrow> s2"
schirmer@12854
   156
schirmer@12854
   157
  If:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<midarrow>n\<rightarrow> s1;
schirmer@12854
   158
	  G\<turnstile>     s1\<midarrow>(if the_Bool b then c1 else c2)\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
   159
		       G\<turnstile>Norm s0 \<midarrow>If(e) c1 Else c2 \<midarrow>n\<rightarrow> s2"
schirmer@12854
   160
schirmer@12854
   161
  Loop:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<midarrow>n\<rightarrow> s1;
schirmer@12854
   162
	  if normal s1 \<and> the_Bool b 
schirmer@12854
   163
             then (G\<turnstile>s1 \<midarrow>c\<midarrow>n\<rightarrow> s2 \<and> 
schirmer@12854
   164
                   G\<turnstile>(abupd (absorb (Cont l)) s2) \<midarrow>l\<bullet> While(e) c\<midarrow>n\<rightarrow> s3)
schirmer@12854
   165
	     else s3 = s1\<rbrakk> \<Longrightarrow>
schirmer@12854
   166
			      G\<turnstile>Norm s0 \<midarrow>l\<bullet> While(e) c\<midarrow>n\<rightarrow> s3"
schirmer@12854
   167
  
schirmer@12854
   168
  Do: "G\<turnstile>Norm s \<midarrow>Do j\<midarrow>n\<rightarrow> (Some (Jump j), s)"
schirmer@12854
   169
  
schirmer@12854
   170
  Throw:"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<midarrow>n\<rightarrow> s1\<rbrakk> \<Longrightarrow>
schirmer@12854
   171
				 G\<turnstile>Norm s0 \<midarrow>Throw e\<midarrow>n\<rightarrow> abupd (throw a') s1"
schirmer@12854
   172
schirmer@12854
   173
  Try:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2;
schirmer@12854
   174
	  if G,s2\<turnstile>catch tn then G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<midarrow>n\<rightarrow> s3 else s3 = s2\<rbrakk>
schirmer@12854
   175
          \<Longrightarrow>
schirmer@12854
   176
		  G\<turnstile>Norm s0 \<midarrow>Try c1 Catch(tn vn) c2\<midarrow>n\<rightarrow> s3"
schirmer@12854
   177
schirmer@12854
   178
  Fin:	"\<lbrakk>G\<turnstile>Norm s0 \<midarrow>c1\<midarrow>n\<rightarrow> (x1,s1);
schirmer@12854
   179
	  G\<turnstile>Norm s1 \<midarrow>c2\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow>
schirmer@12854
   180
              G\<turnstile>Norm s0 \<midarrow>c1 Finally c2\<midarrow>n\<rightarrow> abupd (abrupt_if (x1\<noteq>None) x1) s2"
schirmer@12854
   181
  
schirmer@12854
   182
  Init:	"\<lbrakk>the (class G C) = c;
schirmer@12854
   183
	  if inited C (globs s0) then s3 = Norm s0
schirmer@12854
   184
	  else (G\<turnstile>Norm (init_class_obj G C s0)
schirmer@12854
   185
	          \<midarrow>(if C = Object then Skip else Init (super c))\<midarrow>n\<rightarrow> s1 \<and>
schirmer@12854
   186
	        G\<turnstile>set_lvars empty s1 \<midarrow>init c\<midarrow>n\<rightarrow> s2 \<and> 
schirmer@12854
   187
                s3 = restore_lvars s1 s2)\<rbrakk>
schirmer@12854
   188
          \<Longrightarrow>
schirmer@12854
   189
		 G\<turnstile>Norm s0 \<midarrow>Init C\<midarrow>n\<rightarrow> s3"
schirmer@12854
   190
monos
schirmer@12854
   191
  if_def2
schirmer@12854
   192
schirmer@12854
   193
schirmer@12854
   194
declare split_if     [split del] split_if_asm     [split del]
schirmer@12854
   195
        option.split [split del] option.split_asm [split del]
schirmer@12854
   196
inductive_cases evaln_cases: "G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   197
schirmer@12854
   198
inductive_cases evaln_elim_cases:
schirmer@12854
   199
	"G\<turnstile>(Some xc, s) \<midarrow>t                        \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   200
	"G\<turnstile>Norm s \<midarrow>In1r Skip                      \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   201
        "G\<turnstile>Norm s \<midarrow>In1r (Do j)                    \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   202
        "G\<turnstile>Norm s \<midarrow>In1r (l\<bullet> c)                    \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   203
	"G\<turnstile>Norm s \<midarrow>In3  ([])                      \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   204
	"G\<turnstile>Norm s \<midarrow>In3  (e#es)                    \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   205
	"G\<turnstile>Norm s \<midarrow>In1l (Lit w)                   \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   206
	"G\<turnstile>Norm s \<midarrow>In2  (LVar vn)                 \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   207
	"G\<turnstile>Norm s \<midarrow>In1l (Cast T e)                \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   208
	"G\<turnstile>Norm s \<midarrow>In1l (e InstOf T)              \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   209
	"G\<turnstile>Norm s \<midarrow>In1l (Super)                   \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   210
	"G\<turnstile>Norm s \<midarrow>In1l (Acc va)                  \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   211
	"G\<turnstile>Norm s \<midarrow>In1r (Expr e)                  \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   212
	"G\<turnstile>Norm s \<midarrow>In1r (c1;; c2)                 \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   213
	"G\<turnstile>Norm s \<midarrow>In1l (Methd C sig)             \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   214
	"G\<turnstile>Norm s \<midarrow>In1l (Body D c)                \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   215
	"G\<turnstile>Norm s \<midarrow>In1l (e0 ? e1 : e2)            \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   216
	"G\<turnstile>Norm s \<midarrow>In1r (If(e) c1 Else c2)        \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   217
	"G\<turnstile>Norm s \<midarrow>In1r (l\<bullet> While(e) c)           \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   218
	"G\<turnstile>Norm s \<midarrow>In1r (c1 Finally c2)           \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   219
	"G\<turnstile>Norm s \<midarrow>In1r (Throw e)                 \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   220
	"G\<turnstile>Norm s \<midarrow>In1l (NewC C)                  \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   221
	"G\<turnstile>Norm s \<midarrow>In1l (New T[e])                \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   222
	"G\<turnstile>Norm s \<midarrow>In1l (Ass va e)                \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   223
	"G\<turnstile>Norm s \<midarrow>In1r (Try c1 Catch(tn vn) c2)  \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12925
   224
	"G\<turnstile>Norm s \<midarrow>In2  ({accC,statDeclC,stat}e..fn) \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   225
	"G\<turnstile>Norm s \<midarrow>In2  (e1.[e2])                 \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12925
   226
	"G\<turnstile>Norm s \<midarrow>In1l ({accC,statT,mode}e\<cdot>mn({pT}p)) \<succ>\<midarrow>n\<rightarrow> vs'"
schirmer@12854
   227
	"G\<turnstile>Norm s \<midarrow>In1r (Init C)                  \<succ>\<midarrow>n\<rightarrow> xs'"
schirmer@12854
   228
declare split_if     [split] split_if_asm     [split] 
schirmer@12854
   229
        option.split [split] option.split_asm [split]
schirmer@12854
   230
schirmer@12854
   231
lemma evaln_Inj_elim: "G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (w,s') \<Longrightarrow> case t of In1 ec \<Rightarrow>  
schirmer@12854
   232
  (case ec of Inl e \<Rightarrow> (\<exists>v. w = In1 v) | Inr c \<Rightarrow> w = \<diamondsuit>)  
schirmer@12854
   233
  | In2 e \<Rightarrow> (\<exists>v. w = In2 v) | In3 e \<Rightarrow> (\<exists>v. w = In3 v)"
schirmer@12854
   234
apply (erule evaln_cases , auto)
schirmer@12854
   235
apply (induct_tac "t")
schirmer@12854
   236
apply   (induct_tac "a")
schirmer@12854
   237
apply auto
schirmer@12854
   238
done
schirmer@12854
   239
schirmer@12854
   240
ML_setup {*
schirmer@12854
   241
fun enf nam inj rhs =
schirmer@12854
   242
let
schirmer@12854
   243
  val name = "evaln_" ^ nam ^ "_eq"
schirmer@12854
   244
  val lhs = "G\<turnstile>s \<midarrow>" ^ inj ^ " t\<succ>\<midarrow>n\<rightarrow> (w, s')"
schirmer@12854
   245
  val () = qed_goal name (the_context()) (lhs ^ " = (" ^ rhs ^ ")") 
schirmer@12854
   246
	(K [Auto_tac, ALLGOALS (ftac (thm "evaln_Inj_elim")) THEN Auto_tac])
schirmer@12854
   247
  fun is_Inj (Const (inj,_) $ _) = true
schirmer@12854
   248
    | is_Inj _                   = false
schirmer@12854
   249
  fun pred (_ $ (Const ("Pair",_) $ _ $ (Const ("Pair", _) $ _ $ 
schirmer@12854
   250
    (Const ("Pair", _) $ _ $ (Const ("Pair", _) $ x $ _ )))) $ _ ) = is_Inj x
schirmer@12854
   251
in
schirmer@12854
   252
  make_simproc name lhs pred (thm name)
schirmer@12854
   253
end;
schirmer@12854
   254
schirmer@12854
   255
val evaln_expr_proc = enf "expr" "In1l" "\<exists>v.  w=In1 v  \<and> G\<turnstile>s \<midarrow>t-\<succ>v \<midarrow>n\<rightarrow> s'";
schirmer@12854
   256
val evaln_var_proc  = enf "var"  "In2"  "\<exists>vf. w=In2 vf \<and> G\<turnstile>s \<midarrow>t=\<succ>vf\<midarrow>n\<rightarrow> s'";
schirmer@12854
   257
val evaln_exprs_proc= enf "exprs""In3"  "\<exists>vs. w=In3 vs \<and> G\<turnstile>s \<midarrow>t\<doteq>\<succ>vs\<midarrow>n\<rightarrow> s'";
schirmer@12854
   258
val evaln_stmt_proc = enf "stmt" "In1r" "     w=\<diamondsuit>      \<and> G\<turnstile>s \<midarrow>t     \<midarrow>n\<rightarrow> s'";
schirmer@12854
   259
Addsimprocs [evaln_expr_proc,evaln_var_proc,evaln_exprs_proc,evaln_stmt_proc];
schirmer@12854
   260
schirmer@12854
   261
bind_thms ("evaln_AbruptIs", sum3_instantiate (thm "evaln.Abrupt"))
schirmer@12854
   262
*}
schirmer@12854
   263
declare evaln_AbruptIs [intro!]
schirmer@12854
   264
schirmer@12854
   265
lemma evaln_abrupt_lemma: "G\<turnstile>s \<midarrow>e\<succ>\<midarrow>n\<rightarrow> (v,s') \<Longrightarrow> 
schirmer@12854
   266
 fst s = Some xc \<longrightarrow> s' = s \<and> v = arbitrary3 e"
schirmer@12854
   267
apply (erule evaln_cases , auto)
schirmer@12854
   268
done
schirmer@12854
   269
schirmer@12854
   270
lemma evaln_abrupt: 
schirmer@12854
   271
 "\<And>s'. G\<turnstile>(Some xc,s) \<midarrow>e\<succ>\<midarrow>n\<rightarrow> (w,s') = (s' = (Some xc,s) \<and>  
schirmer@12854
   272
  w=arbitrary3 e \<and> G\<turnstile>(Some xc,s) \<midarrow>e\<succ>\<midarrow>n\<rightarrow> (arbitrary3 e,(Some xc,s)))"
schirmer@12854
   273
apply auto
schirmer@12854
   274
apply (frule evaln_abrupt_lemma, auto)+
schirmer@12854
   275
done
schirmer@12854
   276
schirmer@12854
   277
ML {*
schirmer@12854
   278
local
wenzelm@12919
   279
  fun is_Some (Const ("Pair",_) $ (Const ("Datatype.option.Some",_) $ _)$ _) =true
schirmer@12854
   280
    | is_Some _ = false
schirmer@12854
   281
  fun pred (_ $ (Const ("Pair",_) $
schirmer@12854
   282
     _ $ (Const ("Pair", _) $ _ $ (Const ("Pair", _) $ _ $
schirmer@12854
   283
       (Const ("Pair", _) $ _ $ x)))) $ _ ) = is_Some x
schirmer@12854
   284
in
schirmer@12854
   285
  val evaln_abrupt_proc = 
schirmer@12854
   286
 make_simproc "evaln_abrupt" "G\<turnstile>(Some xc,s) \<midarrow>e\<succ>\<midarrow>n\<rightarrow> (w,s')" pred (thm "evaln_abrupt")
schirmer@12854
   287
end;
schirmer@12854
   288
Addsimprocs [evaln_abrupt_proc]
schirmer@12854
   289
*}
schirmer@12854
   290
schirmer@12854
   291
lemma evaln_LitI: "G\<turnstile>s \<midarrow>Lit v-\<succ>(if normal s then v else arbitrary)\<midarrow>n\<rightarrow> s"
schirmer@12854
   292
apply (case_tac "s", case_tac "a = None")
schirmer@12854
   293
by (auto intro!: evaln.Lit)
schirmer@12854
   294
schirmer@12854
   295
lemma CondI: 
schirmer@12854
   296
 "\<And>s1. \<lbrakk>G\<turnstile>s \<midarrow>e-\<succ>b\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow> 
schirmer@12854
   297
  G\<turnstile>s \<midarrow>e ? e1 : e2-\<succ>(if normal s1 then v else arbitrary)\<midarrow>n\<rightarrow> s2"
schirmer@12854
   298
apply (case_tac "s", case_tac "a = None")
schirmer@12854
   299
by (auto intro!: evaln.Cond)
schirmer@12854
   300
schirmer@12854
   301
lemma evaln_SkipI [intro!]: "G\<turnstile>s \<midarrow>Skip\<midarrow>n\<rightarrow> s"
schirmer@12854
   302
apply (case_tac "s", case_tac "a = None")
schirmer@12854
   303
by (auto intro!: evaln.Skip)
schirmer@12854
   304
schirmer@12854
   305
lemma evaln_ExprI: "G\<turnstile>s \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s' \<Longrightarrow> G\<turnstile>s \<midarrow>Expr e\<midarrow>n\<rightarrow> s'"
schirmer@12854
   306
apply (case_tac "s", case_tac "a = None")
schirmer@12854
   307
by (auto intro!: evaln.Expr)
schirmer@12854
   308
schirmer@12854
   309
lemma evaln_CompI: "\<lbrakk>G\<turnstile>s \<midarrow>c1\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>c2\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow> G\<turnstile>s \<midarrow>c1;; c2\<midarrow>n\<rightarrow> s2"
schirmer@12854
   310
apply (case_tac "s", case_tac "a = None")
schirmer@12854
   311
by (auto intro!: evaln.Comp)
schirmer@12854
   312
schirmer@12854
   313
lemma evaln_IfI: 
schirmer@12854
   314
 "\<lbrakk>G\<turnstile>s \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1; G\<turnstile>s1 \<midarrow>(if the_Bool v then c1 else c2)\<midarrow>n\<rightarrow> s2\<rbrakk> \<Longrightarrow> 
schirmer@12854
   315
  G\<turnstile>s \<midarrow>If(e) c1 Else c2\<midarrow>n\<rightarrow> s2"
schirmer@12854
   316
apply (case_tac "s", case_tac "a = None")
schirmer@12854
   317
by (auto intro!: evaln.If)
schirmer@12854
   318
schirmer@12854
   319
lemma evaln_SkipD [dest!]: "G\<turnstile>s \<midarrow>Skip\<midarrow>n\<rightarrow> s' \<Longrightarrow> s' = s" 
schirmer@12854
   320
by (erule evaln_cases, auto)
schirmer@12854
   321
schirmer@12854
   322
lemma evaln_Skip_eq [simp]: "G\<turnstile>s \<midarrow>Skip\<midarrow>n\<rightarrow> s' = (s = s')"
schirmer@12854
   323
apply auto
schirmer@12854
   324
done
schirmer@12854
   325
schirmer@12925
   326
lemma evaln_eval:  
wenzelm@12937
   327
  assumes evaln: "G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1)" and
schirmer@12925
   328
             wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T" and  
schirmer@12925
   329
        conf_s0: "s0\<Colon>\<preceq>(G, L)" and
schirmer@12925
   330
             wf: "wf_prog G" 
schirmer@12925
   331
       
wenzelm@12937
   332
  shows "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)"
schirmer@12925
   333
proof -
schirmer@12925
   334
  from evaln 
schirmer@12925
   335
  show "\<And> L accC T. \<lbrakk>s0\<Colon>\<preceq>(G, L);\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T\<rbrakk>
schirmer@12925
   336
                    \<Longrightarrow> G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)"
schirmer@12925
   337
       (is "PROP ?EqEval s0 s1 t v")
schirmer@12925
   338
  proof (induct)
schirmer@12925
   339
    case Abrupt
schirmer@12925
   340
    show ?case by (rule eval.Abrupt)
schirmer@12925
   341
  next
schirmer@12925
   342
    case LVar
schirmer@12925
   343
    show ?case by (rule eval.LVar)
schirmer@12925
   344
  next
schirmer@12925
   345
    case (FVar a accC' e fn n s0 s1 s2 s2' stat statDeclC v L accC T)
schirmer@12925
   346
    have eval_initn: "G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<midarrow>n\<rightarrow> s1" .
schirmer@12925
   347
    have eval_en: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<midarrow>n\<rightarrow> s2" .
schirmer@12925
   348
    have hyp_init: "PROP ?EqEval (Norm s0) s1 (In1r (Init statDeclC)) \<diamondsuit>" .
schirmer@12925
   349
    have hyp_e: "PROP ?EqEval s1 s2 (In1l e) (In1 a)" .
schirmer@12925
   350
    have fvar: "(v, s2') = fvar statDeclC stat fn a s2" .
schirmer@12925
   351
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   352
    have wt: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>In2 ({accC',statDeclC,stat}e..fn)\<Colon>T" .
schirmer@12925
   353
    then obtain statC f where
schirmer@12925
   354
                wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-Class statC" and
schirmer@12925
   355
            accfield: "accfield G accC statC fn = Some (statDeclC,f)" and
schirmer@12925
   356
                stat: "stat=is_static f" and
schirmer@12925
   357
               accC': "accC'=accC" and
schirmer@12925
   358
	           T: "T=(Inl (type f))"
schirmer@12925
   359
       by (rule wt_elim_cases) (auto simp add: member_is_static_simp)
schirmer@12925
   360
    from wf wt_e 
schirmer@12925
   361
    have iscls_statC: "is_class G statC"
schirmer@12925
   362
      by (auto dest: ty_expr_is_type type_is_class)
schirmer@12925
   363
    with wf accfield 
schirmer@12925
   364
    have iscls_statDeclC: "is_class G statDeclC"
schirmer@12925
   365
      by (auto dest!: accfield_fields dest: fields_declC)
schirmer@12925
   366
    then 
schirmer@12925
   367
    have wt_init: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>(Init statDeclC)\<Colon>\<surd>"
schirmer@12925
   368
      by simp
schirmer@12925
   369
    from conf_s0 wt_init
schirmer@12925
   370
    have eval_init: "G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<rightarrow> s1"
schirmer@12925
   371
      by (rule hyp_init)
schirmer@12925
   372
    with wt_init conf_s0 wf 
schirmer@12925
   373
    have conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   374
      by (blast dest: exec_ts)
schirmer@12925
   375
    with hyp_e wt_e
schirmer@12925
   376
    have eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2"
schirmer@12925
   377
      by blast
schirmer@12925
   378
    with wf conf_s1 wt_e
schirmer@12925
   379
    obtain conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@12925
   380
            conf_a: "normal s2 \<longrightarrow> G,store s2\<turnstile>a\<Colon>\<preceq>Class statC"
schirmer@12925
   381
      by (auto dest!: eval_type_sound)
schirmer@12925
   382
    obtain s3 where
schirmer@12925
   383
      check: "s3 = check_field_access G accC statDeclC fn stat a s2'"
schirmer@12925
   384
      by simp
schirmer@12925
   385
    from accfield wt_e eval_init eval_e conf_s2 conf_a fvar stat check  wf
schirmer@12925
   386
    have eq_s3_s2': "s3=s2'"  
schirmer@12925
   387
      by (auto dest!: error_free_field_access)
schirmer@12925
   388
    with eval_init eval_e fvar check accC'
schirmer@12925
   389
    show "G\<turnstile>Norm s0 \<midarrow>{accC',statDeclC,stat}e..fn=\<succ>v\<rightarrow> s2'"
schirmer@12925
   390
      by (auto intro: eval.FVar)
schirmer@12925
   391
  next
schirmer@12925
   392
    case AVar
schirmer@12925
   393
    with wf show ?case
schirmer@12925
   394
      apply -
schirmer@12925
   395
      apply (erule wt_elim_cases)
schirmer@12925
   396
      apply (blast intro!: eval.AVar dest: eval_type_sound)
schirmer@12925
   397
      done
schirmer@12925
   398
  next
schirmer@12925
   399
    case NewC
schirmer@12925
   400
    with wf show ?case
schirmer@12925
   401
      apply - 
schirmer@12925
   402
      apply (erule wt_elim_cases)
schirmer@12925
   403
      apply (blast intro!: eval.NewC dest: eval_type_sound is_acc_classD)
schirmer@12925
   404
      done
schirmer@12925
   405
  next
schirmer@12925
   406
    case (NewA T a e i n s0 s1 s2 s3 L accC Ta) 
schirmer@12925
   407
    have hyp_init: "PROP ?EqEval (Norm s0) s1 (In1r (init_comp_ty T)) \<diamondsuit>" .
schirmer@12925
   408
    have hyp_size: "PROP ?EqEval s1 s2 (In1l e) (In1 i)" .
schirmer@12925
   409
    have "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1l (New T[e])\<Colon>Ta" .
schirmer@12925
   410
    then obtain
schirmer@12925
   411
       wt_init: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>init_comp_ty T\<Colon>\<surd>" and
schirmer@12925
   412
       wt_size: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-PrimT Integer"
schirmer@12925
   413
      by (rule wt_elim_cases) (auto intro: wt_init_comp_ty dest: is_acc_typeD)
schirmer@12925
   414
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   415
    from this wt_init 
schirmer@12925
   416
    have eval_init: "G\<turnstile>Norm s0 \<midarrow>init_comp_ty T\<rightarrow> s1"
schirmer@12925
   417
      by (rule hyp_init)
schirmer@12925
   418
    moreover
schirmer@12925
   419
    from eval_init wt_init wf conf_s0
schirmer@12925
   420
    have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   421
      by (auto dest: eval_type_sound)
schirmer@12925
   422
    from this wt_size 
schirmer@12925
   423
    have "G\<turnstile>s1 \<midarrow>e-\<succ>i\<rightarrow> s2"
schirmer@12925
   424
      by (rule hyp_size)
schirmer@12925
   425
    moreover note NewA
schirmer@12925
   426
    ultimately show ?case
schirmer@12925
   427
      by (blast intro!: eval.NewA)
schirmer@12925
   428
  next
schirmer@12925
   429
    case Cast
schirmer@12925
   430
    with wf show ?case
schirmer@12925
   431
      by - (erule wt_elim_cases, rule eval.Cast,auto dest: eval_type_sound)
schirmer@12925
   432
  next
schirmer@12925
   433
    case Inst
schirmer@12925
   434
    with wf show ?case
schirmer@12925
   435
      by - (erule wt_elim_cases, rule eval.Inst,auto dest: eval_type_sound)
schirmer@12925
   436
  next
schirmer@12925
   437
    case Lit
schirmer@12925
   438
    show ?case by (rule eval.Lit)
schirmer@12925
   439
  next
schirmer@12925
   440
    case Super
schirmer@12925
   441
    show ?case by (rule eval.Super)
schirmer@12925
   442
  next
schirmer@12925
   443
    case Acc
schirmer@12925
   444
    then show ?case
schirmer@12925
   445
      by - (erule wt_elim_cases, rule eval.Acc,auto dest: eval_type_sound)
schirmer@12925
   446
  next
schirmer@12925
   447
    case Ass
schirmer@12925
   448
    with wf show ?case
schirmer@12925
   449
      by - (erule wt_elim_cases, blast intro!: eval.Ass dest: eval_type_sound) 
schirmer@12925
   450
  next
schirmer@12925
   451
    case (Cond b e0 e1 e2 n s0 s1 s2 v L accC T)
schirmer@12925
   452
    have hyp_e0: "PROP ?EqEval (Norm s0) s1 (In1l e0) (In1 b)" .
schirmer@12925
   453
    have hyp_if: "PROP ?EqEval s1 s2 
schirmer@12925
   454
                              (In1l (if the_Bool b then e1 else e2)) (In1 v)" .
schirmer@12925
   455
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   456
    have wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1l (e0 ? e1 : e2)\<Colon>T" .
schirmer@12925
   457
    then obtain T1 T2 statT where
schirmer@12925
   458
       wt_e0: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e0\<Colon>-PrimT Boolean" and
schirmer@12925
   459
       wt_e1: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e1\<Colon>-T1" and
schirmer@12925
   460
       wt_e2: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e2\<Colon>-T2" and 
schirmer@12925
   461
       statT: "G\<turnstile>T1\<preceq>T2 \<and> statT = T2  \<or>  G\<turnstile>T2\<preceq>T1 \<and> statT =  T1" and
schirmer@12925
   462
       T    : "T=Inl statT"
schirmer@12925
   463
      by (rule wt_elim_cases) auto
schirmer@12925
   464
    from conf_s0 wt_e0
schirmer@12925
   465
    have eval_e0: "G\<turnstile>Norm s0 \<midarrow>e0-\<succ>b\<rightarrow> s1"
schirmer@12925
   466
      by (rule hyp_e0)
schirmer@12925
   467
    moreover
schirmer@12925
   468
    from eval_e0 conf_s0 wf wt_e0
schirmer@12925
   469
    have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   470
      by (blast dest: eval_type_sound)
schirmer@12925
   471
    with wt_e1 wt_e2 statT hyp_if
schirmer@12925
   472
    have "G\<turnstile>s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<rightarrow> s2"
schirmer@12925
   473
      by (cases "the_Bool b") auto
schirmer@12925
   474
    ultimately
schirmer@12925
   475
    show ?case
schirmer@12925
   476
      by (rule eval.Cond)
schirmer@12925
   477
  next
schirmer@12925
   478
    case (Call invDeclC a' accC' args e mn mode n pTs' s0 s1 s2 s4 statT 
schirmer@12925
   479
           v vs L accC T)
wenzelm@12937
   480
    txt {* Repeats large parts of the type soundness proof. One should factor
wenzelm@12937
   481
      out some lemmata about the relations and conformance of @{text
wenzelm@12937
   482
      s2}, @{text s3} and @{text s3'} *}
schirmer@12925
   483
    have evaln_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<midarrow>n\<rightarrow> s1" .
schirmer@12925
   484
    have evaln_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<midarrow>n\<rightarrow> s2" .
schirmer@12925
   485
    have invDeclC: "invDeclC 
schirmer@12925
   486
                      = invocation_declclass G mode (store s2) a' statT 
schirmer@12925
   487
                           \<lparr>name = mn, parTs = pTs'\<rparr>" .
schirmer@12925
   488
    let ?InitLvars 
schirmer@12925
   489
         = "init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> mode a' vs s2"
schirmer@12925
   490
    obtain s3 s3' where 
schirmer@12925
   491
      init_lvars: "s3 = 
schirmer@12925
   492
             init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> mode a' vs s2" and
schirmer@12925
   493
      check: "s3' =
schirmer@12925
   494
         check_method_access G accC' statT mode \<lparr>name = mn, parTs = pTs'\<rparr> a' s3"
schirmer@12925
   495
      by simp
schirmer@12925
   496
    have evaln_methd: 
schirmer@12925
   497
           "G\<turnstile>?InitLvars \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<midarrow>n\<rightarrow> s4" .
schirmer@12925
   498
    have     hyp_e: "PROP ?EqEval (Norm s0) s1 (In1l e) (In1 a')" .
schirmer@12925
   499
    have  hyp_args: "PROP ?EqEval s1 s2 (In3 args) (In3 vs)" .
schirmer@12925
   500
    have hyp_methd: "PROP ?EqEval ?InitLvars s4 
schirmer@12925
   501
                     (In1l (Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>)) (In1 v)".
schirmer@12925
   502
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   503
    have      wt: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>
schirmer@12925
   504
                    \<turnstile>In1l ({accC',statT,mode}e\<cdot>mn( {pTs'}args))\<Colon>T" .
schirmer@12925
   505
    from wt obtain pTs statDeclT statM where
schirmer@12925
   506
                 wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT" and
schirmer@12925
   507
              wt_args: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>args\<Colon>\<doteq>pTs" and
schirmer@12925
   508
                statM: "max_spec G accC statT \<lparr>name=mn,parTs=pTs\<rparr> 
schirmer@12925
   509
                         = {((statDeclT,statM),pTs')}" and
schirmer@12925
   510
                 mode: "mode = invmode statM e" and
schirmer@12925
   511
                    T: "T =Inl (resTy statM)" and
schirmer@12925
   512
        eq_accC_accC': "accC=accC'"
schirmer@12925
   513
      by (rule wt_elim_cases) auto
schirmer@12925
   514
    from conf_s0 wt_e hyp_e
schirmer@12925
   515
    have eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<rightarrow> s1"
schirmer@12925
   516
      by blast
schirmer@12925
   517
    with wf conf_s0 wt_e
schirmer@12925
   518
    obtain conf_s1: "s1\<Colon>\<preceq>(G, L)" and
schirmer@12925
   519
           conf_a': "normal s1 \<Longrightarrow> G, store s1\<turnstile>a'\<Colon>\<preceq>RefT statT" 
schirmer@12925
   520
      by (auto dest!: eval_type_sound)
schirmer@12925
   521
    from conf_s1 wt_args hyp_args
schirmer@12925
   522
    have eval_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2"
schirmer@12925
   523
      by blast
schirmer@12925
   524
    with wt_args conf_s1 wf 
schirmer@12925
   525
    obtain    conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@12925
   526
            conf_args: "normal s2 
schirmer@12925
   527
                         \<Longrightarrow>  list_all2 (conf G (store s2)) vs pTs" 
schirmer@12925
   528
      by (auto dest!: eval_type_sound)
schirmer@12925
   529
    from statM 
schirmer@12925
   530
    obtain
schirmer@12925
   531
       statM': "(statDeclT,statM)\<in>mheads G accC statT \<lparr>name=mn,parTs=pTs'\<rparr>" and
schirmer@12925
   532
       pTs_widen: "G\<turnstile>pTs[\<preceq>]pTs'"
schirmer@12925
   533
      by (blast dest: max_spec2mheads)
schirmer@12925
   534
    from check
schirmer@12925
   535
    have eq_store_s3'_s3: "store s3'=store s3"
schirmer@12925
   536
      by (cases s3) (simp add: check_method_access_def Let_def)
schirmer@12925
   537
    obtain invC
schirmer@12925
   538
      where invC: "invC = invocation_class mode (store s2) a' statT"
schirmer@12925
   539
      by simp
schirmer@12925
   540
    with init_lvars
schirmer@12925
   541
    have invC': "invC = (invocation_class mode (store s3) a' statT)"
schirmer@12925
   542
      by (cases s2,cases mode) (auto simp add: init_lvars_def2 )
schirmer@12925
   543
    show "G\<turnstile>Norm s0 \<midarrow>{accC',statT,mode}e\<cdot>mn( {pTs'}args)
schirmer@12925
   544
             -\<succ>v\<rightarrow> (set_lvars (locals (store s2))) s4"
schirmer@12925
   545
    proof (cases "normal s2")
schirmer@12925
   546
      case False
schirmer@12925
   547
      with init_lvars 
schirmer@12925
   548
      obtain keep_abrupt: "abrupt s3 = abrupt s2" and
schirmer@12925
   549
             "store s3 = store (init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> 
schirmer@12925
   550
                                            mode a' vs s2)" 
schirmer@12925
   551
	by (auto simp add: init_lvars_def2)
schirmer@12925
   552
      moreover
schirmer@12925
   553
      from keep_abrupt False check
schirmer@12925
   554
      have eq_s3'_s3: "s3'=s3" 
schirmer@12925
   555
	by (auto simp add: check_method_access_def Let_def)
schirmer@12925
   556
      moreover
schirmer@12925
   557
      from eq_s3'_s3 False keep_abrupt evaln_methd init_lvars
schirmer@12925
   558
      obtain "s4=s3'"
schirmer@12925
   559
	 "In1 v=arbitrary3 (In1l (Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>))"
schirmer@12925
   560
	by auto
schirmer@12925
   561
      moreover note False
schirmer@12925
   562
      ultimately have
schirmer@12925
   563
	"G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<rightarrow> s4"
schirmer@12925
   564
	by (auto)
schirmer@12925
   565
      from eval_e eval_args invDeclC init_lvars check this
schirmer@12925
   566
      show ?thesis
schirmer@12925
   567
	by (rule eval.Call)
schirmer@12925
   568
    next
schirmer@12925
   569
      case True
schirmer@12925
   570
      note normal_s2 = True
schirmer@12925
   571
      with eval_args
schirmer@12925
   572
      have normal_s1: "normal s1"
schirmer@12925
   573
	by (cases "normal s1") auto
schirmer@12925
   574
      with conf_a' eval_args 
schirmer@12925
   575
      have conf_a'_s2: "G, store s2\<turnstile>a'\<Colon>\<preceq>RefT statT"
schirmer@12925
   576
	by (auto dest: eval_gext intro: conf_gext)
schirmer@12925
   577
      show ?thesis
schirmer@12925
   578
      proof (cases "a'=Null \<longrightarrow> is_static statM")
schirmer@12925
   579
	case False
schirmer@12925
   580
	then obtain not_static: "\<not> is_static statM" and Null: "a'=Null" 
schirmer@12925
   581
	  by blast
schirmer@12925
   582
	with normal_s2 init_lvars mode
schirmer@12925
   583
	obtain np: "abrupt s3 = Some (Xcpt (Std NullPointer))" and
schirmer@12925
   584
                   "store s3 = store (init_lvars G invDeclC 
schirmer@12925
   585
                                       \<lparr>name = mn, parTs = pTs'\<rparr> mode a' vs s2)"
schirmer@12925
   586
	  by (auto simp add: init_lvars_def2)
schirmer@12925
   587
	moreover
schirmer@12925
   588
	from np check
schirmer@12925
   589
	have eq_s3'_s3: "s3'=s3" 
schirmer@12925
   590
	  by (auto simp add: check_method_access_def Let_def)
schirmer@12925
   591
	moreover
schirmer@12925
   592
	from eq_s3'_s3 np evaln_methd init_lvars
schirmer@12925
   593
	obtain "s4=s3'"
schirmer@12925
   594
	  "In1 v=arbitrary3 (In1l (Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>))"
schirmer@12925
   595
	  by auto
schirmer@12925
   596
	moreover note np 
schirmer@12925
   597
	ultimately have
schirmer@12925
   598
	  "G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<rightarrow> s4"
schirmer@12925
   599
	  by (auto)
schirmer@12925
   600
	from eval_e eval_args invDeclC init_lvars check this
schirmer@12925
   601
	show ?thesis
schirmer@12925
   602
	  by (rule eval.Call)
schirmer@12925
   603
      next
schirmer@12925
   604
	case True
schirmer@12925
   605
	with mode have notNull: "mode = IntVir \<longrightarrow> a' \<noteq> Null"
schirmer@12925
   606
	  by (auto dest!: Null_staticD)
schirmer@12925
   607
	with conf_s2 conf_a'_s2 wf invC 
schirmer@12925
   608
	have dynT_prop: "G\<turnstile>mode\<rightarrow>invC\<preceq>statT"
schirmer@12925
   609
	  by (cases s2) (auto intro: DynT_propI)
schirmer@12925
   610
	with wt_e statM' invC mode wf 
schirmer@12925
   611
	obtain dynM where 
schirmer@12925
   612
           dynM: "dynlookup G statT invC  \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@12925
   613
           acc_dynM: "G \<turnstile>Methd  \<lparr>name=mn,parTs=pTs'\<rparr> dynM 
schirmer@12925
   614
                          in invC dyn_accessible_from accC"
schirmer@12925
   615
	  by (force dest!: call_access_ok)
schirmer@12925
   616
	with invC' check eq_accC_accC'
schirmer@12925
   617
	have eq_s3'_s3: "s3'=s3"
schirmer@12925
   618
	  by (auto simp add: check_method_access_def Let_def)
schirmer@12925
   619
	from dynT_prop wf wt_e statM' mode invC invDeclC dynM 
schirmer@12925
   620
	obtain 
schirmer@12925
   621
	   wf_dynM: "wf_mdecl G invDeclC (\<lparr>name=mn,parTs=pTs'\<rparr>,mthd dynM)" and
schirmer@12925
   622
	     dynM': "methd G invDeclC \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@12925
   623
           iscls_invDeclC: "is_class G invDeclC" and
schirmer@12925
   624
	        invDeclC': "invDeclC = declclass dynM" and
schirmer@12925
   625
	     invC_widen: "G\<turnstile>invC\<preceq>\<^sub>C invDeclC" and
schirmer@12925
   626
	   is_static_eq: "is_static dynM = is_static statM" and
schirmer@12925
   627
	   involved_classes_prop:
schirmer@12925
   628
             "(if invmode statM e = IntVir
schirmer@12925
   629
               then \<forall>statC. statT = ClassT statC \<longrightarrow> G\<turnstile>invC\<preceq>\<^sub>C statC
schirmer@12925
   630
               else ((\<exists>statC. statT = ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C invDeclC) \<or>
schirmer@12925
   631
                     (\<forall>statC. statT \<noteq> ClassT statC \<and> invDeclC = Object)) \<and>
schirmer@12925
   632
                      statDeclT = ClassT invDeclC)"
schirmer@12925
   633
	  by (auto dest: DynT_mheadsD)
schirmer@12925
   634
	obtain L' where 
schirmer@12925
   635
	   L':"L'=(\<lambda> k. 
schirmer@12925
   636
                 (case k of
schirmer@12925
   637
                    EName e
schirmer@12925
   638
                    \<Rightarrow> (case e of 
schirmer@12925
   639
                          VNam v 
schirmer@12925
   640
                          \<Rightarrow>(table_of (lcls (mbody (mthd dynM)))
schirmer@12925
   641
                             (pars (mthd dynM)[\<mapsto>]pTs')) v
schirmer@12925
   642
                        | Res \<Rightarrow> Some (resTy dynM))
schirmer@12925
   643
                  | This \<Rightarrow> if is_static statM 
schirmer@12925
   644
                            then None else Some (Class invDeclC)))"
schirmer@12925
   645
	  by simp
schirmer@12925
   646
	from wf_dynM [THEN wf_mdeclD1, THEN conjunct1] normal_s2 conf_s2 wt_e
schirmer@12925
   647
              wf eval_args conf_a' mode notNull wf_dynM involved_classes_prop
schirmer@12925
   648
	have conf_s3: "s3\<Colon>\<preceq>(G,L')"
schirmer@12925
   649
	   apply - 
schirmer@12925
   650
          (*FIXME confomrs_init_lvars should be 
schirmer@12925
   651
                adjusted to be more directy applicable *)
schirmer@12925
   652
	   apply (drule conforms_init_lvars [of G invDeclC 
schirmer@12925
   653
                  "\<lparr>name=mn,parTs=pTs'\<rparr>" dynM "store s2" vs pTs "abrupt s2" 
schirmer@12925
   654
                  L statT invC a' "(statDeclT,statM)" e])
schirmer@12925
   655
	     apply (rule wf)
schirmer@12925
   656
	     apply (rule conf_args,assumption)
schirmer@12925
   657
	     apply (simp add: pTs_widen)
schirmer@12925
   658
	     apply (cases s2,simp)
schirmer@12925
   659
	     apply (rule dynM')
schirmer@12925
   660
	     apply (force dest: ty_expr_is_type)
schirmer@12925
   661
	     apply (rule invC_widen)
schirmer@12925
   662
	     apply (force intro: conf_gext dest: eval_gext)
schirmer@12925
   663
	     apply simp
schirmer@12925
   664
	     apply simp
schirmer@12925
   665
	     apply (simp add: invC)
schirmer@12925
   666
	     apply (simp add: invDeclC)
schirmer@12925
   667
	     apply (force dest: wf_mdeclD1 is_acc_typeD)
schirmer@12925
   668
	     apply (cases s2, simp add: L' init_lvars
schirmer@12925
   669
	                      cong add: lname.case_cong ename.case_cong)
schirmer@12925
   670
	   done
schirmer@12925
   671
	from is_static_eq wf_dynM L'
schirmer@12925
   672
	obtain mthdT where
schirmer@12925
   673
	   "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr>
schirmer@12925
   674
            \<turnstile>Body invDeclC (stmt (mbody (mthd dynM)))\<Colon>-mthdT" and
schirmer@12925
   675
	   mthdT_widen: "G\<turnstile>mthdT\<preceq>resTy dynM"
schirmer@12925
   676
	  by - (drule wf_mdecl_bodyD,
schirmer@12925
   677
                simp cong add: lname.case_cong ename.case_cong)
schirmer@12925
   678
	with dynM' iscls_invDeclC invDeclC'
schirmer@12925
   679
	have
schirmer@12925
   680
	   "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr>
schirmer@12925
   681
            \<turnstile>(Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>)\<Colon>-mthdT"
schirmer@12925
   682
	  by (auto intro: wt.Methd)
schirmer@12925
   683
	with conf_s3 hyp_methd init_lvars eq_s3'_s3
schirmer@12925
   684
	have "G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<rightarrow> s4"
schirmer@12925
   685
	  by auto
schirmer@12925
   686
	from eval_e eval_args invDeclC init_lvars check this
schirmer@12925
   687
	show ?thesis
schirmer@12925
   688
	  by (rule eval.Call)
schirmer@12925
   689
      qed
schirmer@12925
   690
    qed
schirmer@12925
   691
  next
schirmer@12925
   692
    case Methd
schirmer@12925
   693
    with wf show ?case
schirmer@12925
   694
      by - (erule wt_elim_cases, rule eval.Methd, 
schirmer@12925
   695
            auto dest: eval_type_sound simp add: body_def2)
schirmer@12925
   696
  next
schirmer@12925
   697
    case Body
schirmer@12925
   698
    with wf show ?case
schirmer@12925
   699
       by - (erule wt_elim_cases, blast intro!: eval.Body dest: eval_type_sound)
schirmer@12925
   700
  next
schirmer@12925
   701
    case Nil
schirmer@12925
   702
    show ?case by (rule eval.Nil)
schirmer@12925
   703
  next
schirmer@12925
   704
    case Cons
schirmer@12925
   705
    with wf show ?case
schirmer@12925
   706
      by - (erule wt_elim_cases, blast intro!: eval.Cons dest: eval_type_sound)
schirmer@12925
   707
  next
schirmer@12925
   708
    case Skip
schirmer@12925
   709
    show ?case by (rule eval.Skip)
schirmer@12925
   710
  next
schirmer@12925
   711
    case Expr
schirmer@12925
   712
    with wf show ?case
schirmer@12925
   713
      by - (erule wt_elim_cases, rule eval.Expr,auto dest: eval_type_sound)
schirmer@12925
   714
  next
schirmer@12925
   715
    case Lab
schirmer@12925
   716
    with wf show ?case
schirmer@12925
   717
      by - (erule wt_elim_cases, rule eval.Lab,auto dest: eval_type_sound)
schirmer@12925
   718
  next
schirmer@12925
   719
    case Comp
schirmer@12925
   720
    with wf show ?case
schirmer@12925
   721
      by - (erule wt_elim_cases, blast intro!: eval.Comp dest: eval_type_sound)
schirmer@12925
   722
  next
schirmer@12925
   723
    case (If b c1 c2 e n s0 s1 s2 L accC T)
schirmer@12925
   724
    have hyp_e: "PROP ?EqEval (Norm s0) s1 (In1l e) (In1 b)" .
schirmer@12925
   725
    have hyp_then_else: 
schirmer@12925
   726
      "PROP ?EqEval s1 s2 (In1r (if the_Bool b then c1 else c2)) \<diamondsuit>" .
schirmer@12925
   727
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   728
    have      wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (If(e) c1 Else c2)\<Colon>T" .
schirmer@12925
   729
    then obtain 
schirmer@12925
   730
              wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-PrimT Boolean" and
schirmer@12925
   731
      wt_then_else: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>(if the_Bool b then c1 else c2)\<Colon>\<surd>"
schirmer@12925
   732
      by (rule wt_elim_cases) (auto split add: split_if)
schirmer@12925
   733
    from conf_s0 wt_e
schirmer@12925
   734
    have eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1"
schirmer@12925
   735
      by (rule hyp_e)
schirmer@12925
   736
    moreover
schirmer@12925
   737
    from eval_e wt_e conf_s0 wf
schirmer@12925
   738
    have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   739
      by (blast dest: eval_type_sound)
schirmer@12925
   740
    from this wt_then_else
schirmer@12925
   741
    have "G\<turnstile>s1 \<midarrow>(if the_Bool b then c1 else c2)\<rightarrow> s2"
schirmer@12925
   742
      by (rule hyp_then_else)
schirmer@12925
   743
    ultimately
schirmer@12925
   744
    show ?case
schirmer@12925
   745
      by (rule eval.If)
schirmer@12925
   746
  next
schirmer@12925
   747
    case (Loop b c e l n s0 s1 s2 s3 L accC T)
schirmer@12925
   748
    have hyp_e: "PROP ?EqEval (Norm s0) s1 (In1l e) (In1 b)" .
schirmer@12925
   749
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   750
    have      wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (l\<bullet> While(e) c)\<Colon>T" .
schirmer@12925
   751
    then obtain wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-PrimT Boolean" and
schirmer@12925
   752
                wt_c: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c\<Colon>\<surd>"
schirmer@12925
   753
      by (rule wt_elim_cases) (blast)
schirmer@12925
   754
    from conf_s0 wt_e 
schirmer@12925
   755
    have eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1"
schirmer@12925
   756
      by (rule hyp_e)
schirmer@12925
   757
    moreover
schirmer@12925
   758
    from eval_e wt_e conf_s0 wf
schirmer@12925
   759
    have conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   760
      by (blast dest: eval_type_sound)
schirmer@12925
   761
    have "if normal s1 \<and> the_Bool b 
schirmer@12925
   762
             then (G\<turnstile>s1 \<midarrow>c\<rightarrow> s2 \<and> 
schirmer@12925
   763
                   G\<turnstile>(abupd (absorb (Cont l)) s2) \<midarrow>l\<bullet> While(e) c\<rightarrow> s3)
schirmer@12925
   764
	     else s3 = s1"
schirmer@12925
   765
    proof (cases "normal s1 \<and> the_Bool b")
schirmer@12925
   766
      case True 
schirmer@12925
   767
      from Loop True have hyp_c: "PROP ?EqEval s1 s2 (In1r c) \<diamondsuit>"
schirmer@12925
   768
	by (auto)
schirmer@12925
   769
      from Loop True have hyp_w: "PROP ?EqEval (abupd (absorb (Cont l)) s2)
schirmer@12925
   770
                                        s3 (In1r (l\<bullet> While(e) c)) \<diamondsuit>"
schirmer@12925
   771
	by (auto)
schirmer@12925
   772
      from conf_s1 wt_c
schirmer@12925
   773
      have eval_c: "G\<turnstile>s1 \<midarrow>c\<rightarrow> s2"
schirmer@12925
   774
	by (rule hyp_c)
schirmer@12925
   775
      moreover
schirmer@12925
   776
      from eval_c conf_s1 wt_c wf
schirmer@12925
   777
      have "s2\<Colon>\<preceq>(G, L)"
schirmer@12925
   778
	by (blast dest: eval_type_sound)
schirmer@12925
   779
      then
schirmer@12925
   780
      have "abupd (absorb (Cont l)) s2 \<Colon>\<preceq>(G, L)"
schirmer@12925
   781
	by (cases s2) (auto intro: conforms_absorb)
schirmer@12925
   782
      from this and wt
schirmer@12925
   783
      have "G\<turnstile>abupd (absorb (Cont l)) s2 \<midarrow>l\<bullet> While(e) c\<rightarrow> s3"
schirmer@12925
   784
	by (rule hyp_w)
schirmer@12925
   785
      moreover note True
schirmer@12925
   786
      ultimately
schirmer@12925
   787
      show ?thesis
schirmer@12925
   788
	by simp
schirmer@12925
   789
    next
schirmer@12925
   790
      case False
schirmer@12925
   791
      with Loop have "s3 = s1" by simp
schirmer@12925
   792
      with False
schirmer@12925
   793
      show ?thesis 
schirmer@12925
   794
	by auto
schirmer@12925
   795
    qed
schirmer@12925
   796
    ultimately
schirmer@12925
   797
    show ?case
schirmer@12925
   798
      by (rule eval.Loop)
schirmer@12925
   799
  next
schirmer@12925
   800
    case Do
schirmer@12925
   801
    show ?case by (rule eval.Do)
schirmer@12925
   802
  next
schirmer@12925
   803
    case Throw
schirmer@12925
   804
    with wf show ?case
schirmer@12925
   805
      by - (erule wt_elim_cases, rule eval.Throw,auto dest: eval_type_sound)
schirmer@12925
   806
  next
schirmer@12925
   807
    case (Try c1 c2 n s0 s1 s2 s3 catchC vn L accC T)
schirmer@12925
   808
    have  hyp_c1: "PROP ?EqEval (Norm s0) s1 (In1r c1) \<diamondsuit>" .
schirmer@12925
   809
    have conf_s0:"Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   810
    have      wt:"\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>In1r (Try c1 Catch(catchC vn) c2)\<Colon>T" .
schirmer@12925
   811
    then obtain 
schirmer@12925
   812
      wt_c1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>c1\<Colon>\<surd>" and
schirmer@12925
   813
      wt_c2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<lparr>lcl := L(VName vn\<mapsto>Class catchC)\<rparr>\<turnstile>c2\<Colon>\<surd>"
schirmer@12925
   814
      by (rule wt_elim_cases) (auto)
schirmer@12925
   815
    from conf_s0 wt_c1
schirmer@12925
   816
    have eval_c1: "G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1"
schirmer@12925
   817
      by (rule hyp_c1)
schirmer@12925
   818
    moreover
schirmer@12925
   819
    have sxalloc: "G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2" .
schirmer@12925
   820
    moreover
schirmer@12925
   821
    from eval_c1 wt_c1 conf_s0 wf
schirmer@12925
   822
    have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   823
      by (blast dest: eval_type_sound)
schirmer@12925
   824
    with sxalloc wf
schirmer@12925
   825
    have conf_s2: "s2\<Colon>\<preceq>(G, L)" 
schirmer@12925
   826
      by (auto dest: sxalloc_type_sound split: option.splits)
schirmer@12925
   827
    have "if G,s2\<turnstile>catch catchC then G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<rightarrow> s3 else s3 = s2"
schirmer@12925
   828
    proof (cases "G,s2\<turnstile>catch catchC")
schirmer@12925
   829
      case True
schirmer@12925
   830
      note Catch = this
schirmer@12925
   831
      with Try have hyp_c2: "PROP ?EqEval (new_xcpt_var vn s2) s3 (In1r c2) \<diamondsuit>"
schirmer@12925
   832
	by auto
schirmer@12925
   833
      show ?thesis
schirmer@12925
   834
      proof (cases "normal s1")
schirmer@12925
   835
	case True
schirmer@12925
   836
	with sxalloc wf 
schirmer@12925
   837
	have eq_s2_s1: "s2=s1"
schirmer@12925
   838
	  by (auto dest: sxalloc_type_sound split: option.splits)
schirmer@12925
   839
	with True 
schirmer@12925
   840
	have "\<not>  G,s2\<turnstile>catch catchC"
schirmer@12925
   841
	  by (simp add: catch_def)
schirmer@12925
   842
	with Catch show ?thesis 
schirmer@12925
   843
	  by (contradiction)
schirmer@12925
   844
      next 
schirmer@12925
   845
	case False
schirmer@12925
   846
	with sxalloc wf
schirmer@12925
   847
	obtain a 
schirmer@12925
   848
	  where xcpt_s2: "abrupt s2 = Some (Xcpt (Loc a))"
schirmer@12925
   849
	  by (auto dest!: sxalloc_type_sound split: option.splits)
schirmer@12925
   850
	with Catch
schirmer@12925
   851
	have "G\<turnstile>obj_ty (the (globs (store s2) (Heap a)))\<preceq>Class catchC"
schirmer@12925
   852
	  by (cases s2) simp
schirmer@12925
   853
	with xcpt_s2 conf_s2 wf 
schirmer@12925
   854
	have "new_xcpt_var vn s2\<Colon>\<preceq>(G, L(VName vn\<mapsto>Class catchC))"
schirmer@12925
   855
	  by (auto dest: Try_lemma)
schirmer@12925
   856
	from this wt_c2
schirmer@12925
   857
	have "G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<rightarrow> s3"
schirmer@12925
   858
	  by (auto intro: hyp_c2)
schirmer@12925
   859
	with Catch 
schirmer@12925
   860
	show ?thesis
schirmer@12925
   861
	  by simp
schirmer@12925
   862
      qed
schirmer@12925
   863
    next
schirmer@12925
   864
      case False
schirmer@12925
   865
      with Try
schirmer@12925
   866
      have "s3=s2"
schirmer@12925
   867
	by simp
schirmer@12925
   868
      with False
schirmer@12925
   869
      show ?thesis
schirmer@12925
   870
	by simp
schirmer@12925
   871
    qed
schirmer@12925
   872
    ultimately
schirmer@12925
   873
    show ?case
schirmer@12925
   874
      by (rule eval.Try)
schirmer@12925
   875
  next
schirmer@12925
   876
    case Fin
schirmer@12925
   877
    with wf show ?case
schirmer@12925
   878
      by -(erule wt_elim_cases, blast intro!: eval.Fin
schirmer@12925
   879
           dest: eval_type_sound intro: conforms_NormI)
schirmer@12925
   880
  next
schirmer@12925
   881
    case (Init C c n s0 s1 s2 s3 L accC T)
schirmer@12925
   882
    have     cls: "the (class G C) = c" .
schirmer@12925
   883
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
   884
    have      wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (Init C)\<Colon>T" .
schirmer@12925
   885
    with cls
schirmer@12925
   886
    have cls_C: "class G C = Some c"
schirmer@12925
   887
      by - (erule wt_elim_cases,auto)
schirmer@12925
   888
    have "if inited C (globs s0) then s3 = Norm s0
schirmer@12925
   889
	  else (G\<turnstile>Norm (init_class_obj G C s0) 
schirmer@12925
   890
		  \<midarrow>(if C = Object then Skip else Init (super c))\<rightarrow> s1 \<and>
schirmer@12925
   891
	       G\<turnstile>set_lvars empty s1 \<midarrow>init c\<rightarrow> s2 \<and> s3 = restore_lvars s1 s2)"
schirmer@12925
   892
    proof (cases "inited C (globs s0)")
schirmer@12925
   893
      case True
schirmer@12925
   894
      with Init have "s3 = Norm s0"
schirmer@12925
   895
	by simp
schirmer@12925
   896
      with True show ?thesis 
schirmer@12925
   897
	by simp
schirmer@12925
   898
    next
schirmer@12925
   899
      case False
schirmer@12925
   900
      with Init
schirmer@12925
   901
      obtain 
schirmer@12925
   902
	hyp_init_super: 
schirmer@12925
   903
        "PROP ?EqEval (Norm ((init_class_obj G C) s0)) s1
schirmer@12925
   904
	               (In1r (if C = Object then Skip else Init (super c))) \<diamondsuit>"
schirmer@12925
   905
	and 
schirmer@12925
   906
        hyp_init_c:
schirmer@12925
   907
	   "PROP ?EqEval ((set_lvars empty) s1) s2 (In1r (init c)) \<diamondsuit>" and
schirmer@12925
   908
	s3: "s3 = (set_lvars (locals (store s1))) s2"
schirmer@12925
   909
	by (simp only: if_False)
schirmer@12925
   910
      from conf_s0 wf cls_C False
schirmer@12925
   911
      have conf_s0': "(Norm ((init_class_obj G C) s0))\<Colon>\<preceq>(G, L)"
schirmer@12925
   912
	by (auto dest: conforms_init_class_obj)
schirmer@12925
   913
      moreover
schirmer@12925
   914
      from wf cls_C 
schirmer@12925
   915
      have wt_init_super:
schirmer@12925
   916
           "\<lparr>prg = G, cls = accC, lcl = L\<rparr>
schirmer@12925
   917
                  \<turnstile>(if C = Object then Skip else Init (super c))\<Colon>\<surd>"
schirmer@12925
   918
	by (cases "C=Object")
schirmer@12925
   919
           (auto dest: wf_prog_cdecl wf_cdecl_supD is_acc_classD)
schirmer@12925
   920
      ultimately
schirmer@12925
   921
      have eval_init_super: 
schirmer@12925
   922
	   "G\<turnstile>Norm ((init_class_obj G C) s0) 
schirmer@12925
   923
            \<midarrow>(if C = Object then Skip else Init (super c))\<rightarrow> s1"
schirmer@12925
   924
	by (rule hyp_init_super)
schirmer@12925
   925
      with conf_s0' wt_init_super wf
schirmer@12925
   926
      have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
   927
	by (blast dest: eval_type_sound)
schirmer@12925
   928
      then
schirmer@12925
   929
      have "(set_lvars empty) s1\<Colon>\<preceq>(G, empty)"
schirmer@12925
   930
	by (cases s1) (auto dest: conforms_set_locals )
schirmer@12925
   931
      with wf cls_C 
schirmer@12925
   932
      have eval_init_c: "G\<turnstile>(set_lvars empty) s1 \<midarrow>init c\<rightarrow> s2"
schirmer@12925
   933
	by (auto intro!: hyp_init_c dest: wf_prog_cdecl wf_cdecl_wt_init)
schirmer@12925
   934
      from False eval_init_super eval_init_c s3
schirmer@12925
   935
      show ?thesis
schirmer@12925
   936
	by simp
schirmer@12925
   937
    qed
wenzelm@12937
   938
    with cls show ?case
schirmer@12925
   939
      by (rule eval.Init)
schirmer@12925
   940
  qed 
schirmer@12925
   941
qed
schirmer@12925
   942
schirmer@12925
   943
lemma Suc_le_D_lemma: "\<lbrakk>Suc n <= m'; (\<And>m. n <= m \<Longrightarrow> P (Suc m)) \<rbrakk> \<Longrightarrow> P m'"
schirmer@12925
   944
apply (frule Suc_le_D)
schirmer@12925
   945
apply fast
schirmer@12925
   946
done
schirmer@12925
   947
schirmer@12925
   948
lemma evaln_nonstrict [rule_format (no_asm), elim]: 
schirmer@12925
   949
  "\<And>ws. G\<turnstile>s \<midarrow>t\<succ>\<midarrow>n\<rightarrow> ws \<Longrightarrow> \<forall>m. n\<le>m \<longrightarrow> G\<turnstile>s \<midarrow>t\<succ>\<midarrow>m\<rightarrow> ws"
schirmer@12925
   950
apply (simp (no_asm_simp) only: split_tupled_all)
schirmer@12925
   951
apply (erule evaln.induct)
schirmer@12925
   952
apply (tactic {* ALLGOALS (EVERY'[strip_tac, TRY o etac (thm "Suc_le_D_lemma"),
schirmer@12925
   953
  REPEAT o smp_tac 1, 
schirmer@12925
   954
  resolve_tac (thms "evaln.intros") THEN_ALL_NEW TRY o atac]) *})
schirmer@12925
   955
(* 3 subgoals *)
schirmer@12925
   956
apply (auto split del: split_if)
schirmer@12925
   957
done
schirmer@12925
   958
schirmer@12925
   959
lemmas evaln_nonstrict_Suc = evaln_nonstrict [OF _ le_refl [THEN le_SucI]]
schirmer@12925
   960
schirmer@12925
   961
lemma evaln_max2: "\<lbrakk>G\<turnstile>s1 \<midarrow>t1\<succ>\<midarrow>n1\<rightarrow> ws1; G\<turnstile>s2 \<midarrow>t2\<succ>\<midarrow>n2\<rightarrow> ws2\<rbrakk> \<Longrightarrow> 
schirmer@12925
   962
             G\<turnstile>s1 \<midarrow>t1\<succ>\<midarrow>max n1 n2\<rightarrow> ws1 \<and> G\<turnstile>s2 \<midarrow>t2\<succ>\<midarrow>max n1 n2\<rightarrow> ws2"
schirmer@12925
   963
apply (fast intro: le_maxI1 le_maxI2)
schirmer@12925
   964
done
schirmer@12925
   965
schirmer@12925
   966
lemma evaln_max3: 
schirmer@12925
   967
"\<lbrakk>G\<turnstile>s1 \<midarrow>t1\<succ>\<midarrow>n1\<rightarrow> ws1; G\<turnstile>s2 \<midarrow>t2\<succ>\<midarrow>n2\<rightarrow> ws2; G\<turnstile>s3 \<midarrow>t3\<succ>\<midarrow>n3\<rightarrow> ws3\<rbrakk> \<Longrightarrow>
schirmer@12925
   968
 G\<turnstile>s1 \<midarrow>t1\<succ>\<midarrow>max (max n1 n2) n3\<rightarrow> ws1 \<and>
schirmer@12925
   969
 G\<turnstile>s2 \<midarrow>t2\<succ>\<midarrow>max (max n1 n2) n3\<rightarrow> ws2 \<and> 
schirmer@12925
   970
 G\<turnstile>s3 \<midarrow>t3\<succ>\<midarrow>max (max n1 n2) n3\<rightarrow> ws3"
schirmer@12925
   971
apply (drule (1) evaln_max2, erule thin_rl)
schirmer@12925
   972
apply (fast intro!: le_maxI1 le_maxI2)
schirmer@12925
   973
done
schirmer@12925
   974
schirmer@12925
   975
lemma le_max3I1: "(n2::nat) \<le> max n1 (max n2 n3)"
schirmer@12925
   976
proof -
schirmer@12925
   977
  have "n2 \<le> max n2 n3"
schirmer@12925
   978
    by (rule le_maxI1)
schirmer@12925
   979
  also
schirmer@12925
   980
  have "max n2 n3 \<le> max n1 (max n2 n3)"
schirmer@12925
   981
    by (rule le_maxI2)
schirmer@12925
   982
  finally
schirmer@12925
   983
  show ?thesis .
schirmer@12925
   984
qed
schirmer@12925
   985
schirmer@12925
   986
lemma le_max3I2: "(n3::nat) \<le> max n1 (max n2 n3)"
schirmer@12925
   987
proof -
schirmer@12925
   988
  have "n3 \<le> max n2 n3"
schirmer@12925
   989
    by (rule le_maxI2)
schirmer@12925
   990
  also
schirmer@12925
   991
  have "max n2 n3 \<le> max n1 (max n2 n3)"
schirmer@12925
   992
    by (rule le_maxI2)
schirmer@12925
   993
  finally
schirmer@12925
   994
  show ?thesis .
schirmer@12925
   995
qed
schirmer@12925
   996
wenzelm@12937
   997
text {* *} (* FIXME *)
schirmer@12925
   998
schirmer@12925
   999
lemma eval_evaln: 
wenzelm@12937
  1000
  assumes eval: "G\<turnstile>s0 \<midarrow>t\<succ>\<rightarrow> (v,s1)" and
wenzelm@12937
  1001
            wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T" and  
wenzelm@12937
  1002
       conf_s0: "s0\<Colon>\<preceq>(G, L)" and
wenzelm@12937
  1003
            wf: "wf_prog G"  
wenzelm@12937
  1004
  shows  "\<exists>n. G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1)"
schirmer@12925
  1005
proof -
schirmer@12925
  1006
  from eval 
schirmer@12925
  1007
  show "\<And> L accC T. \<lbrakk>s0\<Colon>\<preceq>(G, L);\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>t\<Colon>T\<rbrakk>
schirmer@12925
  1008
                     \<Longrightarrow> \<exists> n. G\<turnstile>s0 \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (v,s1)"
schirmer@12925
  1009
       (is "PROP ?EqEval s0 s1 t v")
schirmer@12925
  1010
  proof (induct)
schirmer@12925
  1011
    case (Abrupt s t xc L accC T)
schirmer@12925
  1012
    obtain n where
schirmer@12925
  1013
      "G\<turnstile>(Some xc, s) \<midarrow>t\<succ>\<midarrow>n\<rightarrow> (arbitrary3 t, Some xc, s)"
schirmer@12925
  1014
      by (rules intro: evaln.Abrupt)
schirmer@12925
  1015
    then show ?case ..
schirmer@12925
  1016
  next
schirmer@12925
  1017
    case Skip
schirmer@12925
  1018
    show ?case by (blast intro: evaln.Skip)
schirmer@12925
  1019
  next
schirmer@12925
  1020
    case (Expr e s0 s1 v L accC T)
schirmer@12925
  1021
    then obtain n where
schirmer@12925
  1022
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1023
      by (rules elim!: wt_elim_cases)
schirmer@12925
  1024
    then have "G\<turnstile>Norm s0 \<midarrow>Expr e\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1025
      by (rule evaln.Expr) 
schirmer@12925
  1026
    then show ?case ..
schirmer@12925
  1027
  next
schirmer@12925
  1028
    case (Lab c l s0 s1 L accC T)
schirmer@12925
  1029
    then obtain n where
schirmer@12925
  1030
      "G\<turnstile>Norm s0 \<midarrow>c\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1031
      by (rules elim!: wt_elim_cases)
schirmer@12925
  1032
    then have "G\<turnstile>Norm s0 \<midarrow>l\<bullet> c\<midarrow>n\<rightarrow> abupd (absorb (Break l)) s1"
schirmer@12925
  1033
      by (rule evaln.Lab)
schirmer@12925
  1034
    then show ?case ..
schirmer@12925
  1035
  next
schirmer@12925
  1036
    case (Comp c1 c2 s0 s1 s2 L accC T)
schirmer@12925
  1037
    with wf obtain n1 n2 where
schirmer@12925
  1038
      "G\<turnstile>Norm s0 \<midarrow>c1\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1039
      "G\<turnstile>s1 \<midarrow>c2\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1040
      by (blast elim!: wt_elim_cases dest: eval_type_sound)
schirmer@12925
  1041
    then have "G\<turnstile>Norm s0 \<midarrow>c1;; c2\<midarrow>max n1 n2\<rightarrow> s2"
schirmer@12925
  1042
      by (blast intro: evaln.Comp dest: evaln_max2 )
schirmer@12925
  1043
    then show ?case ..
schirmer@12925
  1044
  next
schirmer@12925
  1045
    case (If b c1 c2 e s0 s1 s2 L accC T)
schirmer@12925
  1046
    with wf obtain
schirmer@12925
  1047
      "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-PrimT Boolean"
schirmer@12925
  1048
      "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>(if the_Bool b then c1 else c2)\<Colon>\<surd>"
schirmer@12925
  1049
      by (cases "the_Bool b") (auto elim!: wt_elim_cases)
schirmer@12925
  1050
    with If wf obtain n1 n2 where
schirmer@12925
  1051
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1052
      "G\<turnstile>s1 \<midarrow>(if the_Bool b then c1 else c2)\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1053
      by (blast dest: eval_type_sound)
schirmer@12925
  1054
    then have "G\<turnstile>Norm s0 \<midarrow>If(e) c1 Else c2\<midarrow>max n1 n2\<rightarrow> s2"
schirmer@12925
  1055
      by (blast intro: evaln.If dest: evaln_max2)
schirmer@12925
  1056
    then show ?case ..
schirmer@12925
  1057
  next
schirmer@12925
  1058
    case (Loop b c e l s0 s1 s2 s3 L accC T)
schirmer@12925
  1059
    have eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<rightarrow> s1" .
schirmer@12925
  1060
    have hyp_e: "PROP ?EqEval (Norm s0) s1 (In1l e) (In1 b)" .
schirmer@12925
  1061
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
  1062
    have      wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (l\<bullet> While(e) c)\<Colon>T" .
schirmer@12925
  1063
    then obtain wt_e: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e\<Colon>-PrimT Boolean" and
schirmer@12925
  1064
                wt_c: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>c\<Colon>\<surd>"
schirmer@12925
  1065
      by (rule wt_elim_cases) (blast)
schirmer@12925
  1066
    from conf_s0 wt_e 
schirmer@12925
  1067
    obtain n1 where
schirmer@12925
  1068
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>b\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1069
      by (rules dest: hyp_e)
schirmer@12925
  1070
    moreover
schirmer@12925
  1071
    from eval_e wt_e conf_s0 wf
schirmer@12925
  1072
    have conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
  1073
      by (rules dest: eval_type_sound)
schirmer@12925
  1074
    obtain n2 where
schirmer@12925
  1075
      "if normal s1 \<and> the_Bool b 
schirmer@12925
  1076
             then (G\<turnstile>s1 \<midarrow>c\<midarrow>n2\<rightarrow> s2 \<and> 
schirmer@12925
  1077
                   G\<turnstile>(abupd (absorb (Cont l)) s2)\<midarrow>l\<bullet> While(e) c\<midarrow>n2\<rightarrow> s3)
schirmer@12925
  1078
	     else s3 = s1"
schirmer@12925
  1079
    proof (cases "normal s1 \<and> the_Bool b")
schirmer@12925
  1080
      case True
schirmer@12925
  1081
      from Loop True have hyp_c: "PROP ?EqEval s1 s2 (In1r c) \<diamondsuit>"
schirmer@12925
  1082
	by (auto)
schirmer@12925
  1083
      from Loop True have hyp_w: "PROP ?EqEval (abupd (absorb (Cont l)) s2)
schirmer@12925
  1084
                                        s3 (In1r (l\<bullet> While(e) c)) \<diamondsuit>"
schirmer@12925
  1085
	by (auto)
schirmer@12925
  1086
      from Loop True have eval_c: "G\<turnstile>s1 \<midarrow>c\<rightarrow> s2"
schirmer@12925
  1087
	by simp
schirmer@12925
  1088
      from conf_s1 wt_c
schirmer@12925
  1089
      obtain m1 where 
schirmer@12925
  1090
	evaln_c: "G\<turnstile>s1 \<midarrow>c\<midarrow>m1\<rightarrow> s2"
schirmer@12925
  1091
	by (rules dest: hyp_c)
schirmer@12925
  1092
      moreover
schirmer@12925
  1093
      from eval_c conf_s1 wt_c wf
schirmer@12925
  1094
      have "s2\<Colon>\<preceq>(G, L)"
schirmer@12925
  1095
	by (rules dest: eval_type_sound)
schirmer@12925
  1096
      then
schirmer@12925
  1097
      have "abupd (absorb (Cont l)) s2 \<Colon>\<preceq>(G, L)"
schirmer@12925
  1098
	by (cases s2) (auto intro: conforms_absorb)
schirmer@12925
  1099
      from this and wt
schirmer@12925
  1100
      obtain m2 where 
schirmer@12925
  1101
	"G\<turnstile>abupd (absorb (Cont l)) s2 \<midarrow>l\<bullet> While(e) c\<midarrow>m2\<rightarrow> s3"
schirmer@12925
  1102
	by (blast dest: hyp_w)
schirmer@12925
  1103
      moreover note True and that
schirmer@12925
  1104
      ultimately show ?thesis
schirmer@12925
  1105
	by simp (rules intro: evaln_nonstrict le_maxI1 le_maxI2)
schirmer@12925
  1106
    next
schirmer@12925
  1107
      case False
schirmer@12925
  1108
      with Loop have "s3 = s1"
schirmer@12925
  1109
	by simp
schirmer@12925
  1110
      with False that
schirmer@12925
  1111
      show ?thesis
schirmer@12925
  1112
	by auto 
schirmer@12925
  1113
    qed
schirmer@12925
  1114
    ultimately
schirmer@12925
  1115
    have "G\<turnstile>Norm s0 \<midarrow>l\<bullet> While(e) c\<midarrow>max n1 n2\<rightarrow> s3"
schirmer@12925
  1116
      apply -
schirmer@12925
  1117
      apply (rule evaln.Loop)
schirmer@12925
  1118
      apply   (rules intro: evaln_nonstrict intro: le_maxI1)
schirmer@12925
  1119
schirmer@12925
  1120
      apply   (auto intro: evaln_nonstrict intro: le_maxI2)
schirmer@12925
  1121
      done
schirmer@12925
  1122
    then show ?case ..
schirmer@12925
  1123
  next
schirmer@12925
  1124
    case (Do j s L accC T)
schirmer@12925
  1125
    have "G\<turnstile>Norm s \<midarrow>Do j\<midarrow>n\<rightarrow> (Some (Jump j), s)"
schirmer@12925
  1126
      by (rule evaln.Do)
schirmer@12925
  1127
    then show ?case ..
schirmer@12925
  1128
  next
schirmer@12925
  1129
    case (Throw a e s0 s1 L accC T)
schirmer@12925
  1130
    then obtain n where
schirmer@12925
  1131
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1132
      by (rules elim!: wt_elim_cases)
schirmer@12925
  1133
    then have "G\<turnstile>Norm s0 \<midarrow>Throw e\<midarrow>n\<rightarrow> abupd (throw a) s1"
schirmer@12925
  1134
      by (rule evaln.Throw)
schirmer@12925
  1135
    then show ?case ..
schirmer@12925
  1136
  next 
schirmer@12925
  1137
    case (Try catchC c1 c2 s0 s1 s2 s3 vn L accC T)
schirmer@12925
  1138
    have  hyp_c1: "PROP ?EqEval (Norm s0) s1 (In1r c1) \<diamondsuit>" .
schirmer@12925
  1139
    have eval_c1: "G\<turnstile>Norm s0 \<midarrow>c1\<rightarrow> s1" .
schirmer@12925
  1140
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
  1141
    have      wt: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>In1r (Try c1 Catch(catchC vn) c2)\<Colon>T" .
schirmer@12925
  1142
    then obtain 
schirmer@12925
  1143
      wt_c1: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<turnstile>c1\<Colon>\<surd>" and
schirmer@12925
  1144
      wt_c2: "\<lparr>prg=G,cls=accC,lcl=L\<rparr>\<lparr>lcl := L(VName vn\<mapsto>Class catchC)\<rparr>\<turnstile>c2\<Colon>\<surd>"
schirmer@12925
  1145
      by (rule wt_elim_cases) (auto)
schirmer@12925
  1146
    from conf_s0 wt_c1
schirmer@12925
  1147
    obtain n1 where
schirmer@12925
  1148
      "G\<turnstile>Norm s0 \<midarrow>c1\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1149
      by (blast dest: hyp_c1)
schirmer@12925
  1150
    moreover 
schirmer@12925
  1151
    have sxalloc: "G\<turnstile>s1 \<midarrow>sxalloc\<rightarrow> s2" .
schirmer@12925
  1152
    moreover
schirmer@12925
  1153
    from eval_c1 wt_c1 conf_s0 wf
schirmer@12925
  1154
    have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
  1155
      by (blast dest: eval_type_sound)
schirmer@12925
  1156
    with sxalloc wf
schirmer@12925
  1157
    have conf_s2: "s2\<Colon>\<preceq>(G, L)" 
schirmer@12925
  1158
      by (auto dest: sxalloc_type_sound split: option.splits)
schirmer@12925
  1159
    obtain n2 where
schirmer@12925
  1160
      "if G,s2\<turnstile>catch catchC then G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<midarrow>n2\<rightarrow> s3 else s3 = s2"
schirmer@12925
  1161
    proof (cases "G,s2\<turnstile>catch catchC")
schirmer@12925
  1162
      case True
schirmer@12925
  1163
      note Catch = this
schirmer@12925
  1164
      with Try have hyp_c2: "PROP ?EqEval (new_xcpt_var vn s2) s3 (In1r c2) \<diamondsuit>"
schirmer@12925
  1165
	by auto
schirmer@12925
  1166
      show ?thesis
schirmer@12925
  1167
      proof (cases "normal s1")
schirmer@12925
  1168
	case True
schirmer@12925
  1169
	with sxalloc wf 
schirmer@12925
  1170
	have eq_s2_s1: "s2=s1"
schirmer@12925
  1171
	  by (auto dest: sxalloc_type_sound split: option.splits)
schirmer@12925
  1172
	with True 
schirmer@12925
  1173
	have "\<not>  G,s2\<turnstile>catch catchC"
schirmer@12925
  1174
	  by (simp add: catch_def)
schirmer@12925
  1175
	with Catch show ?thesis 
schirmer@12925
  1176
	  by (contradiction)
schirmer@12925
  1177
      next 
schirmer@12925
  1178
	case False
schirmer@12925
  1179
	with sxalloc wf
schirmer@12925
  1180
	obtain a 
schirmer@12925
  1181
	  where xcpt_s2: "abrupt s2 = Some (Xcpt (Loc a))"
schirmer@12925
  1182
	  by (auto dest!: sxalloc_type_sound split: option.splits)
schirmer@12925
  1183
	with Catch
schirmer@12925
  1184
	have "G\<turnstile>obj_ty (the (globs (store s2) (Heap a)))\<preceq>Class catchC"
schirmer@12925
  1185
	  by (cases s2) simp
schirmer@12925
  1186
	with xcpt_s2 conf_s2 wf 
schirmer@12925
  1187
	have "new_xcpt_var vn s2\<Colon>\<preceq>(G, L(VName vn\<mapsto>Class catchC))"
schirmer@12925
  1188
	  by (auto dest: Try_lemma)
wenzelm@12937
  1189
	(* FIXME extract lemma for this conformance, also useful for
schirmer@12925
  1190
               eval_type_sound and evaln_eval *)
schirmer@12925
  1191
	from this wt_c2
schirmer@12925
  1192
	obtain m where "G\<turnstile>new_xcpt_var vn s2 \<midarrow>c2\<midarrow>m\<rightarrow> s3"
schirmer@12925
  1193
	  by (auto dest: hyp_c2)
schirmer@12925
  1194
	with True that
schirmer@12925
  1195
	show ?thesis
schirmer@12925
  1196
	  by simp
schirmer@12925
  1197
      qed
schirmer@12925
  1198
    next
schirmer@12925
  1199
      case False
schirmer@12925
  1200
      with Try
schirmer@12925
  1201
      have "s3=s2"
schirmer@12925
  1202
	by simp
schirmer@12925
  1203
      with False and that
schirmer@12925
  1204
      show ?thesis
schirmer@12925
  1205
	by simp
schirmer@12925
  1206
    qed
schirmer@12925
  1207
    ultimately
schirmer@12925
  1208
    have "G\<turnstile>Norm s0 \<midarrow>Try c1 Catch(catchC vn) c2\<midarrow>max n1 n2\<rightarrow> s3"
schirmer@12925
  1209
      by (auto intro!: evaln.Try le_maxI1 le_maxI2)
schirmer@12925
  1210
    then show ?case ..
schirmer@12925
  1211
  next
schirmer@12925
  1212
    case (Fin c1 c2 s0 s1 s2 x1 L accC T)
schirmer@12925
  1213
    with wf obtain n1 n2 where 
schirmer@12925
  1214
      "G\<turnstile>Norm s0 \<midarrow>c1\<midarrow>n1\<rightarrow> (x1, s1)"
schirmer@12925
  1215
      "G\<turnstile>Norm s1 \<midarrow>c2\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1216
      by (blast elim!: wt_elim_cases 
schirmer@12925
  1217
	         dest: eval_type_sound intro: conforms_NormI)
schirmer@12925
  1218
    then have 
schirmer@12925
  1219
     "G\<turnstile>Norm s0 \<midarrow>c1 Finally c2\<midarrow>max n1 n2\<rightarrow> abupd (abrupt_if (x1 \<noteq> None) x1) s2"
schirmer@12925
  1220
      by (blast intro: evaln.Fin dest: evaln_max2)
schirmer@12925
  1221
    then show ?case ..
schirmer@12925
  1222
  next
schirmer@12925
  1223
    case (Init C c s0 s1 s2 s3 L accC T)
schirmer@12925
  1224
    have     cls: "the (class G C) = c" .
schirmer@12925
  1225
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
  1226
    have      wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1r (Init C)\<Colon>T" .
schirmer@12925
  1227
    with cls
schirmer@12925
  1228
    have cls_C: "class G C = Some c"
schirmer@12925
  1229
      by - (erule wt_elim_cases,auto)
schirmer@12925
  1230
    obtain n where
schirmer@12925
  1231
      "if inited C (globs s0) then s3 = Norm s0
schirmer@12925
  1232
       else (G\<turnstile>Norm (init_class_obj G C s0)
schirmer@12925
  1233
	      \<midarrow>(if C = Object then Skip else Init (super c))\<midarrow>n\<rightarrow> s1 \<and>
schirmer@12925
  1234
	           G\<turnstile>set_lvars empty s1 \<midarrow>init c\<midarrow>n\<rightarrow> s2 \<and> 
schirmer@12925
  1235
                   s3 = restore_lvars s1 s2)"
schirmer@12925
  1236
    proof (cases "inited C (globs s0)")
schirmer@12925
  1237
      case True
schirmer@12925
  1238
      with Init have "s3 = Norm s0"
schirmer@12925
  1239
	by simp
schirmer@12925
  1240
      with True that show ?thesis 
schirmer@12925
  1241
	by simp
schirmer@12925
  1242
    next
schirmer@12925
  1243
      case False
schirmer@12925
  1244
      with Init
schirmer@12925
  1245
      obtain 
schirmer@12925
  1246
	hyp_init_super: 
schirmer@12925
  1247
        "PROP ?EqEval (Norm ((init_class_obj G C) s0)) s1
schirmer@12925
  1248
	               (In1r (if C = Object then Skip else Init (super c))) \<diamondsuit>"
schirmer@12925
  1249
	and 
schirmer@12925
  1250
        hyp_init_c:
schirmer@12925
  1251
	   "PROP ?EqEval ((set_lvars empty) s1) s2 (In1r (init c)) \<diamondsuit>" and
schirmer@12925
  1252
	s3: "s3 = (set_lvars (locals (store s1))) s2" and
schirmer@12925
  1253
	eval_init_super: 
schirmer@12925
  1254
	"G\<turnstile>Norm ((init_class_obj G C) s0) 
schirmer@12925
  1255
           \<midarrow>(if C = Object then Skip else Init (super c))\<rightarrow> s1"
schirmer@12925
  1256
	by (simp only: if_False)
schirmer@12925
  1257
      from conf_s0 wf cls_C False
schirmer@12925
  1258
      have conf_s0': "(Norm ((init_class_obj G C) s0))\<Colon>\<preceq>(G, L)"
schirmer@12925
  1259
	by (auto dest: conforms_init_class_obj)
schirmer@12925
  1260
      moreover
schirmer@12925
  1261
      from wf cls_C 
schirmer@12925
  1262
      have wt_init_super:
schirmer@12925
  1263
           "\<lparr>prg = G, cls = accC, lcl = L\<rparr>
schirmer@12925
  1264
                  \<turnstile>(if C = Object then Skip else Init (super c))\<Colon>\<surd>"
schirmer@12925
  1265
	by (cases "C=Object")
schirmer@12925
  1266
           (auto dest: wf_prog_cdecl wf_cdecl_supD is_acc_classD)
schirmer@12925
  1267
      ultimately
schirmer@12925
  1268
      obtain m1 where  
schirmer@12925
  1269
	   "G\<turnstile>Norm ((init_class_obj G C) s0) 
schirmer@12925
  1270
            \<midarrow>(if C = Object then Skip else Init (super c))\<midarrow>m1\<rightarrow> s1"
schirmer@12925
  1271
	by (rules dest: hyp_init_super)
schirmer@12925
  1272
      moreover
schirmer@12925
  1273
      from eval_init_super conf_s0' wt_init_super wf
schirmer@12925
  1274
      have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
  1275
	by (rules dest: eval_type_sound)
schirmer@12925
  1276
      then
schirmer@12925
  1277
      have "(set_lvars empty) s1\<Colon>\<preceq>(G, empty)"
schirmer@12925
  1278
	by (cases s1) (auto dest: conforms_set_locals )
schirmer@12925
  1279
      with wf cls_C 
schirmer@12925
  1280
      obtain m2 where
schirmer@12925
  1281
	"G\<turnstile>(set_lvars empty) s1 \<midarrow>init c\<midarrow>m2\<rightarrow> s2"
schirmer@12925
  1282
	by (blast dest!: hyp_init_c 
schirmer@12925
  1283
                   dest: wf_prog_cdecl intro!: wf_cdecl_wt_init)
schirmer@12925
  1284
      moreover note s3 and False and that
schirmer@12925
  1285
      ultimately show ?thesis
schirmer@12925
  1286
	by simp (rules intro: evaln_nonstrict le_maxI1 le_maxI2)
schirmer@12925
  1287
    qed
schirmer@12925
  1288
    from cls this have "G\<turnstile>Norm s0 \<midarrow>Init C\<midarrow>n\<rightarrow> s3"
schirmer@12925
  1289
      by (rule evaln.Init)
schirmer@12925
  1290
    then show ?case ..
schirmer@12925
  1291
  next
schirmer@12925
  1292
    case (NewC C a s0 s1 s2 L accC T)
schirmer@12925
  1293
    with wf obtain n where 
schirmer@12925
  1294
     "G\<turnstile>Norm s0 \<midarrow>Init C\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1295
      by (blast elim!: wt_elim_cases dest: is_acc_classD)
schirmer@12925
  1296
    with NewC 
schirmer@12925
  1297
    have "G\<turnstile>Norm s0 \<midarrow>NewC C-\<succ>Addr a\<midarrow>n\<rightarrow> s2"
schirmer@12925
  1298
      by (rules intro: evaln.NewC)
schirmer@12925
  1299
    then show ?case ..
schirmer@12925
  1300
  next
schirmer@12925
  1301
    case (NewA T a e i s0 s1 s2 s3 L accC Ta)
schirmer@12925
  1302
    hence "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>init_comp_ty T\<Colon>\<surd>" 
schirmer@12925
  1303
      by (auto elim!: wt_elim_cases 
schirmer@12925
  1304
              intro!: wt_init_comp_ty dest: is_acc_typeD)
schirmer@12925
  1305
    with NewA wf obtain n1 n2 where 
schirmer@12925
  1306
      "G\<turnstile>Norm s0 \<midarrow>init_comp_ty T\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1307
      "G\<turnstile>s1 \<midarrow>e-\<succ>i\<midarrow>n2\<rightarrow> s2"      
schirmer@12925
  1308
      by (blast elim!: wt_elim_cases dest: eval_type_sound)
schirmer@12925
  1309
    moreover
schirmer@12925
  1310
    have "G\<turnstile>abupd (check_neg i) s2 \<midarrow>halloc Arr T (the_Intg i)\<succ>a\<rightarrow> s3" .
schirmer@12925
  1311
    ultimately
schirmer@12925
  1312
    have "G\<turnstile>Norm s0 \<midarrow>New T[e]-\<succ>Addr a\<midarrow>max n1 n2\<rightarrow> s3"
schirmer@12925
  1313
      by (blast intro: evaln.NewA dest: evaln_max2)
schirmer@12925
  1314
    then show ?case ..
schirmer@12925
  1315
  next
schirmer@12925
  1316
    case (Cast castT e s0 s1 s2 v L accC T)
schirmer@12925
  1317
    with wf obtain n where
schirmer@12925
  1318
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1319
      by (rules elim!: wt_elim_cases)
schirmer@12925
  1320
    moreover 
schirmer@12925
  1321
    have "s2 = abupd (raise_if (\<not> G,snd s1\<turnstile>v fits castT) ClassCast) s1" .
schirmer@12925
  1322
    ultimately
schirmer@12925
  1323
    have "G\<turnstile>Norm s0 \<midarrow>Cast castT e-\<succ>v\<midarrow>n\<rightarrow> s2"
schirmer@12925
  1324
      by (rule evaln.Cast)
schirmer@12925
  1325
    then show ?case ..
schirmer@12925
  1326
  next
schirmer@12925
  1327
    case (Inst T b e s0 s1 v L accC T')
schirmer@12925
  1328
    with wf obtain n where
schirmer@12925
  1329
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1330
      by (rules elim!: wt_elim_cases)
schirmer@12925
  1331
    moreover 
schirmer@12925
  1332
    have "b = (v \<noteq> Null \<and> G,snd s1\<turnstile>v fits RefT T)" .
schirmer@12925
  1333
    ultimately
schirmer@12925
  1334
    have "G\<turnstile>Norm s0 \<midarrow>e InstOf T-\<succ>Bool b\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1335
      by (rule evaln.Inst)
schirmer@12925
  1336
    then show ?case ..
schirmer@12925
  1337
  next
schirmer@12925
  1338
    case (Lit s v L accC T)
schirmer@12925
  1339
    have "G\<turnstile>Norm s \<midarrow>Lit v-\<succ>v\<midarrow>n\<rightarrow> Norm s"
schirmer@12925
  1340
      by (rule evaln.Lit)
schirmer@12925
  1341
    then show ?case ..
schirmer@12925
  1342
  next
schirmer@12925
  1343
    case (Super s L accC T)
schirmer@12925
  1344
    have "G\<turnstile>Norm s \<midarrow>Super-\<succ>val_this s\<midarrow>n\<rightarrow> Norm s"
schirmer@12925
  1345
      by (rule evaln.Super)
schirmer@12925
  1346
    then show ?case ..
schirmer@12925
  1347
  next
schirmer@12925
  1348
    case (Acc f s0 s1 v va L accC T)
schirmer@12925
  1349
    with wf obtain n where
schirmer@12925
  1350
      "G\<turnstile>Norm s0 \<midarrow>va=\<succ>(v, f)\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1351
      by (rules elim!: wt_elim_cases)
schirmer@12925
  1352
    then
schirmer@12925
  1353
    have "G\<turnstile>Norm s0 \<midarrow>Acc va-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1354
      by (rule evaln.Acc)
schirmer@12925
  1355
    then show ?case ..
schirmer@12925
  1356
  next
schirmer@12925
  1357
    case (Ass e f s0 s1 s2 v var w L accC T)
schirmer@12925
  1358
    with wf obtain n1 n2 where 
schirmer@12925
  1359
      "G\<turnstile>Norm s0 \<midarrow>var=\<succ>(w, f)\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1360
      "G\<turnstile>s1 \<midarrow>e-\<succ>v\<midarrow>n2\<rightarrow> s2"      
schirmer@12925
  1361
      by (blast elim!: wt_elim_cases dest: eval_type_sound)
schirmer@12925
  1362
    then
schirmer@12925
  1363
    have "G\<turnstile>Norm s0 \<midarrow>var:=e-\<succ>v\<midarrow>max n1 n2\<rightarrow> assign f v s2"
schirmer@12925
  1364
      by (blast intro: evaln.Ass dest: evaln_max2)
schirmer@12925
  1365
    then show ?case ..
schirmer@12925
  1366
  next
schirmer@12925
  1367
    case (Cond b e0 e1 e2 s0 s1 s2 v L accC T)
schirmer@12925
  1368
    have hyp_e0: "PROP ?EqEval (Norm s0) s1 (In1l e0) (In1 b)" .
schirmer@12925
  1369
    have hyp_if: "PROP ?EqEval s1 s2 
schirmer@12925
  1370
                              (In1l (if the_Bool b then e1 else e2)) (In1 v)" .
schirmer@12925
  1371
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
  1372
    have wt: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>In1l (e0 ? e1 : e2)\<Colon>T" .
schirmer@12925
  1373
    then obtain T1 T2 statT where
schirmer@12925
  1374
       wt_e0: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e0\<Colon>-PrimT Boolean" and
schirmer@12925
  1375
       wt_e1: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e1\<Colon>-T1" and
schirmer@12925
  1376
       wt_e2: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>e2\<Colon>-T2" and 
schirmer@12925
  1377
       statT: "G\<turnstile>T1\<preceq>T2 \<and> statT = T2  \<or>  G\<turnstile>T2\<preceq>T1 \<and> statT =  T1" and
schirmer@12925
  1378
       T    : "T=Inl statT"
schirmer@12925
  1379
      by (rule wt_elim_cases) auto
schirmer@12925
  1380
    have eval_e0: "G\<turnstile>Norm s0 \<midarrow>e0-\<succ>b\<rightarrow> s1" .
schirmer@12925
  1381
    from conf_s0 wt_e0
schirmer@12925
  1382
    obtain n1 where 
schirmer@12925
  1383
      "G\<turnstile>Norm s0 \<midarrow>e0-\<succ>b\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1384
      by (rules dest: hyp_e0)
schirmer@12925
  1385
    moreover
schirmer@12925
  1386
    from eval_e0 conf_s0 wf wt_e0
schirmer@12925
  1387
    have "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
  1388
      by (blast dest: eval_type_sound)
schirmer@12925
  1389
    with wt_e1 wt_e2 statT hyp_if obtain n2 where
schirmer@12925
  1390
      "G\<turnstile>s1 \<midarrow>(if the_Bool b then e1 else e2)-\<succ>v\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1391
      by  (cases "the_Bool b") force+
schirmer@12925
  1392
    ultimately
schirmer@12925
  1393
    have "G\<turnstile>Norm s0 \<midarrow>e0 ? e1 : e2-\<succ>v\<midarrow>max n1 n2\<rightarrow> s2"
schirmer@12925
  1394
      by (blast intro: evaln.Cond dest: evaln_max2)
schirmer@12925
  1395
    then show ?case ..
schirmer@12925
  1396
  next
schirmer@12925
  1397
    case (Call invDeclC a' accC' args e mn mode pTs' s0 s1 s2 s3 s3' s4 statT 
schirmer@12925
  1398
      v vs L accC T)
schirmer@12925
  1399
    (* Repeats large parts of the type soundness proof. One should factor
schirmer@12925
  1400
       out some lemmata about the relations and conformance of s2, s3 and s3'*)
schirmer@12925
  1401
    have eval_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<rightarrow> s1" .
schirmer@12925
  1402
    have eval_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<rightarrow> s2" .
schirmer@12925
  1403
    have invDeclC: "invDeclC 
schirmer@12925
  1404
                      = invocation_declclass G mode (store s2) a' statT 
schirmer@12925
  1405
                           \<lparr>name = mn, parTs = pTs'\<rparr>" .
schirmer@12925
  1406
    have
schirmer@12925
  1407
      init_lvars: "s3 = 
schirmer@12925
  1408
             init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> mode a' vs s2" .
schirmer@12925
  1409
    have
schirmer@12925
  1410
      check: "s3' =
schirmer@12925
  1411
       check_method_access G accC' statT mode \<lparr>name = mn, parTs = pTs'\<rparr> a' s3" .
schirmer@12925
  1412
    have eval_methd: 
schirmer@12925
  1413
           "G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<rightarrow> s4" .
schirmer@12925
  1414
    have     hyp_e: "PROP ?EqEval (Norm s0) s1 (In1l e) (In1 a')" .
schirmer@12925
  1415
    have  hyp_args: "PROP ?EqEval s1 s2 (In3 args) (In3 vs)" .
schirmer@12925
  1416
    have hyp_methd: "PROP ?EqEval s3' s4 
schirmer@12925
  1417
                     (In1l (Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>)) (In1 v)".
schirmer@12925
  1418
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
  1419
    have      wt: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>
schirmer@12925
  1420
                    \<turnstile>In1l ({accC',statT,mode}e\<cdot>mn( {pTs'}args))\<Colon>T" .
schirmer@12925
  1421
    from wt obtain pTs statDeclT statM where
schirmer@12925
  1422
                 wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-RefT statT" and
schirmer@12925
  1423
              wt_args: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>args\<Colon>\<doteq>pTs" and
schirmer@12925
  1424
                statM: "max_spec G accC statT \<lparr>name=mn,parTs=pTs\<rparr> 
schirmer@12925
  1425
                         = {((statDeclT,statM),pTs')}" and
schirmer@12925
  1426
                 mode: "mode = invmode statM e" and
schirmer@12925
  1427
                    T: "T =Inl (resTy statM)" and
schirmer@12925
  1428
        eq_accC_accC': "accC=accC'"
schirmer@12925
  1429
      by (rule wt_elim_cases) auto
schirmer@12925
  1430
    from conf_s0 wt_e
schirmer@12925
  1431
    obtain n1 where
schirmer@12925
  1432
      evaln_e: "G\<turnstile>Norm s0 \<midarrow>e-\<succ>a'\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1433
      by (rules dest: hyp_e)
schirmer@12925
  1434
    from wf eval_e conf_s0 wt_e
schirmer@12925
  1435
    obtain conf_s1: "s1\<Colon>\<preceq>(G, L)" and
schirmer@12925
  1436
           conf_a': "normal s1 \<Longrightarrow> G, store s1\<turnstile>a'\<Colon>\<preceq>RefT statT"  
schirmer@12925
  1437
      by (auto dest!: eval_type_sound)
schirmer@12925
  1438
    from conf_s1 wt_args
schirmer@12925
  1439
    obtain n2 where
schirmer@12925
  1440
      evaln_args: "G\<turnstile>s1 \<midarrow>args\<doteq>\<succ>vs\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1441
      by (blast dest: hyp_args)
schirmer@12925
  1442
    from wt_args conf_s1 eval_args wf 
schirmer@12925
  1443
    obtain    conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@12925
  1444
            conf_args: "normal s2 
schirmer@12925
  1445
                         \<Longrightarrow>  list_all2 (conf G (store s2)) vs pTs"  
schirmer@12925
  1446
      by (auto dest!: eval_type_sound)
schirmer@12925
  1447
    from statM 
schirmer@12925
  1448
    obtain
schirmer@12925
  1449
       statM': "(statDeclT,statM)\<in>mheads G accC statT \<lparr>name=mn,parTs=pTs'\<rparr>" and
schirmer@12925
  1450
       pTs_widen: "G\<turnstile>pTs[\<preceq>]pTs'"
schirmer@12925
  1451
      by (blast dest: max_spec2mheads)
schirmer@12925
  1452
    from check
schirmer@12925
  1453
    have eq_store_s3'_s3: "store s3'=store s3"
schirmer@12925
  1454
      by (cases s3) (simp add: check_method_access_def Let_def)
schirmer@12925
  1455
    obtain invC
schirmer@12925
  1456
      where invC: "invC = invocation_class mode (store s2) a' statT"
schirmer@12925
  1457
      by simp
schirmer@12925
  1458
    with init_lvars
schirmer@12925
  1459
    have invC': "invC = (invocation_class mode (store s3) a' statT)"
schirmer@12925
  1460
      by (cases s2,cases mode) (auto simp add: init_lvars_def2 )
schirmer@12925
  1461
    obtain n3 where
schirmer@12925
  1462
     "G\<turnstile>Norm s0 \<midarrow>{accC',statT,mode}e\<cdot>mn( {pTs'}args)-\<succ>v\<midarrow>n3\<rightarrow> 
schirmer@12925
  1463
          (set_lvars (locals (store s2))) s4"
schirmer@12925
  1464
    proof (cases "normal s2")
schirmer@12925
  1465
      case False
schirmer@12925
  1466
      with init_lvars 
schirmer@12925
  1467
      obtain keep_abrupt: "abrupt s3 = abrupt s2" and
schirmer@12925
  1468
             "store s3 = store (init_lvars G invDeclC \<lparr>name = mn, parTs = pTs'\<rparr> 
schirmer@12925
  1469
                                            mode a' vs s2)" 
schirmer@12925
  1470
	by (auto simp add: init_lvars_def2)
schirmer@12925
  1471
      moreover
schirmer@12925
  1472
      from keep_abrupt False check
schirmer@12925
  1473
      have eq_s3'_s3: "s3'=s3" 
schirmer@12925
  1474
	by (auto simp add: check_method_access_def Let_def)
schirmer@12925
  1475
      moreover
schirmer@12925
  1476
      from eq_s3'_s3 False keep_abrupt eval_methd init_lvars
schirmer@12925
  1477
      obtain "s4=s3'"
schirmer@12925
  1478
	 "In1 v=arbitrary3 (In1l (Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>))"
schirmer@12925
  1479
	by auto
schirmer@12925
  1480
      moreover note False evaln.Abrupt
schirmer@12925
  1481
      ultimately obtain m where 
schirmer@12925
  1482
	"G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<midarrow>m\<rightarrow> s4"
schirmer@12925
  1483
	by force
schirmer@12925
  1484
      from evaln_e evaln_args invDeclC init_lvars eq_s3'_s3 this
schirmer@12925
  1485
      have 
schirmer@12925
  1486
       "G\<turnstile>Norm s0 \<midarrow>{accC',statT,mode}e\<cdot>mn( {pTs'}args)-\<succ>v\<midarrow>max n1 (max n2 m)\<rightarrow> 
schirmer@12925
  1487
            (set_lvars (locals (store s2))) s4"
schirmer@12925
  1488
	by (auto intro!: evaln.Call le_maxI1 le_max3I1 le_max3I2)
schirmer@12925
  1489
      with that show ?thesis 
schirmer@12925
  1490
	by rules
schirmer@12925
  1491
    next
schirmer@12925
  1492
      case True
schirmer@12925
  1493
      note normal_s2 = True
schirmer@12925
  1494
      with eval_args
schirmer@12925
  1495
      have normal_s1: "normal s1"
schirmer@12925
  1496
	by (cases "normal s1") auto
schirmer@12925
  1497
      with conf_a' eval_args 
schirmer@12925
  1498
      have conf_a'_s2: "G, store s2\<turnstile>a'\<Colon>\<preceq>RefT statT"
schirmer@12925
  1499
	by (auto dest: eval_gext intro: conf_gext)
schirmer@12925
  1500
      show ?thesis
schirmer@12925
  1501
      proof (cases "a'=Null \<longrightarrow> is_static statM")
schirmer@12925
  1502
	case False
schirmer@12925
  1503
	then obtain not_static: "\<not> is_static statM" and Null: "a'=Null" 
schirmer@12925
  1504
	  by blast
schirmer@12925
  1505
	with normal_s2 init_lvars mode
schirmer@12925
  1506
	obtain np: "abrupt s3 = Some (Xcpt (Std NullPointer))" and
schirmer@12925
  1507
                   "store s3 = store (init_lvars G invDeclC 
schirmer@12925
  1508
                                       \<lparr>name = mn, parTs = pTs'\<rparr> mode a' vs s2)"
schirmer@12925
  1509
	  by (auto simp add: init_lvars_def2)
schirmer@12925
  1510
	moreover
schirmer@12925
  1511
	from np check
schirmer@12925
  1512
	have eq_s3'_s3: "s3'=s3" 
schirmer@12925
  1513
	  by (auto simp add: check_method_access_def Let_def)
schirmer@12925
  1514
	moreover
schirmer@12925
  1515
	from eq_s3'_s3 np eval_methd init_lvars
schirmer@12925
  1516
	obtain "s4=s3'"
schirmer@12925
  1517
	  "In1 v=arbitrary3 (In1l (Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>))"
schirmer@12925
  1518
	  by auto
schirmer@12925
  1519
	moreover note np
schirmer@12925
  1520
	ultimately obtain m where 
schirmer@12925
  1521
	  "G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<midarrow>m\<rightarrow> s4"
schirmer@12925
  1522
	  by force
schirmer@12925
  1523
	from evaln_e evaln_args invDeclC init_lvars eq_s3'_s3 this
schirmer@12925
  1524
	have 
schirmer@12925
  1525
        "G\<turnstile>Norm s0 \<midarrow>{accC',statT,mode}e\<cdot>mn( {pTs'}args)-\<succ>v\<midarrow>max n1 (max n2 m)\<rightarrow> 
schirmer@12925
  1526
            (set_lvars (locals (store s2))) s4"
schirmer@12925
  1527
	  by (auto intro!: evaln.Call le_maxI1 le_max3I1 le_max3I2)
schirmer@12925
  1528
	with that show ?thesis 
schirmer@12925
  1529
	  by rules
schirmer@12925
  1530
      next
schirmer@12925
  1531
	case True
schirmer@12925
  1532
	with mode have notNull: "mode = IntVir \<longrightarrow> a' \<noteq> Null"
schirmer@12925
  1533
	  by (auto dest!: Null_staticD)
schirmer@12925
  1534
	with conf_s2 conf_a'_s2 wf invC 
schirmer@12925
  1535
	have dynT_prop: "G\<turnstile>mode\<rightarrow>invC\<preceq>statT"
schirmer@12925
  1536
	  by (cases s2) (auto intro: DynT_propI)
schirmer@12925
  1537
	with wt_e statM' invC mode wf 
schirmer@12925
  1538
	obtain dynM where 
schirmer@12925
  1539
           dynM: "dynlookup G statT invC  \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@12925
  1540
           acc_dynM: "G \<turnstile>Methd  \<lparr>name=mn,parTs=pTs'\<rparr> dynM 
schirmer@12925
  1541
                          in invC dyn_accessible_from accC"
schirmer@12925
  1542
	  by (force dest!: call_access_ok)
schirmer@12925
  1543
	with invC' check eq_accC_accC'
schirmer@12925
  1544
	have eq_s3'_s3: "s3'=s3"
schirmer@12925
  1545
	  by (auto simp add: check_method_access_def Let_def)
schirmer@12925
  1546
	from dynT_prop wf wt_e statM' mode invC invDeclC dynM 
schirmer@12925
  1547
	obtain 
schirmer@12925
  1548
	   wf_dynM: "wf_mdecl G invDeclC (\<lparr>name=mn,parTs=pTs'\<rparr>,mthd dynM)" and
schirmer@12925
  1549
	     dynM': "methd G invDeclC \<lparr>name=mn,parTs=pTs'\<rparr> = Some dynM" and
schirmer@12925
  1550
           iscls_invDeclC: "is_class G invDeclC" and
schirmer@12925
  1551
	        invDeclC': "invDeclC = declclass dynM" and
schirmer@12925
  1552
	     invC_widen: "G\<turnstile>invC\<preceq>\<^sub>C invDeclC" and
schirmer@12925
  1553
	   is_static_eq: "is_static dynM = is_static statM" and
schirmer@12925
  1554
	   involved_classes_prop:
schirmer@12925
  1555
             "(if invmode statM e = IntVir
schirmer@12925
  1556
               then \<forall>statC. statT = ClassT statC \<longrightarrow> G\<turnstile>invC\<preceq>\<^sub>C statC
schirmer@12925
  1557
               else ((\<exists>statC. statT = ClassT statC \<and> G\<turnstile>statC\<preceq>\<^sub>C invDeclC) \<or>
schirmer@12925
  1558
                     (\<forall>statC. statT \<noteq> ClassT statC \<and> invDeclC = Object)) \<and>
schirmer@12925
  1559
                      statDeclT = ClassT invDeclC)"
schirmer@12925
  1560
	  by (auto dest: DynT_mheadsD)
schirmer@12925
  1561
	obtain L' where 
schirmer@12925
  1562
	   L':"L'=(\<lambda> k. 
schirmer@12925
  1563
                 (case k of
schirmer@12925
  1564
                    EName e
schirmer@12925
  1565
                    \<Rightarrow> (case e of 
schirmer@12925
  1566
                          VNam v 
schirmer@12925
  1567
                          \<Rightarrow>(table_of (lcls (mbody (mthd dynM)))
schirmer@12925
  1568
                             (pars (mthd dynM)[\<mapsto>]pTs')) v
schirmer@12925
  1569
                        | Res \<Rightarrow> Some (resTy dynM))
schirmer@12925
  1570
                  | This \<Rightarrow> if is_static statM 
schirmer@12925
  1571
                            then None else Some (Class invDeclC)))"
schirmer@12925
  1572
	  by simp
schirmer@12925
  1573
	from wf_dynM [THEN wf_mdeclD1, THEN conjunct1] normal_s2 conf_s2 wt_e
schirmer@12925
  1574
              wf eval_args conf_a' mode notNull wf_dynM involved_classes_prop
schirmer@12925
  1575
	have conf_s3: "s3\<Colon>\<preceq>(G,L')"
schirmer@12925
  1576
	   apply - 
schirmer@12925
  1577
          (*FIXME confomrs_init_lvars should be 
schirmer@12925
  1578
                adjusted to be more directy applicable *)
schirmer@12925
  1579
	   apply (drule conforms_init_lvars [of G invDeclC 
schirmer@12925
  1580
                  "\<lparr>name=mn,parTs=pTs'\<rparr>" dynM "store s2" vs pTs "abrupt s2" 
schirmer@12925
  1581
                  L statT invC a' "(statDeclT,statM)" e])
schirmer@12925
  1582
	     apply (rule wf)
schirmer@12925
  1583
	     apply (rule conf_args,assumption)
schirmer@12925
  1584
	     apply (simp add: pTs_widen)
schirmer@12925
  1585
	     apply (cases s2,simp)
schirmer@12925
  1586
	     apply (rule dynM')
schirmer@12925
  1587
	     apply (force dest: ty_expr_is_type)
schirmer@12925
  1588
	     apply (rule invC_widen)
schirmer@12925
  1589
	     apply (force intro: conf_gext dest: eval_gext)
schirmer@12925
  1590
	     apply simp
schirmer@12925
  1591
	     apply simp
schirmer@12925
  1592
	     apply (simp add: invC)
schirmer@12925
  1593
	     apply (simp add: invDeclC)
schirmer@12925
  1594
	     apply (force dest: wf_mdeclD1 is_acc_typeD)
schirmer@12925
  1595
	     apply (cases s2, simp add: L' init_lvars
schirmer@12925
  1596
	                      cong add: lname.case_cong ename.case_cong)
schirmer@12925
  1597
	   done
schirmer@12925
  1598
	with is_static_eq wf_dynM L'
schirmer@12925
  1599
	obtain mthdT where
schirmer@12925
  1600
	   "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr>
schirmer@12925
  1601
            \<turnstile>Body invDeclC (stmt (mbody (mthd dynM)))\<Colon>-mthdT" 
schirmer@12925
  1602
	  by - (drule wf_mdecl_bodyD,
schirmer@12925
  1603
                simp cong add: lname.case_cong ename.case_cong)
schirmer@12925
  1604
	with dynM' iscls_invDeclC invDeclC'
schirmer@12925
  1605
	have
schirmer@12925
  1606
	   "\<lparr>prg=G,cls=invDeclC,lcl=L'\<rparr>
schirmer@12925
  1607
            \<turnstile>(Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>)\<Colon>-mthdT"
schirmer@12925
  1608
	  by (auto intro: wt.Methd)
schirmer@12925
  1609
	with conf_s3 eq_s3'_s3 hyp_methd
schirmer@12925
  1610
	obtain m where
schirmer@12925
  1611
	   "G\<turnstile>s3' \<midarrow>Methd invDeclC \<lparr>name = mn, parTs = pTs'\<rparr>-\<succ>v\<midarrow>m\<rightarrow> s4"
schirmer@12925
  1612
	  by (blast)
schirmer@12925
  1613
	from evaln_e evaln_args invDeclC init_lvars  eq_s3'_s3 this
schirmer@12925
  1614
	have 
schirmer@12925
  1615
        "G\<turnstile>Norm s0 \<midarrow>{accC',statT,mode}e\<cdot>mn( {pTs'}args)-\<succ>v\<midarrow>max n1 (max n2 m)\<rightarrow> 
schirmer@12925
  1616
            (set_lvars (locals (store s2))) s4"
schirmer@12925
  1617
	  by (auto intro!: evaln.Call le_maxI1 le_max3I1 le_max3I2)
schirmer@12925
  1618
	with that show ?thesis 
schirmer@12925
  1619
	  by rules
schirmer@12925
  1620
      qed
schirmer@12925
  1621
    qed
schirmer@12925
  1622
    then show ?case ..
schirmer@12925
  1623
  next
schirmer@12925
  1624
    case (Methd D s0 s1 sig v L accC T)
schirmer@12925
  1625
    then obtain n where
schirmer@12925
  1626
      "G\<turnstile>Norm s0 \<midarrow>body G D sig-\<succ>v\<midarrow>n\<rightarrow> s1"
schirmer@12925
  1627
      by - (erule wt_elim_cases, force simp add: body_def2)
schirmer@12925
  1628
    then have "G\<turnstile>Norm s0 \<midarrow>Methd D sig-\<succ>v\<midarrow>Suc n\<rightarrow> s1"
schirmer@12925
  1629
      by (rule evaln.Methd)
schirmer@12925
  1630
    then show ?case ..
schirmer@12925
  1631
  next
schirmer@12925
  1632
    case (Body D c s0 s1 s2 L accC T)
schirmer@12925
  1633
    with wf obtain n1 n2 where 
schirmer@12925
  1634
      "G\<turnstile>Norm s0 \<midarrow>Init D\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1635
      "G\<turnstile>s1 \<midarrow>c\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1636
      by (blast elim!: wt_elim_cases dest: eval_type_sound)
schirmer@12925
  1637
    then have 
schirmer@12925
  1638
     "G\<turnstile>Norm s0 \<midarrow>Body D c-\<succ>the (locals (store s2) Result)\<midarrow>max n1 n2
schirmer@12925
  1639
       \<rightarrow> abupd (absorb Ret) s2"
schirmer@12925
  1640
      by (blast intro: evaln.Body dest: evaln_max2)
schirmer@12925
  1641
    then show ?case ..
schirmer@12925
  1642
  next
schirmer@12925
  1643
    case (LVar s vn L accC T)
schirmer@12925
  1644
    obtain n where
schirmer@12925
  1645
      "G\<turnstile>Norm s \<midarrow>LVar vn=\<succ>lvar vn s\<midarrow>n\<rightarrow> Norm s"
schirmer@12925
  1646
      by (rules intro: evaln.LVar)
schirmer@12925
  1647
    then show ?case ..
schirmer@12925
  1648
  next
schirmer@12925
  1649
    case (FVar a accC e fn s0 s1 s2 s2' s3 stat statDeclC v L accC' T)
schirmer@12925
  1650
    have eval_init: "G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<rightarrow> s1" .
schirmer@12925
  1651
    have eval_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<rightarrow> s2" .
schirmer@12925
  1652
    have check: "s3 = check_field_access G accC statDeclC fn stat a s2'" .
schirmer@12925
  1653
    have hyp_init: "PROP ?EqEval (Norm s0) s1 (In1r (Init statDeclC)) \<diamondsuit>" .
schirmer@12925
  1654
    have hyp_e: "PROP ?EqEval s1 s2 (In1l e) (In1 a)" .
schirmer@12925
  1655
    have fvar: "(v, s2') = fvar statDeclC stat fn a s2" .
schirmer@12925
  1656
    have conf_s0: "Norm s0\<Colon>\<preceq>(G, L)" .
schirmer@12925
  1657
    have wt: "\<lparr>prg=G, cls=accC', lcl=L\<rparr>\<turnstile>In2 ({accC,statDeclC,stat}e..fn)\<Colon>T" .
schirmer@12925
  1658
    then obtain statC f where
schirmer@12925
  1659
                wt_e: "\<lparr>prg=G, cls=accC, lcl=L\<rparr>\<turnstile>e\<Colon>-Class statC" and
schirmer@12925
  1660
            accfield: "accfield G accC statC fn = Some (statDeclC,f)" and
schirmer@12925
  1661
                stat: "stat=is_static f" and
schirmer@12925
  1662
               accC': "accC'=accC" and
schirmer@12925
  1663
	           T: "T=(Inl (type f))"
schirmer@12925
  1664
       by (rule wt_elim_cases) (auto simp add: member_is_static_simp)
schirmer@12925
  1665
    from wf wt_e 
schirmer@12925
  1666
    have iscls_statC: "is_class G statC"
schirmer@12925
  1667
      by (auto dest: ty_expr_is_type type_is_class)
schirmer@12925
  1668
    with wf accfield 
schirmer@12925
  1669
    have iscls_statDeclC: "is_class G statDeclC"
schirmer@12925
  1670
      by (auto dest!: accfield_fields dest: fields_declC)
schirmer@12925
  1671
    then 
schirmer@12925
  1672
    have wt_init: "\<lparr>prg = G, cls = accC, lcl = L\<rparr>\<turnstile>(Init statDeclC)\<Colon>\<surd>"
schirmer@12925
  1673
      by simp
schirmer@12925
  1674
    from conf_s0 wt_init
schirmer@12925
  1675
    obtain n1 where
schirmer@12925
  1676
      evaln_init: "G\<turnstile>Norm s0 \<midarrow>Init statDeclC\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1677
      by (rules dest: hyp_init)
schirmer@12925
  1678
    from eval_init wt_init conf_s0 wf 
schirmer@12925
  1679
    have conf_s1: "s1\<Colon>\<preceq>(G, L)"
schirmer@12925
  1680
      by (blast dest: eval_type_sound)
schirmer@12925
  1681
    with wt_e
schirmer@12925
  1682
    obtain n2 where
schirmer@12925
  1683
      evaln_e: "G\<turnstile>s1 \<midarrow>e-\<succ>a\<midarrow>n2\<rightarrow> s2"
schirmer@12925
  1684
      by (blast dest: hyp_e)
schirmer@12925
  1685
    from eval_e wf conf_s1 wt_e
schirmer@12925
  1686
    obtain conf_s2: "s2\<Colon>\<preceq>(G, L)" and
schirmer@12925
  1687
            conf_a: "normal s2 \<longrightarrow> G,store s2\<turnstile>a\<Colon>\<preceq>Class statC"
schirmer@12925
  1688
      by (auto dest!: eval_type_sound)
schirmer@12925
  1689
    from accfield wt_e eval_init eval_e conf_s2 conf_a fvar stat check  wf
schirmer@12925
  1690
    have eq_s3_s2': "s3=s2'"  
schirmer@12925
  1691
      by (auto dest!: error_free_field_access)
schirmer@12925
  1692
    with evaln_init evaln_e fvar accC'
schirmer@12925
  1693
    have "G\<turnstile>Norm s0 \<midarrow>{accC,statDeclC,stat}e..fn=\<succ>v\<midarrow>max n1 n2\<rightarrow> s3"
schirmer@12925
  1694
      by (auto intro: evaln.FVar dest: evaln_max2)
schirmer@12925
  1695
    then show ?case ..
schirmer@12925
  1696
  next
schirmer@12925
  1697
    case (AVar a e1 e2 i s0 s1 s2 s2' v L accC T)
schirmer@12925
  1698
    with wf obtain n1 n2 where 
schirmer@12925
  1699
      "G\<turnstile>Norm s0 \<midarrow>e1-\<succ>a\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1700
      "G\<turnstile>s1 \<midarrow>e2-\<succ>i\<midarrow>n2\<rightarrow> s2"      
schirmer@12925
  1701
      by (blast elim!: wt_elim_cases dest: eval_type_sound)
schirmer@12925
  1702
    moreover 
schirmer@12925
  1703
    have "(v, s2') = avar G i a s2" .
schirmer@12925
  1704
    ultimately 
schirmer@12925
  1705
    have "G\<turnstile>Norm s0 \<midarrow>e1.[e2]=\<succ>v\<midarrow>max n1 n2\<rightarrow> s2'"
schirmer@12925
  1706
      by (blast intro!: evaln.AVar dest: evaln_max2)
schirmer@12925
  1707
    then show ?case ..
schirmer@12925
  1708
  next
schirmer@12925
  1709
    case (Nil s0 L accC T)
schirmer@12925
  1710
    show ?case by (rules intro: evaln.Nil)
schirmer@12925
  1711
  next
schirmer@12925
  1712
    case (Cons e es s0 s1 s2 v vs L accC T)
schirmer@12925
  1713
    with wf obtain n1 n2 where 
schirmer@12925
  1714
      "G\<turnstile>Norm s0 \<midarrow>e-\<succ>v\<midarrow>n1\<rightarrow> s1"
schirmer@12925
  1715
      "G\<turnstile>s1 \<midarrow>es\<doteq>\<succ>vs\<midarrow>n2\<rightarrow> s2"      
schirmer@12925
  1716
      by (blast elim!: wt_elim_cases dest: eval_type_sound)
schirmer@12925
  1717
    then
schirmer@12925
  1718
    have "G\<turnstile>Norm s0 \<midarrow>e # es\<doteq>\<succ>v # vs\<midarrow>max n1 n2\<rightarrow> s2"
schirmer@12925
  1719
      by (blast intro!: evaln.Cons dest: evaln_max2)
schirmer@12925
  1720
    then show ?case ..
schirmer@12925
  1721
  qed
schirmer@12925
  1722
qed
schirmer@12925
  1723
schirmer@12854
  1724
end