src/HOL/Bali/Example.thy
author nipkow
Wed Jan 04 19:22:53 2006 +0100 (2006-01-04)
changeset 18576 8d98b7711e47
parent 18551 be0705186ff5
child 20769 5d538d3d5e2a
permissions -rw-r--r--
Reversed Larry's option/iff change.
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
schirmer@12854
    89
syntax
schirmer@12854
    90
schirmer@12854
    91
  HasFoo :: qtname
schirmer@12854
    92
  Base   :: qtname
schirmer@12854
    93
  Ext    :: qtname
schirmer@12925
    94
  Main   :: qtname
schirmer@12854
    95
  arr :: ename
schirmer@12854
    96
  vee :: ename
schirmer@12854
    97
  z   :: ename
schirmer@12854
    98
  e   :: ename
schirmer@12854
    99
  lab1:: label
schirmer@12854
   100
translations
schirmer@12854
   101
schirmer@12854
   102
  "HasFoo" == "\<lparr>pid=java_lang,tid=TName (tnam_ HasFoo_)\<rparr>"
schirmer@12854
   103
  "Base"   == "\<lparr>pid=java_lang,tid=TName (tnam_ Base_)\<rparr>"
schirmer@12854
   104
  "Ext"    == "\<lparr>pid=java_lang,tid=TName (tnam_ Ext_)\<rparr>"
schirmer@12925
   105
  "Main"   == "\<lparr>pid=java_lang,tid=TName (tnam_ Main_)\<rparr>"
schirmer@12854
   106
  "arr"    ==        "(vnam_ arr_)"
schirmer@12854
   107
  "vee"    ==        "(vnam_ vee_)"
schirmer@12854
   108
  "z"      ==        "(vnam_ z_)"
schirmer@12854
   109
  "e"      ==        "(vnam_ e_)"
schirmer@12854
   110
  "lab1"   ==        "label_ lab1_"
schirmer@12854
   111
schirmer@12854
   112
schirmer@12854
   113
lemma neq_Base_Object [simp]: "Base\<noteq>Object"
schirmer@12854
   114
by (simp add: Object_def)
schirmer@12854
   115
schirmer@12854
   116
lemma neq_Ext_Object [simp]: "Ext\<noteq>Object"
schirmer@12854
   117
by (simp add: Object_def)
schirmer@12854
   118
schirmer@12925
   119
lemma neq_Main_Object [simp]: "Main\<noteq>Object"
schirmer@12925
   120
by (simp add: Object_def)
schirmer@12925
   121
schirmer@12854
   122
lemma neq_Base_SXcpt [simp]: "Base\<noteq>SXcpt xn"
schirmer@12854
   123
by (simp add: SXcpt_def)
schirmer@12854
   124
schirmer@12854
   125
lemma neq_Ext_SXcpt [simp]: "Ext\<noteq>SXcpt xn"
schirmer@12854
   126
by (simp add: SXcpt_def)
schirmer@12854
   127
wenzelm@13524
   128
lemma neq_Main_SXcpt [simp]: "Main\<noteq>SXcpt xn"
schirmer@12925
   129
by (simp add: SXcpt_def)
schirmer@12925
   130
schirmer@12854
   131
section "classes and interfaces"
schirmer@12854
   132
schirmer@12854
   133
defs
schirmer@12854
   134
schirmer@12854
   135
  Object_mdecls_def: "Object_mdecls \<equiv> []"
schirmer@12854
   136
  SXcpt_mdecls_def:  "SXcpt_mdecls  \<equiv> []"
schirmer@12854
   137
schirmer@12854
   138
consts
schirmer@12854
   139
  
schirmer@12854
   140
  foo    :: mname
schirmer@12854
   141
schirmer@12854
   142
constdefs
schirmer@12854
   143
  
schirmer@12854
   144
  foo_sig   :: sig
schirmer@12854
   145
 "foo_sig   \<equiv> \<lparr>name=foo,parTs=[Class Base]\<rparr>"
schirmer@12854
   146
  
schirmer@12854
   147
  foo_mhead :: mhead
schirmer@12854
   148
 "foo_mhead \<equiv> \<lparr>access=Public,static=False,pars=[z],resT=Class Base\<rparr>"
schirmer@12854
   149
schirmer@12854
   150
constdefs
schirmer@12854
   151
  
schirmer@12854
   152
  Base_foo :: mdecl
schirmer@12854
   153
 "Base_foo \<equiv> (foo_sig, \<lparr>access=Public,static=False,pars=[z],resT=Class Base,
schirmer@12854
   154
                        mbody=\<lparr>lcls=[],stmt=Return (!!z)\<rparr>\<rparr>)"
schirmer@12925
   155
schirmer@12925
   156
constdefs
schirmer@12854
   157
  Ext_foo  :: mdecl
schirmer@12854
   158
 "Ext_foo  \<equiv> (foo_sig, 
schirmer@12854
   159
              \<lparr>access=Public,static=False,pars=[z],resT=Class Ext,
schirmer@12854
   160
	       mbody=\<lparr>lcls=[]
schirmer@12925
   161
                     ,stmt=Expr({Ext,Ext,False}Cast (Class Ext) (!!z)..vee := 
schirmer@13688
   162
       	                                                     Lit (Intg 1)) ;;
schirmer@13688
   163
                                Return (Lit Null)\<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
haftmann@18551
   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
  
haftmann@18551
   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
haftmann@18551
   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@12854
   690
lemma Ext_foo_member_of_Ext: 
schirmer@12854
   691
  "tprg\<turnstile>(Ext,mdecl Ext_foo) member_of Ext"
schirmer@12854
   692
by (auto intro!: members.Immediate Ext_declares_foo)
schirmer@12854
   693
schirmer@12925
   694
lemma Ext_foo_member_in_Ext: 
schirmer@12925
   695
  "tprg\<turnstile>(Ext,mdecl Ext_foo) member_in Ext"
schirmer@12925
   696
by (rule member_of_to_member_in [OF Ext_foo_member_of_Ext])
schirmer@12925
   697
schirmer@12854
   698
lemma Base_foo_permits_acc:
schirmer@14030
   699
 "tprg \<turnstile> (Base, mdecl Base_foo) in Base permits_acc_from S"
schirmer@12854
   700
by ( simp add: permits_acc_def Base_foo_def)
schirmer@12854
   701
schirmer@12854
   702
lemma Base_foo_accessible [simp]:
schirmer@12854
   703
 "tprg\<turnstile>(Base,mdecl Base_foo) of Base accessible_from S"
schirmer@12925
   704
by (auto intro: accessible_fromR.Immediate 
schirmer@12854
   705
                Base_foo_member_of_Base Base_foo_permits_acc)
schirmer@12854
   706
schirmer@12925
   707
lemma Base_foo_dyn_accessible [simp]:
schirmer@12925
   708
 "tprg\<turnstile>(Base,mdecl Base_foo) in Base dyn_accessible_from S"
schirmer@12925
   709
