(* Title: HOL/Bali/State.thy Author: David von Oheimb
*)
subsection \<open>State for evaluation of Java expressions and statements\<close>
theory State imports DeclConcepts begin
text\<open>
design issues: \begin{itemize} \item all kinds of objects (class instances, arrays, and class objects)
are handeled via a general object abstraction \item the heap and the map for class objects are combined into a single table \<open>(recall (loc, obj) table \<times> (qtname, obj) table ~= (loc + qtname, obj) table)\<close> \end{itemize} \<close>
subsubsection "objects"
datatype obj_tag = \<comment> \<open>tag for generic object\<close>
CInst qtname \<comment> \<open>class instance\<close>
| Arr ty int \<comment> \<open>array with component type and length\<close> \<comment> \<open>| CStat qtname the tag is irrelevant for a class object,
i.e. the static fields of a class,
since its type is given already by the reference to
it (see below)\<close>
lemma obj_ty_eq1 [intro!,dest]: "tag obj = tag obj' \ obj_ty obj = obj_ty obj'" by (simp add: obj_ty_def)
lemma obj_ty_cong [simp]: "obj_ty (obj \values:=vs\) = obj_ty obj" by auto
lemma obj_ty_CInst [simp]: "obj_ty \tag=CInst C,values=vs\ = Class C" by (simp add: obj_ty_def)
lemma obj_ty_CInst1 [simp,intro!,dest]: "\tag obj = CInst C\ \ obj_ty obj = Class C" by (simp add: obj_ty_def)
lemma obj_ty_Arr [simp]: "obj_ty \tag=Arr T i,values=vs\ = T.[]" by (simp add: obj_ty_def)
lemma obj_ty_Arr1 [simp,intro!,dest]: "\tag obj = Arr T i\ \ obj_ty obj = T.[]" by (simp add: obj_ty_def)
lemma obj_ty_widenD: "G\obj_ty obj\RefT t \ (\C. tag obj = CInst C) \ (\T k. tag obj = Arr T k)" apply (unfold obj_ty_def) apply (auto split: obj_tag.split_asm) done
definition
obj_class :: "obj \ qtname" where "obj_class obj = (case tag obj of
CInst C \<Rightarrow> C
| Arr T k \<Rightarrow> Object)"
abbreviation (input)
Heap :: "loc \ oref" where "Heap \ Inl" abbreviation (input)
Stat :: "qtname \ oref" where "Stat \ Inr"
definition
fields_table :: "prog \ qtname \ (fspec \ field \ bool) \ (fspec, ty) table" where "fields_table G C P =
map_option type \<circ> table_of (filter (case_prod P) (DeclConcepts.fields G C))"
lemma fields_table_SomeI: "\table_of (DeclConcepts.fields G C) n = Some f; P n f\ \<Longrightarrow> fields_table G C P n = Some (type f)" apply (unfold fields_table_def) apply clarsimp apply (rule exI) apply (rule conjI) apply (erule map_of_filter_in) apply assumption apply simp done
(* unused *) lemma fields_table_SomeD': "fields_table G C P fn = Some T \ \<exists>f. (fn,f)\<in>set(DeclConcepts.fields G C) \<and> type f = T" apply (unfold fields_table_def) apply clarsimp apply (drule map_of_SomeD) apply auto done
lemma fields_table_SomeD: "\fields_table G C P fn = Some T; unique (DeclConcepts.fields G C)\ \ \<exists>f. table_of (DeclConcepts.fields G C) fn = Some f \<and> type f = T" apply (unfold fields_table_def) apply clarsimp apply (rule exI) apply (rule conjI) apply (erule table_of_filter_unique_SomeD) apply assumption apply simp done
definition
in_bounds :: "int \ int \ bool" (\(_/ in'_bounds _)\ [50, 51] 50) where"i in_bounds k = (0 \ i \ i < k)"
definition
arr_comps :: "'a \ int \ int \ 'a option" where"arr_comps T k = (\i. if i in_bounds k then Some T else None)"
definition
var_tys :: "prog \ obj_tag \ oref \ (vn, ty) table" where "var_tys G oi r =
(case r of
Heap a \<Rightarrow> (case oi of
CInst C \<Rightarrow> fields_table G C (\<lambda>n f. \<not>static f) (+) Map.empty
| Arr T k \<Rightarrow> Map.empty (+) arr_comps T k)
| Stat C \<Rightarrow> fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f)
(+) Map.empty)"
lemma var_tys_Some_eq: "var_tys G oi r n = Some T
= (case r of
Inl a \<Rightarrow> (case oi of
CInst C \<Rightarrow> (\<exists>nt. n = Inl nt \<and> fields_table G C (\<lambda>n f. \<not>static f) nt = Some T)
| Arr t k \<Rightarrow> (\<exists> i. n = Inr i \<and> i in_bounds k \<and> t = T))
| Inr C \<Rightarrow> (\<exists>nt. n = Inl nt \<and>
fields_table G C (\<lambda>fn f. declclassf fn = C \<and> static f) nt
= Some T))" apply (unfold var_tys_def arr_comps_def) apply (force split: sum.split_asm sum.split obj_tag.split) done
lemma globs_upd_gobj_new [rule_format (no_asm), simp]: "globs s r = None \ globs (upd_gobj r n v s) = globs s" apply (unfold upd_gobj_def) apply (induct "s") apply auto done
lemma globs_upd_gobj_upd [rule_format (no_asm), simp]: "globs s r=Some obj\ globs (upd_gobj r n v s) = (globs s)(r\upd_obj n v obj)" apply (unfold upd_gobj_def) apply (induct "s") apply auto done
lemma locals_upd_gobj [simp]: "locals (upd_gobj r n v s) = locals s" apply (induct "s") by (simp add: upd_gobj_def)
lemma globs_init_obj [simp]: "globs (init_obj G oi r s) t =
(if t=r then Some \<lparr>tag=oi,values=init_vals (var_tys G oi r)\<rparr> else globs s t)" apply (unfold init_obj_def) apply (simp (no_asm)) done
lemma locals_init_obj [simp]: "locals (init_obj G oi r s) = locals s" by (simp add: init_obj_def)
lemma surjective_st [simp]: "st (globs s) (locals s) = s" apply (induct "s") by auto
lemma surjective_st_init_obj: "st (globs (init_obj G oi r s)) (locals s) = init_obj G oi r s" apply (subst locals_init_obj [THEN sym]) apply (rule surjective_st) done
abbreviation error_if :: "bool \ error \ abopt \ abopt" where"error_if c e == abrupt_if c (Some (Error e))"
lemma raise_if_None [simp]: "(raise_if c x y = None) = (\c \ y = None)" apply (simp add: abrupt_if_def) by auto declare raise_if_None [THEN iffD1, dest!]
lemma if_raise_if_None [simp]: "((if b then y else raise_if c x y) = None) = ((c \ b) \ y = None)" apply (simp add: abrupt_if_def) apply auto done
lemma raise_if_SomeD [dest!]: "raise_if c x y = Some z \ c \ z=(Xcpt (Std x)) \ y=None \ (y=Some z)" apply (case_tac y) apply (case_tac c) apply (simp add: abrupt_if_def) apply (simp add: abrupt_if_def) apply auto done
lemma error_if_None [simp]: "(error_if c e y = None) = (\c \ y = None)" apply (simp add: abrupt_if_def) by auto declare error_if_None [THEN iffD1, dest!]
lemma if_error_if_None [simp]: "((if b then y else error_if c e y) = None) = ((c \ b) \ y = None)" apply (simp add: abrupt_if_def) apply auto done
lemma error_if_SomeD [dest!]: "error_if c e y = Some z \ c \ z=(Error e) \ y=None \ (y=Some z)" apply (case_tac y) apply (case_tac c) apply (simp add: abrupt_if_def) apply (simp add: abrupt_if_def) apply auto done
definition
absorb :: "jump \ abopt \ abopt" where"absorb j a = (if a=Some (Jump j) then None else a)"
lemma absorb_SomeD [dest!]: "absorb j a = Some x \ a = Some x" by (auto simp add: absorb_def)
abbreviation (input)
abrupt :: "state \ abopt" where"abrupt == fst"
abbreviation (input)
store :: "state \ st" where"store == snd"
lemma single_stateE: "\Z. Z = (s::state) \ False" apply (erule_tac x = "(Some k,y)"for k y in all_dupE) apply (erule_tac x = "(None,y)"for y in allE) apply clarify done
lemma state_not_single: "All ((=) (x::state)) \ R" apply (drule_tac x = "(if abrupt x = None then Some x' else None, y)"for x' y in spec) apply clarsimp done
definition
normal :: "state \ bool" where"normal = (\s. abrupt s = None)"
lemma normal_def2 [simp]: "normal s = (abrupt s = None)" apply (unfold normal_def) apply (simp (no_asm)) done
definition
heap_free :: "nat \ state \ bool" where"heap_free n = (\s. atleast_free (heap (store s)) n)"
lemma heap_free_def2 [simp]: "heap_free n s = atleast_free (heap (store s)) n" apply (unfold heap_free_def) apply simp done
subsection "update"
definition
abupd :: "(abopt \ abopt) \ state \ state" where"abupd f = map_prod f id"
lemma error_free_set_lvars [simp,intro]: "error_free s \ error_free ((set_lvars l) s)" by (cases s) simp
lemma error_free_set_locals [simp,intro]: "error_free (x, s) \<Longrightarrow> error_free (x, set_locals l s')" by (simp add: error_free_def)
end
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.14Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.