src/HOL/Bali/Decl.thy
author wenzelm
Wed Feb 10 00:45:16 2010 +0100 (2010-02-10)
changeset 35067 af4c18c30593
parent 32960 69916a850301
child 35069 09154b995ed8
permissions -rw-r--r--
modernized syntax translations, using mostly abbreviation/notation;
minor tuning;
wenzelm@12857
     1
(*  Title:      HOL/Bali/Decl.thy
schirmer@12854
     2
    ID:         $Id$
schirmer@12925
     3
    Author:     David von Oheimb and Norbert Schirmer
schirmer@12854
     4
*)
schirmer@12854
     5
header {* Field, method, interface, and class declarations, whole Java programs
schirmer@12854
     6
*}
schirmer@12854
     7
haftmann@26566
     8
theory Decl
haftmann@27682
     9
imports Term Table (** order is significant, because of clash for "var" **)
haftmann@26566
    10
begin
schirmer@12854
    11
schirmer@12854
    12
text {*
schirmer@12854
    13
improvements:
schirmer@12854
    14
\begin{itemize}
schirmer@12854
    15
\item clarification and correction of some aspects of the package/access concept
schirmer@12854
    16
  (Also submitted as bug report to the Java Bug Database:
schirmer@12854
    17
   Bug Id: 4485402 and Bug Id: 4493343 
schirmer@12854
    18
   http://developer.java.sun.com/developer/bugParade/index.jshtml
schirmer@12854
    19
  )
schirmer@12854
    20
\end{itemize}
schirmer@12854
    21
simplifications:
schirmer@12854
    22
\begin{itemize}
schirmer@12854
    23
\item the only field and method modifiers are static and the access modifiers
schirmer@12854
    24
\item no constructors, which may be simulated by new + suitable methods
schirmer@12854
    25
\item there is just one global initializer per class, which can simulate all 
schirmer@12854
    26
      others
schirmer@12854
    27
schirmer@12854
    28
\item no throws clause
schirmer@12854
    29
\item a void method is replaced by one that returns Unit (of dummy type Void)
schirmer@12854
    30
schirmer@12854
    31
\item no interface fields
schirmer@12854
    32
schirmer@12854
    33
\item every class has an explicit superclass (unused for Object)
schirmer@12854
    34
\item the (standard) methods of Object and of standard exceptions are not 
schirmer@12854
    35
      specified
schirmer@12854
    36
schirmer@12854
    37
\item no main method
schirmer@12854
    38
\end{itemize}
schirmer@12854
    39
*}
schirmer@12854
    40
schirmer@12854
    41
subsection {* Modifier*}
schirmer@12854
    42
schirmer@12854
    43
subsubsection {* Access modifier *}
schirmer@12854
    44
schirmer@12854
    45
datatype acc_modi (* access modifier *)
schirmer@12854
    46
         = Private | Package | Protected | Public 
schirmer@12854
    47
schirmer@12854
    48
text {* 
schirmer@12854
    49
We can define a linear order for the access modifiers. With Private yielding the
schirmer@12854
    50
most restrictive access and public the most liberal access policy:
schirmer@12854
    51
  Private < Package < Protected < Public
schirmer@12854
    52
*}
schirmer@12854
    53
 
haftmann@26566
    54
instantiation acc_modi :: linorder
haftmann@26566
    55
begin
schirmer@12854
    56
haftmann@26566
    57
definition
haftmann@26566
    58
  less_acc_def: "a < b
haftmann@26566
    59
      \<longleftrightarrow> (case a of
schirmer@12854
    60
             Private    \<Rightarrow> (b=Package \<or> b=Protected \<or> b=Public)
schirmer@12854
    61
           | Package    \<Rightarrow> (b=Protected \<or> b=Public)
schirmer@12854
    62
           | Protected  \<Rightarrow> (b=Public)
schirmer@12854
    63
           | Public     \<Rightarrow> False)"
schirmer@12854
    64
haftmann@26566
    65
definition
haftmann@27682
    66
  le_acc_def: "(a :: acc_modi) \<le> b \<longleftrightarrow> a < b \<or> a = b"
haftmann@26566
    67
haftmann@26566
    68
instance proof
schirmer@12854
    69
  fix x y z::acc_modi
haftmann@27682
    70
  show "(x < y) = (x \<le> y \<and> \<not> y \<le> x)"
haftmann@27682
    71
    by (auto simp add: le_acc_def less_acc_def split add: acc_modi.split) 
schirmer@12854
    72
  {
schirmer@12854
    73
  show "x \<le> x"               \<spacespace>\<spacespace>    -- reflexivity
schirmer@12854
    74
    by (auto simp add: le_acc_def)
schirmer@12854
    75
  next
schirmer@12854
    76
  assume "x \<le> y" "y \<le> z"           -- transitivity 
schirmer@12854
    77
  thus "x \<le> z"
schirmer@12854
    78
    by (auto simp add: le_acc_def less_acc_def split add: acc_modi.split)
schirmer@12854
    79
  next
schirmer@12854
    80
  assume "x \<le> y" "y \<le> x"           -- antisymmetry
schirmer@12854
    81
  thus "x = y"
schirmer@12854
    82
  proof -
schirmer@12854
    83
    have "\<forall> x y. x < (y::acc_modi) \<and> y < x \<longrightarrow> False"
schirmer@12854
    84
      by (auto simp add: less_acc_def split add: acc_modi.split)
schirmer@12854
    85
    with prems show ?thesis
nipkow@17589
    86
      by (unfold le_acc_def) iprover
schirmer@12854
    87
  qed
schirmer@12854
    88
  next
schirmer@12854
    89
  fix x y:: acc_modi
schirmer@12854
    90
  show  "x \<le> y \<or> y \<le> x"   
schirmer@12854
    91
  by (auto simp add: less_acc_def le_acc_def split add: acc_modi.split)
haftmann@27682
    92
  }
schirmer@12854
    93
qed
haftmann@26566
    94
  
haftmann@26566
    95
end
schirmer@12854
    96
schirmer@12854
    97
lemma acc_modi_top [simp]: "Public \<le> a \<Longrightarrow> a = Public"
schirmer@12854
    98
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
    99
schirmer@12854
   100
lemma acc_modi_top1 [simp, intro!]: "a \<le> Public"
schirmer@12854
   101
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   102
schirmer@12854
   103
lemma acc_modi_le_Public: 
schirmer@12854
   104
"a \<le> Public \<Longrightarrow> a=Private \<or> a = Package \<or> a=Protected \<or> a=Public"
schirmer@12854
   105
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   106
schirmer@12854
   107
lemma acc_modi_bottom: "a \<le> Private \<Longrightarrow> a = Private"
schirmer@12854
   108
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   109
schirmer@12854
   110
lemma acc_modi_Private_le: 
schirmer@12854
   111
"Private \<le> a \<Longrightarrow> a=Private \<or> a = Package \<or> a=Protected \<or> a=Public"
schirmer@12854
   112
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   113
schirmer@12854
   114
