src/HOL/Bali/DeclConcepts.thy
author berghofe
Sat Jan 30 17:03:46 2010 +0100 (2010-01-30)
changeset 34990 81e8fdfeb849
parent 34915 7894c7dab132
child 35067 af4c18c30593
permissions -rw-r--r--
Adapted to changes in cases method.
schirmer@12925
     1
(*  Title:      HOL/Bali/DeclConcepts.thy
schirmer@12925
     2
    Author:     Norbert Schirmer
schirmer@12925
     3
*)
schirmer@12854
     4
header {* Advanced concepts on Java declarations like overriding, inheritance,
schirmer@12854
     5
dynamic method lookup*}
schirmer@12854
     6
haftmann@16417
     7
theory DeclConcepts imports TypeRel begin
schirmer@12854
     8
schirmer@12854
     9
section "access control (cf. 6.6), overriding and hiding (cf. 8.4.6.1)"
schirmer@12854
    10
schirmer@12854
    11
constdefs
schirmer@12854
    12
is_public :: "prog \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
    13
"is_public G qn \<equiv> (case class G qn of
schirmer@12854
    14
                     None       \<Rightarrow> (case iface G qn of
schirmer@12854
    15
                                      None       \<Rightarrow> False
schirmer@12854
    16
                                    | Some iface \<Rightarrow> access iface = Public)
schirmer@12854
    17
                   | Some class \<Rightarrow> access class = Public)"
schirmer@12854
    18
schirmer@12854
    19
subsection "accessibility of types (cf. 6.6.1)"
schirmer@12854
    20
text {* 
schirmer@12854
    21
Primitive types are always accessible, interfaces and classes are accessible
schirmer@12854
    22
in their package or if they are defined public, an array type is accessible if
schirmer@12854
    23
its element type is accessible *}
schirmer@12854
    24
 
schirmer@12854
    25
consts accessible_in   :: "prog \<Rightarrow> ty     \<Rightarrow> pname \<Rightarrow> bool"  
schirmer@12854
    26
                                      ("_ \<turnstile> _ accessible'_in _" [61,61,61] 60)
schirmer@12854
    27
       rt_accessible_in:: "prog \<Rightarrow> ref_ty \<Rightarrow> pname \<Rightarrow> bool" 
schirmer@12854
    28
                                      ("_ \<turnstile> _ accessible'_in' _" [61,61,61] 60) 
schirmer@12854
    29
primrec
schirmer@12854
    30
"G\<turnstile>(PrimT p)   accessible_in pack  = True"
schirmer@12854
    31
accessible_in_RefT_simp: 
schirmer@12854
    32
"G\<turnstile>(RefT  r)   accessible_in pack  = G\<turnstile>r accessible_in' pack"
schirmer@12854
    33
schirmer@12854
    34
"G\<turnstile>(NullT)     accessible_in' pack = True"
schirmer@12854
    35
"G\<turnstile>(IfaceT I)  accessible_in' pack = ((pid I = pack) \<or> is_public G I)"
schirmer@12854
    36
"G\<turnstile>(ClassT C)  accessible_in' pack = ((pid C = pack) \<or> is_public G C)"
schirmer@12854
    37
"G\<turnstile>(ArrayT ty) accessible_in' pack = G\<turnstile>ty accessible_in pack"
schirmer@12854
    38
schirmer@12854
    39
declare accessible_in_RefT_simp [simp del]
schirmer@12854
    40
schirmer@12854
    41
constdefs
schirmer@12854
    42
  is_acc_class :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
    43
    "is_acc_class G P C \<equiv> is_class G C \<and> G\<turnstile>(Class C) accessible_in P"
schirmer@12854
    44
  is_acc_iface :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
    45
    "is_acc_iface G P I \<equiv> is_iface G I \<and> G\<turnstile>(Iface I) accessible_in P"
schirmer@12854
    46
  is_acc_type  :: "prog \<Rightarrow> pname \<Rightarrow> ty     \<Rightarrow> bool"
schirmer@12854
    47
    "is_acc_type  G P T \<equiv> is_type G T  \<and> G\<turnstile>T accessible_in P"
schirmer@12854
    48
  is_acc_reftype  :: "prog \<Rightarrow> pname \<Rightarrow> ref_ty \<Rightarrow> bool"
schirmer@12854
    49
  "is_acc_reftype  G P T \<equiv> isrtype G T  \<and> G\<turnstile>T accessible_in' P"
schirmer@12854
    50
schirmer@12854
    51
lemma is_acc_classD:
schirmer@12854
    52
 "is_acc_class G P C \<Longrightarrow>  is_class G C \<and> G\<turnstile>(Class C) accessible_in P"
schirmer@12854
    53
by (simp add: is_acc_class_def)
schirmer@12854
    54
schirmer@12854
    55
lemma is_acc_class_is_class: "is_acc_class G P C \<Longrightarrow> is_class G C"
schirmer@12854
    56
by (auto simp add: is_acc_class_def)
schirmer@12854
    57
schirmer@12854
    58
lemma is_acc_ifaceD:
schirmer@12854
    59
  "is_acc_iface G P I \<Longrightarrow> is_iface G I \<and> G\<turnstile>(Iface I) accessible_in P"
schirmer@12854
    60
by (simp add: is_acc_iface_def)
schirmer@12854
    61
schirmer@12854
    62
lemma is_acc_typeD:
schirmer@12925
    63
 "is_acc_type  G P T \<Longrightarrow> is_type G T  \<and> G\<turnstile>T accessible_in P"
schirmer@12854
    64
by (simp add: is_acc_type_def)
schirmer@12854
    65
schirmer@12854
    66
lemma is_acc_reftypeD:
schirmer@12854
    67
"is_acc_reftype  G P T \<Longrightarrow> isrtype G T  \<and> G\<turnstile>T accessible_in' P"
schirmer@12854
    68
by (simp add: is_acc_reftype_def)
schirmer@12854
    69
schirmer@12854
    70
subsection "accessibility of members"
schirmer@12854
    71
text {*
schirmer@12854
    72
The accessibility of members is more involved as the accessibility of types.
schirmer@12854
    73
We have to distinguish several cases to model the different effects of 
schirmer@12854
    74
accessibility during inheritance, overriding and ordinary member access 
schirmer@12854
    75
*}
schirmer@12854
    76
schirmer@12854
    77
subsubsection {* Various technical conversion and selection functions *}
schirmer@12854
    78
schirmer@12854
    79
text {* overloaded selector @{text accmodi} to select the access modifier 
schirmer@12854
    80
out of various HOL types *}
schirmer@12854
    81
schirmer@12854
    82
axclass has_accmodi < "type"
schirmer@12854
    83
consts accmodi:: "'a::has_accmodi \<Rightarrow> acc_modi"
schirmer@12854
    84
wenzelm@12859
    85
instance acc_modi::has_accmodi ..
schirmer@12854
    86
schirmer@12854
    87
defs (overloaded)
schirmer@12854
    88
acc_modi_accmodi_def: "accmodi (a::acc_modi) \<equiv> a"
schirmer@12854
    89
schirmer@12854
    90
lemma acc_modi_accmodi_simp[simp]: "accmodi (a::acc_modi) = a"
schirmer@12854
    91
by (simp add: acc_modi_accmodi_def)
schirmer@12854
    92
schirmer@14700
    93
instance decl_ext_type:: ("type") has_accmodi ..
schirmer@12854
    94
schirmer@12854
    95
defs (overloaded)
schirmer@12854
    96
decl_acc_modi_def: "accmodi (d::('a:: type) decl_scheme) \<equiv> access d"
schirmer@12854
    97
schirmer@12854
    98
schirmer@12854
    99
lemma decl_acc_modi_simp[simp]: "accmodi (d::('a::type) decl_scheme) = access d"
schirmer@12854
   100
by (simp add: decl_acc_modi_def)
schirmer@12854
   101
wenzelm@12859
   102
instance * :: ("type",has_accmodi) has_accmodi ..
schirmer@12854
   103
schirmer@12854
   104
defs (overloaded)
schirmer@12854
   105
pair_acc_modi_def: "accmodi p \<equiv> (accmodi (snd p))"
schirmer@12854
   106
schirmer@12854
   107
lemma pair_acc_modi_simp[simp]: "accmodi (x,a) = (accmodi a)"
schirmer@12854
   108
by (simp add: pair_acc_modi_def)
schirmer@12854
   109
wenzelm@12859
   110
instance memberdecl :: has_accmodi ..
schirmer@12854
   111
schirmer@12854
   112
defs (overloaded)
schirmer@12854
   113
memberdecl_acc_modi_def: "accmodi m \<equiv> (case m of
schirmer@12854
   114
                                          fdecl f \<Rightarrow> accmodi f
schirmer@12854
   115
                                        | mdecl m \<Rightarrow> accmodi m)"
schirmer@12854
   116
schirmer@12854
   117
lemma memberdecl_fdecl_acc_modi_simp[simp]:
schirmer@12854
   118
 "accmodi (fdecl m) = accmodi m"
schirmer@12854
   119
by (simp add: memberdecl_acc_modi_def)
schirmer@12854
   120
schirmer@12854
   121
lemma memberdecl_mdecl_acc_modi_simp[simp]:
schirmer@12854
   122
 "accmodi (mdecl m) = accmodi m"
schirmer@12854
   123
by (simp add: memberdecl_acc_modi_def)
schirmer@12854
   124
schirmer@12854
   125
text {* overloaded selector @{text declclass} to select the declaring class 
schirmer@12854
   126
out of various HOL types *}
schirmer@12854
   127
schirmer@12854
   128
axclass has_declclass < "type"
schirmer@12854
   129
consts declclass:: "'a::has_declclass \<Rightarrow> qtname"
schirmer@12854
   130
schirmer@14700
   131
instance qtname_ext_type::("type") has_declclass ..
schirmer@12854
   132
schirmer@12854
   133
defs (overloaded)
schirmer@12854
   134
qtname_declclass_def: "declclass (q::qtname) \<equiv> q"
schirmer@12854
   135
schirmer@12854
   136
lemma qtname_declclass_simp[simp]: "declclass (q::qtname) = q"
schirmer@12854
   137
by (simp add: qtname_declclass_def)
schirmer@12854
   138
wenzelm@12859
   139
instance * :: ("has_declclass","type") has_declclass ..
schirmer@12854
   140
schirmer@12854
   141
defs (overloaded)
schirmer@12854
   142
pair_declclass_def: "declclass p \<equiv> declclass (fst p)"
schirmer@12854
   143
schirmer@12854
   144
lemma pair_declclass_simp[simp]: "declclass (c,x) = declclass c" 
schirmer@12854
   145
by (simp add: pair_declclass_def)
schirmer@12854
   146
schirmer@12854
   147
text {* overloaded selector @{text is_static} to select the static modifier 
schirmer@12854
   148
out of various HOL types *}
schirmer@12854
   149
schirmer@12854
   150
schirmer@12854
   151
axclass has_static < "type"
schirmer@12854
   152
consts is_static :: "'a::has_static \<Rightarrow> bool"
schirmer@12854
   153
schirmer@14700
   154
instance decl_ext_type :: ("has_static") has_static ..
schirmer@12854
   155
schirmer@14700
   156
instance member_ext_type :: ("type") has_static ..
schirmer@12854
   157
schirmer@12854
   158
defs (overloaded)
schirmer@12854
   159
static_field_type_is_static_def: 
tsewell@32754
   160
 "is_static (m::('b member_scheme)) \<equiv> static m"
schirmer@12854
   161
schirmer@12854
   162
lemma member_is_static_simp: "is_static (m::'a member_scheme) = static m"
tsewell@32754
   163
by (simp add: static_field_type_is_static_def)
schirmer@12854
   164
wenzelm@12859
   165
instance * :: ("type","has_static") has_static ..
schirmer@12854
   166
schirmer@12854
   167
defs (overloaded)
schirmer@12854
   168
pair_is_static_def: "is_static p \<equiv> is_static (snd p)"
schirmer@12854
   169
schirmer@12854
   170
lemma pair_is_static_simp [simp]: "is_static (x,s) = is_static s"
schirmer@12854
   171
by (simp add: pair_is_static_def)
schirmer@12854
   172
schirmer@12854
   173
lemma pair_is_static_simp1: "is_static p = is_static (snd p)"
schirmer@12854
   174
by (simp add: pair_is_static_def)
schirmer@12854
   175
wenzelm@12859
   176
instance memberdecl:: has_static ..
schirmer@12854
   177
schirmer@12854
   178
defs (overloaded)
schirmer@12854
   179
memberdecl_is_static_def: 
schirmer@12854
   180
 "is_static m \<equiv> (case m of
schirmer@12854
   181
                    fdecl f \<Rightarrow> is_static f
schirmer@12854
   182
                  | mdecl m \<Rightarrow> is_static m)"
schirmer@12854
   183
schirmer@12854
   184
lemma memberdecl_is_static_fdecl_simp[simp]:
schirmer@12854
   185
 "is_static (fdecl f) = is_static f"
schirmer@12854
   186
by (simp add: memberdecl_is_static_def)
schirmer@12854
   187
schirmer@12854
   188
lemma memberdecl_is_static_mdecl_simp[simp]:
schirmer@12854
   189
 "is_static (mdecl m) = is_static m"
schirmer@12854
   190
by (simp add: memberdecl_is_static_def)
schirmer@12854
   191
schirmer@12854
   192
lemma mhead_static_simp [simp]: "is_static (mhead m) = is_static m"
schirmer@12854
   193
by (cases m) (simp add: mhead_def member_is_static_simp)
schirmer@12854
   194
schirmer@13688
   195
constdefs  --{* some mnemotic selectors for various pairs *} 
schirmer@13688
   196
           
schirmer@12854
   197
 "decliface":: "(qtname \<times> ('a::type) decl_scheme) \<Rightarrow> qtname"
schirmer@13688
   198
 "decliface \<equiv> fst"          --{* get the interface component *}
schirmer@12854
   199
schirmer@12854
   200
 "mbr"::   "(qtname \<times> memberdecl) \<Rightarrow> memberdecl"
schirmer@13688
   201
 "mbr \<equiv> snd"            --{* get the memberdecl component *}
schirmer@12854
   202
schirmer@12854
   203
 "mthd"::   "('b \<times> 'a) \<Rightarrow> 'a"
schirmer@13688
   204
                           --{* also used for mdecl, mhead *}
schirmer@13688
   205
 "mthd \<equiv> snd"              --{* get the method component *}
schirmer@12854
   206
schirmer@12854
   207
 "fld"::   "('b \<times> ('a::type) decl_scheme) \<Rightarrow> ('a::type) decl_scheme"
schirmer@13688
   208
              --{* also used for @{text "((vname \<times> qtname)\<times> field)"} *}
schirmer@13688
   209
 "fld \<equiv> snd"               --{* get the field component *}
schirmer@12854
   210
schirmer@12854
   211
schirmer@13688
   212
constdefs --{* some mnemotic selectors for @{text "(vname \<times> qtname)"} *}
schirmer@13688
   213
 fname:: "(vname \<times> 'a) \<Rightarrow> vname" --{* also used for fdecl *}
schirmer@12854
   214
 "fname \<equiv> fst"
schirmer@12854
   215
  
schirmer@12854
   216
  declclassf:: "(vname \<times> qtname) \<Rightarrow> qtname"
schirmer@12854
   217
 "declclassf \<equiv> snd"
schirmer@12854
   218
schirmer@13688
   219
schirmer@12854
   220
schirmer@12854
   221
lemma decliface_simp[simp]: "decliface (I,m) = I"
schirmer@12854
   222
by (simp add: decliface_def) 
schirmer@12854
   223
schirmer@12854
   224
lemma mbr_simp[simp]: "mbr (C,m) = m"
schirmer@12854
   225
by (simp add: mbr_def)
schirmer@12854
   226
schirmer@12854
   227
lemma access_mbr_simp [simp]: "(accmodi (mbr m)) = accmodi m"
schirmer@12854
   228
by (cases m) (simp add:  mbr_def) 
schirmer@12854
   229
schirmer@12854
   230
lemma mthd_simp[simp]: "mthd (C,m) = m"
schirmer@12854
   231
by (simp add: mthd_def)
schirmer@12854
   232
schirmer@12854
   233
lemma fld_simp[simp]: "fld (C,f) = f"
schirmer@12854
   234
by (simp add: fld_def)
schirmer@12854
   235
schirmer@12854
   236
lemma accmodi_simp[simp]: "accmodi (C,m) = access m"
schirmer@12854
   237
by (simp )
schirmer@12854
   238
schirmer@12854
   239
lemma access_mthd_simp [simp]: "(access (mthd m)) = accmodi m"
schirmer@12854
   240
by (cases m) (simp add: mthd_def) 
schirmer@12854
   241
schirmer@12854
   242
lemma access_fld_simp [simp]: "(access (fld f)) = accmodi f"
schirmer@12854
   243
by (cases f) (simp add:  fld_def) 
schirmer@12854
   244
schirmer@12854
   245
lemma static_mthd_simp[simp]: "static (mthd m) = is_static m"
schirmer@12854
   246
by (cases m) (simp add:  mthd_def member_is_static_simp)
schirmer@12854
   247
schirmer@12854
   248
lemma mthd_is_static_simp [simp]: "is_static (mthd m) = is_static m"
schirmer@12854
   249
by (cases m) simp
schirmer@12854
   250
schirmer@12854
   251
lemma static_fld_simp[simp]: "static (fld f) = is_static f"
schirmer@12854
   252
by (cases f) (simp add:  fld_def member_is_static_simp)
schirmer@12854
   253
schirmer@12854
   254
lemma ext_field_simp [simp]: "(declclass f,fld f) = f"
schirmer@12854
   255
by (cases f) (simp add:  fld_def)
schirmer@12854
   256
schirmer@12854
   257
lemma ext_method_simp [simp]: "(declclass m,mthd m) = m"
schirmer@12854
   258
by (cases m) (simp add:  mthd_def)
schirmer@12854
   259
schirmer@12854
   260
lemma ext_mbr_simp [simp]: "(declclass m,mbr m) = m"
schirmer@12854
   261
by (cases m) (simp add: mbr_def)
schirmer@12854
   262
schirmer@12854
   263
lemma fname_simp[simp]:"fname (n,c) = n"
schirmer@12854
   264
by (simp add: fname_def)
schirmer@12854
   265
schirmer@12854
   266
lemma declclassf_simp[simp]:"declclassf (n,c) = c"
schirmer@12854
   267
by (simp add: declclassf_def)
schirmer@12854
   268
schirmer@13688
   269
constdefs  --{* some mnemotic selectors for @{text "(vname \<times> qtname)"} *}
schirmer@12854
   270
  "fldname"  :: "(vname \<times> qtname) \<Rightarrow> vname" 
schirmer@12854
   271
  "fldname \<equiv> fst"
schirmer@12854
   272
schirmer@12854
   273
  "fldclass" :: "(vname \<times> qtname) \<Rightarrow> qtname"
schirmer@12854
   274
  "fldclass \<equiv> snd"
schirmer@12854
   275
schirmer@12854
   276
lemma fldname_simp[simp]: "fldname (n,c) = n"
schirmer@12854
   277
by (simp add: fldname_def)
schirmer@12854
   278
schirmer@12854
   279
lemma fldclass_simp[simp]: "fldclass (n,c) = c"
schirmer@12854
   280
by (simp add: fldclass_def)
schirmer@12854
   281
schirmer@12854
   282
lemma ext_fieldname_simp[simp]: "(fldname f,fldclass f) = f"
schirmer@12854
   283
by (simp add: fldname_def fldclass_def)
schirmer@12854
   284
schirmer@12854
   285
text {* Convert a qualified method declaration (qualified with its declaring 
schirmer@12854
   286
class) to a qualified member declaration:  @{text methdMembr}  *}
schirmer@12854
   287
schirmer@12854
   288
constdefs
schirmer@12854
   289
methdMembr :: "(qtname \<times> mdecl) \<Rightarrow> (qtname \<times> memberdecl)"
schirmer@12854
   290
 "methdMembr m \<equiv> (fst m,mdecl (snd m))"
schirmer@12854
   291
schirmer@12854
   292
lemma methdMembr_simp[simp]: "methdMembr (c,m) = (c,mdecl m)"
schirmer@12854
   293
by (simp add: methdMembr_def)
schirmer@12854
   294
schirmer@12854
   295
lemma accmodi_methdMembr_simp[simp]: "accmodi (methdMembr m) = accmodi m"
schirmer@12854
   296
by (cases m) (simp add: methdMembr_def)
schirmer@12854
   297
schirmer@12854
   298
