| author | nipkow | 
| Wed, 31 Mar 2004 11:02:00 +0200 | |
| changeset 14502 | 0c135fa75626 | 
| parent 14171 | 0cab06e3bbd0 | 
| child 14952 | 47455995693d | 
| permissions | -rw-r--r-- | 
| 11376 | 1  | 
(* Title: HOL/NanoJava/TypeRel.thy  | 
2  | 
ID: $Id$  | 
|
3  | 
Author: David von Oheimb  | 
|
4  | 
Copyright 2001 Technische Universitaet Muenchen  | 
|
5  | 
*)  | 
|
6  | 
||
7  | 
header "Type relations"  | 
|
8  | 
||
9  | 
theory TypeRel = Decl:  | 
|
10  | 
||
11  | 
consts  | 
|
| 
11558
 
6539627881e8
simplified vnam/vname, introduced fname, improved comments
 
oheimb 
parents: 
11376 
diff
changeset
 | 
12  | 
  widen   :: "(ty    \<times> ty   ) set"  --{* widening *}
 | 
| 
 
6539627881e8
simplified vnam/vname, introduced fname, improved comments
 
oheimb 
parents: 
11376 
diff
changeset
 | 
13  | 
  subcls1 :: "(cname \<times> cname) set"  --{* subclass *}
 | 
| 11376 | 14  | 
|
15  | 
syntax (xsymbols)  | 
|
16  | 
  widen   :: "[ty   , ty   ] => bool" ("_ \<preceq> _"    [71,71] 70)
 | 
|
17  | 
  subcls1 :: "[cname, cname] => bool" ("_ \<prec>C1 _"  [71,71] 70)
 | 
|
18  | 
  subcls  :: "[cname, cname] => bool" ("_ \<preceq>C _"   [71,71] 70)
 | 
|
19  | 
syntax  | 
|
20  | 
  widen   :: "[ty   , ty   ] => bool" ("_ <= _"   [71,71] 70)
 | 
|
21  | 
  subcls1 :: "[cname, cname] => bool" ("_ <=C1 _" [71,71] 70)
 | 
|
22  | 
  subcls  :: "[cname, cname] => bool" ("_ <=C _"  [71,71] 70)
 | 
|
23  | 
||
24  | 
translations  | 
|
25  | 
"C \<prec>C1 D" == "(C,D) \<in> subcls1"  | 
|
26  | 
"C \<preceq>C D" == "(C,D) \<in> subcls1^*"  | 
|
27  | 
"S \<preceq> T" == "(S,T) \<in> widen"  | 
|
28  | 
||
29  | 
consts  | 
|
| 14134 | 30  | 
method :: "cname => (mname \<rightharpoonup> methd)"  | 
31  | 
field :: "cname => (fname \<rightharpoonup> ty)"  | 
|
| 11376 | 32  | 
|
33  | 
||
| 11565 | 34  | 
subsection "Declarations and properties not used in the meta theory"  | 
| 11376 | 35  | 
|
| 11565 | 36  | 
text{* Direct subclass relation *}
 | 
| 11376 | 37  | 
defs  | 
38  | 
 subcls1_def: "subcls1 \<equiv> {(C,D). C\<noteq>Object \<and> (\<exists>c. class C = Some c \<and> super c=D)}"
 | 
|
| 
11558
 
6539627881e8
simplified vnam/vname, introduced fname, improved comments
 
oheimb 
parents: 
11376 
diff
changeset
 | 
39  | 
|
| 11565 | 40  | 
text{* Widening, viz. method invocation conversion *}
 | 
| 
11558
 
6539627881e8
simplified vnam/vname, introduced fname, improved comments
 
oheimb 
parents: 
11376 
diff
changeset
 | 
41  | 
inductive widen intros  | 
| 11376 | 42  | 
refl [intro!, simp]: "T \<preceq> T"  | 
43  | 
subcls : "C\<preceq>C D \<Longrightarrow> Class C \<preceq> Class D"  | 
|
44  | 
null [intro!]: "NT \<preceq> R"  | 
|
45  | 
||
46  | 
lemma subcls1D:  | 
|
47  | 
"C\<prec>C1D \<Longrightarrow> C \<noteq> Object \<and> (\<exists>c. class C = Some c \<and> super c=D)"  | 
|
48  | 
apply (unfold subcls1_def)  | 
|
49  | 
apply auto  | 
|
50  | 
done  | 
|
51  | 
||
52  | 
lemma subcls1I: "\<lbrakk>class C = Some m; super m = D; C \<noteq> Object\<rbrakk> \<Longrightarrow> C\<prec>C1D"  | 
|
53  | 
apply (unfold subcls1_def)  | 
|
54  | 
apply auto  | 
|
55  | 
done  | 
|
56  | 
||
57  | 
lemma subcls1_def2:  | 
|
| 
14171
 
0cab06e3bbd0
Extended the notion of letter and digit, such that now one may use greek,
 
skalberg 
parents: 
14134 
diff
changeset
 | 
58  | 
"subcls1 = (\<Sigma> C\<in>{C. is_class C} . {D. C\<noteq>Object \<and> super (the (class C)) = D})"
 | 
| 11376 | 59  | 
apply (unfold subcls1_def is_class_def)  | 
60  | 
apply auto  | 
|
61  | 
done  | 
|
62  | 
||
63  | 
lemma finite_subcls1: "finite subcls1"  | 
|
64  | 
apply(subst subcls1_def2)  | 
|
65  | 
apply(rule finite_SigmaI [OF finite_is_class])  | 
|
66  | 
apply(rule_tac B = "{super (the (class C))}" in finite_subset)
 | 