lemma acc_modi_Package_le: 
schirmer@12854
   115
  "Package \<le> a \<Longrightarrow> a = Package \<or> a=Protected \<or> a=Public"
schirmer@12854
   116
by (auto simp add: le_acc_def less_acc_def split: acc_modi.split)
schirmer@12854
   117
schirmer@12854
   118
lemma acc_modi_le_Package: 
schirmer@12854
   119
  "a \<le> Package \<Longrightarrow> a=Private \<or> a = Package"
schirmer@12854
   120
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   121
schirmer@12854
   122
lemma acc_modi_Protected_le: 
schirmer@12854
   123
  "Protected \<le> a \<Longrightarrow> a=Protected \<or> a=Public"
schirmer@12854
   124
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   125
schirmer@12854
   126
lemma acc_modi_le_Protected: 
schirmer@12854
   127
  "a \<le> Protected  \<Longrightarrow> a=Private \<or> a = Package \<or> a = Protected"
schirmer@12854
   128
by (auto simp add: le_acc_def less_acc_def split: acc_modi.splits)
schirmer@12854
   129
schirmer@12854
   130
schirmer@12854
   131
lemmas acc_modi_le_Dests = acc_modi_top           acc_modi_le_Public
schirmer@12854
   132
                           acc_modi_Private_le    acc_modi_bottom
schirmer@12854
   133
                           acc_modi_Package_le    acc_modi_le_Package
schirmer@12854
   134
                           acc_modi_Protected_le  acc_modi_le_Protected
schirmer@12854
   135
schirmer@12854
   136
lemma acc_modi_Package_le_cases 
schirmer@12854
   137
 [consumes 1,case_names Package Protected Public]:
schirmer@12854
   138
 "Package \<le> m \<Longrightarrow> ( m = Package \<Longrightarrow> P m) \<Longrightarrow> (m=Protected \<Longrightarrow> P m) \<Longrightarrow> 
schirmer@12854
   139
   (m=Public \<Longrightarrow> P m) \<Longrightarrow> P m"
schirmer@12854
   140
by (auto dest: acc_modi_Package_le)
schirmer@12854
   141
schirmer@12854
   142
schirmer@12854
   143
subsubsection {* Static Modifier *}
schirmer@12854
   144
types stat_modi = bool (* modifier: static *)
schirmer@12854
   145
schirmer@12854
   146
subsection {* Declaration (base "class" for member,interface and class
schirmer@12854
   147
 declarations *}
schirmer@12854
   148
schirmer@12854
   149
record decl =
schirmer@12854
   150
        access :: acc_modi
schirmer@12854
   151
schirmer@12854
   152
translations
schirmer@12854
   153
  "decl" <= (type) "\<lparr>access::acc_modi\<rparr>"
schirmer@12854
   154
  "decl" <= (type) "\<lparr>access::acc_modi,\<dots>::'a\<rparr>"
schirmer@12854
   155
schirmer@12854
   156
subsection {* Member (field or method)*}
schirmer@12854
   157
record  member = decl +
schirmer@12854
   158
         static :: stat_modi
schirmer@12854
   159
schirmer@12854
   160
translations
schirmer@12854
   161
  "member" <= (type) "\<lparr>access::acc_modi,static::bool\<rparr>"
schirmer@12854
   162
  "member" <= (type) "\<lparr>access::acc_modi,static::bool,\<dots>::'a\<rparr>"
schirmer@12854
   163
schirmer@12854
   164
subsection {* Field *}
schirmer@12854
   165
schirmer@12854
   166
record field = member +
schirmer@12854
   167
        type :: ty
schirmer@12854
   168
translations
schirmer@12854
   169
  "field" <= (type) "\<lparr>access::acc_modi, static::bool, type::ty\<rparr>"
schirmer@12854
   170
  "field" <= (type) "\<lparr>access::acc_modi, static::bool, type::ty,\<dots>::'a\<rparr>"
schirmer@12854
   171
schirmer@12854
   172
types     
schirmer@12854
   173
        fdecl           (* field declaration, cf. 8.3 *)
wenzelm@32960
   174
        = "vname \<times> field"
schirmer@12854
   175
schirmer@12854
   176
schirmer@12854
   177
translations
schirmer@12854
   178
  "fdecl" <= (type) "vname \<times> field"
schirmer@12854
   179
schirmer@12854
   180
subsection  {* Method *}
schirmer@12854
   181
schirmer@12854
   182
record mhead = member +     (* method head (excluding signature) *)
schirmer@12854
   183
        pars ::"vname list" (* parameter names *)
schirmer@12854
   184
        resT ::ty           (* result type *)
schirmer@12854
   185
schirmer@12854
   186
record mbody =                      (* method body *)
schirmer@12854
   187
        lcls::  "(vname \<times> ty) list" (* local variables *)
schirmer@12854
   188
        stmt:: stmt                 (* the body statement *)
schirmer@12854
   189
schirmer@12854
   190
record methd = mhead + (* method in a class *)
schirmer@12854
   191
        mbody::mbody
schirmer@12854
   192
schirmer@12854
   193
types mdecl = "sig \<times> methd"  (* method declaration in a class *)
schirmer@12854
   194
schirmer@12854
   195
schirmer@12854
   196
translations
schirmer@12854
   197
  "mhead" <= (type) "\<lparr>access::acc_modi, static::bool, 
schirmer@12854
   198
                      pars::vname list, resT::ty\<rparr>"
schirmer@12854
   199
  "mhead" <= (type) "\<lparr>access::acc_modi, static::bool, 
schirmer@12854
   200
                      pars::vname list, resT::ty,\<dots>::'a\<rparr>"
schirmer@12854
   201
  "mbody" <= (type) "\<lparr>lcls::(vname \<times> ty) list,stmt::stmt\<rparr>"
schirmer@12854
   202
  "mbody" <= (type) "\<lparr>lcls::(vname \<times> ty) list,stmt::stmt,\<dots>::'a\<rparr>"      
schirmer@12854
   203
  "methd" <= (type) "\<lparr>access::acc_modi, static::bool, 
schirmer@12854
   204
                      pars::vname list, resT::ty,mbody::mbody\<rparr>"
schirmer@12854
   205
  "methd" <= (type) "\<lparr>access::acc_modi, static::bool, 
schirmer@12854
   206
                      pars::vname list, resT::ty,mbody::mbody,\<dots>::'a\<rparr>"
schirmer@12854
   207
  "mdecl" <= (type) "sig \<times> methd"
schirmer@12854
   208
schirmer@12854
   209
schirmer@12854
   210
constdefs 
schirmer@12854
   211
  mhead::"methd \<Rightarrow> mhead"
schirmer@12854
   212
  "mhead m \<equiv> \<lparr>access=access m, static=static m, pars=pars m, resT=resT m\<rparr>"
schirmer@12854
   213
schirmer@12854
   214
lemma access_mhead [simp]:"access (mhead m) = access m"
schirmer@12854
   215
by (simp add: mhead_def)
schirmer@12854
   216
schirmer@12854
   217
lemma static_mhead [simp]:"static (mhead m) = static m"
schirmer@12854
   218
by (simp add: mhead_def)
schirmer@12854
   219
schirmer@12854
   220
lemma pars_mhead [simp]:"pars (mhead m) = pars m"
schirmer@12854
   221
by (simp add: mhead_def)
schirmer@12854
   222
schirmer@12854
   223
lemma resT_mhead [simp]:"resT (mhead m) = resT m"
schirmer@12854
   224
by (simp add: mhead_def)
schirmer@12854
   225
schirmer@12854
   226
text {* To be able to talk uniformaly about field and method declarations we
schirmer@12854
   227
introduce the notion of a member declaration (e.g. useful to define 
schirmer@12854
   228
accessiblity ) *}
schirmer@12854
   229
schirmer@12854
   230
datatype memberdecl = fdecl fdecl | mdecl mdecl
schirmer@12854
   231
schirmer@12854
   232
datatype memberid = fid vname | mid sig
schirmer@12854
   233
schirmer@12854
   234
axclass has_memberid < "type"
schirmer@12854
   235
consts
schirmer@12854
   236
 memberid :: "'a::has_memberid \<Rightarrow> memberid"
schirmer@12854
   237
wenzelm@12859
   238
instance memberdecl::has_memberid ..
schirmer@12854
   239
schirmer@12854
   240
defs (overloaded)
schirmer@12854
   241
memberdecl_memberid_def:
schirmer@12854
   242
  "memberid m \<equiv> (case m of
schirmer@12854
   243
                    fdecl (vn,f)  \<Rightarrow> fid vn
schirmer@12854
   244
                  | mdecl (sig,m) \<Rightarrow> mid sig)"
