src/HOL/Bali/Decl.thy
author haftmann
Tue Oct 07 16:07:50 2008 +0200 (2008-10-07)
changeset 28524 644b62cf678f
parent 27682 25aceefd4786
child 30235 58d147683393
permissions -rw-r--r--
arbitrary is undefined
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 *)
schirmer@12854
   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 *}
schirmer@12854
   297
types	
schirmer@13688
   298
	idecl           --{* interface declaration, cf. 9.1 *}
schirmer@12854
   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 *}
schirmer@12854
   329
types	
schirmer@13688
   330
	cdecl           --{* class declaration, cf. 8.1 *}
schirmer@12854
   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,
schirmer@12854
   391
		SXcptC NullPointer, SXcptC OutOfMemory, SXcptC ClassCast,
schirmer@12854
   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
schirmer@12854
   405
syntax
schirmer@12854
   406
  iface     :: "prog  \<Rightarrow> (qtname, iface) table"
haftmann@18551
   407
  "class"     :: "prog  \<Rightarrow> (qtname, class) table"
schirmer@12854
   408
  is_iface  :: "prog  \<Rightarrow> qtname  \<Rightarrow> bool"
schirmer@12854
   409
  is_class  :: "prog  \<Rightarrow> qtname  \<Rightarrow> bool"
schirmer@12854
   410
schirmer@12854
   411
translations
schirmer@12854
   412
	   "iface G I" == "table_of (ifaces G) I"
schirmer@12854
   413
	   "class G C" == "table_of (classes G) C"
schirmer@12854
   414
	"is_iface G I" == "iface G I \<noteq> None"
schirmer@12854
   415
	"is_class G C" == "class G C \<noteq> None"
schirmer@12854
   416
schirmer@12854
   417
schirmer@12854
   418
section "is type"
schirmer@12854
   419
schirmer@12854
   420
consts
schirmer@12854
   421
  is_type :: "prog \<Rightarrow>     ty \<Rightarrow> bool"
schirmer@12854
   422
  isrtype :: "prog \<Rightarrow> ref_ty \<Rightarrow> bool"
schirmer@12854
   423
schirmer@12854
   424
primrec	"is_type G (PrimT pt)  = True"
schirmer@12854
   425
	"is_type G (RefT  rt)  = isrtype G rt"
schirmer@12854
   426
	"isrtype G (NullT    ) = True"
schirmer@12854
   427
	"isrtype G (IfaceT tn) = is_iface G tn"
schirmer@12854
   428
	"isrtype G (ClassT tn) = is_class G tn"
schirmer@12854
   429
	"isrtype G (ArrayT T ) = is_type  G T"
schirmer@12854
   430
schirmer@12854
   431
lemma type_is_iface: "is_type G (Iface I) \<Longrightarrow> is_iface G I"
schirmer@12854
   432
by auto
schirmer@12854
   433
schirmer@12854
   434
lemma type_is_class: "is_type G (Class C) \<Longrightarrow>  is_class G C"
schirmer@12854
   435
by auto
schirmer@12854
   436
schirmer@12854
   437
schirmer@12854
   438
section "subinterface and subclass relation, in anticipation of TypeRel.thy"
schirmer@12854
   439
schirmer@12854
   440
consts 
schirmer@13688
   441
  subint1  :: "prog \<Rightarrow> (qtname \<times> qtname) set" --{* direct subinterface *}
schirmer@13688
   442
  subcls1  :: "prog \<Rightarrow> (qtname \<times> qtname) set" --{* direct subclass     *}
schirmer@12854
   443
schirmer@12854
   444
defs
schirmer@12854
   445
  subint1_def: "subint1 G \<equiv> {(I,J). \<exists>i\<in>iface G I: J\<in>set (isuperIfs i)}"
schirmer@12854
   446
  subcls1_def: "subcls1 G \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c\<in>class G C: super c = D)}"
schirmer@12854
   447
schirmer@12854
   448
syntax
wenzelm@24783
   449
 "_subcls1" :: "prog => [qtname, qtname] => bool" ("_|-_<:C1_" [71,71,71] 70)
wenzelm@24783
   450
 "_subclseq":: "prog => [qtname, qtname] => bool" ("_|-_<=:C _"[71,71,71] 70)
