src/HOL/Bali/Example.thy
author schirmer
Fri Feb 22 11:26:44 2002 +0100 (2002-02-22)
changeset 12925 99131847fb93
parent 12858 6214f03d6d27
child 13524 604d0f3622d6
permissions -rw-r--r--
Added check for field/method access to operational semantics and proved the acesses valid.
wenzelm@12857
     1
(*  Title:      HOL/Bali/Example.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12854
     3
    Author:     David von Oheimb
wenzelm@12858
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
schirmer@12854
     5
*)
schirmer@12854
     6
header {* Example Bali program *}
schirmer@12854
     7
schirmer@12854
     8
theory Example = Eval + WellForm:
schirmer@12854
     9
schirmer@12854
    10
text {*
schirmer@12854
    11
The following example Bali program includes:
schirmer@12854
    12
\begin{itemize}
schirmer@12854
    13
\item class and interface declarations with inheritance, hiding of fields,
schirmer@12854
    14
    overriding of methods (with refined result type), array type,
schirmer@12854
    15
\item method call (with dynamic binding), parameter access, return expressions,
schirmer@12854
    16
\item expression statements, sequential composition, literal values, 
schirmer@12854
    17
    local assignment, local access, field assignment, type cast,
schirmer@12854
    18
\item exception generation and propagation, try and catch statement, throw 
schirmer@12854
    19
      statement
schirmer@12854
    20
\item instance creation and (default) static initialization
schirmer@12854
    21
\end{itemize}
schirmer@12854
    22
\begin{verbatim}
schirmer@12854
    23
package java_lang
schirmer@12854
    24
schirmer@12854
    25
public interface HasFoo {
schirmer@12854
    26
  public Base foo(Base z);
schirmer@12854
    27
}
schirmer@12854
    28
schirmer@12854
    29
public class Base implements HasFoo {
schirmer@12854
    30
  static boolean arr[] = new boolean[2];
schirmer@12854
    31
  public HasFoo vee;
schirmer@12854
    32
  public Base foo(Base z) {
schirmer@12854
    33
    return z;
schirmer@12854
    34
  }
schirmer@12854
    35
}
schirmer@12854
    36
schirmer@12854
    37
public class Ext extends Base {
schirmer@12854
    38
  public int vee;
schirmer@12854
    39
  public Ext foo(Base z) {
schirmer@12854
    40
    ((Ext)z).vee = 1;
schirmer@12854
    41
    return null;
schirmer@12854
    42
  }
schirmer@12854
    43
}
schirmer@12854
    44
schirmer@12925
    45
public class Main {
schirmer@12854
    46
  public static void main(String args[]) throws Throwable {
schirmer@12854
    47
    Base e = new Ext();
schirmer@12854
    48
    try {e.foo(null); }
schirmer@12854
    49
    catch(NullPointerException z) { 
schirmer@12854
    50
      while(Ext.arr[2]) ;
schirmer@12854
    51
    }
schirmer@12854
    52
  }
schirmer@12854
    53
}
schirmer@12854
    54
\end{verbatim}
schirmer@12854
    55
*}
schirmer@12854
    56
declare widen.null [intro]
schirmer@12854
    57
schirmer@12854
    58
lemma wf_fdecl_def2: "\<And>fd. wf_fdecl G P fd = is_acc_type G P (type (snd fd))"
schirmer@12854
    59
apply (unfold wf_fdecl_def)
schirmer@12854
    60
apply (simp (no_asm))
schirmer@12854
    61
done
schirmer@12854
    62
schirmer@12854
    63
declare wf_fdecl_def2 [iff]
schirmer@12854
    64
schirmer@12854
    65
schirmer@12854
    66
section "type and expression names"
schirmer@12854
    67
schirmer@12854
    68
(** unfortunately cannot simply instantiate tnam **)
schirmer@12925
    69
datatype tnam_  = HasFoo_ | Base_ | Ext_ | Main_
schirmer@12854
    70
datatype vnam_  = arr_ | vee_ | z_ | e_
schirmer@12854
    71
datatype label_ = lab1_
schirmer@12854
    72
schirmer@12854
    73
consts
schirmer@12854
    74
schirmer@12854
    75
  tnam_ :: "tnam_  \<Rightarrow> tnam"
schirmer@12854
    76
  vnam_ :: "vnam_  \<Rightarrow> vname"
schirmer@12854
    77
  label_:: "label_ \<Rightarrow> label"
schirmer@12854
    78
axioms  (** tnam_, vnam_ and label are intended to be isomorphic 
schirmer@12854
    79
            to tnam, vname and label **)
schirmer@12854
    80
schirmer@12854
    81
  inj_tnam_  [simp]: "(tnam_  x = tnam_  y) = (x = y)"
schirmer@12854
    82
  inj_vnam_  [simp]: "(vnam_  x = vnam_  y) = (x = y)"
schirmer@12854
    83
  inj_label_ [simp]: "(label_ x = label_ y) = (x = y)"
schirmer@12854
    84
  
schirmer@12854
    85
  
schirmer@12854
    86
  surj_tnam_:  "\<exists>m. n = tnam_  m"
schirmer@12854
    87
  surj_vnam_:  "\<exists>m. n = vnam_  m"
schirmer@12854
    88
  surj_label_:" \<exists>m. n = label_ m"
schirmer@12854
    89
schirmer@12854
    90
syntax
schirmer@12854
    91
schirmer@12854
    92
  HasFoo :: qtname
schirmer@12854
    93
  Base   :: qtname
schirmer@12854
    94
  Ext    :: qtname
schirmer@12925
    95
  Main   :: qtname
schirmer@12854
    96
  arr :: ename
schirmer@12854
    97
  vee :: ename
schirmer@12854
    98
  z   :: ename
schirmer@12854
    99
  e   :: ename
schirmer@12854
   100
  lab1:: label
schirmer@12854
   101
translations
schirmer@12854
   102
schirmer@12854
   103
  "HasFoo" == "\<lparr>pid=java_lang,tid=TName (tnam_ HasFoo_)\<rparr>"
schirmer@12854
   104
  "Base"   == "\<lparr>pid=java_lang,tid=TName (tnam_ Base_)\<rparr>"
schirmer@12854
   105
  "Ext"    == "\<lparr>pid=java_lang,tid=TName (tnam_ Ext_)\<rparr>"
schirmer@12925
   106
  "Main"   == "\<lparr>pid=java_lang,tid=TName (tnam_ Main_)\<rparr>"
schirmer@12854
   107
  "arr"    ==        "(vnam_ arr_)"
schirmer@12854
   108
  "vee"    ==        "(vnam_ vee_)"
schirmer@12854
   109
  "z"      ==        "(vnam_ z_)"
schirmer@12854
   110
  "e"      ==        "(vnam_ e_)"
schirmer@12854
   111
  "lab1"   ==        "label_ lab1_"
schirmer@12854
   112
schirmer@12854
   113
schirmer@12854
   114
lemma neq_Base_Object [simp]: "Base\<noteq>Object"
schirmer@12854
   115
by (simp add: Object_def)
schirmer@12854
   116
schirmer@12854
   117
lemma neq_Ext_Object [simp]: "Ext\<noteq>Object"
schirmer@12854
   118
by (simp add: Object_def)
schirmer@12854
   119
schirmer@12925
   120
lemma neq_Main_Object [simp]: "Main\<noteq>Object"
schirmer@12925
   121
by (simp add: Object_def)
schirmer@12925
   122
schirmer@12854
   123
lemma neq_Base_SXcpt [simp]: "Base\<noteq>SXcpt xn"
schirmer@12854
   124
by (simp add: SXcpt_def)
schirmer@12854
   125
schirmer@12854
   126
lemma neq_Ext_SXcpt [simp]: "Ext\<noteq>SXcpt xn"
schirmer@12854
   127
by (simp add: SXcpt_def)
schirmer@12854
   128
schirmer@12925
   129
lemma neq_Main_Object [simp]: "Main\<noteq>SXcpt xn"
schirmer@12925
   130
by (simp add: SXcpt_def)
schirmer@12925
   131
schirmer@12854
   132
section "classes and interfaces"
schirmer@12854
   133
schirmer@12854
   134
defs
schirmer@12854
   135
schirmer@12854
   136
  Object_mdecls_def: "Object_mdecls \<equiv> []"
schirmer@12854
   137
  SXcpt_mdecls_def:  "SXcpt_mdecls  \<equiv> []"
schirmer@12854
   138
schirmer@12854
   139
consts
schirmer@12854
   140
  
schirmer@12854
   141
  foo    :: mname
schirmer@12854
   142
schirmer@12854
   143
constdefs
schirmer@12854
   144
  
schirmer@12854
   145
  foo_sig   :: sig
schirmer@12854
   146
 "foo_sig   \<equiv> \<lparr>name=foo,parTs=[Class Base]\<rparr>"
schirmer@12854
   147
  
schirmer@12854
   148
  foo_mhead :: mhead
schirmer@12854
   149
 "foo_mhead \<equiv> \<lparr>access=Public,static=False,pars=[z],resT=Class Base\<rparr>"
schirmer@12854
   150
schirmer@12854
   151
constdefs
schirmer@12854
   152
  
schirmer@12854
   153
  Base_foo :: mdecl
schirmer@12854
   154
 "Base_foo \<equiv> (foo_sig, \<lparr>access=Public,static=False,pars=[z],resT=Class Base,
schirmer@12854
   155
                        mbody=\<lparr>lcls=[],stmt=Return (!!z)\<rparr>\<rparr>)"
schirmer@12925
   156
schirmer@12925
   157
constdefs
schirmer@12854
   158
  Ext_foo  :: mdecl
schirmer@12854
   159
 "Ext_foo  \<equiv> (foo_sig, 
schirmer@12854
   160
              \<lparr>access=Public,static=False,pars=[z],resT=Class Ext,
schirmer@12854
   161
	       mbody=\<lparr>lcls=[]
schirmer@12925
   162
                     ,stmt=Expr({Ext,Ext,False}Cast (Class Ext) (!!z)..vee := 
schirmer@12854
   163
       	                                                     Lit (Intg 1))\<rparr>
schirmer@12854
   164
	      \<rparr>)"
schirmer@12854
   165
schirmer@12854
   166
constdefs
schirmer@12854
   167
  
schirmer@12925
   168
arr_viewed_from :: "qtname \<Rightarrow> qtname \<Rightarrow> var"
schirmer@12925
   169
"arr_viewed_from accC C \<equiv> {accC,Base,True}StatRef (ClassT C)..arr"
schirmer@12854
   170
schirmer@12854
   171
BaseCl :: class
schirmer@12854
   172
"BaseCl \<equiv> \<lparr>access=Public,
schirmer@12854
   173
           cfields=[(arr, \<lparr>access=Public,static=True ,type=PrimT Boolean.[]\<rparr>),
schirmer@12854
   174
	            (vee, \<lparr>access=Public,static=False,type=Iface HasFoo    \<rparr>)],
schirmer@12854
   175
           methods=[Base_foo],
schirmer@12925
   176
           init=Expr(arr_viewed_from Base Base 
schirmer@12925
   177
                     :=New (PrimT Boolean)[Lit (Intg 2)]),
