src/HOL/Bali/WellForm.thy
changeset 12925 99131847fb93
parent 12893 cbb4dc5e6478
child 12937 0c4fd7529467
equal deleted inserted replaced
12924:02eb40cde931 12925:99131847fb93
     1 (*  Title:      HOL/Bali/WellForm.thy
     1 (*  Title:      HOL/Bali/WellForm.thy
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     David von Oheimb
     3     Author:     David von Oheimb and Norbert Schirmer
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     4     License:    GPL (GNU GENERAL PUBLIC LICENSE)
     5 *)
     5 *)
     6 
     6 
     7 header {* Well-formedness of Java programs *}
     7 header {* Well-formedness of Java programs *}
     8 
     8 
    29       classes
    29       classes
    30 \end{itemize}
    30 \end{itemize}
    31 *}
    31 *}
    32 
    32 
    33 section "well-formed field declarations"
    33 section "well-formed field declarations"
    34   (* well-formed field declaration (common part for classes and interfaces),
    34 text  {* well-formed field declaration (common part for classes and interfaces),
    35      cf. 8.3 and (9.3) *)
    35         cf. 8.3 and (9.3) *}
    36 
    36 
    37 constdefs
    37 constdefs
    38   wf_fdecl :: "prog \<Rightarrow> pname \<Rightarrow> fdecl \<Rightarrow> bool"
    38   wf_fdecl :: "prog \<Rightarrow> pname \<Rightarrow> fdecl \<Rightarrow> bool"
    39  "wf_fdecl G P \<equiv> \<lambda>(fn,f). is_acc_type G P (type f)"
    39  "wf_fdecl G P \<equiv> \<lambda>(fn,f). is_acc_type G P (type f)"
    40 
    40 
    96                   EName e 
    96                   EName e 
    97                   \<Rightarrow> (case e of 
    97                   \<Rightarrow> (case e of 
    98                         VNam v 
    98                         VNam v 
    99                         \<Rightarrow>(table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
    99                         \<Rightarrow>(table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
   100                       | Res \<Rightarrow> Some (resTy m))
   100                       | Res \<Rightarrow> Some (resTy m))
   101 	        | This \<Rightarrow> if static m then None else Some (Class C))
   101 	        | This \<Rightarrow> if is_static m then None else Some (Class C))
   102           \<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>"
   102           \<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>"
   103 
   103 
   104 lemma wf_mheadI: 
   104 lemma wf_mheadI: 
   105 "\<lbrakk>length (parTs sig) = length (pars m); \<forall>T\<in>set (parTs sig). is_acc_type G P T;
   105 "\<lbrakk>length (parTs sig) = length (pars m); \<forall>T\<in>set (parTs sig). is_acc_type G P T;
   106   is_acc_type G P (resTy m); distinct (pars m)\<rbrakk> \<Longrightarrow>  
   106   is_acc_type G P (resTy m); distinct (pars m)\<rbrakk> \<Longrightarrow>  
   120           EName e 
   120           EName e 
   121           \<Rightarrow> (case e of 
   121           \<Rightarrow> (case e of 
   122                 VNam v 
   122                 VNam v 
   123                 \<Rightarrow> (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
   123                 \<Rightarrow> (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
   124               | Res \<Rightarrow> Some (resTy m))
   124               | Res \<Rightarrow> Some (resTy m))
   125         | This \<Rightarrow> if static m then None else Some (Class C))
   125         | This \<Rightarrow> if is_static m then None else Some (Class C))
   126   \<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>
   126   \<rparr>\<turnstile>(stmt (mbody m))\<Colon>\<surd>
   127   \<rbrakk> \<Longrightarrow>  
   127   \<rbrakk> \<Longrightarrow>  
   128   wf_mdecl G C (sig,m)"
   128   wf_mdecl G C (sig,m)"
   129 apply (unfold wf_mdecl_def)
   129 apply (unfold wf_mdecl_def)
   130 apply simp
   130 apply simp
   147          (case k of
   147          (case k of
   148             EName e 
   148             EName e 
   149             \<Rightarrow> (case e of 
   149             \<Rightarrow> (case e of 
   150                 VNam v \<Rightarrow> (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
   150                 VNam v \<Rightarrow> (table_of (lcls (mbody m))((pars m)[\<mapsto>](parTs sig))) v
   151                 | Res  \<Rightarrow> Some (resTy m))
   151                 | Res  \<Rightarrow> Some (resTy m))
   152           | This \<Rightarrow> if static m then None else Some (Class C))
   152           | This \<Rightarrow> if is_static m then None else Some (Class C))
   153        \<rparr>\<turnstile>Body C (stmt (mbody m))\<Colon>-T \<and> G\<turnstile>T\<preceq>(resTy m))"
   153        \<rparr>\<turnstile>Body C (stmt (mbody m))\<Colon>-T \<and> G\<turnstile>T\<preceq>(resTy m))"
   154 apply (unfold wf_mdecl_def)
   154 apply (unfold wf_mdecl_def)
   155 apply clarify
   155 apply clarify
   156 apply (rule_tac x="(resTy m)" in exI)
   156 apply (rule_tac x="(resTy m)" in exI)
   157 apply (unfold wf_mhead_def)
   157 apply (unfold wf_mhead_def)
  1289 	by blast
  1289 	by blast
  1290     qed
  1290     qed
  1291   qed
  1291   qed
  1292 qed
  1292 qed
  1293 
  1293 
  1294 declare split_paired_All [simp del] split_paired_Ex [simp del]
       
  1295 ML_setup {*
       
  1296 simpset_ref() := simpset() delloop "split_all_tac";
       
  1297 claset_ref () := claset () delSWrapper "split_all_tac"
       
  1298 *}
       
  1299 
       
  1300 lemma declclass_widen[rule_format]: 
  1294 lemma declclass_widen[rule_format]: 
  1301  "wf_prog G 
  1295  "wf_prog G 
  1302  \<longrightarrow> (\<forall>c m. class G C = Some c \<longrightarrow> methd G C sig = Some m 
  1296  \<longrightarrow> (\<forall>c m. class G C = Some c \<longrightarrow> methd G C sig = Some m 
  1303  \<longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m)" (is "?P G C")
  1297  \<longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m)" (is "?P G C")
  1304 proof (rule class_rec.induct,intro allI impI)
  1298 proof (rule class_rec.induct,intro allI impI)
  1324       from this methd_C have "?filter (methd G (super c)) sig = Some m"
  1318       from this methd_C have "?filter (methd G (super c)) sig = Some m"
  1325 	by simp
  1319 	by simp
  1326       moreover
  1320       moreover
  1327       from wf cls_C False obtain sup where "class G (super c) = Some sup"
  1321       from wf cls_C False obtain sup where "class G (super c) = Some sup"
  1328 	by (blast dest: wf_prog_cdecl wf_cdecl_supD is_acc_class_is_class)
  1322 	by (blast dest: wf_prog_cdecl wf_cdecl_supD is_acc_class_is_class)
  1329       moreover note wf False cls_C Hyp 
  1323       moreover note wf False cls_C  
  1330       ultimately have "G\<turnstile>super c \<preceq>\<^sub>C declclass m"  by auto
  1324       ultimately have "G\<turnstile>super c \<preceq>\<^sub>C declclass m"  
       
  1325 	by (auto intro: Hyp [rule_format])
  1331       moreover from cls_C False have  "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 super c" by (rule subcls1I)
  1326       moreover from cls_C False have  "G\<turnstile>C \<prec>\<^sub>C\<^sub>1 super c" by (rule subcls1I)
  1332       ultimately show ?thesis by - (rule rtrancl_into_rtrancl2)
  1327       ultimately show ?thesis by - (rule rtrancl_into_rtrancl2)
  1333     next
  1328     next
  1334       case Some
  1329       case Some
  1335       from this wf False cls_C methd_C show ?thesis by auto
  1330       from this wf False cls_C methd_C show ?thesis by auto
  1336     qed
  1331     qed
  1337   qed
  1332   qed
  1338 qed
  1333 qed
  1339 
  1334 
  1340 (*
       
  1341 lemma declclass_widen[rule_format]: 
       
  1342  "wf_prog G 
       
  1343  \<longrightarrow> (\<forall>c m. class G C = Some c \<longrightarrow> methd G C sig = Some m 
       
  1344  \<longrightarrow> G\<turnstile>C \<preceq>\<^sub>C declclass m)" (is "?P G C")
       
  1345 apply (rule class_rec.induct)
       
  1346 apply (rule impI)+
       
  1347 apply (case_tac "C=Object")
       
  1348 apply   (force simp add: methd_Object_SomeD)
       
  1349 
       
  1350 apply   (rule allI)+
       
  1351 apply   (rule impI)
       
  1352 apply   (simp (no_asm_simp) add: methd_rec)
       
  1353 apply   (case_tac "table_of (map (\<lambda>(s, m). (s, C, m)) (methods c)) sig")
       
  1354 apply    (simp add: override_def)
       
  1355 apply    (frule (1) subcls1I)
       
  1356 apply    (drule (1) wf_prog_cdecl)
       
  1357 apply    (drule (1) wf_cdecl_supD)
       
  1358 apply    clarify
       
  1359 apply    (drule is_acc_class_is_class)
       
  1360 apply    clarify
       
  1361 apply    (blast dest: rtrancl_into_rtrancl2)
       
  1362 
       
  1363 apply    auto
       
  1364 done
       
  1365 *)
       
  1366 
       
  1367 (*
       
  1368 lemma accessible_public_inheritance_lemma1:
       
  1369   "\<lbrakk>wf_prog G; class G C = Some c; C \<noteq> Object; accmodi m = Public;
       
  1370     G\<turnstile>m accessible_through_inheritance_in (super c)\<rbrakk> 
       
  1371    \<Longrightarrow> G\<turnstile>m accessible_through_inheritance_in C"
       
  1372 apply   (frule (1) subcls1I)
       
  1373 apply   (rule accessible_through_inheritance.Indirect)
       
  1374 apply     (blast)
       
  1375 apply     (erule accessible_through_inheritance_subclsD)
       
  1376 apply     (blast dest: wf_prog_acc_superD is_acc_classD)
       
  1377 apply     assumption
       
  1378 apply     (force dest: wf_prog_acc_superD is_acc_classD
       
  1379                  simp add: accessible_for_inheritance_in_def)
       
  1380 done
       
  1381 
       
  1382 lemma accessible_public_inheritance_lemma[rule_format]:
       
  1383   "\<lbrakk>wf_prog G;C \<noteq> Object; class G C = Some c; 
       
  1384     accmodi m = Public
       
  1385    \<rbrakk> \<Longrightarrow> methd G (super c) sig = Some m 
       
  1386         \<longrightarrow> G\<turnstile>m accessible_through_inheritance_in C" 
       
  1387 apply (frule (2) wf_prog_acc_superD [THEN is_acc_classD])
       
  1388 apply (erule conjE)
       
  1389 apply (simp only: not_None_eq)
       
  1390 apply (erule exE)
       
  1391 apply (case_tac "(super c) = Object")
       
  1392 apply   (rule impI)
       
  1393 apply   (rule accessible_through_inheritance.Direct)
       
  1394 apply     force
       
  1395 apply     (force simp add: accessible_for_inheritance_in_def)
       
  1396 
       
  1397 apply   (frule wf_ws_prog) 
       
  1398 apply   (simp add: methd_rec)
       
  1399 apply   (case_tac "table_of (map (\<lambda>(s, m). (s, super c, m)) (methods y)) sig")
       
  1400 apply     simp
       
  1401 apply     (clarify)
       
  1402 apply     (rule_tac D="super c" in accessible_through_inheritance.Indirect)
       
  1403 apply       (blast dest: subcls1I)
       
  1404 apply       (blast)
       
  1405 apply       simp
       
  1406 apply       assumption
       
  1407 apply       (simp add: accessible_for_inheritance_in_def)
       
  1408 
       
  1409 apply     clarsimp
       
  1410 apply     (rule accessible_through_inheritance.Direct)
       
  1411 apply     (auto dest: subcls1I simp add: accessible_for_inheritance_in_def)
       
  1412 done
       
  1413 
       
  1414 lemma accessible_public_inheritance:
       
  1415   "\<lbrakk>wf_prog G; class G D = Some d; G\<turnstile>C \<prec>\<^sub>C D; methd G D sig = Some m; 
       
  1416     accmodi m = Public\<rbrakk> 
       
  1417    \<Longrightarrow> G \<turnstile> m accessible_through_inheritance_in C"
       
  1418 apply (erule converse_trancl_induct)
       
  1419 apply  (blast dest: subcls1D intro: accessible_public_inheritance_lemma)
       
  1420 
       
  1421 apply  (frule subcls1D)
       
  1422 apply  clarify
       
  1423 apply  (frule  (2) wf_prog_acc_superD [THEN is_acc_classD])
       
  1424 apply  clarify
       
  1425 apply  (rule_tac D="super c" in accessible_through_inheritance.Indirect)
       
  1426 apply   (auto intro:trancl_into_trancl2 
       
  1427                     accessible_through_inheritance_subclsD
       
  1428               simp add: accessible_for_inheritance_in_def)
       
  1429 done
       
  1430 *)
       
  1431 
       
  1432 
       
  1433 lemma declclass_methd_Object: 
  1335 lemma declclass_methd_Object: 
  1434  "\<lbrakk>wf_prog G; methd G Object sig = Some m\<rbrakk> \<Longrightarrow> declclass m = Object"
  1336  "\<lbrakk>wf_prog G; methd G Object sig = Some m\<rbrakk> \<Longrightarrow> declclass m = Object"
  1435 by auto
  1337 by auto
  1436 
       
  1437 
  1338 
  1438 lemma methd_declaredD: 
  1339 lemma methd_declaredD: 
  1439  "\<lbrakk>wf_prog G; is_class G C;methd G C sig = Some m\<rbrakk> 
  1340  "\<lbrakk>wf_prog G; is_class G C;methd G C sig = Some m\<rbrakk> 
  1440   \<Longrightarrow> G\<turnstile>(mdecl (sig,mthd m)) declared_in (declclass m)"
  1341   \<Longrightarrow> G\<turnstile>(mdecl (sig,mthd m)) declared_in (declclass m)"
  1441 proof -
  1342 proof -
  1468       from Some ws clsC m 
  1369       from Some ws clsC m 
  1469       show ?thesis by (auto intro: method_declared_inI simp add: methd_rec) 
  1370       show ?thesis by (auto intro: method_declared_inI simp add: methd_rec) 
  1470     qed
  1371     qed
  1471   qed
  1372   qed
  1472 qed
  1373 qed
  1473 
       
  1474 
  1374 
  1475 lemma methd_rec_Some_cases [consumes 4, case_names NewMethod InheritedMethod]:
  1375 lemma methd_rec_Some_cases [consumes 4, case_names NewMethod InheritedMethod]:
  1476 (assumes methd_C: "methd G C sig = Some m" and
  1376 (assumes methd_C: "methd G C sig = Some m" and
  1477                     ws: "ws_prog G" and
  1377                     ws: "ws_prog G" and
  1478                   clsC: "class G C = Some c" and
  1378                   clsC: "class G C = Some c" and
  1755                                    G,sig\<turnstile>new overrides\<^sub>S old\<rbrakk> \<Longrightarrow> P"
  1655                                    G,sig\<turnstile>new overrides\<^sub>S old\<rbrakk> \<Longrightarrow> P"
  1756         
  1656         
  1757  ) "P"
  1657  ) "P"
  1758 proof -
  1658 proof -
  1759 from subclseq_C_D is_cls_D wf old accmodi_old not_static_old 
  1659 from subclseq_C_D is_cls_D wf old accmodi_old not_static_old 
  1760      inheritance overriding
       
  1761 show ?thesis
  1660 show ?thesis
  1762   by (auto dest: inheritable_instance_methd)
  1661   by (auto dest: inheritable_instance_methd intro: inheritance overriding)
  1763 qed
  1662 qed
  1764 
  1663 
  1765 lemma inheritable_instance_methd_props: 
  1664 lemma inheritable_instance_methd_props: 
  1766  (assumes subclseq_C_D: "G\<turnstile>C \<preceq>\<^sub>C D" and
  1665  (assumes subclseq_C_D: "G\<turnstile>C \<preceq>\<^sub>C D" and
  1767               is_cls_D: "is_class G D" and
  1666               is_cls_D: "is_class G D" and
  1976 apply (drule (3) r_into_rtrancl [THEN inheritable_instance_methd_props, 
  1875 apply (drule (3) r_into_rtrancl [THEN inheritable_instance_methd_props, 
  1977                                  OF _ implmt_is_class])
  1876                                  OF _ implmt_is_class])
  1978 apply auto 
  1877 apply auto 
  1979 done
  1878 done
  1980 
  1879 
  1981 
       
  1982 declare split_paired_All [simp] split_paired_Ex [simp]
       
  1983 ML_setup {*
       
  1984 claset_ref()  := claset() addSbefore ("split_all_tac", split_all_tac);
       
  1985 simpset_ref() := simpset() addloop ("split_all_tac", split_all_tac)
       
  1986 *}
       
  1987 lemma mheadsD [rule_format (no_asm)]: 
  1880 lemma mheadsD [rule_format (no_asm)]: 
  1988 "emh \<in> mheads G S t sig \<longrightarrow> wf_prog G \<longrightarrow>
  1881 "emh \<in> mheads G S t sig \<longrightarrow> wf_prog G \<longrightarrow>
  1989  (\<exists>C D m. t = ClassT C \<and> declrefT emh = ClassT D \<and> 
  1882  (\<exists>C D m. t = ClassT C \<and> declrefT emh = ClassT D \<and> 
  1990           accmethd G S C sig = Some m \<and>
  1883           accmethd G S C sig = Some m \<and>
  1991           (declclass m = D) \<and> mhead (mthd m) = (mhd emh)) \<or>
  1884           (declclass m = D) \<and> mhead (mthd m) = (mhd emh)) \<or>
  2166 @{term "G\<turnstile>Class dynC\<preceq> statT"}. Unfortunately this ordinary widening relation 
  2059 @{term "G\<turnstile>Class dynC\<preceq> statT"}. Unfortunately this ordinary widening relation 
  2167 isn't enough to describe the valid lookup classes, since we must cope the
  2060 isn't enough to describe the valid lookup classes, since we must cope the
  2168 special cases of arrays and interfaces,too. If we statically expect an array or
  2061 special cases of arrays and interfaces,too. If we statically expect an array or
  2169 inteface we may lookup a field or a method in Object which isn't covered in 
  2062 inteface we may lookup a field or a method in Object which isn't covered in 
  2170 the widening relation.
  2063 the widening relation.
  2171 \begin{verbatim}
  2064 
  2172 statT      field         instance method       static (class) method
  2065 statT      field         instance method       static (class) method
  2173 ------------------------------------------------------------------------
  2066 ------------------------------------------------------------------------
  2174  NullT      /                  /                   /
  2067  NullT      /                  /                   /
  2175  Iface      /                dynC                Object
  2068  Iface      /                dynC                Object
  2176  Class    dynC               dynC                 dynC
  2069  Class    dynC               dynC                 dynC
  2177  Array      /                Object              Object
  2070  Array      /                Object              Object
  2178 \end{verbatim}
  2071 
  2179 In most cases we con lookup the member in the dynamic class. But as an
  2072 In most cases we con lookup the member in the dynamic class. But as an
  2180 interface can't declare new static methods, nor an array can define new
  2073 interface can't declare new static methods, nor an array can define new
  2181 methods at all, we have to lookup methods in the base class Object.
  2074 methods at all, we have to lookup methods in the base class Object.
  2182 
  2075 
  2183 The limitation to classes in the field column is artificial  and comes out
  2076 The limitation to classes in the field column is artificial  and comes out
  2187 indeed has no non private fields. So interfaces and arrays can actually
  2080 indeed has no non private fields. So interfaces and arrays can actually
  2188 have no fields at all and a field access would be senseless. (In Java
  2081 have no fields at all and a field access would be senseless. (In Java
  2189 interfaces are allowed to declare new fields but in current Bali not!).
  2082 interfaces are allowed to declare new fields but in current Bali not!).
  2190 So there is no principal reason why we should not allow Objects to declare
  2083 So there is no principal reason why we should not allow Objects to declare
  2191 non private fields. Then we would get the following column:
  2084 non private fields. Then we would get the following column:
  2192 \begin{verbatim}
  2085        
  2193  statT    field
  2086  statT    field
  2194 ----------------- 
  2087 ----------------- 
  2195  NullT      /  
  2088  NullT      /  
  2196  Iface    Object 
  2089  Iface    Object 
  2197  Class    dynC 
  2090  Class    dynC 
  2198  Array    Object
  2091  Array    Object
  2199 \end{verbatim}
       
  2200 *}
  2092 *}
  2201 consts valid_lookup_cls:: "prog \<Rightarrow> ref_ty \<Rightarrow> qtname \<Rightarrow> bool \<Rightarrow> bool"
  2093 consts valid_lookup_cls:: "prog \<Rightarrow> ref_ty \<Rightarrow> qtname \<Rightarrow> bool \<Rightarrow> bool"
  2202                         ("_,_ \<turnstile> _ valid'_lookup'_cls'_for _" [61,61,61,61] 60)
  2094                         ("_,_ \<turnstile> _ valid'_lookup'_cls'_for _" [61,61,61,61] 60)
  2203 primrec
  2095 primrec
  2204 "G,NullT    \<turnstile> dynC valid_lookup_cls_for static_membr = False"
  2096 "G,NullT    \<turnstile> dynC valid_lookup_cls_for static_membr = False"
  2235 declare split_paired_All [simp del] split_paired_Ex [simp del]
  2127 declare split_paired_All [simp del] split_paired_Ex [simp del]
  2236 ML_setup {*
  2128 ML_setup {*
  2237 simpset_ref() := simpset() delloop "split_all_tac";
  2129 simpset_ref() := simpset() delloop "split_all_tac";
  2238 claset_ref () := claset () delSWrapper "split_all_tac"
  2130 claset_ref () := claset () delSWrapper "split_all_tac"
  2239 *}
  2131 *}
  2240 
       
  2241 lemma dynamic_mheadsD:   
  2132 lemma dynamic_mheadsD:   
  2242 "\<lbrakk>emh \<in> mheads G S statT sig;    
  2133 "\<lbrakk>emh \<in> mheads G S statT sig;    
  2243   G,statT \<turnstile> dynC valid_lookup_cls_for (is_static emh);
  2134   G,statT \<turnstile> dynC valid_lookup_cls_for (is_static emh);
  2244   isrtype G statT; wf_prog G
  2135   isrtype G statT; wf_prog G
  2245  \<rbrakk> \<Longrightarrow> \<exists>m \<in> dynlookup G statT dynC sig: 
  2136  \<rbrakk> \<Longrightarrow> \<exists>m \<in> dynlookup G statT dynC sig: 
  2268     from wf statC istype dynC_Prop sm 
  2159     from wf statC istype dynC_Prop sm 
  2269     obtain dm where
  2160     obtain dm where
  2270       "dynmethd G statC dynC sig = Some dm"
  2161       "dynmethd G statC dynC sig = Some dm"
  2271       "is_static dm = is_static sm" 
  2162       "is_static dm = is_static sm" 
  2272       "G\<turnstile>resTy dm\<preceq>resTy sm"  
  2163       "G\<turnstile>resTy dm\<preceq>resTy sm"  
  2273       by (auto dest!: ws_dynmethd accmethd_SomeD)
  2164       by (force dest!: ws_dynmethd accmethd_SomeD)
  2274     with dynlookup eq_mheads 
  2165     with dynlookup eq_mheads 
  2275     show ?thesis 
  2166     show ?thesis 
  2276       by (cases emh type: *) (auto)
  2167       by (cases emh type: *) (auto)
  2277   next
  2168   next
  2278     case Iface_methd
  2169     case Iface_methd
  2291     from wf dynC_Prop statI istype im not_static_emh 
  2182     from wf dynC_Prop statI istype im not_static_emh 
  2292     obtain dm where
  2183     obtain dm where
  2293       "methd G dynC sig = Some dm"
  2184       "methd G dynC sig = Some dm"
  2294       "is_static dm = is_static im" 
  2185       "is_static dm = is_static im" 
  2295       "G\<turnstile>resTy (mthd dm)\<preceq>resTy (mthd im)" 
  2186       "G\<turnstile>resTy (mthd dm)\<preceq>resTy (mthd im)" 
  2296       by (auto dest: implmt_methd)
  2187       by (force dest: implmt_methd)
  2297     with dynlookup eq_mheads
  2188     with dynlookup eq_mheads
  2298     show ?thesis 
  2189     show ?thesis 
  2299       by (cases emh type: *) (auto)
  2190       by (cases emh type: *) (auto)
  2300   next
  2191   next
  2301     case Iface_Object_methd
  2192     case Iface_Object_methd
  2317        obtain dm where
  2208        obtain dm where
  2318 	 "dynmethd G Object dynC sig = Some dm"
  2209 	 "dynmethd G Object dynC sig = Some dm"
  2319 	 "is_static dm = is_static sm" 
  2210 	 "is_static dm = is_static sm" 
  2320 	 "G\<turnstile>resTy (mthd dm)\<preceq>resTy (mthd sm)"  
  2211 	 "G\<turnstile>resTy (mthd dm)\<preceq>resTy (mthd sm)"  
  2321 	 by (auto dest!: ws_dynmethd accmethd_SomeD 
  2212 	 by (auto dest!: ws_dynmethd accmethd_SomeD 
  2322                   intro: class_Object [OF wf])
  2213                   intro: class_Object [OF wf] intro: that)
  2323        with dynlookup eq_mheads
  2214        with dynlookup eq_mheads
  2324        show ?thesis 
  2215        show ?thesis 
  2325 	 by (cases emh type: *) (auto)
  2216 	 by (cases emh type: *) (auto)
  2326      next
  2217      next
  2327        case False
  2218        case False
  2362     with sm eq_mheads sm 
  2253     with sm eq_mheads sm 
  2363     show ?thesis 
  2254     show ?thesis 
  2364       by (cases emh type: *) (auto dest: accmethd_SomeD)
  2255       by (cases emh type: *) (auto dest: accmethd_SomeD)
  2365   qed
  2256   qed
  2366 qed
  2257 qed
       
  2258 declare split_paired_All [simp] split_paired_Ex [simp]
       
  2259 ML_setup {*
       
  2260 claset_ref()  := claset() addSbefore ("split_all_tac", split_all_tac);
       
  2261 simpset_ref() := simpset() addloop ("split_all_tac", split_all_tac)
       
  2262 *}
  2367 
  2263 
  2368 (* Tactical version *)
  2264 (* Tactical version *)
  2369 (*
  2265 (*
  2370 lemma dynamic_mheadsD: "  
  2266 lemma dynamic_mheadsD: "  
  2371  \<lbrakk>emh \<in> mheads G S statT sig; wf_prog G; class G dynC = Some y;  
  2267  \<lbrakk>emh \<in> mheads G S statT sig; wf_prog G; class G dynC = Some y;  
  2429 apply    (case_tac emh)
  2325 apply    (case_tac emh)
  2430 apply    (force dest: accmethd_SomeD simp add: dynmethd_def)
  2326 apply    (force dest: accmethd_SomeD simp add: dynmethd_def)
  2431 done
  2327 done
  2432 *)
  2328 *)
  2433 
  2329 
  2434 (* ### auf ws_class_induct umstellen *)
  2330 (* FIXME occasionally convert to ws_class_induct*) 
  2435 lemma methd_declclass:
  2331 lemma methd_declclass:
  2436 "\<lbrakk>class G C = Some c; wf_prog G; methd G C sig = Some m\<rbrakk> 
  2332 "\<lbrakk>class G C = Some c; wf_prog G; methd G C sig = Some m\<rbrakk> 
  2437  \<Longrightarrow> methd G (declclass m) sig = Some m"
  2333  \<Longrightarrow> methd G (declclass m) sig = Some m"
  2438 proof -
  2334 proof -
  2439   assume asm: "class G C = Some c" "wf_prog G" "methd G C sig = Some m"
  2335   assume asm: "class G C = Some c" "wf_prog G" "methd G C sig = Some m"
  2463 	from this methd_C have "?filter (methd G (super c)) sig = Some m"
  2359 	from this methd_C have "?filter (methd G (super c)) sig = Some m"
  2464 	  by simp
  2360 	  by simp
  2465 	moreover
  2361 	moreover
  2466 	from wf cls_C False obtain sup where "class G (super c) = Some sup"
  2362 	from wf cls_C False obtain sup where "class G (super c) = Some sup"
  2467 	  by (blast dest: wf_prog_cdecl wf_cdecl_supD is_acc_class_is_class)
  2363 	  by (blast dest: wf_prog_cdecl wf_cdecl_supD is_acc_class_is_class)
  2468 	moreover note wf False cls_C hyp
  2364 	moreover note wf False cls_C 
  2469 	ultimately show ?thesis by auto
  2365 	ultimately show ?thesis by (auto intro: hyp [rule_format])
  2470       next
  2366       next
  2471 	case Some
  2367 	case Some
  2472 	from this methd_C m show ?thesis by auto 
  2368 	from this methd_C m show ?thesis by auto 
  2473       qed
  2369       qed
  2474     qed
  2370     qed
  2502   show ?thesis
  2398   show ?thesis
  2503     by (auto simp add: dynlookup_def dynmethd_C_C [OF is_cls_Obj ws]
  2399     by (auto simp add: dynlookup_def dynmethd_C_C [OF is_cls_Obj ws]
  2504                  dest: methd_Object_SomeD)
  2400                  dest: methd_Object_SomeD)
  2505 qed   
  2401 qed   
  2506   
  2402   
       
  2403 
  2507 declare split_paired_All [simp del] split_paired_Ex [simp del]
  2404 declare split_paired_All [simp del] split_paired_Ex [simp del]
  2508 ML_setup {*
  2405 ML_setup {*
  2509 simpset_ref() := simpset() delloop "split_all_tac";
  2406 simpset_ref() := simpset() delloop "split_all_tac";
  2510 claset_ref () := claset () delSWrapper "split_all_tac"
  2407 claset_ref () := claset () delSWrapper "split_all_tac"
  2511 *}
  2408 *}
  2512 
       
  2513 lemma wt_is_type: "E,dt\<Turnstile>v\<Colon>T \<Longrightarrow>  wf_prog (prg E) \<longrightarrow> 
  2409 lemma wt_is_type: "E,dt\<Turnstile>v\<Colon>T \<Longrightarrow>  wf_prog (prg E) \<longrightarrow> 
  2514   dt=empty_dt \<longrightarrow> (case T of 
  2410   dt=empty_dt \<longrightarrow> (case T of 
  2515                      Inl T \<Rightarrow> is_type (prg E) T 
  2411                      Inl T \<Rightarrow> is_type (prg E) T 
  2516                    | Inr Ts \<Rightarrow> Ball (set Ts) (is_type (prg E)))"
  2412                    | Inr Ts \<Rightarrow> Ball (set Ts) (is_type (prg E)))"
  2517 apply (unfold empty_dt_def)
  2413 apply (unfold empty_dt_def)
  2596  "\<lbrakk>emh \<in> mheads G S T sig; wf_prog G\<rbrakk>
  2492  "\<lbrakk>emh \<in> mheads G S T sig; wf_prog G\<rbrakk>
  2597  \<Longrightarrow> G\<turnstile>RefT T accessible_in (pid S)"
  2493  \<Longrightarrow> G\<turnstile>RefT T accessible_in (pid S)"
  2598 by (erule mheads_cases)
  2494 by (erule mheads_cases)
  2599    (auto dest: accmethd_SomeD accessible_from_commonD accimethdsD)
  2495    (auto dest: accmethd_SomeD accessible_from_commonD accimethdsD)
  2600 
  2496 
  2601 lemma static_to_dynamic_accessible_from:
  2497 lemma static_to_dynamic_accessible_from_aux:
  2602 "\<lbrakk>G\<turnstile>m of C accessible_from accC;wf_prog G\<rbrakk> 
  2498 "\<lbrakk>G\<turnstile>m of C accessible_from accC;wf_prog G\<rbrakk> 
  2603  \<Longrightarrow> G\<turnstile>m in C dyn_accessible_from accC"
  2499  \<Longrightarrow> G\<turnstile>m in C dyn_accessible_from accC"
  2604 proof (induct rule: accessible_fromR.induct)
  2500 proof (induct rule: accessible_fromR.induct)
  2605 qed (auto intro: dyn_accessible_fromR.intros 
  2501 qed (auto intro: dyn_accessible_fromR.intros 
  2606                  member_of_to_member_in
  2502                  member_of_to_member_in
  2613  ) "G\<turnstile>m in dynC dyn_accessible_from accC"
  2509  ) "G\<turnstile>m in dynC dyn_accessible_from accC"
  2614 proof - 
  2510 proof - 
  2615   from stat_acc subclseq 
  2511   from stat_acc subclseq 
  2616   show ?thesis (is "?Dyn_accessible m")
  2512   show ?thesis (is "?Dyn_accessible m")
  2617   proof (induct rule: accessible_fromR.induct)
  2513   proof (induct rule: accessible_fromR.induct)
  2618     case (immediate statC m)
  2514     case (Immediate statC m)
  2619     then show "?Dyn_accessible m"
  2515     then show "?Dyn_accessible m"
  2620       by (blast intro: dyn_accessible_fromR.immediate
  2516       by (blast intro: dyn_accessible_fromR.Immediate
  2621                        member_inI
  2517                        member_inI
  2622                        permits_acc_inheritance)
  2518                        permits_acc_inheritance)
  2623   next
  2519   next
  2624     case (overriding _ _ m)
  2520     case (Overriding _ _ m)
  2625     with wf show "?Dyn_accessible m"
  2521     with wf show "?Dyn_accessible m"
  2626       by (blast intro: dyn_accessible_fromR.overriding
  2522       by (blast intro: dyn_accessible_fromR.Overriding
  2627                        member_inI
  2523                        member_inI
  2628                        static_to_dynamic_overriding  
  2524                        static_to_dynamic_overriding  
  2629                        rtrancl_trancl_trancl 
  2525                        rtrancl_trancl_trancl 
  2630                        static_to_dynamic_accessible_from)
  2526                        static_to_dynamic_accessible_from_aux)
  2631   qed
  2527   qed
       
  2528 qed
       
  2529 
       
  2530 lemma static_to_dynamic_accessible_from_static:
       
  2531  (assumes stat_acc: "G\<turnstile>m of statC accessible_from accC" and
       
  2532             static: "is_static m" and
       
  2533                 wf: "wf_prog G"
       
  2534  ) "G\<turnstile>m in (declclass m) dyn_accessible_from accC"
       
  2535 proof -
       
  2536   from stat_acc wf 
       
  2537   have "G\<turnstile>m in statC dyn_accessible_from accC"
       
  2538     by (auto intro: static_to_dynamic_accessible_from)
       
  2539   from this static
       
  2540   show ?thesis
       
  2541     by (rule dyn_accessible_from_static_declC)
  2632 qed
  2542 qed
  2633 
  2543 
  2634 lemma dynmethd_member_in:
  2544 lemma dynmethd_member_in:
  2635  (assumes    m: "dynmethd G statC dynC sig = Some m" and
  2545  (assumes    m: "dynmethd G statC dynC sig = Some m" and
  2636    iscls_statC: "is_class G statC" and
  2546    iscls_statC: "is_class G statC" and
  2721     have "G\<turnstile>Methd sig statM in statC dyn_accessible_from accC"
  2631     have "G\<turnstile>Methd sig statM in statC dyn_accessible_from accC"
  2722       by (blast intro: static_to_dynamic_accessible_from)
  2632       by (blast intro: static_to_dynamic_accessible_from)
  2723     moreover
  2633     moreover
  2724     note override eq_dynM_newM
  2634     note override eq_dynM_newM
  2725     ultimately show ?thesis
  2635     ultimately show ?thesis
  2726       by (cases dynM,cases statM) (auto intro: dyn_accessible_fromR.overriding)
  2636       by (cases dynM,cases statM) (auto intro: dyn_accessible_fromR.Overriding)
  2727   qed
  2637   qed
  2728 qed
  2638 qed
  2729 
  2639 
  2730 lemma implmt_methd_access:
  2640 lemma implmt_methd_access:
  2731 (fixes accC::qtname
  2641 (fixes accC::qtname
  2747     where dynM: "methd G dynC sig = Some dynM" and
  2657     where dynM: "methd G dynC sig = Some dynM" and
  2748            pub: "accmodi dynM = Public"
  2658            pub: "accmodi dynM = Public"
  2749     by (blast dest: implmt_methd)
  2659     by (blast dest: implmt_methd)
  2750   with iscls_dynC wf
  2660   with iscls_dynC wf
  2751   have "G\<turnstile>Methd sig dynM in dynC dyn_accessible_from accC"
  2661   have "G\<turnstile>Methd sig dynM in dynC dyn_accessible_from accC"
  2752     by (auto intro!: dyn_accessible_fromR.immediate 
  2662     by (auto intro!: dyn_accessible_fromR.Immediate 
  2753               intro: methd_member_of member_of_to_member_in
  2663               intro: methd_member_of member_of_to_member_in
  2754                      simp add: permits_acc_def)
  2664                      simp add: permits_acc_def)
  2755   with dynM    
  2665   with dynM    
  2756   show ?thesis
  2666   show ?thesis
  2757     by blast
  2667     by blast
  2970   assume accessible: "G \<turnstile> m in C dyn_accessible_from accC"
  2880   assume accessible: "G \<turnstile> m in C dyn_accessible_from accC"
  2971   then show "accmodi m = Package 
  2881   then show "accmodi m = Package 
  2972             \<Longrightarrow> pid accC = pid (declclass m)"
  2882             \<Longrightarrow> pid accC = pid (declclass m)"
  2973     (is "?Pack m \<Longrightarrow> ?P m")
  2883     (is "?Pack m \<Longrightarrow> ?P m")
  2974   proof (induct rule: dyn_accessible_fromR.induct)
  2884   proof (induct rule: dyn_accessible_fromR.induct)
  2975     case (immediate C m)
  2885     case (Immediate C m)
  2976     assume "G\<turnstile>m member_in C"
  2886     assume "G\<turnstile>m member_in C"
  2977            "G \<turnstile> m in C permits_acc_to accC"
  2887            "G \<turnstile> m in C permits_acc_to accC"
  2978            "accmodi m = Package"      
  2888            "accmodi m = Package"      
  2979     then show "?P m"
  2889     then show "?P m"
  2980       by (auto simp add: permits_acc_def)
  2890       by (auto simp add: permits_acc_def)
  2981   next
  2891   next
  2982     case (overriding declC C new newm old Sup)
  2892     case (Overriding declC C new newm old Sup)
  2983     assume member_new: "G \<turnstile> new member_in C" and
  2893     assume member_new: "G \<turnstile> new member_in C" and
  2984                   new: "new = (declC, mdecl newm)" and
  2894                   new: "new = (declC, mdecl newm)" and
  2985              override: "G \<turnstile> (declC, newm) overrides old" and
  2895              override: "G \<turnstile> (declC, newm) overrides old" and
  2986          subcls_C_Sup: "G\<turnstile>C \<prec>\<^sub>C Sup" and
  2896          subcls_C_Sup: "G\<turnstile>C \<prec>\<^sub>C Sup" and
  2987               acc_old: "G \<turnstile> methdMembr old in Sup dyn_accessible_from accC" and
  2897               acc_old: "G \<turnstile> methdMembr old in Sup dyn_accessible_from accC" and
  2999     with eq_pid_new_old P_sup show "?P new"
  2909     with eq_pid_new_old P_sup show "?P new"
  3000       by auto
  2910       by auto
  3001   qed
  2911   qed
  3002 qed
  2912 qed
  3003 
  2913 
       
  2914 
       
  2915 text {* @{text dyn_accessible_instance_field_Protected} only works for fields
       
  2916 since methods can break the package bounds due to overriding
       
  2917 *}
       
  2918 lemma dyn_accessible_instance_field_Protected:
       
  2919  (assumes dyn_acc: "G \<turnstile> f in C dyn_accessible_from accC" and
       
  2920              prot: "accmodi f = Protected" and
       
  2921             field: "is_field f" and
       
  2922    instance_field: "\<not> is_static f" and
       
  2923           outside: "pid (declclass f) \<noteq> pid accC"
       
  2924  ) "G\<turnstile> C \<preceq>\<^sub>C accC"
       
  2925 proof -
       
  2926   from dyn_acc prot field instance_field outside
       
  2927   show ?thesis
       
  2928   proof (induct)
       
  2929     case (Immediate C f)
       
  2930     have "G \<turnstile> f in C permits_acc_to accC" .
       
  2931     moreover 
       
  2932     assume "accmodi f = Protected" and  "is_field f" and "\<not> is_static f" and
       
  2933            "pid (declclass f) \<noteq> pid accC"
       
  2934     ultimately 
       
  2935     show "G\<turnstile> C \<preceq>\<^sub>C accC"
       
  2936       by (auto simp add: permits_acc_def)
       
  2937   next
       
  2938     case Overriding
       
  2939     then show ?case by (simp add: is_field_def)
       
  2940   qed
       
  2941 qed
       
  2942    
       
  2943 lemma dyn_accessible_static_field_Protected:
       
  2944  (assumes dyn_acc: "G \<turnstile> f in C dyn_accessible_from accC" and
       
  2945              prot: "accmodi f = Protected" and
       
  2946             field: "is_field f" and
       
  2947      static_field: "is_static f" and
       
  2948           outside: "pid (declclass f) \<noteq> pid accC"
       
  2949  ) "G\<turnstile> accC \<preceq>\<^sub>C declclass f  \<and> G\<turnstile>C \<preceq>\<^sub>C declclass f"
       
  2950 proof -
       
  2951   from dyn_acc prot field static_field outside
       
  2952   show ?thesis
       
  2953   proof (induct)
       
  2954     case (Immediate C f)
       
  2955     assume "accmodi f = Protected" and  "is_field f" and "is_static f" and
       
  2956            "pid (declclass f) \<noteq> pid accC"
       
  2957     moreover 
       
  2958     have "G \<turnstile> f in C permits_acc_to accC" .
       
  2959     ultimately
       
  2960     have "G\<turnstile> accC \<preceq>\<^sub>C declclass f"
       
  2961       by (auto simp add: permits_acc_def)
       
  2962     moreover
       
  2963     have "G \<turnstile> f member_in C" .
       
  2964     then have "G\<turnstile>C \<preceq>\<^sub>C declclass f"
       
  2965       by (rule member_in_class_relation)
       
  2966     ultimately show ?case
       
  2967       by blast
       
  2968   next
       
  2969     case Overriding
       
  2970     then show ?case by (simp add: is_field_def)
       
  2971   qed
       
  2972 qed
       
  2973 
  3004 end
  2974 end