|
67  | 
apply auto  | 
|
68  | 
done  | 
|
69  | 
||
70  | 
constdefs  | 
|
71  | 
||
72  | 
ws_prog :: "bool"  | 
|
73  | 
"ws_prog \<equiv> \<forall>(C,c)\<in>set Prog. C\<noteq>Object \<longrightarrow>  | 
|
74  | 
is_class (super c) \<and> (super c,C)\<notin>subcls1^+"  | 
|
75  | 
||
76  | 
lemma ws_progD: "\<lbrakk>class C = Some c; C\<noteq>Object; ws_prog\<rbrakk> \<Longrightarrow>  | 
|
77  | 
is_class (super c) \<and> (super c,C)\<notin>subcls1^+"  | 
|
78  | 
apply (unfold ws_prog_def class_def)  | 
|
79  | 
apply (drule_tac map_of_SomeD)  | 
|
80  | 
apply auto  | 
|
81  | 
done  | 
|
82  | 
||
83  | 
lemma subcls1_irrefl_lemma1: "ws_prog \<Longrightarrow> subcls1^-1 \<inter> subcls1^+ = {}"
 | 
|
84  | 
by (fast dest: subcls1D ws_progD)  | 
|
85  | 
||
| 13867 | 86  | 
(* irrefl_tranclI in Transitive_Closure.thy is more general *)  | 
| 11376 | 87  | 
lemma irrefl_tranclI': "r^-1 Int r^+ = {} ==> !x. (x, x) ~: r^+"
 | 
| 13867 | 88  | 
by(blast elim: tranclE dest: trancl_into_rtrancl)  | 
89  | 
||
| 11376 | 90  | 
|
91  | 
lemmas subcls1_irrefl_lemma2 = subcls1_irrefl_lemma1 [THEN irrefl_tranclI']  | 
|
92  | 
||
93  | 
lemma subcls1_irrefl: "\<lbrakk>(x, y) \<in> subcls1; ws_prog\<rbrakk> \<Longrightarrow> x \<noteq> y"  | 
|
94  | 
apply (rule irrefl_trancl_rD)  | 
|
95  | 
apply (rule subcls1_irrefl_lemma2)  | 
|
96  | 
apply auto  | 
|
97  | 
done  | 
|
98  | 
||
99  | 
lemmas subcls1_acyclic = subcls1_irrefl_lemma2 [THEN acyclicI, standard]  | 
|
100  | 
||
101  | 
lemma wf_subcls1: "ws_prog \<Longrightarrow> wf (subcls1\<inverse>)"  | 
|
102  | 
by (auto intro: finite_acyclic_wf_converse finite_subcls1 subcls1_acyclic)  | 
|
103  | 
||
104  | 
||
| 14134 | 105  | 
consts class_rec ::"cname \<Rightarrow> (class \<Rightarrow> ('a \<times> 'b) list) \<Rightarrow> ('a \<rightharpoonup> 'b)"
 | 
| 11376 | 106  | 
|
| 11626 | 107  | 
recdef (permissive) class_rec "subcls1\<inverse>"  | 
| 11376 | 108  | 
"class_rec C = (\<lambda>f. case class C of None \<Rightarrow> arbitrary  | 
109  | 
| Some m \<Rightarrow> if wf (subcls1\<inverse>)  | 
|
110  | 
then (if C=Object then empty else class_rec (super m) f) ++ map_of (f m)  | 
|
111  | 
else arbitrary)"  | 
|
112  | 
(hints intro: subcls1I)  | 
|
113  | 
||
114  | 
lemma class_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow>  | 
|
115  | 
class_rec C f = (if C = Object then empty else class_rec (super m) f) ++  | 
|
116  | 
map_of (f m)";  | 
|
117  | 
apply (drule wf_subcls1)  | 
|
118  | 
apply (rule class_rec.simps [THEN trans [THEN fun_cong]])  | 
|
119  | 
apply assumption  | 
|
120  | 
apply simp  | 
|
121  | 
done  | 
|
122  | 
||
| 11565 | 123  | 
--{* Methods of a class, with inheritance and hiding *}
 | 
| 11376 | 124  | 
defs method_def: "method C \<equiv> class_rec C methods"  | 
125  | 
||
126  | 
lemma method_rec: "\<lbrakk>class C = Some m; ws_prog\<rbrakk> \<Longrightarrow>  | 
|
127  | 
method C = (if C=Object then empty else method (super m)) ++ map_of (methods m)"  | 
|
128  | 
apply (unfold method_def)  | 
|
129  | 
apply (erule (1) class_rec [THEN trans]);  | 
|
130  | 
apply simp  | 
|
131  | 
done  | 
|
132  | 
||
133  | 
||
| 11565 | 134  | 
--{* Fields of a class, with inheritance and hiding *}
 | 
| 
12264
 
9c356e2da72f
renamed "fields" to "flds" (avoid clash with new "fields" operation);
 
wenzelm 
parents: 
11626 
diff
changeset
 | 
135  | 
defs field_def: "field C \<equiv> class_rec C flds"  | 
| 11376 | 136  | 
|
| 
12264
 
9c356e2da72f
renamed "fields" to "flds" (avoid clash with new "fields" operation);
 
wenzelm 
parents: 
11626 
diff
changeset
 | 
137  | 
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: 
11626 
diff
changeset
 | 
138  | 
field C = (if C=Object then empty else field (super m)) ++ map_of (flds m)"  | 
| 11376 | 139  | 
apply (unfold field_def)  | 
140  | 
apply (erule (1) class_rec [THEN trans]);  | 
|
141  | 
apply simp  | 
|
142  | 
done  | 
|
143  | 
||
144  | 
end  |