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