| author | haftmann | 
| Mon, 03 Feb 2014 08:23:21 +0100 | |
| changeset 55293 | 42cf5802d36a | 
| parent 55017 | 2df6ad1dbd66 | 
| child 58860 | fee7cfa69c50 | 
| permissions | -rw-r--r-- | 
| 11376 | 1 | (* Title: HOL/NanoJava/TypeRel.thy | 
| 41589 | 2 | Author: David von Oheimb, Technische Universitaet Muenchen | 
| 11376 | 3 | *) | 
| 4 | ||
| 5 | header "Type relations" | |
| 6 | ||
| 55017 | 7 | theory TypeRel | 
| 8 | imports Decl | |
| 9 | begin | |
| 11376 | 10 | |
| 44375 | 11 | text{* Direct subclass relation *}
 | 
| 12 | ||
| 13 | definition subcls1 :: "(cname \<times> cname) set" | |
| 14 | where | |
| 15 |   "subcls1 \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c. class C = Some c \<and> super c=D)}"
 | |
| 11376 | 16 | |
| 35102 | 17 | abbreviation | 
| 18 |   subcls1_syntax :: "[cname, cname] => bool"  ("_ <=C1 _" [71,71] 70)
 | |
| 19 | where "C <=C1 D == (C,D) \<in> subcls1" | |
| 20 | abbreviation | |
| 21 |   subcls_syntax  :: "[cname, cname] => bool" ("_ <=C _"  [71,71] 70)
 | |
| 22 | where "C <=C D == (C,D) \<in> subcls1^*" | |
| 11376 | 23 | |
| 35102 | 24 | notation (xsymbols) | 
| 25 |   subcls1_syntax  ("_ \<prec>C1 _"  [71,71] 70) and
 | |
| 26 |   subcls_syntax  ("_ \<preceq>C _"   [71,71] 70)
 | |
| 11376 | 27 | |
| 28 | ||
| 11565 | 29 | subsection "Declarations and properties not used in the meta theory" | 
| 11376 | 30 | |
| 11565 | 31 | text{* Widening, viz. method invocation conversion *}
 | 
| 23755 | 32 | inductive | 
| 33 |   widen :: "ty => ty => bool"  ("_ \<preceq> _" [71,71] 70)
 | |
| 34 | where | |
| 35 | refl [intro!, simp]: "T \<preceq> T" | |
| 36 | | subcls: "C\<preceq>C D \<Longrightarrow> Class C \<preceq> Class D" | |
| 37 | | null [intro!]: "NT \<preceq> R" | |
| 11376 | 38 | |
| 39 | lemma subcls1D: | |
| 40 | "C\<prec>C1D \<Longrightarrow> C \<noteq> Object \<and> (\<exists>c. class C = Some c \<and> super c=D)" | |
| 41 | apply (unfold subcls1_def) | |
| 42 | apply auto | |
| 43 | done | |
| 44 | ||
| 45 | lemma subcls1I: "\<lbrakk>class C = Some m; super m = D; C \<noteq> Object\<rbrakk> \<Longrightarrow> C\<prec>C1D" | |
| 46 | apply (unfold subcls1_def) | |
| 47 | apply auto | |
| 48 | done | |
| 49 | ||
| 50 | lemma subcls1_def2: | |
| 14952 
47455995693d
removal of x-symbol syntax <Sigma> for dependent products
 paulson parents: 
14171diff
changeset | 51 | "subcls1 = | 
| 
47455995693d
removal of x-symbol syntax <Sigma> for dependent products
 paulson parents: 
14171diff
changeset | 52 |     (SIGMA C: {C. is_class C} . {D. C\<noteq>Object \<and> super (the (class C)) = D})"
 | 
| 11376 | 53 | apply (unfold subcls1_def is_class_def) | 
| 31166 
a90fe83f58ea
"{x. P x & x=t & Q x}" is now rewritten to "if P t & Q t then {t} else {}"
 nipkow parents: 
28524diff
changeset | 54 | apply (auto split:split_if_asm) | 
| 11376 | 55 | done | 
| 56 | ||
| 57 | lemma finite_subcls1: "finite subcls1" | |
| 58 | apply(subst subcls1_def2) | |
| 59 | apply(rule finite_SigmaI [OF finite_is_class]) | |
| 60 | apply(rule_tac B = "{super (the (class C))}" in finite_subset)
 | |