schirmer@12854
   245
schirmer@12854
   246
lemma memberid_fdecl_simp[simp]: "memberid (fdecl (vn,f)) = fid vn"
schirmer@12854
   247
by (simp add: memberdecl_memberid_def)
schirmer@12854
   248
schirmer@12854
   249
lemma memberid_fdecl_simp1: "memberid (fdecl f) = fid (fst f)"
schirmer@12854
   250
by (cases f) (simp add: memberdecl_memberid_def)
schirmer@12854
   251
schirmer@12854
   252
lemma memberid_mdecl_simp[simp]: "memberid (mdecl (sig,m)) = mid sig"
schirmer@12854
   253
by (simp add: memberdecl_memberid_def)
schirmer@12854
   254
schirmer@12854
   255
lemma memberid_mdecl_simp1: "memberid (mdecl m) = mid (fst m)"
schirmer@12854
   256
by (cases m) (simp add: memberdecl_memberid_def)
schirmer@12854
   257
wenzelm@12859
   258
instance * :: (type, has_memberid) has_memberid ..
schirmer@12854
   259
schirmer@12854
   260
defs (overloaded)
schirmer@12854
   261
pair_memberid_def:
schirmer@12854
   262
  "memberid p \<equiv> memberid (snd p)"
schirmer@12854
   263
schirmer@12854
   264
lemma memberid_pair_simp[simp]: "memberid (c,m) = memberid m"
schirmer@12854
   265
by (simp add: pair_memberid_def)
schirmer@12854
   266
schirmer@12854
   267
lemma memberid_pair_simp1: "memberid p  = memberid (snd p)"
schirmer@12854
   268
by (simp add: pair_memberid_def)
schirmer@12854
   269
schirmer@12854
   270
constdefs is_field :: "qtname \<times> memberdecl \<Rightarrow> bool"
schirmer@12854
   271
"is_field m \<equiv> \<exists> declC f. m=(declC,fdecl f)"
schirmer@12854
   272
  
schirmer@12854
   273
lemma is_fieldD: "is_field m \<Longrightarrow> \<exists> declC f. m=(declC,fdecl f)"
schirmer@12854
   274
by (simp add: is_field_def)
schirmer@12854
   275
schirmer@12854
   276
lemma is_fieldI: "is_field (C,fdecl f)"
schirmer@12854
   277
by (simp add: is_field_def)
schirmer@12854
   278
schirmer@12854
   279
constdefs is_method :: "qtname \<times> memberdecl \<Rightarrow> bool"
schirmer@12854
   280
"is_method membr \<equiv> \<exists> declC m. membr=(declC,mdecl m)"
schirmer@12854
   281
  
schirmer@12854
   282
lemma is_methodD: "is_method membr \<Longrightarrow> \<exists> declC m. membr=(declC,mdecl m)"
schirmer@12854
   283
by (simp add: is_method_def)
schirmer@12854
   284
schirmer@12854
   285
lemma is_methodI: "is_method (C,mdecl m)"
schirmer@12854
   286
by (simp add: is_method_def)
schirmer@12854
   287
schirmer@12854
   288
schirmer@12854
   289
subsection {* Interface *}
schirmer@12854
   290
schirmer@12854
   291
schirmer@13688
   292
record  ibody = decl +  --{* interface body *}
schirmer@13688
   293
          imethods :: "(sig \<times> mhead) list" --{* method heads *}
schirmer@12854
   294
schirmer@13688
   295
record  iface = ibody + --{* interface *}
schirmer@13688
   296
         isuperIfs:: "qtname list" --{* superinterface list *}
wenzelm@32960
   297
types
wenzelm@32960
   298
        idecl           --{* interface declaration, cf. 9.1 *}
wenzelm@32960
   299
        = "qtname \<times> iface"
schirmer@12854
   300
schirmer@12854
   301
translations
schirmer@12854
   302
  "ibody" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list\<rparr>"
schirmer@12854
   303
  "ibody" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list,\<dots>::'a\<rparr>"
schirmer@12854
   304
  "iface" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list,
schirmer@12854
   305
                      isuperIfs::qtname list\<rparr>"
schirmer@12854
   306
  "iface" <= (type) "\<lparr>access::acc_modi,imethods::(sig \<times> mhead) list,
schirmer@12854
   307
                      isuperIfs::qtname list,\<dots>::'a\<rparr>"
schirmer@12854
   308
  "idecl" <= (type) "qtname \<times> iface"
schirmer@12854
   309
schirmer@12854
   310
constdefs
schirmer@12854
   311
  ibody :: "iface \<Rightarrow> ibody"
schirmer@12854
   312
  "ibody i \<equiv> \<lparr>access=access i,imethods=imethods i\<rparr>"
schirmer@12854
   313
schirmer@12854
   314
lemma access_ibody [simp]: "(access (ibody i)) = access i"
schirmer@12854
   315
by (simp add: ibody_def)
schirmer@12854
   316
schirmer@12854
   317
lemma imethods_ibody [simp]: "(imethods (ibody i)) = imethods i"
schirmer@12854
   318
by (simp add: ibody_def)
schirmer@12854
   319
schirmer@12854
   320
subsection  {* Class *}
schirmer@13688
   321
record cbody = decl +          --{* class body *}
schirmer@12854
   322
         cfields:: "fdecl list" 
schirmer@12854
   323
         methods:: "mdecl list"
