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