(* Title: HOL/MicroJava/J/WellForm.thy Author: David von Oheimb Copyright 1999 Technische Universitaet Muenchen *)
section‹Well-formedness of Java programs›
theory WellForm imports TypeRel SystemClasses begin
text‹ for static checks on expressions and statements, see WellType. \begin{description} \item[improvements over Java Specification 1.0 (cf. 8.4.6.3, 8.4.6.4, 9.4.1):]\ \\ \begin{itemize} \item a method implementing or overwriting another method may have a result type that widens to the result type of the other method (instead of identical type) \end{itemize} \item[simplifications:]\ \\ \begin{itemize} \item for uniformity, Object is assumed to be declared like any other class \end{itemize} \end{description} › type_synonym 'c wf_mb = "'c prog => cname => 'c mdecl => bool"
definition wf_syscls :: "'c prog => bool"where "wf_syscls G == let cs = set G in Object ∈ fst ` cs ∧ (∀x. Xcpt x ∈ fst ` cs)"
definition wf_fdecl :: "'c prog => fdecl => bool"where "wf_fdecl G == λ(fn,ft). is_type G ft"
definition wf_mhead :: "'c prog => sig => ty => bool"where "wf_mhead G == λ(mn,pTs) rT. (∀T∈set pTs. is_type G T) ∧ is_type G rT"
definition ws_cdecl :: "'c prog => 'c cdecl => bool"where "ws_cdecl G == λ(C,(D,fs,ms)). (∀f∈set fs. wf_fdecl G f) ∧ unique fs ∧ (∀(sig,rT,mb)∈set ms. wf_mhead G sig rT) ∧ unique ms ∧ (C ≠ Object ⟶ is_class G D ∧¬G⊨D⪯C C)"
definition ws_prog :: "'c prog => bool"where "ws_prog G == wf_syscls G ∧ (∀c∈set G. ws_cdecl G c) ∧ unique G"
definition wf_cdecl_mdecl :: "'c wf_mb => 'c prog => 'c cdecl => bool"where "wf_cdecl_mdecl wf_mb G == λ(C,(D,fs,ms)). (∀m∈set ms. wf_mb G C m)"
definition wf_prog :: "'c wf_mb => 'c prog => bool"where "wf_prog wf_mb G == ws_prog G ∧ (∀c∈ set G. wf_mrT G c ∧ wf_cdecl_mdecl wf_mb G c)"
definition wf_mdecl :: "'c wf_mb => 'c wf_mb"where "wf_mdecl wf_mb G C == λ(sig,rT,mb). wf_mhead G sig rT ∧ wf_mb G C (sig,rT,mb)"
definition wf_cdecl :: "'c wf_mb => 'c prog => 'c cdecl => bool"where "wf_cdecl wf_mb G == λ(C,(D,fs,ms)). (∀f∈set fs. wf_fdecl G f) ∧ unique fs ∧ (∀m∈set ms. wf_mdecl wf_mb G C m) ∧ unique ms ∧ (C ≠ Object ⟶ is_class G D ∧¬G⊨D⪯C C ∧ (∀(sig,rT,b)∈set ms. ∀D' rT' b'. method(G,D) sig = Some(D',rT',b') --> G⊨rT⪯rT'))"
lemma wf_cdecl_mrT_cdecl_mdecl: "(wf_cdecl wf_mb G c) = (ws_cdecl G c ∧ wf_mrT G c ∧ wf_cdecl_mdecl wf_mb G c)" apply (rule iffI) apply (simp add: wf_cdecl_def ws_cdecl_def wf_mrT_def wf_cdecl_mdecl_def
wf_mdecl_def wf_mhead_def split_beta)+ done
lemma wf_cdecl_ws_cdecl [intro]: "wf_cdecl wf_mb G cd ==> ws_cdecl G cd" by (simp add: wf_cdecl_mrT_cdecl_mdecl)
lemma wf_prog_ws_prog [intro]: "wf_prog wf_mb G ==> ws_prog G" by (simp add: wf_prog_def ws_prog_def)
lemma wf_prog_wf_mdecl: "[ wf_prog wf_mb G; (C,S,fs,mdecls) ∈ set G; ((mn,pTs),rT,code) ∈ set mdecls] ==> wf_mdecl wf_mb G C ((mn,pTs),rT,code)" by (auto simp add: wf_prog_def ws_prog_def wf_mdecl_def
wf_cdecl_mdecl_def ws_cdecl_def)
lemma class_wf: "[|class G C = Some c; wf_prog wf_mb G|] ==> wf_cdecl wf_mb G (C,c) ∧ wf_mrT G (C,c)" apply (unfold wf_prog_def ws_prog_def wf_cdecl_def class_def) apply clarify apply (drule_tac x="(C,c)"in bspec, fast dest: map_of_SomeD) apply (drule_tac x="(C,c)"in bspec, fast dest: map_of_SomeD) apply (simp add: wf_cdecl_def ws_cdecl_def wf_mdecl_def
wf_cdecl_mdecl_def wf_mrT_def split_beta) done
lemma class_wf_struct: "[|class G C = Some c; ws_prog G|] ==> ws_cdecl G (C,c)" apply (unfold ws_prog_def class_def) apply (fast dest: map_of_SomeD) done
lemma class_Object [simp]: "ws_prog G ==> ∃X fs ms. class G Object = Some (X,fs,ms)" apply (unfold ws_prog_def wf_syscls_def class_def) apply (auto simp: map_of_SomeI) done
lemma class_Object_syscls [simp]: "wf_syscls G ==> unique G ==>∃X fs ms. class G Object = Some (X,fs,ms)" apply (unfold wf_syscls_def class_def) apply (auto simp: map_of_SomeI) done
lemma is_class_Object [simp]: "ws_prog G ==> is_class G Object" by (simp add: is_class_def)
lemma is_class_xcpt [simp]: "ws_prog G ==> is_class G (Xcpt x)" apply (simp add: ws_prog_def wf_syscls_def) apply (simp add: is_class_def class_def) apply clarify apply (erule_tac x = x in allE) apply clarify apply (auto intro!: map_of_SomeI) done
lemma method_in_md [rule_format (no_asm)]: "ws_prog G ==> is_class G C ==>∀D. method (G,C) sig = Some(D,mh,code) --> is_class G D ∧ method (G,D) sig = Some(D,mh,code)" apply (erule (1) subcls1_induct_struct) apply clarify apply (frule method_Object, assumption) apply hypsubst apply simp apply (erule conjE) apply (simplesubst method_rec, assumption+) apply (clarify) apply (erule_tac x = "Da"in allE) apply (clarsimp) apply (simp add: map_of_map) apply (subst method_rec, assumption+) apply (simp add: map_add_def map_of_map split: option.split) done
lemma method_in_md_struct [rule_format (no_asm)]: "ws_prog G ==> is_class G C ==>∀D. method (G,C) sig = Some(D,mh,code) --> is_class G D ∧ method (G,D) sig = Some(D,mh,code)" apply (erule (1) subcls1_induct_struct) apply clarify apply (frule method_Object, assumption) apply hypsubst apply simp apply (erule conjE) apply (simplesubst method_rec, assumption+) apply (clarify) apply (erule_tac x = "Da"in allE) apply (clarsimp) apply (simp add: map_of_map) apply (subst method_rec, assumption+) apply (simp add: map_add_def map_of_map split: option.split) done
lemma fields_in_fd [rule_format (no_asm)]: "[ wf_prog wf_mb G; is_class G C] ==>∀ vn D T. (((vn,D),T) ∈ set (fields (G,C)) ⟶ (is_class G D ∧ ((vn,D),T) ∈ set (fields (G,D))))" apply (erule (1) subcls1_induct)
lemma fields_is_type: "[|map_of (fields (G,C)) fn = Some f; ws_prog G; is_class G C|] ==> is_type G f" apply(drule map_of_SomeD) apply(drule (2) fields_is_type_lemma) apply(auto) done
lemma field_is_type: "[ ws_prog G; is_class G C; field (G, C) fn = Some (fd, fT) ] ==> is_type G fT" apply (frule_tac f="((fn, fd), fT)"in fields_is_type_lemma) apply (auto simp add: field_def dest: map_of_SomeD) done
lemma methd: "[| ws_prog G; (C,S,fs,mdecls) ∈ set G; (sig,rT,code) ∈ set mdecls |] ==> method (G,C) sig = Some(C,rT,code) ∧ is_class G C" proof - assume wf: "ws_prog G"and C: "(C,S,fs,mdecls) ∈ set G"and
m: "(sig,rT,code) ∈ set mdecls" moreover from wf C have"class G C = Some (S,fs,mdecls)" by (auto simp add: ws_prog_def class_def is_class_def intro: map_of_SomeI) moreover from wf C have"unique mdecls"by (unfold ws_prog_def ws_cdecl_def) auto hence"unique (map (λ(s,m). (s,C,m)) mdecls)"by (induct mdecls, auto) with m have"map_of (map (λ(s,m). (s,C,m)) mdecls) sig = Some (C,rT,code)" by (force intro: map_of_SomeI) ultimately show ?thesis by (auto simp add: is_class_def dest: method_rec) qed
lemma wf_mb'E: "[ wf_prog wf_mb G; ∧C S fs ms m.[(C,S,fs,ms) ∈ set G; m ∈ set ms]==> wf_mb' G C m ] ==> wf_prog wf_mb' G" apply (simp only: wf_prog_def) apply auto apply (simp add: wf_cdecl_mdecl_def) apply safe apply (drule bspec, assumption) apply simp done
lemma fst_mono: "A ⊆ B ==> fst ` A ⊆ fst ` B"by fast
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 und die Messung sind noch experimentell.