schirmer@13688
   324
         init   :: "stmt"       --{* initializer *}
schirmer@12854
   325
haftmann@18551
   326
record "class" = cbody +           --{* class *}
schirmer@13688
   327
        super   :: "qtname"      --{* superclass *}
schirmer@13688
   328
        superIfs:: "qtname list" --{* implemented interfaces *}
wenzelm@32960
   329
types
wenzelm@32960
   330
        cdecl           --{* class declaration, cf. 8.1 *}
wenzelm@32960
   331
        = "qtname \<times> class"
schirmer@12854
   332
schirmer@12854
   333
translations
schirmer@12854
   334
  "cbody" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list,
schirmer@12854
   335
                      methods::mdecl list,init::stmt\<rparr>"
schirmer@12854
   336
  "cbody" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list,
schirmer@12854
   337
                      methods::mdecl list,init::stmt,\<dots>::'a\<rparr>"
schirmer@12854
   338
  "class" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list,
schirmer@12854
   339
                      methods::mdecl list,init::stmt,
schirmer@12854
   340
                      super::qtname,superIfs::qtname list\<rparr>"
schirmer@12854
   341
  "class" <= (type) "\<lparr>access::acc_modi,cfields::fdecl list,
schirmer@12854
   342
                      methods::mdecl list,init::stmt,
schirmer@12854
   343
                      super::qtname,superIfs::qtname list,\<dots>::'a\<rparr>"
schirmer@12854
   344
  "cdecl" <= (type) "qtname \<times> class"
schirmer@12854
   345
schirmer@12854
   346
constdefs
schirmer@12854
   347
  cbody :: "class \<Rightarrow> cbody"
schirmer@12854
   348
  "cbody c \<equiv> \<lparr>access=access c, cfields=cfields c,methods=methods c,init=init c\<rparr>"
schirmer@12854
   349
schirmer@12854
   350
lemma access_cbody [simp]:"access (cbody c) = access c"
schirmer@12854
   351
by (simp add: cbody_def)
schirmer@12854
   352
schirmer@12854
   353
lemma cfields_cbody [simp]:"cfields (cbody c) = cfields c"
schirmer@12854
   354
by (simp add: cbody_def)
schirmer@12854
   355
schirmer@12854
   356
lemma methods_cbody [simp]:"methods (cbody c) = methods c"
schirmer@12854
   357
by (simp add: cbody_def)
schirmer@12854
   358
schirmer@12854
   359
lemma init_cbody [simp]:"init (cbody c) = init c"
schirmer@12854
   360
by (simp add: cbody_def)
schirmer@12854
   361
schirmer@12854
   362
schirmer@12854
   363
section "standard classes"
schirmer@12854
   364
schirmer@12854
   365
consts
schirmer@12854
   366
wenzelm@14674
   367
  Object_mdecls  ::  "mdecl list" --{* methods of Object *}
wenzelm@14674
   368
  SXcpt_mdecls   ::  "mdecl list" --{* methods of SXcpts *}
wenzelm@14674
   369
  ObjectC ::         "cdecl"      --{* declaration  of root      class   *}
schirmer@13688
   370
  SXcptC  ::"xname \<Rightarrow> cdecl"      --{* declarations of throwable classes *}
schirmer@12854
   371
schirmer@12854
   372
defs 
schirmer@12854
   373
schirmer@12854
   374
schirmer@12854
   375
ObjectC_def:"ObjectC  \<equiv> (Object,\<lparr>access=Public,cfields=[],methods=Object_mdecls,
haftmann@28524
   376
                                  init=Skip,super=undefined,superIfs=[]\<rparr>)"
schirmer@12854
   377
SXcptC_def:"SXcptC xn\<equiv> (SXcpt xn,\<lparr>access=Public,cfields=[],methods=SXcpt_mdecls,
schirmer@12854
   378
                                   init=Skip,
schirmer@12854
   379
                                   super=if xn = Throwable then Object 
schirmer@12854
   380
                                                           else SXcpt Throwable,
schirmer@12854
   381
                                   superIfs=[]\<rparr>)"
schirmer@12854
   382
schirmer@12854
   383
lemma ObjectC_neq_SXcptC [simp]: "ObjectC \<noteq> SXcptC xn"
schirmer@12854
   384
by (simp add: ObjectC_def SXcptC_def Object_def SXcpt_def)
schirmer@12854
   385
schirmer@12854
   386
lemma SXcptC_inject [simp]: "(SXcptC xn = SXcptC xm) = (xn = xm)"
nipkow@17778
   387
by (simp add: SXcptC_def)
schirmer@12854
   388
schirmer@12854
   389
constdefs standard_classes :: "cdecl list"
schirmer@12854
   390
         "standard_classes \<equiv> [ObjectC, SXcptC Throwable,
wenzelm@32960
   391
                SXcptC NullPointer, SXcptC OutOfMemory, SXcptC ClassCast,
wenzelm@32960
   392
                SXcptC NegArrSize , SXcptC IndOutBound, SXcptC ArrStore]"
schirmer@12854
   393
schirmer@12854
   394
schirmer@12854
   395
section "programs"
schirmer@12854
   396
schirmer@12854
   397
record prog =
schirmer@12854
   398
        ifaces ::"idecl list"
schirmer@12854
   399
        "classes"::"cdecl list"
schirmer@12854
   400
schirmer@12854
   401
translations
schirmer@12854
   402
     "prog"<= (type) "\<lparr>ifaces::idecl list,classes::cdecl list\<rparr>"
schirmer@12854
   403
     "prog"<= (type) "\<lparr>ifaces::idecl list,classes::cdecl list,\<dots>::'a\<rparr>"
schirmer@12854
   404
wenzelm@35067
   405
abbreviation
wenzelm@35067
   406
  iface :: "prog  \<Rightarrow> (qtname, iface) table"
wenzelm@35067
   407
  where "iface G I == table_of (ifaces G) I"
wenzelm@35067
   408
wenzelm@35067
   409
abbreviation
wenzelm@35067
   410
  "class" :: "prog  \<Rightarrow> (qtname, class) table"
wenzelm@35067
   411
  where "class G C == table_of (classes G) C"
schirmer@12854
   412
wenzelm@35067
   413
abbreviation
wenzelm@35067
   414
  is_iface :: "prog  \<Rightarrow> qtname  \<Rightarrow> bool"
wenzelm@35067
   415
  where "is_iface G I == iface G I \<noteq> None"
wenzelm@35067
   416
wenzelm@35067
   417
abbreviation
wenzelm@35067
   418
  is_class :: "prog  \<Rightarrow> qtname  \<Rightarrow> bool"
wenzelm@35067
   419
  where "is_class G C == class G C \<noteq> None"
schirmer@12854
   420
schirmer@12854
   421
schirmer@12854
   422
section "is type"
schirmer@12854
   423
schirmer@12854
   424
consts
schirmer@12854
   425
  is_type :: "prog \<Rightarrow>     ty \<Rightarrow> bool"