wenzelm@24783
   451
 "_subcls"  :: "prog => [qtname, qtname] => bool" ("_|-_<:C _"[71,71,71] 70)
schirmer@12854
   452
schirmer@12854
   453
syntax (xsymbols)
wenzelm@24783
   454
  "_subcls1" :: "prog \<Rightarrow> [qtname, qtname] \<Rightarrow> bool" ("_\<turnstile>_\<prec>\<^sub>C\<^sub>1_"  [71,71,71] 70)
wenzelm@24783
   455
  "_subclseq":: "prog \<Rightarrow> [qtname, qtname] \<Rightarrow> bool" ("_\<turnstile>_\<preceq>\<^sub>C _"  [71,71,71] 70)
wenzelm@24783
   456
  "_subcls"  :: "prog \<Rightarrow> [qtname, qtname] \<Rightarrow> bool" ("_\<turnstile>_\<prec>\<^sub>C _"  [71,71,71] 70)
schirmer@12854
   457
schirmer@12854
   458
translations
schirmer@12854
   459
        "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 D" == "(C,D) \<in> subcls1 G"
schirmer@12854
   460
	"G\<turnstile>C \<preceq>\<^sub>C  D" == "(C,D) \<in>(subcls1 G)^*" (* cf. 8.1.3 *)
schirmer@12854
   461
        "G\<turnstile>C \<prec>\<^sub>C  D" == "(C,D) \<in>(subcls1 G)^+"
schirmer@12854
   462
 
schirmer@12854
   463
schirmer@12854
   464
lemma subint1I: "\<lbrakk>iface G I = Some i; J \<in> set (isuperIfs i)\<rbrakk> 
schirmer@12854
   465
                 \<Longrightarrow> (I,J) \<in> subint1 G" 
schirmer@12854
   466
apply (simp add: subint1_def)
schirmer@12854
   467
done
schirmer@12854
   468
schirmer@12854
   469
lemma subcls1I:"\<lbrakk>class G C = Some c; C \<noteq> Object\<rbrakk> \<Longrightarrow> (C,(super c)) \<in> subcls1 G"
schirmer@12854
   470
apply (simp add: subcls1_def)
schirmer@12854
   471
done
schirmer@12854
   472
schirmer@12854
   473
schirmer@12854
   474
lemma subint1D: "(I,J)\<in>subint1 G\<Longrightarrow> \<exists>i\<in>iface G I: J\<in>set (isuperIfs i)"
schirmer@12854
   475
by (simp add: subint1_def)
schirmer@12854
   476
schirmer@12854
   477
lemma subcls1D: 
schirmer@12854
   478
  "(C,D)\<in>subcls1 G \<Longrightarrow> C\<noteq>Object \<and> (\<exists>c. class G C = Some c \<and> (super c = D))"
schirmer@12854
   479
apply (simp add: subcls1_def)
schirmer@12854
   480
apply auto
schirmer@12854
   481
done
schirmer@12854
   482
schirmer@12854
   483
lemma subint1_def2:  
paulson@14952
   484
  "subint1 G = (SIGMA I: {I. is_iface G I}. set (isuperIfs (the (iface G I))))"
schirmer@12854
   485
apply (unfold subint1_def)
schirmer@12854
   486
apply auto
schirmer@12854
   487
done
schirmer@12854
   488
schirmer@12854
   489
lemma subcls1_def2: 
paulson@14952
   490
  "subcls1 G = 
paulson@14952
   491
     (SIGMA C: {C. is_class G C}. {D. C\<noteq>Object \<and> super (the(class G C))=D})"
schirmer@12854
   492
apply (unfold subcls1_def)
schirmer@12854
   493
apply auto
schirmer@12854
   494
done
schirmer@12854
   495
schirmer@12854
   496
lemma subcls_is_class:
schirmer@12854
   497
"\<lbrakk>G\<turnstile>C \<prec>\<^sub>C D\<rbrakk> \<Longrightarrow> \<exists> c. class G C = Some c"
schirmer@12854
   498
by (auto simp add: subcls1_def dest: tranclD)
schirmer@12854
   499
schirmer@12854
   500
lemma no_subcls1_Object:"G\<turnstile>Object\<prec>\<^sub>C\<^sub>1 D \<Longrightarrow> P"
schirmer@12854
   501