apply (rule dyn_accessible_fromR.Immediate)
schirmer@12925
   710
apply   (rule Base_foo_member_in_Base)
schirmer@12925
   711
apply   (rule Base_foo_permits_acc)
schirmer@12925
   712
done
schirmer@12925
   713
schirmer@12854
   714
lemma accmethd_Base [simp]: 
schirmer@12854
   715
  "accmethd tprg S Base = methd tprg Base"
schirmer@12854
   716
apply (simp add: accmethd_def)
schirmer@12854
   717
apply (rule filter_tab_all_True)
schirmer@12854
   718
apply (simp add: snd_special_simp fst_special_simp)
schirmer@12854
   719
done
schirmer@12854
   720
schirmer@12854
   721
lemma Ext_foo_permits_acc:
schirmer@14030
   722
 "tprg \<turnstile> (Ext, mdecl Ext_foo) in Ext permits_acc_from S"
schirmer@12854
   723
by ( simp add: permits_acc_def Ext_foo_def)
schirmer@12854
   724
schirmer@12854
   725
lemma Ext_foo_accessible [simp]:
schirmer@12854
   726
 "tprg\<turnstile>(Ext,mdecl Ext_foo) of Ext accessible_from S"
schirmer@12925
   727
by (auto intro: accessible_fromR.Immediate 
schirmer@12854
   728
                Ext_foo_member_of_Ext Ext_foo_permits_acc)
schirmer@12854
   729
schirmer@12925
   730
lemma Ext_foo_dyn_accessible [simp]:
schirmer@12925
   731
 "tprg\<turnstile>(Ext,mdecl Ext_foo) in Ext dyn_accessible_from S"
schirmer@12925
   732
apply (rule dyn_accessible_fromR.Immediate) 
schirmer@12925
   733
apply   (rule Ext_foo_member_in_Ext)
schirmer@12925
   734
apply   (rule Ext_foo_permits_acc)
schirmer@12854
   735
done
schirmer@12854
   736
schirmer@12854
   737
lemma Ext_foo_overrides_Base_foo:
schirmer@12854
   738
 "tprg\<turnstile>(Ext,Ext_foo) overrides (Base,Base_foo)"
schirmer@12854
   739
proof (rule overridesR.Direct, simp_all)
schirmer@12854
   740
  show "\<not> is_static Ext_foo" 
schirmer@12854
   741
    by (simp add: member_is_static_simp Ext_foo_def)
schirmer@12854
   742
  show "\<not> is_static Base_foo"
schirmer@12854
   743
    by (simp add: member_is_static_simp Base_foo_def)
schirmer@12854
   744
  show "accmodi Ext_foo \<noteq> Private"
schirmer@12854
   745
    by (simp add: Ext_foo_def)
schirmer@12854
   746
  show "msig (Ext, Ext_foo) = msig (Base, Base_foo)"
schirmer@12854
   747
    by (simp add: Ext_foo_def Base_foo_def)
schirmer@12854
   748
  show "tprg\<turnstile>mdecl Ext_foo declared_in Ext"
schirmer@12854
   749
    by (auto intro: Ext_declares_foo)
schirmer@12854
   750
  show "tprg\<turnstile>mdecl Base_foo declared_in Base"
schirmer@12854
   751
    by (auto intro: Base_declares_foo)
schirmer@12854
   752
  show "tprg \<turnstile>(Base, mdecl Base_foo) inheritable_in java_lang"
schirmer@12854
   753
    by (simp add: inheritable_in_def Base_foo_def)
schirmer@12854
   754
  show "tprg\<turnstile>resTy Ext_foo\<preceq>resTy Base_foo"
schirmer@12854
   755
    by (simp add: Ext_foo_def Base_foo_def mhead_resTy_simp)
schirmer@12854
   756
qed
schirmer@12854
   757
schirmer@12854
   758
lemma accmethd_Ext [simp]: 
schirmer@12854
   759
  "accmethd tprg S Ext = methd tprg Ext"
schirmer@12854
   760
apply (simp add: accmethd_def)
schirmer@12854
   761
apply (rule filter_tab_all_True)
schirmer@12854
   762
apply (auto simp add: snd_special_simp fst_special_simp)
schirmer@12854
   763
done
schirmer@12854
   764
schirmer@12854
   765
lemma cls_Ext: "class tprg Ext = Some ExtCl"
schirmer@12854
   766
by simp
schirmer@12854
   767
lemma dynmethd_Ext_foo:
schirmer@12854
   768
 "dynmethd tprg Base Ext \<lparr>name = foo, parTs = [Class Base]\<rparr> 
schirmer@12854
   769
  = Some (Ext,snd Ext_foo)"
schirmer@12854
   770
proof -
schirmer@12854
   771
  have "methd tprg Base \<lparr>name = foo, parTs = [Class Base]\<rparr> 
schirmer@12854
   772
          = Some (Base,snd Base_foo)" and
schirmer@12854
   773
       "methd tprg Ext \<lparr>name = foo, parTs = [Class Base]\<rparr> 
schirmer@12854
   774
          = Some (Ext,snd Ext_foo)" 
schirmer@12854
   775
    by (auto simp add: Ext_foo_def Base_foo_def foo_sig_def)
schirmer@12854
   776
  with cls_Ext ws_tprg Ext_foo_overrides_Base_foo
schirmer@12854
   777
  show ?thesis
schirmer@12854
   778
    by (auto simp add: dynmethd_rec simp add: Ext_foo_def Base_foo_def)
schirmer@12854
   779
qed
schirmer@12854
   780
schirmer@12854
   781
lemma Base_fields_accessible[simp]:
schirmer@12854
   782
 "accfield tprg S Base 
schirmer@12854
   783
  = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (DeclConcepts.fields tprg Base))"
schirmer@12854
   784
apply (auto simp add: accfield_def expand_fun_eq Let_def 
schirmer@12854
   785
                      accessible_in_RefT_simp
schirmer@12854
   786
                      is_public_def
schirmer@12854
   787
                      BaseCl_def
schirmer@12854
   788
                      permits_acc_def
schirmer@12854
   789
                      declared_in_def 
schirmer@12854
   790
                      cdeclaredfield_def
schirmer@12854
   791
               intro!: filter_tab_all_True_Some filter_tab_None
schirmer@12925
   792
                       accessible_fromR.Immediate
schirmer@12854
   793
               intro: members.Immediate)
schirmer@12854
   794
done
schirmer@12854
   795
schirmer@12854
   796
schirmer@12854
   797
lemma arr_member_of_Base:
schirmer@12854
   798
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12854
   799
                 \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12854
   800
          member_of Base"
schirmer@12854
   801
by (auto intro: members.Immediate 
schirmer@12854
   802
       simp add: declared_in_def cdeclaredfield_def BaseCl_def)
schirmer@12854
   803
 
schirmer@12925
   804
lemma arr_member_in_Base:
schirmer@12925
   805
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12925
   806
                 \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12925
   807
          member_in Base"