schirmer@12854
   426
  isrtype :: "prog \<Rightarrow> ref_ty \<Rightarrow> bool"
schirmer@12854
   427
wenzelm@32960
   428
primrec "is_type G (PrimT pt)  = True"
wenzelm@32960
   429
        "is_type G (RefT  rt)  = isrtype G rt"
wenzelm@32960
   430
        "isrtype G (NullT    ) = True"
wenzelm@32960
   431
        "isrtype G (IfaceT tn) = is_iface G tn"
wenzelm@32960
   432
        "isrtype G (ClassT tn) = is_class G tn"
wenzelm@32960
   433
        "isrtype G (ArrayT T ) = is_type  G T"
schirmer@12854
   434
schirmer@12854
   435
lemma type_is_iface: "is_type G (Iface I) \<Longrightarrow> is_iface G I"
schirmer@12854
   436
by auto
schirmer@12854
   437
schirmer@12854
   438
lemma type_is_class: "is_type G (Class C) \<Longrightarrow>  is_class G C"
schirmer@12854
   439
by auto
schirmer@12854
   440
schirmer@12854
   441
schirmer@12854
   442
section "subinterface and subclass relation, in anticipation of TypeRel.thy"
schirmer@12854
   443
schirmer@12854
   444
consts 
schirmer@13688
   445
  subint1  :: "prog \<Rightarrow> (qtname \<times> qtname) set" --{* direct subinterface *}
schirmer@13688
   446
  subcls1  :: "prog \<Rightarrow> (qtname \<times> qtname) set" --{* direct subclass     *}
schirmer@12854
   447
schirmer@12854
   448
defs
schirmer@12854
   449
  subint1_def: "subint1 G \<equiv> {(I,J). \<exists>i\<in>iface G I: J\<in>set (isuperIfs i)}"
schirmer@12854
   450
  subcls1_def: "subcls1 G \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c\<in>class G C: super c = D)}"
schirmer@12854
   451
wenzelm@35067
   452
abbreviation
wenzelm@35067
   453
  subcls1_syntax :: "prog => [qtname, qtname] => bool" ("_|-_<:C1_" [71,71,71] 70)
wenzelm@35067
   454
  where "G|-C <:C1 D == (C,D) \<in> subcls1 G"
wenzelm@35067
   455
wenzelm@35067
   456
abbreviation
wenzelm@35067
   457
  subclseq_syntax :: "prog => [qtname, qtname] => bool" ("_|-_<=:C _"[71,71,71] 70)
wenzelm@35067
   458
  where "G|-C <=:C D == (C,D) \<in>(subcls1 G)^*" (* cf. 8.1.3 *)
schirmer@12854
   459
wenzelm@35067
   460
abbreviation
wenzelm@35067
   461
  subcls_syntax :: "prog => [qtname, qtname] => bool" ("_|-_<:C _"[71,71,71] 70)
wenzelm@35067
   462
  where "G|-C <:C D == (C,D) \<in>(subcls1 G)^+"
schirmer@12854
   463
wenzelm@35067
   464
notation (xsymbols)
wenzelm@35067
   465
  subcls1_syntax  ("_\<turnstile>_\<prec>\<^sub>C\<^sub>1_"  [71,71,71] 70) and
wenzelm@35067
   466
  subclseq_syntax  ("_\<turnstile>_\<preceq>\<^sub>C _"  [71,71,71] 70) and
wenzelm@35067
   467
  subcls_syntax  ("_\<turnstile>_\<prec>\<^sub>C _"  [71,71,71] 70)
schirmer@12854
   468
schirmer@12854
   469
lemma subint1I: "\<lbrakk>iface G I = Some i; J \<in> set (isuperIfs i)\<rbrakk> 
schirmer@12854
   470
                 \<Longrightarrow> (I,J) \<in> subint1 G" 
schirmer@12854
   471
apply (simp add: subint1_def)
schirmer@12854
   472
done
schirmer@12854
   473
schirmer@12854
   474
lemma subcls1I:"\<lbrakk>class G C = Some c; C \<noteq> Object\<rbrakk> \<Longrightarrow> (C,(super c)) \<in> subcls1 G"
schirmer@12854
   475
apply (simp add: subcls1_def)
schirmer@12854
   476
done
schirmer@12854
   477
schirmer@12854
   478
schirmer@12854
   479
lemma subint1D: "(I,J)\<in>subint1 G\<Longrightarrow> \<exists>i\<in>iface G I: J\<in>set (isuperIfs i)"
schirmer@12854
   480
by (simp add: subint1_def)
schirmer@12854
   481
schirmer@12854
   482
lemma subcls1D: 
schirmer@12854
   483
  "(C,D)\<in>subcls1 G \<Longrightarrow> C\<noteq>Object \<and> (\<exists>c. class G C = Some c \<and> (super c = D))"
schirmer@12854
   484
apply (simp add: subcls1_def)
schirmer@12854
   485
apply auto
schirmer@12854
   486
done
schirmer@12854
   487
schirmer@12854
   488
lemma subint1_def2:  
paulson@14952
   489
  "subint1 G = (SIGMA I: {I. is_iface G I}. set (isuperIfs (the (iface G I))))"
schirmer@12854
   490
apply (unfold subint1_def)
schirmer@12854
   491
apply auto
schirmer@12854
   492
done
schirmer@12854
   493
schirmer@12854
   494
lemma subcls1_def2: 
paulson@14952
   495
  "subcls1 G = 
paulson@14952
   496
     (SIGMA C: {C. is_class G C}. {D. C\<noteq>Object \<and> super (the(class G C))=D})"
schirmer@12854
   497
apply (unfold subcls1_def)
schirmer@12854
   498
apply auto
schirmer@12854
   499
done
schirmer@12854
   500
schirmer@12854
   501
lemma subcls_is_class:
schirmer@12854
   502
"\<lbrakk>G\<turnstile>C \<prec>\<^sub>C D\<rbrakk> \<Longrightarrow> \<exists> c. class G C = Some c"
schirmer@12854
   503
by (auto simp add: subcls1_def dest: tranclD)
schirmer@12854
   504
schirmer@12854
   505
lemma no_subcls1_Object:"G\<turnstile>Object\<prec>\<^sub>C\<^sub>1 D \<Longrightarrow> P"
schirmer@12854
   506
by (auto simp add: subcls1_def)
schirmer@12854
   507
schirmer@12854
   508
lemma no_subcls_Object: "G\<turnstile>Object\<prec>\<^sub>C D \<Longrightarrow> P"
schirmer@12854
   509
apply (erule trancl_induct)
schirmer@12854
   510
apply (auto intro: no_subcls1_Object)
schirmer@12854
   511
done
schirmer@12854
   512
schirmer@12854
   513
section "well-structured programs"
schirmer@12854
   514
schirmer@12854
   515
constdefs
schirmer@12854
   516
  ws_idecl :: "prog \<Rightarrow> qtname \<Rightarrow> qtname list \<Rightarrow> bool"
