src/HOL/MicroJava/J/TypeRel.thy
changeset 45970 b6d0cff57d96
parent 45231 d85a2fdc586c
child 53374 a14d2a854c02
equal deleted inserted replaced
45969:562e99c3d316 45970:b6d0cff57d96
     2     Author:     David von Oheimb, Technische Universitaet Muenchen
     2     Author:     David von Oheimb, Technische Universitaet Muenchen
     3 *)
     3 *)
     4 
     4 
     5 header {* \isaheader{Relations between Java Types} *}
     5 header {* \isaheader{Relations between Java Types} *}
     6 
     6 
     7 theory TypeRel imports Decl "~~/src/HOL/Library/Wfrec" begin
     7 theory TypeRel
       
     8 imports Decl "~~/src/HOL/Library/Wfrec"
       
     9 begin
     8 
    10 
     9 -- "direct subclass, cf. 8.1.3"
    11 -- "direct subclass, cf. 8.1.3"
    10 
    12 
    11 inductive_set
    13 inductive_set
    12   subcls1 :: "'c prog => (cname \<times> cname) set"
    14   subcls1 :: "'c prog => (cname \<times> cname) set"
    82 
    84 
    83 code_pred 
    85 code_pred 
    84   (modes: i \<Rightarrow> i \<Rightarrow> o \<Rightarrow> bool, i \<Rightarrow> i \<Rightarrow> i \<Rightarrow> bool)
    86   (modes: i \<Rightarrow> i \<Rightarrow> o \<Rightarrow> bool, i \<Rightarrow> i \<Rightarrow> i \<Rightarrow> bool)
    85   subcls1p 
    87   subcls1p 
    86   .
    88   .
    87 declare subcls1_def[unfolded Collect_def, code_pred_def]
    89 
       
    90 declare subcls1_def [code_pred_def]
       
    91 
    88 code_pred 
    92 code_pred 
    89   (modes: i \<Rightarrow> i \<times> o \<Rightarrow> bool, i \<Rightarrow> i \<times> i \<Rightarrow> bool)
    93   (modes: i \<Rightarrow> i \<times> o \<Rightarrow> bool, i \<Rightarrow> i \<times> i \<Rightarrow> bool)
    90   [inductify]
    94   [inductify]
    91   subcls1 
    95   subcls1 
    92   .
    96   .
    93 
    97 
    94 definition subcls' where "subcls' G = (subcls1p G)^**"
    98 definition subcls' where "subcls' G = (subcls1p G)^**"
       
    99 
    95 code_pred
   100 code_pred
    96   (modes: i \<Rightarrow> i \<Rightarrow> i \<Rightarrow> bool, i \<Rightarrow> i \<Rightarrow> o \<Rightarrow> bool)
   101   (modes: i \<Rightarrow> i \<Rightarrow> i \<Rightarrow> bool, i \<Rightarrow> i \<Rightarrow> o \<Rightarrow> bool)
    97   [inductify]
   102   [inductify]
    98   subcls'
   103   subcls'
    99 .
   104   .
       
   105 
   100 lemma subcls_conv_subcls' [code_unfold]:
   106 lemma subcls_conv_subcls' [code_unfold]:
   101   "(subcls1 G)^* = (\<lambda>(C, D). subcls' G C D)"
   107   "(subcls1 G)^* = {(C, D). subcls' G C D}"
   102 by(simp add: subcls'_def subcls1_def rtrancl_def)(simp add: Collect_def)
   108 by(simp add: subcls'_def subcls1_def rtrancl_def)
   103 
   109 
   104 lemma class_rec_code [code]:
   110 lemma class_rec_code [code]:
   105   "class_rec G C t f = 
   111   "class_rec G C t f = 
   106   (if wf_class G then 
   112   (if wf_class G then 
   107     (case class G C of
   113     (case class G C of
   188 lemma method_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   194 lemma method_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   189   method (G,C) = (if C = Object then empty else method (G,D)) ++  
   195   method (G,C) = (if C = Object then empty else method (G,D)) ++  
   190   map_of (map (\<lambda>(s,m). (s,(C,m))) ms)"
   196   map_of (map (\<lambda>(s,m). (s,(C,m))) ms)"
   191 apply (unfold method_def)
   197 apply (unfold method_def)
   192 apply (simp split del: split_if)
   198 apply (simp split del: split_if)
   193 apply (erule (1) class_rec_lemma [THEN trans]);
   199 apply (erule (1) class_rec_lemma [THEN trans])
   194 apply auto
   200 apply auto
   195 done
   201 done
   196 
   202 
   197 
   203 
   198 -- "list of fields of a class, including inherited and hidden ones"
   204 -- "list of fields of a class, including inherited and hidden ones"
   202 lemma fields_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   208 lemma fields_rec_lemma: "[|class G C = Some (D,fs,ms); wf ((subcls1 G)^-1)|] ==>
   203  fields (G,C) = 
   209  fields (G,C) = 
   204   map (\<lambda>(fn,ft). ((fn,C),ft)) fs @ (if C = Object then [] else fields (G,D))"
   210   map (\<lambda>(fn,ft). ((fn,C),ft)) fs @ (if C = Object then [] else fields (G,D))"
   205 apply (unfold fields_def)
   211 apply (unfold fields_def)
   206 apply (simp split del: split_if)
   212 apply (simp split del: split_if)
   207 apply (erule (1) class_rec_lemma [THEN trans]);
   213 apply (erule (1) class_rec_lemma [THEN trans])
   208 apply auto
   214 apply auto
   209 done
   215 done
   210 
   216 
   211 
   217 
   212 defs field_def [code]: "field == map_of o (map (\<lambda>((fn,fd),ft). (fn,(fd,ft)))) o fields"
   218 defs field_def [code]: "field == map_of o (map (\<lambda>((fn,fd),ft). (fn,(fd,ft)))) o fields"