schirmer@12925
   808
by (rule member_of_to_member_in [OF arr_member_of_Base])
schirmer@12925
   809
schirmer@12854
   810
lemma arr_member_of_Ext:
schirmer@12854
   811
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12854
   812
                    \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12854
   813
             member_of Ext"
schirmer@12854
   814
apply (rule members.Inherited)
schirmer@12854
   815
apply   (simp add: inheritable_in_def)
schirmer@12854
   816
apply   (simp add: undeclared_in_def cdeclaredfield_def ExtCl_def)
schirmer@12854
   817
apply   (auto intro: arr_member_of_Base simp add: subcls1_def ExtCl_def)
schirmer@12854
   818
done
schirmer@12854
   819
schirmer@12925
   820
lemma arr_member_in_Ext:
schirmer@12925
   821
  "tprg\<turnstile>(Base, fdecl (arr, 
schirmer@12925
   822
                 \<lparr>access = Public, static = True, type = PrimT Boolean.[]\<rparr>))
schirmer@12925
   823
          member_in Ext"
schirmer@12925
   824
by (rule member_of_to_member_in [OF arr_member_of_Ext])
schirmer@12925
   825
schirmer@12854
   826
lemma Ext_fields_accessible[simp]:
schirmer@12854
   827
"accfield tprg S Ext 
schirmer@12854
   828
  = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (DeclConcepts.fields tprg Ext))"
schirmer@12854
   829
apply (auto simp add: accfield_def expand_fun_eq Let_def 
schirmer@12854
   830
                      accessible_in_RefT_simp
schirmer@12854
   831
                      is_public_def
schirmer@12854
   832
                      BaseCl_def
schirmer@12854
   833
                      ExtCl_def
schirmer@12854
   834
                      permits_acc_def
schirmer@12854
   835
               intro!: filter_tab_all_True_Some filter_tab_None
schirmer@12925
   836
                       accessible_fromR.Immediate)
schirmer@12854
   837
apply (auto intro: members.Immediate arr_member_of_Ext
schirmer@12854
   838
            simp add: declared_in_def cdeclaredfield_def ExtCl_def)
schirmer@12854
   839
done
schirmer@12854
   840
schirmer@12925
   841
lemma arr_Base_dyn_accessible [simp]:
schirmer@12925
   842
"tprg\<turnstile>(Base, fdecl (arr, \<lparr>access=Public,static=True ,type=PrimT Boolean.[]\<rparr>)) 
schirmer@12925
   843
       in Base dyn_accessible_from S"
schirmer@12925
   844
apply (rule dyn_accessible_fromR.Immediate)
schirmer@12925
   845
apply   (rule arr_member_in_Base)
schirmer@12925
   846
apply   (simp add: permits_acc_def)
schirmer@12925
   847
done
schirmer@12925
   848
schirmer@12925
   849
lemma arr_Ext_dyn_accessible[simp]:
schirmer@12925
   850
"tprg\<turnstile>(Base, fdecl (arr, \<lparr>access=Public,static=True ,type=PrimT Boolean.[]\<rparr>)) 
schirmer@12925
   851
       in Ext dyn_accessible_from S"
schirmer@12925
   852
apply (rule dyn_accessible_fromR.Immediate)
schirmer@12925
   853
apply   (rule arr_member_in_Ext)
schirmer@12925
   854
apply   (simp add: permits_acc_def)
schirmer@12925
   855
done
schirmer@12925
   856
schirmer@12854
   857
lemma array_of_PrimT_acc [simp]:
schirmer@12854
   858
 "is_acc_type tprg java_lang (PrimT t.[])"
schirmer@12854
   859
apply (simp add: is_acc_type_def accessible_in_RefT_simp)
schirmer@12854
   860
done
schirmer@12854
   861
schirmer@12854
   862
lemma PrimT_acc [simp]: 
schirmer@12854
   863
 "is_acc_type tprg java_lang (PrimT t)"
schirmer@12854
   864
apply (simp add: is_acc_type_def accessible_in_RefT_simp)
schirmer@12854
   865
done
schirmer@12854
   866
schirmer@12854
   867
lemma Object_acc [simp]:
schirmer@12854
   868
 "is_acc_class tprg java_lang Object"
schirmer@12854
   869
apply (auto simp add: is_acc_class_def accessible_in_RefT_simp is_public_def)
schirmer@12854
   870
done
schirmer@12854
   871
schirmer@12854
   872
schirmer@12854
   873
section "well-formedness"
schirmer@12854
   874
schirmer@12854
   875
schirmer@12854
   876
lemma wf_HasFoo: "wf_idecl tprg (HasFoo, HasFooInt)"
schirmer@12854
   877
apply (unfold wf_idecl_def HasFooInt_def)
schirmer@12854
   878
apply (auto intro!: wf_mheadI ws_idecl_HasFoo 
schirmer@12854
   879
            simp add: foo_sig_def foo_mhead_def mhead_resTy_simp
schirmer@12854
   880
                      member_is_static_simp )
schirmer@12854
   881
done
schirmer@12854
   882
schirmer@12925
   883
schirmer@12925
   884
declare member_is_static_simp [simp]
schirmer@12854
   885
declare wt.Skip [rule del] wt.Init [rule del]
schirmer@13688
   886
ML {* bind_thms ("wt_intros",map (rewrite_rule [id_def]) (thms "wt.intros")) *}
schirmer@13688
   887
lemmas wtIs = wt_Call wt_Super wt_FVar wt_StatRef wt_intros
schirmer@13688
   888
lemmas daIs = assigned.select_convs da_Skip da_NewC da_Lit da_Super da.intros
schirmer@13688
   889
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@13688
   892
schirmer@13688
   893
schirmer@13688
   894
schirmer@12854
   895
schirmer@12854
   896
lemma wf_Base_foo: "wf_mdecl tprg Base Base_foo"
schirmer@12854
   897
apply (unfold Base_foo_defs )
schirmer@13688
   898
apply (auto intro!: wf_mdeclI wf_mheadI intro!: wtIs 
schirmer@12854
   899
            simp add: mhead_resTy_simp)
schirmer@13688
   900
(* for definite assignment *)
schirmer@13688
   901
apply (rule exI)
schirmer@13688
   902
apply (simp add: parameters_def)
schirmer@13688
   903
apply (rule conjI)
schirmer@13688
   904
apply  (rule da.Comp)
schirmer@13688
   905
apply     (rule da.Expr)
schirmer@13688
   906
apply     (rule da.AssLVar)
schirmer@13688
   907
apply       (rule da.AccLVar)
schirmer@13688
   908
apply         (simp)
schirmer@13688
   909
apply        (rule assigned.select_convs)
schirmer@13688
   910
apply       (simp)
schirmer@13688
   911
apply      (rule assigned.select_convs)
schirmer@13688
   912
apply     (simp)
schirmer@13688
   913
apply    (simp)
schirmer@13688
   914
apply    (rule da.Jmp)
schirmer@13688
   915
