src/HOL/Bali/WellForm.thy
author schirmer
Mon, 28 Jan 2002 17:00:19 +0100
changeset 12854 00d4a435777f
child 12857 a4386cc9b1c3
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
(*  Title:      isabelle/Bali/WellForm.thy
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     2
    ID:         $Id$
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     3
    Author:     David von Oheimb
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     4
    Copyright   1997 Technische Universitaet Muenchen
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     5
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     6
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     7
header {* Well-formedness of Java programs *}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     8
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     9
theory WellForm = WellType:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    10
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    11
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    12
For static checks on expressions and statements, see WellType.thy
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    13
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    14
improvements over Java Specification 1.0 (cf. 8.4.6.3, 8.4.6.4, 9.4.1):
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    15
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    16
\item a method implementing or overwriting another method may have a result 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    17
      type that widens to the result type of the other method 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    18
      (instead of identical type)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    19
\item if a method hides another method (both methods have to be static!)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    20
  there are no restrictions to the result type 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    21
  since the methods have to be static and there is no dynamic binding of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    22
  static methods
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    23
\item if an interface inherits more than one method with the same signature, the
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    24
  methods need not have identical return types
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    25
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    26
simplifications:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    27
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    28
\item Object and standard exceptions are assumed to be declared like normal 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    29
      classes
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    30
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    31
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    32
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    33
section "well-formed field declarations"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    34
  (* well-formed field declaration (common part for classes and interfaces),
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    35
     cf. 8.3 and (9.3) *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    36
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    37
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    38
  wf_fdecl :: "prog \<Rightarrow> pname \<Rightarrow> fdecl \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    39
 "wf_fdecl G P \<equiv> \<lambda>(fn,f). is_acc_type G P (type f)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    40
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    41
lemma wf_fdecl_def2: "\<And>fd. wf_fdecl G P fd = is_acc_type G P (type (snd fd))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    42
apply (unfold wf_fdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    43
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    44
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    45
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    46
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    47
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    48
section "well-formed method declarations"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    49
  (*well-formed method declaration,cf. 8.4, 8.4.1, 8.4.3, 8.4.5, 14.3.2, (9.4)*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    50
  (* cf. 14.15, 15.7.2, for scope issues cf. 8.4.1 and 14.3.2 *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    51
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    52
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    53
A method head is wellformed if:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    54
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    55
\item the signature and the method head agree in the number of parameters
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    56
\item all types of the parameters are visible
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    57
\item the result type is visible
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    58
\item the parameter names are unique
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    59
\end{itemize} 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    60
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    61
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    62
  wf_mhead :: "prog \<Rightarrow> pname \<Rightarrow> sig \<Rightarrow> mhead \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    63
 "wf_mhead G P \<equiv> \<lambda> sig mh. length (parTs sig) = length (pars mh) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    64
			    \<spacespace> ( \<forall>T\<in>set (parTs sig). is_acc_type G P T) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    65
                            is_acc_type G P (resTy mh) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    66
			    \<spacespace> nodups (pars mh)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    67
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    68
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    69
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    70
A method declaration is wellformed if:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    71
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    72
\item the method head is wellformed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    73
\item the names of the local variables are unique
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    74
\item the types of the local variables must be accessible
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    75
\item the local variables don't shadow the parameters
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    76
\item the class of the method is defined
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    77
\item the body statement is welltyped with respect to the
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    78
      modified environment of local names, were the local variables, 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    79
      the parameters the special result variable (Res) and This are assoziated
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    80
      with there types. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    81
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    82
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    83
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    84
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    85
  wf_mdecl :: "prog \<Rightarrow> qtname \<Rightarrow> mdecl \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    86
 "wf_mdecl G C \<equiv> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    87
      \<lambda>(sig,m).
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    88
	  wf_mhead G (pid C) sig (mhead m) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    89
          unique (lcls (mbody m)) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    90
          (\<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    91
	  (\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    92
          is_class G C \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    93
          \<lparr>prg=G,cls=C,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    94
           lcl=\<lambda> k. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    95
               (case k of
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    96
                  EName e 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    97
                  \<Rightarrow> (case e of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    98
                        VNam v 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    99
                        \<Rightarrow>(table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   100
                      | Res \<Rightarrow> Some (resTy m))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   101
	        | This \<Rightarrow> if static m then None else Some (Class C))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   102
          \<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   103
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   104
lemma wf_mheadI: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   105
"\<lbrakk>length (parTs sig) = length (pars m); \<forall>T\<in>set (parTs sig). is_acc_type G P T;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   106
  is_acc_type G P (resTy m); nodups (pars m)\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   107
  wf_mhead G P sig m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   108
apply (unfold wf_mhead_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   109
apply (simp (no_asm_simp))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   110
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   111
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   112
lemma wf_mdeclI: "\<lbrakk>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   113
  wf_mhead G (pid C) sig (mhead m); unique (lcls (mbody m));  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   114
  (\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None); 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   115
  \<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   116
  is_class G C;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   117
  \<lparr>prg=G,cls=C,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   118
   lcl=\<lambda> k. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   119
       (case k of
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   120
          EName e 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   121
          \<Rightarrow> (case e of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   122
                VNam v 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   123
                \<Rightarrow> (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   124
              | Res \<Rightarrow> Some (resTy m))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   125
        | This \<Rightarrow> if static m then None else Some (Class C))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   126
  \<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   127
  \<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   128
  wf_mdecl G C (sig,m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   129
apply (unfold wf_mdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   130
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   131
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   132
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   133
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   134
lemma wf_mdeclD1: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   135
"wf_mdecl G C (sig,m) \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   136
   wf_mhead G (pid C) sig (mhead m) \<and> unique (lcls (mbody m)) \<and>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   137
  (\<forall>pn\<in>set (pars m). table_of (lcls (mbody m)) pn = None) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   138
  (\<forall>(vn,T)\<in>set (lcls (mbody m)). is_acc_type G (pid C) T)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   139
apply (unfold wf_mdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   140
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   141
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   142
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   143
lemma wf_mdecl_bodyD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   144
"wf_mdecl G C (sig,m) \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   145
 (\<exists>T. \<lparr>prg=G,cls=C,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   146
       lcl = \<lambda> k. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   147
         (case k of
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   148
            EName e 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   149
            \<Rightarrow> (case e of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   150
                VNam v \<Rightarrow> (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   151
                | Res  \<Rightarrow> Some (resTy m))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   152
          | This \<Rightarrow> if static m then None else Some (Class C))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   153
       \<rparr>\<turnstile>Body C (stmt (mbody m))\<Colon>-T \<and> G\<turnstile>T\<preceq>(resTy m))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   154
apply (unfold wf_mdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   155
apply clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   156
apply (rule_tac x="(resTy m)" in exI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   157
apply (unfold wf_mhead_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   158
apply (auto simp add: wf_mhead_def is_acc_type_def intro: wt.Body )
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   159
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   160
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   161
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   162
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   163
lemma static_Object_methodsE [elim!]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   164
 "\<lbrakk>wf_mdecl G Object (sig, m);static m\<rbrakk> \<Longrightarrow> R"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   165
apply (unfold wf_mdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   166
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   167
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   168
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   169
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   170
lemma rT_is_acc_type: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   171
  "wf_mhead G P sig m \<Longrightarrow> is_acc_type G P (resTy m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   172
apply (unfold wf_mhead_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   173
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   174
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   175
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   176
section "well-formed interface declarations"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   177
  (* well-formed interface declaration, cf. 9.1, 9.1.2.1, 9.1.3, 9.4 *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   178
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   179
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   180
A interface declaration is wellformed if:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   181
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   182
\item the interface hierarchy is wellstructured
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   183
\item there is no class with the same name
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   184
\item the method heads are wellformed and not static and have Public access
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   185
\item the methods are uniquely named
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   186
\item all superinterfaces are accessible
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   187
\item the result type of a method overriding a method of Object widens to the
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   188
      result type of the overridden method.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   189
      Shadowing static methods is forbidden.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   190
\item the result type of a method overriding a set of methods defined in the
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   191
      superinterfaces widens to each of the corresponding result types
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   192
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   193
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   194
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   195
  wf_idecl :: "prog  \<Rightarrow> idecl \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   196
 "wf_idecl G \<equiv> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   197
    \<lambda>(I,i). 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   198
        ws_idecl G I (isuperIfs i) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   199
	\<not>is_class G I \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   200
	(\<forall>(sig,mh)\<in>set (imethods i). wf_mhead G (pid I) sig mh \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   201
                                     \<not>is_static mh \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   202
                                      accmodi mh = Public) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   203
	unique (imethods i) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   204
        (\<forall> J\<in>set (isuperIfs i). is_acc_iface G (pid I) J) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   205
        (table_of (imethods i)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   206
          hiding (methd G Object)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   207
          under  (\<lambda> new old. accmodi old \<noteq> Private)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   208
          entails (\<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   209
                             is_static new = is_static old)) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   210
        (o2s \<circ> table_of (imethods i) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   211
               hidings Un_tables((\<lambda>J.(imethds G J))`set (isuperIfs i))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   212
	       entails (\<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   213
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   214
lemma wf_idecl_mhead: "\<lbrakk>wf_idecl G (I,i); (sig,mh)\<in>set (imethods i)\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   215
  wf_mhead G (pid I) sig mh \<and> \<not>is_static mh \<and> accmodi mh = Public"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   216
apply (unfold wf_idecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   217
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   218
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   219
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   220
lemma wf_idecl_hidings: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   221
"wf_idecl G (I, i) \<Longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   222
  (\<lambda>s. o2s (table_of (imethods i) s)) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   223
  hidings Un_tables ((\<lambda>J. imethds G J) ` set (isuperIfs i))  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   224
  entails \<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   225
apply (unfold wf_idecl_def o_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   226
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   227
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   228
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   229
lemma wf_idecl_hiding:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   230
"wf_idecl G (I, i) \<Longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   231
 (table_of (imethods i)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   232
           hiding (methd G Object)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   233
           under  (\<lambda> new old. accmodi old \<noteq> Private)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   234
           entails (\<lambda>new old. G\<turnstile>resTy new\<preceq>resTy old \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   235
                              is_static new = is_static old))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   236
apply (unfold wf_idecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   237
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   238
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   239
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   240
lemma wf_idecl_supD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   241
"\<lbrakk>wf_idecl G (I,i); J \<in> set (isuperIfs i)\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   242
 \<Longrightarrow> is_acc_iface G (pid I) J \<and> (J, I) \<notin> (subint1 G)^+"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   243
apply (unfold wf_idecl_def ws_idecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   244
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   245
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   246
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   247
section "well-formed class declarations"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   248
  (* well-formed class declaration, cf. 8.1, 8.1.2.1, 8.1.2.2, 8.1.3, 8.1.4 and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   249
   class method declaration, cf. 8.4.3.3, 8.4.6.1, 8.4.6.2, 8.4.6.3, 8.4.6.4 *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   250
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   251
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   252
A class declaration is wellformed if:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   253
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   254
\item there is no interface with the same name
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   255
\item all superinterfaces are accessible and for all methods implementing 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   256
      an interface method the result type widens to the result type of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   257
      the interface method, the method is not static and offers at least 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   258
      as much access 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   259
      (this actually means that the method has Public access, since all 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   260
      interface methods have public access)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   261
\item all field declarations are wellformed and the field names are unique
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   262
\item all method declarations are wellformed and the method names are unique
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   263
\item the initialization statement is welltyped
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   264
\item the classhierarchy is wellstructured
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   265
\item Unless the class is Object:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   266
      \begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   267
      \item the superclass is accessible
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   268
      \item for all methods overriding another method (of a superclass )the
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   269
            result type widens to the result type of the overridden method,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   270
            the access modifier of the new method provides at least as much
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   271
            access as the overwritten one.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   272
      \item for all methods hiding a method (of a superclass) the hidden 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   273
            method must be static and offer at least as much access rights.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   274
            Remark: In contrast to the Java Language Specification we don't
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   275
            restrict the result types of the method
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   276
            (as in case of overriding), because there seems to be no reason,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   277
            since there is no dynamic binding of static methods.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   278
            (cf. 8.4.6.3 vs. 15.12.1).
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   279
            Stricly speaking the restrictions on the access rights aren't 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   280
            necessary to, since the static type and the access rights 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   281
            together determine which method is to be called statically. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   282
            But if a class gains more then one static method with the 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   283
            same signature due to inheritance, it is confusing when the 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   284
            method selection depends on the access rights only: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   285
            e.g.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   286
              Class C declares static public method foo().
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   287
              Class D is subclass of C and declares static method foo()
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   288
              with default package access.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   289
              D.foo() ? if this call is in the same package as D then
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   290
                        foo of class D is called, otherwise foo of class C.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   291
      \end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   292
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   293
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   294
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   295
(* to Table *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   296
constdefs entails:: "('a,'b) table \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   297
                                 ("_ entails _" 20)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   298
"t entails P \<equiv> \<forall>k. \<forall> x \<in> t k: P x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   299
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   300
lemma entailsD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   301
 "\<lbrakk>t entails P; t k = Some x\<rbrakk> \<Longrightarrow> P x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   302
by (simp add: entails_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   303
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   304
lemma empty_entails[simp]: "empty entails P"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   305
by (simp add: entails_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   306
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   307
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   308
 wf_cdecl :: "prog \<Rightarrow> cdecl \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   309
"wf_cdecl G \<equiv> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   310
   \<lambda>(C,c).
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   311
      \<not>is_iface G C \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   312
      (\<forall>I\<in>set (superIfs c). is_acc_iface G (pid C) I \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   313
        (\<forall>s. \<forall> im \<in> imethds G I s.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   314
      	    (\<exists> cm \<in> methd  G C s: G\<turnstile>resTy cm\<preceq>resTy im \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   315
      	                             \<not> is_static cm \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   316
                                     accmodi im \<le> accmodi cm))) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   317
      (\<forall>f\<in>set (cfields c). wf_fdecl G (pid C) f) \<and> unique (cfields c) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   318
      (\<forall>m\<in>set (methods c). wf_mdecl G C m) \<and> unique (methods c) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   319
      \<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>(init c)\<Colon>\<surd> \<and> ws_cdecl G C (super c) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   320
      (C \<noteq> Object \<longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   321
            (is_acc_class G (pid C) (super c) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   322
            (table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   323
             entails (\<lambda> new. \<forall> old sig. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   324
                       (G,sig\<turnstile>new overrides\<^sub>S old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   325
                        \<longrightarrow> (G\<turnstile>resTy new\<preceq>resTy old \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   326
                             accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   327
      	                     \<not>is_static old)) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   328
                       (G,sig\<turnstile>new hides old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   329
                         \<longrightarrow> (accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   330
      	                      is_static old)))) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   331
            ))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   332
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   333
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   334
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   335
 wf_cdecl :: "prog \<Rightarrow> cdecl \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   336
"wf_cdecl G \<equiv> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   337
   \<lambda>(C,c).
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   338
      \<not>is_iface G C \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   339
      (\<forall>I\<in>set (superIfs c). is_acc_iface G (pid C) I \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   340
        (\<forall>s. \<forall> im \<in> imethds G I s.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   341
      	    (\<exists> cm \<in> methd  G C s: G\<turnstile>resTy (mthd cm)\<preceq>resTy (mthd im) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   342
      	                             \<not> is_static cm \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   343
                                     accmodi im \<le> accmodi cm))) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   344
      (\<forall>f\<in>set (cfields c). wf_fdecl G (pid C) f) \<and> unique (cfields c) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   345
      (\<forall>m\<in>set (methods c). wf_mdecl G C m) \<and> unique (methods c) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   346
      \<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>(init c)\<Colon>\<surd> \<and> ws_cdecl G C (super c) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   347
      (C \<noteq> Object \<longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   348
            (is_acc_class G (pid C) (super c) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   349
            (table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   350
              hiding methd G (super c)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   351
              under (\<lambda> new old. G\<turnstile>new overrides old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   352
              entails (\<lambda> new old. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   353
                           (G\<turnstile>resTy (mthd new)\<preceq>resTy (mthd old) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   354
                            accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   355
      	                   \<not> is_static old)))  \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   356
            (table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   357
              hiding methd G (super c)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   358
              under (\<lambda> new old. G\<turnstile>new hides old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   359
              entails (\<lambda> new old. is_static old \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   360
                                  accmodi old \<le> accmodi new))  \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   361
            (table_of (cfields c) hiding accfield G C (super c)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   362
              entails (\<lambda> newF oldF. accmodi oldF \<le> access newF))))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   363
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   364
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   365
lemma wf_cdecl_unique: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   366
"wf_cdecl G (C,c) \<Longrightarrow> unique (cfields c) \<and> unique (methods c)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   367
apply (unfold wf_cdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   368
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   369
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   370
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   371
lemma wf_cdecl_fdecl: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   372
"\<lbrakk>wf_cdecl G (C,c); f\<in>set (cfields c)\<rbrakk> \<Longrightarrow> wf_fdecl G (pid C) f"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   373
apply (unfold wf_cdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   374
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   375
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   376
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   377
lemma wf_cdecl_mdecl: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   378
"\<lbrakk>wf_cdecl G (C,c); m\<in>set (methods c)\<rbrakk> \<Longrightarrow> wf_mdecl G C m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   379
apply (unfold wf_cdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   380
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   381
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   382
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   383
lemma wf_cdecl_impD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   384
"\<lbrakk>wf_cdecl G (C,c); I\<in>set (superIfs c)\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   385
\<Longrightarrow> is_acc_iface G (pid C) I \<and>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   386
    (\<forall>s. \<forall>im \<in> imethds G I s.  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   387
        (\<exists>cm \<in> methd G C s: G\<turnstile>resTy cm\<preceq>resTy im \<and> \<not>is_static cm \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   388
                                   accmodi im \<le> accmodi cm))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   389
apply (unfold wf_cdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   390
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   391
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   392
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   393
lemma wf_cdecl_supD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   394
"\<lbrakk>wf_cdecl G (C,c); C \<noteq> Object\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   395
  is_acc_class G (pid C) (super c) \<and> (super c,C) \<notin> (subcls1 G)^+ \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   396
   (table_of (map (\<lambda> (s,m). (s,C,m)) (methods c)) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   397
    entails (\<lambda> new. \<forall> old sig. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   398
                 (G,sig\<turnstile>new overrides\<^sub>S old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   399
                  \<longrightarrow> (G\<turnstile>resTy new\<preceq>resTy old \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   400
                       accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   401
                       \<not>is_static old)) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   402
                 (G,sig\<turnstile>new hides old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   403
                   \<longrightarrow> (accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   404
                        is_static old))))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   405
apply (unfold wf_cdecl_def ws_cdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   406
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   407
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   408
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   409
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   410
lemma wf_cdecl_overrides_SomeD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   411
"\<lbrakk>wf_cdecl G (C,c); C \<noteq> Object; table_of (methods c) sig = Some newM;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   412
  G,sig\<turnstile>(C,newM) overrides\<^sub>S old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   413
\<rbrakk> \<Longrightarrow>  G\<turnstile>resTy newM\<preceq>resTy old \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   414
       accmodi old \<le> accmodi newM \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   415
       \<not> is_static old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   416
apply (drule (1) wf_cdecl_supD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   417
apply (clarify)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   418
apply (drule entailsD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   419
apply   (blast intro: table_of_map_SomeI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   420
apply (drule_tac x="old" in spec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   421
apply (auto dest: overrides_eq_sigD simp add: msig_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   422
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   423
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   424
lemma wf_cdecl_hides_SomeD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   425
"\<lbrakk>wf_cdecl G (C,c); C \<noteq> Object; table_of (methods c) sig = Some newM;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   426
  G,sig\<turnstile>(C,newM) hides old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   427
\<rbrakk> \<Longrightarrow>  accmodi old \<le> access newM \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   428
       is_static old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   429
apply (drule (1) wf_cdecl_supD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   430
apply (clarify)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   431
apply (drule entailsD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   432
apply   (blast intro: table_of_map_SomeI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   433
apply (drule_tac x="old" in spec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   434
apply (auto dest: hides_eq_sigD simp add: msig_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   435
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   436
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   437
lemma wf_cdecl_wt_init: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   438
 "wf_cdecl G (C, c) \<Longrightarrow> \<lparr>prg=G,cls=C,lcl=empty\<rparr>\<turnstile>init c\<Colon>\<surd>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   439
apply (unfold wf_cdecl_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   440
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   441
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   442
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   443
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   444
section "well-formed programs"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   445
  (* well-formed program, cf. 8.1, 9.1 *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   446
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   447
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   448
A program declaration is wellformed if:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   449
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   450
\item the class ObjectC of Object is defined
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   451
\item every method of has an access modifier distinct from Package. This is
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   452
      necessary since every interface automatically inherits from Object.  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   453
      We must know, that every time a Object method is "overriden" by an 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   454
      interface method this is also overriden by the class implementing the
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   455
      the interface (see @{text "implement_dynmethd and class_mheadsD"})
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   456
\item all standard Exceptions are defined
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   457
\item all defined interfaces are wellformed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   458
\item all defined classes are wellformed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   459
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   460
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   461
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   462
  wf_prog  :: "prog \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   463
 "wf_prog G \<equiv> let is = ifaces G; cs = classes G in
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   464
	         ObjectC \<in> set cs \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   465
                (\<forall> m\<in>set Object_mdecls. accmodi m \<noteq> Package) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   466
                (\<forall>xn. SXcptC xn \<in> set cs) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   467
		(\<forall>i\<in>set is. wf_idecl G i) \<and> unique is \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   468
		(\<forall>c\<in>set cs. wf_cdecl G c) \<and> unique cs"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   469
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   470
lemma wf_prog_idecl: "\<lbrakk>iface G I = Some i; wf_prog G\<rbrakk> \<Longrightarrow> wf_idecl G (I,i)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   471
apply (unfold wf_prog_def Let_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   472
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   473
apply (fast dest: map_of_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   474
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   475
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   476
lemma wf_prog_cdecl: "\<lbrakk>class G C = Some c; wf_prog G\<rbrakk> \<Longrightarrow> wf_cdecl G (C,c)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   477
apply (unfold wf_prog_def Let_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   478
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   479
apply (fast dest: map_of_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   480
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   481
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   482
lemma wf_prog_Object_mdecls:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   483
"wf_prog G \<Longrightarrow> (\<forall> m\<in>set Object_mdecls. accmodi m \<noteq> Package)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   484
apply (unfold wf_prog_def Let_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   485
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   486
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   487
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   488
lemma wf_prog_acc_superD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   489
 "\<lbrakk>wf_prog G; class G C = Some c; C \<noteq> Object \<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   490
  \<Longrightarrow> is_acc_class G (pid C) (super c)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   491
by (auto dest: wf_prog_cdecl wf_cdecl_supD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   492
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   493
lemma wf_ws_prog [elim!,simp]: "wf_prog G \<Longrightarrow> ws_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   494
apply (unfold wf_prog_def Let_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   495
apply (rule ws_progI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   496
apply  (simp_all (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   497
apply  (auto simp add: is_acc_class_def is_acc_iface_def 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   498
             dest!: wf_idecl_supD wf_cdecl_supD )+
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   499
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   500
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   501
lemma class_Object [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   502
"wf_prog G \<Longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   503
  class G Object = Some \<lparr>access=Public,cfields=[],methods=Object_mdecls,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   504
                                  init=Skip,super=arbitrary,superIfs=[]\<rparr>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   505
apply (unfold wf_prog_def Let_def ObjectC_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   506
apply (fast dest!: map_of_SomeI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   507
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   508
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   509
lemma methd_Object[simp]: "wf_prog G \<Longrightarrow> methd G Object =  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   510
  table_of (map (\<lambda>(s,m). (s, Object, m)) Object_mdecls)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   511
apply (subst methd_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   512
apply (auto simp add: Let_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   513
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   514
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   515
lemma wf_prog_Object_methd:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   516
"\<lbrakk>wf_prog G; methd G Object sig = Some m\<rbrakk> \<Longrightarrow> accmodi m \<noteq> Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   517
by (auto dest!: wf_prog_Object_mdecls) (auto dest!: map_of_SomeD) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   518
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   519
lemma wf_prog_Object_is_public[intro]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   520
 "wf_prog G \<Longrightarrow> is_public G Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   521
by (auto simp add: is_public_def dest: class_Object)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   522
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   523
lemma class_SXcpt [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   524
"wf_prog G \<Longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   525
  class G (SXcpt xn) = Some \<lparr>access=Public,cfields=[],methods=SXcpt_mdecls,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   526
                                   init=Skip,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   527
                                   super=if xn = Throwable then Object 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   528
                                                           else SXcpt Throwable,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   529
                                   superIfs=[]\<rparr>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   530
apply (unfold wf_prog_def Let_def SXcptC_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   531
apply (fast dest!: map_of_SomeI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   532
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   533
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   534
lemma wf_ObjectC [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   535
	"wf_cdecl G ObjectC = (\<not>is_iface G Object \<and> Ball (set Object_mdecls)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   536
  (wf_mdecl G Object) \<and> unique Object_mdecls)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   537
apply (unfold wf_cdecl_def ws_cdecl_def ObjectC_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   538
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   539
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   540
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   541
lemma Object_is_class [simp,elim!]: "wf_prog G \<Longrightarrow> is_class G Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   542
apply (simp (no_asm_simp))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   543
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   544
 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   545
lemma Object_is_acc_class [simp,elim!]: "wf_prog G \<Longrightarrow> is_acc_class G S Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   546
apply (simp (no_asm_simp) add: is_acc_class_def is_public_def
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   547
                               accessible_in_RefT_simp)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   548
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   549
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   550
lemma SXcpt_is_class [simp,elim!]: "wf_prog G \<Longrightarrow> is_class G (SXcpt xn)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   551
apply (simp (no_asm_simp))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   552
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   553
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   554
lemma SXcpt_is_acc_class [simp,elim!]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   555
"wf_prog G \<Longrightarrow> is_acc_class G S (SXcpt xn)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   556
apply (simp (no_asm_simp) add: is_acc_class_def is_public_def
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   557
                               accessible_in_RefT_simp)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   558
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   559
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   560
lemma fields_Object [simp]: "wf_prog G \<Longrightarrow> DeclConcepts.fields G Object = []"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   561
by (force intro: fields_emptyI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   562
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   563
lemma accfield_Object [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   564
 "wf_prog G \<Longrightarrow> accfield G S Object = empty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   565
apply (unfold accfield_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   566
apply (simp (no_asm_simp) add: Let_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   567
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   568
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   569
lemma fields_Throwable [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   570
 "wf_prog G \<Longrightarrow> DeclConcepts.fields G (SXcpt Throwable) = []"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   571
by (force intro: fields_emptyI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   572
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   573
lemma fields_SXcpt [simp]: "wf_prog G \<Longrightarrow> DeclConcepts.fields G (SXcpt xn) = []"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   574
apply (case_tac "xn = Throwable")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   575
apply  (simp (no_asm_simp))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   576
by (force intro: fields_emptyI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   577
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   578
lemmas widen_trans = ws_widen_trans [OF _ _ wf_ws_prog, elim]
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   579
lemma widen_trans2 [elim]: "\<lbrakk>G\<turnstile>U\<preceq>T; G\<turnstile>S\<preceq>U; wf_prog G\<rbrakk> \<Longrightarrow> G\<turnstile>S\<preceq>T"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   580
apply (erule (2) widen_trans)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   581
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   582
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   583
lemma Xcpt_subcls_Throwable [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   584
"wf_prog G \<Longrightarrow> G\<turnstile>SXcpt xn\<preceq>\<^sub>C SXcpt Throwable"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   585
apply (rule SXcpt_subcls_Throwable_lemma)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   586
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   587
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   588
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   589
lemma unique_fields: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   590
 "\<lbrakk>is_class G C; wf_prog G\<rbrakk> \<Longrightarrow> unique (DeclConcepts.fields G C)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   591
apply (erule ws_unique_fields)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   592
apply  (erule wf_ws_prog)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   593
apply (erule (1) wf_prog_cdecl [THEN wf_cdecl_unique [THEN conjunct1]])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   594
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   595
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   596
lemma fields_mono: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   597
"\<lbrakk>table_of (DeclConcepts.fields G C) fn = Some f; G\<turnstile>D\<preceq>\<^sub>C C; 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   598
  is_class G D; wf_prog G\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   599
   \<Longrightarrow> table_of (DeclConcepts.fields G D) fn = Some f"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   600
apply (rule map_of_SomeI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   601
apply  (erule (1) unique_fields)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   602
apply (erule (1) map_of_SomeD [THEN fields_mono_lemma])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   603
apply (erule wf_ws_prog)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   604
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   605
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   606
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   607
lemma fields_is_type [elim]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   608
"\<lbrakk>table_of (DeclConcepts.fields G C) m = Some f; wf_prog G; is_class G C\<rbrakk> \<Longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   609
      is_type G (type f)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   610
apply (frule wf_ws_prog)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   611
apply (force dest: fields_declC [THEN conjunct1] 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   612
                   wf_prog_cdecl [THEN wf_cdecl_fdecl]
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   613
             simp add: wf_fdecl_def2 is_acc_type_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   614
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   615
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   616
lemma imethds_wf_mhead [rule_format (no_asm)]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   617
"\<lbrakk>m \<in> imethds G I sig; wf_prog G; is_iface G I\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   618
  wf_mhead G (pid (decliface m)) sig (mthd m) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   619
  \<not> is_static m \<and> accmodi m = Public"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   620
apply (frule wf_ws_prog)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   621
apply (drule (2) imethds_declI [THEN conjunct1])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   622
apply clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   623
apply (frule_tac I="(decliface m)" in wf_prog_idecl,assumption)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   624
apply (drule wf_idecl_mhead)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   625
apply (erule map_of_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   626
apply (cases m, simp)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   627
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   628
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   629
lemma methd_wf_mdecl: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   630
 "\<lbrakk>methd G C sig = Some m; wf_prog G; class G C = Some y\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   631
  G\<turnstile>C\<preceq>\<^sub>C (declclass m) \<and> is_class G (declclass m) \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   632
  wf_mdecl G (declclass m) (sig,(mthd m))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   633
apply (frule wf_ws_prog)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   634
apply (drule (1) methd_declC)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   635
apply  fast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   636
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   637
apply (frule (1) wf_prog_cdecl, erule wf_cdecl_mdecl, erule map_of_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   638
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   639
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   640
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   641
This lemma doesn't hold!
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   642
lemma methd_rT_is_acc_type: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   643
"\<lbrakk>wf_prog G;methd G C C sig = Some (D,m);
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   644
    class G C = Some y\<rbrakk>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   645
\<Longrightarrow> is_acc_type G (pid C) (resTy m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   646
The result Type is only visible in the scope of defining class D 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   647
"is_vis_type G (pid D) (resTy m)" but not necessarily in scope of class C!
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   648
(The same is true for the type of pramaters of a method)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   649
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   650
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   651
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   652
lemma methd_rT_is_type: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   653
"\<lbrakk>wf_prog G;methd G C sig = Some m;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   654
    class G C = Some y\<rbrakk>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   655
\<Longrightarrow> is_type G (resTy m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   656
apply (drule (2) methd_wf_mdecl)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   657
apply clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   658
apply (drule wf_mdeclD1)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   659
apply clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   660
apply (drule rT_is_acc_type)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   661
apply (cases m, simp add: is_acc_type_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   662
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   663
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   664
lemma accmethd_rT_is_type:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   665
"\<lbrakk>wf_prog G;accmethd G S C sig = Some m;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   666
    class G C = Some y\<rbrakk>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   667
\<Longrightarrow> is_type G (resTy m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   668
by (auto simp add: accmethd_def  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   669
         intro: methd_rT_is_type)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   670
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   671
lemma methd_Object_SomeD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   672
"\<lbrakk>wf_prog G;methd G Object sig = Some m\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   673
 \<Longrightarrow> declclass m = Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   674
by (auto dest: class_Object simp add: methd_rec )
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   675
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   676
lemma wf_imethdsD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   677
 "\<lbrakk>im \<in> imethds G I sig;wf_prog G; is_iface G I\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   678
 \<Longrightarrow> \<not>is_static im \<and> accmodi im = Public"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   679
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   680
  assume asm: "wf_prog G" "is_iface G I" "im \<in> imethds G I sig"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   681
  have "wf_prog G \<longrightarrow> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   682
         (\<forall> i im. iface G I = Some i \<longrightarrow> im \<in> imethds G I sig
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   683
                  \<longrightarrow> \<not>is_static im \<and> accmodi im = Public)" (is "?P G I")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   684
  proof (rule iface_rec.induct,intro allI impI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   685
    fix G I i im
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   686
    assume hyp: "\<forall> J i. J \<in> set (isuperIfs i) \<and> ws_prog G \<and> iface G I = Some i
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   687
                 \<longrightarrow> ?P G J"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   688
    assume wf: "wf_prog G" and if_I: "iface G I = Some i" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   689
           im: "im \<in> imethds G I sig" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   690
    show "\<not>is_static im \<and> accmodi im = Public" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   691
    proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   692
      let ?inherited = "Un_tables (imethds G ` set (isuperIfs i))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   693
      let ?new = "(o2s \<circ> table_of (map (\<lambda>(s, mh). (s, I, mh)) (imethods i)))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   694
      from if_I wf im have imethds:"im \<in> (?inherited \<oplus>\<oplus> ?new) sig"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   695
	by (simp add: imethds_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   696
      from wf if_I have 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   697
	wf_supI: "\<forall> J. J \<in> set (isuperIfs i) \<longrightarrow> (\<exists> j. iface G J = Some j)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   698
	by (blast dest: wf_prog_idecl wf_idecl_supD is_acc_ifaceD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   699
      from wf if_I have
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   700
	"\<forall> im \<in> set (imethods i). \<not> is_static im \<and> accmodi im = Public"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   701
	by (auto dest!: wf_prog_idecl wf_idecl_mhead)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   702
      then have new_ok: "\<forall> im. table_of (imethods i) sig = Some im 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   703
                         \<longrightarrow>  \<not> is_static im \<and> accmodi im = Public"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   704
	by (auto dest!: table_of_Some_in_set)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   705
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   706
	proof (cases "?new sig = {}")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   707
	  case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   708
	  from True wf wf_supI if_I imethds hyp 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   709
	  show ?thesis by (auto simp del:  split_paired_All)  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   710
	next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   711
	  case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   712
	  from False wf wf_supI if_I imethds new_ok hyp 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   713
	  show ?thesis by (auto dest: wf_idecl_hidings hidings_entailsD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   714
	qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   715
      qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   716
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   717
  with asm show ?thesis by (auto simp del: split_paired_All)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   718
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   719
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   720
lemma wf_prog_hidesD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   721
 (assumes hides: "G \<turnstile>new hides old" and wf: "wf_prog G") 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   722
   "accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   723
    is_static old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   724
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   725
  from hides 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   726
  obtain c where 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   727
    clsNew: "class G (declclass new) = Some c" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   728
    neqObj: "declclass new \<noteq> Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   729
    by (auto dest: hidesD declared_in_classD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   730
  with hides obtain newM oldM where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   731
    newM: "table_of (methods c) (msig new) = Some newM" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   732
     new: "new = (declclass new,(msig new),newM)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   733
     old: "old = (declclass old,(msig old),oldM)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   734
          "msig new = msig old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   735
    by (cases new,cases old) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   736
       (auto dest: hidesD 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   737
         simp add: cdeclaredmethd_def declared_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   738
  with hides 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   739
  have hides':
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   740
        "G,(msig new)\<turnstile>(declclass new,newM) hides (declclass old,oldM)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   741
    by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   742
  from clsNew wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   743
  have "wf_cdecl G (declclass new,c)" by (blast intro: wf_prog_cdecl)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   744
  note wf_cdecl_hides_SomeD [OF this neqObj newM hides']
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   745
  with new old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   746
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   747
    by (cases new, cases old) auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   748
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   749
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   750
text {* Compare this lemma about static  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   751
overriding @{term "G \<turnstile>new overrides\<^sub>S old"} with the definition of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   752
dynamic overriding @{term "G \<turnstile>new overrides old"}. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   753
Conforming result types and restrictions on the access modifiers of the old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   754
and the new method are not part of the predicate for static overriding. But
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   755
they are enshured in a wellfromed program.  Dynamic overriding has 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   756
no restrictions on the access modifiers but enforces confrom result types 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   757
as precondition. But with some efford we can guarantee the access modifier
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   758
restriction for dynamic overriding, too. See lemma 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   759
@{text wf_prog_dyn_override_prop}.
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   760
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   761
lemma wf_prog_stat_overridesD:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   762
 (assumes stat_override: "G \<turnstile>new overrides\<^sub>S old" and wf: "wf_prog G") 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   763
   "G\<turnstile>resTy new\<preceq>resTy old \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   764
    accmodi old \<le> accmodi new \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   765
    \<not> is_static old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   766
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   767
  from stat_override 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   768
  obtain c where 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   769
    clsNew: "class G (declclass new) = Some c" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   770
    neqObj: "declclass new \<noteq> Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   771
    by (auto dest: stat_overrides_commonD declared_in_classD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   772
  with stat_override obtain newM oldM where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   773
    newM: "table_of (methods c) (msig new) = Some newM" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   774
     new: "new = (declclass new,(msig new),newM)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   775
     old: "old = (declclass old,(msig old),oldM)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   776
          "msig new = msig old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   777
    by (cases new,cases old) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   778
       (auto dest: stat_overrides_commonD 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   779
         simp add: cdeclaredmethd_def declared_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   780
  with stat_override 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   781
  have stat_override':
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   782
        "G,(msig new)\<turnstile>(declclass new,newM) overrides\<^sub>S (declclass old,oldM)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   783
    by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   784
  from clsNew wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   785
  have "wf_cdecl G (declclass new,c)" by (blast intro: wf_prog_cdecl)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   786
  note wf_cdecl_overrides_SomeD [OF this neqObj newM stat_override']
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   787
  with new old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   788
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   789
    by (cases new, cases old) auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   790
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   791
    
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   792
lemma static_to_dynamic_overriding: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   793
  (assumes stat_override: "G\<turnstile>new overrides\<^sub>S old" and wf : "wf_prog G")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   794
   "G\<turnstile>new overrides old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   795
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   796
  from stat_override 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   797
  show ?thesis (is "?Overrides new old")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   798
  proof (induct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   799
    case (Direct new old superNew)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   800
    then have stat_override:"G\<turnstile>new overrides\<^sub>S old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   801
      by (rule stat_overridesR.Direct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   802
    from stat_override wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   803
    have resTy_widen: "G\<turnstile>resTy new\<preceq>resTy old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   804
      not_static_old: "\<not> is_static old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   805
      by (auto dest: wf_prog_stat_overridesD)  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   806
    have not_private_new: "accmodi new \<noteq> Private"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   807
    proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   808
      from stat_override 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   809
      have "accmodi old \<noteq> Private"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   810
	by (rule no_Private_stat_override)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   811
      moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   812
      from stat_override wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   813
      have "accmodi old \<le> accmodi new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   814
	by (auto dest: wf_prog_stat_overridesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   815
      ultimately
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   816
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   817
	by (auto dest: acc_modi_bottom)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   818
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   819
    with Direct resTy_widen not_static_old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   820
    show "?Overrides new old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   821
      by (auto intro: overridesR.Direct) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   822
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   823
    case (Indirect inter new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   824
    then show "?Overrides new old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   825
      by (blast intro: overridesR.Indirect) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   826
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   827
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   828
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   829
lemma non_Package_instance_method_inheritance:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   830
(assumes old_inheritable: "G\<turnstile>Method old inheritable_in (pid C)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   831
             accmodi_old: "accmodi old \<noteq> Package" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   832
         instance_method: "\<not> is_static old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   833
                  subcls: "G\<turnstile>C \<prec>\<^sub>C declclass old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   834
            old_declared: "G\<turnstile>Method old declared_in (declclass old)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   835
                      wf: "wf_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   836
) "G\<turnstile>Method old member_of C \<or>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   837
   (\<exists> new. G\<turnstile> new overrides\<^sub>S old \<and>  G\<turnstile>Method new member_of C)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   838
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   839
  from wf have ws: "ws_prog G" by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   840
  from old_declared have iscls_declC_old: "is_class G (declclass old)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   841
    by (auto simp add: declared_in_def cdeclaredmethd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   842
  from subcls have  iscls_C: "is_class G C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   843
    by (blast dest:  subcls_is_class)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   844
  from iscls_C ws old_inheritable subcls 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   845
  show ?thesis (is "?P C old")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   846
  proof (induct rule: ws_class_induct')
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   847
    case Object
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   848
    assume "G\<turnstile>Object\<prec>\<^sub>C declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   849
    then show "?P Object old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   850
      by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   851
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   852
    case (Subcls C c)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   853
    assume cls_C: "class G C = Some c" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   854
       neq_C_Obj: "C \<noteq> Object" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   855
             hyp: "\<lbrakk>G \<turnstile>Method old inheritable_in pid (super c); 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   856
                   G\<turnstile>super c\<prec>\<^sub>C declclass old\<rbrakk> \<Longrightarrow> ?P (super c) old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   857
     inheritable: "G \<turnstile>Method old inheritable_in pid C" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   858
         subclsC: "G\<turnstile>C\<prec>\<^sub>C declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   859
    from cls_C neq_C_Obj  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   860
    have super: "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 super c" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   861
      by (rule subcls1I)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   862
    from wf cls_C neq_C_Obj
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   863
    have accessible_super: "G\<turnstile>(Class (super c)) accessible_in (pid C)" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   864
      by (auto dest: wf_prog_cdecl wf_cdecl_supD is_acc_classD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   865
    {
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   866
      fix old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   867
      assume    member_super: "G\<turnstile>Method old member_of (super c)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   868
      assume     inheritable: "G \<turnstile>Method old inheritable_in pid C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   869
      assume instance_method: "\<not> is_static old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   870
      from member_super
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   871
      have old_declared: "G\<turnstile>Method old declared_in (declclass old)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   872
       by (cases old) (auto dest: member_of_declC)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   873
      have "?P C old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   874
      proof (cases "G\<turnstile>mid (msig old) undeclared_in C")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   875
	case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   876
	with inheritable super accessible_super member_super
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   877
	have "G\<turnstile>Method old member_of C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   878
	  by (cases old) (auto intro: members.Inherited)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   879
	then show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   880
	  by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   881
      next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   882
	case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   883
	then obtain new_member where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   884
	     "G\<turnstile>new_member declared_in C" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   885
             "mid (msig old) = memberid new_member"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   886
          by (auto dest: not_undeclared_declared)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   887
	then obtain new where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   888
	          new: "G\<turnstile>Method new declared_in C" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   889
               eq_sig: "msig old = msig new" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   890
	    declC_new: "declclass new = C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   891
	  by (cases new_member) auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   892
	then have member_new: "G\<turnstile>Method new member_of C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   893
	  by (cases new) (auto intro: members.Immediate)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   894
	from declC_new super member_super
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   895
	have subcls_new_old: "G\<turnstile>declclass new \<prec>\<^sub>C declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   896
	  by (auto dest!: member_of_subclseq_declC
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   897
	            dest: r_into_trancl intro: trancl_rtrancl_trancl)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   898
	show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   899
	proof (cases "is_static new")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   900
	  case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   901
	  with eq_sig declC_new new old_declared inheritable
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   902
	       super member_super subcls_new_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   903
	  have "G\<turnstile>new overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   904
	    by (auto intro!: stat_overridesR.Direct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   905
	  with member_new show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   906
	    by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   907
	next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   908
	  case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   909
	  with eq_sig declC_new subcls_new_old new old_declared inheritable
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   910
	  have "G\<turnstile>new hides old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   911
	    by (auto intro: hidesI)    
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   912
	  with wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   913
	  have "is_static old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   914
	    by (blast dest: wf_prog_hidesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   915
	  with instance_method
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   916
	  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   917
	    by (contradiction)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   918
	qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   919
      qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   920
    } note hyp_member_super = this
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   921
    from subclsC cls_C 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   922
    have "G\<turnstile>(super c)\<preceq>\<^sub>C declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   923
      by (rule subcls_superD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   924
    then
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   925
    show "?P C old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   926
    proof (cases rule: subclseq_cases) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   927
      case Eq
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   928
      assume "super c = declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   929
      with old_declared 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   930
      have "G\<turnstile>Method old member_of (super c)" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   931
	by (cases old) (auto intro: members.Immediate)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   932
      with inheritable instance_method 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   933
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   934
	by (blast dest: hyp_member_super)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   935
    next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   936
      case Subcls
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   937
      assume "G\<turnstile>super c\<prec>\<^sub>C declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   938
      moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   939
      from inheritable accmodi_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   940
      have "G \<turnstile>Method old inheritable_in pid (super c)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   941
	by (cases "accmodi old") (auto simp add: inheritable_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   942
      ultimately
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   943
      have "?P (super c) old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   944
	by (blast dest: hyp)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   945
      then show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   946
      proof
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   947
	assume "G \<turnstile>Method old member_of super c"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   948
	with inheritable instance_method
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   949
	show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   950
	  by (blast dest: hyp_member_super)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   951
      next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   952
	assume "\<exists>new. G \<turnstile> new overrides\<^sub>S old \<and> G \<turnstile>Method new member_of super c"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   953
	then obtain super_new where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   954
	  super_new_override:  "G \<turnstile> super_new overrides\<^sub>S old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   955
            super_new_member:  "G \<turnstile>Method super_new member_of super c"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   956
	  by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   957
	from super_new_override wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   958
	have "accmodi old \<le> accmodi super_new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   959
	  by (auto dest: wf_prog_stat_overridesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   960
	with inheritable accmodi_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   961
	have "G \<turnstile>Method super_new inheritable_in pid C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   962
	  by (auto simp add: inheritable_in_def 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   963
	              split: acc_modi.splits
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   964
                       dest: acc_modi_le_Dests)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   965
	moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   966
	from super_new_override 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   967
	have "\<not> is_static super_new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   968
	  by (auto dest: stat_overrides_commonD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   969
	moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   970
	note super_new_member
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   971
	ultimately have "?P C super_new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   972
	  by (auto dest: hyp_member_super)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   973
	then show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   974
	proof 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   975
	  assume "G \<turnstile>Method super_new member_of C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   976
	  with super_new_override
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   977
	  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   978
	    by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   979
	next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   980
	  assume "\<exists>new. G \<turnstile> new overrides\<^sub>S super_new \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   981
                  G \<turnstile>Method new member_of C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   982
	  with super_new_override show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   983
	    by (blast intro: stat_overridesR.Indirect) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   984
	qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   985
      qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   986
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   987
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   988
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   989
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   990
lemma non_Package_instance_method_inheritance_cases [consumes 6,
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   991
         case_names Inheritance Overriding]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   992
(assumes old_inheritable: "G\<turnstile>Method old inheritable_in (pid C)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   993
             accmodi_old: "accmodi old \<noteq> Package" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   994
         instance_method: "\<not> is_static old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   995
                  subcls: "G\<turnstile>C \<prec>\<^sub>C declclass old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   996
            old_declared: "G\<turnstile>Method old declared_in (declclass old)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   997
                      wf: "wf_prog G" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   998
             inheritance: "G\<turnstile>Method old member_of C \<Longrightarrow> P" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   999
             overriding:  "\<And> new. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1000
                           \<lbrakk>G\<turnstile> new overrides\<^sub>S old;G\<turnstile>Method new member_of C\<rbrakk>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1001
                           \<Longrightarrow> P"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1002
) "P"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1003
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1004
  from old_inheritable accmodi_old instance_method subcls old_declared wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1005
       inheritance overriding
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1006
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1007
    by (auto dest: non_Package_instance_method_inheritance)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1008
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1009
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1010
lemma dynamic_to_static_overriding:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1011
(assumes dyn_override: "G\<turnstile> new overrides old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1012
          accmodi_old: "accmodi old \<noteq> Package" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1013
                   wf: "wf_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1014
) "G\<turnstile> new overrides\<^sub>S old"  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1015
proof - 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1016
  from dyn_override accmodi_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1017
  show ?thesis (is "?Overrides new old")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1018
  proof (induct rule: overridesR.induct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1019
    case (Direct new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1020
    assume   new_declared: "G\<turnstile>Method new declared_in declclass new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1021
    assume eq_sig_new_old: "msig new = msig old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1022
    assume subcls_new_old: "G\<turnstile>declclass new \<prec>\<^sub>C declclass old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1023
    assume "G \<turnstile>Method old inheritable_in pid (declclass new)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1024
           "accmodi old \<noteq> Package" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1025
           "\<not> is_static old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1026
           "G\<turnstile>declclass new\<prec>\<^sub>C declclass old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1027
           "G\<turnstile>Method old declared_in declclass old" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1028
    from this wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1029
    show "?Overrides new old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1030
    proof (cases rule: non_Package_instance_method_inheritance_cases)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1031
      case Inheritance
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1032
      assume "G \<turnstile>Method old member_of declclass new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1033
      then have "G\<turnstile>mid (msig old) undeclared_in declclass new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1034
      proof cases
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1035
	case Immediate 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1036
	with subcls_new_old wf show ?thesis 	
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1037
	  by (auto dest: subcls_irrefl)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1038
      next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1039
	case Inherited
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1040
	then show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1041
	  by (cases old) auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1042
      qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1043
      with eq_sig_new_old new_declared
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1044
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1045
	by (cases old,cases new) (auto dest!: declared_not_undeclared)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1046
    next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1047
      case (Overriding new') 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1048
      assume stat_override_new': "G \<turnstile> new' overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1049
      then have "msig new' = msig old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1050
	by (auto dest: stat_overrides_commonD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1051
      with eq_sig_new_old have eq_sig_new_new': "msig new=msig new'"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1052
	by simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1053
      assume "G \<turnstile>Method new' member_of declclass new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1054
      then show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1055
      proof (cases)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1056
	case Immediate
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1057
	then have declC_new: "declclass new' = declclass new" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1058
	  by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1059
	from Immediate 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1060
	have "G\<turnstile>Method new' declared_in declclass new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1061
	  by (cases new') auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1062
	with new_declared eq_sig_new_new' declC_new 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1063
	have "new=new'"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1064
	  by (cases new, cases new') (auto dest: unique_declared_in) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1065
	with stat_override_new'
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1066
	show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1067
	  by simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1068
      next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1069
	case Inherited
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1070
	then have "G\<turnstile>mid (msig new') undeclared_in declclass new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1071
	  by (cases new') (auto)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1072
	with eq_sig_new_new' new_declared
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1073
	show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1074
	  by (cases new,cases new') (auto dest!: declared_not_undeclared)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1075
      qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1076
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1077
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1078
    case (Indirect inter new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1079
    assume accmodi_old: "accmodi old \<noteq> Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1080
    assume "accmodi old \<noteq> Package \<Longrightarrow> G \<turnstile> inter overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1081
    with accmodi_old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1082
    have stat_override_inter_old: "G \<turnstile> inter overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1083
      by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1084
    moreover 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1085
    assume hyp_inter: "accmodi inter \<noteq> Package \<Longrightarrow> G \<turnstile> new overrides\<^sub>S inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1086
    moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1087
    have "accmodi inter \<noteq> Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1088
    proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1089
      from stat_override_inter_old wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1090
      have "accmodi old \<le> accmodi inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1091
	by (auto dest: wf_prog_stat_overridesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1092
      with stat_override_inter_old accmodi_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1093
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1094
	by (auto dest!: no_Private_stat_override
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1095
                 split: acc_modi.splits 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1096
	         dest: acc_modi_le_Dests)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1097
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1098
    ultimately show "?Overrides new old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1099
      by (blast intro: stat_overridesR.Indirect)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1100
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1101
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1102
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1103
lemma wf_prog_dyn_override_prop:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1104
 (assumes dyn_override: "G \<turnstile> new overrides old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1105
                    wf: "wf_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1106
 ) "accmodi old \<le> accmodi new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1107
proof (cases "accmodi old = Package")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1108
  case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1109
  note old_Package = this
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1110
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1111
  proof (cases "accmodi old \<le> accmodi new")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1112
    case True then show ?thesis .
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1113
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1114
    case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1115
    with old_Package 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1116
    have "accmodi new = Private"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1117
      by (cases "accmodi new") (auto simp add: le_acc_def less_acc_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1118
    with dyn_override 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1119
    show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1120
      by (auto dest: overrides_commonD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1121
  qed    
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1122
next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1123
  case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1124
  with dyn_override wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1125
  have "G \<turnstile> new overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1126
    by (blast intro: dynamic_to_static_overriding)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1127
  with wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1128
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1129
   by (blast dest: wf_prog_stat_overridesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1130
qed 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1131
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1132
lemma overrides_Package_old: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1133
(assumes dyn_override: "G \<turnstile> new overrides old" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1134
          accmodi_new: "accmodi new = Package" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1135
                   wf: "wf_prog G "
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1136
) "accmodi old = Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1137
proof (cases "accmodi old")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1138
  case Private
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1139
  with dyn_override show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1140
    by (simp add: no_Private_override)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1141
next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1142
  case Package
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1143
  then show ?thesis .
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1144
next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1145
  case Protected
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1146
  with dyn_override wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1147
  have "G \<turnstile> new overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1148
    by (auto intro: dynamic_to_static_overriding)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1149
  with wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1150
  have "accmodi old \<le> accmodi new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1151
    by (auto dest: wf_prog_stat_overridesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1152
  with Protected accmodi_new
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1153
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1154
    by (simp add: less_acc_def le_acc_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1155
next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1156
  case Public
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1157
  with dyn_override wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1158
  have "G \<turnstile> new overrides\<^sub>S old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1159
    by (auto intro: dynamic_to_static_overriding)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1160
  with wf 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1161
  have "accmodi old \<le> accmodi new"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1162
    by (auto dest: wf_prog_stat_overridesD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1163
  with Public accmodi_new
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1164
  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1165
    by (simp add: less_acc_def le_acc_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1166
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1167
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1168
lemma dyn_override_Package:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1169
 (assumes dyn_override: "G \<turnstile> new overrides old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1170
          accmodi_old: "accmodi old = Package" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1171
          accmodi_new: "accmodi new = Package" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1172
                    wf: "wf_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1173
 ) "pid (declclass old) = pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1174
proof - 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1175
  from dyn_override accmodi_old accmodi_new
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1176
  show ?thesis (is "?EqPid old new")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1177
  proof (induct rule: overridesR.induct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1178
    case (Direct new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1179
    assume "accmodi old = Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1180
           "G \<turnstile>Method old inheritable_in pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1181
    then show "pid (declclass old) =  pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1182
      by (auto simp add: inheritable_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1183
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1184
    case (Indirect inter new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1185
    assume accmodi_old: "accmodi old = Package" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1186
           accmodi_new: "accmodi new = Package" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1187
    assume "G \<turnstile> new overrides inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1188
    with accmodi_new wf
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1189
    have "accmodi inter = Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1190
      by  (auto intro: overrides_Package_old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1191
    with Indirect
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1192
    show "pid (declclass old) =  pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1193
      by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1194
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1195
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1196
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1197
lemma dyn_override_Package_escape:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1198
 (assumes dyn_override: "G \<turnstile> new overrides old" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1199
          accmodi_old: "accmodi old = Package" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1200
         outside_pack: "pid (declclass old) \<noteq> pid (declclass new)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1201
                    wf: "wf_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1202
 ) "\<exists> inter. G \<turnstile> new overrides inter \<and> G \<turnstile> inter overrides old \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1203
             pid (declclass old) = pid (declclass inter) \<and>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1204
             Protected \<le> accmodi inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1205
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1206
  from dyn_override accmodi_old outside_pack
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1207
  show ?thesis (is "?P new old")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1208
  proof (induct rule: overridesR.induct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1209
    case (Direct new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1210
    assume accmodi_old: "accmodi old = Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1211
    assume outside_pack: "pid (declclass old) \<noteq> pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1212
    assume "G \<turnstile>Method old inheritable_in pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1213
    with accmodi_old 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1214
    have "pid (declclass old) = pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1215
      by (simp add: inheritable_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1216
    with outside_pack 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1217
    show "?P new old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1218
      by (contradiction)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1219
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1220
    case (Indirect inter new old)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1221
    assume accmodi_old: "accmodi old = Package"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1222
    assume outside_pack: "pid (declclass old) \<noteq> pid (declclass new)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1223
    assume override_new_inter: "G \<turnstile> new overrides inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1224
    assume override_inter_old: "G \<turnstile> inter overrides old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1225
    assume hyp_new_inter: "\<lbrakk>accmodi inter = Package; 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1226
                           pid (declclass inter) \<noteq> pid (declclass new)\<rbrakk>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1227
                           \<Longrightarrow> ?P new inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1228
    assume hyp_inter_old: "\<lbrakk>accmodi old = Package; 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1229
                           pid (declclass old) \<noteq> pid (declclass inter)\<rbrakk>
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1230
                           \<Longrightarrow> ?P inter old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1231
    show "?P new old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1232
    proof (cases "pid (declclass old) = pid (declclass inter)")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1233
      case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1234
      note same_pack_old_inter = this
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1235
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1236
      proof (cases "pid (declclass inter) = pid (declclass new)")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1237
	case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1238
	with same_pack_old_inter outside_pack
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1239
	show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1240
	  by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1241
      next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1242
	case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1243
	note diff_pack_inter_new = this
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1244
	show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1245
	proof (cases "accmodi inter = Package")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1246
	  case True
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1247
	  with diff_pack_inter_new hyp_new_inter  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1248
	  obtain newinter where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1249
	    over_new_newinter: "G \<turnstile> new overrides newinter" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1250
            over_newinter_inter: "G \<turnstile> newinter overrides inter" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1251
            eq_pid: "pid (declclass inter) = pid (declclass newinter)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1252
            accmodi_newinter: "Protected \<le> accmodi newinter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1253
	    by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1254
	  from over_newinter_inter override_inter_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1255
	  have "G\<turnstile>newinter overrides old"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1256
	    by (rule overridesR.Indirect)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1257
	  moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1258
	  from eq_pid same_pack_old_inter 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1259
	  have "pid (declclass old) = pid (declclass newinter)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1260
	    by simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1261
	  moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1262
	  note over_new_newinter accmodi_newinter
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1263
	  ultimately show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1264
	    by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1265
	next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1266
	  case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1267
	  with override_new_inter
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1268
	  have "Protected \<le> accmodi inter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1269
	    by (cases "accmodi inter") (auto dest: no_Private_override)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1270
	  with override_new_inter override_inter_old same_pack_old_inter
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1271
	  show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1272
	    by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1273
	qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1274
      qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1275
    next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1276
      case False
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1277
      with accmodi_old hyp_inter_old
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1278
      obtain newinter where
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1279
	over_inter_newinter: "G \<turnstile> inter overrides newinter" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1280
          over_newinter_old: "G \<turnstile> newinter overrides old" and 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1281
                eq_pid: "pid (declclass old) = pid (declclass newinter)" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1282
	accmodi_newinter: "Protected \<le> accmodi newinter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1283
	by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1284
      from override_new_inter over_inter_newinter 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1285
      have "G \<turnstile> new overrides newinter"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1286
	by (rule overridesR.Indirect)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1287
      with eq_pid over_newinter_old accmodi_newinter
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1288
      show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1289
	by blast
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1290
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1291
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1292
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1293
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1294
declare split_paired_All [simp del] split_paired_Ex [simp del]
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1295
ML_setup {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1296
simpset_ref() := simpset() delloop "split_all_tac";
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1297
claset_ref () := claset () delSWrapper "split_all_tac"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1298
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1299
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1300
lemma declclass_widen[rule_format]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1301
 "wf_prog G 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1302
 \<longrightarrow> (\<forall>c m. class G C = Some c \<longrightarrow> methd G C sig = Some m 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1303
 \<longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m)" (is "?P G C")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1304
proof (rule class_rec.induct,intro allI impI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1305
  fix G C c m
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1306
  assume Hyp: "\<forall>c. C \<noteq> Object \<and> ws_prog G \<and> class G C = Some c 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1307
               \<longrightarrow> ?P G (super c)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1308
  assume wf: "wf_prog G" and cls_C: "class G C = Some c" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1309
         m:  "methd G C sig = Some m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1310
  show "G\<turnstile>C\<preceq>\<^sub>C declclass m" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1311
  proof (cases "C=Object")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1312
    case True 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1313
    with wf m show ?thesis by (simp add: methd_Object_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1314
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1315
    let ?filter="filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1316
    let ?table = "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1317
    case False 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1318
    with cls_C wf m
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1319
    have methd_C: "(?filter (methd G (super c)) ++ ?table) sig = Some m "
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1320
      by (simp add: methd_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1321
    show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1322
    proof (cases "?table sig")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1323
      case None
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1324
      from this methd_C have "?filter (methd G (super c)) sig = Some m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1325
	by simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1326
      moreover
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1327
      from wf cls_C False obtain sup where "class G (super c) = Some sup"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1328
	by (blast dest: wf_prog_cdecl wf_cdecl_supD is_acc_class_is_class)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1329
      moreover note wf False cls_C Hyp 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1330
      ultimately have "G\<turnstile>super c \<preceq>\<^sub>C declclass m"  by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1331
      moreover from cls_C False have  "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 super c" by (rule subcls1I)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1332
      ultimately show ?thesis by - (rule rtrancl_into_rtrancl2)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1333
    next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1334
      case Some
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1335
      from this wf False cls_C methd_C show ?thesis by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1336
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1337
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1338
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1339
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1340
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1341
lemma declclass_widen[rule_format]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1342
 "wf_prog G 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1343
 \<longrightarrow> (\<forall>c m. class G C = Some c \<longrightarrow> methd G C sig = Some m 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1344
 \<longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m)" (is "?P G C")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1345
apply (rule class_rec.induct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1346
apply (rule impI)+
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1347
apply (case_tac "C=Object")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1348
apply   (force simp add: methd_Object_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1349
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1350
apply   (rule allI)+
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1351
apply   (rule impI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1352
apply   (simp (no_asm_simp) add: methd_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1353
apply   (case_tac "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c)) sig")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1354
apply    (simp add: override_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1355
apply    (frule (1) subcls1I)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1356
apply    (drule (1) wf_prog_cdecl)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1357
apply    (drule (1) wf_cdecl_supD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1358
apply    clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1359
apply    (drule is_acc_class_is_class)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1360
apply    clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1361
apply    (blast dest: rtrancl_into_rtrancl2)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1362
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1363
apply    auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1364
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1365
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1366
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1367
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1368
lemma accessible_public_inheritance_lemma1:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1369
  "\<lbrakk>wf_prog G; class G C = Some c; C \<noteq> Object; accmodi m = Public;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1370
    G\<turnstile>m accessible_through_inheritance_in (super c)\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1371
   \<Longrightarrow> G\<turnstile>m accessible_through_inheritance_in C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1372
apply   (frule (1) subcls1I)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1373
apply   (rule accessible_through_inheritance.Indirect)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1374
apply     (blast)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1375
apply     (erule accessible_through_inheritance_subclsD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1376
apply     (blast dest: wf_prog_acc_superD is_acc_classD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1377
apply     assumption
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1378
apply     (force dest: wf_prog_acc_superD is_acc_classD
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1379
                 simp add: accessible_for_inheritance_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1380
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1381
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1382
lemma accessible_public_inheritance_lemma[rule_format]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1383
  "\<lbrakk>wf_prog G;C \<noteq> Object; class G C = Some c; 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1384
    accmodi m = Public
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1385
   \<rbrakk> \<Longrightarrow> methd G (super c) sig = Some m 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1386
        \<longrightarrow> G\<turnstile>m accessible_through_inheritance_in C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1387
apply (frule (2) wf_prog_acc_superD [THEN is_acc_classD])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1388
apply (erule conjE)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1389
apply (simp only: not_None_eq)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1390
apply (erule exE)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1391
apply (case_tac "(super c) = Object")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1392
apply   (rule impI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1393
apply   (rule accessible_through_inheritance.Direct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1394
apply     force
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1395
apply     (force simp add: accessible_for_inheritance_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1396
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1397
apply   (frule wf_ws_prog) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1398
apply   (simp add: methd_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1399
apply   (case_tac "table_of (map (\<lambda>(s, m). (s, super c, m)) (methods y)) sig")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1400
apply     simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1401
apply     (clarify)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1402
apply     (rule_tac D="super c" in accessible_through_inheritance.Indirect)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1403
apply       (blast dest: subcls1I)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1404
apply       (blast)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1405
apply       simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1406
apply       assumption
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1407
apply       (simp add: accessible_for_inheritance_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1408
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1409
apply     clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1410
apply     (rule accessible_through_inheritance.Direct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1411
apply     (auto dest: subcls1I simp add: accessible_for_inheritance_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1412
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1413
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1414
lemma accessible_public_inheritance:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1415
  "\<lbrakk>wf_prog G; class G D = Some d; G\<turnstile>C \<prec>\<^sub>C D; methd G D sig = Some m; 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1416
    accmodi m = Public\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1417
   \<Longrightarrow> G \<turnstile> m accessible_through_inheritance_in C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1418
apply (erule converse_trancl_induct)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1419
apply  (blast dest: subcls1D intro: accessible_public_inheritance_lemma)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1420
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1421
apply  (frule subcls1D)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1422
apply  clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1423
apply  (frule  (2) wf_prog_acc_superD [THEN is_acc_classD])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1424
apply  clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1425
apply  (rule_tac D="super c" in accessible_through_inheritance.Indirect)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1426
apply   (auto intro:trancl_into_trancl2 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1427
                    accessible_through_inheritance_subclsD
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1428
              simp add: accessible_for_inheritance_in_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1429
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1430
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1431
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1432
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1433
lemma declclass_methd_Object: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1434
 "\<lbrakk>wf_prog G; methd G Object sig = Some m\<rbrakk> \<Longrightarrow> declclass m = Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1435
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1436
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1437
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1438
lemma methd_declaredD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1439
 "\<lbrakk>wf_prog G; is_class G C;methd G C sig = Some m\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1440
  \<Longrightarrow> G\<turnstile>(mdecl (sig,mthd m)) declared_in (declclass m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1441
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1442
  assume    wf: "wf_prog G"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1443
  then have ws: "ws_prog G" ..
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1444
  assume  clsC: "is_class G C"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1445
  from clsC ws 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1446
  show "methd G C sig = Some m 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1447
        \<Longrightarrow> G\<turnstile>(mdecl (sig,mthd m)) declared_in (declclass m)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1448
    (is "PROP ?P C") 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1449
  proof (induct ?P C rule: ws_class_induct')
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1450
    case Object
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1451
    assume "methd G Object sig = Some m" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1452
    with wf show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1453
      by - (rule method_declared_inI, auto) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1454
  next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1455
    case Subcls
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1456
    fix C c
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1457
    assume clsC: "class G C = Some c"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1458
    and       m: "methd G C sig = Some m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1459
    and     hyp: "methd G (super c) sig = Some m \<Longrightarrow> ?thesis" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1460
    let ?newMethods = "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1461
    show ?thesis
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1462
    proof (cases "?newMethods sig")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1463
      case None
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1464
      from None ws clsC m hyp 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1465
      show ?thesis by (auto intro: method_declared_inI simp add: methd_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1466
    next
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1467
      case Some
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1468
      from Some ws clsC m 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1469
      show ?thesis by (auto intro: method_declared_inI simp add: methd_rec) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1470
    qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1471
  qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1472
qed
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1473
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1474
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1475
lemma methd_rec_Some_cases [consumes 4, case_names NewMethod InheritedMethod]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1476
(assumes methd_C: "methd G C sig = Some m" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1477
                    ws: "ws_prog G" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1478
                  clsC: "class G C = Some c" and
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1479
             neq_C_Obj: "C\<noteq>Object" )  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1480
"\<lbrakk>table_of (map (\<lambda>(s, m). (s, C, m)) (methods c)) sig = Some m \<Longrightarrow> P;
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1481
  \<lbrakk>G\<turnstile>C inherits (method sig m); methd G (super c) sig = Some m\<rbrakk> \<Longrightarrow> P 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1482
 \<rbrakk> \<Longrightarrow> P"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1483
proof -
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1484
  let ?inherited   = "filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1485
                              (methd G (super c))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1486
  let ?new = "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1487
  from ws clsC neq_C_Obj methd_C 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1488
  have methd_unfold: "(?inherited ++ ?new) sig = Some m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1489
    by (simp add: methd_rec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1490
  assume NewMethod: "?new sig = Some m \<Longrightarrow> P"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1491
  assume InheritedMethod: "\<lbrakk>G\<turnstile>C inherits (method sig m); 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1492
                            methd G (super c) sig = Some m\<rbrakk> \<Longrightarrow> P"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1493
  show P
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1494
  proof (cases "?new sig")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1495
    case None
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1496
    with methd_unfold have "?inherited sig = Some m"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
  1497
      by (auto)