lemma is_static_methdMembr_simp[simp]: "is_static (methdMembr m) = is_static m"
schirmer@12854
   299
by (cases m) (simp add: methdMembr_def)
schirmer@12854
   300
schirmer@12854
   301
lemma declclass_methdMembr_simp[simp]: "declclass (methdMembr m) = declclass m"
schirmer@12854
   302
by (cases m) (simp add: methdMembr_def)
schirmer@12854
   303
schirmer@12854
   304
text {* Convert a qualified method (qualified with its declaring 
schirmer@12854
   305
class) to a qualified member declaration:  @{text method}  *}
schirmer@12854
   306
schirmer@12854
   307
constdefs
schirmer@12854
   308
method :: "sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> memberdecl)" 
schirmer@12854
   309
"method sig m \<equiv> (declclass m, mdecl (sig, mthd m))"
schirmer@12854
   310
schirmer@12854
   311
lemma method_simp[simp]: "method sig (C,m) = (C,mdecl (sig,m))"
schirmer@12854
   312
by (simp add: method_def)
schirmer@12854
   313
schirmer@12854
   314
lemma accmodi_method_simp[simp]: "accmodi (method sig m) = accmodi m"
schirmer@12854
   315
by (simp add: method_def)
schirmer@12854
   316
schirmer@12854
   317
lemma declclass_method_simp[simp]: "declclass (method sig m) = declclass m"
schirmer@12854
   318
by (simp add: method_def)
schirmer@12854
   319
schirmer@12854
   320
lemma is_static_method_simp[simp]: "is_static (method sig m) = is_static m"
schirmer@12854
   321
by (cases m) (simp add: method_def)
schirmer@12854
   322
schirmer@12854
   323
lemma mbr_method_simp[simp]: "mbr (method sig m) = mdecl (sig,mthd m)"
schirmer@12854
   324
by (simp add: mbr_def method_def)
schirmer@12854
   325
schirmer@12854
   326
lemma memberid_method_simp[simp]:  "memberid (method sig m) = mid sig"
schirmer@12854
   327
  by (simp add: method_def) 
schirmer@12854
   328
schirmer@12854
   329
constdefs
schirmer@12854
   330
fieldm :: "vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> (qtname \<times> memberdecl)" 
schirmer@12854
   331
"fieldm n f \<equiv> (declclass f, fdecl (n, fld f))"
schirmer@12854
   332
schirmer@12854
   333
lemma fieldm_simp[simp]: "fieldm n (C,f) = (C,fdecl (n,f))"
schirmer@12854
   334
by (simp add: fieldm_def)
schirmer@12854
   335
schirmer@12854
   336
lemma accmodi_fieldm_simp[simp]: "accmodi (fieldm n f) = accmodi f"
schirmer@12854
   337
by (simp add: fieldm_def)
schirmer@12854
   338
schirmer@12854
   339
lemma declclass_fieldm_simp[simp]: "declclass (fieldm n f) = declclass f"
schirmer@12854
   340
by (simp add: fieldm_def)
schirmer@12854
   341
schirmer@12854
   342
lemma is_static_fieldm_simp[simp]: "is_static (fieldm n f) = is_static f"
schirmer@12854
   343
by (cases f) (simp add: fieldm_def)
schirmer@12854
   344
schirmer@12854
   345
lemma mbr_fieldm_simp[simp]: "mbr (fieldm n f) = fdecl (n,fld f)"
schirmer@12854
   346
by (simp add: mbr_def fieldm_def)
schirmer@12854
   347
schirmer@12854
   348
lemma memberid_fieldm_simp[simp]:  "memberid (fieldm n f) = fid n"
schirmer@12854
   349
by (simp add: fieldm_def) 
schirmer@12854
   350
schirmer@12854
   351
text {* Select the signature out of a qualified method declaration:
schirmer@12854
   352
 @{text msig} *}
schirmer@12854
   353
schirmer@12854
   354
constdefs msig:: "(qtname \<times> mdecl) \<Rightarrow> sig"
schirmer@12854
   355
"msig m \<equiv> fst (snd m)"
schirmer@12854
   356
schirmer@12854
   357
lemma msig_simp[simp]: "msig (c,(s,m)) = s"
schirmer@12854
   358
by (simp add: msig_def)
schirmer@12854
   359
schirmer@12854
   360
text {* Convert a qualified method (qualified with its declaring 
schirmer@12854
   361
class) to a qualified method declaration:  @{text qmdecl}  *}
schirmer@12854
   362
schirmer@12854
   363
constdefs qmdecl :: "sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> mdecl)"
schirmer@12854
   364
"qmdecl sig m \<equiv> (declclass m, (sig,mthd m))"
schirmer@12854
   365
schirmer@12854
   366
lemma qmdecl_simp[simp]: "qmdecl sig (C,m) = (C,(sig,m))"
schirmer@12854
   367
by (simp add: qmdecl_def)
schirmer@12854
   368
schirmer@12854
   369
lemma declclass_qmdecl_simp[simp]: "declclass (qmdecl sig m) = declclass m"
schirmer@12854
   370
by (simp add: qmdecl_def)
schirmer@12854
   371
schirmer@12854
   372
lemma accmodi_qmdecl_simp[simp]: "accmodi (qmdecl sig m) = accmodi m"
schirmer@12854
   373
by (simp add: qmdecl_def)
schirmer@12854
   374
schirmer@12854
   375
lemma is_static_qmdecl_simp[simp]: "is_static (qmdecl sig m) = is_static m"
schirmer@12854
   376
by (cases m) (simp add: qmdecl_def)
schirmer@12854
   377
schirmer@12854
   378
lemma msig_qmdecl_simp[simp]: "msig (qmdecl sig m) = sig"
schirmer@12854
   379
by (simp add: qmdecl_def)
schirmer@12854
   380
schirmer@12854
   381
lemma mdecl_qmdecl_simp[simp]:  
schirmer@12854
   382
 "mdecl (mthd (qmdecl sig new)) = mdecl (sig, mthd new)" 
schirmer@12854
   383
by (simp add: qmdecl_def) 
schirmer@12854
   384
schirmer@12854
   385
lemma methdMembr_qmdecl_simp [simp]: 
schirmer@12854
   386
 "methdMembr (qmdecl sig old) = method sig old"
schirmer@12854
   387
by (simp add: methdMembr_def qmdecl_def method_def)
schirmer@12854
   388
schirmer@12854
   389
text {* overloaded selector @{text resTy} to select the result type 
schirmer@12854
   390
out of various HOL types *}
schirmer@12854
   391
schirmer@12854
   392
axclass has_resTy < "type"
schirmer@12854
   393
consts resTy:: "'a::has_resTy \<Rightarrow> ty"
schirmer@12854
   394
schirmer@14700
   395
instance decl_ext_type :: ("has_resTy") has_resTy ..
schirmer@12854
   396
schirmer@14700
   397
instance member_ext_type :: ("has_resTy") has_resTy ..
schirmer@12854
   398
schirmer@14700
   399
instance mhead_ext_type :: ("type") has_resTy ..
schirmer@12854
   400
schirmer@12854
   401
defs (overloaded)
schirmer@14700
   402
mhead_ext_type_resTy_def: 
tsewell@32754
   403
 "resTy (m::('b mhead_scheme)) \<equiv> resT m"
schirmer@12854
   404
schirmer@12854
   405
lemma mhead_resTy_simp: "resTy (m::'a mhead_scheme) = resT m"
tsewell@32754
   406
by (simp add: mhead_ext_type_resTy_def)
schirmer@12854
   407
schirmer@12854
   408
lemma resTy_mhead [simp]:"resTy (mhead m) = resTy m"
schirmer@12854
   409
by (simp add: mhead_def mhead_resTy_simp)
schirmer@12854
   410
wenzelm@12859
   411
instance * :: ("type","has_resTy") has_resTy ..
schirmer@12854
   412
schirmer@12854
   413
defs (overloaded)
schirmer@12854
   414
pair_resTy_def: "resTy p \<equiv> resTy (snd p)"
schirmer@12854
   415
schirmer@12854
   416
lemma pair_resTy_simp[simp]: "resTy (x,m) = resTy m"
schirmer@12854
   417
by (simp add: pair_resTy_def)
schirmer@12854
   418
schirmer@12854
   419
lemma qmdecl_resTy_simp [simp]: "resTy (qmdecl sig m) = resTy m"
schirmer@12854
   420
by (cases m) (simp)
schirmer@12854
   421
schirmer@12854
   422
lemma resTy_mthd [simp]:"resTy (mthd m) = resTy m"
schirmer@12854
   423
by (cases m) (simp add: mthd_def )
schirmer@12854
   424
schirmer@12854
   425
subsubsection "inheritable-in"
schirmer@12854
   426
text {*
schirmer@12854
   427
@{text "G\<turnstile>m inheritable_in P"}: m can be inherited by
schirmer@12854
   428
classes in package P if:
schirmer@12854
   429
\begin{itemize} 
schirmer@12854
   430
\item the declaration class of m is accessible in P and
schirmer@12854
   431
\item the member m is declared with protected or public access or if it is
schirmer@12854
   432
      declared with default (package) access, the package of the declaration 
schirmer@12854
   433
      class of m is also P. If the member m is declared with private access
schirmer@12854
   434
      it is not accessible for inheritance at all.
schirmer@12854
   435
\end{itemize}
schirmer@12854
   436
*}
schirmer@12854
   437
constdefs
schirmer@12854
   438
inheritable_in:: 
schirmer@12854
   439
 "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> pname \<Rightarrow> bool"
schirmer@12854
   440
                  ("_ \<turnstile> _ inheritable'_in _" [61,61,61] 60)
schirmer@12854
   441
"G\<turnstile>membr inheritable_in pack 
schirmer@12854
   442
  \<equiv> (case (accmodi membr) of
schirmer@12854
   443
       Private   \<Rightarrow> False
schirmer@12854
   444
     | Package   \<Rightarrow> (pid (declclass membr)) = pack
schirmer@12854
   445
     | Protected \<Rightarrow> True
schirmer@12854
   446
     | Public    \<Rightarrow> True)"
schirmer@12854
   447
schirmer@12854
   448
syntax
schirmer@12854
   449
Method_inheritable_in::
schirmer@12854
   450
 "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> pname \<Rightarrow> bool"
schirmer@12854
   451
                ("_ \<turnstile>Method _ inheritable'_in _ " [61,61,61] 60)
schirmer@12854
   452
schirmer@12854
   453
translations
schirmer@12854
   454
"G\<turnstile>Method m inheritable_in p" == "G\<turnstile>methdMembr m inheritable_in p"
schirmer@12854
   455
schirmer@12854
   456
syntax
schirmer@12854
   457
Methd_inheritable_in::
schirmer@12854
   458
 "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> pname \<Rightarrow> bool"
schirmer@12854
   459
                ("_ \<turnstile>Methd _ _ inheritable'_in _ " [61,61,61,61] 60)
schirmer@12854
   460
schirmer@12854
   461
translations
schirmer@12854
   462
"G\<turnstile>Methd s m inheritable_in p" == "G\<turnstile>(method s m) inheritable_in p"
schirmer@12854
   463
schirmer@12854
   464
subsubsection "declared-in/undeclared-in"
schirmer@12854
   465
schirmer@12854
   466
constdefs cdeclaredmethd:: "prog \<Rightarrow> qtname \<Rightarrow> (sig,methd) table"
schirmer@12854
   467
"cdeclaredmethd G C 
schirmer@12854
   468
  \<equiv> (case class G C of
schirmer@12854
   469
       None \<Rightarrow> \<lambda> sig. None
schirmer@12854
   470
     | Some c \<Rightarrow> table_of (methods c)
schirmer@12854
   471
    )"
schirmer@12854
   472
schirmer@12854
   473
constdefs
schirmer@12854
   474
cdeclaredfield:: "prog \<Rightarrow> qtname \<Rightarrow> (vname,field) table"
schirmer@12854
   475
"cdeclaredfield G C 
schirmer@12854
   476
  \<equiv> (case class G C of
schirmer@12854
   477
       None \<Rightarrow> \<lambda> sig. None
schirmer@12854
   478
     | Some c \<Rightarrow> table_of (cfields c)
schirmer@12854
   479
    )"
schirmer@12854
   480
schirmer@12854
   481
schirmer@12854
   482
constdefs
schirmer@12854
   483
declared_in:: "prog  \<Rightarrow> memberdecl \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   484
                                 ("_\<turnstile> _ declared'_in _" [61,61,61] 60)
schirmer@12854
   485
"G\<turnstile>m declared_in C \<equiv> (case m of
schirmer@12854
   486
                        fdecl (fn,f ) \<Rightarrow> cdeclaredfield G C fn  = Some f
schirmer@12854
   487
                      | mdecl (sig,m) \<Rightarrow> cdeclaredmethd G C sig = Some m)"
schirmer@12854
   488
schirmer@12854
   489
syntax
schirmer@12854
   490
method_declared_in:: "prog  \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   491
                                 ("_\<turnstile>Method _ declared'_in _" [61,61,61] 60)
schirmer@12854
   492
translations
schirmer@12854
   493
"G\<turnstile>Method m declared_in C" == "G\<turnstile>mdecl (mthd m) declared_in C"
schirmer@12854
   494
schirmer@12854
   495
syntax
schirmer@12854
   496
methd_declared_in:: "prog  \<Rightarrow> sig  \<Rightarrow>(qtname \<times> methd) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   497
                               ("_\<turnstile>Methd _  _ declared'_in _" [61,61,61,61] 60)
schirmer@12854
   498
translations
schirmer@12854
   499
"G\<turnstile>Methd s m declared_in C" == "G\<turnstile>mdecl (s,mthd m) declared_in C"
schirmer@12854
   500
schirmer@12854
   501
lemma declared_in_classD:
schirmer@12854
   502
 "G\<turnstile>m declared_in C \<Longrightarrow> is_class G C"
schirmer@12854
   503
by (cases m) 
schirmer@12854
   504
   (auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def)
schirmer@12854
   505
schirmer@12854
   506
constdefs
schirmer@12854
   507
undeclared_in:: "prog  \<Rightarrow> memberid \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   508
                                 ("_\<turnstile> _ undeclared'_in _" [61,61,61] 60)
schirmer@12854
   509
schirmer@12854
   510
"G\<turnstile>m undeclared_in C \<equiv> (case m of
schirmer@12854
   511
                            fid fn  \<Rightarrow> cdeclaredfield G C fn  = None
schirmer@12854
   512
                          | mid sig \<Rightarrow> cdeclaredmethd G C sig = None)"
schirmer@12854
   513
schirmer@12854
   514
schirmer@12854
   515
subsubsection "members"
schirmer@12854
   516
schirmer@12854
   517
(* Can't just take a function: prog \<Rightarrow> qtname \<Rightarrow> memberdecl set because
schirmer@12854
   518
   the class qtname changes to the superclass in the inductive definition
schirmer@12854
   519
   below
schirmer@12854
   520
*)
schirmer@12854
   521
berghofe@23747
   522
inductive
berghofe@21765
   523
  members :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   524
    ("_ \<turnstile> _ member'_of _" [61,61,61] 60)
berghofe@21765
   525
  for G :: prog
berghofe@21765
   526
where
schirmer@12854
   527
berghofe@21765
   528
  Immediate: "\<lbrakk>G\<turnstile>mbr m declared_in C;declclass m = C\<rbrakk> \<Longrightarrow> G\<turnstile>m member_of C"
berghofe@21765
   529
| Inherited: "\<lbrakk>G\<turnstile>m inheritable_in (pid C); G\<turnstile>memberid m undeclared_in C; 
berghofe@21765
   530
               G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S; G\<turnstile>(Class S) accessible_in (pid C);G\<turnstile>m member_of S 
berghofe@21765
   531
              \<rbrakk> \<Longrightarrow> G\<turnstile>m member_of C"
schirmer@12854
   532
text {* Note that in the case of an inherited member only the members of the
schirmer@12854
   533
direct superclass are concerned. If a member of a superclass of the direct
schirmer@12854
   534
superclass isn't inherited in the direct superclass (not member of the
schirmer@12854
   535
direct superclass) than it can't be a member of the class. E.g. If a
schirmer@12854
   536
member of a class A is defined with package access it isn't member of a 
schirmer@12854
   537
subclass S if S isn't in the same package as A. Any further subclasses 
schirmer@12854
   538
of S will not inherit the member, regardless if they are in the same
schirmer@12854
   539
package as A or not.*}
schirmer@12854
   540
schirmer@12854
   541
syntax
schirmer@12854
   542
method_member_of:: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   543
                           ("_ \<turnstile>Method _ member'_of _" [61,61,61] 60)
schirmer@12854
   544
schirmer@12854
   545
translations
schirmer@12854
   546
 "G\<turnstile>Method m member_of C" \<rightleftharpoons> "G\<turnstile>(methdMembr m) member_of C" 
schirmer@12854
   547
schirmer@12854
   548
syntax
schirmer@12854
   549
methd_member_of:: "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   550
                           ("_ \<turnstile>Methd _ _ member'_of _" [61,61,61,61] 60)
schirmer@12854
   551
schirmer@12854
   552
translations
schirmer@12854
   553
 "G\<turnstile>Methd s m member_of C" \<rightleftharpoons> "G\<turnstile>(method s m) member_of C" 
schirmer@12854
   554
schirmer@12854
   555
syntax
schirmer@12854
   556
fieldm_member_of:: "prog \<Rightarrow> vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   557
                           ("_ \<turnstile>Field _  _ member'_of _" [61,61,61] 60)
schirmer@12854
   558
schirmer@12854
   559
translations
schirmer@12854
   560
 "G\<turnstile>Field n f member_of C" \<rightleftharpoons> "G\<turnstile>fieldm n f member_of C" 
schirmer@12854
   561
schirmer@12854
   562
constdefs
schirmer@12854
   563
inherits:: "prog \<Rightarrow> qtname \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> bool"
schirmer@12854
   564
                           ("_ \<turnstile> _ inherits _" [61,61,61] 60)
schirmer@12854
   565
"G\<turnstile>C inherits m 
schirmer@12854
   566
  \<equiv> G\<turnstile>m inheritable_in (pid C) \<and> G\<turnstile>memberid m undeclared_in C \<and> 
schirmer@12854
   567
    (\<exists> S. G\<turnstile>C \<prec>\<^sub>C\<^sub>1 S \<and> G\<turnstile>(Class S) accessible_in (pid C) \<and> G\<turnstile>m member_of S)"
schirmer@12854
   568
schirmer@12854
   569
lemma inherits_member: "G\<turnstile>C inherits m \<Longrightarrow> G\<turnstile>m member_of C"
schirmer@12854
   570
by (auto simp add: inherits_def intro: members.Inherited)
schirmer@12854
   571
schirmer@12854
   572
schirmer@12854
   573
constdefs member_in::"prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   574
                           ("_ \<turnstile> _ member'_in _" [61,61,61] 60)
schirmer@12854
   575
"G\<turnstile>m member_in C \<equiv> \<exists> provC. G\<turnstile> C \<preceq>\<^sub>C provC \<and> G \<turnstile> m member_of provC"
schirmer@12854
   576
text {* A member is in a class if it is member of the class or a superclass.
schirmer@12854
   577
If a member is in a class we can select this member. This additional notion
schirmer@12854
   578
is necessary since not all members are inherited to subclasses. So such
schirmer@12854
   579
members are not member-of the subclass but member-in the subclass.*}
schirmer@12854
   580
schirmer@12854
   581
syntax
schirmer@12854
   582
method_member_in:: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   583
                           ("_ \<turnstile>Method _ member'_in _" [61,61,61] 60)
schirmer@12854
   584
schirmer@12854
   585
translations
schirmer@12854
   586
 "G\<turnstile>Method m member_in C" \<rightleftharpoons> "G\<turnstile>(methdMembr m) member_in C" 
schirmer@12854
   587
schirmer@12854
   588
syntax
schirmer@12854
   589
methd_member_in:: "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   590
                           ("_ \<turnstile>Methd _ _ member'_in _" [61,61,61,61] 60)
schirmer@12854
   591
schirmer@12854
   592
translations
schirmer@12854
   593
 "G\<turnstile>Methd s m member_in C" \<rightleftharpoons> "G\<turnstile>(method s m) member_in C" 
schirmer@12854
   594
schirmer@12854
   595
lemma member_inD: "G\<turnstile>m member_in C 
schirmer@12854
   596
 \<Longrightarrow> \<exists> provC. G\<turnstile> C \<preceq>\<^sub>C provC \<and> G \<turnstile> m member_of provC"
schirmer@12854
   597
by (auto simp add: member_in_def)
schirmer@12854
   598