apply      (simp)
schirmer@13688
   916
apply     (rule assigned.select_convs)
schirmer@13688
   917
apply    (simp)
schirmer@13688
   918
apply   (rule assigned.select_convs)
schirmer@13688
   919
apply  (simp)
schirmer@13688
   920
apply (simp)
schirmer@12854
   921
done
schirmer@12854
   922
schirmer@13688
   923
schirmer@12854
   924
lemma wf_Ext_foo: "wf_mdecl tprg Ext Ext_foo"
schirmer@12854
   925
apply (unfold Ext_foo_defs )
schirmer@12854
   926
apply (auto intro!: wf_mdeclI wf_mheadI intro!: wtIs 
schirmer@12854
   927
            simp add: mhead_resTy_simp )
schirmer@12854
   928
apply  (rule wt.Cast)
schirmer@12854
   929
prefer 2
schirmer@12854
   930
apply    simp
schirmer@12854
   931
apply   (rule_tac [2] narrow.subcls [THEN cast.narrow])
schirmer@12854
   932
apply   (auto intro!: wtIs)
schirmer@13688
   933
(* for definite assignment *)
schirmer@13688
   934
apply (rule exI)
schirmer@13688
   935
apply (simp add: parameters_def)
schirmer@13688
   936
apply (rule conjI)
schirmer@13688
   937
apply  (rule da.Comp)
schirmer@13688
   938
apply     (rule da.Expr)
schirmer@13688
   939
apply     (rule da.Ass)   
schirmer@13688
   940
apply       simp
schirmer@13688
   941
apply      (rule da.FVar)
schirmer@13688
   942
apply      (rule da.Cast)
schirmer@13688
   943
apply      (rule da.AccLVar)
schirmer@13688
   944
apply        simp
schirmer@13688
   945
apply       (rule assigned.select_convs)
schirmer@13688
   946
apply      simp
schirmer@13688
   947
apply     (rule da_Lit)
schirmer@13688
   948
apply     (simp)
schirmer@13688
   949
apply    (rule da.Comp)
schirmer@13688
   950
apply       (rule da.Expr)
schirmer@13688
   951
apply       (rule da.AssLVar)
schirmer@13688
   952
apply         (rule da.Lit)                  
schirmer@13688
   953
apply        (rule assigned.select_convs)
schirmer@13688
   954
apply       simp
schirmer@13688
   955
apply      (rule da.Jmp)
schirmer@13688
   956
apply        simp
schirmer@13688
   957
apply       (rule assigned.select_convs)
schirmer@13688
   958
apply      simp
schirmer@13688
   959
apply     (rule assigned.select_convs)
schirmer@13688
   960
apply    (simp)
schirmer@13688
   961
apply   (rule assigned.select_convs)
schirmer@13688
   962
apply  simp
schirmer@13688
   963
apply simp
schirmer@12854
   964
done
schirmer@12854
   965
schirmer@12854
   966
declare mhead_resTy_simp [simp add]
schirmer@12854
   967
declare member_is_static_simp [simp add]
schirmer@12854
   968
schirmer@12854
   969
lemma wf_BaseC: "wf_cdecl tprg (Base,BaseCl)"
schirmer@12854
   970
apply (unfold wf_cdecl_def BaseCl_def arr_viewed_from_def)
schirmer@12854
   971
apply (auto intro!: wf_Base_foo)
schirmer@13688
   972
apply        (auto intro!: ws_cdecl_Base simp add: Base_foo_def foo_mhead_def)
schirmer@13688
   973
apply   (auto intro!: wtIs)
schirmer@13688
   974
(* for definite assignment *)
schirmer@13688
   975
apply   (rule exI)
schirmer@13688
   976
apply   (rule da.Expr)
schirmer@13688
   977
apply  (rule da.Ass)
schirmer@13688
   978
apply    (simp)
schirmer@13688
   979
apply   (rule da.FVar)
schirmer@13688
   980
apply   (rule da.Cast)
schirmer@13688
   981
apply   (rule da_Lit)
schirmer@13688
   982
apply   simp
schirmer@13688
   983
apply  (rule da.NewA)
schirmer@13688
   984
apply  (rule da.Lit)
schirmer@12854
   985
apply (auto simp add: Base_foo_defs entails_def Let_def)
schirmer@12854
   986
apply   (insert Base_foo_no_stat_override, simp add: Base_foo_def,blast)+
schirmer@13688
   987
apply (insert Base_foo_no_hide         , simp add: Base_foo_def,blast)
schirmer@12854
   988
done
schirmer@12854
   989
schirmer@12854
   990
schirmer@12854
   991
lemma wf_ExtC: "wf_cdecl tprg (Ext,ExtCl)"
schirmer@12854
   992
apply (unfold wf_cdecl_def ExtCl_def)
schirmer@12854
   993
apply (auto intro!: wf_Ext_foo ws_cdecl_Ext)
schirmer@13688
   994
apply  (auto simp add: entails_def snd_special_simp)
schirmer@13688
   995
apply      (insert Ext_foo_stat_override)
schirmer@13688
   996
apply      (rule exI,rule da.Skip)      
schirmer@13688
   997
apply     (force simp add: qmdecl_def Ext_foo_def Base_foo_def)
schirmer@13688
   998
apply    (force simp add: qmdecl_def Ext_foo_def Base_foo_def)
schirmer@13688
   999
apply   (force simp add: qmdecl_def Ext_foo_def Base_foo_def)
schirmer@13688
  1000
apply  (insert Ext_foo_no_hide)
schirmer@12854
  1001
apply  (simp_all add: qmdecl_def)
schirmer@12854
  1002
apply  blast+
schirmer@12854
  1003
done
schirmer@12854
  1004
schirmer@12925
  1005
lemma wf_MainC: "wf_cdecl tprg (Main,MainCl)"
schirmer@12925
  1006
apply (unfold wf_cdecl_def MainCl_def)
schirmer@12925
  1007
apply (auto intro: ws_cdecl_Main)
schirmer@13688
  1008
apply (rule exI,rule da.Skip)
schirmer@12925
  1009
done
schirmer@12925
  1010
schirmer@12854
  1011
lemma wf_idecl_all: "p=tprg \<Longrightarrow> Ball (set Ifaces) (wf_idecl p)"
schirmer@12854
  1012
apply (simp (no_asm) add: Ifaces_def)
schirmer@12854
  1013
apply (simp (no_asm_simp))
schirmer@12854
  1014
apply (rule wf_HasFoo)
schirmer@12854
  1015
done
schirmer@12854
  1016
schirmer@12854
  1017
lemma wf_cdecl_all_standard_classes: 
schirmer@12854
  1018
  "Ball (set standard_classes) (wf_cdecl tprg)"
schirmer@12854
  1019
apply (unfold standard_classes_def Let_def 
schirmer@12854
  1020
       ObjectC_def SXcptC_def Object_mdecls_def SXcpt_mdecls_def)
nipkow@18576
  1021
