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