schirmer@12854
   178
           super=Object,
schirmer@12854
   179
           superIfs=[HasFoo]\<rparr>"
schirmer@12854
   180
  
schirmer@12854
   181
ExtCl  :: class
schirmer@12854
   182
"ExtCl  \<equiv> \<lparr>access=Public,
schirmer@12854
   183
           cfields=[(vee, \<lparr>access=Public,static=False,type= PrimT Integer\<rparr>)], 
schirmer@12854
   184
           methods=[Ext_foo],
schirmer@12854
   185
           init=Skip,
schirmer@12854
   186
           super=Base,
schirmer@12854
   187
           superIfs=[]\<rparr>"
schirmer@12854
   188
schirmer@12925
   189
MainCl :: class
schirmer@12925
   190
"MainCl \<equiv> \<lparr>access=Public,
schirmer@12925
   191
           cfields=[], 
schirmer@12925
   192
           methods=[], 
schirmer@12925
   193
           init=Skip,
schirmer@12925
   194
           super=Object,
schirmer@12925
   195
           superIfs=[]\<rparr>"
schirmer@12925
   196
(* The "main" method is modeled seperately (see tprg) *)
schirmer@12925
   197
schirmer@12854
   198
constdefs
schirmer@12854
   199
  
schirmer@12854
   200
  HasFooInt :: iface
schirmer@12854
   201
 "HasFooInt \<equiv> \<lparr>access=Public,imethods=[(foo_sig, foo_mhead)],isuperIfs=[]\<rparr>"
schirmer@12854
   202
schirmer@12854
   203
  Ifaces ::"idecl list"
schirmer@12854
   204
 "Ifaces \<equiv> [(HasFoo,HasFooInt)]"
schirmer@12854
   205
schirmer@12854
   206
 "Classes" ::"cdecl list"
schirmer@12925
   207
 "Classes \<equiv> [(Base,BaseCl),(Ext,ExtCl),(Main,MainCl)]@standard_classes"
schirmer@12854
   208
schirmer@12854
   209
lemmas table_classes_defs = 
schirmer@12854
   210
     Classes_def standard_classes_def ObjectC_def SXcptC_def
schirmer@12854
   211
schirmer@12854
   212
lemma table_ifaces [simp]: "table_of Ifaces = empty(HasFoo\<mapsto>HasFooInt)"
schirmer@12854
   213
apply (unfold Ifaces_def)
schirmer@12854
   214
apply (simp (no_asm))
schirmer@12854
   215
done
schirmer@12854
   216
schirmer@12854
   217
lemma table_classes_Object [simp]: 
schirmer@12854
   218
 "table_of Classes Object = Some \<lparr>access=Public,cfields=[]
schirmer@12854
   219
                                 ,methods=Object_mdecls
schirmer@12854
   220
                                 ,init=Skip,super=arbitrary,superIfs=[]\<rparr>"
schirmer@12854
   221
apply (unfold table_classes_defs)
schirmer@12854
   222
apply (simp (no_asm) add:Object_def)
schirmer@12854
   223
done
schirmer@12854
   224
schirmer@12854
   225
lemma table_classes_SXcpt [simp]: 
schirmer@12854
   226
  "table_of Classes (SXcpt xn) 
schirmer@12854
   227
    = Some \<lparr>access=Public,cfields=[],methods=SXcpt_mdecls,
schirmer@12854
   228
            init=Skip,
schirmer@12854
   229
            super=if xn = Throwable then Object else SXcpt Throwable,
schirmer@12854
   230
            superIfs=[]\<rparr>"
schirmer@12854
   231
apply (unfold table_classes_defs)
schirmer@12854
   232
apply (induct_tac xn)
schirmer@12854
   233
apply (simp add: Object_def SXcpt_def)+
schirmer@12854
   234
done
schirmer@12854
   235
schirmer@12854
   236
lemma table_classes_HasFoo [simp]: "table_of Classes HasFoo = None"
schirmer@12854
   237
apply (unfold table_classes_defs)
schirmer@12854
   238
apply (simp (no_asm) add: Object_def SXcpt_def)
schirmer@12854
   239
done
schirmer@12854
   240
schirmer@12854
   241
lemma table_classes_Base [simp]: "table_of Classes Base = Some BaseCl"
schirmer@12854
   242
apply (unfold table_classes_defs )
schirmer@12854
   243
apply (simp (no_asm) add: Object_def SXcpt_def)
schirmer@12854
   244
done
schirmer@12854
   245
schirmer@12854
   246
lemma table_classes_Ext [simp]: "table_of Classes Ext = Some ExtCl"
schirmer@12854
   247
apply (unfold table_classes_defs )
schirmer@12854
   248
apply (simp (no_asm) add: Object_def SXcpt_def)
schirmer@12854
   249
done
schirmer@12854
   250
schirmer@12925
   251
lemma table_classes_Main [simp]: "table_of Classes Main = Some MainCl"
schirmer@12925
   252
apply (unfold table_classes_defs )
schirmer@12925
   253
apply (simp (no_asm) add: Object_def SXcpt_def)
schirmer@12925
   254
done
schirmer@12854
   255
schirmer@12854
   256
section "program"
schirmer@12854
   257
schirmer@12854
   258
syntax
schirmer@12854
   259
  tprg :: prog
schirmer@12854
   260
schirmer@12854
   261
translations
schirmer@12854
   262
  "tprg" == "\<lparr>ifaces=Ifaces,classes=Classes\<rparr>"
schirmer@12854
   263
schirmer@12854
   264
constdefs
schirmer@12854
   265
  test    :: "(ty)list \<Rightarrow> stmt"
schirmer@12854
   266
 "test pTs \<equiv> e:==NewC Ext;; 
schirmer@12925
   267
           \<spacespace> Try Expr({Main,ClassT Base,IntVir}!!e\<cdot>foo({pTs}[Lit Null]))
schirmer@12854
   268
           \<spacespace> Catch((SXcpt NullPointer) z)
schirmer@12925
   269
           (lab1\<bullet> While(Acc 
schirmer@12925
   270
                        (Acc (arr_viewed_from Main Ext).[Lit (Intg 2)])) Skip)"
schirmer@12854
   271
schirmer@12854
   272
schirmer@12854
   273
section "well-structuredness"
schirmer@12854
   274
schirmer@12854
   275
lemma not_Object_subcls_any [elim!]: "(Object, C) \<in> (subcls1 tprg)^+ \<Longrightarrow> R"
schirmer@12854
   276
apply (auto dest!: tranclD subcls1D)
schirmer@12854
   277
done
schirmer@12854
   278
schirmer@12854
   279
lemma not_Throwable_subcls_SXcpt [elim!]: 
schirmer@12854
   280
  "(SXcpt Throwable, SXcpt xn) \<in> (subcls1 tprg)^+ \<Longrightarrow> R"
schirmer@12854
   281
apply (auto dest!: tranclD subcls1D) 
schirmer@12854
   282
apply (simp add: Object_def SXcpt_def)
schirmer@12854
   283
done
schirmer@12854
   284
schirmer@12854
   285
lemma not_SXcpt_n_subcls_SXcpt_n [elim!]: 
schirmer@12854
   286
  "(SXcpt xn, SXcpt xn)  \<in> (subcls1 tprg)^+ \<Longrightarrow> R"
schirmer@12854
   287
apply (auto dest!: tranclD subcls1D)
schirmer@12854
   288
apply (drule rtranclD)
schirmer@12854
   289
apply auto
schirmer@12854
   290
done
schirmer@12854
   291
schirmer@12854
   292
lemma not_Base_subcls_Ext [elim!]: "(Base, Ext) \<in> (subcls1 tprg)^+  \<Longrightarrow> R"
schirmer@12854
   293
apply (auto dest!: tranclD subcls1D simp add: BaseCl_def)
schirmer@12854
   294
done
schirmer@12854
   295
schirmer@12854
   296
lemma not_TName_n_subcls_TName_n [rule_format (no_asm), elim!]: 
schirmer@12854
   297
  "(\<lparr>pid=java_lang,tid=TName tn\<rparr>, \<lparr>pid=java_lang,tid=TName tn\<rparr>) 
schirmer@12854
   298
   \<in> (subcls1 tprg)^+ \<longrightarrow> R"
schirmer@12854
   299
apply (rule_tac n1 = "tn" in surj_tnam_ [THEN exE])
schirmer@12854
   300
apply (erule ssubst)
schirmer@12854
   301
apply (rule tnam_.induct)
schirmer@12854
   302
apply  safe
schirmer@12925
   303
apply (auto dest!: tranclD subcls1D simp add: BaseCl_def ExtCl_def MainCl_def)
schirmer@12854
   304
apply (drule rtranclD)
schirmer@12854
   305
apply auto
schirmer@12854
   306
done
schirmer@12854
   307
schirmer@12854
   308
schirmer@12854
   309
lemma ws_idecl_HasFoo: "ws_idecl tprg HasFoo []"
schirmer@12854
   310
apply (unfold ws_idecl_def)
schirmer@12854
   311
apply (simp (no_asm))
schirmer@12854
   312
done
schirmer@12854
   313
schirmer@12854
   314
lemma ws_cdecl_Object: "ws_cdecl tprg Object any"
schirmer@12854
   315
apply (unfold ws_cdecl_def)
schirmer@12854
   316
apply auto
schirmer@12854
   317
done
schirmer@12854
   318
schirmer@12854
   319
lemma ws_cdecl_Throwable: "ws_cdecl tprg (SXcpt Throwable) Object"
schirmer@12854
   320
apply (unfold ws_cdecl_def)
schirmer@12854
   321
apply auto
schirmer@12854
   322
done
schirmer@12854
   323
schirmer@12854
   324
lemma ws_cdecl_SXcpt: "ws_cdecl tprg (SXcpt xn) (SXcpt Throwable)"
schirmer@12854
   325
apply (unfold ws_cdecl_def)
schirmer@12854
   326
apply auto
schirmer@12854
   327
done
schirmer@12854
   328
schirmer@12854
   329
lemma ws_cdecl_Base: "ws_cdecl tprg Base Object"
schirmer@12854
   330
apply (unfold ws_cdecl_def)
schirmer@12854
   331
apply auto
schirmer@12854
   332
done
schirmer@12854
   333
schirmer@12854
   334
lemma ws_cdecl_Ext: "ws_cdecl tprg Ext Base"
schirmer@12854
   335
apply (unfold ws_cdecl_def)
schirmer@12854
   336
apply auto
schirmer@12854
   337
done
schirmer@12854
   338
schirmer@12925
   339
lemma ws_cdecl_Main: "ws_cdecl tprg Main Object"
schirmer@12925
   340
apply (unfold ws_cdecl_def)
schirmer@12925
   341
apply auto
schirmer@12925
   342
done
schirmer@12925
   343
schirmer@12854
   344
lemmas ws_cdecls = ws_cdecl_SXcpt ws_cdecl_Object ws_cdecl_Throwable
schirmer@12925
   345
                   ws_cdecl_Base ws_cdecl_Ext ws_cdecl_Main