by (auto simp add: subcls1_def)
schirmer@12854
   502
schirmer@12854
   503
lemma no_subcls_Object: "G\<turnstile>Object\<prec>\<^sub>C D \<Longrightarrow> P"
schirmer@12854
   504
apply (erule trancl_induct)
schirmer@12854
   505
apply (auto intro: no_subcls1_Object)
schirmer@12854
   506
done
schirmer@12854
   507
schirmer@12854
   508
section "well-structured programs"
schirmer@12854
   509
schirmer@12854
   510
constdefs
schirmer@12854
   511
  ws_idecl :: "prog \<Rightarrow> qtname \<Rightarrow> qtname list \<Rightarrow> bool"
schirmer@12854
   512
 "ws_idecl G I si \<equiv> \<forall>J\<in>set si.  is_iface G J   \<and> (J,I)\<notin>(subint1 G)^+"
schirmer@12854
   513
  
schirmer@12854
   514
  ws_cdecl :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   515
 "ws_cdecl G C sc \<equiv> C\<noteq>Object \<longrightarrow> is_class G sc \<and> (sc,C)\<notin>(subcls1 G)^+"
schirmer@12854
   516
  
schirmer@12854
   517
  ws_prog  :: "prog \<Rightarrow> bool"
schirmer@12854
   518
 "ws_prog G \<equiv> (\<forall>(I,i)\<in>set (ifaces  G). ws_idecl G I (isuperIfs i)) \<and> 
schirmer@12854
   519
	      (\<forall>(C,c)\<in>set (classes G). ws_cdecl G C (super c))"
schirmer@12854
   520
schirmer@12854
   521
schirmer@12854
   522
lemma ws_progI: 
schirmer@12854
   523
"\<lbrakk>\<forall>(I,i)\<in>set (ifaces G). \<forall>J\<in>set (isuperIfs i). is_iface G J \<and> 
schirmer@12854
   524
                                                (J,I) \<notin> (subint1 G)^+; 
schirmer@12854
   525
  \<forall>(C,c)\<in>set (classes G). C\<noteq>Object \<longrightarrow> is_class G (super c) \<and> 
schirmer@12854
   526
                                        ((super c),C) \<notin> (subcls1 G)^+  
schirmer@12854
   527
 \<rbrakk> \<Longrightarrow> ws_prog G"
schirmer@12854
   528
apply (unfold ws_prog_def ws_idecl_def ws_cdecl_def)
schirmer@12854
   529
apply (erule_tac conjI)
schirmer@12854
   530
apply blast
schirmer@12854
   531
done
schirmer@12854
   532
schirmer@12854
   533
lemma ws_prog_ideclD: 
schirmer@12854
   534
"\<lbrakk>iface G I = Some i; J\<in>set (isuperIfs i); ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   535
  is_iface G J \<and> (J,I)\<notin>(subint1 G)^+"
schirmer@12854
   536
apply (unfold ws_prog_def ws_idecl_def)
schirmer@12854
   537
apply clarify
schirmer@12854
   538
apply (drule_tac map_of_SomeD)
schirmer@12854
   539
apply auto
schirmer@12854
   540
done
schirmer@12854
   541
schirmer@12854
   542
lemma ws_prog_cdeclD: 
schirmer@12854
   543
"\<lbrakk>class G C = Some c; C\<noteq>Object; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   544
  is_class G (super c) \<and> (super c,C)\<notin>(subcls1 G)^+"
schirmer@12854
   545
apply (unfold ws_prog_def ws_cdecl_def)
schirmer@12854
   546
apply clarify
schirmer@12854
   547
apply (drule_tac map_of_SomeD)
schirmer@12854
   548
apply auto
schirmer@12854
   549
done
schirmer@12854
   550
schirmer@12854
   551
schirmer@12854
   552
section "well-foundedness"
schirmer@12854
   553
schirmer@12854
   554
lemma finite_is_iface: "finite {I. is_iface G I}"
schirmer@12854
   555
apply (fold dom_def)
schirmer@12854
   556
apply (rule_tac finite_dom_map_of)
schirmer@12854
   557
done
schirmer@12854
   558
schirmer@12854
   559