schirmer@12854
   599
lemma member_inI: "\<lbrakk>G \<turnstile> m member_of provC;G\<turnstile> C \<preceq>\<^sub>C provC\<rbrakk> \<Longrightarrow>  G\<turnstile>m member_in C"
schirmer@12854
   600
by (auto simp add: member_in_def)
schirmer@12854
   601
schirmer@12854
   602
lemma member_of_to_member_in: "G \<turnstile> m member_of C \<Longrightarrow> G \<turnstile>m member_in C"
schirmer@12854
   603
by (auto intro: member_inI)
schirmer@12854
   604
schirmer@12854
   605
schirmer@12854
   606
subsubsection "overriding"
schirmer@12854
   607
schirmer@12854
   608
text {* Unfortunately the static notion of overriding (used during the
schirmer@12854
   609
typecheck of the compiler) and the dynamic notion of overriding (used during
schirmer@12854
   610
execution in the JVM) are not exactly the same. 
schirmer@12854
   611
*}
schirmer@12854
   612
schirmer@12854
   613
text {* Static overriding (used during the typecheck of the compiler) *}
schirmer@12854
   614
berghofe@23747
   615
inductive
berghofe@21765
   616
  stat_overridesR :: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> bool"
berghofe@21765
   617
    ("_ \<turnstile> _ overrides\<^sub>S _" [61,61,61] 60)
berghofe@21765
   618
  for G :: prog
berghofe@21765
   619
where
schirmer@12854
   620
berghofe@21765
   621
  Direct: "\<lbrakk>\<not> is_static new; msig new = msig old; 
berghofe@21765
   622
           G\<turnstile>Method new declared_in (declclass new);  
berghofe@21765
   623
           G\<turnstile>Method old declared_in (declclass old); 
berghofe@21765
   624
           G\<turnstile>Method old inheritable_in pid (declclass new);
berghofe@21765
   625
           G\<turnstile>(declclass new) \<prec>\<^sub>C\<^sub>1 superNew;
berghofe@21765
   626
           G \<turnstile>Method old member_of superNew
berghofe@21765
   627
           \<rbrakk> \<Longrightarrow> G\<turnstile>new overrides\<^sub>S old"
schirmer@12854
   628
haftmann@32134
   629
| Indirect: "\<lbrakk>G\<turnstile>new overrides\<^sub>S intr; G\<turnstile>intr overrides\<^sub>S old\<rbrakk>
berghofe@21765
   630
             \<Longrightarrow> G\<turnstile>new overrides\<^sub>S old"
schirmer@12854
   631
schirmer@12854
   632
text {* Dynamic overriding (used during the typecheck of the compiler) *}
schirmer@12854
   633
berghofe@23747
   634
inductive
berghofe@21765
   635
  overridesR :: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> bool"
berghofe@21765
   636
    ("_ \<turnstile> _ overrides _" [61,61,61] 60)
berghofe@21765
   637
  for G :: prog
berghofe@21765
   638
where
schirmer@12854
   639
berghofe@21765
   640
  Direct: "\<lbrakk>\<not> is_static new; \<not> is_static old; accmodi new \<noteq> Private;
berghofe@21765
   641
           msig new = msig old; 
berghofe@21765
   642
           G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old);
berghofe@21765
   643
           G\<turnstile>Method new declared_in (declclass new);  
berghofe@21765
   644
           G\<turnstile>Method old declared_in (declclass old);    
berghofe@21765
   645
           G\<turnstile>Method old inheritable_in pid (declclass new);
berghofe@21765
   646
           G\<turnstile>resTy new \<preceq> resTy old
berghofe@21765
   647
           \<rbrakk> \<Longrightarrow> G\<turnstile>new overrides old"
schirmer@12854
   648
haftmann@32134
   649
| Indirect: "\<lbrakk>G\<turnstile>new overrides intr; G\<turnstile>intr overrides old\<rbrakk>
berghofe@21765
   650
            \<Longrightarrow> G\<turnstile>new overrides old"
schirmer@12854
   651
schirmer@12854
   652
syntax
schirmer@12854
   653
sig_stat_overrides:: 
schirmer@12854
   654
 "prog  \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> methd) \<Rightarrow> bool" 
schirmer@12854
   655
                                  ("_,_\<turnstile> _ overrides\<^sub>S _" [61,61,61,61] 60)
schirmer@12854
   656
translations
schirmer@12854
   657
 "G,s\<turnstile>new overrides\<^sub>S old" \<rightharpoonup> "G\<turnstile>(qmdecl s new) overrides\<^sub>S (qmdecl s old)" 
schirmer@12854
   658
schirmer@12854
   659
syntax
schirmer@12854
   660
sig_overrides:: "prog  \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> methd) \<Rightarrow> bool" 
schirmer@12854
   661
                                  ("_,_\<turnstile> _ overrides _" [61,61,61,61] 60)
schirmer@12854
   662
translations
schirmer@12854
   663
 "G,s\<turnstile>new overrides old" \<rightharpoonup> "G\<turnstile>(qmdecl s new) overrides (qmdecl s old)" 
schirmer@12854
   664
schirmer@12854
   665
subsubsection "Hiding"
schirmer@12854
   666
schirmer@12854
   667
constdefs hides::
schirmer@12854
   668
"prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> bool" 
schirmer@12854
   669
                                ("_\<turnstile> _ hides _" [61,61,61] 60)
schirmer@12854
   670
"G\<turnstile>new hides old
schirmer@12854
   671
  \<equiv> is_static new \<and> msig new = msig old \<and>
schirmer@12854
   672
    G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and>
schirmer@12854
   673
    G\<turnstile>Method new declared_in (declclass new) \<and>
schirmer@12854
   674
    G\<turnstile>Method old declared_in (declclass old) \<and> 
schirmer@12854
   675
    G\<turnstile>Method old inheritable_in pid (declclass new)"
schirmer@12854
   676
schirmer@12854
   677
syntax
schirmer@12854
   678
sig_hides:: "prog  \<Rightarrow> sig \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> bool" 
schirmer@12854
   679
                                  ("_,_\<turnstile> _ hides _" [61,61,61,61] 60)
schirmer@12854
   680
translations
schirmer@12854
   681
 "G,s\<turnstile>new hides old" \<rightharpoonup> "G\<turnstile>(qmdecl s new) hides (qmdecl s old)" 
schirmer@12854
   682
schirmer@12854
   683
lemma hidesI:
schirmer@12854
   684
"\<lbrakk>is_static new; msig new = msig old;
schirmer@12854
   685
  G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old);
schirmer@12854
   686
  G\<turnstile>Method new declared_in (declclass new);
schirmer@12854
   687
  G\<turnstile>Method old declared_in (declclass old);
schirmer@12854
   688
  G\<turnstile>Method old inheritable_in pid (declclass new)
schirmer@12854
   689
 \<rbrakk> \<Longrightarrow> G\<turnstile>new hides old"
schirmer@12854
   690
by (auto simp add: hides_def)
schirmer@12854
   691
schirmer@12854
   692
lemma hidesD:
schirmer@12854
   693
"\<lbrakk>G\<turnstile>new hides old\<rbrakk> \<Longrightarrow>  
schirmer@12854
   694
  declclass new \<noteq> Object \<and> is_static new \<and> msig new = msig old \<and> 
schirmer@12854
   695
  G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and>
schirmer@12854
   696
  G\<turnstile>Method new declared_in (declclass new) \<and>   
schirmer@12854
   697
  G\<turnstile>Method old declared_in (declclass old)"
schirmer@12854
   698
by (auto simp add: hides_def)
schirmer@12854
   699
schirmer@12854
   700
lemma overrides_commonD:
schirmer@12854
   701
"\<lbrakk>G\<turnstile>new overrides old\<rbrakk> \<Longrightarrow>  
schirmer@12854
   702
  declclass new \<noteq> Object \<and> \<not> is_static new \<and> \<not> is_static old \<and>
schirmer@12854
   703
  accmodi new \<noteq> Private \<and> 
schirmer@12854
   704
  msig new = msig old  \<and>
schirmer@12854
   705
  G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and>
schirmer@12854
   706
  G\<turnstile>Method new declared_in (declclass new) \<and>   
schirmer@12854
   707
  G\<turnstile>Method old declared_in (declclass old)"
schirmer@12854
   708
by (induct set: overridesR) (auto intro: trancl_trans)
schirmer@12854
   709
schirmer@12854
   710
lemma ws_overrides_commonD:
schirmer@12854
   711
"\<lbrakk>G\<turnstile>new overrides old;ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
   712
  declclass new \<noteq> Object \<and> \<not> is_static new \<and> \<not> is_static old \<and>
schirmer@12854
   713
  accmodi new \<noteq> Private \<and> G\<turnstile>resTy new \<preceq> resTy old \<and>
schirmer@12854
   714
  msig new = msig old  \<and>
schirmer@12854
   715
  G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and>
schirmer@12854
   716
  G\<turnstile>Method new declared_in (declclass new) \<and>   
schirmer@12854
   717
  G\<turnstile>Method old declared_in (declclass old)"
schirmer@12854
   718
by (induct set: overridesR) (auto intro: trancl_trans ws_widen_trans)
schirmer@12854
   719
schirmer@12854
   720
lemma overrides_eq_sigD: 
schirmer@12854
   721
 "\<lbrakk>G\<turnstile>new overrides old\<rbrakk> \<Longrightarrow> msig old=msig new"
schirmer@12854
   722
by (auto dest: overrides_commonD)
schirmer@12854
   723
schirmer@12854
   724
lemma hides_eq_sigD: 
schirmer@12854
   725
 "\<lbrakk>G\<turnstile>new hides old\<rbrakk> \<Longrightarrow> msig old=msig new"
schirmer@12854
   726
by (auto simp add: hides_def)
schirmer@12854
   727
schirmer@12854
   728
subsubsection "permits access" 
schirmer@12854
   729
constdefs 
schirmer@12854
   730
permits_acc:: 
schirmer@12854
   731
 "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@14030
   732
                   ("_ \<turnstile> _ in _ permits'_acc'_from _" [61,61,61,61] 60)
schirmer@12854
   733
schirmer@14030
   734
"G\<turnstile>membr in class permits_acc_from accclass 
schirmer@12854
   735
  \<equiv> (case (accmodi membr) of
schirmer@12854
   736
       Private   \<Rightarrow> (declclass membr = accclass)
schirmer@12854
   737
     | Package   \<Rightarrow> (pid (declclass membr) = pid accclass)
schirmer@12854
   738
     | Protected \<Rightarrow> (pid (declclass membr) = pid accclass)
schirmer@12854
   739
                    \<or>
schirmer@12925
   740
                    (G\<turnstile>accclass \<prec>\<^sub>C declclass membr 
schirmer@12925
   741
                     \<and> (G\<turnstile>class \<preceq>\<^sub>C accclass \<or> is_static membr)) 
schirmer@12854
   742
     | Public    \<Rightarrow> True)"
schirmer@12854
   743
text {*
schirmer@12854
   744
The subcondition of the @{term "Protected"} case: 
schirmer@12854
   745
@{term "G\<turnstile>accclass \<prec>\<^sub>C declclass membr"} could also be relaxed to:
schirmer@12854
   746
@{term "G\<turnstile>accclass \<preceq>\<^sub>C declclass membr"} since in case both classes are the
schirmer@12854
   747
same the other condition @{term "(pid (declclass membr) = pid accclass)"}
schirmer@12854
   748
holds anyway.
schirmer@12854
   749
*} 
schirmer@12854
   750
schirmer@12854
   751
text {* Like in case of overriding, the static and dynamic accessibility 
schirmer@12854
   752
of members is not uniform.
schirmer@12854
   753
\begin{itemize}
schirmer@12854
   754
\item Statically the class/interface of the member must be accessible for the
schirmer@12854
   755
      member to be accessible. During runtime this is not necessary. For
schirmer@12854
   756
      Example, if a class is accessible and we are allowed to access a member
schirmer@12854
   757
      of this class (statically) we expect that we can access this member in 
schirmer@12854
   758
      an arbitrary subclass (during runtime). It's not intended to restrict
schirmer@12854
   759
      the access to accessible subclasses during runtime.
schirmer@12854
   760
\item Statically the member we want to access must be "member of" the class.
schirmer@12854
   761
      Dynamically it must only be "member in" the class.
schirmer@12854
   762
\end{itemize} 
schirmer@12854
   763
*} 
schirmer@12854
   764
berghofe@23747
   765
inductive
berghofe@21765
   766
  accessible_fromR :: "prog \<Rightarrow> qtname \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   767
  and accessible_from :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   768
    ("_ \<turnstile> _ of _ accessible'_from _" [61,61,61,61] 60)
berghofe@21765
   769
  and method_accessible_from :: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   770
    ("_ \<turnstile>Method _ of _ accessible'_from _" [61,61,61,61] 60)
berghofe@21765
   771
  for G :: prog and accclass :: qtname
berghofe@21765
   772
where
berghofe@21765
   773
  "G\<turnstile>membr of cls accessible_from accclass \<equiv> accessible_fromR G accclass membr cls"
schirmer@12854
   774
wenzelm@25143
   775
| "G\<turnstile>Method m of cls accessible_from accclass \<equiv> accessible_fromR G accclass (methdMembr m) cls"
schirmer@12854
   776
berghofe@21765
   777
| Immediate:  "\<lbrakk>G\<turnstile>membr member_of class;
berghofe@21765
   778
                G\<turnstile>(Class class) accessible_in (pid accclass);
berghofe@21765
   779
                G\<turnstile>membr in class permits_acc_from accclass 
berghofe@21765
   780
               \<rbrakk> \<Longrightarrow> G\<turnstile>membr of class accessible_from accclass"
schirmer@12854
   781
berghofe@21765
   782
| Overriding: "\<lbrakk>G\<turnstile>membr member_of class;
berghofe@21765
   783
                G\<turnstile>(Class class) accessible_in (pid accclass);
berghofe@21765
   784
                membr=(C,mdecl new);
berghofe@21765
   785
                G\<turnstile>(C,new) overrides\<^sub>S old; 
haftmann@22426
   786
                G\<turnstile>class \<prec>\<^sub>C supr;
haftmann@22426
   787
                G\<turnstile>Method old of supr accessible_from accclass
berghofe@21765
   788
               \<rbrakk>\<Longrightarrow> G\<turnstile>membr of class accessible_from accclass"
schirmer@12854
   789
schirmer@12854
   790
syntax 
schirmer@12854
   791
methd_accessible_from:: 
schirmer@12854
   792
 "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   793
                 ("_ \<turnstile>Methd _ _ of _ accessible'_from _" [61,61,61,61,61] 60)
schirmer@12854
   794
schirmer@12854
   795
translations
schirmer@12854
   796
"G\<turnstile>Methd s m of cls accessible_from accclass"  
schirmer@12854
   797
 \<rightleftharpoons> "G\<turnstile>(method s m) of cls accessible_from accclass"  
schirmer@12854
   798
schirmer@12854
   799
syntax 
schirmer@12854
   800
field_accessible_from:: 
schirmer@12854
   801
 "prog \<Rightarrow> vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   802
                 ("_ \<turnstile>Field _  _ of _ accessible'_from _" [61,61,61,61,61] 60)
schirmer@12854
   803
schirmer@12854
   804
translations
schirmer@12854
   805
"G\<turnstile>Field fn f of C accessible_from accclass"  
schirmer@12854
   806
 \<rightleftharpoons> "G\<turnstile>(fieldm fn f) of C accessible_from accclass" 
schirmer@12854
   807
berghofe@23747
   808
inductive
berghofe@21765
   809
  dyn_accessible_fromR :: "prog \<Rightarrow> qtname \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   810
  and dyn_accessible_from' ::  "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   811
    ("_ \<turnstile> _ in _ dyn'_accessible'_from _" [61,61,61,61] 60)
berghofe@21765
   812
  and method_dyn_accessible_from :: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
berghofe@21765
   813
    ("_ \<turnstile>Method _ in _ dyn'_accessible'_from _" [61,61,61,61] 60)
berghofe@21765
   814
  for G :: prog and accclass :: qtname
berghofe@21765
   815
where
berghofe@21765
   816
  "G\<turnstile>membr in C dyn_accessible_from accC \<equiv> dyn_accessible_fromR G accC membr C"
schirmer@12854
   817
wenzelm@25143
   818
| "G\<turnstile>Method m in C dyn_accessible_from accC \<equiv> dyn_accessible_fromR G accC (methdMembr m) C"
schirmer@12854
   819
berghofe@21765
   820
| Immediate:  "\<lbrakk>G\<turnstile>membr member_in class;
berghofe@21765
   821
                G\<turnstile>membr in class permits_acc_from accclass 
berghofe@21765
   822
               \<rbrakk> \<Longrightarrow> G\<turnstile>membr in class dyn_accessible_from accclass"
schirmer@12854
   823
berghofe@21765
   824
| Overriding: "\<lbrakk>G\<turnstile>membr member_in class;
berghofe@21765
   825
                membr=(C,mdecl new);
berghofe@21765
   826
                G\<turnstile>(C,new) overrides old; 
haftmann@22426
   827
                G\<turnstile>class \<prec>\<^sub>C supr;
haftmann@22426
   828
                G\<turnstile>Method old in supr dyn_accessible_from accclass
berghofe@21765
   829
               \<rbrakk>\<Longrightarrow> G\<turnstile>membr in class dyn_accessible_from accclass"
schirmer@12854
   830
schirmer@12854
   831
syntax 
schirmer@12854
   832
methd_dyn_accessible_from:: 
schirmer@12854
   833
 "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   834
             ("_ \<turnstile>Methd _ _ in _ dyn'_accessible'_from _" [61,61,61,61,61] 60)
schirmer@12854
   835
schirmer@12854
   836
translations
schirmer@12854
   837
"G\<turnstile>Methd s m in C dyn_accessible_from accC"  
schirmer@12854
   838
 \<rightleftharpoons> "G\<turnstile>(method s m) in C dyn_accessible_from accC"  
schirmer@12854
   839
schirmer@12854
   840
syntax 
schirmer@12854
   841
field_dyn_accessible_from:: 
schirmer@12854
   842
 "prog \<Rightarrow> vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool"
schirmer@12854
   843
         ("_ \<turnstile>Field _ _ in _ dyn'_accessible'_from _" [61,61,61,61,61] 60)
schirmer@12854
   844
schirmer@12854
   845
translations
schirmer@12854
   846
"G\<turnstile>Field fn f in dynC dyn_accessible_from accC"  
schirmer@12854
   847
 \<rightleftharpoons> "G\<turnstile>(fieldm fn f) in dynC dyn_accessible_from accC"
schirmer@12854
   848
schirmer@12854
   849
schirmer@12854
   850
lemma accessible_from_commonD: "G\<turnstile>m of C accessible_from S
schirmer@12854
   851
 \<Longrightarrow> G\<turnstile>m member_of C \<and> G\<turnstile>(Class C) accessible_in (pid S)"
schirmer@12854
   852
by (auto elim: accessible_fromR.induct)
schirmer@12854
   853
schirmer@12925
   854
lemma unique_declaration: 
schirmer@12925
   855
 "\<lbrakk>G\<turnstile>m declared_in C;  G\<turnstile>n declared_in C; memberid m = memberid n \<rbrakk> 
schirmer@12925
   856
  \<Longrightarrow> m = n"
schirmer@12925
   857
apply (cases m)
schirmer@12925
   858
apply (cases n,
schirmer@12925
   859
        auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def)+
schirmer@12925
   860
done
schirmer@12925
   861
schirmer@12854
   862
lemma declared_not_undeclared:
schirmer@12854
   863
  "G\<turnstile>m declared_in C \<Longrightarrow> \<not> G\<turnstile> memberid m undeclared_in C"
schirmer@12854
   864
by (cases m) (auto simp add: declared_in_def undeclared_in_def)
schirmer@12854
   865
schirmer@12925
   866
lemma undeclared_not_declared:
schirmer@12925
   867
 "G\<turnstile> memberid m undeclared_in C \<Longrightarrow> \<not> G\<turnstile> m declared_in C" 
schirmer@12925
   868
by (cases m) (auto simp add: declared_in_def undeclared_in_def)
schirmer@12925
   869
schirmer@12854
   870
lemma not_undeclared_declared:
schirmer@12854
   871
  "\<not> G\<turnstile> membr_id undeclared_in C \<Longrightarrow> (\<exists> m. G\<turnstile>m declared_in C \<and> 
schirmer@12854
   872
                                           membr_id = memberid m)"
schirmer@12854
   873