schirmer@12854
   346
schirmer@12854
   347
declare not_Object_subcls_any [rule del]
schirmer@12854
   348
          not_Throwable_subcls_SXcpt [rule del] 
schirmer@12854
   349
          not_SXcpt_n_subcls_SXcpt_n [rule del] 
schirmer@12854
   350
          not_Base_subcls_Ext [rule del] not_TName_n_subcls_TName_n [rule del]
schirmer@12854
   351
schirmer@12854
   352
lemma ws_idecl_all: 
schirmer@12854
   353
 "G=tprg \<Longrightarrow> (\<forall>(I,i)\<in>set Ifaces. ws_idecl G I (isuperIfs i))"
schirmer@12854
   354
apply (simp (no_asm) add: Ifaces_def HasFooInt_def)
schirmer@12854
   355
apply (auto intro!: ws_idecl_HasFoo)
schirmer@12854
   356
done
schirmer@12854
   357
schirmer@12854
   358
lemma ws_cdecl_all: "G=tprg \<Longrightarrow> (\<forall>(C,c)\<in>set Classes. ws_cdecl G C (super c))"
schirmer@12925
   359
apply (simp (no_asm) add: Classes_def BaseCl_def ExtCl_def MainCl_def)
schirmer@12854
   360
apply (auto intro!: ws_cdecls simp add: standard_classes_def ObjectC_def 
schirmer@12854
   361
        SXcptC_def)
schirmer@12854
   362
done
schirmer@12854
   363
schirmer@12854
   364
lemma ws_tprg: "ws_prog tprg"
schirmer@12854
   365
apply (unfold ws_prog_def)
schirmer@12854
   366
apply (auto intro!: ws_idecl_all ws_cdecl_all)
schirmer@12854
   367
done
schirmer@12854
   368
schirmer@12854
   369
schirmer@12854
   370
section "misc program properties (independent of well-structuredness)"
schirmer@12854
   371
schirmer@12854
   372
lemma single_iface [simp]: "is_iface tprg I = (I = HasFoo)"
schirmer@12854
   373
apply (unfold Ifaces_def)
schirmer@12854
   374
apply (simp (no_asm))
schirmer@12854
   375
done
schirmer@12854
   376
schirmer@12854
   377
lemma empty_subint1 [simp]: "subint1 tprg = {}"
schirmer@12854
   378
apply (unfold subint1_def Ifaces_def HasFooInt_def)
schirmer@12854
   379
apply auto
schirmer@12854
   380
done
schirmer@12854
   381
schirmer@12854
   382
lemma unique_ifaces: "unique Ifaces"
schirmer@12854
   383
apply (unfold Ifaces_def)
schirmer@12854
   384
apply (simp (no_asm))
schirmer@12854
   385
done
schirmer@12854
   386
schirmer@12854
   387
lemma unique_classes: "unique Classes"
schirmer@12854
   388
apply (unfold table_classes_defs )
schirmer@12854
   389
apply (simp )
schirmer@12854
   390
done
schirmer@12854
   391
schirmer@12854
   392
lemma SXcpt_subcls_Throwable [simp]: "tprg\<turnstile>SXcpt xn\<preceq>\<^sub>C SXcpt Throwable"
schirmer@12854
   393
apply (rule SXcpt_subcls_Throwable_lemma)
schirmer@12854
   394
apply auto
schirmer@12854
   395
done
schirmer@12854
   396
schirmer@12854
   397
lemma Ext_subclseq_Base [simp]: "tprg\<turnstile>Ext \<preceq>\<^sub>C Base"
schirmer@12854
   398
apply (rule subcls_direct1)
schirmer@12854
   399
apply  (simp (no_asm) add: ExtCl_def)
schirmer@12854
   400
apply  (simp add: Object_def)
schirmer@12854
   401
apply (simp (no_asm))
schirmer@12854
   402
done
schirmer@12854
   403
schirmer@12854
   404
lemma Ext_subcls_Base [simp]: "tprg\<turnstile>Ext \<prec>\<^sub>C Base"
schirmer@12854
   405
apply (rule subcls_direct2)
schirmer@12854
   406
apply  (simp (no_asm) add: ExtCl_def)
schirmer@12854
   407
apply  (simp add: Object_def)
schirmer@12854
   408
apply (simp (no_asm))
schirmer@12854
   409
done
schirmer@12854
   410
schirmer@12854
   411
schirmer@12854
   412
schirmer@12854
   413
section "fields and method lookup"
schirmer@12854
   414
schirmer@12854
   415
lemma fields_tprg_Object [simp]: "DeclConcepts.fields tprg Object = []"
schirmer@12854
   416
by (rule ws_tprg [THEN fields_emptyI], force+)
schirmer@12854
   417
schirmer@12854
   418
lemma fields_tprg_Throwable [simp]: 
schirmer@12854
   419
  "DeclConcepts.fields tprg (SXcpt Throwable) = []"
schirmer@12854
   420
by (rule ws_tprg [THEN fields_emptyI], force+)
schirmer@12854
   421
schirmer@12854
   422
lemma fields_tprg_SXcpt [simp]: "DeclConcepts.fields tprg (SXcpt xn) = []"
schirmer@12854
   423
apply (case_tac "xn = Throwable")
schirmer@12854
   424
apply  (simp (no_asm_simp))
schirmer@12854
   425
by (rule ws_tprg [THEN fields_emptyI], force+)
schirmer@12854
   426
schirmer@12854
   427
lemmas fields_rec_ = fields_rec [OF _ ws_tprg]
schirmer@12854
   428
schirmer@12854
   429
lemma fields_Base [simp]: 
schirmer@12854
   430
"DeclConcepts.fields tprg Base 
schirmer@12854
   431
  = [((arr,Base), \<lparr>access=Public,static=True ,type=PrimT Boolean.[]\<rparr>),
schirmer@12854
   432
     ((vee,Base), \<lparr>access=Public,static=False,type=Iface HasFoo    \<rparr>)]"
schirmer@12854
   433
apply (subst fields_rec_)
schirmer@12854
   434
apply   (auto simp add: BaseCl_def)
schirmer@12854
   435
done
schirmer@12854
   436
schirmer@12854
   437
lemma fields_Ext [simp]: 
schirmer@12854
   438
 "DeclConcepts.fields tprg Ext  
schirmer@12854
   439
  = [((vee,Ext), \<lparr>access=Public,static=False,type= PrimT Integer\<rparr>)] 
schirmer@12854
   440
    @ DeclConcepts.fields tprg Base"
schirmer@12854
   441
apply (rule trans)
schirmer@12854
   442
apply (rule fields_rec_)
schirmer@12854
   443
apply   (auto simp add: ExtCl_def Object_def)
schirmer@12854
   444
done
schirmer@12854
   445
schirmer@12854
   446
lemmas imethds_rec_ = imethds_rec [OF _ ws_tprg]
schirmer@12854
   447
lemmas methd_rec_  = methd_rec  [OF _ ws_tprg]
schirmer@12854
   448
schirmer@12854
   449
lemma imethds_HasFoo [simp]: 
schirmer@12854
   450
  "imethds tprg HasFoo = o2s \<circ> empty(foo_sig\<mapsto>(HasFoo, foo_mhead))"
schirmer@12854
   451
apply (rule trans)
schirmer@12854
   452
apply (rule imethds_rec_)
schirmer@12854
   453
apply  (auto simp add: HasFooInt_def)
schirmer@12854
   454
done
schirmer@12854
   455
schirmer@12854
   456
lemma methd_tprg_Object [simp]: "methd tprg Object = empty"
schirmer@12854
   457
apply (subst methd_rec_)
schirmer@12854
   458
apply (auto simp add: Object_mdecls_def)
schirmer@12854
   459
done
schirmer@12854
   460
schirmer@12854
   461
lemma methd_Base [simp]: 
schirmer@12854
   462
  "methd tprg Base = table_of [(\<lambda>(s,m). (s, Base, m)) Base_foo]"
schirmer@12854
   463
apply (rule trans)
schirmer@12854
   464
apply (rule methd_rec_)
schirmer@12854
   465
apply   (auto simp add: BaseCl_def)
schirmer@12854
   466
done
schirmer@12854
   467
schirmer@12854
   468
lemma memberid_Base_foo_simp [simp]:
schirmer@12854
   469
 "memberid (mdecl Base_foo) = mid foo_sig"
schirmer@12854
   470
by (simp add: Base_foo_def)
schirmer@12854
   471
schirmer@12854
   472
lemma memberid_Ext_foo_simp [simp]:
schirmer@12854
   473
 "memberid (mdecl Ext_foo) = mid foo_sig"
schirmer@12854
   474
by (simp add: Ext_foo_def)
schirmer@12854
   475
schirmer@12854
   476
lemma Base_declares_foo:
schirmer@12854
   477
  "tprg\<turnstile>mdecl Base_foo declared_in Base"
schirmer@12854
   478
by (auto simp add: declared_in_def cdeclaredmethd_def BaseCl_def Base_foo_def)
schirmer@12854
   479
schirmer@12854
   480
lemma foo_sig_not_undeclared_in_Base:
schirmer@12854
   481
  "\<not> tprg\<turnstile>mid foo_sig undeclared_in Base"
schirmer@12854
   482
proof -
schirmer@12854
   483
  from Base_declares_foo
schirmer@12854
   484
  show ?thesis
schirmer@12854
   485
    by (auto dest!: declared_not_undeclared )
schirmer@12854
   486
qed
schirmer@12854
   487
schirmer@12854
   488
lemma Ext_declares_foo:
schirmer@12854
   489
  "tprg\<turnstile>mdecl Ext_foo declared_in Ext"
schirmer@12854
   490
by (auto simp add: declared_in_def cdeclaredmethd_def ExtCl_def Ext_foo_def)
schirmer@12854
   491
schirmer@12854
   492
lemma foo_sig_not_undeclared_in_Ext:
schirmer@12854
   493
  "\<not> tprg\<turnstile>mid foo_sig undeclared_in Ext"
schirmer@12854
   494
proof -
schirmer@12854
   495
  from Ext_declares_foo
schirmer@12854
   496
  show ?thesis
schirmer@12854
   497
    by (auto dest!: declared_not_undeclared )
schirmer@12854
   498
qed
schirmer@12854
   499
schirmer@12854
   500
lemma Base_foo_not_inherited_in_Ext:
schirmer@12854
   501
 "\<not> tprg \<turnstile> Ext inherits (Base,mdecl Base_foo)"
schirmer@12854
   502
by (auto simp add: inherits_def foo_sig_not_undeclared_in_Ext)
schirmer@12854
   503
schirmer@12854
   504
lemma Ext_method_inheritance:
schirmer@12854
   505
 "filter_tab (\<lambda>sig m. tprg \<turnstile> Ext inherits method sig m)
schirmer@12854
   506
     (empty(fst ((\<lambda>(s, m). (s, Base, m)) Base_foo)\<mapsto>
schirmer@12854
   507
      snd ((\<lambda>(s, m). (s, Base, m)) Base_foo)))
schirmer@12854
   508
  = empty"
schirmer@12854
   509