apply (simp (no_asm) add: wf_cdecl_def ws_cdecls)
schirmer@13688
  1022
apply (auto simp add:is_acc_class_def accessible_in_RefT_simp SXcpt_def 
schirmer@13688
  1023
            intro: da.Skip)
schirmer@12854
  1024
apply (auto simp add: Object_def Classes_def standard_classes_def 
schirmer@12854
  1025
                      SXcptC_def SXcpt_def)
schirmer@12854
  1026
done
schirmer@12854
  1027
schirmer@12854
  1028
lemma wf_cdecl_all: "p=tprg \<Longrightarrow> Ball (set Classes) (wf_cdecl p)"
schirmer@12854
  1029
apply (simp (no_asm) add: Classes_def)
schirmer@12854
  1030
apply (simp (no_asm_simp))
schirmer@12925
  1031
apply    (rule wf_BaseC [THEN conjI])
schirmer@12925
  1032
apply   (rule wf_ExtC [THEN conjI])
schirmer@12925
  1033
apply  (rule wf_MainC [THEN conjI])
schirmer@12854
  1034
apply (rule wf_cdecl_all_standard_classes)
schirmer@12854
  1035
done
schirmer@12854
  1036
schirmer@12854
  1037
theorem wf_tprg: "wf_prog tprg"
schirmer@12854
  1038
apply (unfold wf_prog_def Let_def)
schirmer@12854
  1039
apply (simp (no_asm) add: unique_ifaces unique_classes)
schirmer@12854
  1040
apply (rule conjI)
schirmer@12854
  1041
apply  ((simp (no_asm) add: Classes_def standard_classes_def))
schirmer@12854
  1042
apply (rule conjI)
schirmer@12854
  1043
apply (simp add: Object_mdecls_def)
schirmer@12854
  1044
apply safe
schirmer@13688
  1045
apply  (cut_tac xn_cases)   
schirmer@12854
  1046
apply  (simp (no_asm_simp) add: Classes_def standard_classes_def)
schirmer@12854
  1047
apply  (insert wf_idecl_all)
schirmer@12854
  1048
apply  (insert wf_cdecl_all)
schirmer@12854
  1049
apply  auto
schirmer@12854
  1050
done
schirmer@12854
  1051
schirmer@12854
  1052
section "max spec"
schirmer@12854
  1053
schirmer@12854
  1054
lemma appl_methds_Base_foo: 
schirmer@12854
  1055
"appl_methds tprg S (ClassT Base) \<lparr>name=foo, parTs=[NT]\<rparr> =  
schirmer@12854
  1056
  {((ClassT Base, \<lparr>access=Public,static=False,pars=[z],resT=Class Base\<rparr>)
schirmer@12854
  1057
    ,[Class Base])}"
schirmer@12854
  1058
apply (unfold appl_methds_def)
schirmer@12854
  1059
apply (simp (no_asm))
schirmer@12854
  1060
apply (subgoal_tac "tprg\<turnstile>NT\<preceq> Class Base")
schirmer@12854
  1061
apply  (auto simp add: cmheads_def Base_foo_defs)
schirmer@12854
  1062
done
schirmer@12854
  1063
schirmer@12854
  1064
lemma max_spec_Base_foo: "max_spec tprg S (ClassT Base) \<lparr>name=foo,parTs=[NT]\<rparr> = 
schirmer@12854
  1065
  {((ClassT Base, \<lparr>access=Public,static=False,pars=[z],resT=Class Base\<rparr>)
schirmer@12854
  1066
   , [Class Base])}"
schirmer@12854
  1067
apply (unfold max_spec_def)
schirmer@12854
  1068
apply (simp (no_asm) add: appl_methds_Base_foo)
schirmer@12854
  1069
apply auto
schirmer@12854
  1070
done
schirmer@12854
  1071
schirmer@12854
  1072
section "well-typedness"
schirmer@12854
  1073
schirmer@12925
  1074
lemma wt_test: "\<lparr>prg=tprg,cls=Main,lcl=empty(VName e\<mapsto>Class Base)\<rparr>\<turnstile>test ?pTs\<Colon>\<surd>"
schirmer@12854
  1075
apply (unfold test_def arr_viewed_from_def)
schirmer@12854
  1076
(* ?pTs = [Class Base] *)
schirmer@12854
  1077
apply (rule wtIs (* ;; *))
schirmer@12854
  1078
apply  (rule wtIs (* Ass *))
schirmer@12854
  1079
apply  (rule wtIs (* NewC *))
schirmer@12854
  1080
apply     (rule wtIs (* LVar *))
schirmer@12854
  1081
apply      (simp)
schirmer@12854
  1082
apply     (simp)
schirmer@12854
  1083
apply    (simp)
schirmer@12854
  1084
apply   (rule wtIs (* NewC *))
schirmer@12854
  1085
apply   (simp)
schirmer@12854
  1086
apply  (simp)
schirmer@12854
  1087
apply (rule wtIs (* Try *))
schirmer@12854
  1088
prefer 4
schirmer@12854
  1089
apply    (simp)
schirmer@12854
  1090
defer
schirmer@12854
  1091
apply    (rule wtIs (* Expr *))
schirmer@12854
  1092
apply    (rule wtIs (* Call *))
schirmer@12854
  1093
apply       (rule wtIs (* Acc *))
schirmer@12854
  1094
apply       (rule wtIs (* LVar *))
schirmer@12854
  1095
apply        (simp)
schirmer@12854
  1096
apply       (simp)
schirmer@12854
  1097
apply      (rule wtIs (* Cons *))
schirmer@12854
  1098
apply       (rule wtIs (* Lit *))
schirmer@12854
  1099
apply       (simp)
schirmer@12854
  1100
apply      (rule wtIs (* Nil *))
schirmer@12854
  1101
apply     (simp)
schirmer@12854
  1102
apply     (rule max_spec_Base_foo)
schirmer@12854
  1103
apply    (simp)
schirmer@12854
  1104
apply   (simp)
schirmer@12854
  1105
apply  (simp)
schirmer@12854
  1106
apply  (simp)
schirmer@12925
  1107
apply  (simp)
schirmer@12854
  1108
apply (rule wtIs (* While *))
schirmer@12854
  1109
apply  (rule wtIs (* Acc *))
schirmer@12854
  1110
apply   (rule wtIs (* AVar *))
schirmer@12854
  1111
apply   (rule wtIs (* Acc *))
schirmer@12854
  1112
apply   (rule wtIs (* FVar *))
schirmer@12854
  1113
apply    (rule wtIs (* StatRef *))
schirmer@12854
  1114
apply    (simp)
schirmer@12854
  1115
apply   (simp)
schirmer@12854
  1116
apply   (simp )
schirmer@12854
  1117
apply   (simp)
schirmer@12925
  1118
apply   (simp)
schirmer@12854
  1119
apply  (rule wtIs (* LVar *))
schirmer@12854
  1120
apply  (simp)
schirmer@12854
  1121