proof -
schirmer@12854
   874
  assume not_undecl:"\<not> G\<turnstile> membr_id undeclared_in C"
schirmer@12854
   875
  show ?thesis (is "?P membr_id")
schirmer@12854
   876
  proof (cases membr_id)
schirmer@12854
   877
    case (fid vname)
schirmer@12854
   878
    with not_undecl
schirmer@12854
   879
    obtain fld where
schirmer@12854
   880
      "G\<turnstile>fdecl (vname,fld) declared_in C" 
schirmer@12854
   881
      by (auto simp add: undeclared_in_def declared_in_def
schirmer@12854
   882
                         cdeclaredfield_def)
schirmer@12854
   883
    with fid show ?thesis 
schirmer@12854
   884
      by auto
schirmer@12854
   885
  next
schirmer@12854
   886
    case (mid sig)
schirmer@12854
   887
    with not_undecl
schirmer@12854
   888
    obtain mthd where
schirmer@12854
   889
      "G\<turnstile>mdecl (sig,mthd) declared_in C" 
schirmer@12854
   890
      by (auto simp add: undeclared_in_def declared_in_def
schirmer@12854
   891
                         cdeclaredmethd_def)
schirmer@12854
   892
    with mid show ?thesis 
schirmer@12854
   893
      by auto
schirmer@12854
   894
  qed
schirmer@12854
   895
qed
schirmer@12854
   896
schirmer@12854
   897
lemma unique_declared_in:
schirmer@12854
   898
 "\<lbrakk>G\<turnstile>m declared_in C; G\<turnstile>n declared_in C; memberid m = memberid n\<rbrakk>
schirmer@12854
   899
 \<Longrightarrow> m = n"
schirmer@12854
   900
by (auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def
schirmer@12854
   901
            split: memberdecl.splits)
schirmer@12854
   902
schirmer@12854
   903
lemma unique_member_of: 
wenzelm@12937
   904
  assumes n: "G\<turnstile>n member_of C" and  
schirmer@12854
   905
          m: "G\<turnstile>m member_of C" and
schirmer@12854
   906
       eqid: "memberid n = memberid m"
wenzelm@12937
   907
  shows "n=m"
schirmer@12854
   908
proof -
schirmer@12854
   909
  from n m eqid  
schirmer@12854
   910
  show "n=m"
schirmer@12854
   911
  proof (induct)
berghofe@21765
   912
    case (Immediate n C)
schirmer@12854
   913
    assume member_n: "G\<turnstile> mbr n declared_in C" "declclass n = C"
schirmer@12854
   914
    assume eqid: "memberid n = memberid m"
schirmer@12854
   915
    assume "G \<turnstile> m member_of C"
schirmer@12854
   916
    then show "n=m"
schirmer@12854
   917
    proof (cases)
berghofe@34990
   918
      case Immediate
berghofe@34990
   919
      with eqid member_n
schirmer@12854
   920
      show ?thesis
wenzelm@32960
   921
        by (cases n, cases m) 
schirmer@12854
   922
           (auto simp add: declared_in_def 
schirmer@12854
   923
                           cdeclaredmethd_def cdeclaredfield_def
schirmer@12854
   924
                    split: memberdecl.splits)
schirmer@12854
   925
    next
berghofe@34990
   926
      case Inherited
schirmer@12854
   927
      with eqid member_n
schirmer@12854
   928
      show ?thesis
wenzelm@32960
   929
        by (cases n) (auto dest: declared_not_undeclared)
schirmer@12854
   930
    qed
schirmer@12854
   931
  next
berghofe@21765
   932
    case (Inherited n C S)
schirmer@12854
   933
    assume undecl: "G\<turnstile> memberid n undeclared_in C"
schirmer@12854
   934
    assume  super: "G\<turnstile>C\<prec>\<^sub>C\<^sub>1S"
schirmer@12854
   935
    assume    hyp: "\<lbrakk>G \<turnstile> m member_of S; memberid n = memberid m\<rbrakk> \<Longrightarrow> n = m"
schirmer@12854
   936
    assume   eqid: "memberid n = memberid m"
schirmer@12854
   937
    assume "G \<turnstile> m member_of C"
schirmer@12854
   938
    then show "n=m"
schirmer@12854
   939
    proof (cases)
schirmer@12854
   940
      case Immediate
schirmer@12854
   941
      then have "G\<turnstile> mbr m declared_in C" by simp
schirmer@12854
   942
      with eqid undecl
schirmer@12854
   943
      show ?thesis
wenzelm@32960
   944
        by (cases m) (auto dest: declared_not_undeclared)
schirmer@12854
   945
    next
schirmer@12854
   946
      case Inherited 
schirmer@12854
   947
      with super have "G \<turnstile> m member_of S"
wenzelm@32960
   948
        by (auto dest!: subcls1D)
schirmer@12854
   949
      with eqid hyp
schirmer@12854
   950
      show ?thesis 
wenzelm@32960
   951
        by blast
schirmer@12854
   952
    qed
schirmer@12854
   953
  qed
schirmer@12854
   954
qed
schirmer@12854
   955
schirmer@12854
   956
lemma member_of_is_classD: "G\<turnstile>m member_of C \<Longrightarrow> is_class G C"
schirmer@12854
   957
proof (induct set: members)
berghofe@21765
   958
  case (Immediate m C)
schirmer@12854
   959
  assume "G\<turnstile> mbr m declared_in C"
schirmer@12854
   960
  then show "is_class G C"
schirmer@12854
   961
    by (cases "mbr m")
schirmer@12854
   962
       (auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def)
schirmer@12854
   963
next
berghofe@21765
   964
  case (Inherited m C S)  
schirmer@12854
   965
  assume "G\<turnstile>C\<prec>\<^sub>C\<^sub>1S" and "is_class G S"
schirmer@12854
   966
  then show "is_class G C"
schirmer@12854
   967
    by - (rule subcls_is_class2,auto)
schirmer@12854
   968
qed
schirmer@12854
   969
schirmer@12854
   970
lemma member_of_declC: 
schirmer@12854
   971
 "G\<turnstile>m member_of C 
schirmer@12854
   972
  \<Longrightarrow> G\<turnstile>mbr m declared_in (declclass m)"
schirmer@12854
   973
by (induct set: members) auto
schirmer@12854
   974
schirmer@12854
   975
lemma member_of_member_of_declC:
schirmer@12854
   976
 "G\<turnstile>m member_of C 
schirmer@12854
   977
  \<Longrightarrow> G\<turnstile>m member_of (declclass m)"
schirmer@12854
   978
by (auto dest: member_of_declC intro: members.Immediate)
schirmer@12854
   979
schirmer@12854
   980
lemma member_of_class_relation:
schirmer@12854
   981
  "G\<turnstile>m member_of C \<Longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m"
schirmer@12854
   982
proof (induct set: members)
berghofe@21765
   983
  case (Immediate m C)
schirmer@12854
   984
  then show "G\<turnstile>C \<preceq>\<^sub>C declclass m" by simp
schirmer@12854
   985
next
berghofe@21765
   986
  case (Inherited m C S)
schirmer@12854
   987
  then show "G\<turnstile>C \<preceq>\<^sub>C declclass m" 
schirmer@12854
   988
    by (auto dest: r_into_rtrancl intro: rtrancl_trans)
schirmer@12854
   989
qed
schirmer@12854
   990
schirmer@12854
   991
lemma member_in_class_relation:
schirmer@12854
   992
  "G\<turnstile>m member_in C \<Longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m"
schirmer@12854
   993
by (auto dest: member_inD member_of_class_relation
schirmer@12854
   994
        intro: rtrancl_trans)
schirmer@12854
   995
schirmer@12962
   996
lemma stat_override_declclasses_relation: 
schirmer@12962
   997
"\<lbrakk>G\<turnstile>(declclass new) \<prec>\<^sub>C\<^sub>1 superNew; G \<turnstile>Method old member_of superNew \<rbrakk>
schirmer@12962
   998
\<Longrightarrow> G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old)"
schirmer@12962
   999
apply (rule trancl_rtrancl_trancl)
schirmer@12962
  1000
apply (erule r_into_trancl)
schirmer@12962
  1001
apply (cases old)
schirmer@12962
  1002
apply (auto dest: member_of_class_relation)
schirmer@12962
  1003
done
schirmer@12962
  1004
schirmer@12962
  1005
lemma stat_overrides_commonD:
schirmer@12962
  1006
"\<lbrakk>G\<turnstile>new overrides\<^sub>S old\<rbrakk> \<Longrightarrow>  
schirmer@12962
  1007
  declclass new \<noteq> Object \<and> \<not> is_static new \<and> msig new = msig old \<and> 
schirmer@12962
  1008
  G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and>
schirmer@12962
  1009
  G\<turnstile>Method new declared_in (declclass new) \<and>   
schirmer@12962
  1010
  G\<turnstile>Method old declared_in (declclass old)"
schirmer@12962
  1011
apply (induct set: stat_overridesR) 
schirmer@12962
  1012
apply (frule (1) stat_override_declclasses_relation) 
schirmer@12962
  1013
apply (auto intro: trancl_trans)
schirmer@12962
  1014
done
schirmer@12962
  1015
schirmer@12854
  1016
lemma member_of_Package: 
schirmer@12854
  1017
 "\<lbrakk>G\<turnstile>m member_of C; accmodi m = Package\<rbrakk> 
schirmer@12854
  1018
  \<Longrightarrow> pid (declclass m) = pid C" 
schirmer@12854
  1019
proof -
schirmer@12854
  1020
  assume   member: "G\<turnstile>m member_of C"
schirmer@12854
  1021
  then show " accmodi m = Package \<Longrightarrow> ?thesis" (is "PROP ?P m C")
schirmer@12854
  1022
  proof (induct rule: members.induct)
schirmer@12854
  1023
    fix C m
schirmer@12854
  1024
    assume     C: "declclass m = C"
schirmer@12854
  1025
    then show "pid (declclass m) = pid C"
schirmer@12854
  1026
      by simp
schirmer@12854
  1027
  next
schirmer@12854
  1028
    fix C S m  
schirmer@12854
  1029
    assume inheritable: "G \<turnstile> m inheritable_in pid C"
schirmer@12854
  1030
    assume         hyp: "PROP ?P m S" and
schirmer@12854
  1031
           package_acc: "accmodi m = Package" 
schirmer@12854
  1032
    with inheritable package_acc hyp
schirmer@12854
  1033
    show "pid (declclass m) = pid C" 
schirmer@12854
  1034
      by (auto simp add: inheritable_in_def)
schirmer@12854
  1035
  qed
schirmer@12854
  1036
qed
schirmer@12854
  1037
schirmer@12925
  1038
lemma member_in_declC: "G\<turnstile>m member_in C\<Longrightarrow> G\<turnstile>m member_in (declclass m)"
schirmer@12925
  1039
proof -
schirmer@12925
  1040
  assume member_in_C:  "G\<turnstile>m member_in C"
schirmer@12925
  1041
  from member_in_C
schirmer@12925
  1042
  obtain provC where
schirmer@12925
  1043
    subclseq_C_provC: "G\<turnstile> C \<preceq>\<^sub>C provC" and
schirmer@12925
  1044
     member_of_provC: "G \<turnstile> m member_of provC"
schirmer@12925
  1045
    by (auto simp add: member_in_def)
schirmer@12925
  1046
  from member_of_provC
schirmer@12925
  1047
  have "G \<turnstile> m member_of declclass m"
schirmer@12925
  1048
    by (rule member_of_member_of_declC)
schirmer@12925
  1049
  moreover
schirmer@12925
  1050
  from member_in_C
schirmer@12925
  1051
  have "G\<turnstile>C \<preceq>\<^sub>C declclass m"
schirmer@12925
  1052
    by (rule member_in_class_relation)
schirmer@12925
  1053
  ultimately
schirmer@12925
  1054
  show ?thesis
schirmer@12925
  1055
    by (auto simp add: member_in_def)
schirmer@12925
  1056
qed
schirmer@12925
  1057
schirmer@12854
  1058
lemma dyn_accessible_from_commonD: "G\<turnstile>m in C dyn_accessible_from S
schirmer@12854
  1059
 \<Longrightarrow> G\<turnstile>m member_in C"
schirmer@12854
  1060
by (auto elim: dyn_accessible_fromR.induct)
schirmer@12854
  1061
schirmer@12854
  1062
lemma no_Private_stat_override: 
schirmer@12854
  1063
 "\<lbrakk>G\<turnstile>new overrides\<^sub>S old\<rbrakk> \<Longrightarrow> accmodi old \<noteq> Private"
schirmer@12854
  1064
by (induct set:  stat_overridesR) (auto simp add: inheritable_in_def)
schirmer@12854
  1065
schirmer@12854
  1066
lemma no_Private_override: "\<lbrakk>G\<turnstile>new overrides old\<rbrakk> \<Longrightarrow> accmodi old \<noteq> Private"
schirmer@12854
  1067
by (induct set: overridesR) (auto simp add: inheritable_in_def)
schirmer@12854
  1068
schirmer@12854
  1069
lemma permits_acc_inheritance:
schirmer@14030
  1070
 "\<lbrakk>G\<turnstile>m in statC permits_acc_from accC; G\<turnstile>dynC \<preceq>\<^sub>C statC
schirmer@14030
  1071
  \<rbrakk> \<Longrightarrow> G\<turnstile>m in dynC permits_acc_from accC"
schirmer@12854
  1072
by (cases "accmodi m")
schirmer@12854
  1073
   (auto simp add: permits_acc_def
schirmer@12854
  1074
            intro: subclseq_trans) 
schirmer@12854
  1075
schirmer@12925
  1076
lemma permits_acc_static_declC:
schirmer@14030
  1077
 "\<lbrakk>G\<turnstile>m in C permits_acc_from accC; G\<turnstile>m member_in C; is_static m
schirmer@14030
  1078
  \<rbrakk> \<Longrightarrow> G\<turnstile>m in (declclass m) permits_acc_from accC"
schirmer@12925
  1079
by (cases "accmodi m") (auto simp add: permits_acc_def)
schirmer@12925
  1080
schirmer@12925
  1081
lemma dyn_accessible_from_static_declC: 
wenzelm@12937
  1082
  assumes  acc_C: "G\<turnstile>m in C dyn_accessible_from accC" and
schirmer@12925
  1083
           static: "is_static m"
wenzelm@12937
  1084
  shows "G\<turnstile>m in (declclass m) dyn_accessible_from accC"
schirmer@12925
  1085
proof -
schirmer@12925
  1086
  from acc_C static
schirmer@12925
  1087
  show "G\<turnstile>m in (declclass m) dyn_accessible_from accC"
schirmer@12925
  1088
  proof (induct)
berghofe@21765
  1089
    case (Immediate m C)
schirmer@12925
  1090
    then show ?case 
schirmer@12925
  1091
      by (auto intro!: dyn_accessible_fromR.Immediate
schirmer@12925
  1092
                 dest: member_in_declC permits_acc_static_declC) 
schirmer@12925
  1093
  next 
berghofe@21765
  1094
    case (Overriding m C declCNew new old sup)
schirmer@12925
  1095
    then have "\<not> is_static m"
schirmer@12925
  1096
      by (auto dest: overrides_commonD)
schirmer@12925
  1097
    moreover
schirmer@12925
  1098
    assume "is_static m"
schirmer@12925
  1099
    ultimately show ?case 
schirmer@12925
  1100
      by contradiction
schirmer@12925
  1101
  qed
schirmer@12925
  1102
qed
schirmer@12925
  1103
schirmer@12854
  1104
lemma field_accessible_fromD:
schirmer@12854
  1105
 "\<lbrakk>G\<turnstile>membr of C accessible_from accC;is_field membr\<rbrakk> 
schirmer@12854
  1106
  \<Longrightarrow> G\<turnstile>membr member_of C \<and>
schirmer@12854
  1107
      G\<turnstile>(Class C) accessible_in (pid accC) \<and>
schirmer@14030
  1108
      G\<turnstile>membr in C permits_acc_from accC"
schirmer@12854
  1109
by (cases set: accessible_fromR)
schirmer@12854
  1110
   (auto simp add: is_field_def split: memberdecl.splits) 
schirmer@12854
  1111
schirmer@12854
  1112
lemma field_accessible_from_permits_acc_inheritance:
schirmer@12854
  1113
"\<lbrakk>G\<turnstile>membr of statC accessible_from accC; is_field membr; G \<turnstile> dynC \<preceq>\<^sub>C statC\<rbrakk>
schirmer@14030
  1114
\<Longrightarrow> G\<turnstile>membr in dynC permits_acc_from accC"
schirmer@12854
  1115
by (auto dest: field_accessible_fromD intro: permits_acc_inheritance)
schirmer@12854
  1116
schirmer@12854
  1117
schirmer@12854
  1118
(*
schirmer@12854
  1119
lemma accessible_Package:
schirmer@12854
  1120
 "\<lbrakk>G \<turnstile> m of C accessible_from S;accmodi m = Package;
schirmer@12854
  1121
   \<And> new old. G\<turnstile>new overrides\<^sub>S old \<Longrightarrow> accmodi old \<le> accmodi new\<rbrakk>
schirmer@12854
  1122
  \<Longrightarrow> pid S = pid C \<and> pid C = pid (declclass m)"
schirmer@12854
  1123
proof -
schirmer@12854
  1124
  assume wf: "\<And> new old. G\<turnstile>new overrides\<^sub>S old \<Longrightarrow> accmodi old \<le> accmodi new"
schirmer@12854
  1125
  assume "G \<turnstile> m of C accessible_from S"
schirmer@12854
  1126
  then show "accmodi m = Package \<Longrightarrow> pid S = pid C \<and> pid C = pid (declclass m)"
schirmer@12854
  1127
    (is "?Pack m \<Longrightarrow> ?P C m")
schirmer@12854
  1128
  proof (induct rule: accessible_fromR.induct)
schirmer@12854
  1129
    fix C m
schirmer@12854
  1130
    assume "G\<turnstile>m member_of C"
schirmer@14030
  1131
           "G \<turnstile> m in C permits_acc_from S"
schirmer@12854
  1132
           "accmodi m = Package"      
schirmer@12854
  1133
    then show "?P C m"
schirmer@12854
  1134
      by (auto dest: member_of_Package simp add: permits_acc_def)
schirmer@12854
  1135
  next
schirmer@12854
  1136
    fix declC C new newm old Sup
schirmer@12854
  1137
    assume member_new: "G \<turnstile> new member_of C" and 
schirmer@12854
  1138
                acc_C: "G \<turnstile> Class C accessible_in pid S" and
schirmer@12854
  1139
                  new: "new = (declC, mdecl newm)" and
schirmer@12854
  1140
             override: "G \<turnstile> (declC, newm) overrides\<^sub>S old" and
schirmer@12854
  1141
         subcls_C_Sup: "G\<turnstile>C \<prec>\<^sub>C Sup" and
schirmer@12854
  1142
              acc_old: "G \<turnstile> methdMembr old of Sup accessible_from S" and
schirmer@12854
  1143
                  hyp: "?Pack (methdMembr old) \<Longrightarrow> ?P Sup (methdMembr old)" and
schirmer@12854
  1144
          accmodi_new: "accmodi new = Package"
schirmer@12854
  1145
    from override wf 
schirmer@12854
  1146
    have accmodi_weaken: "accmodi old \<le> accmodi newm"
schirmer@12854
  1147
      by (cases old,cases newm) auto
schirmer@12854
  1148
    from override new
schirmer@12854
  1149
    have "accmodi old \<noteq> Private"
schirmer@12854
  1150
      by (simp add: no_Private_stat_override)
schirmer@12854
  1151
    with accmodi_weaken accmodi_new new
schirmer@12854
  1152
    have accmodi_old: "accmodi old = Package"
schirmer@12854
  1153
      by (cases "accmodi old") (auto simp add: le_acc_def less_acc_def) 
schirmer@12854
  1154
    with hyp 
schirmer@12854
  1155
    have P_sup: "?P Sup (methdMembr old)"
schirmer@12854
  1156
      by (simp)
schirmer@12854
  1157
    from wf override new accmodi_old accmodi_new
schirmer@12854
  1158
    have eq_pid_new_old: "pid (declclass new) = pid (declclass old)"
schirmer@12854
  1159
      by (auto dest: stat_override_Package) 
schirmer@12854
  1160
    from member_new accmodi_new
schirmer@12854
  1161
    have "pid (declclass new) = pid C"
schirmer@12854
  1162
      by (auto dest: member_of_Package)
schirmer@12854
  1163
    with eq_pid_new_old P_sup show "?P C new"
schirmer@12854
  1164
      by auto
schirmer@12854
  1165
  qed
schirmer@12854
  1166
qed
schirmer@12854
  1167
*)
schirmer@13688
  1168