proof -
schirmer@12854
   510
  from Base_foo_not_inherited_in_Ext
schirmer@12854
   511
  show ?thesis
schirmer@12854
   512
    by (auto intro: filter_tab_all_False simp add: Base_foo_def)
schirmer@12854
   513
qed
schirmer@12854
   514
schirmer@12854
   515
schirmer@12854
   516
lemma methd_Ext [simp]: "methd tprg Ext =   
schirmer@12854
   517
  table_of [(\<lambda>(s,m). (s, Ext, m)) Ext_foo]"
schirmer@12854
   518
apply (rule trans)
schirmer@12854
   519
apply (rule methd_rec_)
schirmer@12854
   520
apply   (auto simp add: ExtCl_def Object_def Ext_method_inheritance)
schirmer@12854
   521
done
schirmer@12854
   522
schirmer@12854
   523
section "accessibility"
schirmer@12854
   524
schirmer@12854
   525
lemma classesDefined: 
schirmer@12854
   526
 "\<lbrakk>class tprg C = Some c; C\<noteq>Object\<rbrakk> \<Longrightarrow> \<exists> sc. class tprg (super c) = Some sc"
schirmer@12854
   527
apply (auto simp add: Classes_def standard_classes_def 
schirmer@12925
   528
                      BaseCl_def ExtCl_def MainCl_def
schirmer@12854
   529
                      SXcptC_def ObjectC_def) 
schirmer@12854
   530
done
schirmer@12854
   531
schirmer@12854
   532
lemma superclassesBase [simp]: "superclasses tprg Base={Object}"
schirmer@12854
   533
proof -
schirmer@12854
   534
  have ws: "ws_prog tprg" by (rule ws_tprg)
schirmer@12854
   535
  then show ?thesis
schirmer@12854
   536
    by (auto simp add: superclasses_rec  BaseCl_def)
schirmer@12854
   537
qed
schirmer@12854
   538
schirmer@12854
   539
lemma superclassesExt [simp]: "superclasses tprg Ext={Base,Object}"
schirmer@12854
   540
proof -
schirmer@12854
   541
  have ws: "ws_prog tprg" by (rule ws_tprg)
schirmer@12854
   542
  then show ?thesis
schirmer@12854
   543
    by (auto simp add: superclasses_rec  ExtCl_def BaseCl_def)
schirmer@12854
   544
qed
schirmer@12854
   545
schirmer@12925
   546
lemma superclassesMain [simp]: "superclasses tprg Main={Object}"
schirmer@12925
   547
proof -
schirmer@12925
   548
  have ws: "ws_prog tprg" by (rule ws_tprg)
schirmer@12925
   549
  then show ?thesis
schirmer@12925
   550
    by (auto simp add: superclasses_rec  MainCl_def)
schirmer@12925
   551
qed
schirmer@12925
   552
schirmer@12854
   553
lemma HasFoo_accessible[simp]:"tprg\<turnstile>(Iface HasFoo) accessible_in P" 
schirmer@12854
   554
by (simp add: accessible_in_RefT_simp is_public_def HasFooInt_def)
schirmer@12854
   555
schirmer@12854
   556
lemma HasFoo_is_acc_iface[simp]: "is_acc_iface tprg P HasFoo"
schirmer@12854
   557
by (simp add: is_acc_iface_def)
schirmer@12854
   558
schirmer@12854
   559
lemma HasFoo_is_acc_type[simp]: "is_acc_type tprg P (Iface HasFoo)"
schirmer@12854
   560
by (simp add: is_acc_type_def)
schirmer@12854
   561
schirmer@12854
   562
lemma Base_accessible[simp]:"tprg\<turnstile>(Class Base) accessible_in P" 
schirmer@12854
   563
by (simp add: accessible_in_RefT_simp is_public_def BaseCl_def)
schirmer@12854
   564
schirmer@12854
   565
lemma Base_is_acc_class[simp]: "is_acc_class tprg P Base"
schirmer@12854
   566
by (simp add: is_acc_class_def)
schirmer@12854
   567
schirmer@12854
   568
lemma Base_is_acc_type[simp]: "is_acc_type tprg P (Class Base)"
schirmer@12854
   569
by (simp add: is_acc_type_def)
schirmer@12854
   570
schirmer@12854
   571
lemma Ext_accessible[simp]:"tprg\<turnstile>(Class Ext) accessible_in P" 
schirmer@12854
   572
by (simp add: accessible_in_RefT_simp is_public_def ExtCl_def)
schirmer@12854
   573
schirmer@12854
   574
lemma Ext_is_acc_class[simp]: "is_acc_class tprg P Ext"
schirmer@12854
   575
by (simp add: is_acc_class_def)
schirmer@12854
   576
schirmer@12854
   577
lemma Ext_is_acc_type[simp]: "is_acc_type tprg P (Class Ext)"
schirmer@12854
   578
by (simp add: is_acc_type_def)
schirmer@12854
   579
schirmer@12854
   580
lemma accmethd_tprg_Object [simp]: "accmethd tprg S Object = empty"
schirmer@12854
   581
apply (unfold accmethd_def)
schirmer@12854
   582
apply (simp)
schirmer@12854
   583
done
schirmer@12854
   584
schirmer@12854
   585
lemma  snd_special_simp: "snd ((\<lambda>(s, m). (s, a, m)) x) = (a,snd x)"
schirmer@12854
   586
by (cases x) (auto)
schirmer@12854
   587
schirmer@12854
   588
lemma  fst_special_simp: "fst ((\<lambda>(s, m). (s, a, m)) x) = fst x"
schirmer@12854
   589
by (cases x) (auto)
schirmer@12854
   590
schirmer@12854
   591
lemma foo_sig_undeclared_in_Object:
schirmer@12854
   592
  "tprg\<turnstile>mid foo_sig undeclared_in Object"
schirmer@12854
   593
by (auto simp add: undeclared_in_def cdeclaredmethd_def Object_mdecls_def)
schirmer@12854
   594
schirmer@12854
   595
lemma unique_sig_Base_foo:
schirmer@12854
   596
 "tprg\<turnstile> mdecl (sig, snd Base_foo) declared_in Base \<Longrightarrow> sig=foo_sig"
schirmer@12854
   597
by (auto simp add: declared_in_def cdeclaredmethd_def 
schirmer@12854
   598
                   Base_foo_def BaseCl_def)
schirmer@12854
   599
schirmer@12854
   600
lemma Base_foo_no_override:
schirmer@12854
   601
 "tprg,sig\<turnstile>(Base,(snd Base_foo)) overrides old \<Longrightarrow> P"
schirmer@12854
   602
apply (drule overrides_commonD)
schirmer@12854
   603
apply (clarsimp)
schirmer@12854
   604
apply (frule subclsEval)
schirmer@12854
   605
apply    (rule ws_tprg)
schirmer@12854
   606
apply    (simp)
schirmer@12854
   607
apply    (rule classesDefined) 
schirmer@12854
   608
apply    assumption+
schirmer@12854
   609
apply (frule unique_sig_Base_foo) 
schirmer@12854
   610
apply (auto dest!: declared_not_undeclared intro: foo_sig_undeclared_in_Object
schirmer@12854
   611
            dest: unique_sig_Base_foo)
schirmer@12854
   612
done
schirmer@12854
   613
schirmer@12854
   614
lemma Base_foo_no_stat_override:
schirmer@12854
   615
 "tprg,sig\<turnstile>(Base,(snd Base_foo)) overrides\<^sub>S old \<Longrightarrow> P"
schirmer@12854
   616
apply (drule stat_overrides_commonD)
schirmer@12854
   617
apply (clarsimp)
schirmer@12854
   618
apply (frule subclsEval)
schirmer@12854
   619
apply    (rule ws_tprg)
schirmer@12854
   620
apply    (simp)
schirmer@12854
   621
apply    (rule classesDefined) 
schirmer@12854
   622
apply    assumption+
schirmer@12854
   623
apply (frule unique_sig_Base_foo) 
schirmer@12854
   624
apply (auto dest!: declared_not_undeclared intro: foo_sig_undeclared_in_Object
schirmer@12854
   625
            dest: unique_sig_Base_foo)
schirmer@12854
   626
done
schirmer@12854
   627
schirmer@12854
   628
schirmer@12854
   629
lemma Base_foo_no_hide:
schirmer@12854
   630
 "tprg,sig\<turnstile>(Base,(snd Base_foo)) hides old \<Longrightarrow> P"
schirmer@12854
   631
by (auto dest: hidesD simp add: Base_foo_def member_is_static_simp)
schirmer@12854
   632
schirmer@12854
   633
lemma Ext_foo_no_hide:
schirmer@12854
   634
 "tprg,sig\<turnstile>(Ext,(snd Ext_foo)) hides old \<Longrightarrow> P"
schirmer@12854
   635
by (auto dest: hidesD simp add: Ext_foo_def member_is_static_simp)
schirmer@12854
   636
schirmer@12854
   637
lemma unique_sig_Ext_foo:
schirmer@12854
   638
 "tprg\<turnstile> mdecl (sig, snd Ext_foo) declared_in Ext \<Longrightarrow> sig=foo_sig"
schirmer@12854
   639
by (auto simp add: declared_in_def cdeclaredmethd_def 
schirmer@12854
   640
                   Ext_foo_def ExtCl_def)
schirmer@12854
   641
schirmer@12854
   642
lemma Ext_foo_override:
schirmer@12854
   643
 "tprg,sig\<turnstile>(Ext,(snd Ext_foo)) overrides old 
schirmer@12854
   644
  \<Longrightarrow> old = (Base,(snd Base_foo))"
schirmer@12854
   645
apply (drule overrides_commonD)
schirmer@12854
   646
apply (clarsimp)
schirmer@12854
   647
apply (frule subclsEval)
schirmer@12854
   648
apply    (rule ws_tprg)
schirmer@12854
   649
apply    (simp)
schirmer@12854
   650
apply    (rule classesDefined) 
schirmer@12854
   651
apply    assumption+
schirmer@12854
   652
apply (frule unique_sig_Ext_foo) 
schirmer@12854
   653
apply (case_tac "old")
schirmer@12854
   654
apply (insert Base_declares_foo foo_sig_undeclared_in_Object) 
schirmer@12854
   655
apply (auto simp add: ExtCl_def Ext_foo_def
schirmer@12854
   656
                      BaseCl_def Base_foo_def Object_mdecls_def
schirmer@12854
   657
                      split_paired_all
schirmer@12854
   658
                      member_is_static_simp
schirmer@12854
   659
           dest: declared_not_undeclared unique_declaration)
schirmer@12854
   660
done
schirmer@12854
   661
schirmer@12854
   662
lemma Ext_foo_stat_override:
schirmer@12854
   663
 "tprg,sig\<turnstile>(Ext,(snd Ext_foo)) overrides\<^sub>S old 
schirmer@12854
   664
  \<Longrightarrow> old = (Base,(snd Base_foo))"
schirmer@12854
   665
apply (drule stat_overrides_commonD)
schirmer@12854
   666
apply (clarsimp)
schirmer@12854
   667
apply (frule subclsEval)
schirmer@12854
   668
