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