lemma finite_is_class: "finite {C. is_class G C}"
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_subint1: "finite (subint1 G)"
schirmer@12854
   565
apply (subst subint1_def2)
schirmer@12854
   566
apply (rule finite_SigmaI)
schirmer@12854
   567
apply (rule finite_is_iface)
schirmer@12854
   568
apply (simp (no_asm))
schirmer@12854
   569
done
schirmer@12854
   570
schirmer@12854
   571
lemma finite_subcls1: "finite (subcls1 G)"
schirmer@12854
   572
apply (subst subcls1_def2)
schirmer@12854
   573
apply (rule finite_SigmaI)
schirmer@12854
   574
apply (rule finite_is_class)
schirmer@12854
   575
apply (rule_tac B = "{super (the (class G C))}" in finite_subset)
schirmer@12854
   576
apply  auto
schirmer@12854
   577
done
schirmer@12854
   578
schirmer@12854
   579
lemma subint1_irrefl_lemma1: 
schirmer@12854
   580
  "ws_prog G \<Longrightarrow> (subint1 G)^-1 \<inter> (subint1 G)^+ = {}"
schirmer@12854
   581
apply (force dest: subint1D ws_prog_ideclD conjunct2)
schirmer@12854
   582
done
schirmer@12854
   583
schirmer@12854
   584
lemma subcls1_irrefl_lemma1: 
schirmer@12854
   585
  "ws_prog G \<Longrightarrow> (subcls1 G)^-1 \<inter> (subcls1 G)^+ = {}"
schirmer@12854
   586
apply (force dest: subcls1D ws_prog_cdeclD conjunct2)
schirmer@12854
   587
done
schirmer@12854
   588
schirmer@12854
   589
lemmas subint1_irrefl_lemma2 = subint1_irrefl_lemma1 [THEN irrefl_tranclI']
schirmer@12854
   590
lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']
schirmer@12854
   591
schirmer@12854
   592
lemma subint1_irrefl: "\<lbrakk>(x, y) \<in> subint1 G; ws_prog G\<rbrakk> \<Longrightarrow> x \<noteq> y"
schirmer@12854
   593
apply (rule irrefl_trancl_rD)
schirmer@12854
   594
apply (rule subint1_irrefl_lemma2)
schirmer@12854
   595
apply auto
schirmer@12854
   596
done
schirmer@12854
   597
schirmer@12854
   598
lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1 G; ws_prog G\<rbrakk> \<Longrightarrow> x \<noteq> y"
schirmer@12854
   599
apply (rule irrefl_trancl_rD)
schirmer@12854
   600
apply (rule subcls1_irrefl_lemma2)
schirmer@12854
   601
apply auto
schirmer@12854
   602
done
schirmer@12854
   603
schirmer@12854
   604
lemmas subint1_acyclic = subint1_irrefl_lemma2 [THEN acyclicI, standard]
schirmer@12854
   605
lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI, standard]
schirmer@12854
   606
schirmer@12854
   607
schirmer@12854
   608
lemma wf_subint1: "ws_prog G \<Longrightarrow> wf ((subint1 G)\<inverse>)"
schirmer@12854
   609
by (auto intro: finite_acyclic_wf_converse finite_subint1 subint1_acyclic)
schirmer@12854
   610
schirmer@12854
   611
lemma wf_subcls1: "ws_prog G \<Longrightarrow> wf ((subcls1 G)\<inverse>)"
schirmer@12854
   612
by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)
schirmer@12854
   613
schirmer@12854
   614
schirmer@12854
   615
lemma subint1_induct: 
schirmer@12854
   616
  "\<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
   617
apply (frule wf_subint1)
schirmer@12854
   618
apply (erule wf_induct)
schirmer@12854
   619
apply (simp (no_asm_use) only: converse_iff)
schirmer@12854
   620
apply blast
schirmer@12854
   621
done
schirmer@12854
   622
schirmer@12854
   623
lemma subcls1_induct [consumes 1]:
schirmer@12854
   624
  "\<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
   625
apply (frule wf_subcls1)
schirmer@12854
   626
apply (erule wf_induct)
schirmer@12854
   627
apply (simp (no_asm_use) only: converse_iff)
schirmer@12854
   628
apply blast
schirmer@12854
   629
