src/HOL/MicroJava/J/TypeRel.thy
author oheimb
Wed Jan 05 18:27:07 2000 +0100 (2000-01-05)
changeset 8106 de9fae0cdfde
parent 8082 381716a86fcb
child 9246 91423cd08c6f
permissions -rw-r--r--
improved symbol for subcls relation
nipkow@8011
     1
(*  Title:      HOL/MicroJava/J/TypeRel.thy
nipkow@8011
     2
    ID:         $Id$
nipkow@8011
     3
    Author:     David von Oheimb
nipkow@8011
     4
    Copyright   1999 Technische Universitaet Muenchen
nipkow@8011
     5
nipkow@8011
     6
The relations between Java types
nipkow@8011
     7
*)
nipkow@8011
     8
nipkow@8011
     9
TypeRel = Prog +
nipkow@8011
    10
nipkow@8011
    11
consts
nipkow@8011
    12
  subcls1	:: "'c prog \\<Rightarrow> (cname \\<times> cname) set" (*        subclass *)
nipkow@8011
    13
  widen,				 	    (*        widening *)
nipkow@8011
    14
  cast		:: "'c prog \\<Rightarrow> (ty \\<times> ty) set"	    (*        casting *)
nipkow@8011
    15
nipkow@8011
    16
syntax
nipkow@8011
    17
  subcls1	:: "'c prog \\<Rightarrow> [cname, cname] \\<Rightarrow> bool" ("_\\<turnstile>_\\<prec>C1_"	 [71,71,71] 70)
oheimb@8106
    18
  subcls	:: "'c prog \\<Rightarrow> [cname, cname] \\<Rightarrow> bool" ("_\\<turnstile>_\\<preceq>C _"	 [71,71,71] 70)
nipkow@8011
    19
  widen		:: "'c prog \\<Rightarrow> [ty, ty] \\<Rightarrow> bool"       ("_\\<turnstile>_\\<preceq>_"  [71,71,71] 70)
nipkow@8011
    20
  cast		:: "'c prog \\<Rightarrow> [ty, ty] \\<Rightarrow> bool"       ("_\\<turnstile>_\\<Rightarrow>? _"[71,71,71] 70)
nipkow@8011
    21
nipkow@8011
    22
translations
nipkow@8011
    23
  	"G\\<turnstile>C \\<prec>C1 D" == "(C,D) \\<in> subcls1 G"
oheimb@8106
    24
	"G\\<turnstile>C \\<preceq>C  D" == "(C,D) \\<in> (subcls1 G)^*"
nipkow@8011
    25
	"G\\<turnstile>S \\<preceq>   T" == "(S,T) \\<in> widen   G"
nipkow@8011
    26
	"G\\<turnstile>S \\<Rightarrow>?  T" == "(S,T) \\<in> cast    G"
nipkow@8011
    27
nipkow@8011
    28
defs
nipkow@8011
    29
nipkow@8011
    30
  (* direct subclass, cf. 8.1.3 *)
nipkow@8011
    31
  subcls1_def	"subcls1 G \\<equiv> {(C,D). \\<exists>c. class G C = Some c \\<and> fst c = Some D}"
nipkow@8011
    32
  
nipkow@8011
    33
consts
nipkow@8011
    34
nipkow@8034
    35
  method	:: "'c prog \\<times> cname \\<Rightarrow> ( sig   \\<leadsto> cname \\<times> ty \\<times> 'c)"
nipkow@8034
    36
  field	:: "'c prog \\<times> cname \\<Rightarrow> ( vname \\<leadsto> cname \\<times> ty)"
nipkow@8011
    37
  fields	:: "'c prog \\<times> cname \\<Rightarrow> ((vname \\<times> cname) \\<times>  ty) list"
nipkow@8011
    38
nipkow@8011
    39
constdefs       (* auxiliary relations for recursive definitions below *)
nipkow@8011
    40
nipkow@8011
    41
  subcls1_rel	:: "(('c prog \\<times> cname) \\<times> ('c prog \\<times> cname)) set"
nipkow@8011
    42
 "subcls1_rel \\<equiv> {((G,C),(G',C')). G = G' \\<and>  wf ((subcls1 G)^-1) \\<and>  G\\<turnstile>C'\\<prec>C1C}"
nipkow@8011
    43
nipkow@8011
    44
(* methods of a class, with inheritance, overriding and hiding, cf. 8.4.6 *)
nipkow@8034
    45
recdef method "subcls1_rel"
nipkow@8034
    46
 "method (G,C) = (if wf((subcls1 G)^-1) then (case class G C of None \\<Rightarrow> empty
nipkow@8011
    47
                   | Some (sc,fs,ms) \\<Rightarrow> (case sc of None \\<Rightarrow> empty | Some D \\<Rightarrow> 
nipkow@8034
    48
                                           if is_class G D then method (G,D) 
nipkow@8011
    49
                                                           else arbitrary) \\<oplus>
nipkow@8011
    50
                                           map_of (map (\\<lambda>(s,  m ). 
nipkow@8011
    51
                                                        (s,(C,m))) ms))
nipkow@8011
    52
                  else arbitrary)"
nipkow@8011
    53
nipkow@8011
    54
(* list of fields of a class, including inherited and hidden ones *)
nipkow@8011
    55
recdef fields  "subcls1_rel"
nipkow@8011
    56
 "fields (G,C) = (if wf((subcls1 G)^-1) then (case class G C of None \\<Rightarrow> arbitrary
nipkow@8011
    57
                   | Some (sc,fs,ms) \\<Rightarrow> map (\\<lambda>(fn,ft). ((fn,C),ft)) fs@
nipkow@8011
    58
                                           (case sc of None \\<Rightarrow> [] | Some D \\<Rightarrow> 
nipkow@8011
    59
                                           if is_class G D then fields (G,D) 
nipkow@8011
    60
                                                           else arbitrary))
nipkow@8011
    61
                  else arbitrary)"
nipkow@8011
    62
defs
nipkow@8011
    63
nipkow@8034
    64
  field_def "field \\<equiv> map_of o (map (\\<lambda>((fn,fd),ft). (fn,(fd,ft)))) o fields"
nipkow@8011
    65
nipkow@8011
    66
inductive "widen G" intrs (*widening, viz. method invocation conversion, cf. 5.3
nipkow@8011
    67
			     i.e. sort of syntactic subtyping *)
nipkow@8011
    68
  refl	              "G\\<turnstile>      T \\<preceq> T" 	 (* identity conv., cf. 5.1.1 *)
oheimb@8106
    69
  subcls "G\\<turnstile>C\\<preceq>C D \\<Longrightarrow> G\\<turnstile>Class C \\<preceq> Class D"
nipkow@8011
    70
  null	              "G\\<turnstile>     NT \\<preceq> RefT R"
nipkow@8011
    71
nipkow@8011
    72
inductive "cast G" intrs (* casting / narr.ref. conversion, cf. 5.5 / 5.1.5 *)
nipkow@8011
    73
  widen	 "G\\<turnstile>S\\<preceq>T  \\<Longrightarrow> G\\<turnstile>      S \\<Rightarrow>? T"
oheimb@8106
    74
  subcls "G\\<turnstile>C\\<preceq>C D \\<Longrightarrow> G\\<turnstile>Class D \\<Rightarrow>? Class C"
nipkow@8011
    75
nipkow@8011
    76
end