schirmer@12854
   517
 "ws_idecl G I si \<equiv> \<forall>J\<in>set si.  is_iface G J   \<and> (J,I)\<notin>(subint1 G)^+"
schirmer@12854
   518
  
schirmer@12854
   519
  ws_cdecl :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   520
 "ws_cdecl G C sc \<equiv> C\<noteq>Object \<longrightarrow> is_class G sc \<and> (sc,C)\<notin>(subcls1 G)^+"
schirmer@12854
   521
  
schirmer@12854
   522
  ws_prog  :: "prog \<Rightarrow> bool"
schirmer@12854
   523
 "ws_prog G \<equiv> (\<forall>(I,i)\<in>set (ifaces  G). ws_idecl G I (isuperIfs i)) \<and> 
wenzelm@32960
   524
              (\<forall>(C,c)\<in>set (classes G). ws_cdecl G C (super c))"
schirmer@12854
   525
schirmer@12854
   526
schirmer@12854
   527
lemma ws_progI: 
schirmer@12854
   528
"\<lbrakk>\<forall>(I,i)\<in>set (ifaces G). \<forall>J\<in>set (isuperIfs i). is_iface G J \<and> 
schirmer@12854
   529
                                                (J,I) \<notin> (subint1 G)^+; 
schirmer@12854
   530
  \<forall>(C,c)\<in>set (classes G). C\<noteq>Object \<longrightarrow> is_class G (super c) \<and> 
schirmer@12854
   531
                                        ((super c),C) \<notin> (subcls1 G)^+  
schirmer@12854
   532
 \<rbrakk> \<Longrightarrow> ws_prog G"
schirmer@12854
   533
apply (unfold ws_prog_def ws_idecl_def ws_cdecl_def)
schirmer@12854
   534
apply (erule_tac conjI)
schirmer@12854
   535
apply blast
schirmer@12854
   536
done
schirmer@12854
   537
schirmer@12854
   538
lemma ws_prog_ideclD: 
schirmer@12854
   539
"\<lbrakk>iface G I = Some i; J\<in>set (isuperIfs i); ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   540
  is_iface G J \<and> (J,I)\<notin>(subint1 G)^+"
schirmer@12854
   541
apply (unfold ws_prog_def ws_idecl_def)
schirmer@12854
   542
apply clarify
schirmer@12854
   543
apply (drule_tac map_of_SomeD)
schirmer@12854
   544
apply auto
schirmer@12854
   545
done
schirmer@12854
   546
schirmer@12854
   547
lemma ws_prog_cdeclD: 
schirmer@12854
   548
"\<lbrakk>class G C = Some c; C\<noteq>Object; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   549
  is_class G (super c) \<and> (super c,C)\<notin>(subcls1 G)^+"
schirmer@12854
   550
apply (unfold ws_prog_def ws_cdecl_def)
schirmer@12854
   551
apply clarify
schirmer@12854
   552
apply (drule_tac map_of_SomeD)
schirmer@12854
   553
apply auto
schirmer@12854
   554
done
schirmer@12854
   555
schirmer@12854
   556
schirmer@12854
   557
section "well-foundedness"
schirmer@12854
   558
schirmer@12854
   559
lemma finite_is_iface: "finite {I. is_iface G I}"
schirmer@12854
   560
apply (fold dom_def)
schirmer@12854
   561
apply (rule_tac finite_dom_map_of)
schirmer@12854
   562
done
schirmer@12854
   563
schirmer@12854
   564
lemma finite_is_class: "finite {C. is_class G C}"
schirmer@12854
   565
apply (fold dom_def)
schirmer@12854
   566
apply (rule_tac finite_dom_map_of)
schirmer@12854
   567
done
schirmer@12854
   568
schirmer@12854
   569
lemma finite_subint1: "finite (subint1 G)"
schirmer@12854
   570
apply (subst subint1_def2)
schirmer@12854
   571
apply (rule finite_SigmaI)
schirmer@12854
   572
apply (rule finite_is_iface)
schirmer@12854
   573
apply (simp (no_asm))
schirmer@12854
   574
done
schirmer@12854
   575
schirmer@12854
   576
lemma finite_subcls1: "finite (subcls1 G)"
schirmer@12854
   577
apply (subst subcls1_def2)
schirmer@12854
   578
apply (rule finite_SigmaI)
schirmer@12854
   579
apply (rule finite_is_class)
schirmer@12854
   580
apply (rule_tac B = "{super (the (class G C))}" in finite_subset)
schirmer@12854
   581
apply  auto
schirmer@12854
   582
done
schirmer@12854
   583
schirmer@12854
   584
lemma subint1_irrefl_lemma1: 
schirmer@12854
   585
  "ws_prog G \<Longrightarrow> (subint1 G)^-1 \<inter> (subint1 G)^+ = {}"
schirmer@12854
   586
apply (force dest: subint1D ws_prog_ideclD conjunct2)
schirmer@12854
   587
done
schirmer@12854
   588
schirmer@12854
   589
lemma subcls1_irrefl_lemma1: 
schirmer@12854
   590
  "ws_prog G \<Longrightarrow> (subcls1 G)^-1 \<inter> (subcls1 G)^+ = {}"
schirmer@12854
   591
apply (force dest: subcls1D ws_prog_cdeclD conjunct2)
schirmer@12854
   592
done
schirmer@12854
   593
schirmer@12854
   594
lemmas subint1_irrefl_lemma2 = subint1_irrefl_lemma1 [THEN irrefl_tranclI']
schirmer@12854
   595
lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']
schirmer@12854
   596
schirmer@12854
   597
lemma subint1_irrefl: "\<lbrakk>(x, y) \<in> subint1 G; ws_prog G\<rbrakk> \<Longrightarrow> x \<noteq> y"
schirmer@12854
   598
apply (rule irrefl_trancl_rD)
schirmer@12854
   599
apply (rule subint1_irrefl_lemma2)
schirmer@12854
   600
apply auto
schirmer@12854
   601
done
schirmer@12854
   602
schirmer@12854
   603
lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1 G; ws_prog G\<rbrakk> \<Longrightarrow> x \<noteq> y"
schirmer@12854
   604
apply (rule irrefl_trancl_rD)
schirmer@12854
   605
apply (rule subcls1_irrefl_lemma2)
schirmer@12854
   606
apply auto
schirmer@12854
   607
done
schirmer@12854
   608
schirmer@12854
   609
lemmas subint1_acyclic = subint1_irrefl_lemma2 [THEN acyclicI, standard]
schirmer@12854
   610
lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI, standard]
schirmer@12854
   611
schirmer@12854
   612
schirmer@12854
   613
lemma wf_subint1: "ws_prog G \<Longrightarrow> wf ((subint1 G)\<inverse>)"
schirmer@12854
   614
by (auto intro: finite_acyclic_wf_converse finite_subint1 subint1_acyclic)
schirmer@12854
   615
schirmer@12854
   616
lemma wf_subcls1: "ws_prog G \<Longrightarrow> wf ((subcls1 G)\<inverse>)"
schirmer@12854
   617
by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)
schirmer@12854
   618