done
schirmer@12854
   630
schirmer@12854
   631
lemma ws_subint1_induct: 
schirmer@12854
   632
 "\<lbrakk>is_iface G I; ws_prog G; \<And>I i. \<lbrakk>iface G I = Some i \<and> 
schirmer@12854
   633
   (\<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
   634
  \<rbrakk> \<Longrightarrow> P I"
wenzelm@24038
   635
apply (erule rev_mp)
schirmer@12854
   636
apply (rule subint1_induct)
schirmer@12854
   637
apply  assumption
paulson@18447
   638
apply (simp (no_asm)) 
schirmer@12854
   639
apply safe
paulson@18447
   640
apply (blast dest: subint1I ws_prog_ideclD)
schirmer@12854
   641
done
schirmer@12854
   642
schirmer@12854
   643
schirmer@12854
   644
lemma ws_subcls1_induct: "\<lbrakk>is_class G C; ws_prog G;  
schirmer@12854
   645
  \<And>C c. \<lbrakk>class G C = Some c;  
schirmer@12854
   646
 (C \<noteq> Object \<longrightarrow> (C,(super c))\<in>subcls1 G \<and> 
schirmer@12854
   647
                  P (super c) \<and> is_class G (super c))\<rbrakk> \<Longrightarrow> P C
schirmer@12854
   648
 \<rbrakk> \<Longrightarrow> P C"
wenzelm@24038
   649
apply (erule rev_mp)
schirmer@12854
   650
apply (rule subcls1_induct)
schirmer@12854
   651
apply  assumption
paulson@18447
   652
apply (simp (no_asm)) 
schirmer@12854
   653
apply safe
schirmer@12854
   654
apply (fast dest: subcls1I ws_prog_cdeclD)
schirmer@12854
   655
done
schirmer@12854
   656
schirmer@12854
   657
lemma ws_class_induct [consumes 2, case_names Object Subcls]:
schirmer@12854
   658
"\<lbrakk>class G C = Some c; ws_prog G; 
schirmer@12854
   659
  \<And> co. class G Object = Some co \<Longrightarrow> P Object; 
schirmer@12854
   660
  \<And>  C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C
schirmer@12854
   661
 \<rbrakk> \<Longrightarrow> P C"
schirmer@12854
   662
proof -
schirmer@12854
   663
  assume clsC: "class G C = Some c"
schirmer@12854
   664
  and    init: "\<And> co. class G Object = Some co \<Longrightarrow> P Object"
schirmer@12854
   665
  and    step: "\<And>   C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C"
schirmer@12854
   666
  assume ws: "ws_prog G"
schirmer@12854
   667
  then have "is_class G C \<Longrightarrow> P C"  
schirmer@12854
   668
  proof (induct rule: subcls1_induct)
schirmer@12854
   669
    fix C
schirmer@12854
   670
    assume   hyp:"\<forall> S. G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S \<longrightarrow> is_class G S \<longrightarrow> P S"
schirmer@12854
   671
       and iscls:"is_class G C"
schirmer@12854
   672
    show "P C"
schirmer@12854
   673
    proof (cases "C=Object")
schirmer@12854
   674
      case True with iscls init show "P C" by auto
schirmer@12854
   675
    next
schirmer@12854
   676
      case False with ws step hyp iscls 
nipkow@18576
   677
      show "P C" by (auto dest: subcls1I ws_prog_cdeclD)
schirmer@12854
   678
    qed
schirmer@12854
   679
  qed
schirmer@12854
   680
  with clsC show ?thesis by simp
schirmer@12854
   681
qed
schirmer@12854
   682
schirmer@12854
   683
lemma ws_class_induct' [consumes 2, case_names Object Subcls]:
schirmer@12854
   684
"\<lbrakk>is_class G C; ws_prog G; 
schirmer@12854
   685
  \<And> co. class G Object = Some co \<Longrightarrow> P Object; 
schirmer@12854
   686
  \<And> C c. \<lbrakk>class G C = Some c; C \<noteq> Object; P (super c)\<rbrakk> \<Longrightarrow> P C
schirmer@12854
   687
 \<rbrakk> \<Longrightarrow> P C"
paulson@18447
   688
by (auto intro: ws_class_induct)
schirmer@12854
   689
schirmer@12854
   690
lemma ws_class_induct'' [consumes 2, case_names Object Subcls]:
schirmer@12854
   691
"\<lbrakk>class G C = Some c; ws_prog G; 
schirmer@12854
   692
  \<And> co. class G Object = Some co \<Longrightarrow> P Object co; 
schirmer@12854
   693
  \<And>  C c sc. \<lbrakk>class G C = Some c; class G (super c) = Some sc;
schirmer@12854
   694
            C \<noteq> Object; P (super c) sc\<rbrakk> \<Longrightarrow> P C c
schirmer@12854
   695
 \<rbrakk> \<Longrightarrow> P C c"
schirmer@12854
   696
proof -
schirmer@12854
   697
  assume clsC: "class G C = Some c"
schirmer@12854
   698
  and    init: "\<And> co. class G Object = Some co \<Longrightarrow> P Object co"
schirmer@12854
   699
  and    step: "\<And> C c sc . \<lbrakk>class G C = Some c; class G (super c) = Some sc;
schirmer@12854
   700
                             C \<noteq> Object; P (super c) sc\<rbrakk> \<Longrightarrow> P C c"
schirmer@12854
   701
  assume ws: "ws_prog G"
schirmer@12854
   702
  then have "\<And> c. class G C = Some c\<Longrightarrow> P C c"  
schirmer@12854
   703
  proof (induct rule: subcls1_induct)
schirmer@12854
   704
    fix C c
schirmer@12854
   705
    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
   706
       and iscls:"class G C = Some c"
schirmer@12854
   707
    show "P C c"
schirmer@12854
   708
    proof (cases "C=Object")
schirmer@12854
   709
      case True with iscls init show "P C c" by auto
schirmer@12854
   710
    next
schirmer@12854
   711
      case False
schirmer@12854
   712
      with ws iscls obtain sc where
schirmer@12854
   713
	sc: "class G (super c) = Some sc"
nipkow@18576
   714
	by (auto dest: ws_prog_cdeclD)
schirmer@12854
   715
      from iscls False have "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 (super c)" by (rule subcls1I)
schirmer@12854
   716
      with False ws step hyp iscls sc
schirmer@12854
   717
      show "P C c" 
schirmer@12854
   718
	by (auto)  
schirmer@12854
   719
    qed
schirmer@12854
   720
  qed
schirmer@12854
   721
  with clsC show "P C c" by auto
schirmer@12854
   722
qed
schirmer@12854
   723
schirmer@12854
   724
lemma ws_interface_induct [consumes 2, case_names Step]:
wenzelm@12937
   725
  assumes is_if_I: "is_iface G I" and 
schirmer@12854
   726
               ws: "ws_prog G" and
schirmer@12854
   727
          hyp_sub: "\<And>I i. \<lbrakk>iface G I = Some i; 
schirmer@12854
   728
                            \<forall> J \<in> set (isuperIfs i).
schirmer@12854
   729
                                 (I,J)\<in>subint1 G \<and> P J \<and> is_iface G J\<rbrakk> \<Longrightarrow> P I"
wenzelm@12937
   730
  shows "P I"
schirmer@12854
   731
proof -
schirmer@12854
   732
  from is_if_I ws 
schirmer@12854
   733
  show "P I"
schirmer@12854
   734
  proof (rule ws_subint1_induct)
schirmer@12854
   735
    fix I i
schirmer@12854
   736
    assume hyp: "iface G I = Some i \<and>
schirmer@12854
   737
                (\<forall>J\<in>set (isuperIfs i). (I,J) \<in>subint1 G \<and> P J \<and> is_iface G J)"
schirmer@12854
   738
    then have if_I: "iface G I = Some i"
schirmer@12854
   739
      by blast
schirmer@12854
   740
    show "P I"
schirmer@12854
   741
    proof (cases "isuperIfs i")
schirmer@12854
   742
      case Nil
schirmer@12854
   743
      with if_I hyp_sub 
schirmer@12854
   744
      show "P I" 
schirmer@12854
   745
	by auto
schirmer@12854
   746
    next
schirmer@12854
   747
      case (Cons hd tl)
schirmer@12854
   748
      with hyp if_I hyp_sub 
schirmer@12854
   749
      show "P I" 
schirmer@12854
   750
	by auto
schirmer@12854
   751
    qed
schirmer@12854
   752
  qed
schirmer@12854
   753
qed
schirmer@12854
   754
schirmer@12854
   755
section "general recursion operators for the interface and class hiearchies"
schirmer@12854
   756
schirmer@12854
   757
consts
schirmer@12854
   758
  iface_rec  :: "prog \<times> qtname \<Rightarrow>   \<spacespace>  (qtname \<Rightarrow> iface \<Rightarrow> 'a set \<Rightarrow> 'a) \<Rightarrow> 'a"
schirmer@12854
   759
  class_rec  :: "prog \<times> qtname \<Rightarrow> 'a \<Rightarrow> (qtname \<Rightarrow> class \<Rightarrow> 'a     \<Rightarrow> 'a) \<Rightarrow> 'a"
schirmer@12854
   760
schirmer@12854
   761
recdef iface_rec "same_fst ws_prog (\<lambda>G. (subint1 G)^-1)" 
schirmer@12854
   762
"iface_rec (G,I) = 
schirmer@12854
   763
  (\<lambda>f. case iface G I of 
haftmann@28524
   764
         None \<Rightarrow> undefined 
schirmer@12854
   765
       | Some i \<Rightarrow> if ws_prog G 
schirmer@12854
   766
                      then f I i 
schirmer@12854
   767
                               ((\<lambda>J. iface_rec (G,J) f)`set (isuperIfs i))
haftmann@28524
   768
                      else undefined)"
schirmer@12854
   769
(hints recdef_wf: wf_subint1 intro: subint1I)
schirmer@12854
   770
declare iface_rec.simps [simp del]
schirmer@12854
   771
schirmer@12854
   772
lemma iface_rec: 
schirmer@12854
   773
"\<lbrakk>iface G I = Some i; ws_prog G\<rbrakk> \<Longrightarrow> 
schirmer@12854
   774
 iface_rec (G,I) f = f I i ((\<lambda>J. iface_rec (G,J) f)`set (isuperIfs i))"
schirmer@12854
   775
apply (subst iface_rec.simps)
schirmer@12854
   776
apply simp
schirmer@12854
   777
done
schirmer@12854
   778
schirmer@12854
   779
recdef class_rec "same_fst ws_prog (\<lambda>G. (subcls1 G)^-1)"
schirmer@12854
   780
"class_rec(G,C) = 
schirmer@12854
   781
  (\<lambda>t f. case class G C of 
haftmann@28524
   782
           None \<Rightarrow> undefined 
schirmer@12854
   783
         | Some c \<Rightarrow> if ws_prog G 
schirmer@12854
   784
                        then f C c 
schirmer@12854
   785
                                 (if C = Object then t 
schirmer@12854
   786
                                                else class_rec (G,super c) t f)
haftmann@28524
   787
                        else undefined)"
schirmer@12854
   788
(hints recdef_wf: wf_subcls1 intro: subcls1I)
schirmer@12854
   789
declare class_rec.simps [simp del]
schirmer@12854
   790
schirmer@12854
   791
lemma class_rec: "\<lbrakk>class G C = Some c; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   792
 class_rec (G,C) t f = 
schirmer@12854
   793
   f C c (if C = Object then t else class_rec (G,super c) t f)"
schirmer@12854
   794
apply (rule class_rec.simps [THEN trans [THEN fun_cong [THEN fun_cong]]])
schirmer@12854
   795
apply simp
schirmer@12854
   796
done
schirmer@12854
   797
schirmer@12854
   798
constdefs
schirmer@12854
   799
imethds:: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables"
schirmer@13688
   800
  --{* methods of an interface, with overriding and inheritance, cf. 9.2 *}
schirmer@12854
   801
"imethds G I 
schirmer@12854
   802
  \<equiv> iface_rec (G,I)  
schirmer@12854
   803
              (\<lambda>I i ts. (Un_tables ts) \<oplus>\<oplus> 
schirmer@12854
   804
                        (o2s \<circ> table_of (map (\<lambda>(s,m). (s,I,m)) (imethods i))))"
schirmer@12854
   805
	
schirmer@12854
   806
schirmer@12854
   807
schirmer@12854
   808
end