| 61 | apply auto | |
| 62 | done | |
| 63 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
35102diff
changeset | 64 | definition ws_prog :: "bool" where | 
| 11376 | 65 | "ws_prog \<equiv> \<forall>(C,c)\<in>set Prog. C\<noteq>Object \<longrightarrow> | 
| 66 | is_class (super c) \<and> (super c,C)\<notin>subcls1^+" | |
| 67 | ||
| 68 | lemma ws_progD: "\<lbrakk>class C = Some c; C\<noteq>Object; ws_prog\<rbrakk> \<Longrightarrow> | |
| 69 | is_class (super c) \<and> (super c,C)\<notin>subcls1^+" | |
| 70 | apply (unfold ws_prog_def class_def) | |
| 71 | apply (drule_tac map_of_SomeD) | |
| 72 | apply auto | |
| 73 | done | |
| 74 | ||
| 75 | lemma subcls1_irrefl_lemma1: "ws_prog \<Longrightarrow> subcls1^-1 \<inter> subcls1^+ = {}"
 | |
| 76 | by (fast dest: subcls1D ws_progD) | |
| 77 | ||
| 13867 | 78 | (* irrefl_tranclI in Transitive_Closure.thy is more general *) | 
| 11376 | 79 | lemma irrefl_tranclI': "r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+"
 | 
| 13867 | 80 | by(blast elim: tranclE dest: trancl_into_rtrancl) | 
| 81 | ||
| 11376 | 82 | |
| 83 | lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI'] | |
| 84 | ||
| 85 | lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1; ws_prog\<rbrakk> \<Longrightarrow> x \<noteq> y" | |
| 86 | apply (rule irrefl_trancl_rD) | |
| 87 | apply (rule subcls1_irrefl_lemma2) | |
| 88 | apply auto | |
| 89 | done | |
| 90 | ||
| 45605 | 91 | lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI] | 
| 11376 | 92 | |
| 93 | lemma wf_subcls1: "ws_prog \<Longrightarrow> wf (subcls1\<inverse>)" | |
| 94 | by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic) | |
| 95 | ||
| 44146 | 96 | definition class_rec ::"cname \<Rightarrow> (class \<Rightarrow> ('a \<times> 'b) list) \<Rightarrow> ('a \<rightharpoonup> 'b)"
 | 
| 97 | where | |
| 98 | "class_rec \<equiv> wfrec (subcls1\<inverse>) (\<lambda>rec C f. | |
| 99 | case class C of None \<Rightarrow> undefined | |
| 100 | | Some m \<Rightarrow> (if C = Object then empty else rec (super m) f) ++ map_of (f m))" | |
| 11376 | 101 | |
| 102 | lemma class_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow> | |
| 103 | class_rec C f = (if C = Object then empty else class_rec (super m) f) ++ | |
| 44146 | 104 | map_of (f m)" | 
| 11376 | 105 | apply (drule wf_subcls1) | 
| 44146 | 106 | apply (subst def_wfrec[OF class_rec_def], auto) | 
| 107 | apply (subst cut_apply, auto intro: subcls1I) | |
| 11376 | 108 | done | 
| 109 | ||
| 11565 | 110 | --{* Methods of a class, with inheritance and hiding *}
 | 
| 44375 | 111 | definition method :: "cname => (mname \<rightharpoonup> methd)" where | 
| 112 | "method C \<equiv> class_rec C methods" | |
| 11376 | 113 | |
| 114 | lemma method_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow> | |
| 115 | method C = (if C=Object then empty else method (super m)) ++ map_of (methods m)" | |
| 116 | apply (unfold method_def) | |
| 117 | apply (erule (1) class_rec [THEN trans]); | |
| 118 | apply simp | |
| 119 | done | |
| 120 | ||
| 121 | ||
| 11565 | 122 | --{* Fields of a class, with inheritance and hiding *}
 | 
| 44375 | 123 | definition field :: "cname => (fname \<rightharpoonup> ty)" where | 
| 124 | "field C \<equiv> class_rec C flds" | |
| 11376 | 125 | |
| 12264 
9c356e2da72f
renamed "fields" to "flds" (avoid clash with new "fields" operation);
 wenzelm parents: 
11626diff
changeset | 126 | lemma flds_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow> | 
| 
9c356e2da72f
renamed "fields" to "flds" (avoid clash with new "fields" operation);
 wenzelm parents: 
11626diff
changeset | 127 | field C = (if C=Object then empty else field (super m)) ++ map_of (flds m)" | 
| 11376 | 128 | apply (unfold field_def) | 
| 129 | apply (erule (1) class_rec [THEN trans]); | |
| 130 | apply simp | |
| 131 | done | |
| 132 | ||
| 133 | end |