schirmer@12854
   619
schirmer@12854
   620
lemma subint1_induct: 
schirmer@12854
   621
  "\<lbrakk>ws_prog G; \<And>x. \<forall>y. (x, y) \<in> subint1 G \<longrightarrow> P y \<Longrightarrow> P x\<rbrakk> \<Longrightarrow> P a"
schirmer@12854
   622
apply (frule wf_subint1)
schirmer@12854
   623
apply (erule wf_induct)
schirmer@12854
   624
apply (simp (no_asm_use) only: converse_iff)
schirmer@12854
   625
apply blast
schirmer@12854
   626
done
schirmer@12854
   627
schirmer@12854
   628
lemma subcls1_induct [consumes 1]:
schirmer@12854
   629
  "\<lbrakk>ws_prog G; \<And>x. \<forall>y. (x, y) \<in> subcls1 G \<longrightarrow> P y \<Longrightarrow> P x\<rbrakk> \<Longrightarrow> P a"
schirmer@12854
   630
apply (frule wf_subcls1)
schirmer@12854
   631
apply (erule wf_induct)
schirmer@12854
   632
apply (simp (no_asm_use) only: converse_iff)
schirmer@12854
   633
apply blast
schirmer@12854
   634
done
schirmer@12854
   635
schirmer@12854
   636
lemma ws_subint1_induct: 
schirmer@12854
   637
 "\<lbrakk>is_iface G I; ws_prog G; \<And>I i. \<lbrakk>iface G I = Some i \<and> 
schirmer@12854
   638
   (\<forall>J \<in> set (isuperIfs i). (I,J)\<in>subint1 G \<and> P J \<and> is_iface G J)\<rbrakk> \<Longrightarrow> P I
schirmer@12854
   639
  \<rbrakk> \<Longrightarrow> P I"
wenzelm@24038
   640
apply (erule rev_mp)
schirmer@12854
   641
apply (rule subint1_induct)
schirmer@12854
   642
apply  assumption
paulson@18447
   643
apply (simp (no_asm)) 
schirmer@12854
   644
apply safe
paulson@18447
   645
apply (blast dest: subint1I ws_prog_ideclD)
schirmer@12854
   646
done
schirmer@12854
   647
schirmer@12854
   648
schirmer@12854
   649
lemma ws_subcls1_induct: "\<lbrakk>is_class G C; ws_prog G;  
schirmer@12854
   650
  \<And>C c. \<lbrakk>class G C = Some c;  
schirmer@12854
   651
 (C \<noteq> Object \<longrightarrow> (C,(super c))\<in>subcls1 G \<and> 
schirmer@12854
   652
                  P (super c) \<and> is_class G (super c))\<rbrakk> \<Longrightarrow> P C
schirmer@12854
   653
 \<rbrakk> \<Longrightarrow> P C"
wenzelm@24038
   654
apply (erule rev_mp)
schirmer@12854
   655
apply (rule subcls1_induct)
schirmer@12854
   656
apply  assumption
paulson@18447
   657
apply (simp (no_asm)) 
schirmer@12854
   658
apply safe
schirmer@12854
   659
apply (fast dest: subcls1I ws_prog_cdeclD)
schirmer@12854
   660
done
schirmer@12854
   661
schirmer@12854
   662
lemma ws_class_induct [consumes 2, case_names Object Subcls]:
schirmer@12854
   663
"\<lbrakk>class G C = Some c; ws_prog G; 
schirmer@12854
   664
  \<And> co. class G Object = Some co \<Longrightarrow> P Object; 
schirmer@12854
   665
  \<And>  C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C
schirmer@12854
   666
 \<rbrakk> \<Longrightarrow> P C"
schirmer@12854
   667
proof -
schirmer@12854
   668
  assume clsC: "class G C = Some c"
schirmer@12854
   669
  and    init: "\<And> co. class G Object = Some co \<Longrightarrow> P Object"
schirmer@12854
   670
  and    step: "\<And>   C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C"
schirmer@12854
   671
  assume ws: "ws_prog G"
schirmer@12854
   672
  then have "is_class G C \<Longrightarrow> P C"  
schirmer@12854
   673
  proof (induct rule: subcls1_induct)
schirmer@12854
   674
    fix C
schirmer@12854
   675
    assume   hyp:"\<forall> S. G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S \<longrightarrow> is_class G S \<longrightarrow> P S"
schirmer@12854
   676
       and iscls:"is_class G C"
schirmer@12854
   677
    show "P C"
schirmer@12854
   678
    proof (cases "C=Object")
schirmer@12854
   679
      case True with iscls init show "P C" by auto
schirmer@12854
   680
    next
schirmer@12854
   681
      case False with ws step hyp iscls 
nipkow@18576
   682
      show "P C" by (auto dest: subcls1I ws_prog_cdeclD)
schirmer@12854
   683
    qed
schirmer@12854
   684
  qed
schirmer@12854
   685
  with clsC show ?thesis by simp
schirmer@12854
   686
qed
schirmer@12854
   687
schirmer@12854
   688
lemma ws_class_induct' [consumes 2, case_names Object Subcls]:
schirmer@12854
   689
"\<lbrakk>is_class G C; ws_prog G; 
schirmer@12854
   690
  \<And> co. class G Object = Some co \<Longrightarrow> P Object; 
schirmer@12854
   691
  \<And> C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C
schirmer@12854
   692
 \<rbrakk> \<Longrightarrow> P C"
paulson@18447
   693
by (auto intro: ws_class_induct)
schirmer@12854
   694
schirmer@12854
   695
lemma ws_class_induct'' [consumes 2, case_names Object Subcls]:
schirmer@12854
   696
"\<lbrakk>class G C = Some c; ws_prog G; 
schirmer@12854
   697
  \<And> co. class G Object = Some co \<Longrightarrow> P Object co; 
schirmer@12854
   698
  \<And>  C c sc. \<lbrakk>class G C = Some c; class G (super c) = Some sc;
schirmer@12854
   699
            C \<noteq> Object; P (super c) sc\<rbrakk> \<Longrightarrow> P C c
schirmer@12854
   700
 \<rbrakk> \<Longrightarrow> P C c"
schirmer@12854
   701
proof -
schirmer@12854
   702
  assume clsC: "class G C = Some c"
schirmer@12854
   703
  and    init: "\<And> co. class G Object = Some co \<Longrightarrow> P Object co"
schirmer@12854
   704
  and    step: "\<And> C c sc . \<lbrakk>class G C = Some c; class G (super c) = Some sc;
schirmer@12854
   705
                             C \<noteq> Object; P (super c) sc\<rbrakk> \<Longrightarrow> P C c"
schirmer@12854
   706
  assume ws: "ws_prog G"
schirmer@12854
   707
  then have "\<And> c. class G C = Some c\<Longrightarrow> P C c"  
schirmer@12854
   708
  proof (induct rule: subcls1_induct)
schirmer@12854
   709
    fix C c
schirmer@12854
   710
    assume   hyp:"\<forall> S. G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S \<longrightarrow> (\<forall> s. class G S = Some s \<longrightarrow> P S s)"
