| author | wenzelm | 
| Mon, 12 Apr 2021 22:16:31 +0200 | |
| changeset 73568 | bdba138d462d | 
| parent 67613 | ce654b0e6d69 | 
| child 77645 | 7edbb16bc60f | 
| permissions | -rw-r--r-- | 
| 13673 | 1 | (* Title: HOL/MicroJava/Comp/CorrComp.thy | 
| 2 | Author: Martin Strecker | |
| 3 | *) | |
| 4 | ||
| 5 | (* Compiler correctness statement and proof *) | |
| 6 | ||
| 15860 | 7 | theory CorrComp | 
| 65538 | 8 | imports "../J/JTypeSafe" LemmasComp | 
| 15860 | 9 | begin | 
| 13673 | 10 | |
| 14045 | 11 | declare wf_prog_ws_prog [simp add] | 
| 13673 | 12 | |
| 13 | (* If no exception is present after evaluation/execution, | |
| 14 | none can have been present before *) | |
| 15 | lemma eval_evals_exec_xcpt: | |
| 22271 | 16 | "(G \<turnstile> xs -ex\<succ>val-> xs' \<longrightarrow> gx xs' = None \<longrightarrow> gx xs = None) \<and> | 
| 17 | (G \<turnstile> xs -exs[\<succ>]vals-> xs' \<longrightarrow> gx xs' = None \<longrightarrow> gx xs = None) \<and> | |
| 18 | (G \<turnstile> xs -st-> xs' \<longrightarrow> gx xs' = None \<longrightarrow> gx xs = None)" | |
| 60304 | 19 | by (induct rule: eval_evals_exec.induct) auto | 
| 13673 | 20 | |
| 21 | ||
| 22 | (* instance of eval_evals_exec_xcpt for eval *) | |
| 22271 | 23 | lemma eval_xcpt: "G \<turnstile> xs -ex\<succ>val-> xs' \<Longrightarrow> gx xs' = None \<Longrightarrow> gx xs = None" | 
| 13673 | 24 | (is "?H1 \<Longrightarrow> ?H2 \<Longrightarrow> ?T") | 
| 25 | proof- | |
| 26 | assume h1: ?H1 | |
| 27 | assume h2: ?H2 | |
| 28 | from h1 h2 eval_evals_exec_xcpt show "?T" by simp | |
| 29 | qed | |
| 30 | ||
| 31 | (* instance of eval_evals_exec_xcpt for evals *) | |
| 22271 | 32 | lemma evals_xcpt: "G \<turnstile> xs -exs[\<succ>]vals-> xs' \<Longrightarrow> gx xs' = None \<Longrightarrow> gx xs = None" | 
| 13673 | 33 | (is "?H1 \<Longrightarrow> ?H2 \<Longrightarrow> ?T") | 
| 34 | proof- | |
| 35 | assume h1: ?H1 | |
| 36 | assume h2: ?H2 | |
| 37 | from h1 h2 eval_evals_exec_xcpt show "?T" by simp | |
| 38 | qed | |
| 39 | ||
| 40 | (* instance of eval_evals_exec_xcpt for exec *) | |
| 22271 | 41 | lemma exec_xcpt: "G \<turnstile> xs -st-> xs' \<Longrightarrow> gx xs' = None \<Longrightarrow> gx xs = None" | 
| 13673 | 42 | (is "?H1 \<Longrightarrow> ?H2 \<Longrightarrow> ?T") | 
| 43 | proof- | |
| 44 | assume h1: ?H1 | |
| 45 | assume h2: ?H2 | |
| 46 | from h1 h2 eval_evals_exec_xcpt show "?T" by simp | |
| 47 | qed | |
| 48 | ||
| 49 | (**********************************************************************) | |
| 50 | ||
| 51 | theorem exec_all_trans: "\<lbrakk>(exec_all G s0 s1); (exec_all G s1 s2)\<rbrakk> \<Longrightarrow> (exec_all G s0 s2)" | |
| 60304 | 52 | by (auto simp: exec_all_def elim: Transitive_Closure.rtrancl_trans) | 
| 13673 | 53 | |
| 54 | theorem exec_all_refl: "exec_all G s s" | |
| 60304 | 55 | by (simp only: exec_all_def) | 
| 13673 | 56 | |
| 57 | ||
| 58 | theorem exec_instr_in_exec_all: | |
| 59 | "\<lbrakk> exec_instr i G hp stk lvars C S pc frs = (None, hp', frs'); | |
| 60 | gis (gmb G C S) ! pc = i\<rbrakk> \<Longrightarrow> | |
| 53024 | 61 | G \<turnstile> (None, hp, (stk, lvars, C, S, pc) # frs) \<midarrow>jvm\<rightarrow> (None, hp', frs')" | 
| 60304 | 62 | apply (simp only: exec_all_def) | 
| 63 | apply (rule rtrancl_refl [THEN rtrancl_into_rtrancl]) | |
| 64 | apply (simp add: gis_def gmb_def) | |
| 65 | apply (case_tac frs', simp+) | |
| 66 | done | |
| 13673 | 67 | |
| 68 | theorem exec_all_one_step: " | |
| 69 | \<lbrakk> gis (gmb G C S) = pre @ (i # post); pc0 = length pre; | |
| 70 | (exec_instr i G hp0 stk0 lvars0 C S pc0 frs) = | |
| 71 | (None, hp1, (stk1,lvars1,C,S, Suc pc0)#frs) \<rbrakk> | |
| 72 | \<Longrightarrow> | |
| 53024 | 73 | G \<turnstile> (None, hp0, (stk0,lvars0,C,S, pc0)#frs) \<midarrow>jvm\<rightarrow> | 
| 13673 | 74 | (None, hp1, (stk1,lvars1,C,S, Suc pc0)#frs)" | 
| 60304 | 75 | apply (unfold exec_all_def) | 
| 76 | apply (rule r_into_rtrancl) | |
| 77 | apply (simp add: gis_def gmb_def split_beta) | |
| 78 | done | |
| 13673 | 79 | |
| 80 | ||
| 81 | (***********************************************************************) | |
| 82 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 83 | definition progression :: "jvm_prog \<Rightarrow> cname \<Rightarrow> sig \<Rightarrow> | 
| 13673 | 84 | aheap \<Rightarrow> opstack \<Rightarrow> locvars \<Rightarrow> | 
| 85 | bytecode \<Rightarrow> | |
| 86 | aheap \<Rightarrow> opstack \<Rightarrow> locvars \<Rightarrow> | |
| 87 | bool" | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 88 |   ("{_,_,_} \<turnstile> {_, _, _} >- _ \<rightarrow> {_, _, _}" [61,61,61,61,61,61,90,61,61,61]60) where
 | 
| 13673 | 89 |   "{G,C,S} \<turnstile> {hp0, os0, lvars0} >- instrs \<rightarrow> {hp1, os1, lvars1} ==
 | 
| 60304 | 90 | \<forall>pre post frs. | 
| 13673 | 91 | (gis (gmb G C S) = pre @ instrs @ post) \<longrightarrow> | 
| 53024 | 92 | G \<turnstile> (None,hp0,(os0,lvars0,C,S,length pre)#frs) \<midarrow>jvm\<rightarrow> | 
| 13673 | 93 | (None,hp1,(os1,lvars1,C,S,(length pre) + (length instrs))#frs)" | 
| 94 | ||
| 95 | ||
| 96 | ||
| 97 | lemma progression_call: | |
| 60304 | 98 | "\<lbrakk> \<forall>pc frs. | 
| 13673 | 99 | exec_instr instr G hp0 os0 lvars0 C S pc frs = | 
| 100 | (None, hp', (os', lvars', C', S', 0) # (fr pc) # frs) \<and> | |
| 101 | gis (gmb G C' S') = instrs' @ [Return] \<and> | |
| 102 |   {G, C', S'} \<turnstile> {hp', os', lvars'} >- instrs' \<rightarrow> {hp'', os'', lvars''}  \<and>
 | |
| 103 | exec_instr Return G hp'' os'' lvars'' C' S' (length instrs') | |
| 104 | ((fr pc) # frs) = | |
| 105 | (None, hp2, (os2, lvars2, C, S, Suc pc) # frs) \<rbrakk> \<Longrightarrow> | |
| 106 |   {G, C, S} \<turnstile> {hp0, os0, lvars0} >-[instr]\<rightarrow> {hp2,os2,lvars2}"
 | |
| 60304 | 107 | apply (simp only: progression_def) | 
| 108 | apply (intro strip) | |
| 109 | apply (drule_tac x="length pre" in spec) | |
| 110 | apply (drule_tac x="frs" in spec) | |
| 111 | apply clarify | |
| 112 | apply (rule exec_all_trans) | |
| 113 | apply (rule exec_instr_in_exec_all) | |
| 114 | apply simp | |
| 115 | apply simp | |
| 116 | apply (rule exec_all_trans) | |
| 117 | apply (simp only: append_Nil) | |
| 118 | apply (drule_tac x="[]" in spec) | |
| 119 | apply (simp only: list.simps list.size) | |
| 120 | apply blast | |
| 121 | apply (rule exec_instr_in_exec_all) | |
| 122 | apply auto | |
| 123 | done | |
| 13673 | 124 | |
| 125 | ||
| 126 | lemma progression_transitive: | |
| 127 | "\<lbrakk> instrs_comb = instrs0 @ instrs1; | |
| 128 |   {G, C, S} \<turnstile> {hp0, os0, lvars0} >- instrs0 \<rightarrow> {hp1, os1, lvars1};
 | |
| 129 |   {G, C, S} \<turnstile> {hp1, os1, lvars1} >- instrs1 \<rightarrow> {hp2, os2, lvars2} \<rbrakk>
 | |
| 130 | \<Longrightarrow> | |
| 131 |   {G, C, S} \<turnstile> {hp0, os0, lvars0} >- instrs_comb \<rightarrow> {hp2, os2, lvars2}"
 | |
| 60304 | 132 | apply (simp only: progression_def) | 
| 133 | apply (intro strip) | |
| 134 | apply (rule_tac ?s1.0 = "Norm (hp1, (os1, lvars1, C, S, | |
| 135 | length pre + length instrs0) # frs)" | |
| 136 | in exec_all_trans) | |
| 137 | apply (simp only: append_assoc) | |
| 138 | apply (erule thin_rl, erule thin_rl) | |
| 139 | apply (drule_tac x="pre @ instrs0" in spec) | |
| 140 | apply (simp add: add.assoc) | |
| 141 | done | |
| 13673 | 142 | |
| 143 | lemma progression_refl: | |
| 144 |   "{G, C, S} \<turnstile> {hp0, os0, lvars0} >- [] \<rightarrow> {hp0, os0, lvars0}"
 | |
| 60304 | 145 | apply (simp add: progression_def) | 
| 146 | apply (intro strip) | |
| 147 | apply (rule exec_all_refl) | |
| 148 | done | |
| 13673 | 149 | |
| 150 | lemma progression_one_step: " | |
| 60304 | 151 | \<forall>pc frs. | 
| 13673 | 152 | (exec_instr i G hp0 os0 lvars0 C S pc frs) = | 
| 153 | (None, hp1, (os1,lvars1,C,S, Suc pc)#frs) | |
| 154 |   \<Longrightarrow> {G, C, S} \<turnstile> {hp0, os0, lvars0} >- [i] \<rightarrow> {hp1, os1, lvars1}"
 | |
| 60304 | 155 | apply (unfold progression_def) | 
| 156 | apply (intro strip) | |
| 157 | apply simp | |
| 158 | apply (rule exec_all_one_step) | |
| 159 | apply auto | |
| 160 | done | |
| 13673 | 161 | |
| 162 | (*****) | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 163 | definition jump_fwd :: "jvm_prog \<Rightarrow> cname \<Rightarrow> sig \<Rightarrow> | 
| 13673 | 164 | aheap \<Rightarrow> locvars \<Rightarrow> opstack \<Rightarrow> opstack \<Rightarrow> | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 165 | instr \<Rightarrow> bytecode \<Rightarrow> bool" where | 
| 13673 | 166 | "jump_fwd G C S hp lvars os0 os1 instr instrs == | 
| 60304 | 167 | \<forall>pre post frs. | 
| 13673 | 168 | (gis (gmb G C S) = pre @ instr # instrs @ post) \<longrightarrow> | 
| 169 | exec_all G (None,hp,(os0,lvars,C,S, length pre)#frs) | |
| 170 | (None,hp,(os1,lvars,C,S,(length pre) + (length instrs) + 1)#frs)" | |
| 171 | ||
| 172 | ||
| 173 | lemma jump_fwd_one_step: | |
| 60304 | 174 | "\<forall>pc frs. | 
| 13673 | 175 | exec_instr instr G hp os0 lvars C S pc frs = | 
| 176 | (None, hp, (os1, lvars, C, S, pc + (length instrs) + 1)#frs) | |
| 177 | \<Longrightarrow> jump_fwd G C S hp lvars os0 os1 instr instrs" | |
| 60304 | 178 | apply (unfold jump_fwd_def) | 
| 179 | apply (intro strip) | |
| 180 | apply (rule exec_instr_in_exec_all) | |
| 181 | apply auto | |
| 182 | done | |
| 13673 | 183 | |
| 184 | ||
| 185 | lemma jump_fwd_progression_aux: | |
| 186 | "\<lbrakk> instrs_comb = instr # instrs0 @ instrs1; | |
| 187 | jump_fwd G C S hp lvars os0 os1 instr instrs0; | |
| 188 |      {G, C, S} \<turnstile> {hp, os1, lvars} >- instrs1 \<rightarrow> {hp2, os2, lvars2} \<rbrakk> 
 | |
| 189 |   \<Longrightarrow> {G, C, S} \<turnstile> {hp, os0, lvars} >- instrs_comb \<rightarrow> {hp2, os2, lvars2}"
 | |
| 60304 | 190 | apply (simp only: progression_def jump_fwd_def) | 
| 191 | apply (intro strip) | |
| 192 | apply (rule_tac ?s1.0 = "Norm(hp, (os1, lvars, C, S, length pre + length instrs0 + 1) # frs)" in exec_all_trans) | |
| 193 | apply (simp only: append_assoc) | |
| 194 | apply (subgoal_tac "pre @ (instr # instrs0 @ instrs1) @ post = pre @ instr # instrs0 @ (instrs1 @ post)") | |
| 195 | apply blast | |
| 196 | apply simp | |
| 197 | apply (erule thin_rl, erule thin_rl) | |
| 198 | apply (drule_tac x="pre @ instr # instrs0" in spec) | |
| 199 | apply (simp add: add.assoc) | |
| 200 | done | |
| 13673 | 201 | |
| 202 | ||
| 203 | lemma jump_fwd_progression: | |
| 204 | "\<lbrakk> instrs_comb = instr # instrs0 @ instrs1; | |
| 205 | \<forall> pc frs. | |
| 206 | exec_instr instr G hp os0 lvars C S pc frs = | |
| 207 | (None, hp, (os1, lvars, C, S, pc + (length instrs0) + 1)#frs); | |
| 208 |   {G, C, S} \<turnstile> {hp, os1, lvars} >- instrs1 \<rightarrow> {hp2, os2, lvars2} \<rbrakk> 
 | |
| 209 |   \<Longrightarrow> {G, C, S}  \<turnstile> {hp, os0, lvars} >- instrs_comb \<rightarrow> {hp2, os2, lvars2}"
 | |
| 60304 | 210 | apply (rule jump_fwd_progression_aux) | 
| 211 | apply assumption | |
| 212 | apply (rule jump_fwd_one_step, assumption+) | |
| 213 | done | |
| 13673 | 214 | |
| 215 | ||
| 216 | (* note: instrs and instr reversed wrt. jump_fwd *) | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 217 | definition jump_bwd :: "jvm_prog \<Rightarrow> cname \<Rightarrow> sig \<Rightarrow> | 
| 13673 | 218 | aheap \<Rightarrow> locvars \<Rightarrow> opstack \<Rightarrow> opstack \<Rightarrow> | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 219 | bytecode \<Rightarrow> instr \<Rightarrow> bool" where | 
| 13673 | 220 | "jump_bwd G C S hp lvars os0 os1 instrs instr == | 
| 221 | \<forall> pre post frs. | |
| 222 | (gis (gmb G C S) = pre @ instrs @ instr # post) \<longrightarrow> | |
| 223 | exec_all G (None,hp,(os0,lvars,C,S, (length pre) + (length instrs))#frs) | |
| 224 | (None,hp,(os1,lvars,C,S, (length pre))#frs)" | |
| 225 | ||
| 226 | ||
| 227 | lemma jump_bwd_one_step: | |
| 228 | "\<forall> pc frs. | |
| 229 | exec_instr instr G hp os0 lvars C S (pc + (length instrs)) frs = | |
| 230 | (None, hp, (os1, lvars, C, S, pc)#frs) | |
| 231 | \<Longrightarrow> | |
| 232 | jump_bwd G C S hp lvars os0 os1 instrs instr" | |
| 60304 | 233 | apply (unfold jump_bwd_def) | 
| 234 | apply (intro strip) | |
| 235 | apply (rule exec_instr_in_exec_all) | |
| 236 | apply auto | |
| 237 | done | |
| 13673 | 238 | |
| 239 | lemma jump_bwd_progression: | |
| 240 | "\<lbrakk> instrs_comb = instrs @ [instr]; | |
| 241 |   {G, C, S} \<turnstile> {hp0, os0, lvars0} >- instrs \<rightarrow> {hp1, os1, lvars1};
 | |
| 242 | jump_bwd G C S hp1 lvars1 os1 os2 instrs instr; | |
| 243 |   {G, C, S} \<turnstile> {hp1, os2, lvars1} >- instrs_comb \<rightarrow> {hp3, os3, lvars3} \<rbrakk> 
 | |
| 244 |   \<Longrightarrow> {G, C, S}  \<turnstile> {hp0, os0, lvars0} >- instrs_comb \<rightarrow> {hp3, os3, lvars3}"
 | |
| 60304 | 245 | apply (simp only: progression_def jump_bwd_def) | 
| 246 | apply (intro strip) | |
| 247 | apply (rule exec_all_trans, force) | |
| 248 | apply (rule exec_all_trans, force) | |
| 249 | apply (rule exec_all_trans, force) | |
| 250 | apply simp | |
| 251 | apply (rule exec_all_refl) | |
| 252 | done | |
| 13673 | 253 | |
| 254 | ||
| 255 | (**********************************************************************) | |
| 256 | ||
| 257 | (* class C with signature S is defined in program G *) | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 258 | definition class_sig_defined :: "'c prog \<Rightarrow> cname \<Rightarrow> sig \<Rightarrow> bool" where | 
| 13673 | 259 | "class_sig_defined G C S == | 
| 260 | is_class G C \<and> (\<exists> D rT mb. (method (G, C) S = Some (D, rT, mb)))" | |
| 261 | ||
| 262 | ||
| 263 | (* The environment of a java method body | |
| 264 | (characterized by class and signature) *) | |
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 265 | definition env_of_jmb :: "java_mb prog \<Rightarrow> cname \<Rightarrow> sig \<Rightarrow> java_mb env" where | 
| 13673 | 266 | "env_of_jmb G C S == | 
| 267 | (let (mn,pTs) = S; | |
| 268 | (D,rT,(pns,lvars,blk,res)) = the(method (G, C) S) in | |
| 269 | (G,map_of lvars(pns[\<mapsto>]pTs)(This\<mapsto>Class C)))" | |
| 270 | ||
| 271 | lemma env_of_jmb_fst [simp]: "fst (env_of_jmb G C S) = G" | |
| 272 | by (simp add: env_of_jmb_def split_beta) | |
| 273 | ||
| 274 | ||
| 275 | (**********************************************************************) | |
| 276 | ||
| 277 | ||
| 278 | lemma method_preserves [rule_format (no_asm)]: | |
| 279 | "\<lbrakk> wf_prog wf_mb G; is_class G C; | |
| 280 | \<forall> S rT mb. \<forall> cn \<in> fst ` set G. wf_mdecl wf_mb G cn (S,rT,mb) \<longrightarrow> (P cn S (rT,mb))\<rbrakk> | |
| 281 | \<Longrightarrow> \<forall> D. | |
| 282 | method (G, C) S = Some (D, rT, mb) \<longrightarrow> (P D S (rT,mb))" | |
| 283 | ||
| 60304 | 284 | apply (frule wf_prog_ws_prog [THEN wf_subcls1]) | 
| 285 | apply (rule subcls1_induct, assumption, assumption) | |
| 13673 | 286 | |
| 60304 | 287 | apply (intro strip) | 
| 288 | apply ((drule spec)+, drule_tac x="Object" in bspec) | |
| 289 | apply (simp add: wf_prog_def ws_prog_def wf_syscls_def) | |
| 290 | apply (subgoal_tac "D=Object") apply simp | |
| 291 | apply (drule mp) | |
| 292 | apply (frule_tac C=Object in method_wf_mdecl) | |
| 293 | apply simp | |
| 294 | apply assumption | |
| 295 | apply simp | |
| 296 | apply assumption | |
| 297 | apply simp | |
| 13673 | 298 | |
| 60304 | 299 | apply (simplesubst method_rec) | 
| 300 | apply simp | |
| 301 | apply force | |
| 302 | apply simp | |
| 303 | apply (simp only: map_add_def) | |
| 304 | apply (split option.split) | |
| 305 | apply (rule conjI) | |
| 306 | apply force | |
| 307 | apply (intro strip) | |
| 308 | apply (frule_tac ?P1.0 = "wf_mdecl wf_mb G Ca" and | |
| 309 | ?P2.0 = "%(S, (Da, rT, mb)). P Da S (rT, mb)" in map_of_map_prop) | |
| 310 | apply (force simp: wf_cdecl_def) | |
| 13673 | 311 | |
| 60304 | 312 | apply clarify | 
| 13673 | 313 | |
| 60304 | 314 | apply (simp only: class_def) | 
| 315 | apply (drule map_of_SomeD)+ | |
| 316 | apply (frule_tac A="set G" and f=fst in imageI, simp) | |
| 317 | apply blast | |
| 318 | apply simp | |
| 319 | done | |
| 13673 | 320 | |
| 321 | ||
| 322 | lemma method_preserves_length: | |
| 323 | "\<lbrakk> wf_java_prog G; is_class G C; | |
| 324 | method (G, C) (mn,pTs) = Some (D, rT, pns, lvars, blk, res)\<rbrakk> | |
| 325 | \<Longrightarrow> length pns = length pTs" | |
| 60304 | 326 | apply (frule_tac P="%D (mn,pTs) (rT, pns, lvars, blk, res). length pns = length pTs" | 
| 327 | in method_preserves) | |
| 328 | apply (auto simp: wf_mdecl_def wf_java_mdecl_def) | |
| 329 | done | |
| 13673 | 330 | |
| 331 | (**********************************************************************) | |
| 332 | ||
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 333 | definition wtpd_expr :: "java_mb env \<Rightarrow> expr \<Rightarrow> bool" where | 
| 13673 | 334 | "wtpd_expr E e == (\<exists> T. E\<turnstile>e :: T)" | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 335 | |
| 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 336 | definition wtpd_exprs :: "java_mb env \<Rightarrow> (expr list) \<Rightarrow> bool" where | 
| 13673 | 337 | "wtpd_exprs E e == (\<exists> T. E\<turnstile>e [::] T)" | 
| 35416 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 338 | |
| 
d8d7d1b785af
replaced a couple of constsdefs by definitions (also some old primrecs by modern ones)
 haftmann parents: 
33639diff
changeset | 339 | definition wtpd_stmt :: "java_mb env \<Rightarrow> stmt \<Rightarrow> bool" where | 
| 13673 | 340 | "wtpd_stmt E c == (E\<turnstile>c \<surd>)" | 
| 341 | ||
| 342 | lemma wtpd_expr_newc: "wtpd_expr E (NewC C) \<Longrightarrow> is_class (prg E) C" | |
| 60304 | 343 | by (simp only: wtpd_expr_def, erule exE, erule ty_expr.cases, auto) | 
| 13673 | 344 | |
| 345 | lemma wtpd_expr_cast: "wtpd_expr E (Cast cn e) \<Longrightarrow> (wtpd_expr E e)" | |
| 60304 | 346 | by (simp only: wtpd_expr_def, erule exE, erule ty_expr.cases, auto) | 
| 13673 | 347 | |
| 60304 | 348 | lemma wtpd_expr_lacc: | 
| 349 | "\<lbrakk> wtpd_expr (env_of_jmb G C S) (LAcc vn); class_sig_defined G C S \<rbrakk> | |
| 13673 | 350 | \<Longrightarrow> vn \<in> set (gjmb_plns (gmb G C S)) \<or> vn = This" | 
| 60304 | 351 | apply (clarsimp simp: wtpd_expr_def env_of_jmb_def class_sig_defined_def galldefs) | 
| 352 | apply (case_tac S) | |
| 353 | apply (erule ty_expr.cases; fastforce dest: map_upds_SomeD map_of_SomeD fst_in_set_lemma) | |
| 354 | done | |
| 13673 | 355 | |
| 356 | lemma wtpd_expr_lass: "wtpd_expr E (vn::=e) | |
| 357 | \<Longrightarrow> (vn \<noteq> This) & (wtpd_expr E (LAcc vn)) & (wtpd_expr E e)" | |
| 60304 | 358 | by (simp only: wtpd_expr_def, erule exE, erule ty_expr.cases, auto) | 
| 13673 | 359 | |
| 360 | lemma wtpd_expr_facc: "wtpd_expr E ({fd}a..fn) 
 | |
| 361 | \<Longrightarrow> (wtpd_expr E a)" | |
| 60304 | 362 | by (simp only: wtpd_expr_def, erule exE, erule ty_expr.cases, auto) | 
| 13673 | 363 | |
| 364 | lemma wtpd_expr_fass: "wtpd_expr E ({fd}a..fn:=v) 
 | |
| 365 |   \<Longrightarrow> (wtpd_expr E ({fd}a..fn)) & (wtpd_expr E v)"
 | |
| 60304 | 366 | by (simp only: wtpd_expr_def, erule exE, erule ty_expr.cases, auto) | 
| 13673 | 367 | |
| 368 | ||
| 369 | lemma wtpd_expr_binop: "wtpd_expr E (BinOp bop e1 e2) | |
| 370 | \<Longrightarrow> (wtpd_expr E e1) & (wtpd_expr E e2)" | |
| 60304 | 371 | by (simp only: wtpd_expr_def, erule exE, erule ty_expr.cases, auto) | 
| 13673 | 372 | |
| 373 | lemma wtpd_exprs_cons: "wtpd_exprs E (e # es) | |
| 374 | \<Longrightarrow> (wtpd_expr E e) & (wtpd_exprs E es)" | |
| 60304 | 375 | by (simp only: wtpd_exprs_def wtpd_expr_def, erule exE, erule ty_exprs.cases, auto) | 
| 13673 | 376 | |
| 377 | lemma wtpd_stmt_expr: "wtpd_stmt E (Expr e) \<Longrightarrow> (wtpd_expr E e)" | |
| 60304 | 378 | by (simp only: wtpd_stmt_def wtpd_expr_def, erule wt_stmt.cases, auto) | 
| 13673 | 379 | |
| 380 | lemma wtpd_stmt_comp: "wtpd_stmt E (s1;; s2) \<Longrightarrow> | |
| 381 | (wtpd_stmt E s1) & (wtpd_stmt E s2)" | |
| 60304 | 382 | by (simp only: wtpd_stmt_def wtpd_expr_def, erule wt_stmt.cases, auto) | 
| 13673 | 383 | |
| 384 | lemma wtpd_stmt_cond: "wtpd_stmt E (If(e) s1 Else s2) \<Longrightarrow> | |
| 385 | (wtpd_expr E e) & (wtpd_stmt E s1) & (wtpd_stmt E s2) | |
| 386 | & (E\<turnstile>e::PrimT Boolean)" | |
| 60304 | 387 | by (simp only: wtpd_stmt_def wtpd_expr_def, erule wt_stmt.cases, auto) | 
| 13673 | 388 | |
| 389 | lemma wtpd_stmt_loop: "wtpd_stmt E (While(e) s) \<Longrightarrow> | |
| 390 | (wtpd_expr E e) & (wtpd_stmt E s) & (E\<turnstile>e::PrimT Boolean)" | |
| 60304 | 391 | by (simp only: wtpd_stmt_def wtpd_expr_def, erule wt_stmt.cases, auto) | 
| 13673 | 392 | |
| 393 | lemma wtpd_expr_call: "wtpd_expr E ({C}a..mn({pTs'}ps))
 | |
| 394 | \<Longrightarrow> (wtpd_expr E a) & (wtpd_exprs E ps) | |
| 395 | & (length ps = length pTs') & (E\<turnstile>a::Class C) | |
| 396 | & (\<exists> pTs md rT. | |
| 397 |        E\<turnstile>ps[::]pTs & max_spec (prg E) C (mn, pTs) = {((md,rT),pTs')})"
 | |
| 60304 | 398 | apply (simp only: wtpd_expr_def wtpd_exprs_def) | 
| 399 | apply (erule exE) | |
| 400 |   apply (ind_cases "E \<turnstile> {C}a..mn( {pTs'}ps) :: T" for T)
 | |
| 401 | apply (auto simp: max_spec_preserves_length) | |
| 402 | done | |
| 13673 | 403 | |
| 404 | lemma wtpd_blk: | |
| 405 | "\<lbrakk> method (G, D) (md, pTs) = Some (D, rT, (pns, lvars, blk, res)); | |
| 406 | wf_prog wf_java_mdecl G; is_class G D \<rbrakk> | |
| 407 | \<Longrightarrow> wtpd_stmt (env_of_jmb G D (md, pTs)) blk" | |
| 60304 | 408 | apply (simp add: wtpd_stmt_def env_of_jmb_def) | 
| 409 | apply (frule_tac P="%D (md, pTs) (rT, (pns, lvars, blk, res)). (G, map_of lvars(pns[\<mapsto>]pTs)(This\<mapsto>Class D)) \<turnstile> blk \<surd> " in method_preserves) | |
| 410 | apply (auto simp: wf_mdecl_def wf_java_mdecl_def) | |
| 411 | done | |
| 13673 | 412 | |
| 413 | lemma wtpd_res: | |
| 414 | "\<lbrakk> method (G, D) (md, pTs) = Some (D, rT, (pns, lvars, blk, res)); | |
| 415 | wf_prog wf_java_mdecl G; is_class G D \<rbrakk> | |
| 416 | \<Longrightarrow> wtpd_expr (env_of_jmb G D (md, pTs)) res" | |
| 60304 | 417 | apply (simp add: wtpd_expr_def env_of_jmb_def) | 
| 418 | apply (frule_tac P="%D (md, pTs) (rT, (pns, lvars, blk, res)). \<exists>T. (G, map_of lvars(pns[\<mapsto>]pTs)(This\<mapsto>Class D)) \<turnstile> res :: T " in method_preserves) | |
| 419 | apply (auto simp: wf_mdecl_def wf_java_mdecl_def) | |
| 420 | done | |
| 13673 | 421 | |
| 422 | ||
| 423 | (**********************************************************************) | |
| 424 | ||
| 425 | ||
| 426 | (* Is there a more elegant proof? *) | |
| 427 | lemma evals_preserves_length: | |
| 428 | "G\<turnstile> xs -es[\<succ>]vs-> (None, s) \<Longrightarrow> length es = length vs" | |
| 60304 | 429 | apply (subgoal_tac | 
| 430 | "\<forall> xs'. (G \<turnstile> xk -xj\<succ>xi-> xh \<longrightarrow> True) & | |
| 431 | (G\<turnstile> xs -es[\<succ>]vs-> xs' \<longrightarrow> (\<exists> s. (xs' = (None, s))) \<longrightarrow> | |
| 432 | length es = length vs) & | |
| 433 | (G \<turnstile> xc -xb-> xa \<longrightarrow> True)") | |
| 434 | apply blast | |
| 435 | apply (rule allI) | |
| 436 | apply (rule Eval.eval_evals_exec.induct; simp) | |
| 437 | done | |
| 13673 | 438 | |
| 439 | (***********************************************************************) | |
| 440 | ||
| 441 | (* required for translation of BinOp *) | |
| 442 | ||
| 443 | ||
| 444 | lemma progression_Eq : "{G, C, S} \<turnstile>
 | |
| 445 |   {hp, (v2 # v1 # os), lvars} 
 | |
| 446 | >- [Ifcmpeq 3, LitPush (Bool False), Goto 2, LitPush (Bool True)] \<rightarrow> | |
| 447 |   {hp, (Bool (v1 = v2) # os), lvars}"
 | |
| 60304 | 448 | apply (case_tac "v1 = v2") | 
| 13673 | 449 | |
| 60304 | 450 | (* case v1 = v2 *) | 
| 451 | apply (rule_tac ?instrs1.0 = "[LitPush (Bool True)]" in jump_fwd_progression) | |
| 452 | apply (auto simp: nat_add_distrib) | |
| 453 | apply (rule progression_one_step) | |
| 454 | apply simp | |
| 13673 | 455 | |
| 60304 | 456 | (* case v1 \<noteq> v2 *) | 
| 457 | apply (rule progression_one_step [THEN HOL.refl [THEN progression_transitive], simplified]) | |
| 458 | apply auto | |
| 459 | apply (rule progression_one_step [THEN HOL.refl [THEN progression_transitive], simplified]) | |
| 460 | apply auto | |
| 461 | apply (rule_tac ?instrs1.0 = "[]" in jump_fwd_progression) | |
| 462 | apply (auto simp: nat_add_distrib intro: progression_refl) | |
| 463 | done | |
| 13673 | 464 | |
| 465 | ||
| 466 | (**********************************************************************) | |
| 467 | ||
| 468 | ||
| 469 | (* to avoid automatic pair splits *) | |
| 470 | ||
| 471 | declare split_paired_All [simp del] split_paired_Ex [simp del] | |
| 472 | ||
| 60304 | 473 | lemma distinct_method: | 
| 474 | "\<lbrakk> wf_java_prog G; is_class G C; method (G, C) S = Some (D, rT, pns, lvars, blk, res) \<rbrakk> \<Longrightarrow> | |
| 13673 | 475 | distinct (gjmb_plns (gmb G C S))" | 
| 60304 | 476 | apply (frule method_wf_mdecl [THEN conjunct2], assumption, assumption) | 
| 477 | apply (case_tac S) | |
| 478 | apply (simp add: wf_mdecl_def wf_java_mdecl_def galldefs) | |
| 479 | apply (simp add: unique_def map_of_in_set) | |
| 480 | apply blast | |
| 481 | done | |
| 13673 | 482 | |
| 483 | lemma distinct_method_if_class_sig_defined : | |
| 60304 | 484 | "\<lbrakk> wf_java_prog G; class_sig_defined G C S \<rbrakk> \<Longrightarrow> distinct (gjmb_plns (gmb G C S))" | 
| 485 | by (auto intro: distinct_method simp: class_sig_defined_def) | |
| 13673 | 486 | |
| 487 | ||
| 488 | lemma method_yields_wf_java_mdecl: "\<lbrakk> wf_java_prog G; is_class G C; | |
| 489 | method (G, C) S = Some (D, rT, pns, lvars, blk, res) \<rbrakk> \<Longrightarrow> | |
| 490 | wf_java_mdecl G D (S,rT,(pns,lvars,blk,res))" | |
| 60304 | 491 | apply (frule method_wf_mdecl) | 
| 492 | apply (auto simp: wf_mdecl_def) | |
| 493 | done | |
| 13673 | 494 | |
| 495 | (**********************************************************************) | |
| 496 | ||
| 497 | ||
| 498 | lemma progression_lvar_init_aux [rule_format (no_asm)]: " | |
| 499 | \<forall> zs prfx lvals lvars0. | |
| 500 | lvars0 = (zs @ lvars) \<longrightarrow> | |
| 501 | (disjoint_varnames pns lvars0 \<longrightarrow> | |
| 502 | (length lvars = length lvals) \<longrightarrow> | |
| 503 | (Suc(length pns + length zs) = length prfx) \<longrightarrow> | |
| 504 |    ({cG, D, S} \<turnstile> 
 | |
| 505 |     {h, os, (prfx @ lvals)}
 | |
| 506 | >- (concat (map (compInit (pns, lvars0, blk, res)) lvars)) \<rightarrow> | |
| 507 |     {h, os, (prfx @ (map (\<lambda>p. (default_val (snd p))) lvars))}))"
 | |
| 60304 | 508 | apply simp | 
| 509 | apply (induct lvars) | |
| 510 | apply (clarsimp, rule progression_refl) | |
| 511 | apply (intro strip) | |
| 512 | apply (case_tac lvals) | |
| 513 | apply simp | |
| 514 | apply (simp (no_asm_simp) ) | |
| 13673 | 515 | |
| 60304 | 516 | apply (rule_tac ?lvars1.0 = "(prfx @ [default_val (snd a)]) @ list" in progression_transitive, rule HOL.refl) | 
| 517 | apply (case_tac a) | |
| 518 | apply (simp (no_asm_simp) add: compInit_def) | |
| 519 | apply (rule_tac ?instrs0.0 = "[load_default_val b]" in progression_transitive, simp) | |
| 520 | apply (rule progression_one_step) | |
| 521 | apply (simp (no_asm_simp) add: load_default_val_def) | |
| 13673 | 522 | |
| 60304 | 523 | apply (rule progression_one_step) | 
| 524 | apply (simp (no_asm_simp)) | |
| 525 | apply (rule conjI, simp)+ | |
| 526 | apply (simp add: index_of_var2) | |
| 527 | apply (drule_tac x="zs @ [a]" in spec) (* instantiate zs *) | |
| 528 | apply (drule mp, simp) | |
| 529 | apply (drule_tac x="(prfx @ [default_val (snd a)])" in spec) (* instantiate prfx *) | |
| 530 | apply auto | |
| 531 | done | |
| 13673 | 532 | |
| 533 | lemma progression_lvar_init [rule_format (no_asm)]: | |
| 534 | "\<lbrakk> wf_java_prog G; is_class G C; | |
| 535 | method (G, C) S = Some (D, rT, pns, lvars, blk, res) \<rbrakk> \<Longrightarrow> | |
| 536 | length pns = length pvs \<longrightarrow> | |
| 537 | (\<forall> lvals. | |
| 538 | length lvars = length lvals \<longrightarrow> | |
| 539 |    {cG, D, S} \<turnstile>
 | |
| 540 |    {h, os, (a' # pvs @ lvals)}
 | |
| 541 | >- (compInitLvars (pns, lvars, blk, res) lvars) \<rightarrow> | |
| 542 |    {h, os, (locvars_xstate G C S (Norm (h, init_vars lvars(pns[\<mapsto>]pvs)(This\<mapsto>a'))))})"
 | |
| 60304 | 543 | apply (simp only: compInitLvars_def) | 
| 544 | apply (frule method_yields_wf_java_mdecl, assumption, assumption) | |
| 13673 | 545 | |
| 60304 | 546 | apply (simp only: wf_java_mdecl_def) | 
| 547 | apply (subgoal_tac "(\<forall>y\<in>set pns. y \<notin> set (map fst lvars))") | |
| 548 | apply (simp add: init_vars_def locvars_xstate_def locvars_locals_def galldefs unique_def split_def map_of_map_as_map_upd del: map_map) | |
| 549 | apply (intro strip) | |
| 550 | apply (simp (no_asm_simp) only: append_Cons [symmetric]) | |
| 551 | apply (rule progression_lvar_init_aux) | |
| 552 | apply (auto simp: unique_def map_of_in_set disjoint_varnames_def) | |
| 553 | done | |
| 13673 | 554 | |
| 555 | ||
| 556 | ||
| 557 | ||
| 558 | (**********************************************************************) | |
| 559 | ||
| 60304 | 560 | lemma state_ok_eval: | 
| 561 | "\<lbrakk>xs::\<preceq>E; wf_java_prog (prg E); wtpd_expr E e; (prg E)\<turnstile>xs -e\<succ>v -> xs'\<rbrakk> \<Longrightarrow> xs'::\<preceq>E" | |
| 562 | apply (simp only: wtpd_expr_def) | |
| 563 | apply (erule exE) | |
| 564 | apply (case_tac xs', case_tac xs) | |
| 565 | apply (auto intro: eval_type_sound [THEN conjunct1]) | |
| 566 | done | |
| 13673 | 567 | |
| 60304 | 568 | lemma state_ok_evals: | 
| 569 | "\<lbrakk>xs::\<preceq>E; wf_java_prog (prg E); wtpd_exprs E es; prg E \<turnstile> xs -es[\<succ>]vs-> xs'\<rbrakk> \<Longrightarrow> xs'::\<preceq>E" | |
| 570 | apply (simp only: wtpd_exprs_def) | |
| 571 | apply (erule exE) | |
| 572 | apply (case_tac xs) | |
| 573 | apply (case_tac xs') | |
| 574 | apply (auto intro: evals_type_sound [THEN conjunct1]) | |
| 575 | done | |
| 13673 | 576 | |
| 60304 | 577 | lemma state_ok_exec: | 
| 578 | "\<lbrakk>xs::\<preceq>E; wf_java_prog (prg E); wtpd_stmt E st; prg E \<turnstile> xs -st-> xs'\<rbrakk> \<Longrightarrow> xs'::\<preceq>E" | |
| 579 | apply (simp only: wtpd_stmt_def) | |
| 580 | apply (case_tac xs', case_tac xs) | |
| 581 | apply (auto dest: exec_type_sound) | |
| 582 | done | |
| 13673 | 583 | |
| 584 | lemma state_ok_init: | |
| 14045 | 585 | "\<lbrakk> wf_java_prog G; (x, h, l)::\<preceq>(env_of_jmb G C S); | 
| 13673 | 586 | is_class G dynT; | 
| 587 | method (G, dynT) (mn, pTs) = Some (md, rT, pns, lvars, blk, res); | |
| 588 | list_all2 (conf G h) pvs pTs; G,h \<turnstile> a' ::\<preceq> Class md\<rbrakk> | |
| 60304 | 589 | \<Longrightarrow> | 
| 590 | (np a' x, h, init_vars lvars(pns[\<mapsto>]pvs)(This\<mapsto>a'))::\<preceq>(env_of_jmb G md (mn, pTs))" | |
| 591 | apply (frule wf_prog_ws_prog) | |
| 592 | apply (frule method_in_md [THEN conjunct2], assumption+) | |
| 593 | apply (frule method_yields_wf_java_mdecl, assumption, assumption) | |
| 594 | apply (simp add: env_of_jmb_def gs_def conforms_def split_beta) | |
| 595 | apply (simp add: wf_java_mdecl_def) | |
| 596 | apply (rule conjI) | |
| 597 | apply (rule lconf_ext) | |
| 598 | apply (rule lconf_ext_list) | |
| 599 | apply (rule lconf_init_vars) | |
| 600 | apply (auto dest: Ball_set_table) | |
| 601 | apply (simp add: np_def xconf_raise_if) | |
| 602 | done | |
| 13673 | 603 | |
| 604 | ||
| 605 | lemma ty_exprs_list_all2 [rule_format (no_asm)]: | |
| 606 | "(\<forall> Ts. (E \<turnstile> es [::] Ts) = list_all2 (\<lambda>e T. E \<turnstile> e :: T) es Ts)" | |
| 60304 | 607 | apply (rule list.induct) | 
| 608 | apply simp | |
| 609 | apply (rule allI) | |
| 610 | apply (rule iffI) | |
| 611 | apply (ind_cases "E \<turnstile> [] [::] Ts" for Ts, assumption) | |
| 612 | apply simp apply (rule WellType.Nil) | |
| 613 | apply (simp add: list_all2_Cons1) | |
| 614 | apply (rule allI) | |
| 615 | apply (rule iffI) | |
| 616 | apply (rename_tac a exs Ts) | |
| 617 | apply (ind_cases "E \<turnstile> a # exs [::] Ts" for a exs Ts) apply blast | |
| 13673 | 618 | apply (auto intro: WellType.Cons) | 
| 60304 | 619 | done | 
| 13673 | 620 | |
| 621 | ||
| 622 | lemma conf_bool: "G,h \<turnstile> v::\<preceq>PrimT Boolean \<Longrightarrow> \<exists> b. v = Bool b" | |
| 60304 | 623 | apply (simp add: conf_def) | 
| 624 | apply (erule exE) | |
| 625 | apply (case_tac v) | |
| 626 | apply (auto elim: widen.cases) | |
| 627 | done | |
| 13673 | 628 | |
| 629 | ||
| 630 | lemma max_spec_widen: "max_spec G C (mn, pTs) = {((md,rT),pTs')} \<Longrightarrow> 
 | |
| 631 | list_all2 (\<lambda> T T'. G \<turnstile> T \<preceq> T') pTs pTs'" | |
| 60304 | 632 | by (blast dest: singleton_in_set max_spec2appl_meths appl_methsD) | 
| 13673 | 633 | |
| 634 | ||
| 14045 | 635 | lemma eval_conf: "\<lbrakk>G \<turnstile> s -e\<succ>v-> s'; wf_java_prog G; s::\<preceq>E; | 
| 13673 | 636 | E\<turnstile>e::T; gx s' = None; prg E = G \<rbrakk> | 
| 637 | \<Longrightarrow> G,gh s'\<turnstile>v::\<preceq>T" | |
| 60304 | 638 | apply (simp add: gh_def) | 
| 639 | apply (rule_tac x3="fst s" and s3="snd s"and x'3="fst s'" | |
| 640 | in eval_type_sound [THEN conjunct2 [THEN conjunct1 [THEN mp]], simplified]) | |
| 641 | apply assumption+ | |
| 642 | apply (simp (no_asm_use)) | |
| 643 | apply (simp only: surjective_pairing [symmetric]) | |
| 644 | apply (auto simp add: gs_def gx_def) | |
| 645 | done | |
| 13673 | 646 | |
| 647 | lemma evals_preserves_conf: | |
| 648 | "\<lbrakk> G\<turnstile> s -es[\<succ>]vs-> s'; G,gh s \<turnstile> t ::\<preceq> T; E \<turnstile>es[::]Ts; | |
| 14045 | 649 | wf_java_prog G; s::\<preceq>E; | 
| 13673 | 650 | prg E = G \<rbrakk> \<Longrightarrow> G,gh s' \<turnstile> t ::\<preceq> T" | 
| 60304 | 651 | apply (subgoal_tac "gh s\<le>| gh s'") | 
| 652 | apply (frule conf_hext, assumption, assumption) | |
| 653 | apply (frule eval_evals_exec_type_sound [THEN conjunct2 [THEN conjunct1 [THEN mp]]]) | |
| 654 | apply (subgoal_tac "G \<turnstile> (gx s, (gh s, gl s)) -es[\<succ>]vs-> (gx s', (gh s', gl s'))") | |
| 655 | apply assumption | |
| 656 | apply (simp add: gx_def gh_def gl_def) | |
| 657 | apply (case_tac E) | |
| 658 | apply (simp add: gx_def gs_def gh_def gl_def) | |
| 659 | done | |
| 13673 | 660 | |
| 60304 | 661 | lemma eval_of_class: | 
| 662 | "\<lbrakk> G \<turnstile> s -e\<succ>a'-> s'; E \<turnstile> e :: Class C; wf_java_prog G; s::\<preceq>E; gx s'=None; a' \<noteq> Null; G=prg E\<rbrakk> | |
| 13673 | 663 | \<Longrightarrow> (\<exists> lc. a' = Addr lc)" | 
| 60304 | 664 | apply (case_tac s, case_tac s', simp) | 
| 665 | apply (frule eval_type_sound, (simp add: gs_def)+) | |
| 666 | apply (case_tac a') | |
| 667 | apply (auto simp: conf_def) | |
| 668 | done | |
| 13673 | 669 | |
| 670 | ||
| 671 | lemma dynT_subcls: | |
| 672 | "\<lbrakk> a' \<noteq> Null; G,h\<turnstile>a'::\<preceq> Class C; dynT = fst (the (h (the_Addr a'))); | |
| 14045 | 673 | is_class G dynT; ws_prog G \<rbrakk> \<Longrightarrow> G\<turnstile>dynT \<preceq>C C" | 
| 60304 | 674 | apply (case_tac "C = Object") | 
| 675 | apply (simp, rule subcls_C_Object, assumption+) | |
| 676 | apply simp | |
| 677 | apply (frule non_np_objD, auto) | |
| 678 | done | |
| 13673 | 679 | |
| 680 | ||
| 681 | lemma method_defined: "\<lbrakk> | |
| 682 | m = the (method (G, dynT) (mn, pTs)); | |
| 683 | dynT = fst (the (h a)); is_class G dynT; wf_java_prog G; | |
| 684 | a' \<noteq> Null; G,h\<turnstile>a'::\<preceq> Class C; a = the_Addr a'; | |
| 685 |   \<exists>pTsa md rT. max_spec G C (mn, pTsa) = {((md, rT), pTs)} \<rbrakk>
 | |
| 686 | \<Longrightarrow> (method (G, dynT) (mn, pTs)) = Some m" | |
| 60304 | 687 | apply (erule exE)+ | 
| 688 | apply (drule singleton_in_set, drule max_spec2appl_meths) | |
| 689 | apply (simp add: appl_methds_def) | |
| 690 | apply (elim exE conjE) | |
| 691 | apply (drule widen_methd) | |
| 692 | apply (auto intro!: dynT_subcls) | |
| 693 | done | |
| 13673 | 694 | |
| 695 | ||
| 696 | ||
| 697 | (**********************************************************************) | |
| 698 | ||
| 699 | ||
| 700 | (* 1. any difference between locvars_xstate \<dots> and L ??? *) | |
| 701 | (* 2. possibly skip env_of_jmb ??? *) | |
| 702 | theorem compiler_correctness: | |
| 703 | "wf_java_prog G \<Longrightarrow> | |
| 22271 | 704 | (G \<turnstile> xs -ex\<succ>val-> xs' \<longrightarrow> | 
| 13673 | 705 | gx xs = None \<longrightarrow> gx xs' = None \<longrightarrow> | 
| 706 | (\<forall> os CL S. | |
| 707 | (class_sig_defined G CL S) \<longrightarrow> | |
| 708 | (wtpd_expr (env_of_jmb G CL S) ex) \<longrightarrow> | |
| 14045 | 709 | (xs ::\<preceq> (env_of_jmb G CL S)) \<longrightarrow> | 
| 13673 | 710 |   ( {TranslComp.comp G, CL, S} \<turnstile>
 | 
| 711 |     {gh xs, os, (locvars_xstate G CL S xs)}
 | |
| 712 | >- (compExpr (gmb G CL S) ex) \<rightarrow> | |
| 713 |     {gh xs', val#os, locvars_xstate G CL S xs'}))) \<and> 
 | |
| 714 | ||
| 22271 | 715 | (G \<turnstile> xs -exs[\<succ>]vals-> xs' \<longrightarrow> | 
| 13673 | 716 | gx xs = None \<longrightarrow> gx xs' = None \<longrightarrow> | 
| 717 | (\<forall> os CL S. | |
| 718 | (class_sig_defined G CL S) \<longrightarrow> | |
| 719 | (wtpd_exprs (env_of_jmb G CL S) exs) \<longrightarrow> | |
| 14045 | 720 | (xs::\<preceq>(env_of_jmb G CL S)) \<longrightarrow> | 
| 13673 | 721 |   ( {TranslComp.comp G, CL, S} \<turnstile>
 | 
| 722 |     {gh xs, os, (locvars_xstate G CL S xs)}
 | |
| 723 | >- (compExprs (gmb G CL S) exs) \<rightarrow> | |
| 724 |     {gh xs', (rev vals)@os, (locvars_xstate G CL S xs')}))) \<and> 
 | |
| 725 | ||
| 22271 | 726 | (G \<turnstile> xs -st-> xs' \<longrightarrow> | 
| 13673 | 727 | gx xs = None \<longrightarrow> gx xs' = None \<longrightarrow> | 
| 728 | (\<forall> os CL S. | |
| 729 | (class_sig_defined G CL S) \<longrightarrow> | |
| 730 | (wtpd_stmt (env_of_jmb G CL S) st) \<longrightarrow> | |
| 14045 | 731 | (xs::\<preceq>(env_of_jmb G CL S)) \<longrightarrow> | 
| 13673 | 732 |   ( {TranslComp.comp G, CL, S} \<turnstile>
 | 
| 733 |     {gh xs, os, (locvars_xstate G CL S xs)}
 | |
| 734 | >- (compStmt (gmb G CL S) st) \<rightarrow> | |
| 735 |     {gh xs', os, (locvars_xstate G CL S xs')})))"
 | |
| 60304 | 736 | apply (rule Eval.eval_evals_exec.induct) | 
| 13673 | 737 | |
| 60304 | 738 | (* case XcptE *) | 
| 739 | apply simp | |
| 13673 | 740 | |
| 60304 | 741 | (* case NewC *) | 
| 742 | apply clarify | |
| 67613 | 743 | apply (frule wf_prog_ws_prog [THEN wf_subcls1]) (* establish wf ((subcls1 G)\<inverse>) *) | 
| 60304 | 744 | apply (simp add: c_hupd_hp_invariant) | 
| 745 | apply (rule progression_one_step) | |
| 746 | apply (rotate_tac 1, drule sym) (* reverse equation (a, None) = new_Addr (fst s) *) | |
| 747 | apply (simp add: locvars_xstate_def locvars_locals_def comp_fields) | |
| 13673 | 748 | |
| 749 | ||
| 60304 | 750 | (* case Cast *) | 
| 751 | apply (intro allI impI) | |
| 752 | apply simp | |
| 753 | apply (frule raise_if_NoneD) | |
| 754 | apply (frule wtpd_expr_cast) | |
| 755 | apply simp | |
| 756 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e)" in progression_transitive, simp) | |
| 757 | apply blast | |
| 758 | apply (rule progression_one_step) | |
| 759 | apply (simp add: raise_system_xcpt_def gh_def comp_cast_ok) | |
| 13673 | 760 | |
| 761 | ||
| 60304 | 762 | (* case Lit *) | 
| 763 | apply simp | |
| 764 | apply (intro strip) | |
| 765 | apply (rule progression_one_step) | |
| 766 | apply simp | |
| 767 | ||
| 768 | ||
| 769 | (* case BinOp *) | |
| 770 | apply (intro allI impI) | |
| 771 | apply (frule_tac xs=s1 in eval_xcpt, assumption) (* establish (gx s1 = None) *) | |
| 772 | apply (frule wtpd_expr_binop) | |
| 773 | (* establish (s1::\<preceq> \<dots>) *) | |
| 774 | apply (frule_tac e=e1 in state_ok_eval) apply (simp (no_asm_simp)) | |
| 775 | apply simp | |
| 776 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 777 | |
| 778 | ||
| 60304 | 779 | apply (simp (no_asm_use) only: compExpr.simps compExprs.simps) | 
| 780 | apply (rule_tac ?instrs0.0 = "compExpr (gmb G CL S) e1" in progression_transitive, simp) apply blast | |
| 781 | apply (rule_tac ?instrs0.0 = "compExpr (gmb G CL S) e2" in progression_transitive, simp) apply blast | |
| 782 | apply (case_tac bop) | |
| 783 | (*subcase bop = Eq *) | |
| 784 | apply simp | |
| 785 | apply (rule progression_Eq) | |
| 786 | (*subcase bop = Add *) | |
| 787 | apply simp | |
| 788 | apply (rule progression_one_step) | |
| 789 | apply simp | |
| 13673 | 790 | |
| 791 | ||
| 60304 | 792 | (* case LAcc *) | 
| 793 | apply simp | |
| 794 | apply (intro strip) | |
| 795 | apply (rule progression_one_step) | |
| 796 | apply (simp add: locvars_xstate_def locvars_locals_def) | |
| 797 | apply (frule wtpd_expr_lacc) | |
| 798 | apply assumption | |
| 799 | apply (simp add: gl_def) | |
| 800 | apply (erule select_at_index) | |
| 13673 | 801 | |
| 802 | ||
| 60304 | 803 | (* case LAss *) | 
| 804 | apply (intro allI impI) | |
| 805 | apply (frule wtpd_expr_lass, erule conjE, erule conjE) | |
| 806 | apply simp | |
| 13673 | 807 | |
| 60304 | 808 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e)" in progression_transitive, rule HOL.refl) | 
| 809 | apply blast | |
| 13673 | 810 | |
| 60304 | 811 | apply (rule_tac ?instrs0.0 = "[Dup]" in progression_transitive, simp) | 
| 812 | apply (rule progression_one_step) | |
| 813 | apply (simp add: gh_def) | |
| 814 | apply simp | |
| 815 | apply (rule progression_one_step) | |
| 816 | apply (simp add: gh_def) | |
| 817 | (* the following falls out of the general scheme *) | |
| 818 | apply (frule wtpd_expr_lacc) apply assumption | |
| 819 | apply (rule update_at_index) | |
| 820 | apply (rule distinct_method_if_class_sig_defined) | |
| 821 | apply assumption | |
| 822 | apply assumption | |
| 823 | apply simp | |
| 824 | apply assumption | |
| 13673 | 825 | |
| 826 | ||
| 60304 | 827 | (* case FAcc *) | 
| 828 | apply (intro allI impI) | |
| 829 | (* establish x1 = None \<and> a' \<noteq> Null *) | |
| 830 | apply (simp (no_asm_use) only: gx_conv, frule np_NoneD) | |
| 831 | apply (frule wtpd_expr_facc) | |
| 13673 | 832 | |
| 60304 | 833 | apply (simp (no_asm_use) only: compExpr.simps compExprs.simps) | 
| 834 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e)" in progression_transitive, rule HOL.refl) | |
| 835 | apply blast | |
| 836 | apply (rule progression_one_step) | |
| 837 | apply (simp add: gh_def) | |
| 838 | apply (case_tac "(the (fst s1 (the_Addr a')))") | |
| 839 | apply (simp add: raise_system_xcpt_def) | |
| 13673 | 840 | |
| 841 | ||
| 60304 | 842 | (* case FAss *) | 
| 843 | apply (intro allI impI) | |
| 844 | apply (frule wtpd_expr_fass) apply (erule conjE) apply (frule wtpd_expr_facc) | |
| 845 | apply (simp only: c_hupd_xcpt_invariant) (* establish x2 = None *) | |
| 846 | (* establish x1 = None and a' \<noteq> Null *) | |
| 847 | apply (frule_tac xs="(np a' x1, s1)" in eval_xcpt) | |
| 848 | apply (simp only: gx_conv, simp only: gx_conv, frule np_NoneD, erule conjE) | |
| 13673 | 849 | |
| 850 | ||
| 60304 | 851 | (* establish ((Norm s1)::\<preceq> \<dots>) *) | 
| 852 | apply (frule_tac e=e1 in state_ok_eval) | |
| 853 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 854 | apply assumption | |
| 855 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 856 | |
| 60304 | 857 | apply (simp only: compExpr.simps compExprs.simps) | 
| 13673 | 858 | |
| 60304 | 859 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e1)" in progression_transitive, rule HOL.refl) | 
| 860 | apply fast (* blast does not seem to work - why? *) | |
| 861 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e2)" in progression_transitive, rule HOL.refl) | |
| 862 | apply fast | |
| 863 | apply (rule_tac ?instrs0.0 = "[Dup_x1]" and ?instrs1.0 = "[Putfield fn T]" in progression_transitive, simp) | |
| 13673 | 864 | |
| 60304 | 865 | (* Dup_x1 *) | 
| 866 | apply (rule progression_one_step) | |
| 867 | apply (simp add: gh_def) | |
| 13673 | 868 | |
| 60304 | 869 | (* Putfield \<longrightarrow> still looks nasty*) | 
| 870 | apply (rule progression_one_step) | |
| 871 | apply simp | |
| 872 | apply (case_tac "(the (fst s2 (the_Addr a')))") | |
| 873 | apply (simp add: c_hupd_hp_invariant) | |
| 874 | apply (case_tac s2) | |
| 875 | apply (simp add: c_hupd_conv raise_system_xcpt_def) | |
| 876 | apply (rule locvars_xstate_par_dep, rule HOL.refl) | |
| 13673 | 877 | |
| 60304 | 878 | defer (* method call *) | 
| 13673 | 879 | |
| 60304 | 880 | (* case XcptEs *) | 
| 881 | apply simp | |
| 13673 | 882 | |
| 60304 | 883 | (* case Nil *) | 
| 884 | apply simp | |
| 885 | apply (intro strip) | |
| 886 | apply (rule progression_refl) | |
| 13673 | 887 | |
| 60304 | 888 | (* case Cons *) | 
| 889 | apply (intro allI impI) | |
| 890 | apply (frule_tac xs=s1 in evals_xcpt, simp only: gx_conv) (* establish gx s1 = None *) | |
| 891 | apply (frule wtpd_exprs_cons) | |
| 892 | (* establish ((Norm s0)::\<preceq> \<dots>) *) | |
| 893 | apply (frule_tac e=e in state_ok_eval) | |
| 894 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 895 | apply simp | |
| 896 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 897 | |
| 60304 | 898 | apply simp | 
| 899 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e)" in progression_transitive, rule HOL.refl) | |
| 900 | apply fast | |
| 901 | apply fast | |
| 13673 | 902 | |
| 903 | ||
| 60304 | 904 | (* case Statement: exception *) | 
| 905 | apply simp | |
| 13673 | 906 | |
| 60304 | 907 | (* case Skip *) | 
| 908 | apply (intro allI impI) | |
| 909 | apply simp | |
| 910 | apply (rule progression_refl) | |
| 13673 | 911 | |
| 60304 | 912 | (* case Expr *) | 
| 913 | apply (intro allI impI) | |
| 914 | apply (frule wtpd_stmt_expr) | |
| 915 | apply simp | |
| 916 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e)" in progression_transitive, rule HOL.refl) | |
| 917 | apply fast | |
| 918 | apply (rule progression_one_step) | |
| 919 | apply simp | |
| 13673 | 920 | |
| 60304 | 921 | (* case Comp *) | 
| 922 | apply (intro allI impI) | |
| 923 | apply (frule_tac xs=s1 in exec_xcpt, assumption) (* establish (gx s1 = None) *) | |
| 924 | apply (frule wtpd_stmt_comp) | |
| 13673 | 925 | |
| 60304 | 926 | (* establish (s1::\<preceq> \<dots>) *) | 
| 927 | apply (frule_tac st=c1 in state_ok_exec) | |
| 928 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 929 | apply simp apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 930 | |
| 60304 | 931 | apply simp | 
| 932 | apply (rule_tac ?instrs0.0 = "(compStmt (gmb G CL S) c1)" in progression_transitive, rule HOL.refl) | |
| 933 | apply fast | |
| 934 | apply fast | |
| 13673 | 935 | |
| 936 | ||
| 60304 | 937 | (* case Cond *) | 
| 938 | apply (intro allI impI) | |
| 939 | apply (frule_tac xs=s1 in exec_xcpt, assumption) (* establish (gx s1 = None) *) | |
| 940 | apply (frule wtpd_stmt_cond, (erule conjE)+) | |
| 941 | (* establish (s1::\<preceq> \<dots>) *) | |
| 942 | apply (frule_tac e=e in state_ok_eval) | |
| 943 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 944 | apply assumption | |
| 945 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 946 | (* establish G,gh s1\<turnstile>v::\<preceq>PrimT Boolean *) | |
| 947 | apply (frule eval_conf, assumption+, rule env_of_jmb_fst) | |
| 948 | apply (frule conf_bool) (* establish \<exists>b. v = Bool b *) | |
| 949 | apply (erule exE) | |
| 13673 | 950 | |
| 60304 | 951 | apply simp | 
| 952 | apply (rule_tac ?instrs0.0 = "[LitPush (Bool False)]" in progression_transitive, simp (no_asm_simp)) | |
| 953 | apply (rule progression_one_step, simp) | |
| 13673 | 954 | |
| 60304 | 955 | apply (rule_tac ?instrs0.0 = "compExpr (gmb G CL S) e" in progression_transitive, rule HOL.refl) | 
| 956 | apply fast | |
| 13673 | 957 | |
| 60304 | 958 | apply (case_tac b) | 
| 959 | (* case b= True *) | |
| 960 | apply simp | |
| 961 | apply (rule_tac ?instrs0.0 = "[Ifcmpeq (2 + int (length (compStmt (gmb G CL S) c1)))]" in progression_transitive, simp) | |
| 962 | apply (rule progression_one_step) | |
| 963 | apply simp | |
| 964 | apply (rule_tac ?instrs0.0 = "(compStmt (gmb G CL S) c1)" in progression_transitive, simp) | |
| 965 | apply fast | |
| 966 | apply (rule_tac ?instrs1.0 = "[]" in jump_fwd_progression) | |
| 967 | apply (simp) | |
| 968 | apply simp | |
| 969 | apply (rule conjI, simp) | |
| 970 | apply (simp add: nat_add_distrib) | |
| 971 | apply (rule progression_refl) | |
| 13673 | 972 | |
| 60304 | 973 | (* case b= False *) | 
| 974 | apply simp | |
| 975 | apply (rule_tac ?instrs1.0 = "compStmt (gmb G CL S) c2" in jump_fwd_progression) | |
| 976 | apply (simp) | |
| 977 | apply (simp, rule conjI, rule HOL.refl, simp add: nat_add_distrib) | |
| 978 | apply fast | |
| 13673 | 979 | |
| 60304 | 980 | (* case exit Loop *) | 
| 981 | apply (intro allI impI) | |
| 982 | apply (frule wtpd_stmt_loop, (erule conjE)+) | |
| 13673 | 983 | |
| 60304 | 984 | (* establish G,gh s1\<turnstile>v::\<preceq>PrimT Boolean *) | 
| 985 | apply (frule eval_conf, assumption+, rule env_of_jmb_fst) | |
| 986 | apply (frule conf_bool) (* establish \<exists>b. v = Bool b *) | |
| 987 | apply (erule exE) | |
| 988 | apply (case_tac b) | |
| 989 | ||
| 990 | (* case b= True \<longrightarrow> contradiction *) | |
| 991 | apply simp | |
| 13673 | 992 | |
| 60304 | 993 | (* case b= False *) | 
| 994 | apply simp | |
| 995 | ||
| 996 | apply (rule_tac ?instrs0.0 = "[LitPush (Bool False)]" in progression_transitive, simp (no_asm_simp)) | |
| 997 | apply (rule progression_one_step) | |
| 998 | apply simp | |
| 13673 | 999 | |
| 60304 | 1000 | apply (rule_tac ?instrs0.0 = "compExpr (gmb G CL S) e" in progression_transitive, rule HOL.refl) | 
| 1001 | apply fast | |
| 1002 | apply (rule_tac ?instrs1.0 = "[]" in jump_fwd_progression) | |
| 1003 | apply (simp) | |
| 1004 | apply (simp, rule conjI, rule HOL.refl, simp add: nat_add_distrib) | |
| 1005 | apply (rule progression_refl) | |
| 13673 | 1006 | |
| 1007 | ||
| 60304 | 1008 | (* case continue Loop *) | 
| 1009 | apply (intro allI impI) | |
| 1010 | apply (frule_tac xs=s2 in exec_xcpt, assumption) (* establish (gx s2 = None) *) | |
| 1011 | apply (frule_tac xs=s1 in exec_xcpt, assumption) (* establish (gx s1 = None) *) | |
| 1012 | apply (frule wtpd_stmt_loop, (erule conjE)+) | |
| 13673 | 1013 | |
| 60304 | 1014 | (* establish (s1::\<preceq> \<dots>) *) | 
| 1015 | apply (frule_tac e=e in state_ok_eval) | |
| 1016 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 1017 | apply simp | |
| 1018 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 1019 | (* establish (s2::\<preceq> \<dots>) *) | |
| 1020 | apply (frule_tac xs=s1 and st=c in state_ok_exec) | |
| 1021 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 1022 | apply assumption | |
| 1023 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 1024 | |
| 60304 | 1025 | (* establish G,gh s1\<turnstile>v::\<preceq>PrimT Boolean *) | 
| 1026 | apply (frule eval_conf, assumption+, rule env_of_jmb_fst) | |
| 1027 | apply (frule conf_bool) (* establish \<exists>b. v = Bool b *) | |
| 1028 | apply (erule exE) | |
| 13673 | 1029 | |
| 60304 | 1030 | apply simp | 
| 1031 | apply (rule jump_bwd_progression) | |
| 1032 | apply simp | |
| 1033 | ||
| 1034 | apply (rule_tac ?instrs0.0 = "[LitPush (Bool False)]" in progression_transitive, simp (no_asm_simp)) | |
| 1035 | apply (rule progression_one_step) | |
| 1036 | apply simp | |
| 13673 | 1037 | |
| 60304 | 1038 | apply (rule_tac ?instrs0.0 = "compExpr (gmb G CL S) e" in progression_transitive, rule HOL.refl) | 
| 1039 | apply fast | |
| 13673 | 1040 | |
| 60304 | 1041 | apply (case_tac b) | 
| 1042 | (* case b= True *) | |
| 1043 | apply simp | |
| 13673 | 1044 | |
| 60304 | 1045 | apply (rule_tac ?instrs0.0 = "[Ifcmpeq (2 + int (length (compStmt (gmb G CL S) c)))]" in progression_transitive, simp) | 
| 1046 | apply (rule progression_one_step) | |
| 1047 | apply simp | |
| 1048 | apply fast | |
| 13673 | 1049 | |
| 60304 | 1050 | (* case b= False \<longrightarrow> contradiction*) | 
| 1051 | apply simp | |
| 13673 | 1052 | |
| 60304 | 1053 | apply (rule jump_bwd_one_step) | 
| 1054 | apply simp | |
| 1055 | apply blast | |
| 13673 | 1056 | |
| 60304 | 1057 | (*****) | 
| 1058 | (* case method call *) | |
| 13673 | 1059 | |
| 60304 | 1060 | apply (intro allI impI) | 
| 13673 | 1061 | |
| 60304 | 1062 | apply (frule_tac xs=s3 in eval_xcpt, simp only: gx_conv) (* establish gx s3 = None *) | 
| 1063 | apply (frule exec_xcpt, assumption, simp (no_asm_use) only: gx_conv, frule np_NoneD) (* establish x = None \<and> a' \<noteq> Null *) | |
| 1064 | apply (frule evals_xcpt, simp only: gx_conv) (* establish gx s1 = None *) | |
| 13673 | 1065 | |
| 60304 | 1066 | apply (frule wtpd_expr_call, (erule conjE)+) | 
| 13673 | 1067 | |
| 1068 | ||
| 60304 | 1069 | (* assumptions about state_ok and is_class *) | 
| 13673 | 1070 | |
| 60304 | 1071 | (* establish s1::\<preceq> (env_of_jmb G CL S) *) | 
| 1072 | apply (frule_tac xs="Norm s0" and e=e in state_ok_eval) | |
| 1073 | apply (simp (no_asm_simp) only: env_of_jmb_fst, assumption, simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 1074 | |
| 60304 | 1075 | (* establish (x, h, l)::\<preceq>(env_of_jmb G CL S) *) | 
| 1076 | apply (frule_tac xs=s1 and xs'="(x, h, l)" in state_ok_evals) | |
| 1077 | apply (simp (no_asm_simp) only: env_of_jmb_fst, assumption, simp only: env_of_jmb_fst) | |
| 13673 | 1078 | |
| 60304 | 1079 | (* establish \<exists> lc. a' = Addr lc *) | 
| 1080 | apply (frule (5) eval_of_class, rule env_of_jmb_fst [symmetric]) | |
| 1081 | apply (subgoal_tac "G,h \<turnstile> a' ::\<preceq> Class C") | |
| 1082 | apply (subgoal_tac "is_class G dynT") | |
| 13673 | 1083 | |
| 60304 | 1084 | (* establish method (G, dynT) (mn, pTs) = Some(md, rT, pns, lvars, blk, res) *) | 
| 1085 | apply (drule method_defined, assumption+) | |
| 1086 | apply (simp only: env_of_jmb_fst) | |
| 1087 | apply ((erule exE)+, erule conjE, (rule exI)+, assumption) | |
| 13673 | 1088 | |
| 60304 | 1089 | apply (subgoal_tac "is_class G md") | 
| 1090 | apply (subgoal_tac "G\<turnstile>Class dynT \<preceq> Class md") | |
| 1091 | apply (subgoal_tac " method (G, md) (mn, pTs) = Some (md, rT, pns, lvars, blk, res)") | |
| 1092 | apply (subgoal_tac "list_all2 (conf G h) pvs pTs") | |
| 13673 | 1093 | |
| 60304 | 1094 | (* establish (np a' x, h, init_vars lvars(pns[\<mapsto>]pvs)(This\<mapsto>a'))::\<preceq>(env_of_jmb G md (mn, pTs)) *) | 
| 1095 | apply (subgoal_tac "G,h \<turnstile> a' ::\<preceq> Class dynT") | |
| 1096 | apply (frule (2) conf_widen) | |
| 1097 | apply (frule state_ok_init, assumption+) | |
| 13673 | 1098 | |
| 60304 | 1099 | apply (subgoal_tac "class_sig_defined G md (mn, pTs)") | 
| 1100 | apply (frule wtpd_blk, assumption, assumption) | |
| 1101 | apply (frule wtpd_res, assumption, assumption) | |
| 1102 | apply (subgoal_tac "s3::\<preceq>(env_of_jmb G md (mn, pTs))") | |
| 13673 | 1103 | |
| 60304 | 1104 | apply (subgoal_tac "method (TranslComp.comp G, md) (mn, pTs) = | 
| 1105 | Some (md, rT, snd (snd (compMethod G md ((mn, pTs), rT, pns, lvars, blk, res))))") | |
| 1106 | prefer 2 | |
| 1107 | apply (simp add: wf_prog_ws_prog [THEN comp_method]) | |
| 1108 | apply (subgoal_tac "method (TranslComp.comp G, dynT) (mn, pTs) = | |
| 1109 | Some (md, rT, snd (snd (compMethod G md ((mn, pTs), rT, pns, lvars, blk, res))))") | |
| 1110 | prefer 2 | |
| 1111 | apply (simp add: wf_prog_ws_prog [THEN comp_method]) | |
| 1112 | apply (simp only: fst_conv snd_conv) | |
| 13673 | 1113 | |
| 60304 | 1114 | (* establish length pns = length pTs *) | 
| 1115 | apply (frule method_preserves_length, assumption, assumption) | |
| 1116 | (* establish length pvs = length ps *) | |
| 1117 | apply (frule evals_preserves_length [symmetric]) | |
| 13673 | 1118 | |
| 60304 | 1119 | (** start evaluating subexpressions **) | 
| 1120 | apply (simp (no_asm_use) only: compExpr.simps compExprs.simps) | |
| 13673 | 1121 | |
| 60304 | 1122 | (* evaluate e *) | 
| 1123 | apply (rule_tac ?instrs0.0 = "(compExpr (gmb G CL S) e)" in progression_transitive, rule HOL.refl) | |
| 1124 | apply fast | |
| 1125 | ||
| 1126 | (* evaluate parameters *) | |
| 1127 | apply (rule_tac ?instrs0.0 = "compExprs (gmb G CL S) ps" in progression_transitive, rule HOL.refl) | |
| 1128 | apply fast | |
| 13673 | 1129 | |
| 60304 | 1130 | (* invokation *) | 
| 1131 | apply (rule progression_call) | |
| 1132 | apply (intro allI impI conjI) | |
| 1133 | (* execute Invoke statement *) | |
| 1134 | apply (simp (no_asm_use) only: exec_instr.simps) | |
| 1135 | apply (erule thin_rl, erule thin_rl, erule thin_rl) | |
| 1136 | apply (simp add: compMethod_def raise_system_xcpt_def) | |
| 13673 | 1137 | |
| 60304 | 1138 | (* get instructions of invoked method *) | 
| 1139 | apply (simp (no_asm_simp) add: gis_def gmb_def compMethod_def) | |
| 13673 | 1140 | |
| 60304 | 1141 | (* var. initialization *) | 
| 1142 | apply (rule_tac ?instrs0.0 = "(compInitLvars (pns, lvars, blk, res) lvars)" in progression_transitive, rule HOL.refl) | |
| 1143 | apply (rule_tac C=md in progression_lvar_init, assumption, assumption, assumption) | |
| 1144 | apply (simp (no_asm_simp)) (* length pns = length pvs *) | |
| 1145 | apply (simp (no_asm_simp)) (* length lvars = length (replicate (length lvars) undefined) *) | |
| 13673 | 1146 | |
| 1147 | ||
| 60304 | 1148 | (* body statement *) | 
| 1149 | apply (rule_tac ?instrs0.0 = "compStmt (pns, lvars, blk, res) blk" in progression_transitive, rule HOL.refl) | |
| 1150 | apply (subgoal_tac "(pns, lvars, blk, res) = gmb G md (mn, pTs)") | |
| 1151 | apply (simp (no_asm_simp)) | |
| 1152 | apply (simp only: gh_conv) | |
| 1153 | apply (drule mp [OF _ TrueI])+ | |
| 1154 | apply (erule allE, erule allE, erule allE, erule impE, assumption)+ | |
| 1155 | apply ((erule impE, assumption)+, assumption) | |
| 15860 | 1156 | |
| 60304 | 1157 | apply (simp (no_asm_use)) | 
| 1158 | apply (simp (no_asm_simp) add: gmb_def) | |
| 13673 | 1159 | |
| 60304 | 1160 | (* return expression *) | 
| 1161 | apply (subgoal_tac "(pns, lvars, blk, res) = gmb G md (mn, pTs)") | |
| 1162 | apply (simp (no_asm_simp)) | |
| 1163 | apply (simp only: gh_conv) | |
| 1164 | apply ((drule mp, rule TrueI)+, (drule spec)+, (drule mp, assumption)+, assumption) | |
| 1165 | apply (simp (no_asm_use)) | |
| 1166 | apply (simp (no_asm_simp) add: gmb_def) | |
| 13673 | 1167 | |
| 60304 | 1168 | (* execute return statement *) | 
| 1169 | apply (simp (no_asm_use) add: gh_def locvars_xstate_def gl_def del: drop_append) | |
| 1170 | apply (subgoal_tac "rev pvs @ a' # os = (rev (a' # pvs)) @ os") | |
| 1171 | apply (simp only: drop_append) | |
| 1172 | apply (simp (no_asm_simp)) | |
| 1173 | apply (simp (no_asm_simp)) | |
| 13673 | 1174 | |
| 60304 | 1175 | (* show s3::\<preceq>\<dots> *) | 
| 1176 | apply (rule_tac xs = "(np a' x, h, init_vars lvars(pns[\<mapsto>]pvs)(This\<mapsto>a'))" and st=blk in state_ok_exec) | |
| 1177 | apply assumption | |
| 1178 | apply (simp (no_asm_simp) only: env_of_jmb_fst) | |
| 1179 | apply assumption | |
| 1180 | apply (simp (no_asm_use) only: env_of_jmb_fst) | |
| 13673 | 1181 | |
| 60304 | 1182 | (* show class_sig_defined G md (mn, pTs) *) | 
| 1183 | apply (simp (no_asm_simp) add: class_sig_defined_def) | |
| 13673 | 1184 | |
| 60304 | 1185 | (* show G,h \<turnstile> a' ::\<preceq> Class dynT *) | 
| 1186 | apply (frule non_npD) | |
| 1187 | apply assumption | |
| 1188 | apply (erule exE)+ | |
| 1189 | apply simp | |
| 1190 | apply (rule conf_obj_AddrI) | |
| 1191 | apply simp | |
| 1192 | apply (rule widen_Class_Class [THEN iffD1], rule widen.refl) | |
| 13673 | 1193 | |
| 1194 | ||
| 60304 | 1195 | (* show list_all2 (conf G h) pvs pTs *) | 
| 1196 | apply (erule exE)+ apply (erule conjE)+ | |
| 1197 | apply (rule_tac Ts="pTsa" in conf_list_gext_widen) | |
| 1198 | apply assumption | |
| 1199 | apply (subgoal_tac "G \<turnstile> (gx s1, gs s1) -ps[\<succ>]pvs-> (x, h, l)") | |
| 1200 | apply (frule_tac E="env_of_jmb G CL S" in evals_type_sound) | |
| 1201 | apply assumption+ | |
| 1202 | apply (simp only: env_of_jmb_fst) | |
| 1203 | apply (simp add: conforms_def xconf_def gs_def) | |
| 1204 | apply simp | |
| 1205 | apply (simp (no_asm_use) only: gx_def gs_def surjective_pairing [symmetric]) | |
| 1206 | apply (simp (no_asm_use) only: ty_exprs_list_all2) | |
| 1207 | apply simp | |
| 1208 | apply simp | |
| 1209 | apply (simp (no_asm_use) only: gx_def gs_def surjective_pairing [symmetric]) | |
| 1210 | (* list_all2 (\<lambda>T T'. G \<turnstile> T \<preceq> T') pTsa pTs *) | |
| 1211 | apply (rule max_spec_widen, simp only: env_of_jmb_fst) | |
| 13673 | 1212 | |
| 1213 | ||
| 60304 | 1214 | (* show method (G, md) (mn, pTs) = Some (md, rT, pns, lvars, blk, res) *) | 
| 1215 | apply (frule wf_prog_ws_prog [THEN method_in_md [THEN conjunct2]], assumption+) | |
| 13673 | 1216 | |
| 60304 | 1217 | (* show G\<turnstile>Class dynT \<preceq> Class md *) | 
| 1218 | apply (simp (no_asm_use) only: widen_Class_Class) | |
| 1219 | apply (rule method_wf_mdecl [THEN conjunct1], assumption+) | |
| 13673 | 1220 | |
| 60304 | 1221 | (* is_class G md *) | 
| 1222 | apply (rule wf_prog_ws_prog [THEN method_in_md [THEN conjunct1]], assumption+) | |
| 13673 | 1223 | |
| 60304 | 1224 | (* show is_class G dynT *) | 
| 1225 | apply (frule non_npD) | |
| 1226 | apply assumption | |
| 1227 | apply (erule exE)+ | |
| 1228 | apply (erule conjE)+ | |
| 1229 | apply simp | |
| 1230 | apply (rule subcls_is_class2) | |
| 1231 | apply assumption | |
| 1232 | apply (frule expr_class_is_class [rotated]) | |
| 1233 | apply (simp only: env_of_jmb_fst) | |
| 1234 | apply (rule wf_prog_ws_prog, assumption) | |
| 1235 | apply (simp only: env_of_jmb_fst) | |
| 13673 | 1236 | |
| 60304 | 1237 | (* show G,h \<turnstile> a' ::\<preceq> Class C *) | 
| 1238 | apply (simp only: wtpd_exprs_def, erule exE) | |
| 1239 | apply (frule evals_preserves_conf) | |
| 1240 | apply (rule eval_conf, assumption+) | |
| 1241 | apply (rule env_of_jmb_fst, assumption+) | |
| 1242 | apply (rule env_of_jmb_fst) | |
| 1243 | apply (simp only: gh_conv) | |
| 1244 | done | |
| 13673 | 1245 | |
| 1246 | ||
| 1247 | theorem compiler_correctness_eval: " | |
| 1248 | \<lbrakk> G \<turnstile> (None,hp,loc) -ex \<succ> val-> (None,hp',loc'); | |
| 1249 | wf_java_prog G; | |
| 1250 | class_sig_defined G C S; | |
| 1251 | wtpd_expr (env_of_jmb G C S) ex; | |
| 1252 | (None,hp,loc) ::\<preceq> (env_of_jmb G C S) \<rbrakk> \<Longrightarrow> | |
| 1253 |   {(TranslComp.comp G), C, S} \<turnstile> 
 | |
| 1254 |     {hp, os, (locvars_locals G C S loc)}
 | |
| 1255 | >- (compExpr (gmb G C S) ex) \<rightarrow> | |
| 1256 |     {hp', val#os, (locvars_locals G C S loc')}"
 | |
| 60304 | 1257 | apply (frule compiler_correctness [THEN conjunct1]) | 
| 1258 | apply (auto simp: gh_def gx_def gs_def gl_def locvars_xstate_def) | |
| 1259 | done | |
| 13673 | 1260 | |
| 1261 | theorem compiler_correctness_exec: " | |
| 22271 | 1262 | \<lbrakk> G \<turnstile> Norm (hp, loc) -st-> Norm (hp', loc'); | 
| 13673 | 1263 | wf_java_prog G; | 
| 1264 | class_sig_defined G C S; | |
| 1265 | wtpd_stmt (env_of_jmb G C S) st; | |
| 1266 | (None,hp,loc) ::\<preceq> (env_of_jmb G C S) \<rbrakk> \<Longrightarrow> | |
| 1267 |   {(TranslComp.comp G), C, S} \<turnstile> 
 | |
| 1268 |     {hp, os, (locvars_locals G C S loc)}
 | |
| 1269 | >- (compStmt (gmb G C S) st) \<rightarrow> | |
| 1270 |     {hp', os, (locvars_locals G C S loc')}"
 | |
| 60304 | 1271 | apply (frule compiler_correctness [THEN conjunct2 [THEN conjunct2]]) | 
| 1272 | apply (auto simp: gh_def gx_def gs_def gl_def locvars_xstate_def) | |
| 1273 | done | |
| 13673 | 1274 | |
| 1275 | (**********************************************************************) | |
| 1276 | ||
| 1277 | ||
| 1278 | (* reinstall pair splits *) | |
| 1279 | declare split_paired_All [simp] split_paired_Ex [simp] | |
| 1280 | ||
| 14045 | 1281 | declare wf_prog_ws_prog [simp del] | 
| 1282 | ||
| 13673 | 1283 | end |