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