schirmer@12854
   711
       and iscls:"class G C = Some c"
schirmer@12854
   712
    show "P C c"
schirmer@12854
   713
    proof (cases "C=Object")
schirmer@12854
   714
      case True with iscls init show "P C c" by auto
schirmer@12854
   715
    next
schirmer@12854
   716
      case False
schirmer@12854
   717
      with ws iscls obtain sc where
wenzelm@32960
   718
        sc: "class G (super c) = Some sc"
wenzelm@32960
   719
        by (auto dest: ws_prog_cdeclD)
schirmer@12854
   720
      from iscls False have "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 (super c)" by (rule subcls1I)
schirmer@12854
   721
      with False ws step hyp iscls sc
schirmer@12854
   722
      show "P C c" 
wenzelm@32960
   723
        by (auto)  
schirmer@12854
   724
    qed
schirmer@12854
   725
  qed
schirmer@12854
   726
  with clsC show "P C c" by auto
schirmer@12854
   727
qed
schirmer@12854
   728
schirmer@12854
   729
lemma ws_interface_induct [consumes 2, case_names Step]:
wenzelm@12937
   730
  assumes is_if_I: "is_iface G I" and 
schirmer@12854
   731
               ws: "ws_prog G" and
schirmer@12854
   732
          hyp_sub: "\<And>I i. \<lbrakk>iface G I = Some i; 
schirmer@12854
   733
                            \<forall> J \<in> set (isuperIfs i).
schirmer@12854
   734
                                 (I,J)\<in>subint1 G \<and> P J \<and> is_iface G J\<rbrakk> \<Longrightarrow> P I"
wenzelm@12937
   735
  shows "P I"
schirmer@12854
   736
proof -
schirmer@12854
   737
  from is_if_I ws 
schirmer@12854
   738
  show "P I"
schirmer@12854
   739
  proof (rule ws_subint1_induct)
schirmer@12854
   740
    fix I i
schirmer@12854
   741
    assume hyp: "iface G I = Some i \<and>
schirmer@12854
   742
                (\<forall>J\<in>set (isuperIfs i). (I,J) \<in>subint1 G \<and> P J \<and> is_iface G J)"
schirmer@12854
   743
    then have if_I: "iface G I = Some i"
schirmer@12854
   744
      by blast
schirmer@12854
   745
    show "P I"
schirmer@12854
   746
    proof (cases "isuperIfs i")
schirmer@12854
   747
      case Nil
schirmer@12854
   748
      with if_I hyp_sub 
schirmer@12854
   749
      show "P I" 
wenzelm@32960
   750
        by auto
schirmer@12854
   751
    next
schirmer@12854
   752
      case (Cons hd tl)
schirmer@12854
   753
      with hyp if_I hyp_sub 
schirmer@12854
   754
      show "P I" 
wenzelm@32960
   755
        by auto
schirmer@12854
   756
    qed
schirmer@12854
   757
  qed
schirmer@12854
   758
qed
schirmer@12854
   759
schirmer@12854
   760
section "general recursion operators for the interface and class hiearchies"
schirmer@12854
   761
schirmer@12854
   762
consts
schirmer@12854
   763
  iface_rec  :: "prog \<times> qtname \<Rightarrow>   \<spacespace>  (qtname \<Rightarrow> iface \<Rightarrow> 'a set \<Rightarrow> 'a) \<Rightarrow> 'a"
schirmer@12854
   764
  class_rec  :: "prog \<times> qtname \<Rightarrow> 'a \<Rightarrow> (qtname \<Rightarrow> class \<Rightarrow> 'a     \<Rightarrow> 'a) \<Rightarrow> 'a"
schirmer@12854
   765
schirmer@12854
   766
recdef iface_rec "same_fst ws_prog (\<lambda>G. (subint1 G)^-1)" 
schirmer@12854
   767
"iface_rec (G,I) = 
schirmer@12854
   768
  (\<lambda>f. case iface G I of 
haftmann@28524
   769
         None \<Rightarrow> undefined 
schirmer@12854
   770
       | Some i \<Rightarrow> if ws_prog G 
schirmer@12854
   771
                      then f I i 
schirmer@12854
   772
                               ((\<lambda>J. iface_rec (G,J) f)`set (isuperIfs i))
haftmann@28524
   773
                      else undefined)"
schirmer@12854
   774
(hints recdef_wf: wf_subint1 intro: subint1I)
schirmer@12854
   775
declare iface_rec.simps [simp del]
schirmer@12854
   776
schirmer@12854
   777
lemma iface_rec: 
schirmer@12854
   778
"\<lbrakk>iface G I = Some i; ws_prog G\<rbrakk> \<Longrightarrow> 
schirmer@12854
   779
 iface_rec (G,I) f = f I i ((\<lambda>J. iface_rec (G,J) f)`set (isuperIfs i))"
schirmer@12854
   780
apply (subst iface_rec.simps)
schirmer@12854
   781
apply simp
schirmer@12854
   782
done
schirmer@12854
   783
schirmer@12854
   784
recdef class_rec "same_fst ws_prog (\<lambda>G. (subcls1 G)^-1)"
schirmer@12854
   785
"class_rec(G,C) = 
schirmer@12854
   786
  (\<lambda>t f. case class G C of 
haftmann@28524
   787
           None \<Rightarrow> undefined 
schirmer@12854
   788
         | Some c \<Rightarrow> if ws_prog G 
schirmer@12854
   789
                        then f C c 
schirmer@12854
   790
                                 (if C = Object then t 
schirmer@12854
   791
                                                else class_rec (G,super c) t f)
haftmann@28524
   792
                        else undefined)"
schirmer@12854
   793
(hints recdef_wf: wf_subcls1 intro: subcls1I)
schirmer@12854
   794
declare class_rec.simps [simp del]
schirmer@12854
   795
schirmer@12854
   796
lemma class_rec: "\<lbrakk>class G C = Some c; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   797
 class_rec (G,C) t f = 
schirmer@12854
   798
   f C c (if C = Object then t else class_rec (G,super c) t f)"
schirmer@12854
   799
apply (rule class_rec.simps [THEN trans [THEN fun_cong [THEN fun_cong]]])
schirmer@12854
   800
apply simp
schirmer@12854
   801
done
schirmer@12854
   802
schirmer@12854
   803
constdefs
schirmer@12854
   804
imethds:: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables"
schirmer@13688
   805
  --{* methods of an interface, with overriding and inheritance, cf. 9.2 *}
schirmer@12854
   806
"imethds G I 
schirmer@12854
   807
  \<equiv> iface_rec (G,I)  
schirmer@12854
   808
              (\<lambda>I i ts. (Un_tables ts) \<oplus>\<oplus> 
nipkow@30235
   809
                        (Option.set \<circ> table_of (map (\<lambda>(s,m). (s,I,m)) (imethods i))))"
wenzelm@32960
   810
        
schirmer@12854
   811
schirmer@12854
   812
schirmer@12854
   813
end