schirmer@12854
  1169
lemma accessible_fieldD: 
schirmer@12854
  1170
 "\<lbrakk>G\<turnstile>membr of C accessible_from accC; is_field membr\<rbrakk>
schirmer@12854
  1171
 \<Longrightarrow> G\<turnstile>membr member_of C \<and>
schirmer@12854
  1172
     G\<turnstile>(Class C) accessible_in (pid accC) \<and>
schirmer@14030
  1173
     G\<turnstile>membr in C permits_acc_from accC"
schirmer@12854
  1174
by (induct rule: accessible_fromR.induct) (auto dest: is_fieldD)
schirmer@12854
  1175
      
schirmer@12854
  1176
schirmer@12854
  1177
schirmer@12854
  1178
lemma member_of_Private:
schirmer@12854
  1179
"\<lbrakk>G\<turnstile>m member_of C; accmodi m = Private\<rbrakk> \<Longrightarrow> declclass m = C"
schirmer@12854
  1180
by (induct set: members) (auto simp add: inheritable_in_def)
schirmer@12854
  1181
schirmer@12854
  1182
lemma member_of_subclseq_declC:
schirmer@12854
  1183
  "G\<turnstile>m member_of C \<Longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m"
schirmer@12854
  1184
by (induct set: members) (auto dest: r_into_rtrancl intro: rtrancl_trans)
schirmer@12854
  1185
schirmer@12854
  1186
lemma member_of_inheritance:
wenzelm@12937
  1187
  assumes       m: "G\<turnstile>m member_of D" and
schirmer@12854
  1188
     subclseq_D_C: "G\<turnstile>D \<preceq>\<^sub>C C" and
schirmer@12854
  1189
     subclseq_C_m: "G\<turnstile>C \<preceq>\<^sub>C declclass m" and
schirmer@12854
  1190
               ws: "ws_prog G" 
wenzelm@12937
  1191
  shows "G\<turnstile>m member_of C"
schirmer@12854
  1192
proof -
schirmer@12854
  1193
  from m subclseq_D_C subclseq_C_m
schirmer@12854
  1194
  show ?thesis
schirmer@12854
  1195
  proof (induct)
berghofe@21765
  1196
    case (Immediate m D)
schirmer@12854
  1197
    assume "declclass m = D" and
schirmer@12854
  1198
           "G\<turnstile>D\<preceq>\<^sub>C C" and "G\<turnstile>C\<preceq>\<^sub>C declclass m"
schirmer@12854
  1199
    with ws have "D=C" 
schirmer@12854
  1200
      by (auto intro: subclseq_acyclic)
schirmer@12854
  1201
    with Immediate 
schirmer@12854
  1202
    show "G\<turnstile>m member_of C"
schirmer@12854
  1203
      by (auto intro: members.Immediate)
schirmer@12854
  1204
  next
berghofe@21765
  1205
    case (Inherited m D S)
schirmer@12854
  1206
    assume member_of_D_props: 
schirmer@12854
  1207
            "G \<turnstile> m inheritable_in pid D" 
schirmer@12854
  1208
            "G\<turnstile> memberid m undeclared_in D"  
schirmer@12854
  1209
            "G \<turnstile> Class S accessible_in pid D" 
schirmer@12854
  1210
            "G \<turnstile> m member_of S"
schirmer@12854
  1211
    assume super: "G\<turnstile>D\<prec>\<^sub>C\<^sub>1S"
schirmer@12854
  1212
    assume hyp: "\<lbrakk>G\<turnstile>S\<preceq>\<^sub>C C; G\<turnstile>C\<preceq>\<^sub>C declclass m\<rbrakk> \<Longrightarrow> G \<turnstile> m member_of C"
schirmer@12854
  1213
    assume subclseq_C_m: "G\<turnstile>C\<preceq>\<^sub>C declclass m"
schirmer@12854
  1214
    assume "G\<turnstile>D\<preceq>\<^sub>C C"
schirmer@12854
  1215
    then show "G\<turnstile>m member_of C"
schirmer@12854
  1216
    proof (cases rule: subclseq_cases)
schirmer@12854
  1217
      case Eq
schirmer@12854
  1218
      assume "D=C" 
schirmer@12854
  1219
      with super member_of_D_props 
schirmer@12854
  1220
      show ?thesis
wenzelm@32960
  1221
        by (auto intro: members.Inherited)
schirmer@12854
  1222
    next
schirmer@12854
  1223
      case Subcls
schirmer@12854
  1224
      assume "G\<turnstile>D\<prec>\<^sub>C C"
schirmer@12854
  1225
      with super 
schirmer@12854
  1226
      have "G\<turnstile>S\<preceq>\<^sub>C C"
wenzelm@32960
  1227
        by (auto dest: subcls1D subcls_superD)
schirmer@12854
  1228
      with subclseq_C_m hyp show ?thesis
wenzelm@32960
  1229
        by blast
schirmer@12854
  1230
    qed
schirmer@12854
  1231
  qed
schirmer@12854
  1232
qed
schirmer@12854
  1233
schirmer@12854
  1234
lemma member_of_subcls:
wenzelm@12937
  1235
  assumes     old: "G\<turnstile>old member_of C" and 
schirmer@12854
  1236
              new: "G\<turnstile>new member_of D" and
schirmer@12854
  1237
             eqid: "memberid new = memberid old" and
schirmer@12854
  1238
     subclseq_D_C: "G\<turnstile>D \<preceq>\<^sub>C C" and 
schirmer@12854
  1239
   subcls_new_old: "G\<turnstile>declclass new \<prec>\<^sub>C declclass old" and
schirmer@12854
  1240
               ws: "ws_prog G"
wenzelm@12937
  1241
  shows "G\<turnstile>D \<prec>\<^sub>C C"
schirmer@12854
  1242
proof -
schirmer@12854
  1243
  from old 
schirmer@12854
  1244
  have subclseq_C_old: "G\<turnstile>C \<preceq>\<^sub>C declclass old"
schirmer@12854
  1245
    by (auto dest: member_of_subclseq_declC)
schirmer@12854
  1246
  from new 
schirmer@12854
  1247
  have subclseq_D_new: "G\<turnstile>D \<preceq>\<^sub>C declclass new"
schirmer@12854
  1248
    by (auto dest: member_of_subclseq_declC)
schirmer@12854
  1249
  from subcls_new_old ws
schirmer@12854
  1250
  have neq_new_old: "new\<noteq>old"
schirmer@12854
  1251
    by (cases new,cases old) (auto dest: subcls_irrefl)
schirmer@12854
  1252
  from subclseq_D_new subclseq_D_C
schirmer@12854
  1253
  have "G\<turnstile>(declclass new) \<preceq>\<^sub>C C \<or> G\<turnstile>C \<preceq>\<^sub>C (declclass new)" 
schirmer@12854
  1254
    by (rule subcls_compareable)
schirmer@12854
  1255
  then have "G\<turnstile>(declclass new) \<preceq>\<^sub>C C"
schirmer@12854
  1256
  proof
schirmer@12854
  1257
    assume "G\<turnstile>declclass new\<preceq>\<^sub>C C" then show ?thesis .
schirmer@12854
  1258
  next
schirmer@12854
  1259
    assume "G\<turnstile>C \<preceq>\<^sub>C (declclass new)"
schirmer@12854
  1260
    with new subclseq_D_C ws 
schirmer@12854
  1261
    have "G\<turnstile>new member_of C"
schirmer@12854
  1262
      by (blast intro: member_of_inheritance)
schirmer@12854
  1263
    with eqid old 
schirmer@12854
  1264
    have "new=old"
schirmer@12854
  1265
      by (blast intro: unique_member_of)
schirmer@12854
  1266
    with neq_new_old 
schirmer@12854
  1267
    show ?thesis
schirmer@12854
  1268
      by contradiction
schirmer@12854
  1269
  qed
schirmer@12854
  1270
  then show ?thesis
schirmer@12854
  1271
  proof (cases rule: subclseq_cases)
schirmer@12854
  1272
    case Eq
schirmer@12854
  1273
    assume "declclass new = C"
schirmer@12854
  1274
    with new have "G\<turnstile>new member_of C"
schirmer@12854
  1275
      by (auto dest: member_of_member_of_declC)
schirmer@12854
  1276
    with eqid old 
schirmer@12854
  1277
    have "new=old"
schirmer@12854
  1278
      by (blast intro: unique_member_of)
schirmer@12854
  1279
    with neq_new_old 
schirmer@12854
  1280
    show ?thesis
schirmer@12854
  1281
      by contradiction
schirmer@12854
  1282
  next
schirmer@12854
  1283
    case Subcls
schirmer@12854
  1284
    assume "G\<turnstile>declclass new\<prec>\<^sub>C C"
schirmer@12854
  1285
    with subclseq_D_new
schirmer@12854
  1286
    show "G\<turnstile>D\<prec>\<^sub>C C"
schirmer@12854
  1287
      by (rule rtrancl_trancl_trancl)
schirmer@12854
  1288
  qed
schirmer@12854
  1289
qed
schirmer@12854
  1290
schirmer@12854
  1291
corollary member_of_overrides_subcls:
schirmer@12854
  1292
 "\<lbrakk>G\<turnstile>Methd sig old member_of C; G\<turnstile>Methd sig new member_of D;G\<turnstile>D \<preceq>\<^sub>C C;
schirmer@12854
  1293
   G,sig\<turnstile>new overrides old; ws_prog G\<rbrakk>
schirmer@12854
  1294
 \<Longrightarrow> G\<turnstile>D \<prec>\<^sub>C C"
schirmer@12854
  1295
by (drule overrides_commonD) (auto intro: member_of_subcls)    
schirmer@12854
  1296
schirmer@12854
  1297
corollary member_of_stat_overrides_subcls:
schirmer@12854
  1298
 "\<lbrakk>G\<turnstile>Methd sig old member_of C; G\<turnstile>Methd sig new member_of D;G\<turnstile>D \<preceq>\<^sub>C C;
schirmer@12854
  1299
   G,sig\<turnstile>new overrides\<^sub>S old; ws_prog G\<rbrakk>
schirmer@12854
  1300
 \<Longrightarrow> G\<turnstile>D \<prec>\<^sub>C C"
schirmer@12854
  1301
by (drule stat_overrides_commonD) (auto intro: member_of_subcls)    
schirmer@12854
  1302
schirmer@12854
  1303
schirmer@12854
  1304
schirmer@12854
  1305
lemma inherited_field_access: 
wenzelm@12937
  1306
  assumes stat_acc: "G\<turnstile>membr of statC accessible_from accC" and
schirmer@12854
  1307
          is_field: "is_field membr" and 
schirmer@12854
  1308
          subclseq: "G \<turnstile> dynC \<preceq>\<^sub>C statC"
wenzelm@12937
  1309
  shows "G\<turnstile>membr in dynC dyn_accessible_from accC"
schirmer@12854
  1310
proof -
schirmer@12854
  1311
  from stat_acc is_field subclseq 
schirmer@12854
  1312
  show ?thesis
schirmer@12854
  1313
    by (auto dest: accessible_fieldD 
schirmer@12925
  1314
            intro: dyn_accessible_fromR.Immediate 
schirmer@12854
  1315
                   member_inI 
schirmer@12854
  1316
                   permits_acc_inheritance)
schirmer@12854
  1317
qed
schirmer@12854
  1318
schirmer@12854
  1319
lemma accessible_inheritance:
wenzelm@12937
  1320
  assumes stat_acc: "G\<turnstile>m of statC accessible_from accC" and
schirmer@12854
  1321
          subclseq: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and
schirmer@12854
  1322
       member_dynC: "G\<turnstile>m member_of dynC" and
schirmer@12854
  1323
          dynC_acc: "G\<turnstile>(Class dynC) accessible_in (pid accC)"
wenzelm@12937
  1324
  shows "G\<turnstile>m of dynC accessible_from accC"
schirmer@12854
  1325
proof -
schirmer@12854
  1326
  from stat_acc
schirmer@12854
  1327
  have member_statC: "G\<turnstile>m member_of statC" 
schirmer@12854
  1328
    by (auto dest: accessible_from_commonD)
schirmer@12854
  1329
  from stat_acc
schirmer@12854
  1330
  show ?thesis
schirmer@12854
  1331
  proof (cases)
schirmer@12925
  1332
    case Immediate
schirmer@12854
  1333
    with member_dynC member_statC subclseq dynC_acc
schirmer@12854
  1334
    show ?thesis
schirmer@12925
  1335
      by (auto intro: accessible_fromR.Immediate permits_acc_inheritance)
schirmer@12854
  1336
  next
schirmer@12925
  1337
    case Overriding
schirmer@12854
  1338
    with member_dynC subclseq dynC_acc
schirmer@12854
  1339
    show ?thesis
schirmer@12925
  1340
      by (auto intro: accessible_fromR.Overriding rtrancl_trancl_trancl)
schirmer@12854
  1341
  qed
schirmer@12854
  1342
qed
schirmer@12854
  1343
schirmer@12854
  1344
section "fields and methods"
schirmer@12854
  1345
schirmer@12854
  1346
schirmer@12854
  1347
types
schirmer@12854
  1348
  fspec = "vname \<times> qtname"
schirmer@12854
  1349
schirmer@12854
  1350
translations 
schirmer@12854
  1351
  "fspec" <= (type) "vname \<times> qtname" 
schirmer@12854
  1352
schirmer@12854
  1353
constdefs
schirmer@12854
  1354
imethds:: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables"
schirmer@12854
  1355
"imethds G I 
schirmer@12854
  1356
  \<equiv> iface_rec (G,I)  
schirmer@12854
  1357
              (\<lambda>I i ts. (Un_tables ts) \<oplus>\<oplus> 
nipkow@30235
  1358
                        (Option.set \<circ> table_of (map (\<lambda>(s,m). (s,I,m)) (imethods i))))"
schirmer@12854
  1359
text {* methods of an interface, with overriding and inheritance, cf. 9.2 *}
schirmer@12854
  1360
schirmer@12854
  1361
constdefs
schirmer@12854
  1362
accimethds:: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables"
schirmer@12854
  1363
"accimethds G pack I
schirmer@12854
  1364
  \<equiv> if G\<turnstile>Iface I accessible_in pack 
schirmer@12854
  1365
       then imethds G I
schirmer@12854
  1366
       else \<lambda> k. {}"
schirmer@12854
  1367
text {* only returns imethds if the interface is accessible *}
schirmer@12854
  1368
schirmer@12854
  1369
constdefs
schirmer@12854
  1370
methd:: "prog \<Rightarrow> qtname  \<Rightarrow> (sig,qtname \<times> methd) table"
schirmer@12854
  1371
schirmer@12854
  1372
"methd G C 
schirmer@12854
  1373
 \<equiv> class_rec (G,C) empty
schirmer@12854
  1374
             (\<lambda>C c subcls_mthds. 
schirmer@12854
  1375
               filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m)
schirmer@12854
  1376
                          subcls_mthds 
schirmer@12854
  1377
               ++ 
schirmer@12854
  1378
               table_of (map (\<lambda>(s,m). (s,C,m)) (methods c)))"
schirmer@12854
  1379
text {* @{term "methd G C"}: methods of a class C (statically visible from C), 
schirmer@12854
  1380
     with inheritance and hiding cf. 8.4.6;
schirmer@12854
  1381
     Overriding is captured by @{text dynmethd}.
schirmer@12854
  1382
     Every new method with the same signature coalesces the
schirmer@12854
  1383
     method of a superclass. *}
schirmer@12854
  1384
schirmer@12854
  1385
constdefs                      
schirmer@12854
  1386
accmethd:: "prog \<Rightarrow> qtname \<Rightarrow> qtname  \<Rightarrow> (sig,qtname \<times> methd) table"
schirmer@12854
  1387
"accmethd G S C 
schirmer@12854
  1388
 \<equiv> filter_tab (\<lambda>sig m. G\<turnstile>method sig m of C accessible_from S) 
schirmer@12854
  1389
              (methd G C)"
schirmer@12854
  1390
text {* @{term "accmethd G S C"}: only those methods of @{term "methd G C"}, 
schirmer@12854
  1391
        accessible from S *}
schirmer@12854
  1392
schirmer@12854
  1393
text {* Note the class component in the accessibility filter. The class where
schirmer@12854
  1394
    method @{term m} is declared (@{term declC}) isn't necessarily accessible 
schirmer@12854
  1395
    from the current scope @{term S}. The method can be made accessible 
schirmer@12854
  1396
    through inheritance, too.
schirmer@12854
  1397
    So we must test accessibility of method @{term m} of class @{term C} 
schirmer@12854
  1398
    (not @{term "declclass m"}) *}
schirmer@12854
  1399
schirmer@12854
  1400
constdefs 
schirmer@12854
  1401
dynmethd:: "prog  \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table"
schirmer@12854
  1402
"dynmethd G statC dynC  
schirmer@12854
  1403
  \<equiv> \<lambda> sig. 
schirmer@12854
  1404
     (if G\<turnstile>dynC \<preceq>\<^sub>C statC
schirmer@12854
  1405
        then (case methd G statC sig of
schirmer@12854
  1406
                None \<Rightarrow> None
schirmer@12854
  1407
              | Some statM 
schirmer@12854
  1408
                  \<Rightarrow> (class_rec (G,dynC) empty
schirmer@12854
  1409
                       (\<lambda>C c subcls_mthds. 
schirmer@12854
  1410
                          subcls_mthds
schirmer@12854
  1411
                          ++
schirmer@12854
  1412
                          (filter_tab 
schirmer@12854
  1413
                            (\<lambda> _ dynM. G,sig\<turnstile>dynM overrides statM \<or> dynM=statM)
schirmer@12854
  1414
                            (methd G C) ))
schirmer@12854
  1415
                      ) sig
schirmer@12854
  1416
              )
schirmer@12854
  1417
        else None)"
schirmer@13688
  1418
schirmer@12854
  1419
text {* @{term "dynmethd G statC dynC"}: dynamic method lookup of a reference 
schirmer@12854
  1420
        with dynamic class @{term dynC} and static class @{term statC} *}
schirmer@12854
  1421
text {* Note some kind of duality between @{term methd} and @{term dynmethd} 
schirmer@12854
  1422
        in the @{term class_rec} arguments. Whereas @{term methd} filters the 
schirmer@12854
  1423
        subclass methods (to get only the inherited ones), @{term dynmethd} 
schirmer@12854
  1424
        filters the new methods (to get only those methods which actually
schirmer@12854
  1425
        override the methods of the static class) *}
schirmer@12854
  1426
schirmer@12854
  1427
constdefs 
schirmer@12854
  1428
dynimethd:: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table"
schirmer@12854
  1429
"dynimethd G I dynC 
schirmer@12854
  1430
  \<equiv> \<lambda> sig. if imethds G I sig \<noteq> {}
schirmer@12854
  1431
               then methd G dynC sig
schirmer@12854
  1432
               else dynmethd G Object dynC sig"
schirmer@12854
  1433
text {* @{term "dynimethd G I dynC"}: dynamic method lookup of a reference with 
schirmer@12854
  1434
        dynamic class dynC and static interface type I *}
schirmer@12854
  1435
text {* 
schirmer@12854
  1436
   When calling an interface method, we must distinguish if the method signature
schirmer@12854
  1437
   was defined in the interface or if it must be an Object method in the other
schirmer@12854
  1438
   case. If it was an interface method we search the class hierarchy
schirmer@12854
  1439
   starting at the dynamic class of the object up to Object to find the 
schirmer@12854
  1440
   first matching method (@{term methd}). Since all interface methods have 
schirmer@12854
  1441
   public access the method can't be coalesced due to some odd visibility 
schirmer@12854
  1442
   effects like in case of dynmethd. The method will be inherited or 
schirmer@12854
  1443
   overridden in all classes from the first class implementing the interface 
schirmer@12854
  1444
   down to the actual dynamic class.
schirmer@12854
  1445
 *}
schirmer@12854
  1446
schirmer@12854
  1447
constdefs
schirmer@12854
  1448
dynlookup::"prog  \<Rightarrow> ref_ty \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table"
schirmer@12854
  1449
"dynlookup G statT dynC
schirmer@12854
  1450
  \<equiv> (case statT of
schirmer@12854
  1451
       NullT        \<Rightarrow> empty
schirmer@12854
  1452
     | IfaceT I     \<Rightarrow> dynimethd G I      dynC
schirmer@12854
  1453
     | ClassT statC \<Rightarrow> dynmethd  G statC  dynC
schirmer@12854
  1454
     | ArrayT ty    \<Rightarrow> dynmethd  G Object dynC)"