apply (rule wtIs (* Skip *))
schirmer@12854
  1122
done
schirmer@12854
  1123
schirmer@13688
  1124
section "definite assignment"
schirmer@13688
  1125
schirmer@13688
  1126
lemma da_test: "\<lparr>prg=tprg,cls=Main,lcl=empty(VName e\<mapsto>Class Base)\<rparr>
schirmer@13688
  1127
                  \<turnstile>{} \<guillemotright>\<langle>test ?pTs\<rangle>\<guillemotright> \<lparr>nrm={VName e},brk=\<lambda> l. UNIV\<rparr>"
schirmer@13688
  1128
apply (unfold test_def arr_viewed_from_def)
schirmer@13688
  1129
apply (rule da.Comp)
schirmer@13688
  1130
apply    (rule da.Expr)
schirmer@13688
  1131
apply    (rule da.AssLVar)
schirmer@13688
  1132
apply      (rule da.NewC)
schirmer@13688
  1133
apply     (rule assigned.select_convs)
schirmer@13688
  1134
apply    (simp)
schirmer@13688
  1135
apply   (rule da.Try)
schirmer@13688
  1136
apply      (rule da.Expr)
schirmer@13688
  1137
apply      (rule da.Call)
schirmer@13688
  1138
apply       (rule da.AccLVar)
schirmer@13688
  1139
apply         (simp)   
schirmer@13688
  1140
apply        (rule assigned.select_convs)
schirmer@13688
  1141
apply       (simp)
schirmer@13688
  1142
apply      (rule da.Cons)
schirmer@13688
  1143
apply       (rule da.Lit)
schirmer@13688
  1144
apply      (rule da.Nil)
schirmer@13688
  1145
apply     (rule da.Loop)
schirmer@13688
  1146
apply        (rule da.Acc)
schirmer@13688
  1147
apply         (simp)
schirmer@13688
  1148
apply        (rule da.AVar)
schirmer@13688
  1149
apply         (rule da.Acc)
schirmer@13688
  1150
apply          simp
schirmer@13688
  1151
apply         (rule da.FVar)
schirmer@13688
  1152
apply         (rule da.Cast)
schirmer@13688
  1153
apply         (rule da.Lit)
schirmer@13688
  1154
apply        (rule da.Lit)
schirmer@13688
  1155
apply       (rule da_Skip)
schirmer@13688
  1156
apply       (simp)
schirmer@13688
  1157
apply      (simp,rule assigned.select_convs)
schirmer@13688
  1158
apply     (simp)
schirmer@13688
  1159
apply    (simp,rule assigned.select_convs)
schirmer@13688
  1160
apply   (simp)
schirmer@13688
  1161
apply  simp
schirmer@13688
  1162
apply  blast
schirmer@13688
  1163
apply simp
schirmer@13688
  1164
apply (simp add: intersect_ts_def)
schirmer@13688
  1165
done
schirmer@13688
  1166
schirmer@12854
  1167
schirmer@12854
  1168
section "execution"
schirmer@12854
  1169
schirmer@12854
  1170
lemma alloc_one: "\<And>a obj. \<lbrakk>the (new_Addr h) = a; atleast_free h (Suc n)\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1171
  new_Addr h = Some a \<and> atleast_free (h(a\<mapsto>obj)) n"
schirmer@12854
  1172
apply (frule atleast_free_SucD)
schirmer@12854
  1173
apply (drule atleast_free_Suc [THEN iffD1])
schirmer@12854
  1174
apply clarsimp
schirmer@12854
  1175
apply (frule new_Addr_SomeI)
schirmer@12854
  1176
apply force
schirmer@12854
  1177
done
schirmer@12854
  1178
schirmer@12854
  1179
declare fvar_def2 [simp] avar_def2 [simp] init_lvars_def2 [simp]
schirmer@12854
  1180
declare init_obj_def [simp] var_tys_def [simp] fields_table_def [simp]
schirmer@12854
  1181
declare BaseCl_def [simp] ExtCl_def [simp] Ext_foo_def [simp]
schirmer@12854
  1182
        Base_foo_defs  [simp]
schirmer@12854
  1183
schirmer@12854
  1184
ML {* bind_thms ("eval_intros", map 
schirmer@12854
  1185
        (simplify (simpset() delsimps [thm "Skip_eq"]
schirmer@12854
  1186
                             addsimps [thm "lvar_def"]) o 
schirmer@12854
  1187
         rewrite_rule [thm "assign_def",Let_def]) (thms "eval.intros")) *}
schirmer@12854
  1188
lemmas eval_Is = eval_Init eval_StatRef AbruptIs eval_intros
schirmer@12854
  1189
schirmer@12854
  1190
consts
schirmer@12854
  1191
  a :: loc
schirmer@12854
  1192
  b :: loc
schirmer@12854
  1193
  c :: loc
schirmer@12854
  1194
  
schirmer@12854
  1195
syntax
schirmer@12854
  1196
schirmer@12854
  1197
  tprg :: prog
schirmer@12854
  1198
schirmer@12854
  1199
  obj_a :: obj
schirmer@12854
  1200
  obj_b :: obj
schirmer@12854
  1201
  obj_c :: obj
schirmer@12854
  1202
  arr_N :: "(vn, val) table"
schirmer@12854
  1203
  arr_a :: "(vn, val) table"
schirmer@12854
  1204
  globs1 :: globs
schirmer@12854
  1205
  globs2 :: globs
schirmer@12854
  1206
  globs3 :: globs
schirmer@12854
  1207
  globs8 :: globs
schirmer@12854
  1208
  locs3 :: locals
schirmer@12854
  1209
  locs4 :: locals
schirmer@12854
  1210
  locs8 :: locals
schirmer@12854
  1211
  s0  :: state
schirmer@12854
  1212
  s0' :: state
schirmer@12854
  1213
  s9' :: state
schirmer@12854
  1214
  s1  :: state
schirmer@12854
  1215
  s1' :: state
schirmer@12854
  1216
  s2  :: state
schirmer@12854
  1217
  s2' :: state
schirmer@12854
  1218
  s3  :: state
schirmer@12854
  1219
  s3' :: state
schirmer@12854
  1220
  s4  :: state
schirmer@12854
  1221
  s4' :: state
schirmer@12854
  1222
  s6' :: state
schirmer@12854
  1223
  s7' :: state
schirmer@12854
  1224
  s8  :: state
schirmer@12854
  1225
  s8' :: state
schirmer@12854
  1226
schirmer@12854
  1227
translations
schirmer@12854
  1228
schirmer@12854
  1229
  "tprg"    == "\<lparr>ifaces=Ifaces,classes=Classes\<rparr>"
schirmer@12854
  1230
  
schirmer@12854
  1231
  "obj_a"   <= "\<lparr>tag=Arr (PrimT Boolean) two
schirmer@12854
  1232
                ,values=empty(Inr 0\<mapsto>Bool False)(Inr one\<mapsto>Bool False)\<rparr>"
