src/HOL/Bali/DeclConcepts.thy
changeset 69597 ff784d5a5bfb
parent 68451 c34aa23a1fb6
child 71547 d350aabace23
equal deleted inserted replaced
69596:c8a2755bf220 69597:ff784d5a5bfb
   798                     \<or>
   798                     \<or>
   799                     (G\<turnstile>accclass \<prec>\<^sub>C declclass membr 
   799                     (G\<turnstile>accclass \<prec>\<^sub>C declclass membr 
   800                      \<and> (G\<turnstile>cls \<preceq>\<^sub>C accclass \<or> is_static membr)) 
   800                      \<and> (G\<turnstile>cls \<preceq>\<^sub>C accclass \<or> is_static membr)) 
   801     | Public    \<Rightarrow> True)"
   801     | Public    \<Rightarrow> True)"
   802 text \<open>
   802 text \<open>
   803 The subcondition of the @{term "Protected"} case: 
   803 The subcondition of the \<^term>\<open>Protected\<close> case: 
   804 @{term "G\<turnstile>accclass \<prec>\<^sub>C declclass membr"} could also be relaxed to:
   804 \<^term>\<open>G\<turnstile>accclass \<prec>\<^sub>C declclass membr\<close> could also be relaxed to:
   805 @{term "G\<turnstile>accclass \<preceq>\<^sub>C declclass membr"} since in case both classes are the
   805 \<^term>\<open>G\<turnstile>accclass \<preceq>\<^sub>C declclass membr\<close> since in case both classes are the
   806 same the other condition @{term "(pid (declclass membr) = pid accclass)"}
   806 same the other condition \<^term>\<open>(pid (declclass membr) = pid accclass)\<close>
   807 holds anyway.
   807 holds anyway.
   808 \<close> 
   808 \<close> 
   809 
   809 
   810 text \<open>Like in case of overriding, the static and dynamic accessibility 
   810 text \<open>Like in case of overriding, the static and dynamic accessibility 
   811 of members is not uniform.
   811 of members is not uniform.
  1420              (\<lambda>C c subcls_mthds. 
  1420              (\<lambda>C c subcls_mthds. 
  1421                filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m)
  1421                filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m)
  1422                           subcls_mthds 
  1422                           subcls_mthds 
  1423                ++ 
  1423                ++ 
  1424                table_of (map (\<lambda>(s,m). (s,C,m)) (methods c)))"
  1424                table_of (map (\<lambda>(s,m). (s,C,m)) (methods c)))"
  1425 text \<open>@{term "methd G C"}: methods of a class C (statically visible from C), 
  1425 text \<open>\<^term>\<open>methd G C\<close>: methods of a class C (statically visible from C), 
  1426      with inheritance and hiding cf. 8.4.6;
  1426      with inheritance and hiding cf. 8.4.6;
  1427      Overriding is captured by \<open>dynmethd\<close>.
  1427      Overriding is captured by \<open>dynmethd\<close>.
  1428      Every new method with the same signature coalesces the
  1428      Every new method with the same signature coalesces the
  1429      method of a superclass.\<close>
  1429      method of a superclass.\<close>
  1430 
  1430 
  1431 definition
  1431 definition
  1432   accmethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname  \<Rightarrow> (sig,qtname \<times> methd) table" where
  1432   accmethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname  \<Rightarrow> (sig,qtname \<times> methd) table" where
  1433   "accmethd G S C =
  1433   "accmethd G S C =
  1434     filter_tab (\<lambda>sig m. G\<turnstile>method sig m of C accessible_from S) (methd G C)"
  1434     filter_tab (\<lambda>sig m. G\<turnstile>method sig m of C accessible_from S) (methd G C)"
  1435 text \<open>@{term "accmethd G S C"}: only those methods of @{term "methd G C"}, 
  1435 text \<open>\<^term>\<open>accmethd G S C\<close>: only those methods of \<^term>\<open>methd G C\<close>, 
  1436         accessible from S\<close>
  1436         accessible from S\<close>
  1437 
  1437 
  1438 text \<open>Note the class component in the accessibility filter. The class where
  1438 text \<open>Note the class component in the accessibility filter. The class where
  1439     method @{term m} is declared (@{term declC}) isn't necessarily accessible 
  1439     method \<^term>\<open>m\<close> is declared (\<^term>\<open>declC\<close>) isn't necessarily accessible 
  1440     from the current scope @{term S}. The method can be made accessible 
  1440     from the current scope \<^term>\<open>S\<close>. The method can be made accessible 
  1441     through inheritance, too.
  1441     through inheritance, too.
  1442     So we must test accessibility of method @{term m} of class @{term C} 
  1442     So we must test accessibility of method \<^term>\<open>m\<close> of class \<^term>\<open>C\<close> 
  1443     (not @{term "declclass m"})\<close>
  1443     (not \<^term>\<open>declclass m\<close>)\<close>
  1444 
  1444 
  1445 definition
  1445 definition
  1446   dynmethd :: "prog  \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where
  1446   dynmethd :: "prog  \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where
  1447   "dynmethd G statC dynC =
  1447   "dynmethd G statC dynC =
  1448     (\<lambda>sig.
  1448     (\<lambda>sig.
  1459                               (methd G C) ))
  1459                               (methd G C) ))
  1460                         ) sig
  1460                         ) sig
  1461                 )
  1461                 )
  1462           else None))"
  1462           else None))"
  1463 
  1463 
  1464 text \<open>@{term "dynmethd G statC dynC"}: dynamic method lookup of a reference 
  1464 text \<open>\<^term>\<open>dynmethd G statC dynC\<close>: dynamic method lookup of a reference 
  1465         with dynamic class @{term dynC} and static class @{term statC}\<close>
  1465         with dynamic class \<^term>\<open>dynC\<close> and static class \<^term>\<open>statC\<close>\<close>
  1466 text \<open>Note some kind of duality between @{term methd} and @{term dynmethd} 
  1466 text \<open>Note some kind of duality between \<^term>\<open>methd\<close> and \<^term>\<open>dynmethd\<close> 
  1467         in the @{term class_rec} arguments. Whereas @{term methd} filters the 
  1467         in the \<^term>\<open>class_rec\<close> arguments. Whereas \<^term>\<open>methd\<close> filters the 
  1468         subclass methods (to get only the inherited ones), @{term dynmethd} 
  1468         subclass methods (to get only the inherited ones), \<^term>\<open>dynmethd\<close> 
  1469         filters the new methods (to get only those methods which actually
  1469         filters the new methods (to get only those methods which actually
  1470         override the methods of the static class)\<close>
  1470         override the methods of the static class)\<close>
  1471 
  1471 
  1472 definition
  1472 definition
  1473   dynimethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where
  1473   dynimethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where
  1474   "dynimethd G I dynC =
  1474   "dynimethd G I dynC =
  1475     (\<lambda>sig. if imethds G I sig \<noteq> {}
  1475     (\<lambda>sig. if imethds G I sig \<noteq> {}
  1476            then methd G dynC sig
  1476            then methd G dynC sig
  1477            else dynmethd G Object dynC sig)"
  1477            else dynmethd G Object dynC sig)"
  1478 text \<open>@{term "dynimethd G I dynC"}: dynamic method lookup of a reference with 
  1478 text \<open>\<^term>\<open>dynimethd G I dynC\<close>: dynamic method lookup of a reference with 
  1479         dynamic class dynC and static interface type I\<close>
  1479         dynamic class dynC and static interface type I\<close>
  1480 text \<open>
  1480 text \<open>
  1481    When calling an interface method, we must distinguish if the method signature
  1481    When calling an interface method, we must distinguish if the method signature
  1482    was defined in the interface or if it must be an Object method in the other
  1482    was defined in the interface or if it must be an Object method in the other
  1483    case. If it was an interface method we search the class hierarchy
  1483    case. If it was an interface method we search the class hierarchy
  1484    starting at the dynamic class of the object up to Object to find the 
  1484    starting at the dynamic class of the object up to Object to find the 
  1485    first matching method (@{term methd}). Since all interface methods have 
  1485    first matching method (\<^term>\<open>methd\<close>). Since all interface methods have 
  1486    public access the method can't be coalesced due to some odd visibility 
  1486    public access the method can't be coalesced due to some odd visibility 
  1487    effects like in case of dynmethd. The method will be inherited or 
  1487    effects like in case of dynmethd. The method will be inherited or 
  1488    overridden in all classes from the first class implementing the interface 
  1488    overridden in all classes from the first class implementing the interface 
  1489    down to the actual dynamic class.
  1489    down to the actual dynamic class.
  1490 \<close>
  1490 \<close>
  1495     (case statT of
  1495     (case statT of
  1496       NullT        \<Rightarrow> Map.empty
  1496       NullT        \<Rightarrow> Map.empty
  1497     | IfaceT I     \<Rightarrow> dynimethd G I      dynC
  1497     | IfaceT I     \<Rightarrow> dynimethd G I      dynC
  1498     | ClassT statC \<Rightarrow> dynmethd  G statC  dynC
  1498     | ClassT statC \<Rightarrow> dynmethd  G statC  dynC
  1499     | ArrayT ty    \<Rightarrow> dynmethd  G Object dynC)"
  1499     | ArrayT ty    \<Rightarrow> dynmethd  G Object dynC)"
  1500 text \<open>@{term "dynlookup G statT dynC"}: dynamic lookup of a method within the 
  1500 text \<open>\<^term>\<open>dynlookup G statT dynC\<close>: dynamic lookup of a method within the 
  1501     static reference type statT and the dynamic class dynC. 
  1501     static reference type statT and the dynamic class dynC. 
  1502     In a wellformd context statT will not be NullT and in case
  1502     In a wellformd context statT will not be NullT and in case
  1503     statT is an array type, dynC=Object\<close>
  1503     statT is an array type, dynC=Object\<close>
  1504 
  1504 
  1505 definition
  1505 definition
  1506   fields :: "prog \<Rightarrow> qtname \<Rightarrow> ((vname \<times> qtname) \<times> field) list" where
  1506   fields :: "prog \<Rightarrow> qtname \<Rightarrow> ((vname \<times> qtname) \<times> field) list" where
  1507   "fields G C =
  1507   "fields G C =
  1508     class_rec G C [] (\<lambda>C c ts. map (\<lambda>(n,t). ((n,C),t)) (cfields c) @ ts)"
  1508     class_rec G C [] (\<lambda>C c ts. map (\<lambda>(n,t). ((n,C),t)) (cfields c) @ ts)"
  1509 text \<open>@{term "fields G C"} 
  1509 text \<open>\<^term>\<open>fields G C\<close> 
  1510      list of fields of a class, including all the fields of the superclasses
  1510      list of fields of a class, including all the fields of the superclasses
  1511      (private, inherited and hidden ones) not only the accessible ones
  1511      (private, inherited and hidden ones) not only the accessible ones
  1512      (an instance of a object allocates all these fields\<close>
  1512      (an instance of a object allocates all these fields\<close>
  1513 
  1513 
  1514 definition
  1514 definition
  1515   accfield :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (vname, qtname  \<times>  field) table" where
  1515   accfield :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (vname, qtname  \<times>  field) table" where
  1516   "accfield G S C =
  1516   "accfield G S C =
  1517     (let field_tab = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (fields G C))
  1517     (let field_tab = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (fields G C))
  1518       in filter_tab (\<lambda>n (declC,f). G\<turnstile> (declC,fdecl (n,f)) of C accessible_from S)
  1518       in filter_tab (\<lambda>n (declC,f). G\<turnstile> (declC,fdecl (n,f)) of C accessible_from S)
  1519                     field_tab)"
  1519                     field_tab)"
  1520 text  \<open>@{term "accfield G C S"}: fields of a class @{term C} which are 
  1520 text  \<open>\<^term>\<open>accfield G C S\<close>: fields of a class \<^term>\<open>C\<close> which are 
  1521          accessible from scope of class
  1521          accessible from scope of class
  1522          @{term S} with inheritance and hiding, cf. 8.3\<close>
  1522          \<^term>\<open>S\<close> with inheritance and hiding, cf. 8.3\<close>
  1523 text \<open>note the class component in the accessibility filter (see also 
  1523 text \<open>note the class component in the accessibility filter (see also 
  1524         @{term methd}).
  1524         \<^term>\<open>methd\<close>).
  1525    The class declaring field @{term f} (@{term declC}) isn't necessarily 
  1525    The class declaring field \<^term>\<open>f\<close> (\<^term>\<open>declC\<close>) isn't necessarily 
  1526    accessible from scope @{term S}. The field can be made visible through 
  1526    accessible from scope \<^term>\<open>S\<close>. The field can be made visible through 
  1527    inheritance, too. So we must test accessibility of field @{term f} of class 
  1527    inheritance, too. So we must test accessibility of field \<^term>\<open>f\<close> of class 
  1528    @{term C} (not @{term "declclass f"})\<close> 
  1528    \<^term>\<open>C\<close> (not \<^term>\<open>declclass f\<close>)\<close> 
  1529 
  1529 
  1530 definition
  1530 definition
  1531   is_methd :: "prog \<Rightarrow> qtname  \<Rightarrow> sig \<Rightarrow> bool"
  1531   is_methd :: "prog \<Rightarrow> qtname  \<Rightarrow> sig \<Rightarrow> bool"
  1532   where "is_methd G = (\<lambda>C sig. is_class G C \<and> methd G C sig \<noteq> None)"
  1532   where "is_methd G = (\<lambda>C sig. is_class G C \<and> methd G C sig \<noteq> None)"
  1533 
  1533