apply    (rule ws_tprg)
schirmer@12854
   669
apply    (simp)
schirmer@12854
   670
apply    (rule classesDefined) 
schirmer@12854
   671
apply    assumption+
schirmer@12854
   672
apply (frule unique_sig_Ext_foo) 
schirmer@12854
   673
apply (case_tac "old")
schirmer@12854
   674
apply (insert Base_declares_foo foo_sig_undeclared_in_Object) 
schirmer@12854
   675
apply (auto simp add: ExtCl_def Ext_foo_def
schirmer@12854
   676
                      BaseCl_def Base_foo_def Object_mdecls_def
schirmer@12854
   677
                      split_paired_all
schirmer@12854
   678
                      member_is_static_simp
schirmer@12854
   679
           dest: declared_not_undeclared unique_declaration)
schirmer@12854
   680
done
schirmer@12854
   681
schirmer@12854
   682
lemma Base_foo_member_of_Base: 
schirmer@12854
   683
  "tprg\<turnstile>(Base,mdecl Base_foo) member_of Base"
schirmer@12854
   684
by (auto intro!: members.Immediate Base_declares_foo)
schirmer@12854
   685
schirmer@12925
   686
lemma Base_foo_member_in_Base: 
schirmer@12925
   687
  "tprg\<turnstile>(Base,mdecl Base_foo) member_in Base"
schirmer@12925
   688
by (rule member_of_to_member_in [OF Base_foo_member_of_Base])
schirmer@12925
   689
schirmer@12925
   690
lemma Base_foo_member_of_Base: 
schirmer@12925
   691
  "tprg\<turnstile>(Base,mdecl Base_foo) member_of Base"
schirmer@12925
   692
by (auto intro!: members.Immediate Base_declares_foo)
schirmer@12925
   693
schirmer@12854
   694
lemma Ext_foo_member_of_Ext: 
schirmer@12854
   695
  "tprg\<turnstile>(Ext,mdecl Ext_foo) member_of Ext"
schirmer@12854
   696
by (auto intro!: members.Immediate Ext_declares_foo)
schirmer@12854
   697
schirmer@12925
   698
lemma Ext_foo_member_in_Ext: 
schirmer@12925
   699
  "tprg\<turnstile>(Ext,mdecl Ext_foo) member_in Ext"
schirmer@12925
   700
by (rule member_of_to_member_in [OF Ext_foo_member_of_Ext])
schirmer@12925
   701
schirmer@12854
   702
lemma Base_foo_permits_acc:
schirmer@12854
   703
 "tprg \<turnstile> (Base, mdecl Base_foo) in Base permits_acc_to S"
schirmer@12854
   704
by ( simp add: permits_acc_def Base_foo_def)
schirmer@12854
   705
schirmer@12854
   706
lemma Base_foo_accessible [simp]:
schirmer@12854
   707
 "tprg\<turnstile>(Base,mdecl Base_foo) of Base accessible_from S"
schirmer@12925
   708
by (auto intro: accessible_fromR.Immediate 
schirmer@12854
   709
                Base_foo_member_of_Base Base_foo_permits_acc)
schirmer@12854
   710
schirmer@12925
   711
lemma Base_foo_dyn_accessible [simp]:
schirmer@12925
   712
 "tprg\<turnstile>(Base,mdecl Base_foo) in Base dyn_accessible_from S"
schirmer@12925
   713
apply (rule dyn_accessible_fromR.Immediate)
schirmer@12925
   714
apply   (rule Base_foo_member_in_Base)
schirmer@12925
   715
apply   (rule Base_foo_permits_acc)
schirmer@12925
   716
done
schirmer@12925
   717
schirmer@12854
   718
lemma accmethd_Base [simp]: 
schirmer@12854
   719
  "accmethd tprg S Base = methd tprg Base"
schirmer@12854
   720
apply (simp add: accmethd_def)
schirmer@12854
   721
apply (rule filter_tab_all_True)
schirmer@12854
   722
apply (simp add: snd_special_simp fst_special_simp)
schirmer@12854
   723
done
schirmer@12854
   724
schirmer@12854
   725
lemma Ext_foo_permits_acc:
schirmer@12854
   726
 "tprg \<turnstile> (Ext, mdecl Ext_foo) in Ext permits_acc_to S"
schirmer@12854
   727
by ( simp add: permits_acc_def Ext_foo_def)
schirmer@12854
   728
schirmer@12854
   729
lemma Ext_foo_accessible [simp]:
schirmer@12854
   730
 "tprg\<turnstile>(Ext,mdecl Ext_foo) of Ext accessible_from S"
schirmer@12925
   731
by (auto intro: accessible_fromR.Immediate 
schirmer@12854
   732
                Ext_foo_member_of_Ext Ext_foo_permits_acc)
schirmer@12854
   733
schirmer@12925
   734
lemma Ext_foo_dyn_accessible [simp]:
schirmer@12925
   735
 "tprg\<turnstile>(Ext,mdecl Ext_foo) in Ext dyn_accessible_from S"
schirmer@12925
   736
apply (rule dyn_accessible_fromR.Immediate) 
schirmer@12925
   737
apply   (rule Ext_foo_member_in_Ext)
schirmer@12925
   738
apply   (rule Ext_foo_permits_acc)
schirmer@12854
   739
done
schirmer@12854
   740
schirmer@12854
   741
lemma Ext_foo_overrides_Base_foo:
schirmer@12854
   742
 "tprg\<turnstile>(Ext,Ext_foo) overrides (Base,Base_foo)"
schirmer@12854
   743
proof (rule overridesR.Direct, simp_all)
schirmer@12854
   744
  show "\<not> is_static Ext_foo" 
schirmer@12854
   745
    by (simp add: member_is_static_simp Ext_foo_def)
schirmer@12854
   746
  show "\<not> is_static Base_foo"
schirmer@12854
   747
    by (simp add: member_is_static_simp Base_foo_def)
schirmer@12854
   748
  show "accmodi Ext_foo \<noteq> Private"
schirmer@12854
   749
    by (simp add: Ext_foo_def)
schirmer@12854
   750
  show "msig (Ext, Ext_foo) = msig (Base, Base_foo)"
schirmer@12854
   751
    by (simp add: Ext_foo_def Base_foo_def)
schirmer@12854
   752
  show "tprg\<turnstile>mdecl Ext_foo declared_in Ext"
schirmer@12854
   753
    by (auto intro: Ext_declares_foo)
schirmer@12854
   754
  show "tprg\<turnstile>mdecl Base_foo declared_in Base"
schirmer@12854
   755
    by (auto intro: Base_declares_foo)
schirmer@12854
   756
  show "tprg \<turnstile>(Base, mdecl Base_foo) inheritable_in java_lang"
schirmer@12854
   757
    by (simp add: inheritable_in_def Base_foo_def)
schirmer@12854
   758
  show "tprg\<turnstile>resTy Ext_foo\<preceq>resTy Base_foo"
schirmer@12854
   759
    by (simp add: Ext_foo_def Base_foo_def mhead_resTy_simp)
schirmer@12854
   760
qed
schirmer@12854
   761
schirmer@12854
   762
lemma accmethd_Ext [simp]: 
schirmer@12854
   763
  "accmethd tprg S Ext = methd tprg Ext"
schirmer@12854
   764
apply (simp add: accmethd_def)
schirmer@12854
   765
apply (rule filter_tab_all_True)
schirmer@12854
   766
apply (auto simp add: snd_special_simp fst_special_simp)
schirmer@12854
   767
done
schirmer@12854
   768
schirmer@12854
   769
lemma cls_Ext: "class tprg Ext = Some ExtCl"
schirmer@12854
   770
by simp
schirmer@12854
   771
lemma dynmethd_Ext_foo:
schirmer@12854
   772
 "dynmethd tprg Base Ext \<lparr>name = foo, parTs = [Class Base]\<rparr> 
schirmer@12854
   773
  = Some (Ext,snd Ext_foo)"
schirmer@12854
   774
proof -
schirmer@12854
   775
  have "methd tprg Base \<lparr>name = foo, parTs = [Class Base]\<rparr> 
schirmer@12854
   776
          = Some (Base,snd Base_foo)" and
schirmer@12854
   777
       "methd tprg Ext \<lparr>name = foo, parTs = [Class Base]\<rparr> 
schirmer@12854
   778
          = Some (Ext,snd Ext_foo)" 
schirmer@12854
   779
    by (auto simp add: Ext_foo_def Base_foo_def foo_sig_def)
schirmer@12854
   780
  with cls_Ext ws_tprg Ext_foo_overrides_Base_foo
schirmer@12854
   781
  show ?thesis
schirmer@12854
   782
    by (auto simp add: dynmethd_rec simp add: Ext_foo_def Base_foo_def)
schirmer@12854
   783
qed
schirmer@12854
   784
schirmer@12854
   785
lemma Base_fields_accessible[simp]:
schirmer@12854
   786
 "accfield tprg S Base 
schirmer@12854
   787
  = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (DeclConcepts.fields tprg Base))"
schirmer@12854
   788
apply (auto simp add: accfield_def expand_fun_eq Let_def 
schirmer@12854
   789
                      accessible_in_RefT_simp
schirmer@12854
   790
                      is_public_def
schirmer@12854
   791
                      BaseCl_def
schirmer@12854
   792
                      permits_acc_def
schirmer@12854
   793
                      declared_in_def 
schirmer@12854
   794
                      cdeclaredfield_def
schirmer@12854
   795
               intro!: filter_tab_all_True_Some filter_tab_None
schirmer@12925
   796
                       accessible_fromR.Immediate
schirmer@12854
   797
               intro: members.Immediate)
schirmer@12854
   798
done
schirmer@12854
   799
schirmer@12854
   800
schirmer@12854
   801
lemma arr_member_of_Base:
schirmer@12854
   802
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12854
   803
                 \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12854
   804
          member_of Base"
schirmer@12854
   805
by (auto intro: members.Immediate 
schirmer@12854
   806
       simp add: declared_in_def cdeclaredfield_def BaseCl_def)
schirmer@12854
   807
 
schirmer@12925
   808
lemma arr_member_in_Base:
schirmer@12925
   809
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12925
   810
                 \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12925
   811
          member_in Base"
schirmer@12925
   812
by (rule member_of_to_member_in [OF arr_member_of_Base])
schirmer@12925
   813
schirmer@12854
   814
lemma arr_member_of_Ext:
schirmer@12854
   815
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12854
   816
                    \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12854
   817
             member_of Ext"
schirmer@12854
   818
apply (rule members.Inherited)
schirmer@12854
   819
apply   (simp add: inheritable_in_def)
schirmer@12854
   820
apply   (simp add: undeclared_in_def cdeclaredfield_def ExtCl_def)
schirmer@12854
   821
apply   (auto intro: arr_member_of_Base simp add: subcls1_def ExtCl_def)
schirmer@12854
   822
done
schirmer@12854
   823
schirmer@12925
   824
lemma arr_member_in_Ext:
schirmer@12925
   825
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12925
   826
                 \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12925
   827
          member_in Ext"
schirmer@12925
   828