schirmer@12854
  1233
  "obj_b"   <= "\<lparr>tag=CInst Ext
schirmer@12854
  1234
                ,values=(empty(Inl (vee, Base)\<mapsto>Null   ) 
schirmer@12854
  1235
			      (Inl (vee, Ext )\<mapsto>Intg 0))\<rparr>"
schirmer@12854
  1236
  "obj_c"   == "\<lparr>tag=CInst (SXcpt NullPointer),values=empty\<rparr>"
schirmer@12854
  1237
  "arr_N"   == "empty(Inl (arr, Base)\<mapsto>Null)"
schirmer@12854
  1238
  "arr_a"   == "empty(Inl (arr, Base)\<mapsto>Addr a)"
schirmer@12854
  1239
  "globs1"  == "empty(Inr Ext   \<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)
schirmer@12854
  1240
		     (Inr Base  \<mapsto>\<lparr>tag=arbitrary, values=arr_N\<rparr>)
schirmer@12854
  1241
		     (Inr Object\<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)"
schirmer@12854
  1242
  "globs2"  == "empty(Inr Ext   \<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)
schirmer@12854
  1243
		     (Inr Object\<mapsto>\<lparr>tag=arbitrary, values=empty\<rparr>)
schirmer@12854
  1244
		     (Inl a\<mapsto>obj_a)
schirmer@12854
  1245
		     (Inr Base  \<mapsto>\<lparr>tag=arbitrary, values=arr_a\<rparr>)"
schirmer@12854
  1246
  "globs3"  == "globs2(Inl b\<mapsto>obj_b)"
schirmer@12854
  1247
  "globs8"  == "globs3(Inl c\<mapsto>obj_c)"
schirmer@12854
  1248
  "locs3"   == "empty(VName e\<mapsto>Addr b)"
schirmer@12854
  1249
  "locs4"   == "empty(VName z\<mapsto>Null)(Inr()\<mapsto>Addr b)"
schirmer@12854
  1250
  "locs8"   == "locs3(VName z\<mapsto>Addr c)"
schirmer@12854
  1251
  "s0"  == "       st empty  empty"
schirmer@12854
  1252
  "s0'" == " Norm  s0"
schirmer@12854
  1253
  "s1"  == "       st globs1 empty"
schirmer@12854
  1254
  "s1'" == " Norm  s1"
schirmer@12854
  1255
  "s2"  == "       st globs2 empty"
schirmer@12854
  1256
  "s2'" == " Norm  s2"
schirmer@12854
  1257
  "s3"  == "       st globs3 locs3 "
schirmer@12854
  1258
  "s3'" == " Norm  s3"
schirmer@12854
  1259
  "s4"  == "       st globs3 locs4"
schirmer@12854
  1260
  "s4'" == " Norm  s4"
schirmer@12854
  1261
  "s6'" == "(Some (Xcpt (Std NullPointer)), s4)"
schirmer@12854
  1262
  "s7'" == "(Some (Xcpt (Std NullPointer)), s3)"
schirmer@12854
  1263
  "s8"  == "       st globs8 locs8"
schirmer@12854
  1264
  "s8'" == " Norm  s8"
schirmer@12854
  1265
  "s9'" == "(Some (Xcpt (Std IndOutBound)), s8)"
schirmer@12854
  1266
schirmer@12854
  1267
schirmer@12854
  1268
syntax "four"::nat
schirmer@12854
  1269
       "tree"::nat
schirmer@12854
  1270
       "two" ::nat
schirmer@12854
  1271
       "one" ::nat
schirmer@12854
  1272
translations 
schirmer@12854
  1273
  "one"  == "Suc 0"
schirmer@12854
  1274
  "two"  == "Suc one"
schirmer@12854
  1275
  "tree" == "Suc two"
schirmer@12854
  1276
  "four" == "Suc tree"
schirmer@12854
  1277
schirmer@12854
  1278
declare Pair_eq [simp del]
schirmer@12854
  1279
lemma exec_test: 
schirmer@12854
  1280
"\<lbrakk>the (new_Addr (heap  s1)) = a;  
schirmer@12854
  1281
  the (new_Addr (heap ?s2)) = b;  
schirmer@12854
  1282
  the (new_Addr (heap ?s3)) = c\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1283
  atleast_free  (heap s0) four \<Longrightarrow>  
schirmer@12854
  1284
  tprg\<turnstile>s0' \<midarrow>test [Class Base]\<rightarrow> ?s9'"
schirmer@12854
  1285
apply (unfold test_def arr_viewed_from_def)
schirmer@12854
  1286
(* ?s9' = s9' *)
schirmer@12854
  1287
apply (simp (no_asm_use))
schirmer@12854
  1288
apply (drule (1) alloc_one,clarsimp)
schirmer@12854
  1289
apply (rule eval_Is (* ;; *))
schirmer@12854
  1290
apply  (erule_tac V = "the (new_Addr ?h) = c" in thin_rl)
schirmer@12854
  1291
apply  (erule_tac [2] V = "new_Addr ?h = Some a" in thin_rl)
schirmer@12854
  1292
apply  (erule_tac [2] V = "atleast_free ?h four" in thin_rl)
schirmer@12854
  1293
apply  (rule eval_Is (* Expr *))
schirmer@12854
  1294
apply  (rule eval_Is (* Ass *))
schirmer@12854
  1295
apply   (rule eval_Is (* LVar *))
schirmer@12854
  1296
apply  (rule eval_Is (* NewC *))
schirmer@12854
  1297
      (* begin init Ext *)
schirmer@12854
  1298
apply   (erule_tac V = "the (new_Addr ?h) = b" in thin_rl)
schirmer@12854
  1299
apply   (erule_tac V = "atleast_free ?h tree" in thin_rl)
schirmer@12854
  1300
apply   (erule_tac [2] V = "atleast_free ?h four" in thin_rl)
schirmer@12854
  1301
apply   (erule_tac [2] V = "new_Addr ?h = Some a" in thin_rl)
schirmer@12854
  1302
apply   (rule eval_Is (* Init Ext *))
schirmer@12854
  1303
apply   (simp)
schirmer@12854
  1304
apply   (rule conjI)
schirmer@12854
  1305
prefer 2 apply (rule conjI HOL.refl)+
schirmer@12854
  1306
apply   (rule eval_Is (* Init Base *))
schirmer@12854
  1307
apply   (simp add: arr_viewed_from_def)
schirmer@12854
  1308
apply   (rule conjI)
schirmer@12854
  1309
apply    (rule eval_Is (* Init Object *))
schirmer@12854
  1310
apply    (simp)
schirmer@12854
  1311
apply    (rule conjI, rule HOL.refl)+
schirmer@12854
  1312
apply    (rule HOL.refl)
schirmer@12854
  1313
apply   (simp)
schirmer@12854
  1314
apply   (rule conjI, rule_tac [2] HOL.refl)
schirmer@12854
  1315
