src/HOL/Bali/TypeRel.thy
changeset 67443 3abf6a722518
parent 62042 6c6ccf573479
child 67613 ce654b0e6d69
equal deleted inserted replaced
67442:f075640b8868 67443:3abf6a722518
    30 (*subcls1, in Decl.thy*)                     (* direct subclass           *)
    30 (*subcls1, in Decl.thy*)                     (* direct subclass           *)
    31 (*subcls , by translation*)                  (*        subclass           *)
    31 (*subcls , by translation*)                  (*        subclass           *)
    32 (*subclseq, by translation*)                 (* subclass + identity       *)
    32 (*subclseq, by translation*)                 (* subclass + identity       *)
    33 
    33 
    34 definition
    34 definition
    35   implmt1 :: "prog \<Rightarrow> (qtname \<times> qtname) set" \<comment>\<open>direct implementation\<close>
    35   implmt1 :: "prog \<Rightarrow> (qtname \<times> qtname) set" \<comment> \<open>direct implementation\<close>
    36   \<comment>\<open>direct implementation, cf. 8.1.3\<close>
    36   \<comment> \<open>direct implementation, cf. 8.1.3\<close>
    37   where "implmt1 G = {(C,I). C\<noteq>Object \<and> (\<exists>c\<in>class G C: I\<in>set (superIfs c))}"
    37   where "implmt1 G = {(C,I). C\<noteq>Object \<and> (\<exists>c\<in>class G C: I\<in>set (superIfs c))}"
    38 
    38 
    39 
    39 
    40 abbreviation
    40 abbreviation
    41   subint1_syntax :: "prog => [qtname, qtname] => bool" ("_\<turnstile>_\<prec>I1_"  [71,71,71] 70)
    41   subint1_syntax :: "prog => [qtname, qtname] => bool" ("_\<turnstile>_\<prec>I1_"  [71,71,71] 70)
    42   where "G\<turnstile>I \<prec>I1 J == (I,J) \<in> subint1 G"
    42   where "G\<turnstile>I \<prec>I1 J == (I,J) \<in> subint1 G"
    43 
    43 
    44 abbreviation
    44 abbreviation
    45   subint_syntax :: "prog => [qtname, qtname] => bool" ("_\<turnstile>_\<preceq>I _"  [71,71,71] 70)
    45   subint_syntax :: "prog => [qtname, qtname] => bool" ("_\<turnstile>_\<preceq>I _"  [71,71,71] 70)
    46   where "G\<turnstile>I \<preceq>I J == (I,J) \<in>(subint1 G)^*" \<comment>\<open>cf. 9.1.3\<close>
    46   where "G\<turnstile>I \<preceq>I J == (I,J) \<in>(subint1 G)^*" \<comment> \<open>cf. 9.1.3\<close>
    47 
    47 
    48 abbreviation
    48 abbreviation
    49   implmt1_syntax :: "prog => [qtname, qtname] => bool" ("_\<turnstile>_\<leadsto>1_"  [71,71,71] 70)
    49   implmt1_syntax :: "prog => [qtname, qtname] => bool" ("_\<turnstile>_\<leadsto>1_"  [71,71,71] 70)
    50   where "G\<turnstile>C \<leadsto>1 I == (C,I) \<in> implmt1 G"
    50   where "G\<turnstile>C \<leadsto>1 I == (C,I) \<in> implmt1 G"
    51 
    51 
   332 lemma implmt1D: "G\<turnstile>C\<leadsto>1I \<Longrightarrow> C\<noteq>Object \<and> (\<exists>c\<in>class G C: I\<in>set (superIfs c))"
   332 lemma implmt1D: "G\<turnstile>C\<leadsto>1I \<Longrightarrow> C\<noteq>Object \<and> (\<exists>c\<in>class G C: I\<in>set (superIfs c))"
   333 apply (unfold implmt1_def)
   333 apply (unfold implmt1_def)
   334 apply auto
   334 apply auto
   335 done
   335 done
   336 
   336 
   337 inductive \<comment>\<open>implementation, cf. 8.1.4\<close>
   337 inductive \<comment> \<open>implementation, cf. 8.1.4\<close>
   338   implmt :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool" ("_\<turnstile>_\<leadsto>_" [71,71,71] 70)
   338   implmt :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool" ("_\<turnstile>_\<leadsto>_" [71,71,71] 70)
   339   for G :: prog
   339   for G :: prog
   340 where
   340 where
   341   direct: "G\<turnstile>C\<leadsto>1J \<Longrightarrow> G\<turnstile>C\<leadsto>J"
   341   direct: "G\<turnstile>C\<leadsto>1J \<Longrightarrow> G\<turnstile>C\<leadsto>J"
   342 | subint: "G\<turnstile>C\<leadsto>1I \<Longrightarrow> G\<turnstile>I\<preceq>I J \<Longrightarrow> G\<turnstile>C\<leadsto>J"
   342 | subint: "G\<turnstile>C\<leadsto>1I \<Longrightarrow> G\<turnstile>I\<preceq>I J \<Longrightarrow> G\<turnstile>C\<leadsto>J"
   367 
   367 
   368 
   368 
   369 subsubsection "widening relation"
   369 subsubsection "widening relation"
   370 
   370 
   371 inductive
   371 inductive
   372  \<comment>\<open>widening, viz. method invocation conversion, cf. 5.3
   372  \<comment> \<open>widening, viz. method invocation conversion, cf. 5.3
   373                             i.e. kind of syntactic subtyping\<close>
   373                             i.e. kind of syntactic subtyping\<close>
   374   widen :: "prog \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_\<turnstile>_\<preceq>_" [71,71,71] 70)
   374   widen :: "prog \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_\<turnstile>_\<preceq>_" [71,71,71] 70)
   375   for G :: prog
   375   for G :: prog
   376 where
   376 where
   377   refl:    "G\<turnstile>T\<preceq>T" \<comment>\<open>identity conversion, cf. 5.1.1\<close>
   377   refl:    "G\<turnstile>T\<preceq>T" \<comment> \<open>identity conversion, cf. 5.1.1\<close>
   378 | subint:  "G\<turnstile>I\<preceq>I J  \<Longrightarrow> G\<turnstile>Iface I\<preceq> Iface J" \<comment>\<open>wid.ref.conv.,cf. 5.1.4\<close>
   378 | subint:  "G\<turnstile>I\<preceq>I J  \<Longrightarrow> G\<turnstile>Iface I\<preceq> Iface J" \<comment> \<open>wid.ref.conv.,cf. 5.1.4\<close>
   379 | int_obj: "G\<turnstile>Iface I\<preceq> Class Object"
   379 | int_obj: "G\<turnstile>Iface I\<preceq> Class Object"
   380 | subcls:  "G\<turnstile>C\<preceq>\<^sub>C D  \<Longrightarrow> G\<turnstile>Class C\<preceq> Class D"
   380 | subcls:  "G\<turnstile>C\<preceq>\<^sub>C D  \<Longrightarrow> G\<turnstile>Class C\<preceq> Class D"
   381 | implmt:  "G\<turnstile>C\<leadsto>I   \<Longrightarrow> G\<turnstile>Class C\<preceq> Iface I"
   381 | implmt:  "G\<turnstile>C\<leadsto>I   \<Longrightarrow> G\<turnstile>Class C\<preceq> Iface I"
   382 | null:    "G\<turnstile>NT\<preceq> RefT R"
   382 | null:    "G\<turnstile>NT\<preceq> RefT R"
   383 | arr_obj: "G\<turnstile>T.[]\<preceq> Class Object"
   383 | arr_obj: "G\<turnstile>T.[]\<preceq> Class Object"
   592   cast_RefT2   "G\<turnstile>S\<preceq>? RefT R   \<Longrightarrow> \<exists>t. S=RefT t" 
   592   cast_RefT2   "G\<turnstile>S\<preceq>? RefT R   \<Longrightarrow> \<exists>t. S=RefT t" 
   593   cast_PrimT2  "G\<turnstile>S\<preceq>? PrimT pt \<Longrightarrow> \<exists>t. S=PrimT t \<and> G\<turnstile>PrimT t\<preceq>PrimT pt"
   593   cast_PrimT2  "G\<turnstile>S\<preceq>? PrimT pt \<Longrightarrow> \<exists>t. S=PrimT t \<and> G\<turnstile>PrimT t\<preceq>PrimT pt"
   594 *)
   594 *)
   595 
   595 
   596 (* more detailed than necessary for type-safety, see above rules. *)
   596 (* more detailed than necessary for type-safety, see above rules. *)
   597 inductive \<comment>\<open>narrowing reference conversion, cf. 5.1.5\<close>
   597 inductive \<comment> \<open>narrowing reference conversion, cf. 5.1.5\<close>
   598   narrow :: "prog \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_\<turnstile>_\<succ>_" [71,71,71] 70)
   598   narrow :: "prog \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_\<turnstile>_\<succ>_" [71,71,71] 70)
   599   for G :: prog
   599   for G :: prog
   600 where
   600 where
   601   subcls:  "G\<turnstile>C\<preceq>\<^sub>C D \<Longrightarrow> G\<turnstile>     Class D\<succ>Class C"
   601   subcls:  "G\<turnstile>C\<preceq>\<^sub>C D \<Longrightarrow> G\<turnstile>     Class D\<succ>Class C"
   602 | implmt:  "\<not>G\<turnstile>C\<leadsto>I \<Longrightarrow> G\<turnstile>     Class C\<succ>Iface I"
   602 | implmt:  "\<not>G\<turnstile>C\<leadsto>I \<Longrightarrow> G\<turnstile>     Class C\<succ>Iface I"
   643 lemma narrow_Boolean2: "G\<turnstile>S\<succ>PrimT Boolean \<Longrightarrow> S=PrimT Boolean"
   643 lemma narrow_Boolean2: "G\<turnstile>S\<succ>PrimT Boolean \<Longrightarrow> S=PrimT Boolean"
   644 by (ind_cases "G\<turnstile>S\<succ>PrimT Boolean")
   644 by (ind_cases "G\<turnstile>S\<succ>PrimT Boolean")
   645 
   645 
   646 subsubsection "casting relation"
   646 subsubsection "casting relation"
   647 
   647 
   648 inductive \<comment>\<open>casting conversion, cf. 5.5\<close>
   648 inductive \<comment> \<open>casting conversion, cf. 5.5\<close>
   649   cast :: "prog \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_\<turnstile>_\<preceq>? _" [71,71,71] 70)
   649   cast :: "prog \<Rightarrow> ty \<Rightarrow> ty \<Rightarrow> bool" ("_\<turnstile>_\<preceq>? _" [71,71,71] 70)
   650   for G :: prog
   650   for G :: prog
   651 where
   651 where
   652   widen:   "G\<turnstile>S\<preceq>T \<Longrightarrow> G\<turnstile>S\<preceq>? T"
   652   widen:   "G\<turnstile>S\<preceq>T \<Longrightarrow> G\<turnstile>S\<preceq>? T"
   653 | narrow:  "G\<turnstile>S\<succ>T \<Longrightarrow> G\<turnstile>S\<preceq>? T"
   653 | narrow:  "G\<turnstile>S\<succ>T \<Longrightarrow> G\<turnstile>S\<preceq>? T"