by (rule member_of_to_member_in [OF arr_member_of_Ext])
schirmer@12925
   829
schirmer@12854
   830
lemma Ext_fields_accessible[simp]:
schirmer@12854
   831
"accfield tprg S Ext 
schirmer@12854
   832
  = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (DeclConcepts.fields tprg Ext))"
schirmer@12854
   833
apply (auto simp add: accfield_def expand_fun_eq Let_def 
schirmer@12854
   834
                      accessible_in_RefT_simp
schirmer@12854
   835
                      is_public_def
schirmer@12854
   836
                      BaseCl_def
schirmer@12854
   837
                      ExtCl_def
schirmer@12854
   838
                      permits_acc_def
schirmer@12854
   839
               intro!: filter_tab_all_True_Some filter_tab_None
schirmer@12925
   840
                       accessible_fromR.Immediate)
schirmer@12854
   841
apply (auto intro: members.Immediate arr_member_of_Ext
schirmer@12854
   842
            simp add: declared_in_def cdeclaredfield_def ExtCl_def)
schirmer@12854
   843
done
schirmer@12854
   844
schirmer@12925
   845
lemma arr_Base_dyn_accessible [simp]:
schirmer@12925
   846
"tprg\<turnstile>(Base, fdecl (arr, \<lparr>access=Public,static=True ,type=PrimT Boolean.[]\<rparr>)) 
schirmer@12925
   847
       in Base dyn_accessible_from S"
schirmer@12925
   848
apply (rule dyn_accessible_fromR.Immediate)
schirmer@12925
   849
apply   (rule arr_member_in_Base)
schirmer@12925
   850
apply   (simp add: permits_acc_def)
schirmer@12925
   851
done
schirmer@12925
   852
schirmer@12925
   853
lemma arr_Ext_dyn_accessible[simp]:
schirmer@12925
   854
"tprg\<turnstile>(Base, fdecl (arr, \<lparr>access=Public,static=True ,type=PrimT Boolean.[]\<rparr>)) 
schirmer@12925
   855
       in Ext dyn_accessible_from S"
schirmer@12925
   856
apply (rule dyn_accessible_fromR.Immediate)
schirmer@12925
   857
apply   (rule arr_member_in_Ext)
schirmer@12925
   858
apply   (simp add: permits_acc_def)
schirmer@12925
   859
done
schirmer@12925
   860
schirmer@12854
   861
lemma array_of_PrimT_acc [simp]:
schirmer@12854
   862
 "is_acc_type tprg java_lang (PrimT t.[])"
schirmer@12854
   863
apply (simp add: is_acc_type_def accessible_in_RefT_simp)
schirmer@12854
   864
done
schirmer@12854
   865
schirmer@12854
   866
lemma PrimT_acc [simp]: 
schirmer@12854
   867
 "is_acc_type tprg java_lang (PrimT t)"
schirmer@12854
   868
apply (simp add: is_acc_type_def accessible_in_RefT_simp)
schirmer@12854
   869
done
schirmer@12854
   870
schirmer@12854
   871
lemma Object_acc [simp]:
schirmer@12854
   872
 "is_acc_class tprg java_lang Object"
schirmer@12854
   873
apply (auto simp add: is_acc_class_def accessible_in_RefT_simp is_public_def)
schirmer@12854
   874
done
schirmer@12854
   875
schirmer@12854
   876
schirmer@12854
   877
section "well-formedness"
schirmer@12854
   878
schirmer@12854
   879
schirmer@12854
   880
lemma wf_HasFoo: "wf_idecl tprg (HasFoo, HasFooInt)"
schirmer@12854
   881
apply (unfold wf_idecl_def HasFooInt_def)
schirmer@12854
   882
apply (auto intro!: wf_mheadI ws_idecl_HasFoo 
schirmer@12854
   883
            simp add: foo_sig_def foo_mhead_def mhead_resTy_simp
schirmer@12854
   884
                      member_is_static_simp )
schirmer@12854
   885
done
schirmer@12854
   886
schirmer@12925
   887
schirmer@12925
   888
declare member_is_static_simp [simp]
schirmer@12854
   889
declare wt.Skip [rule del] wt.Init [rule del]
schirmer@12854
   890
lemmas Base_foo_defs = Base_foo_def foo_sig_def foo_mhead_def
schirmer@12854
   891
lemmas Ext_foo_defs  = Ext_foo_def  foo_sig_def
schirmer@12854
   892
ML {* bind_thms ("wt_intros",map (rewrite_rule [id_def]) (thms "wt.intros")) *}
schirmer@12854
   893
lemmas wtIs = wt_Call wt_Super wt_FVar wt_StatRef wt_intros
schirmer@12854
   894
schirmer@12854
   895
lemma wf_Base_foo: "wf_mdecl tprg Base Base_foo"
schirmer@12854
   896
apply (unfold Base_foo_defs )
schirmer@12854
   897
apply (auto intro!: wf_mdeclI wf_mheadI intro!: wtIs
schirmer@12854
   898
            simp add: mhead_resTy_simp)
schirmer@12854
   899
done
schirmer@12854
   900
schirmer@12854
   901
lemma wf_Ext_foo: "wf_mdecl tprg Ext Ext_foo"
schirmer@12854
   902
apply (unfold Ext_foo_defs )
schirmer@12854
   903
apply (auto intro!: wf_mdeclI wf_mheadI intro!: wtIs 
schirmer@12854
   904
            simp add: mhead_resTy_simp )
schirmer@12854
   905
apply  (rule wt.Cast)
schirmer@12854
   906
prefer 2
schirmer@12854
   907
apply    simp
schirmer@12854
   908
apply   (rule_tac [2] narrow.subcls [THEN cast.narrow])
schirmer@12854
   909
apply   (auto intro!: wtIs)
schirmer@12854
   910
done
schirmer@12854
   911
schirmer@12854
   912
declare mhead_resTy_simp [simp add]
schirmer@12854
   913
declare member_is_static_simp [simp add]
schirmer@12854
   914
schirmer@12854
   915
lemma wf_BaseC: "wf_cdecl tprg (Base,BaseCl)"
schirmer@12854
   916
apply (unfold wf_cdecl_def BaseCl_def arr_viewed_from_def)
schirmer@12854
   917
apply (auto intro!: wf_Base_foo)
schirmer@12854
   918
apply       (auto intro!: ws_cdecl_Base simp add: Base_foo_def foo_mhead_def)
schirmer@12854
   919
apply (auto intro!: wtIs)
schirmer@12854
   920
apply (auto simp add: Base_foo_defs entails_def Let_def)
schirmer@12854
   921
apply   (insert Base_foo_no_stat_override, simp add: Base_foo_def,blast)+
schirmer@12854
   922
apply   (insert Base_foo_no_hide         , simp add: Base_foo_def,blast)
schirmer@12854
   923
done
schirmer@12854
   924
schirmer@12854
   925
schirmer@12854
   926
lemma wf_ExtC: "wf_cdecl tprg (Ext,ExtCl)"
schirmer@12854
   927
apply (unfold wf_cdecl_def ExtCl_def)
schirmer@12854
   928
apply (auto intro!: wf_Ext_foo ws_cdecl_Ext)
schirmer@12854
   929
apply (auto simp add: entails_def snd_special_simp)
schirmer@12854
   930
apply (insert Ext_foo_stat_override)
schirmer@12854
   931
apply  (force simp add: qmdecl_def Ext_foo_def Base_foo_def)
schirmer@12854
   932
apply  (force simp add: qmdecl_def Ext_foo_def Base_foo_def)
schirmer@12854
   933
apply  (force simp add: qmdecl_def Ext_foo_def Base_foo_def)
schirmer@12854
   934
apply (insert Ext_foo_no_hide)
schirmer@12854
   935
apply  (simp_all add: qmdecl_def)
schirmer@12854
   936
apply  blast+
schirmer@12854
   937
done
schirmer@12854
   938
schirmer@12925
   939
lemma wf_MainC: "wf_cdecl tprg (Main,MainCl)"
schirmer@12925
   940
apply (unfold wf_cdecl_def MainCl_def)
schirmer@12925
   941
apply (auto intro: ws_cdecl_Main)
schirmer@12925
   942
done
schirmer@12925
   943
schirmer@12854
   944
lemma wf_idecl_all: "p=tprg \<Longrightarrow> Ball (set Ifaces) (wf_idecl p)"
schirmer@12854
   945
apply (simp (no_asm) add: Ifaces_def)
schirmer@12854
   946
apply (simp (no_asm_simp))
schirmer@12854
   947
apply (rule wf_HasFoo)
schirmer@12854
   948
done
schirmer@12854
   949
schirmer@12854
   950
lemma wf_cdecl_all_standard_classes: 
schirmer@12854
   951
  "Ball (set standard_classes) (wf_cdecl tprg)"
schirmer@12854
   952
apply (unfold standard_classes_def Let_def 
schirmer@12854
   953
       ObjectC_def SXcptC_def Object_mdecls_def SXcpt_mdecls_def)
schirmer@12854
   954
apply (simp (no_asm) add: wf_cdecl_def ws_cdecls)
schirmer@12854
   955
apply (auto simp add:is_acc_class_def accessible_in_RefT_simp SXcpt_def)
schirmer@12854
   956
apply (auto simp add: Object_def Classes_def standard_classes_def 
schirmer@12854
   957
                      SXcptC_def SXcpt_def)
schirmer@12854
   958
done
schirmer@12854
   959
schirmer@12854
   960
lemma wf_cdecl_all: "p=tprg \<Longrightarrow> Ball (set Classes) (wf_cdecl p)"
schirmer@12854
   961
apply (simp (no_asm) add: Classes_def)
schirmer@12854
   962
apply (simp (no_asm_simp))
schirmer@12925
   963
apply    (rule wf_BaseC [THEN conjI])
schirmer@12925
   964
apply   (rule wf_ExtC [THEN conjI])
schirmer@12925
   965
apply  (rule wf_MainC [THEN conjI])
schirmer@12854
   966
apply (rule wf_cdecl_all_standard_classes)
schirmer@12854
   967
done
schirmer@12854
   968
schirmer@12854
   969
theorem wf_tprg: "wf_prog tprg"
schirmer@12854
   970
apply (unfold wf_prog_def Let_def)
schirmer@12854
   971
apply (simp (no_asm) add: unique_ifaces unique_classes)
schirmer@12854
   972
apply (rule conjI)
schirmer@12854
   973
apply  ((simp (no_asm) add: Classes_def standard_classes_def))
schirmer@12854
   974
apply (rule conjI)
schirmer@12854
   975
apply (simp add: Object_mdecls_def)
schirmer@12854
   976
apply safe
schirmer@12854
   977
apply  (cut_tac xn_cases_old)   (* FIXME (insert xn_cases) *)
schirmer@12854
   978
apply  (simp (no_asm_simp) add: Classes_def standard_classes_def)
schirmer@12854
   979
apply  (insert wf_idecl_all)
schirmer@12854
   980
apply  (insert wf_cdecl_all)
schirmer@12854
   981
apply  auto
schirmer@12854
   982
done
schirmer@12854
   983
