src/HOL/Bali/State.thy
author wenzelm
Mon, 25 Feb 2002 20:48:14 +0100
changeset 12937 0c4fd7529467
parent 12925 99131847fb93
child 13337 f75dfc606ac7
permissions -rw-r--r--
clarified syntax of ``long'' statements: fixes/assumes/shows;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12857
a4386cc9b1c3 tuned header;
wenzelm
parents: 12854
diff changeset
     1
(*  Title:      HOL/Bali/State.thy
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     2
    ID:         $Id$
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     3
    Author:     David von Oheimb
12858
wenzelm
parents: 12857
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     5
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     6
header {* State for evaluation of Java expressions and statements *}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     7
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     8
theory State = DeclConcepts:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
     9
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    10
text {*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    11
design issues:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    12
\begin{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    13
\item all kinds of objects (class instances, arrays, and class objects)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    14
  are handeled via a general object abstraction
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    15
\item the heap and the map for class objects are combined into a single table
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    16
  @{text "(recall (loc, obj) table \<times> (qtname, obj) table  ~=  (loc + qtname, obj) table)"}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    17
\end{itemize}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    18
*}
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    19
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    20
section "objects"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    21
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    22
datatype  obj_tag =     (* tag for generic object   *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    23
	  CInst qtname   (* class instance           *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    24
	| Arr  ty int   (* array with component type and length *)
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
    25
     (* | CStat qtname     the tag is irrelevant for a class object,
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
    26
			   i.e. the static fields of a class,
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
    27
                           since its type is given already by the reference to 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
    28
                           it (see below) *)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    29
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    30
types	vn   = "fspec + int"                    (* variable name      *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    31
record	obj  = 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    32
          tag :: "obj_tag"                      (* generalized object *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    33
          values :: "(vn, val) table"      
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    34
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    35
translations 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    36
  "fspec" <= (type) "vname \<times> qtname" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    37
  "vn"    <= (type) "fspec + int"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    38
  "obj"   <= (type) "\<lparr>tag::obj_tag, values::vn \<Rightarrow> val option\<rparr>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    39
  "obj"   <= (type) "\<lparr>tag::obj_tag, values::vn \<Rightarrow> val option,\<dots>::'a\<rparr>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    40
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    41
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    42
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    43
  the_Arr :: "obj option \<Rightarrow> ty \<times> int \<times> (vn, val) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    44
 "the_Arr obj \<equiv> \<epsilon>(T,k,t). obj = Some \<lparr>tag=Arr T k,values=t\<rparr>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    45
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    46
lemma the_Arr_Arr [simp]: "the_Arr (Some \<lparr>tag=Arr T k,values=cs\<rparr>) = (T,k,cs)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    47
apply (auto simp: the_Arr_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    48
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    49
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    50
lemma the_Arr_Arr1 [simp,intro,dest]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    51
 "\<lbrakk>tag obj = Arr T k\<rbrakk> \<Longrightarrow> the_Arr (Some obj) = (T,k,values obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    52
apply (auto simp add: the_Arr_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    53
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    54
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    55
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    56
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    57
  upd_obj       :: "vn \<Rightarrow> val \<Rightarrow> obj \<Rightarrow> obj" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    58
 "upd_obj n v \<equiv> \<lambda> obj . obj \<lparr>values:=(values obj)(n\<mapsto>v)\<rparr>"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    59
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    60
lemma upd_obj_def2 [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    61
  "upd_obj n v obj = obj \<lparr>values:=(values obj)(n\<mapsto>v)\<rparr>" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    62
apply (auto simp: upd_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    63
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    64
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    65
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    66
  obj_ty        :: "obj \<Rightarrow> ty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    67
 "obj_ty obj    \<equiv> case tag obj of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    68
                    CInst C \<Rightarrow> Class C 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    69
                  | Arr T k \<Rightarrow> T.[]"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    70
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    71
lemma obj_ty_eq [intro!]: "obj_ty \<lparr>tag=oi,values=x\<rparr> = obj_ty \<lparr>tag=oi,values=y\<rparr>" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    72
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    73
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    74
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    75
lemma obj_ty_eq1 [intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    76
  "tag obj = tag obj' \<Longrightarrow> obj_ty obj = obj_ty obj'" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    77
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    78
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    79
lemma obj_ty_cong [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    80
  "obj_ty (obj \<lparr>values:=vs\<rparr>) = obj_ty obj" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    81
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    82
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    83
lemma obj_ty_cong [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    84
  "obj_ty (obj \<lparr>values:=vs(n\<mapsto>v)\<rparr>) = obj_ty (obj \<lparr>values:=vs\<rparr>)" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    85
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    86
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    87
lemma obj_ty_CInst [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    88
 "obj_ty \<lparr>tag=CInst C,values=vs\<rparr> = Class C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    89
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    90
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    91
lemma obj_ty_CInst1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    92
 "\<lbrakk>tag obj = CInst C\<rbrakk> \<Longrightarrow> obj_ty obj = Class C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    93
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    94
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    95
lemma obj_ty_Arr [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    96
 "obj_ty \<lparr>tag=Arr T i,values=vs\<rparr> = T.[]"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    97
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    98
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
    99
lemma obj_ty_Arr1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   100
 "\<lbrakk>tag obj = Arr T i\<rbrakk> \<Longrightarrow> obj_ty obj = T.[]"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   101
by (simp add: obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   102
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   103
lemma obj_ty_widenD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   104
 "G\<turnstile>obj_ty obj\<preceq>RefT t \<Longrightarrow> (\<exists>C. tag obj = CInst C) \<or> (\<exists>T k. tag obj = Arr T k)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   105
apply (unfold obj_ty_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   106
apply (auto split add: obj_tag.split_asm)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   107
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   108
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   109
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   110
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   111
  obj_class :: "obj \<Rightarrow> qtname"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   112
 "obj_class obj \<equiv> case tag obj of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   113
                    CInst C \<Rightarrow> C 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   114
                  | Arr T k \<Rightarrow> Object"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   115
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   116
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   117
lemma obj_class_CInst [simp]: "obj_class \<lparr>tag=CInst C,values=vs\<rparr> = C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   118
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   119
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   120
lemma obj_class_CInst1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   121
  "tag obj = CInst C \<Longrightarrow> obj_class obj = C" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   122
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   123
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   124
lemma obj_class_Arr [simp]: "obj_class \<lparr>tag=Arr T k,values=vs\<rparr> = Object" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   125
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   126
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   127
lemma obj_class_Arr1 [simp,intro!,dest]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   128
 "tag obj = Arr T k \<Longrightarrow> obj_class obj = Object" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   129
by (auto simp: obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   130
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   131
lemma obj_ty_obj_class: "G\<turnstile>obj_ty obj\<preceq> Class statC = G\<turnstile>obj_class obj \<preceq>\<^sub>C statC"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   132
apply (case_tac "tag obj")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   133
apply (auto simp add: obj_ty_def obj_class_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   134
apply (case_tac "statC = Object")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   135
apply (auto dest: widen_Array_Class)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   136
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   137
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   138
section "object references"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   139
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   140
types oref = "loc + qtname"          (* generalized object reference *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   141
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   142
  Heap  :: "loc   \<Rightarrow> oref"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   143
  Stat  :: "qtname \<Rightarrow> oref"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   144
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   145
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   146
  "Heap" => "Inl"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   147
  "Stat" => "Inr"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   148
  "oref" <= (type) "loc + qtname"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   149
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   150
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   151
  fields_table::
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   152
    "prog \<Rightarrow> qtname \<Rightarrow> (fspec \<Rightarrow> field \<Rightarrow> bool)  \<Rightarrow> (fspec, ty) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   153
 "fields_table G C P 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   154
    \<equiv> option_map type \<circ> table_of (filter (split P) (DeclConcepts.fields G C))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   155
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   156
lemma fields_table_SomeI: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   157
"\<lbrakk>table_of (DeclConcepts.fields G C) n = Some f; P n f\<rbrakk> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   158
 \<Longrightarrow> fields_table G C P n = Some (type f)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   159
apply (unfold fields_table_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   160
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   161
apply (rule exI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   162
apply (rule conjI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   163
apply (erule map_of_filter_in)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   164
apply assumption
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   165
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   166
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   167
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   168
(* unused *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   169
lemma fields_table_SomeD': "fields_table G C P fn = Some T \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   170
  \<exists>f. (fn,f)\<in>set(DeclConcepts.fields G C) \<and> type f = T"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   171
apply (unfold fields_table_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   172
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   173
apply (drule map_of_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   174
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   175
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   176
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   177
lemma fields_table_SomeD: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   178
"\<lbrakk>fields_table G C P fn = Some T; unique (DeclConcepts.fields G C)\<rbrakk> \<Longrightarrow>  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   179
  \<exists>f. table_of (DeclConcepts.fields G C) fn = Some f \<and> type f = T"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   180
apply (unfold fields_table_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   181
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   182
apply (rule exI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   183
apply (rule conjI)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   184
apply (erule table_of_filter_unique_SomeD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   185
apply assumption
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   186
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   187
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   188
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   189
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   190
  in_bounds :: "int \<Rightarrow> int \<Rightarrow> bool"            ("(_/ in'_bounds _)" [50, 51] 50)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   191
 "i in_bounds k \<equiv> 0 \<le> i \<and> i < k"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   192
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   193
  arr_comps :: "'a \<Rightarrow> int \<Rightarrow> int \<Rightarrow> 'a option"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   194
 "arr_comps T k \<equiv> \<lambda>i. if i in_bounds k then Some T else None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   195
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   196
  var_tys       :: "prog \<Rightarrow> obj_tag \<Rightarrow> oref \<Rightarrow> (vn, ty) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   197
"var_tys G oi r 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   198
  \<equiv> case r of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   199
      Heap a \<Rightarrow> (case oi of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   200
                   CInst C \<Rightarrow> fields_table G C (\<lambda>n f. \<not>static f) (+) empty
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   201
                 | Arr T k \<Rightarrow> empty (+) arr_comps T k)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   202
    | Stat C \<Rightarrow> fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   203
                (+) empty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   204
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   205
lemma var_tys_Some_eq: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   206
 "var_tys G oi r n = Some T 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   207
  = (case r of 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   208
       Inl a \<Rightarrow> (case oi of  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   209
                   CInst C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> fields_table G C (\<lambda>n f. 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   210
                               \<not>static f) nt = Some T)  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   211
                 | Arr t k \<Rightarrow> (\<exists> i. n = Inr i  \<and> i in_bounds k \<and> t = T))  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   212
     | Inr C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   213
                 fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) nt 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   214
                  = Some T))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   215
apply (unfold var_tys_def arr_comps_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   216
apply (force split add: sum.split_asm sum.split obj_tag.split)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   217
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   218
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   219
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   220
section "stores"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   221
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   222
types	globs                  (* global variables: heap and static variables *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   223
	= "(oref , obj) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   224
	heap
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   225
	= "(loc  , obj) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   226
	locals
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   227
	= "(lname, val) table" (* local variables *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   228
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   229
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   230
 "globs"  <= (type) "(oref , obj) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   231
 "heap"   <= (type) "(loc  , obj) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   232
 "locals" <= (type) "(lname, val) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   233
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   234
datatype st = (* pure state, i.e. contents of all variables *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   235
	 st globs locals
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   236
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   237
subsection "access"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   238
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   239
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   240
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   241
  globs  :: "st \<Rightarrow> globs"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   242
 "globs  \<equiv> st_case (\<lambda>g l. g)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   243
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   244
  locals :: "st \<Rightarrow> locals"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   245
 "locals \<equiv> st_case (\<lambda>g l. l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   246
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   247
  heap   :: "st \<Rightarrow> heap"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   248
 "heap s \<equiv> globs s \<circ> Heap"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   249
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   250
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   251
lemma globs_def2 [simp]: " globs (st g l) = g"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   252
by (simp add: globs_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   253
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   254
lemma locals_def2 [simp]: "locals (st g l) = l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   255
by (simp add: locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   256
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   257
lemma heap_def2 [simp]:  "heap s a=globs s (Heap a)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   258
by (simp add: heap_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   259
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   260
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   261
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   262
  val_this     :: "st \<Rightarrow> val"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   263
  lookup_obj   :: "st \<Rightarrow> val \<Rightarrow> obj"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   264
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   265
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   266
 "val_this s"       == "the (locals s This)" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   267
 "lookup_obj s a'"  == "the (heap s (the_Addr a'))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   268
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   269
subsection "memory allocation"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   270
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   271
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   272
  new_Addr     :: "heap \<Rightarrow> loc option"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   273
 "new_Addr h   \<equiv> if (\<forall>a. h a \<noteq> None) then None else Some (\<epsilon>a. h a = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   274
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   275
lemma new_AddrD: "new_Addr h = Some a \<Longrightarrow> h a = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   276
apply (unfold new_Addr_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   277
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   278
apply (case_tac "h (SOME a\<Colon>loc. h a = None)")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   279
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   280
apply (fast intro: someI2)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   281
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   282
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   283
lemma new_AddrD2: "new_Addr h = Some a \<Longrightarrow> \<forall>b. h b \<noteq> None \<longrightarrow> b \<noteq> a"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   284
apply (drule new_AddrD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   285
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   286
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   287
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   288
lemma new_Addr_SomeI: "h a = None \<Longrightarrow> \<exists>b. new_Addr h = Some b \<and> h b = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   289
apply (unfold new_Addr_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   290
apply (frule not_Some_eq [THEN iffD2])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   291
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   292
apply  (drule not_Some_eq [THEN iffD2])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   293
apply  auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   294
apply (fast intro!: someI2)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   295
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   296
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   297
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   298
subsection "initialization"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   299
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   300
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   301
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   302
  init_vals     :: "('a, ty) table \<Rightarrow> ('a, val) table"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   303
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   304
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   305
 "init_vals vs"    == "option_map default_val \<circ> vs"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   306
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   307
lemma init_arr_comps_base [simp]: "init_vals (arr_comps T 0) = empty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   308
apply (unfold arr_comps_def in_bounds_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   309
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   310
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   311
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   312
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   313
lemma init_arr_comps_step [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   314
"0 < j \<Longrightarrow> init_vals (arr_comps T  j    ) =  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   315
           init_vals (arr_comps T (j - 1))(j - 1\<mapsto>default_val T)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   316
apply (unfold arr_comps_def in_bounds_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   317
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   318
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   319
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   320
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   321
subsection "update"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   322
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   323
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   324
  gupd       :: "oref  \<Rightarrow> obj \<Rightarrow> st \<Rightarrow> st"        ("gupd'(_\<mapsto>_')"[10,10]1000)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   325
 "gupd r obj  \<equiv> st_case (\<lambda>g l. st (g(r\<mapsto>obj)) l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   326
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   327
  lupd       :: "lname \<Rightarrow> val \<Rightarrow> st \<Rightarrow> st"        ("lupd'(_\<mapsto>_')"[10,10]1000)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   328
 "lupd vn v   \<equiv> st_case (\<lambda>g l. st g (l(vn\<mapsto>v)))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   329
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   330
  upd_gobj   :: "oref \<Rightarrow> vn \<Rightarrow> val \<Rightarrow> st \<Rightarrow> st" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   331
 "upd_gobj r n v \<equiv> st_case (\<lambda>g l. st (chg_map (upd_obj n v) r g) l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   332
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   333
  set_locals  :: "locals \<Rightarrow> st \<Rightarrow> st"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   334
 "set_locals l \<equiv> st_case (\<lambda>g l'. st g l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   335
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   336
  init_obj    :: "prog \<Rightarrow> obj_tag \<Rightarrow> oref \<Rightarrow> st \<Rightarrow> st"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   337
 "init_obj G oi r \<equiv> gupd(r\<mapsto>\<lparr>tag=oi, values=init_vals (var_tys G oi r)\<rparr>)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   338
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   339
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   340
  init_class_obj :: "prog \<Rightarrow> qtname \<Rightarrow> st \<Rightarrow> st"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   341
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   342
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   343
 "init_class_obj G C" == "init_obj G arbitrary (Inr C)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   344
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   345
lemma gupd_def2 [simp]: "gupd(r\<mapsto>obj) (st g l) = st (g(r\<mapsto>obj)) l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   346
apply (unfold gupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   347
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   348
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   349
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   350
lemma lupd_def2 [simp]: "lupd(vn\<mapsto>v) (st g l) = st g (l(vn\<mapsto>v))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   351
apply (unfold lupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   352
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   353
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   354
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   355
lemma globs_gupd [simp]: "globs  (gupd(r\<mapsto>obj) s) = globs s(r\<mapsto>obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   356
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   357
by (simp add: gupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   358
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   359
lemma globs_lupd [simp]: "globs  (lupd(vn\<mapsto>v ) s) = globs  s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   360
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   361
by (simp add: lupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   362
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   363
lemma locals_gupd [simp]: "locals (gupd(r\<mapsto>obj) s) = locals s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   364
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   365
by (simp add: gupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   366
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   367
lemma locals_lupd [simp]: "locals (lupd(vn\<mapsto>v ) s) = locals s(vn\<mapsto>v )"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   368
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   369
by (simp add: lupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   370
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   371
lemma globs_upd_gobj_new [rule_format (no_asm), simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   372
  "globs s r = None \<longrightarrow> globs (upd_gobj r n v s) = globs s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   373
apply (unfold upd_gobj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   374
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   375
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   376
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   377
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   378
lemma globs_upd_gobj_upd [rule_format (no_asm), simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   379
"globs s r=Some obj\<longrightarrow> globs (upd_gobj r n v s) = globs s(r\<mapsto>upd_obj n v obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   380
apply (unfold upd_gobj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   381
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   382
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   383
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   384
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   385
lemma locals_upd_gobj [simp]: "locals (upd_gobj r n v s) = locals s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   386
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   387
by (simp add: upd_gobj_def) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   388
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   389
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   390
lemma globs_init_obj [simp]: "globs (init_obj G oi r s) t =  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   391
  (if t=r then Some \<lparr>tag=oi,values=init_vals (var_tys G oi r)\<rparr> else globs s t)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   392
apply (unfold init_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   393
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   394
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   395
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   396
lemma locals_init_obj [simp]: "locals (init_obj G oi r s) = locals s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   397
by (simp add: init_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   398
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   399
lemma surjective_st [simp]: "st (globs s) (locals s) = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   400
apply (induct "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   401
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   402
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   403
lemma surjective_st_init_obj: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   404
 "st (globs (init_obj G oi r s)) (locals s) = init_obj G oi r s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   405
apply (subst locals_init_obj [THEN sym])
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   406
apply (rule surjective_st)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   407
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   408
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   409
lemma heap_heap_upd [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   410
  "heap (st (g(Inl a\<mapsto>obj)) l) = heap (st g l)(a\<mapsto>obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   411
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   412
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   413
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   414
lemma heap_stat_upd [simp]: "heap (st (g(Inr C\<mapsto>obj)) l) = heap (st g l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   415
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   416
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   417
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   418
lemma heap_local_upd [simp]: "heap (st g (l(vn\<mapsto>v))) = heap (st g l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   419
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   420
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   421
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   422
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   423
lemma heap_gupd_Heap [simp]: "heap (gupd(Heap a\<mapsto>obj) s) = heap s(a\<mapsto>obj)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   424
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   425
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   426
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   427
lemma heap_gupd_Stat [simp]: "heap (gupd(Stat C\<mapsto>obj) s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   428
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   429
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   430
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   431
lemma heap_lupd [simp]: "heap (lupd(vn\<mapsto>v) s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   432
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   433
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   434
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   435
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   436
(*
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   437
lemma heap_upd_gobj_Heap: "!!a. heap (upd_gobj (Heap a) n v s) = ?X"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   438
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   439
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   440
apply (case_tac "globs s (Heap a)")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   441
apply  auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   442
*)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   443
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   444
lemma heap_upd_gobj_Stat [simp]: "heap (upd_gobj (Stat C) n v s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   445
apply (rule ext)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   446
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   447
apply (case_tac "globs s (Stat C)")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   448
apply  auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   449
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   450
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   451
lemma set_locals_def2 [simp]: "set_locals l (st g l') = st g l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   452
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   453
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   454
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   455
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   456
lemma set_locals_id [simp]: "set_locals (locals s) s = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   457
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   458
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   459
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   460
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   461
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   462
lemma set_set_locals [simp]: "set_locals l (set_locals l' s) = set_locals l s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   463
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   464
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   465
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   466
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   467
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   468
lemma locals_set_locals [simp]: "locals (set_locals l s) = l"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   469
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   470
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   471
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   472
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   473
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   474
lemma globs_set_locals [simp]: "globs (set_locals l s) = globs s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   475
apply (unfold set_locals_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   476
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   477
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   478
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   479
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   480
lemma heap_set_locals [simp]: "heap (set_locals l s) = heap s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   481
apply (unfold heap_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   482
apply (induct_tac "s")
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   483
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   484
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   485
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   486
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   487
section "abrupt completion"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   488
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   489
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   490
datatype xcpt        (* exception *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   491
	= Loc loc    (* location of allocated execption object *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   492
	| Std xname  (* intermediate standard exception, see Eval.thy *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   493
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   494
datatype error
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   495
       = AccessViolation (* Access to a member that isn't permitted *)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   496
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   497
datatype abrupt      (* abrupt completion *) 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   498
        = Xcpt xcpt  (* exception *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   499
        | Jump jump  (* break, continue, return *)
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   500
        | Error error (* runtime errors, we wan't to detect and proof absent
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   501
                         in welltyped programms *)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   502
consts
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   503
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   504
  the_Xcpt :: "abrupt \<Rightarrow> xcpt"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   505
  the_Jump :: "abrupt => jump"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   506
  the_Loc  :: "xcpt \<Rightarrow> loc"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   507
  the_Std  :: "xcpt \<Rightarrow> xname"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   508
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   509
primrec "the_Xcpt (Xcpt x) = x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   510
primrec "the_Jump (Jump j) = j"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   511
primrec "the_Loc (Loc a) = a"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   512
primrec "the_Std (Std x) = x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   513
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   514
types
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   515
  abopt  = "abrupt option"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   516
	
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   517
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   518
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   519
  abrupt_if    :: "bool \<Rightarrow> abopt \<Rightarrow> abopt \<Rightarrow> abopt"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   520
 "abrupt_if c x' x \<equiv> if c \<and> (x = None) then x' else x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   521
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   522
lemma abrupt_if_True_None [simp]: "abrupt_if True x None = x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   523
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   524
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   525
lemma abrupt_if_True_not_None [simp]: "x \<noteq> None \<Longrightarrow> abrupt_if True x y \<noteq> None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   526
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   527
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   528
lemma abrupt_if_False [simp]: "abrupt_if False x y = y"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   529
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   530
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   531
lemma abrupt_if_Some [simp]: "abrupt_if c x (Some y) = Some y"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   532
by (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   533
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   534
lemma abrupt_if_not_None [simp]: "y \<noteq> None \<Longrightarrow> abrupt_if c x y = y"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   535
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   536
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   537
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   538
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   539
lemma split_abrupt_if: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   540
"P (abrupt_if c x' x) = 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   541
      ((c \<and> x = None \<longrightarrow> P x') \<and> (\<not> (c \<and> x = None) \<longrightarrow> P x))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   542
apply (unfold abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   543
apply (split split_if)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   544
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   545
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   546
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   547
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   548
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   549
  raise_if :: "bool \<Rightarrow> xname \<Rightarrow> abopt \<Rightarrow> abopt"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   550
  np       :: "val  \<spacespace>        \<Rightarrow> abopt \<Rightarrow> abopt"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   551
  check_neg:: "val  \<spacespace>        \<Rightarrow> abopt \<Rightarrow> abopt"
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   552
  error_if :: "bool \<Rightarrow> error \<Rightarrow> abopt \<Rightarrow> abopt"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   553
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   554
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   555
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   556
 "raise_if c xn" == "abrupt_if c (Some (Xcpt (Std xn)))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   557
 "np v"          == "raise_if (v = Null)      NullPointer"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   558
 "check_neg i'"  == "raise_if (the_Intg i'<0) NegArrSize"
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   559
 "error_if c e"  == "abrupt_if c (Some (Error e))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   560
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   561
lemma raise_if_None [simp]: "(raise_if c x y = None) = (\<not>c \<and> y = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   562
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   563
by auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   564
declare raise_if_None [THEN iffD1, dest!]
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   565
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   566
lemma if_raise_if_None [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   567
  "((if b then y else raise_if c x y) = None) = ((c \<longrightarrow> b) \<and> y = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   568
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   569
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   570
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   571
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   572
lemma raise_if_SomeD [dest!]:
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   573
  "raise_if c x y = Some z \<Longrightarrow> c \<and> z=(Xcpt (Std x)) \<and> y=None \<or> (y=Some z)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   574
apply (case_tac y)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   575
apply (case_tac c)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   576
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   577
apply (simp add: abrupt_if_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   578
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   579
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   580
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   581
lemma error_if_None [simp]: "(error_if c e y = None) = (\<not>c \<and> y = None)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   582
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   583
by auto
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   584
declare error_if_None [THEN iffD1, dest!]
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   585
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   586
lemma if_error_if_None [simp]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   587
  "((if b then y else error_if c e y) = None) = ((c \<longrightarrow> b) \<and> y = None)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   588
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   589
apply auto
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   590
done
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   591
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   592
lemma raise_if_SomeD [dest!]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   593
  "error_if c e y = Some z \<Longrightarrow> c \<and> z=(Error e) \<and> y=None \<or> (y=Some z)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   594
apply (case_tac y)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   595
apply (case_tac c)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   596
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   597
apply (simp add: abrupt_if_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   598
apply auto
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   599
done
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   600
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   601
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   602
   absorb :: "jump \<Rightarrow> abopt \<Rightarrow> abopt"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   603
  "absorb j a \<equiv> if a=Some (Jump j) then None else a"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   604
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   605
lemma absorb_SomeD [dest!]: "absorb j a = Some x \<Longrightarrow> a = Some x"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   606
by (auto simp add: absorb_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   607
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   608
lemma absorb_same [simp]: "absorb j (Some (Jump j)) = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   609
by (auto simp add: absorb_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   610
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   611
lemma absorb_other [simp]: "a \<noteq> Some (Jump j) \<Longrightarrow> absorb j a = a"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   612
by (auto simp add: absorb_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   613
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   614
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   615
section "full program state"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   616
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   617
types
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   618
  state = "abopt \<times> st"          (* state including exception information *)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   619
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   620
syntax 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   621
  Norm   :: "st \<Rightarrow> state"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   622
  abrupt :: "state \<Rightarrow> abopt"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   623
  store  :: "state \<Rightarrow> st"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   624
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   625
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   626
   
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   627
  "Norm s"     == "(None,s)" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   628
  "abrupt"     => "fst"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   629
  "store"      => "snd"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   630
  "abopt"       <= (type) "State.abrupt option"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   631
  "abopt"       <= (type) "abrupt option"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   632
  "state"      <= (type) "abopt \<times> State.st"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   633
  "state"      <= (type) "abopt \<times> st"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   634
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   635
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   636
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   637
lemma single_stateE: "\<forall>Z. Z = (s::state) \<Longrightarrow> False"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   638
apply (erule_tac x = "(Some k,y)" in all_dupE)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   639
apply (erule_tac x = "(None,y)" in allE)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   640
apply clarify
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   641
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   642
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   643
lemma state_not_single: "All (op = (x::state)) \<Longrightarrow> R"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   644
apply (drule_tac x = "(if abrupt x = None then Some ?x else None,?y)" in spec)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   645
apply clarsimp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   646
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   647
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   648
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   649
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   650
  normal     :: "state \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   651
 "normal \<equiv> \<lambda>s. abrupt s = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   652
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   653
lemma normal_def2 [simp]: "normal s = (abrupt s = None)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   654
apply (unfold normal_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   655
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   656
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   657
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   658
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   659
  heap_free :: "nat \<Rightarrow> state \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   660
 "heap_free n \<equiv> \<lambda>s. atleast_free (heap (store s)) n"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   661
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   662
lemma heap_free_def2 [simp]: "heap_free n s = atleast_free (heap (store s)) n"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   663
apply (unfold heap_free_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   664
apply simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   665
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   666
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   667
subsection "update"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   668
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   669
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   670
 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   671
  abupd     :: "(abopt \<Rightarrow> abopt) \<Rightarrow> state \<Rightarrow> state"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   672
 "abupd f \<equiv> prod_fun f id"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   673
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   674
  supd     :: "(st \<Rightarrow> st) \<Rightarrow> state \<Rightarrow> state" 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   675
 "supd \<equiv> prod_fun id"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   676
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   677
lemma abupd_def2 [simp]: "abupd f (x,s) = (f x,s)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   678
by (simp add: abupd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   679
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   680
lemma abupd_abrupt_if_False [simp]: "\<And> s. abupd (abrupt_if False xo) s = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   681
by simp
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   682
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   683
lemma supd_def2 [simp]: "supd f (x,s) = (x,f s)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   684
by (simp add: supd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   685
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   686
lemma supd_lupd [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   687
 "\<And> s. supd (lupd vn v ) s = (abrupt s,lupd vn v (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   688
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   689
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   690
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   691
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   692
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   693
lemma supd_gupd [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   694
 "\<And> s. supd (gupd r obj) s = (abrupt s,gupd r obj (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   695
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   696
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   697
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   698
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   699
lemma supd_init_obj [simp]: 
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   700
 "supd (init_obj G oi r) s = (abrupt s,init_obj G oi r (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   701
apply (unfold init_obj_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   702
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   703
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   704
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   705
syntax
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   706
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   707
  set_lvars     :: "locals \<Rightarrow> state \<Rightarrow> state"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   708
  restore_lvars :: "state  \<Rightarrow> state \<Rightarrow> state"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   709
  
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   710
translations
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   711
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   712
 "set_lvars l" == "supd (set_locals l)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   713
 "restore_lvars s' s" == "set_lvars (locals (store s')) s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   714
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   715
lemma set_set_lvars [simp]: "\<And> s. set_lvars l (set_lvars l' s) = set_lvars l s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   716
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   717
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   718
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   719
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   720
lemma set_lvars_id [simp]: "\<And> s. set_lvars (locals (store s)) s = s"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   721
apply (simp (no_asm_simp) only: split_tupled_all)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   722
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   723
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   724
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   725
section "initialisation test"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   726
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   727
constdefs
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   728
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   729
  inited   :: "qtname \<Rightarrow> globs \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   730
 "inited C g \<equiv> g (Stat C) \<noteq> None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   731
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   732
  initd    :: "qtname \<Rightarrow> state \<Rightarrow> bool"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   733
 "initd C \<equiv> inited C \<circ> globs \<circ> store"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   734
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   735
lemma not_inited_empty [simp]: "\<not>inited C empty"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   736
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   737
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   738
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   739
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   740
lemma inited_gupdate [simp]: "inited C (g(r\<mapsto>obj)) = (inited C g \<or> r = Stat C)"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   741
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   742
apply (auto split add: st.split)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   743
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   744
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   745
lemma inited_init_class_obj [intro!]: "inited C (globs (init_class_obj G C s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   746
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   747
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   748
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   749
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   750
lemma not_initedD: "\<not> inited C g \<Longrightarrow> g (Stat C) = None"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   751
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   752
apply (erule notnotD)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   753
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   754
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   755
lemma initedD: "inited C g \<Longrightarrow> \<exists> obj. g (Stat C) = Some obj"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   756
apply (unfold inited_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   757
apply auto
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   758
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   759
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   760
lemma initd_def2 [simp]: "initd C s = inited C (globs (store s))"
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   761
apply (unfold initd_def)
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   762
apply (simp (no_asm))
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   763
done
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   764
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   765
section {* @{text error_free} *}
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   766
constdefs error_free:: "state \<Rightarrow> bool"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   767
"error_free s \<equiv> \<not> (\<exists> err. abrupt s = Some (Error err))"
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   768
12925
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   769
lemma error_free_Norm [simp,intro]: "error_free (Norm s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   770
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   771
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   772
lemma error_free_normal [simp,intro]: "normal s \<Longrightarrow> error_free s"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   773
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   774
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   775
lemma error_free_Xcpt [simp]: "error_free (Some (Xcpt x),s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   776
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   777
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   778
lemma error_free_Jump [simp,intro]: "error_free (Some (Jump j),s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   779
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   780
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   781
lemma error_free_Error [simp]: "error_free (Some (Error e),s) = False"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   782
by (simp add: error_free_def)  
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   783
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   784
lemma error_free_Some [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   785
 "\<not> (\<exists> err. x=Error err) \<Longrightarrow> error_free ((Some x),s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   786
by (auto simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   787
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   788
lemma error_free_absorb [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   789
 "error_free s \<Longrightarrow> error_free (abupd (absorb j) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   790
by (cases s) 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   791
   (auto simp add: error_free_def absorb_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   792
         split: split_if_asm)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   793
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   794
lemma error_free_absorb [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   795
 "error_free (a,s) \<Longrightarrow> error_free (absorb j a, s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   796
by (auto simp add: error_free_def absorb_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   797
            split: split_if_asm)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   798
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   799
lemma error_free_abrupt_if [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   800
"\<lbrakk>error_free s; \<not> (\<exists> err. x=Error err)\<rbrakk>
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   801
 \<Longrightarrow> error_free (abupd (abrupt_if p (Some x)) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   802
by (cases s)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   803
   (auto simp add: abrupt_if_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   804
            split: split_if)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   805
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   806
lemma error_free_abrupt_if1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   807
"\<lbrakk>error_free (a,s); \<not> (\<exists> err. x=Error err)\<rbrakk>
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   808
 \<Longrightarrow> error_free (abrupt_if p (Some x) a, s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   809
by  (auto simp add: abrupt_if_def
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   810
            split: split_if)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   811
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   812
lemma error_free_abrupt_if_Xcpt [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   813
 "error_free s 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   814
  \<Longrightarrow> error_free (abupd (abrupt_if p (Some (Xcpt x))) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   815
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   816
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   817
lemma error_free_abrupt_if_Xcpt1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   818
 "error_free (a,s) 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   819
  \<Longrightarrow> error_free (abrupt_if p (Some (Xcpt x)) a, s)" 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   820
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   821
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   822
lemma error_free_abrupt_if_Jump [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   823
 "error_free s 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   824
  \<Longrightarrow> error_free (abupd (abrupt_if p (Some (Jump j))) s)" 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   825
by simp
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   826
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   827
lemma error_free_abrupt_if_Jump1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   828
 "error_free (a,s) 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   829
  \<Longrightarrow> error_free (abrupt_if p (Some (Jump j)) a, s)" 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   830
by simp
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   831
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   832
lemma error_free_raise_if [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   833
 "error_free s \<Longrightarrow> error_free (abupd (raise_if p x) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   834
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   835
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   836
lemma error_free_raise_if1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   837
 "error_free (a,s) \<Longrightarrow> error_free ((raise_if p x a), s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   838
by simp 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   839
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   840
lemma error_free_supd [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   841
 "error_free s \<Longrightarrow> error_free (supd f s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   842
by (cases s) (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   843
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   844
lemma error_free_supd1 [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   845
 "error_free (a,s) \<Longrightarrow> error_free (a,f s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   846
by (simp add: error_free_def)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   847
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   848
lemma error_free_set_lvars [simp,intro]:
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   849
"error_free s \<Longrightarrow> error_free ((set_lvars l) s)"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   850
by (cases s) simp
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   851
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   852
lemma error_free_set_locals [simp,intro]: 
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   853
"error_free (x, s)
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   854
       \<Longrightarrow> error_free (x, set_locals l s')"
99131847fb93 Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents: 12858
diff changeset
   855
by (simp add: error_free_def)
12854
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   856
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   857
end
00d4a435777f Isabelle/Bali sources;
schirmer
parents:
diff changeset
   858