apply   (rule eval_Is (* Expr *))
schirmer@12854
  1316
apply   (rule eval_Is (* Ass *))
schirmer@12854
  1317
apply    (rule eval_Is (* FVar *))
schirmer@12925
  1318
apply         (rule init_done, simp)
schirmer@12925
  1319
apply        (rule eval_Is (* StatRef *))
schirmer@12925
  1320
apply       (simp)
schirmer@12925
  1321
apply     (simp add: check_field_access_def Let_def) 
schirmer@12854
  1322
apply   (rule eval_Is (* NewA *))
schirmer@12854
  1323
apply     (simp)
schirmer@12854
  1324
apply    (rule eval_Is (* Lit *))
schirmer@12854
  1325
apply   (simp)
schirmer@12854
  1326
apply   (rule halloc.New)
schirmer@12854
  1327
apply    (simp (no_asm_simp))
schirmer@13688
  1328
apply   (drule atleast_free_weaken,drule atleast_free_weaken)
schirmer@12854
  1329
apply   (simp (no_asm_simp))
schirmer@12854
  1330
apply  (simp add: upd_gobj_def)
schirmer@12854
  1331
      (* end init Ext *)
schirmer@12854
  1332
apply  (rule halloc.New)
schirmer@12854
  1333
apply   (drule alloc_one)
schirmer@12854
  1334
prefer 2 apply fast
schirmer@12854
  1335
apply   (simp (no_asm_simp))
schirmer@12854
  1336
apply  (drule atleast_free_weaken)
schirmer@12854
  1337
apply  force
schirmer@12854
  1338
apply (simp)
schirmer@12854
  1339
apply (drule alloc_one)
schirmer@12854
  1340
apply  (simp (no_asm_simp))
schirmer@12854
  1341
apply clarsimp
schirmer@12854
  1342
apply (erule_tac V = "atleast_free ?h tree" in thin_rl)
schirmer@12854
  1343
apply (drule_tac x = "a" in new_AddrD2 [THEN spec])
schirmer@12854
  1344
apply (simp (no_asm_use))
schirmer@12854
  1345
apply (rule eval_Is (* Try *))
schirmer@12854
  1346
apply   (rule eval_Is (* Expr *))
schirmer@12854
  1347
      (* begin method call *)
schirmer@12854
  1348
apply   (rule eval_Is (* Call *))
schirmer@12854
  1349
apply      (rule eval_Is (* Acc *))
schirmer@12854
  1350
apply      (rule eval_Is (* LVar *))
schirmer@12854
  1351
apply     (rule eval_Is (* Cons *))
schirmer@12854
  1352
apply      (rule eval_Is (* Lit *))
schirmer@12854
  1353
apply     (rule eval_Is (* Nil *))
schirmer@12854
  1354
apply    (simp)
schirmer@12925
  1355
apply    (simp)
schirmer@12925
  1356
apply    (subgoal_tac
schirmer@12925
  1357
             "tprg\<turnstile>(Ext,mdecl Ext_foo) in Ext dyn_accessible_from Main")
schirmer@12925
  1358
apply      (simp add: check_method_access_def Let_def
schirmer@12925
  1359
                      invocation_declclass_def dynlookup_def dynmethd_Ext_foo)
schirmer@12925
  1360
apply      (rule Ext_foo_dyn_accessible)
schirmer@12854
  1361
apply   (rule eval_Is (* Methd *))
schirmer@12854
  1362
apply   (simp add: body_def Let_def)
schirmer@12854
  1363
apply   (rule eval_Is (* Body *))
schirmer@12854
  1364
apply     (rule init_done, simp)
schirmer@12854
  1365
apply       (simp add: invocation_declclass_def dynlookup_def dynmethd_Ext_foo)
schirmer@12854
  1366
apply    (simp add: invocation_declclass_def dynlookup_def dynmethd_Ext_foo)
schirmer@13688
  1367
apply    (rule eval_Is (* Comp *))
schirmer@13688
  1368
apply     (rule eval_Is (* Expr *))
schirmer@13688
  1369
apply     (rule eval_Is (* Ass *))
schirmer@13688
  1370
apply      (rule eval_Is (* FVar *))
schirmer@13688
  1371
apply         (rule init_done, simp)
schirmer@13688
  1372
apply        (rule eval_Is (* Cast *))
schirmer@13688
  1373
apply         (rule eval_Is (* Acc *))
schirmer@13688
  1374
apply         (rule eval_Is (* LVar *))
schirmer@13688
  1375
apply        (simp)
schirmer@13688
  1376
apply       (simp split del: split_if)
schirmer@12925
  1377
apply      (simp add: check_field_access_def Let_def)
schirmer@13688
  1378
apply     (rule eval_Is (* XcptE *))
schirmer@13688
  1379
apply    (simp)
schirmer@13688
  1380
apply    (rule conjI)
schirmer@13688
  1381
apply     (simp)
schirmer@13688
  1382
apply    (rule eval_Is (* Comp *))
schirmer@12854
  1383
apply   (simp)
schirmer@12854
  1384
      (* end method call *)
schirmer@13688
  1385
apply  simp
schirmer@12854
  1386
apply  (rule sxalloc.intros)
schirmer@12854
  1387
apply  (rule halloc.New)
schirmer@12854
  1388
apply   (erule alloc_one [THEN conjunct1])
schirmer@12854
  1389
apply   (simp (no_asm_simp))
schirmer@12854
  1390
apply  (simp (no_asm_simp))
schirmer@12854
  1391
apply (simp add: gupd_def lupd_def obj_ty_def split del: split_if)
schirmer@12854
  1392
apply (drule alloc_one [THEN conjunct1])
schirmer@12854
  1393
apply  (simp (no_asm_simp))
schirmer@12854
  1394
apply (erule_tac V = "atleast_free ?h two" in thin_rl)
schirmer@12854
  1395
apply (drule_tac x = "a" in new_AddrD2 [THEN spec])
schirmer@12854
  1396
apply simp
schirmer@12854
  1397
apply (rule eval_Is (* While *))
schirmer@12854
  1398
apply  (rule eval_Is (* Acc *))
schirmer@12854
  1399
apply  (rule eval_Is (* AVar *))
schirmer@12854
  1400
apply    (rule eval_Is (* Acc *))
schirmer@12854
  1401
apply    (rule eval_Is (* FVar *))
schirmer@12854
  1402
apply      (rule init_done, simp)
schirmer@12854
  1403
apply     (rule eval_Is (* StatRef *))
schirmer@12854
  1404
apply    (simp)
schirmer@12925
  1405
apply    (simp add: check_field_access_def Let_def)
schirmer@12854
  1406
apply   (rule eval_Is (* Lit *))
schirmer@12854
  1407
apply  (simp (no_asm_simp))
schirmer@12854
  1408
apply (auto simp add: in_bounds_def)
schirmer@12854
  1409
done
schirmer@12854
  1410
declare Pair_eq [simp]
schirmer@12854
  1411
schirmer@12854
  1412
end