schirmer@12854
   984
schirmer@12854
   985
section "max spec"
schirmer@12854
   986
schirmer@12854
   987
lemma appl_methds_Base_foo: 
schirmer@12854
   988
"appl_methds tprg S (ClassT Base) \<lparr>name=foo, parTs=[NT]\<rparr> =  
schirmer@12854
   989
  {((ClassT Base, \<lparr>access=Public,static=False,pars=[z],resT=Class Base\<rparr>)
schirmer@12854
   990
    ,[Class Base])}"
schirmer@12854
   991
apply (unfold appl_methds_def)
schirmer@12854
   992
apply (simp (no_asm))
schirmer@12854
   993
apply (subgoal_tac "tprg\<turnstile>NT\<preceq> Class Base")
schirmer@12854
   994
apply  (auto simp add: cmheads_def Base_foo_defs)
schirmer@12854
   995
done
schirmer@12854
   996
schirmer@12854
   997
lemma max_spec_Base_foo: "max_spec tprg S (ClassT Base) \<lparr>name=foo,parTs=[NT]\<rparr> = 
schirmer@12854
   998
  {((ClassT Base, \<lparr>access=Public,static=False,pars=[z],resT=Class Base\<rparr>)
schirmer@12854
   999
   , [Class Base])}"
schirmer@12854
  1000
apply (unfold max_spec_def)
schirmer@12854
  1001
apply (simp (no_asm) add: appl_methds_Base_foo)
schirmer@12854
  1002
apply auto
schirmer@12854
  1003
done
schirmer@12854
  1004
schirmer@12854
  1005
schirmer@12854
  1006
section "well-typedness"
schirmer@12854
  1007
schirmer@12925
  1008
lemma wt_test: "\<lparr>prg=tprg,cls=Main,lcl=empty(VName e\<mapsto>Class Base)\<rparr>\<turnstile>test ?pTs\<Colon>\<surd>"
schirmer@12854
  1009
apply (unfold test_def arr_viewed_from_def)
schirmer@12854
  1010
(* ?pTs = [Class Base] *)
schirmer@12854
  1011
apply (rule wtIs (* ;; *))
schirmer@12854
  1012
apply  (rule wtIs (* Ass *))
schirmer@12854
  1013
apply  (rule wtIs (* NewC *))
schirmer@12854
  1014
apply     (rule wtIs (* LVar *))
schirmer@12854
  1015
apply      (simp)
schirmer@12854
  1016
apply     (simp)
schirmer@12854
  1017
apply    (simp)
schirmer@12854
  1018
apply   (rule wtIs (* NewC *))
schirmer@12854
  1019
apply   (simp)
schirmer@12854
  1020
apply  (simp)
schirmer@12854
  1021
apply (rule wtIs (* Try *))
schirmer@12854
  1022
prefer 4
schirmer@12854
  1023
apply    (simp)
schirmer@12854
  1024
defer
schirmer@12854
  1025
apply    (rule wtIs (* Expr *))
schirmer@12854
  1026
apply    (rule wtIs (* Call *))
schirmer@12854
  1027
apply       (rule wtIs (* Acc *))
schirmer@12854
  1028
apply       (rule wtIs (* LVar *))
schirmer@12854
  1029
apply        (simp)
schirmer@12854
  1030
apply       (simp)
schirmer@12854
  1031
apply      (rule wtIs (* Cons *))
schirmer@12854
  1032
apply       (rule wtIs (* Lit *))
schirmer@12854
  1033
apply       (simp)
schirmer@12854
  1034
apply      (rule wtIs (* Nil *))
schirmer@12854
  1035
apply     (simp)
schirmer@12854
  1036
apply     (rule max_spec_Base_foo)
schirmer@12854
  1037
apply    (simp)
schirmer@12854
  1038
apply   (simp)
schirmer@12854
  1039
apply  (simp)
schirmer@12854
  1040
apply  (simp)
schirmer@12925
  1041
apply  (simp)
schirmer@12854
  1042
apply (rule wtIs (* While *))
schirmer@12854
  1043
apply  (rule wtIs (* Acc *))
schirmer@12854
  1044
apply   (rule wtIs (* AVar *))
schirmer@12854
  1045
apply   (rule wtIs (* Acc *))
schirmer@12854
  1046
apply   (rule wtIs (* FVar *))
schirmer@12854
  1047
apply    (rule wtIs (* StatRef *))
schirmer@12854
  1048
apply    (simp)
schirmer@12854
  1049
apply   (simp)
schirmer@12854
  1050
apply   (simp )
schirmer@12854
  1051
apply   (simp)
schirmer@12925
  1052
apply   (simp)
schirmer@12854
  1053
apply  (rule wtIs (* LVar *))
schirmer@12854
  1054
apply  (simp)
schirmer@12854
  1055
apply (rule wtIs (* Skip *))
schirmer@12854
  1056
done
schirmer@12854
  1057
schirmer@12854
  1058
schirmer@12854
  1059
section "execution"
schirmer@12854
  1060
schirmer@12854
  1061
lemma alloc_one: "\<And>a obj. \<lbrakk>the (new_Addr h) = a; atleast_free h (Suc n)\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1062
  new_Addr h = Some a \<and> atleast_free (h(a\<mapsto>obj)) n"
schirmer@12854
  1063
apply (frule atleast_free_SucD)
schirmer@12854
  1064
apply (drule atleast_free_Suc [THEN iffD1])
schirmer@12854
  1065
apply clarsimp
schirmer@12854
  1066
apply (frule new_Addr_SomeI)
schirmer@12854
  1067
apply force
schirmer@12854
  1068
done
schirmer@12854
  1069
schirmer@12854
  1070
declare fvar_def2 [simp] avar_def2 [simp] init_lvars_def2 [simp]
schirmer@12854
  1071
declare init_obj_def [simp] var_tys_def [simp] fields_table_def [simp]
schirmer@12854
  1072
declare BaseCl_def [simp] ExtCl_def [simp] Ext_foo_def [simp]
schirmer@12854
  1073
        Base_foo_defs  [simp]
schirmer@12854
  1074
schirmer@12854
  1075
ML {* bind_thms ("eval_intros", map 
schirmer@12854
  1076
        (simplify (simpset() delsimps [thm "Skip_eq"]
schirmer@12854
  1077
                             addsimps [thm "lvar_def"]) o 
schirmer@12854
  1078
         rewrite_rule [thm "assign_def",Let_def]) (thms "eval.intros")) *}
schirmer@12854
  1079
lemmas eval_Is = eval_Init eval_StatRef AbruptIs eval_intros
schirmer@12854
  1080
schirmer@12854
  1081
consts
schirmer@12854
  1082
  a :: loc
schirmer@12854
  1083
  b :: loc
schirmer@12854
  1084
  c :: loc
schirmer@12854
  1085
  
schirmer@12854
  1086
syntax
schirmer@12854
  1087
schirmer@12854
  1088
  tprg :: prog
schirmer@12854
  1089
schirmer@12854
  1090
  obj_a :: obj
schirmer@12854
  1091
  obj_b :: obj
schirmer@12854
  1092
  obj_c :: obj
schirmer@12854
  1093
  arr_N :: "(vn, val) table"
schirmer@12854
  1094
  arr_a :: "(vn, val) table"
schirmer@12854
  1095
  globs1 :: globs
schirmer@12854
  1096
  globs2 :: globs
schirmer@12854
  1097
  globs3 :: globs
schirmer@12854
  1098
  globs8 :: globs
schirmer@12854
  1099
  locs3 :: locals
schirmer@12854
  1100
  locs4 :: locals
schirmer@12854
  1101
  locs8 :: locals
schirmer@12854
  1102
  s0  :: state
schirmer@12854
  1103
  s0' :: state
schirmer@12854
  1104
  s9' :: state
schirmer@12854
  1105
  s1  :: state
schirmer@12854
  1106
  s1' :: state
schirmer@12854
  1107
  s2  :: state
schirmer@12854
  1108
  s2' :: state
schirmer@12854
  1109
  s3  :: state
schirmer@12854
  1110
  s3' :: state
schirmer@12854
  1111
  s4  :: state
schirmer@12854
  1112
  s4' :: state
schirmer@12854
  1113
  s6' :: state
schirmer@12854
  1114
  s7' :: state
schirmer@12854
  1115
  s8  :: state
schirmer@12854
  1116
  s8' :: state
schirmer@12854
  1117
schirmer@12854
  1118
translations
schirmer@12854
  1119
schirmer@12854
  1120
  "tprg"    == "\<lparr>ifaces=Ifaces,classes=Classes\<rparr>"
schirmer@12854
  1121
  
schirmer@12854
  1122
  "obj_a"   <= "\<lparr>tag=Arr (PrimT Boolean) two
schirmer@12854
  1123
                ,values=empty(Inr 0\<mapsto>Bool False)(Inr one\<mapsto>Bool False)\<rparr>"
schirmer@12854
  1124
  "obj_b"   <= "\<lparr>tag=CInst Ext
schirmer@12854
  1125
                ,values=(empty(Inl (vee, Base)\<mapsto>Null   ) 
schirmer@12854
  1126
			      (Inl (vee, Ext )\<mapsto>Intg 0))\<rparr>"
schirmer@12854
  1127
  "obj_c"   == "\<lparr>tag=CInst (SXcpt NullPointer),values=empty\<rparr>"
schirmer@12854
  1128
  "arr_N"   == "empty(Inl (arr, Base)\<mapsto>Null)"
schirmer@12854
  1129
  "arr_a"   == "empty(Inl (arr, Base)\<mapsto>Addr a)"
schirmer@12854
  1130
  "globs1"  == "empty(Inr Ext   \<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)
schirmer@12854
  1131
		     (Inr Base  \<mapsto>\<lparr>tag=arbitrary, values=arr_N\<rparr>)
schirmer@12854
  1132
		     (Inr Object\<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)"
schirmer@12854
  1133
  "globs2"  == "empty(Inr Ext   \<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)
schirmer@12854
  1134
		     (Inr Object\<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)
schirmer@12854
  1135
		     (Inl a\<mapsto>obj_a)
schirmer@12854
  1136
		     (Inr Base  \<mapsto>\<lparr>tag=arbitrary, values=arr_a\<rparr>)"
schirmer@12854
  1137
  "globs3"  == "globs2(Inl b\<mapsto>obj_b)"
schirmer@12854
  1138
  "globs8"  == "globs3(Inl c\<mapsto>obj_c)"
schirmer@12854
  1139
  "locs3"   == "empty(VName e\<mapsto>Addr b)"
schirmer@12854
  1140
  "locs4"   == "empty(VName z\<mapsto>Null)(Inr()\<mapsto>Addr b)"
schirmer@12854
  1141
  "locs8"   == "locs3(VName z\<mapsto>Addr c)"
schirmer@12854
  1142
  "s0"  == "       st empty  empty"
schirmer@12854
  1143
  "s0'" == " Norm  s0"
schirmer@12854
  1144
  "s1"  == "       st globs1 empty"
schirmer@12854
  1145
  "s1'" == " Norm  s1"
schirmer@12854
  1146
  "s2"  == "       st globs2 empty"