schirmer@12854
  1455
text {* @{term "dynlookup G statT dynC"}: dynamic lookup of a method within the 
schirmer@12854
  1456
    static reference type statT and the dynamic class dynC. 
schirmer@12854
  1457
    In a wellformd context statT will not be NullT and in case
schirmer@12854
  1458
    statT is an array type, dynC=Object *}
schirmer@12854
  1459
schirmer@12854
  1460
constdefs
schirmer@12854
  1461
fields:: "prog \<Rightarrow> qtname \<Rightarrow> ((vname \<times> qtname) \<times> field) list"
schirmer@12854
  1462
"fields G C 
schirmer@12854
  1463
  \<equiv> class_rec (G,C) [] (\<lambda>C c ts. map (\<lambda>(n,t). ((n,C),t)) (cfields c) @ ts)"
schirmer@12854
  1464
text {* @{term "fields G C"} 
schirmer@12854
  1465
     list of fields of a class, including all the fields of the superclasses
schirmer@12854
  1466
     (private, inherited and hidden ones) not only the accessible ones
schirmer@12854
  1467
     (an instance of a object allocates all these fields *}
schirmer@12854
  1468
schirmer@12854
  1469
constdefs
schirmer@12854
  1470
accfield:: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (vname, qtname  \<times>  field) table"
schirmer@12854
  1471
"accfield G S C
schirmer@12854
  1472
  \<equiv> let field_tab = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (fields G C))
schirmer@12854
  1473
    in filter_tab (\<lambda>n (declC,f). G\<turnstile> (declC,fdecl (n,f)) of C accessible_from S)
schirmer@12854
  1474
                  field_tab"
schirmer@12854
  1475
text  {* @{term "accfield G C S"}: fields of a class @{term C} which are 
schirmer@12854
  1476
         accessible from scope of class
schirmer@12854
  1477
         @{term S} with inheritance and hiding, cf. 8.3 *}
schirmer@12854
  1478
text {* note the class component in the accessibility filter (see also 
schirmer@12854
  1479
        @{term methd}).
schirmer@12854
  1480
   The class declaring field @{term f} (@{term declC}) isn't necessarily 
schirmer@12854
  1481
   accessible from scope @{term S}. The field can be made visible through 
schirmer@12854
  1482
   inheritance, too. So we must test accessibility of field @{term f} of class 
schirmer@12854
  1483
   @{term C} (not @{term "declclass f"}) *} 
schirmer@12854
  1484
schirmer@12854
  1485
constdefs
schirmer@12854
  1486
schirmer@12854
  1487
  is_methd :: "prog \<Rightarrow> qtname  \<Rightarrow> sig \<Rightarrow> bool"
schirmer@12854
  1488
 "is_methd G \<equiv> \<lambda>C sig. is_class G C \<and> methd G C sig \<noteq> None"
schirmer@12854
  1489
schirmer@12854
  1490
constdefs efname:: "((vname \<times> qtname) \<times> field) \<Rightarrow> (vname \<times> qtname)"
schirmer@12854
  1491
"efname \<equiv> fst"
schirmer@12854
  1492
schirmer@12854
  1493
lemma efname_simp[simp]:"efname (n,f) = n"
schirmer@12854
  1494
by (simp add: efname_def) 
schirmer@12854
  1495
schirmer@12854
  1496
schirmer@12854
  1497
subsection "imethds"
schirmer@12854
  1498
schirmer@12854
  1499