schirmer@12854
  1147
  "s2'" == " Norm  s2"
schirmer@12854
  1148
  "s3"  == "       st globs3 locs3 "
schirmer@12854
  1149
  "s3'" == " Norm  s3"
schirmer@12854
  1150
  "s4"  == "       st globs3 locs4"
schirmer@12854
  1151
  "s4'" == " Norm  s4"
schirmer@12854
  1152
  "s6'" == "(Some (Xcpt (Std NullPointer)), s4)"
schirmer@12854
  1153
  "s7'" == "(Some (Xcpt (Std NullPointer)), s3)"
schirmer@12854
  1154
  "s8"  == "       st globs8 locs8"
schirmer@12854
  1155
  "s8'" == " Norm  s8"
schirmer@12854
  1156
  "s9'" == "(Some (Xcpt (Std IndOutBound)), s8)"
schirmer@12854
  1157
schirmer@12854
  1158
schirmer@12854
  1159
syntax "four"::nat
schirmer@12854
  1160
       "tree"::nat
schirmer@12854
  1161
       "two" ::nat
schirmer@12854
  1162
       "one" ::nat
schirmer@12854
  1163
translations 
schirmer@12854
  1164
  "one"  == "Suc 0"
schirmer@12854
  1165
  "two"  == "Suc one"
schirmer@12854
  1166
  "tree" == "Suc two"
schirmer@12854
  1167
  "four" == "Suc tree"
schirmer@12854
  1168
schirmer@12854
  1169
declare Pair_eq [simp del]
schirmer@12854
  1170
lemma exec_test: 
schirmer@12854
  1171
"\<lbrakk>the (new_Addr (heap  s1)) = a;  
schirmer@12854
  1172
  the (new_Addr (heap ?s2)) = b;  
schirmer@12854
  1173
  the (new_Addr (heap ?s3)) = c\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1174
  atleast_free  (heap s0) four \<Longrightarrow>  
schirmer@12854
  1175
  tprg\<turnstile>s0' \<midarrow>test [Class Base]\<rightarrow> ?s9'"
schirmer@12854
  1176
apply (unfold test_def arr_viewed_from_def)
schirmer@12854
  1177
(* ?s9' = s9' *)
schirmer@12854
  1178
apply (simp (no_asm_use))
schirmer@12854
  1179
apply (drule (1) alloc_one,clarsimp)
schirmer@12854
  1180
apply (rule eval_Is (* ;; *))
schirmer@12854
  1181
apply  (erule_tac V = "the (new_Addr ?h) = c" in thin_rl)
schirmer@12854
  1182
apply  (erule_tac [2] V = "new_Addr ?h = Some a" in thin_rl)
schirmer@12854
  1183
apply  (erule_tac [2] V = "atleast_free ?h four" in thin_rl)
schirmer@12854
  1184
apply  (rule eval_Is (* Expr *))
schirmer@12854
  1185
apply  (rule eval_Is (* Ass *))
schirmer@12854
  1186
apply   (rule eval_Is (* LVar *))
schirmer@12854
  1187
apply  (rule eval_Is (* NewC *))
schirmer@12854
  1188
      (* begin init Ext *)
schirmer@12854
  1189
apply   (erule_tac V = "the (new_Addr ?h) = b" in thin_rl)
schirmer@12854
  1190
apply   (erule_tac V = "atleast_free ?h tree" in thin_rl)
schirmer@12854
  1191
apply   (erule_tac [2] V = "atleast_free ?h four" in thin_rl)
schirmer@12854
  1192
apply   (erule_tac [2] V = "new_Addr ?h = Some a" in thin_rl)
schirmer@12854
  1193
apply   (rule eval_Is (* Init Ext *))
schirmer@12854
  1194
apply   (simp)
schirmer@12854
  1195
apply   (rule conjI)
schirmer@12854
  1196
prefer 2 apply (rule conjI HOL.refl)+
schirmer@12854
  1197
apply   (rule eval_Is (* Init Base *))
schirmer@12854
  1198
apply   (simp add: arr_viewed_from_def)
schirmer@12854
  1199
apply   (rule conjI)
schirmer@12854
  1200
apply    (rule eval_Is (* Init Object *))
schirmer@12854
  1201
apply    (simp)
schirmer@12854
  1202
apply    (rule conjI, rule HOL.refl)+
schirmer@12854
  1203
apply    (rule HOL.refl)
schirmer@12854
  1204
apply   (simp)
schirmer@12854
  1205
apply   (rule conjI, rule_tac [2] HOL.refl)
schirmer@12854
  1206
apply   (rule eval_Is (* Expr *))
schirmer@12854
  1207
apply   (rule eval_Is (* Ass *))
schirmer@12854
  1208
apply    (rule eval_Is (* FVar *))
schirmer@12925
  1209
apply         (rule init_done, simp)
schirmer@12925
  1210
apply        (rule eval_Is (* StatRef *))
schirmer@12925
  1211
apply       (simp)
schirmer@12925
  1212
apply     (simp add: check_field_access_def Let_def) 
schirmer@12854
  1213
apply   (rule eval_Is (* NewA *))
schirmer@12854
  1214
apply     (simp)
schirmer@12854
  1215
apply    (rule eval_Is (* Lit *))
schirmer@12854
  1216
apply   (simp)
schirmer@12854
  1217
apply   (rule halloc.New)
schirmer@12854
  1218
apply    (simp (no_asm_simp))
schirmer@12854
  1219
apply   (drule atleast_free_weaken,rotate_tac -1,drule atleast_free_weaken)
schirmer@12854
  1220
apply   (simp (no_asm_simp))
schirmer@12854
  1221
apply  (simp add: upd_gobj_def)
schirmer@12854
  1222
      (* end init Ext *)
schirmer@12854
  1223
apply  (rule halloc.New)
schirmer@12854
  1224
apply   (drule alloc_one)
schirmer@12854
  1225
prefer 2 apply fast
schirmer@12854
  1226
apply   (simp (no_asm_simp))
schirmer@12854
  1227
apply  (drule atleast_free_weaken)
schirmer@12854
  1228
apply  force
schirmer@12854
  1229
apply (simp)
schirmer@12854
  1230
apply (drule alloc_one)
schirmer@12854
  1231
apply  (simp (no_asm_simp))
schirmer@12854
  1232
apply clarsimp
schirmer@12854
  1233
apply (erule_tac V = "atleast_free ?h tree" in thin_rl)
schirmer@12854
  1234
apply (drule_tac x = "a" in new_AddrD2 [THEN spec])
schirmer@12854
  1235
apply (simp (no_asm_use))
schirmer@12854
  1236
apply (rule eval_Is (* Try *))
schirmer@12854
  1237
apply   (rule eval_Is (* Expr *))
schirmer@12854
  1238
      (* begin method call *)
schirmer@12854
  1239
apply   (rule eval_Is (* Call *))
schirmer@12854
  1240
apply      (rule eval_Is (* Acc *))
schirmer@12854
  1241
apply      (rule eval_Is (* LVar *))
schirmer@12854
  1242
apply     (rule eval_Is (* Cons *))
schirmer@12854
  1243
apply      (rule eval_Is (* Lit *))
schirmer@12854
  1244
apply     (rule eval_Is (* Nil *))
schirmer@12854
  1245
apply    (simp)
schirmer@12925
  1246
apply    (simp)
schirmer@12925
  1247
apply    (subgoal_tac
schirmer@12925
  1248
             "tprg\<turnstile>(Ext,mdecl Ext_foo) in Ext dyn_accessible_from Main")
schirmer@12925
  1249
apply      (simp add: check_method_access_def Let_def
schirmer@12925
  1250
                      invocation_declclass_def dynlookup_def dynmethd_Ext_foo)
schirmer@12925
  1251
apply      (rule Ext_foo_dyn_accessible)
schirmer@12854
  1252
apply   (rule eval_Is (* Methd *))
schirmer@12854
  1253
apply   (simp add: body_def Let_def)
schirmer@12854
  1254
apply   (rule eval_Is (* Body *))
schirmer@12854
  1255
apply     (rule init_done, simp)
schirmer@12854
  1256
apply       (simp add: invocation_declclass_def dynlookup_def dynmethd_Ext_foo)
schirmer@12854
  1257
apply    (simp add: invocation_declclass_def dynlookup_def dynmethd_Ext_foo)
schirmer@12854
  1258
apply    (rule eval_Is (* Expr *))
schirmer@12854
  1259
apply    (rule eval_Is (* Ass *))
schirmer@12854
  1260
apply     (rule eval_Is (* FVar *))
schirmer@12854
  1261
apply       (rule init_done, simp)
schirmer@12854
  1262
apply      (rule eval_Is (* Cast *))
schirmer@12854
  1263
apply       (rule eval_Is (* Acc *))
schirmer@12854
  1264
apply       (rule eval_Is (* LVar *))
schirmer@12854
  1265
apply      (simp)
schirmer@12925
  1266
apply      (simp split del: split_if)
schirmer@12925
  1267
apply      (simp add: check_field_access_def Let_def)
schirmer@12854
  1268
apply    (rule eval_Is (* XcptE *))
schirmer@12854
  1269
apply   (simp)
schirmer@12854
  1270
      (* end method call *)
schirmer@12854
  1271
apply  (rule sxalloc.intros)
schirmer@12854
  1272
apply  (rule halloc.New)
schirmer@12854
  1273
apply   (erule alloc_one [THEN conjunct1])
schirmer@12854
  1274
apply   (simp (no_asm_simp))
schirmer@12854
  1275
apply  (simp (no_asm_simp))
schirmer@12854
  1276
apply (simp add: gupd_def lupd_def obj_ty_def split del: split_if)
schirmer@12854
  1277
apply (drule alloc_one [THEN conjunct1])
schirmer@12854
  1278
apply  (simp (no_asm_simp))
schirmer@12854
  1279
apply (erule_tac V = "atleast_free ?h two" in thin_rl)
schirmer@12854
  1280
apply (drule_tac x = "a" in new_AddrD2 [THEN spec])
schirmer@12854
  1281
apply simp
schirmer@12854
  1282
apply (rule eval_Is (* While *))
schirmer@12854
  1283
apply  (rule eval_Is (* Acc *))
schirmer@12854
  1284
apply  (rule eval_Is (* AVar *))
schirmer@12854
  1285
apply    (rule eval_Is (* Acc *))
schirmer@12854
  1286
apply    (rule eval_Is (* FVar *))
schirmer@12854
  1287
apply      (rule init_done, simp)
schirmer@12854
  1288
apply     (rule eval_Is (* StatRef *))
schirmer@12854
  1289
apply    (simp)
schirmer@12925
  1290
apply    (simp add: check_field_access_def Let_def)
schirmer@12854
  1291
apply   (rule eval_Is (* Lit *))
schirmer@12854
  1292
apply  (simp (no_asm_simp))
schirmer@12854
  1293
apply (auto simp add: in_bounds_def)
schirmer@12854
  1294
done
schirmer@12854
  1295
declare Pair_eq [simp]
schirmer@12854
  1296
schirmer@12854
  1297
end