lemma imethds_rec: "\<lbrakk>iface G I = Some i; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1500
  imethds G I = Un_tables ((\<lambda>J. imethds  G J)`set (isuperIfs i)) \<oplus>\<oplus>  
nipkow@30235
  1501
                      (Option.set \<circ> table_of (map (\<lambda>(s,mh). (s,I,mh)) (imethods i)))"
schirmer@12854
  1502
apply (unfold imethds_def)
schirmer@12854
  1503
apply (rule iface_rec [THEN trans])
schirmer@12854
  1504
apply auto
schirmer@12854
  1505
done
schirmer@12854
  1506
schirmer@12854
  1507
schirmer@12854
  1508
(* local lemma *)
schirmer@12854
  1509
lemma imethds_norec:
schirmer@12854
  1510
  "\<lbrakk>iface G md = Some i; ws_prog G; table_of (imethods i) sig = Some mh\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1511
  (md, mh) \<in> imethds G md sig"
schirmer@12854
  1512
apply (subst imethds_rec)
schirmer@12854
  1513
apply assumption+
schirmer@12854
  1514
apply (rule iffD2)
schirmer@12854
  1515
apply (rule overrides_t_Some_iff)
schirmer@12854
  1516
apply (rule disjI1)
schirmer@12854
  1517
apply (auto elim: table_of_map_SomeI)
schirmer@12854
  1518
done
schirmer@12854
  1519
schirmer@12854
  1520
lemma imethds_declI: "\<lbrakk>m \<in> imethds G I sig; ws_prog G; is_iface G I\<rbrakk> \<Longrightarrow> 
schirmer@12854
  1521
  (\<exists>i. iface G (decliface m) = Some i \<and> 
schirmer@12854
  1522
  table_of (imethods i) sig = Some (mthd m)) \<and>  
schirmer@12854
  1523
  (I,decliface m) \<in> (subint1 G)^* \<and> m \<in> imethds G (decliface m) sig"
wenzelm@24038
  1524
apply (erule rev_mp)
schirmer@12854
  1525
apply (rule ws_subint1_induct, assumption, assumption)
schirmer@12854
  1526
apply (subst imethds_rec, erule conjunct1, assumption)
schirmer@12854
  1527
apply (force elim: imethds_norec intro: rtrancl_into_rtrancl2)
schirmer@12854
  1528
done
schirmer@12854
  1529
schirmer@12854
  1530
lemma imethds_cases [consumes 3, case_names NewMethod InheritedMethod]:
wenzelm@12937
  1531
  assumes im: "im \<in> imethds G I sig" and  
schirmer@12854
  1532
         ifI: "iface G I = Some i" and
schirmer@12854
  1533
          ws: "ws_prog G" and
schirmer@12854
  1534
     hyp_new:  "table_of (map (\<lambda>(s, mh). (s, I, mh)) (imethods i)) sig 
schirmer@12854
  1535
                = Some im \<Longrightarrow> P" and
schirmer@12854
  1536
     hyp_inh: "\<And> J. \<lbrakk>J \<in> set (isuperIfs i); im \<in> imethds G J sig\<rbrakk> \<Longrightarrow> P"
wenzelm@12937
  1537
  shows P
schirmer@12854
  1538
proof -
schirmer@12854
  1539
  from ifI ws im hyp_new hyp_inh
schirmer@12854
  1540
  show "P"
schirmer@12854
  1541
    by (auto simp add: imethds_rec)
schirmer@12854
  1542
qed
schirmer@12854
  1543
schirmer@12854
  1544
subsection "accimethd"
schirmer@12854
  1545
schirmer@12854
  1546
lemma accimethds_simp [simp]: 
schirmer@12854
  1547
"G\<turnstile>Iface I accessible_in pack \<Longrightarrow> accimethds G pack I = imethds G I"
schirmer@12854
  1548
by (simp add: accimethds_def)
schirmer@12854
  1549
schirmer@12854
  1550
lemma accimethdsD:
schirmer@12854
  1551
 "im \<in> accimethds G pack I sig 
schirmer@12854
  1552
  \<Longrightarrow> im \<in> imethds G I sig \<and> G\<turnstile>Iface I accessible_in pack"
schirmer@12854
  1553
by (auto simp add: accimethds_def)
schirmer@12854
  1554
schirmer@12854
  1555
lemma accimethdsI: 
schirmer@12854
  1556
"\<lbrakk>im \<in> imethds G I sig;G\<turnstile>Iface I accessible_in pack\<rbrakk>
schirmer@12854
  1557
 \<Longrightarrow> im \<in> accimethds G pack I sig"
schirmer@12854
  1558
by simp
schirmer@12854
  1559
schirmer@12854
  1560
subsection "methd"
schirmer@12854
  1561
schirmer@12854
  1562
lemma methd_rec: "\<lbrakk>class G C = Some c; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1563
  methd G C 
schirmer@12854
  1564
    = (if C = Object 
schirmer@12854
  1565
          then empty 
schirmer@12854
  1566
          else filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m)
schirmer@12854
  1567
                          (methd G (super c))) 
schirmer@12854
  1568
      ++ table_of (map (\<lambda>(s,m). (s,C,m)) (methods c))"
schirmer@12854
  1569
apply (unfold methd_def)
schirmer@12854
  1570
apply (erule class_rec [THEN trans], assumption)
schirmer@12854
  1571
apply (simp)
schirmer@12854
  1572
done
schirmer@12854
  1573
schirmer@12854
  1574
(* local lemma *)
schirmer@12854
  1575
lemma methd_norec: 
schirmer@12854
  1576
 "\<lbrakk>class G declC = Some c; ws_prog G;table_of (methods c) sig = Some m\<rbrakk> 
schirmer@12854
  1577
  \<Longrightarrow> methd G declC sig = Some (declC, m)"
schirmer@12854
  1578
apply (simp only: methd_rec)
nipkow@14025
  1579
apply (rule disjI1 [THEN map_add_Some_iff [THEN iffD2]])
schirmer@12854
  1580
apply (auto elim: table_of_map_SomeI)
schirmer@12854
  1581
done
schirmer@12854
  1582
schirmer@12854
  1583
schirmer@12854
  1584
lemma methd_declC: 
schirmer@12854
  1585
"\<lbrakk>methd G C sig = Some m; ws_prog G;is_class G C\<rbrakk> \<Longrightarrow>
schirmer@12854
  1586
 (\<exists>d. class G (declclass m)=Some d \<and> table_of (methods d) sig=Some (mthd m)) \<and> 
schirmer@12854
  1587
 G\<turnstile>C \<preceq>\<^sub>C (declclass m) \<and> methd G (declclass m) sig = Some m"   
wenzelm@24038
  1588
apply (erule rev_mp)
schirmer@12854
  1589
apply (rule ws_subcls1_induct, assumption, assumption)
schirmer@12854
  1590
apply (subst methd_rec, assumption)
schirmer@12854
  1591
apply (case_tac "Ca=Object")
schirmer@12854
  1592
apply   (force elim: methd_norec )
schirmer@12854
  1593
schirmer@12854
  1594
apply   simp
schirmer@12854
  1595
apply   (case_tac "table_of (map (\<lambda>(s, m). (s, Ca, m)) (methods c)) sig")
schirmer@12854
  1596
apply     (force intro: rtrancl_into_rtrancl2)
schirmer@12854
  1597
schirmer@12854
  1598
apply     (auto intro: methd_norec)
schirmer@12854
  1599
done
schirmer@12854
  1600
schirmer@12854
  1601
lemma methd_inheritedD:
schirmer@12854
  1602
  "\<lbrakk>class G C = Some c; ws_prog G;methd G C sig = Some m\<rbrakk>
schirmer@12854
  1603
  \<Longrightarrow>  (declclass m \<noteq> C \<longrightarrow> G \<turnstile>C inherits method sig m)"
schirmer@12854
  1604
by (auto simp add: methd_rec)
schirmer@12854
  1605
schirmer@12854
  1606
lemma methd_diff_cls:
schirmer@12854
  1607
"\<lbrakk>ws_prog G; is_class G C; is_class G D;
schirmer@12854
  1608
 methd G C sig = m; methd G D sig = n; m\<noteq>n
schirmer@12854
  1609
\<rbrakk> \<Longrightarrow> C\<noteq>D"
schirmer@12854
  1610
by (auto simp add: methd_rec)
schirmer@12854
  1611
schirmer@12854
  1612
lemma method_declared_inI: 
schirmer@12854
  1613
 "\<lbrakk>table_of (methods c) sig = Some m; class G C = Some c\<rbrakk>
schirmer@12854
  1614
  \<Longrightarrow> G\<turnstile>mdecl (sig,m) declared_in C"
schirmer@12854
  1615
by (auto simp add: cdeclaredmethd_def declared_in_def)
schirmer@12854
  1616
schirmer@12854
  1617
lemma methd_declared_in_declclass: 
schirmer@12854
  1618
 "\<lbrakk>methd G C sig = Some m; ws_prog G;is_class G C\<rbrakk> 
schirmer@12854
  1619
 \<Longrightarrow> G\<turnstile>Methd sig m declared_in (declclass m)"
schirmer@12854
  1620
by (auto dest: methd_declC method_declared_inI)
schirmer@12854
  1621
schirmer@12854
  1622
lemma member_methd:
wenzelm@12937
  1623
  assumes member_of: "G\<turnstile>Methd sig m member_of C" and
schirmer@12854
  1624
                 ws: "ws_prog G"
wenzelm@12937
  1625
  shows "methd G C sig = Some m"
schirmer@12854
  1626
proof -
schirmer@12854
  1627
  from member_of 
schirmer@12854
  1628
  have iscls_C: "is_class G C" 
schirmer@12854
  1629
    by (rule member_of_is_classD)
schirmer@12854
  1630
  from iscls_C ws member_of
schirmer@12854
  1631
  show ?thesis (is "?Methd C")
schirmer@12854
  1632
  proof (induct rule: ws_class_induct')
schirmer@12854
  1633
    case (Object co)
schirmer@12854
  1634
    assume "G \<turnstile>Methd sig m member_of Object"
schirmer@12854
  1635
    then have "G\<turnstile>Methd sig m declared_in Object \<and> declclass m = Object"
schirmer@12854
  1636
      by (cases set: members) (cases m, auto dest: subcls1D)
schirmer@12854
  1637
    with ws Object 
schirmer@12854
  1638
    show "?Methd Object"
schirmer@12854
  1639
      by (cases m)
schirmer@12854
  1640
         (auto simp add: declared_in_def cdeclaredmethd_def methd_rec
schirmer@12854
  1641
                  intro:  table_of_mapconst_SomeI)
schirmer@12854
  1642
  next
schirmer@12854
  1643
    case (Subcls C c)
schirmer@12854
  1644
    assume clsC: "class G C = Some c" and
schirmer@12854
  1645
      neq_C_Obj: "C \<noteq> Object" and
schirmer@12854
  1646
            hyp: "G \<turnstile>Methd sig m member_of super c \<Longrightarrow> ?Methd (super c)" and
schirmer@12854
  1647
      member_of: "G \<turnstile>Methd sig m member_of C"
schirmer@12854
  1648
    from member_of
schirmer@12854
  1649
    show "?Methd C"
schirmer@12854
  1650
    proof (cases)
berghofe@34990
  1651
      case Immediate
schirmer@12854
  1652
      with clsC 
schirmer@12854
  1653
      have "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c)) sig = Some m"
wenzelm@32960
  1654
        by (cases m)
wenzelm@32960
  1655
           (auto simp add: declared_in_def cdeclaredmethd_def
wenzelm@32960
  1656
                    intro: table_of_mapconst_SomeI)
schirmer@12854
  1657
      with clsC neq_C_Obj ws 
schirmer@12854
  1658
      show ?thesis
wenzelm@32960
  1659
        by (simp add: methd_rec)
schirmer@12854
  1660
    next
berghofe@34990
  1661
      case (Inherited S)
schirmer@12854
  1662
      with clsC
berghofe@34990
  1663
      have  undecl: "G\<turnstile>mid sig undeclared_in C" and
schirmer@12854
  1664
             super: "G \<turnstile>Methd sig m member_of (super c)"
wenzelm@32960
  1665
        by (auto dest: subcls1D)
berghofe@34990
  1666
      from clsC undecl 
schirmer@12854
  1667
      have "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c)) sig = None"
wenzelm@32960
  1668
        by (auto simp add: undeclared_in_def cdeclaredmethd_def
wenzelm@32960
  1669
                    intro: table_of_mapconst_NoneI)
schirmer@12854
  1670
      moreover
schirmer@12854
  1671
      from Inherited have "G \<turnstile> C inherits (method sig m)"
wenzelm@32960
  1672
        by (auto simp add: inherits_def)
schirmer@12854
  1673
      moreover
schirmer@12854
  1674
      note clsC neq_C_Obj ws super hyp 
schirmer@12854
  1675
      ultimately
schirmer@12854
  1676
      show ?thesis
wenzelm@32960
  1677
        by (auto simp add: methd_rec intro: filter_tab_SomeI)
schirmer@12854
  1678
    qed
schirmer@12854
  1679
  qed
schirmer@12854
  1680
qed
schirmer@12854
  1681
schirmer@12854
  1682
(*unused*)
schirmer@12854
  1683
lemma finite_methd:"ws_prog G \<Longrightarrow> finite {methd G C sig |sig C. is_class G C}"
schirmer@12854
  1684
apply (rule finite_is_class [THEN finite_SetCompr2])
schirmer@12854
  1685
apply (intro strip)
schirmer@12854
  1686
apply (erule_tac ws_subcls1_induct, assumption)
schirmer@12854
  1687
apply (subst methd_rec)
schirmer@12854
  1688
apply (assumption)
nipkow@14025
  1689
apply (auto intro!: finite_range_map_of finite_range_filter_tab finite_range_map_of_map_add)
schirmer@12854
  1690
done
schirmer@12854
  1691
schirmer@12854
  1692
lemma finite_dom_methd:
schirmer@12854
  1693
 "\<lbrakk>ws_prog G; is_class G C\<rbrakk> \<Longrightarrow> finite (dom (methd G C))"
schirmer@12854
  1694
apply (erule_tac ws_subcls1_induct)
schirmer@12854
  1695
apply assumption
schirmer@12854
  1696
apply (subst methd_rec)
schirmer@12854
  1697
apply (assumption)
schirmer@12854
  1698
apply (auto intro!: finite_dom_map_of finite_dom_filter_tab)
schirmer@12854
  1699
done
schirmer@12854
  1700
schirmer@12854
  1701
schirmer@12854
  1702
subsection "accmethd"
schirmer@12854
  1703
schirmer@12854
  1704
lemma accmethd_SomeD:
schirmer@12854
  1705
"accmethd G S C sig = Some m
schirmer@12854
  1706
 \<Longrightarrow> methd G C sig = Some m \<and> G\<turnstile>method sig m of C accessible_from S"
schirmer@12854
  1707
by (auto simp add: accmethd_def dest: filter_tab_SomeD)
schirmer@12854
  1708
schirmer@12854
  1709
lemma accmethd_SomeI:
schirmer@12854
  1710
"\<lbrakk>methd G C sig = Some m; G\<turnstile>method sig m of C accessible_from S\<rbrakk> 
schirmer@12854
  1711
 \<Longrightarrow> accmethd G S C sig = Some m"
schirmer@12854
  1712
by (auto simp add: accmethd_def intro: filter_tab_SomeI)
schirmer@12854
  1713
schirmer@12854
  1714
lemma accmethd_declC: 
schirmer@12854
  1715
"\<lbrakk>accmethd G S C sig = Some m; ws_prog G; is_class G C\<rbrakk> \<Longrightarrow>
schirmer@12854
  1716
 (\<exists>d. class G (declclass m)=Some d \<and> 
schirmer@12854
  1717
  table_of (methods d) sig=Some (mthd m)) \<and> 
schirmer@12854
  1718
 G\<turnstile>C \<preceq>\<^sub>C (declclass m) \<and> methd G (declclass m) sig = Some m \<and> 
schirmer@12854
  1719
 G\<turnstile>method sig m of C accessible_from S"
schirmer@12854
  1720
by (auto dest: accmethd_SomeD methd_declC accmethd_SomeI)
schirmer@12854
  1721
schirmer@12854
  1722
schirmer@12854
  1723
lemma finite_dom_accmethd:
schirmer@12854
  1724
 "\<lbrakk>ws_prog G; is_class G C\<rbrakk> \<Longrightarrow> finite (dom (accmethd G S C))"
schirmer@12854
  1725
by (auto simp add: accmethd_def intro: finite_dom_filter_tab finite_dom_methd)
schirmer@12854
  1726
schirmer@12854
  1727
schirmer@12854
  1728
subsection "dynmethd"
schirmer@12854
  1729
schirmer@12854
  1730
lemma dynmethd_rec:
schirmer@12854
  1731
"\<lbrakk>class G dynC = Some c; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
  1732
 dynmethd G statC dynC sig
schirmer@12854
  1733
   = (if G\<turnstile>dynC \<preceq>\<^sub>C statC
schirmer@12854
  1734
        then (case methd G statC sig of
schirmer@12854
  1735
                None \<Rightarrow> None
schirmer@12854
  1736
              | Some statM 
schirmer@12854
  1737
                  \<Rightarrow> (case methd G dynC sig of
schirmer@12854
  1738
                        None \<Rightarrow> dynmethd G statC (super c) sig
schirmer@12854
  1739
                      | Some dynM \<Rightarrow> 
schirmer@12854
  1740
                          (if G,sig\<turnstile> dynM overrides statM \<or> dynM = statM 
schirmer@12854
  1741
                              then Some dynM
schirmer@12854
  1742
                              else (dynmethd G statC (super c) sig)
schirmer@12854
  1743
                      )))
schirmer@12854
  1744
         else None)" 
schirmer@12854
  1745
   (is "_ \<Longrightarrow> _ \<Longrightarrow> ?Dynmethd_def dynC sig  = ?Dynmethd_rec dynC c sig") 
schirmer@12854
  1746
proof -
schirmer@12854
  1747
  assume clsDynC: "class G dynC = Some c" and 
schirmer@12854
  1748
              ws: "ws_prog G"
schirmer@12854
  1749
  then show "?Dynmethd_def dynC sig  = ?Dynmethd_rec dynC c sig" 
schirmer@12854
  1750
  proof (induct rule: ws_class_induct'')
schirmer@12854
  1751
    case (Object co)
schirmer@12854
  1752
    show "?Dynmethd_def Object sig = ?Dynmethd_rec Object co sig"
schirmer@12854
  1753
    proof (cases "G\<turnstile>Object \<preceq>\<^sub>C statC") 
schirmer@12854
  1754
      case False
schirmer@12854
  1755
      then show ?thesis by (simp add: dynmethd_def)
schirmer@12854
  1756
    next
schirmer@12854
  1757
      case True
schirmer@12854
  1758
      then have eq_statC_Obj: "statC = Object" ..
schirmer@12854
  1759
      show ?thesis 
schirmer@12854
  1760
      proof (cases "methd G statC sig")
wenzelm@32960
  1761
        case None then show ?thesis by (simp add: dynmethd_def)
schirmer@12854
  1762
      next
wenzelm@32960
  1763
        case Some
wenzelm@32960
  1764
        with True Object ws eq_statC_Obj 
wenzelm@32960
  1765
        show ?thesis
wenzelm@32960
  1766
          by (auto simp add: dynmethd_def class_rec
schirmer@12854
  1767
                      intro: filter_tab_SomeI)
schirmer@12854
  1768
      qed
schirmer@12854
  1769
    qed
schirmer@12854
  1770
  next  
schirmer@12854
  1771
    case (Subcls dynC c sc)
schirmer@12854
  1772
    show "?Dynmethd_def dynC sig = ?Dynmethd_rec dynC c sig"
schirmer@12854
  1773
    proof (cases "G\<turnstile>dynC \<preceq>\<^sub>C statC") 
schirmer@12854
  1774
      case False
schirmer@12854
  1775
      then show ?thesis by (simp add: dynmethd_def)
schirmer@12854
  1776
    next
schirmer@12854
  1777
      case True
schirmer@12854
  1778
      note subclseq_dynC_statC = True
schirmer@12854
  1779
      show ?thesis
schirmer@12854
  1780
      proof (cases "methd G statC sig")
wenzelm@32960
  1781
        case None then show ?thesis by (simp add: dynmethd_def)
schirmer@12854
  1782
      next
wenzelm@32960
  1783
        case (Some statM)
wenzelm@32960
  1784
        note statM = Some
wenzelm@32960
  1785
        let "?filter C" = 
schirmer@12854
  1786
              "filter_tab
schirmer@12854
  1787
                (\<lambda>_ dynM. G,sig \<turnstile> dynM overrides statM \<or> dynM = statM)
schirmer@12854
  1788
                (methd G C)"
schirmer@12854
  1789
        let "?class_rec C" =
schirmer@12854
  1790
              "(class_rec (G, C) empty
schirmer@12854
  1791
                           (\<lambda>C c subcls_mthds. subcls_mthds ++ (?filter C)))"
wenzelm@32960
  1792
        from statM Subcls ws subclseq_dynC_statC
wenzelm@32960
  1793
        have dynmethd_dynC_def:
schirmer@12854
  1794
             "?Dynmethd_def dynC sig =
schirmer@12854
  1795
                ((?class_rec (super c)) 
schirmer@12854
  1796
                 ++
schirmer@12854
  1797
                (?filter dynC)) sig"
schirmer@12854
  1798
         by (simp (no_asm_simp) only: dynmethd_def class_rec)
wenzelm@32960
  1799
            auto
schirmer@12854
  1800
       show ?thesis
schirmer@12854
  1801
       proof (cases "dynC = statC")
wenzelm@32960
  1802
         case True
wenzelm@32960
  1803
         with subclseq_dynC_statC statM dynmethd_dynC_def
wenzelm@32960
  1804
         have "?Dynmethd_def dynC sig = Some statM"
wenzelm@32960
  1805
           by (auto intro: map_add_find_right filter_tab_SomeI)
wenzelm@32960
  1806
         with subclseq_dynC_statC True Some 
wenzelm@32960
  1807
         show ?thesis
wenzelm@32960
  1808
           by auto
schirmer@12854
  1809
       next
wenzelm@32960
  1810
         case False
wenzelm@32960
  1811
         with subclseq_dynC_statC Subcls 
wenzelm@32960
  1812
         have subclseq_super_statC: "G\<turnstile>(super c) \<preceq>\<^sub>C statC"
wenzelm@32960
  1813
           by (blast dest: subclseq_superD)
wenzelm@32960
  1814
         show ?thesis
wenzelm@32960
  1815
         proof (cases "methd G dynC sig") 
wenzelm@32960
  1816
           case None
wenzelm@32960
  1817
           then have "?filter dynC sig = None"
wenzelm@32960
  1818
             by (rule filter_tab_None)
schirmer@12854
  1819
           then have "?Dynmethd_def dynC sig=?class_rec (super c) sig"
wenzelm@32960
  1820
             by (simp add: dynmethd_dynC_def)
wenzelm@32960
  1821
           with  subclseq_super_statC statM None
wenzelm@32960
  1822
           have "?Dynmethd_def dynC sig = ?Dynmethd_def (super c) sig"
wenzelm@32960
  1823
             by (auto simp add: empty_def dynmethd_def)
schirmer@12854
  1824
           with None subclseq_dynC_statC statM
wenzelm@32960
  1825
           show ?thesis 
wenzelm@32960
  1826
             by simp
wenzelm@32960
  1827
         next
wenzelm@32960
  1828
           case (Some dynM)
wenzelm@32960
  1829
           note dynM = Some
wenzelm@32960
  1830
           let ?Termination = "G \<turnstile> qmdecl sig dynM overrides qmdecl sig statM \<or>
schirmer@12854
  1831
                               dynM = statM"
wenzelm@32960
  1832
           show ?thesis
wenzelm@32960
  1833
           proof (cases "?filter dynC sig")
wenzelm@32960
  1834
             case None
wenzelm@32960
  1835
             with dynM 
wenzelm@32960
  1836
             have no_termination: "\<not> ?Termination"
wenzelm@32960
  1837
               by (simp add: filter_tab_def)
wenzelm@32960
  1838
             from None 
wenzelm@32960
  1839
             have "?Dynmethd_def dynC sig=?class_rec (super c) sig"
wenzelm@32960
  1840
               by (simp add: dynmethd_dynC_def)
wenzelm@32960
  1841
             with subclseq_super_statC statM dynM no_termination
wenzelm@32960
  1842
             show ?thesis
wenzelm@32960
  1843
               by (auto simp add: empty_def dynmethd_def)
wenzelm@32960
  1844
           next
wenzelm@32960
  1845
             case Some
wenzelm@32960
  1846
             with dynM
wenzelm@32960
  1847
             have "termination": "?Termination"
wenzelm@32960
  1848
               by (auto)
wenzelm@32960
  1849
             with Some dynM
wenzelm@32960
  1850
             have "?Dynmethd_def dynC sig=Some dynM"
wenzelm@32960
  1851
              by (auto simp add: dynmethd_dynC_def)
wenzelm@32960
  1852
             with subclseq_super_statC statM dynM "termination"
wenzelm@32960
  1853
             show ?thesis
wenzelm@32960
  1854
               by (auto simp add: dynmethd_def)
wenzelm@32960
  1855
           qed
wenzelm@32960
  1856
         qed
schirmer@12854
  1857
       qed
schirmer@12854
  1858
     qed
schirmer@12854
  1859
   qed
schirmer@12854
  1860
 qed
schirmer@12854
  1861
qed
wenzelm@32960
  1862
               
schirmer@12854
  1863
lemma dynmethd_C_C:"\<lbrakk>is_class G C; ws_prog G\<rbrakk> 
schirmer@12854
  1864
\<Longrightarrow> dynmethd G C C sig = methd G C sig"          
schirmer@12854
  1865
apply (auto simp add: dynmethd_rec)
schirmer@12854
  1866
done
schirmer@12854
  1867
 
schirmer@12854
  1868
lemma dynmethdSomeD: 
schirmer@12854
  1869
 "\<lbrakk>dynmethd G statC dynC sig = Some dynM; is_class G dynC; ws_prog G\<rbrakk> 
schirmer@12854
  1870
  \<Longrightarrow> G\<turnstile>dynC \<preceq>\<^sub>C statC \<and> (\<exists> statM. methd G statC sig = Some statM)"
schirmer@12854
  1871
by (auto simp add: dynmethd_rec)
schirmer@12854
  1872
 
schirmer@12854
  1873
lemma dynmethd_Some_cases [consumes 3, case_names Static Overrides]:
wenzelm@12937
  1874
  assumes      dynM: "dynmethd G statC dynC sig = Some dynM" and
schirmer@12854
  1875
        is_cls_dynC: "is_class G dynC" and
schirmer@12854
  1876
                 ws: "ws_prog G" and
schirmer@12854
  1877
         hyp_static: "methd G statC sig = Some dynM \<Longrightarrow> P" and
schirmer@12854
  1878
       hyp_override: "\<And> statM. \<lbrakk>methd G statC sig = Some statM;dynM\<noteq>statM;
schirmer@12854
  1879
                       G,sig\<turnstile>dynM overrides statM\<rbrakk> \<Longrightarrow> P"
wenzelm@12937
  1880
  shows P
schirmer@12854
  1881
proof -
schirmer@12854
  1882
  from is_cls_dynC obtain dc where clsDynC: "class G dynC = Some dc" by blast
schirmer@12854
  1883
  from clsDynC ws dynM hyp_static hyp_override
schirmer@12854
  1884
  show "P"
schirmer@12854
  1885
  proof (induct rule: ws_class_induct)
schirmer@12854
  1886
    case (Object co)
schirmer@12854
  1887
    with ws  have "statC = Object" 
schirmer@12854
  1888
      by (auto simp add: dynmethd_rec)
schirmer@12854
  1889
    with ws Object show ?thesis by (auto simp add: dynmethd_C_C)
schirmer@12854
  1890
  next
schirmer@12854
  1891
    case (Subcls C c)
schirmer@12854
  1892
    with ws show ?thesis
schirmer@12854
  1893
      by (auto simp add: dynmethd_rec)
schirmer@12854
  1894
  qed
schirmer@12854
  1895
qed
schirmer@12854
  1896
schirmer@12854
  1897
lemma no_override_in_Object:
wenzelm@12937
  1898
  assumes          dynM: "dynmethd G statC dynC sig = Some dynM" and
schirmer@12854
  1899
            is_cls_dynC: "is_class G dynC" and
schirmer@12854
  1900
                     ws: "ws_prog G" and
schirmer@12854
  1901
                  statM: "methd G statC sig = Some statM" and
schirmer@12854
  1902
         neq_dynM_statM: "dynM\<noteq>statM"
wenzelm@12937
  1903
  shows "dynC \<noteq> Object"
schirmer@12854
  1904
proof -
schirmer@12854
  1905
  from is_cls_dynC obtain dc where clsDynC: "class G dynC = Some dc" by blast
schirmer@12854
  1906
  from clsDynC ws dynM statM neq_dynM_statM 
schirmer@12854
  1907
  show ?thesis (is "?P dynC")
schirmer@12854
  1908
  proof (induct rule: ws_class_induct)
schirmer@12854
  1909
    case (Object co)
schirmer@12854
  1910
    with ws  have "statC = Object" 
schirmer@12854
  1911
      by (auto simp add: dynmethd_rec)
schirmer@12854
  1912
    with ws Object show "?P Object" by (auto simp add: dynmethd_C_C)
schirmer@12854
  1913
  next
schirmer@12854
  1914
    case (Subcls dynC c)
schirmer@12854
  1915
    with ws show "?P dynC"
schirmer@12854
  1916
      by (auto simp add: dynmethd_rec)
schirmer@12854
  1917
  qed
schirmer@12854
  1918
qed
schirmer@12854
  1919
schirmer@12854
  1920
schirmer@12854
  1921
lemma dynmethd_Some_rec_cases [consumes 3, 
schirmer@12854
  1922
                               case_names Static Override  Recursion]:
wenzelm@12937
  1923
  assumes          dynM: "dynmethd G statC dynC sig = Some dynM" and
schirmer@12854
  1924
                clsDynC: "class G dynC = Some c" and
schirmer@12854
  1925
                     ws: "ws_prog G" and
schirmer@12854
  1926
             hyp_static: "methd G statC sig = Some dynM \<Longrightarrow> P" and
schirmer@12854
  1927
           hyp_override: "\<And> statM. \<lbrakk>methd G statC sig = Some statM;
schirmer@12854
  1928
                                     methd G dynC sig = Some dynM; statM\<noteq>dynM;
schirmer@12854
  1929
                                     G,sig\<turnstile> dynM overrides statM\<rbrakk> \<Longrightarrow> P" and
schirmer@12854
  1930
schirmer@12854
  1931
          hyp_recursion: "\<lbrakk>dynC\<noteq>Object;
wenzelm@12937
  1932
                           dynmethd G statC (super c) sig = Some dynM\<rbrakk> \<Longrightarrow> P"
wenzelm@12937
  1933
  shows P
schirmer@12854
  1934
proof -
schirmer@12854
  1935
  from clsDynC have "is_class G dynC" by simp
schirmer@12854
  1936
  note no_override_in_Object' = no_override_in_Object [OF dynM this ws]
schirmer@12854
  1937
  from ws clsDynC dynM hyp_static hyp_override hyp_recursion
schirmer@12854
  1938
  show ?thesis
schirmer@12854
  1939
    by (auto simp add: dynmethd_rec dest: no_override_in_Object')
schirmer@12854
  1940
qed
schirmer@12854
  1941
schirmer@12854
  1942
lemma dynmethd_declC: 
schirmer@12854
  1943
"\<lbrakk>dynmethd G statC dynC sig = Some m;
schirmer@12854
  1944
  is_class G statC;ws_prog G
schirmer@12854
  1945
 \<rbrakk> \<Longrightarrow>
schirmer@12854
  1946
  (\<exists>d. class G (declclass m)=Some d \<and> table_of (methods d) sig=Some (mthd m)) \<and>
schirmer@12854
  1947
  G\<turnstile>dynC \<preceq>\<^sub>C (declclass m) \<and> methd G (declclass m) sig = Some m"
schirmer@12854
  1948
proof - 
schirmer@12854
  1949
  assume  is_cls_statC: "is_class G statC" 
schirmer@12854
  1950
  assume            ws: "ws_prog G"  
schirmer@12854
  1951
  assume             m: "dynmethd G statC dynC sig = Some m"
schirmer@12854
  1952
  from m 
schirmer@12854
  1953
  have "G\<turnstile>dynC \<preceq>\<^sub>C statC" by (auto simp add: dynmethd_def)
schirmer@12854
  1954
  from this is_cls_statC 
schirmer@12854
  1955
  have is_cls_dynC: "is_class G dynC" by (rule subcls_is_class2)
schirmer@12854
  1956
  from is_cls_dynC ws m  
schirmer@12854
  1957
  show ?thesis (is "?P dynC") 
schirmer@12854
  1958
  proof (induct rule: ws_class_induct')
schirmer@12854
  1959
    case (Object co)
schirmer@12854
  1960
    with ws have "statC=Object" by (auto simp add: dynmethd_rec)
schirmer@12854
  1961
    with ws Object  
schirmer@12854
  1962
    show "?P Object" 
schirmer@12854
  1963
      by (auto simp add: dynmethd_C_C dest: methd_declC)
schirmer@12854
  1964
  next
schirmer@12854
  1965
    case (Subcls dynC c)
schirmer@12854
  1966
    assume   hyp: "dynmethd G statC (super c) sig = Some m \<Longrightarrow> ?P (super c)" and
schirmer@12854
  1967
         clsDynC: "class G dynC = Some c"  and
schirmer@12854
  1968
              m': "dynmethd G statC dynC sig = Some m" and
schirmer@12854
  1969
    neq_dynC_Obj: "dynC \<noteq> Object"
schirmer@12854
  1970
    from ws this obtain statM where
schirmer@12854
  1971
      subclseq_dynC_statC: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and 
schirmer@12854
  1972
                     statM: "methd G statC sig = Some statM"
schirmer@12854
  1973
      by (blast dest: dynmethdSomeD)
schirmer@12854
  1974
    from clsDynC neq_dynC_Obj 
schirmer@12854
  1975
    have subclseq_dynC_super: "G\<turnstile>dynC \<preceq>\<^sub>C (super c)" 
schirmer@12854
  1976
      by (auto intro: subcls1I) 
schirmer@12854
  1977
    from m' clsDynC ws 
schirmer@12854
  1978
    show "?P dynC"
schirmer@12854
  1979
    proof (cases rule: dynmethd_Some_rec_cases) 
schirmer@12854
  1980
      case Static
schirmer@12854
  1981
      with is_cls_statC ws subclseq_dynC_statC 
schirmer@12854
  1982
      show ?thesis 
wenzelm@32960
  1983
        by (auto intro: rtrancl_trans dest: methd_declC)
schirmer@12854
  1984
    next
schirmer@12854
  1985
      case Override
schirmer@12854
  1986
      with clsDynC ws 
schirmer@12854
  1987
      show ?thesis 
wenzelm@32960
  1988
        by (auto dest: methd_declC)
schirmer@12854
  1989
    next
schirmer@12854
  1990
      case Recursion
schirmer@12854
  1991
      with hyp subclseq_dynC_super 
schirmer@12854
  1992
      show ?thesis 
wenzelm@32960
  1993
        by (auto intro: rtrancl_trans) 
schirmer@12854
  1994
    qed
schirmer@12854
  1995
  qed
schirmer@12854
  1996
qed
schirmer@12854
  1997
schirmer@12854
  1998
lemma methd_Some_dynmethd_Some:
wenzelm@12937
  1999
  assumes     statM: "methd G statC sig = Some statM" and
schirmer@12854
  2000
           subclseq: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and
schirmer@12854
  2001
       is_cls_statC: "is_class G statC" and
schirmer@12854
  2002
                 ws: "ws_prog G"
wenzelm@12937
  2003
  shows "\<exists> dynM. dynmethd G statC dynC sig = Some dynM"
wenzelm@12937
  2004
    (is "?P dynC")
schirmer@12854
  2005
proof -
schirmer@12854
  2006
  from subclseq is_cls_statC 
schirmer@12854
  2007
  have is_cls_dynC: "is_class G dynC" by (rule subcls_is_class2)
schirmer@12854
  2008
  then obtain dc where
schirmer@12854
  2009
    clsDynC: "class G dynC = Some dc" by blast
schirmer@12854
  2010
  from clsDynC ws subclseq 
schirmer@12854
  2011
  show "?thesis"
schirmer@12854
  2012
  proof (induct rule: ws_class_induct)
schirmer@12854
  2013
    case (Object co)
schirmer@12854
  2014
    with ws  have "statC = Object" 
schirmer@12854
  2015
      by (auto)
schirmer@12854
  2016
    with ws Object statM
schirmer@12854
  2017
    show "?P Object"  
schirmer@12854
  2018
      by (auto simp add: dynmethd_C_C)
schirmer@12854
  2019
  next
schirmer@12854
  2020
    case (Subcls dynC dc)
schirmer@12854
  2021
    assume clsDynC': "class G dynC = Some dc"
schirmer@12854
  2022
    assume neq_dynC_Obj: "dynC \<noteq> Object"
schirmer@12854
  2023
    assume hyp: "G\<turnstile>super dc\<preceq>\<^sub>C statC \<Longrightarrow> ?P (super dc)"
schirmer@12854
  2024
    assume subclseq': "G\<turnstile>dynC\<preceq>\<^sub>C statC"
schirmer@12854
  2025
    then
schirmer@12854
  2026
    show "?P dynC"
schirmer@12854
  2027
    proof (cases rule: subclseq_cases)
schirmer@12854
  2028
      case Eq
schirmer@12854
  2029
      with ws statM clsDynC' 
schirmer@12854
  2030
      show ?thesis
wenzelm@32960
  2031
        by (auto simp add: dynmethd_rec)
schirmer@12854
  2032
    next
schirmer@12854
  2033
      case Subcls
schirmer@12854
  2034
      assume "G\<turnstile>dynC\<prec>\<^sub>C statC"
schirmer@12854
  2035
      from this clsDynC' 
schirmer@12854
  2036
      have "G\<turnstile>super dc\<preceq>\<^sub>C statC" by (rule subcls_superD)
schirmer@12854
  2037
      with hyp ws clsDynC' subclseq' statM
schirmer@12854
  2038
      show ?thesis
wenzelm@32960
  2039
        by (auto simp add: dynmethd_rec)
schirmer@12854
  2040
    qed
schirmer@12854
  2041
  qed
schirmer@12854
  2042
qed
schirmer@12854
  2043
schirmer@12854
  2044
lemma dynmethd_cases [consumes 4, case_names Static Overrides]:
wenzelm@12937
  2045
  assumes     statM: "methd G statC sig = Some statM" and 
schirmer@12854
  2046
           subclseq: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and
schirmer@12854
  2047
       is_cls_statC: "is_class G statC" and
schirmer@12854
  2048
                 ws: "ws_prog G" and
schirmer@12854
  2049
         hyp_static: "dynmethd G statC dynC sig = Some statM \<Longrightarrow> P" and
schirmer@12854
  2050
       hyp_override: "\<And> dynM. \<lbrakk>dynmethd G statC dynC sig = Some dynM;
schirmer@12854
  2051
                                 dynM\<noteq>statM;
schirmer@12854
  2052
                           G,sig\<turnstile>dynM overrides statM\<rbrakk> \<Longrightarrow> P"
wenzelm@12937
  2053
  shows P
schirmer@12854
  2054
proof -
schirmer@12854
  2055
  from subclseq is_cls_statC 
schirmer@12854
  2056
  have is_cls_dynC: "is_class G dynC" by (rule subcls_is_class2)
schirmer@12854
  2057
  then obtain dc where
schirmer@12854
  2058
    clsDynC: "class G dynC = Some dc" by blast
schirmer@12854
  2059
  from statM subclseq is_cls_statC ws 
schirmer@12854
  2060
  obtain dynM
schirmer@12854
  2061
    where dynM: "dynmethd G statC dynC sig = Some dynM"
schirmer@12854
  2062
    by (blast dest: methd_Some_dynmethd_Some)
schirmer@12854
  2063
  from dynM is_cls_dynC ws 
schirmer@12854
  2064
  show ?thesis
schirmer@12854
  2065
  proof (cases rule: dynmethd_Some_cases)
schirmer@12854
  2066
    case Static
schirmer@12854
  2067
    with hyp_static dynM statM show ?thesis by simp
schirmer@12854
  2068
  next
schirmer@12854
  2069
    case Overrides
schirmer@12854
  2070
    with hyp_override dynM statM show ?thesis by simp
schirmer@12854
  2071
  qed
schirmer@12854
  2072
qed
schirmer@12854
  2073
schirmer@12854
  2074
lemma ws_dynmethd:
wenzelm@12937
  2075
  assumes  statM: "methd G statC sig = Some statM" and
schirmer@12854
  2076
        subclseq: "G\<turnstile>dynC \<preceq>\<^sub>C statC" and
schirmer@12854
  2077
    is_cls_statC: "is_class G statC" and
schirmer@12854
  2078
              ws: "ws_prog G"
wenzelm@12937
  2079
  shows
wenzelm@12937
  2080
    "\<exists> dynM. dynmethd G statC dynC sig = Some dynM \<and>
wenzelm@12937
  2081
             is_static dynM = is_static statM \<and> G\<turnstile>resTy dynM\<preceq>resTy statM"
schirmer@12854
  2082
proof - 
schirmer@12854
  2083
  from statM subclseq is_cls_statC ws
schirmer@12854
  2084
  show ?thesis
schirmer@12854
  2085
  proof (cases rule: dynmethd_cases)
schirmer@12854
  2086
    case Static
schirmer@12854
  2087
    with statM 
schirmer@12854
  2088
    show ?thesis
schirmer@12854
  2089
      by simp
schirmer@12854
  2090
  next
schirmer@12854
  2091
    case Overrides
schirmer@12854
  2092
    with ws
schirmer@12854
  2093
    show ?thesis
schirmer@12854
  2094
      by (auto dest: ws_overrides_commonD)
schirmer@12854
  2095
  qed
schirmer@12854
  2096
qed
schirmer@12854
  2097
schirmer@12854
  2098
subsection "dynlookup"
schirmer@12854
  2099
schirmer@12854
  2100
lemma dynlookup_cases [consumes 1, case_names NullT IfaceT ClassT ArrayT]:
schirmer@12854
  2101
"\<lbrakk>dynlookup G statT dynC sig = x;
schirmer@12854
  2102
           \<lbrakk>statT = NullT       ; empty sig = x                  \<rbrakk> \<Longrightarrow> P;
schirmer@12854
  2103
  \<And> I.    \<lbrakk>statT = IfaceT I    ; dynimethd G I      dynC sig = x\<rbrakk> \<Longrightarrow> P;
schirmer@12854
  2104
  \<And> statC.\<lbrakk>statT = ClassT statC; dynmethd  G statC  dynC sig = x\<rbrakk> \<Longrightarrow> P;
schirmer@12854
  2105
  \<And> ty.   \<lbrakk>statT = ArrayT ty   ; dynmethd  G Object dynC sig = x\<rbrakk> \<Longrightarrow> P
schirmer@12854
  2106
 \<rbrakk> \<Longrightarrow> P"
schirmer@12854
  2107
by (cases statT) (auto simp add: dynlookup_def)
schirmer@12854
  2108
schirmer@12854
  2109
subsection "fields"
schirmer@12854
  2110
schirmer@12854
  2111
lemma fields_rec: "\<lbrakk>class G C = Some c; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
  2112
  fields G C = map (\<lambda>(fn,ft). ((fn,C),ft)) (cfields c) @  
schirmer@12854
  2113
  (if C = Object then [] else fields G (super c))"
schirmer@12854
  2114
apply (simp only: fields_def)
schirmer@12854
  2115
apply (erule class_rec [THEN trans])
schirmer@12854
  2116
apply assumption
schirmer@12854
  2117
apply clarsimp
schirmer@12854
  2118
done
schirmer@12854
  2119
schirmer@12854
  2120
(* local lemma *)
schirmer@12854
  2121
lemma fields_norec: 
schirmer@12854
  2122
"\<lbrakk>class G fd = Some c; ws_prog G;  table_of (cfields c) fn = Some f\<rbrakk> 
schirmer@12854
  2123
 \<Longrightarrow> table_of (fields G fd) (fn,fd) = Some f"
schirmer@12854
  2124
apply (subst fields_rec)
schirmer@12854
  2125
apply assumption+
nipkow@14025
  2126
apply (subst map_of_append)
nipkow@14025
  2127
apply (rule disjI1 [THEN map_add_Some_iff [THEN iffD2]])
schirmer@12854
  2128
apply (auto elim: table_of_map2_SomeI)
schirmer@12854
  2129
done
schirmer@12854
  2130
schirmer@12854
  2131
(* local lemma *)
schirmer@12854
  2132
lemma table_of_fieldsD:
schirmer@12854
  2133
"table_of (map (\<lambda>(fn,ft). ((fn,C),ft)) (cfields c)) efn = Some f
schirmer@12854
  2134
\<Longrightarrow> (declclassf efn) = C \<and> table_of (cfields c) (fname efn) = Some f"
schirmer@12854
  2135
apply (case_tac "efn")
schirmer@12854
  2136
by auto
schirmer@12854
  2137
schirmer@12854
  2138
lemma fields_declC: 
schirmer@12854
  2139
 "\<lbrakk>table_of (fields G C) efn = Some f; ws_prog G; is_class G C\<rbrakk> \<Longrightarrow>  
schirmer@12854
  2140
  (\<exists>d. class G (declclassf efn) = Some d \<and> 
schirmer@12854
  2141
                    table_of (cfields d) (fname efn)=Some f) \<and> 
schirmer@12854
  2142
  G\<turnstile>C \<preceq>\<^sub>C (declclassf efn)  \<and> table_of (fields G (declclassf efn)) efn = Some f"
wenzelm@24038
  2143
apply (erule rev_mp)
schirmer@12854
  2144
apply (rule ws_subcls1_induct, assumption, assumption)
schirmer@12854
  2145
apply (subst fields_rec, assumption)
schirmer@12854
  2146
apply clarify
nipkow@14025
  2147
apply (simp only: map_of_append)
schirmer@12854
  2148
apply (case_tac "table_of (map (split (\<lambda>fn. Pair (fn, Ca))) (cfields c)) efn") 
nipkow@14025
  2149
apply   (force intro:rtrancl_into_rtrancl2 simp add: map_add_def)
schirmer@12854
  2150
schirmer@12854
  2151
apply   (frule_tac fd="Ca" in fields_norec)
schirmer@12854
  2152
apply     assumption
schirmer@12854
  2153
apply     blast
schirmer@12854
  2154
apply   (frule table_of_fieldsD)  
schirmer@12854
  2155
apply   (frule_tac n="table_of (map (split (\<lambda>fn. Pair (fn, Ca))) (cfields c))"
schirmer@12854
  2156
              and  m="table_of (if Ca = Object then [] else fields G (super c))"
nipkow@14025
  2157
         in map_add_find_right)
schirmer@12854
  2158
apply   (case_tac "efn")
schirmer@12854
  2159
apply   (simp)
schirmer@12854
  2160
done
schirmer@12854
  2161
schirmer@12854
  2162
lemma fields_emptyI: "\<And>y. \<lbrakk>ws_prog G; class G C = Some c;cfields c = [];  
schirmer@12854
  2163
  C \<noteq> Object \<longrightarrow> class G (super c) = Some y \<and> fields G (super c) = []\<rbrakk> \<Longrightarrow>  
schirmer@12854
  2164
  fields G C = []"
schirmer@12854
  2165
apply (subst fields_rec)
schirmer@12854
  2166
apply assumption
schirmer@12854
  2167
apply auto
schirmer@12854
  2168
done
schirmer@12854
  2169
schirmer@12854
  2170
(* easier than with table_of *)
schirmer@12854
  2171
lemma fields_mono_lemma: 
schirmer@12854
  2172
"\<lbrakk>x \<in> set (fields G C); G\<turnstile>D \<preceq>\<^sub>C C; ws_prog G\<rbrakk> 
schirmer@12854
  2173
 \<Longrightarrow> x \<in> set (fields G D)"
wenzelm@24038
  2174
apply (erule rev_mp)
schirmer@12854
  2175
apply (erule converse_rtrancl_induct)
schirmer@12854
  2176
apply  fast
schirmer@12854
  2177
apply (drule subcls1D)
schirmer@12854
  2178
apply clarsimp
schirmer@12854
  2179
apply (subst fields_rec)
schirmer@12854
  2180
apply   auto
schirmer@12854
  2181
done
schirmer@12854
  2182
schirmer@12854
  2183
schirmer@12854
  2184
lemma ws_unique_fields_lemma: 
schirmer@12854
  2185
 "\<lbrakk>(efn,fd)  \<in> set (fields G (super c)); fc \<in> set (cfields c); ws_prog G;  
schirmer@12854
  2186
   fname efn = fname fc; declclassf efn = C;
schirmer@12854
  2187
   class G C = Some c; C \<noteq> Object; class G (super c) = Some d\<rbrakk> \<Longrightarrow> R"
schirmer@12854
  2188
apply (frule_tac ws_prog_cdeclD [THEN conjunct2], assumption, assumption)
schirmer@12854
  2189
apply (drule_tac weak_map_of_SomeI)
schirmer@12854
  2190
apply (frule_tac subcls1I [THEN subcls1_irrefl], assumption, assumption)
schirmer@12854
  2191
apply (auto dest: fields_declC [THEN conjunct2 [THEN conjunct1[THEN rtranclD]]])
schirmer@12854
  2192
done
schirmer@12854
  2193
schirmer@12854
  2194
lemma ws_unique_fields: "\<lbrakk>is_class G C; ws_prog G; 
schirmer@12854
  2195
       \<And>C c. \<lbrakk>class G C = Some c\<rbrakk> \<Longrightarrow> unique (cfields c) \<rbrakk> \<Longrightarrow>
schirmer@12854
  2196
      unique (fields G C)" 
schirmer@12854
  2197
apply (rule ws_subcls1_induct, assumption, assumption)
schirmer@12854
  2198
apply (subst fields_rec, assumption)            
paulson@13585
  2199
apply (auto intro!: unique_map_inj inj_onI 
paulson@13585
  2200
            elim!: unique_append ws_unique_fields_lemma fields_norec)
schirmer@12854
  2201
done
schirmer@12854
  2202
schirmer@12854
  2203
schirmer@12854
  2204
subsection "accfield"
schirmer@12854
  2205
schirmer@12854
  2206
lemma accfield_fields: 
schirmer@12854
  2207
 "accfield G S C fn = Some f 
schirmer@12854
  2208
  \<Longrightarrow> table_of (fields G C) (fn, declclass f) = Some (fld f)"
schirmer@12854
  2209
apply (simp only: accfield_def Let_def)
schirmer@12854
  2210
apply (rule table_of_remap_SomeD)
schirmer@12854
  2211
apply (auto dest: filter_tab_SomeD)
schirmer@12854
  2212
done
schirmer@12854
  2213
schirmer@12854
  2214
schirmer@12854
  2215
lemma accfield_declC_is_class: 
schirmer@12854
  2216
 "\<lbrakk>is_class G C; accfield G S C en = Some (fd, f); ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
  2217
   is_class G fd"
schirmer@12854
  2218
apply (drule accfield_fields)
schirmer@12854
  2219
apply (drule fields_declC [THEN conjunct1], assumption)
schirmer@12854
  2220
apply auto
schirmer@12854
  2221
done
schirmer@12854
  2222
schirmer@12854
  2223
lemma accfield_accessibleD: 
schirmer@12854
  2224
  "accfield G S C fn = Some f \<Longrightarrow> G\<turnstile>Field fn f of C accessible_from S"
schirmer@12854
  2225
by (auto simp add: accfield_def Let_def)
schirmer@12854
  2226
schirmer@12854
  2227
subsection "is methd"
schirmer@12854
  2228
schirmer@12854
  2229
lemma is_methdI: 
schirmer@12854
  2230
"\<lbrakk>class G C = Some y; methd G C sig = Some b\<rbrakk> \<Longrightarrow> is_methd G C sig"
schirmer@12854
  2231
apply (unfold is_methd_def)
schirmer@12854
  2232
apply auto
schirmer@12854
  2233
done
schirmer@12854
  2234
schirmer@12854
  2235
lemma is_methdD: 
schirmer@12854
  2236
"is_methd G C sig \<Longrightarrow> class G C \<noteq> None \<and> methd G C sig \<noteq> None"
schirmer@12854
  2237
apply (unfold is_methd_def)
schirmer@12854
  2238
apply auto
schirmer@12854
  2239
done
schirmer@12854
  2240
schirmer@12854
  2241
lemma finite_is_methd: 
schirmer@12854
  2242
 "ws_prog G \<Longrightarrow> finite (Collect (split (is_methd G)))"
schirmer@12854
  2243
apply (unfold is_methd_def)
schirmer@12854
  2244
apply (subst SetCompr_Sigma_eq)
schirmer@12854
  2245
apply (rule finite_is_class [THEN finite_SigmaI])
schirmer@12854
  2246
apply (simp only: mem_Collect_eq)
schirmer@12854
  2247
apply (fold dom_def)
schirmer@12854
  2248
apply (erule finite_dom_methd)
schirmer@12854
  2249
apply assumption
schirmer@12854
  2250
done
schirmer@12854
  2251
schirmer@12854
  2252
section "calculation of the superclasses of a class"
schirmer@12854
  2253
schirmer@12854
  2254
constdefs 
schirmer@12854
  2255
 superclasses:: "prog \<Rightarrow> qtname \<Rightarrow> qtname set"
schirmer@12854
  2256
 "superclasses G C \<equiv> class_rec (G,C) {} 
schirmer@12854
  2257
                       (\<lambda> C c superclss. (if C=Object 
schirmer@12854
  2258
                                            then {} 
schirmer@12854
  2259
                                            else insert (super c) superclss))"
schirmer@12854
  2260
   
schirmer@12854
  2261
lemma superclasses_rec: "\<lbrakk>class G C = Some c; ws_prog G\<rbrakk> \<Longrightarrow>  
schirmer@12854
  2262
 superclasses G C 
schirmer@12854
  2263
 = (if (C=Object) 
schirmer@12854
  2264
       then {}
schirmer@12854
  2265
       else insert (super c) (superclasses G (super c)))"
schirmer@12854
  2266
apply (unfold superclasses_def)
schirmer@12854
  2267
apply (erule class_rec [THEN trans], assumption)
schirmer@12854
  2268
apply (simp)
schirmer@12854
  2269
done
schirmer@12854
  2270
schirmer@12854
  2271
lemma superclasses_mono:
berghofe@34915
  2272
  assumes clsrel: "G\<turnstile>C\<prec>\<^sub>C D"
berghofe@34915
  2273
  and ws: "ws_prog G"
berghofe@34915
  2274
  and cls_C: "class G C = Some c"
berghofe@34915
  2275
  and wf: "\<And>C c. \<lbrakk>class G C = Some c; C \<noteq> Object\<rbrakk>
berghofe@34915
  2276
    \<Longrightarrow> \<exists>sc. class G (super c) = Some sc"
berghofe@34915
  2277
  and x: "x\<in>superclasses G D"
berghofe@34915
  2278
  shows "x\<in>superclasses G C" using clsrel cls_C x
berghofe@34915
  2279
proof (induct arbitrary: c rule: converse_trancl_induct)
berghofe@34915
  2280
  case (base C)
berghofe@34915
  2281
  with wf ws show ?case
berghofe@34915
  2282
    by (auto    intro: no_subcls1_Object 
berghofe@34915
  2283
             simp add: superclasses_rec subcls1_def)
berghofe@34915
  2284
next
berghofe@34915
  2285
  case (step C S)
berghofe@34915
  2286
  moreover note wf ws
berghofe@34915
  2287
  moreover from calculation 
berghofe@34915
  2288
  have "x\<in>superclasses G S"
berghofe@34915
  2289
    by (force intro: no_subcls1_Object simp add: subcls1_def)
berghofe@34915
  2290
  moreover from calculation 
berghofe@34915
  2291
  have "super c = S" 
berghofe@34915
  2292
    by (auto intro: no_subcls1_Object simp add: subcls1_def)
berghofe@34915
  2293
  ultimately show ?case 
berghofe@34915
  2294
    by (auto intro: no_subcls1_Object simp add: superclasses_rec)
schirmer@12854
  2295
qed
schirmer@12854
  2296
schirmer@12854
  2297
lemma subclsEval:
berghofe@34915
  2298
  assumes clsrel: "G\<turnstile>C\<prec>\<^sub>C D"
berghofe@34915
  2299
  and ws: "ws_prog G"
berghofe@34915
  2300
  and cls_C: "class G C = Some c"
berghofe@34915
  2301
  and wf: "\<And>C c. \<lbrakk>class G C = Some c; C \<noteq> Object\<rbrakk>
berghofe@34915
  2302
    \<Longrightarrow> \<exists>sc. class G (super c) = Some sc"
berghofe@34915
  2303
  shows "D\<in>superclasses G C" using clsrel cls_C
berghofe@34915
  2304
proof (induct arbitrary: c rule: converse_trancl_induct)
berghofe@34915
  2305
  case (base C)
berghofe@34915
  2306
  with ws wf show ?case
berghofe@34915
  2307
    by (auto intro: no_subcls1_Object simp add: superclasses_rec subcls1_def)
berghofe@34915
  2308
next
berghofe@34915
  2309
  case (step C S)
berghofe@34915
  2310
  with ws wf show ?case
berghofe@34915
  2311
    by - (rule superclasses_mono,
berghofe@34915
  2312
          auto dest: no_subcls1_Object simp add: subcls1_def )
schirmer@12854
  2313
qed
schirmer@12854
  2314
kleing@14981
  2315
end