24 \item statements are typed like expressions with dummy type Void |
24 \item statements are typed like expressions with dummy type Void |
25 \item the typing rules take an extra argument that is capable of determining |
25 \item the typing rules take an extra argument that is capable of determining |
26 the dynamic type of objects. Therefore, they can be used for both |
26 the dynamic type of objects. Therefore, they can be used for both |
27 checking static types and determining runtime types in transition semantics. |
27 checking static types and determining runtime types in transition semantics. |
28 \end{itemize} |
28 \end{itemize} |
29 *} |
29 \<close> |
30 |
30 |
31 type_synonym lenv |
31 type_synonym lenv |
32 = "(lname, ty) table" --{* local variables, including This and Result*} |
32 = "(lname, ty) table" \<comment>\<open>local variables, including This and Result\<close> |
33 |
33 |
34 record env = |
34 record env = |
35 prg:: "prog" --{* program *} |
35 prg:: "prog" \<comment>\<open>program\<close> |
36 cls:: "qtname" --{* current package and class name *} |
36 cls:: "qtname" \<comment>\<open>current package and class name\<close> |
37 lcl:: "lenv" --{* local environment *} |
37 lcl:: "lenv" \<comment>\<open>local environment\<close> |
38 |
38 |
39 translations |
39 translations |
40 (type) "lenv" <= (type) "(lname, ty) table" |
40 (type) "lenv" <= (type) "(lname, ty) table" |
41 (type) "lenv" <= (type) "lname \<Rightarrow> ty option" |
41 (type) "lenv" <= (type) "lname \<Rightarrow> ty option" |
42 (type) "env" <= (type) "\<lparr>prg::prog,cls::qtname,lcl::lenv\<rparr>" |
42 (type) "env" <= (type) "\<lparr>prg::prog,cls::qtname,lcl::lenv\<rparr>" |
43 (type) "env" <= (type) "\<lparr>prg::prog,cls::qtname,lcl::lenv,\<dots>::'a\<rparr>" |
43 (type) "env" <= (type) "\<lparr>prg::prog,cls::qtname,lcl::lenv,\<dots>::'a\<rparr>" |
44 |
44 |
45 |
45 |
46 abbreviation |
46 abbreviation |
47 pkg :: "env \<Rightarrow> pname" --{* select the current package from an environment *} |
47 pkg :: "env \<Rightarrow> pname" \<comment>\<open>select the current package from an environment\<close> |
48 where "pkg e == pid (cls e)" |
48 where "pkg e == pid (cls e)" |
49 |
49 |
50 subsubsection "Static overloading: maximally specific methods " |
50 subsubsection "Static overloading: maximally specific methods " |
51 |
51 |
52 type_synonym |
52 type_synonym |
53 emhead = "ref_ty \<times> mhead" |
53 emhead = "ref_ty \<times> mhead" |
54 |
54 |
55 --{* Some mnemotic selectors for emhead *} |
55 \<comment>\<open>Some mnemotic selectors for emhead\<close> |
56 definition |
56 definition |
57 "declrefT" :: "emhead \<Rightarrow> ref_ty" |
57 "declrefT" :: "emhead \<Rightarrow> ref_ty" |
58 where "declrefT = fst" |
58 where "declrefT = fst" |
59 |
59 |
60 definition |
60 definition |
105 accObjectmheads G S (IfaceT I) sig)" |
105 accObjectmheads G S (IfaceT I) sig)" |
106 | "mheads G S (ClassT C) = cmheads G S C" |
106 | "mheads G S (ClassT C) = cmheads G S C" |
107 | "mheads G S (ArrayT T) = accObjectmheads G S (ArrayT T)" |
107 | "mheads G S (ArrayT T) = accObjectmheads G S (ArrayT T)" |
108 |
108 |
109 definition |
109 definition |
110 --{* applicable methods, cf. 15.11.2.1 *} |
110 \<comment>\<open>applicable methods, cf. 15.11.2.1\<close> |
111 appl_methds :: "prog \<Rightarrow> qtname \<Rightarrow> ref_ty \<Rightarrow> sig \<Rightarrow> (emhead \<times> ty list) set" where |
111 appl_methds :: "prog \<Rightarrow> qtname \<Rightarrow> ref_ty \<Rightarrow> sig \<Rightarrow> (emhead \<times> ty list) set" where |
112 "appl_methds G S rt = (\<lambda> sig. |
112 "appl_methds G S rt = (\<lambda> sig. |
113 {(mh,pTs') |mh pTs'. mh \<in> mheads G S rt \<lparr>name=name sig,parTs=pTs'\<rparr> \<and> |
113 {(mh,pTs') |mh pTs'. mh \<in> mheads G S rt \<lparr>name=name sig,parTs=pTs'\<rparr> \<and> |
114 G\<turnstile>(parTs sig)[\<preceq>]pTs'})" |
114 G\<turnstile>(parTs sig)[\<preceq>]pTs'})" |
115 |
115 |
116 definition |
116 definition |
117 --{* more specific methods, cf. 15.11.2.2 *} |
117 \<comment>\<open>more specific methods, cf. 15.11.2.2\<close> |
118 more_spec :: "prog \<Rightarrow> emhead \<times> ty list \<Rightarrow> emhead \<times> ty list \<Rightarrow> bool" where |
118 more_spec :: "prog \<Rightarrow> emhead \<times> ty list \<Rightarrow> emhead \<times> ty list \<Rightarrow> bool" where |
119 "more_spec G = (\<lambda>(mh,pTs). \<lambda>(mh',pTs'). G\<turnstile>pTs[\<preceq>]pTs')" |
119 "more_spec G = (\<lambda>(mh,pTs). \<lambda>(mh',pTs'). G\<turnstile>pTs[\<preceq>]pTs')" |
120 (*more_spec G \<equiv>\<lambda>((d,h),pTs). \<lambda>((d',h'),pTs'). G\<turnstile>RefT d\<preceq>RefT d'\<and>G\<turnstile>pTs[\<preceq>]pTs'*) |
120 (*more_spec G \<equiv>\<lambda>((d,h),pTs). \<lambda>((d',h'),pTs'). G\<turnstile>RefT d\<preceq>RefT d'\<and>G\<turnstile>pTs[\<preceq>]pTs'*) |
121 |
121 |
122 definition |
122 definition |
123 --{* maximally specific methods, cf. 15.11.2.2 *} |
123 \<comment>\<open>maximally specific methods, cf. 15.11.2.2\<close> |
124 max_spec :: "prog \<Rightarrow> qtname \<Rightarrow> ref_ty \<Rightarrow> sig \<Rightarrow> (emhead \<times> ty list) set" where |
124 max_spec :: "prog \<Rightarrow> qtname \<Rightarrow> ref_ty \<Rightarrow> sig \<Rightarrow> (emhead \<times> ty list) set" where |
125 "max_spec G S rt sig = {m. m \<in>appl_methds G S rt sig \<and> |
125 "max_spec G S rt sig = {m. m \<in>appl_methds G S rt sig \<and> |
126 (\<forall>m'\<in>appl_methds G S rt sig. more_spec G m' m \<longrightarrow> m'=m)}" |
126 (\<forall>m'\<in>appl_methds G S rt sig. more_spec G m' m \<longrightarrow> m'=m)}" |
127 |
127 |
128 |
128 |
260 "E,dt\<Turnstile>s\<Colon>\<surd> \<equiv> E,dt\<Turnstile>In1r s\<Colon>Inl (PrimT Void)" |
260 "E,dt\<Turnstile>s\<Colon>\<surd> \<equiv> E,dt\<Turnstile>In1r s\<Colon>Inl (PrimT Void)" |
261 | "E,dt\<Turnstile>e\<Colon>-T \<equiv> E,dt\<Turnstile>In1l e\<Colon>Inl T" |
261 | "E,dt\<Turnstile>e\<Colon>-T \<equiv> E,dt\<Turnstile>In1l e\<Colon>Inl T" |
262 | "E,dt\<Turnstile>e\<Colon>=T \<equiv> E,dt\<Turnstile>In2 e\<Colon>Inl T" |
262 | "E,dt\<Turnstile>e\<Colon>=T \<equiv> E,dt\<Turnstile>In2 e\<Colon>Inl T" |
263 | "E,dt\<Turnstile>e\<Colon>\<doteq>T \<equiv> E,dt\<Turnstile>In3 e\<Colon>Inr T" |
263 | "E,dt\<Turnstile>e\<Colon>\<doteq>T \<equiv> E,dt\<Turnstile>In3 e\<Colon>Inr T" |
264 |
264 |
265 --{* well-typed statements *} |
265 \<comment>\<open>well-typed statements\<close> |
266 |
266 |
267 | Skip: "E,dt\<Turnstile>Skip\<Colon>\<surd>" |
267 | Skip: "E,dt\<Turnstile>Skip\<Colon>\<surd>" |
268 |
268 |
269 | Expr: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-T\<rbrakk> \<Longrightarrow> |
269 | Expr: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-T\<rbrakk> \<Longrightarrow> |
270 E,dt\<Turnstile>Expr e\<Colon>\<surd>" |
270 E,dt\<Turnstile>Expr e\<Colon>\<surd>" |
271 --{* cf. 14.6 *} |
271 \<comment>\<open>cf. 14.6\<close> |
272 | Lab: "E,dt\<Turnstile>c\<Colon>\<surd> \<Longrightarrow> |
272 | Lab: "E,dt\<Turnstile>c\<Colon>\<surd> \<Longrightarrow> |
273 E,dt\<Turnstile>l\<bullet> c\<Colon>\<surd>" |
273 E,dt\<Turnstile>l\<bullet> c\<Colon>\<surd>" |
274 |
274 |
275 | Comp: "\<lbrakk>E,dt\<Turnstile>c1\<Colon>\<surd>; |
275 | Comp: "\<lbrakk>E,dt\<Turnstile>c1\<Colon>\<surd>; |
276 E,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
276 E,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
277 E,dt\<Turnstile>c1;; c2\<Colon>\<surd>" |
277 E,dt\<Turnstile>c1;; c2\<Colon>\<surd>" |
278 |
278 |
279 --{* cf. 14.8 *} |
279 \<comment>\<open>cf. 14.8\<close> |
280 | If: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-PrimT Boolean; |
280 | If: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-PrimT Boolean; |
281 E,dt\<Turnstile>c1\<Colon>\<surd>; |
281 E,dt\<Turnstile>c1\<Colon>\<surd>; |
282 E,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
282 E,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
283 E,dt\<Turnstile>If(e) c1 Else c2\<Colon>\<surd>" |
283 E,dt\<Turnstile>If(e) c1 Else c2\<Colon>\<surd>" |
284 |
284 |
285 --{* cf. 14.10 *} |
285 \<comment>\<open>cf. 14.10\<close> |
286 | Loop: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-PrimT Boolean; |
286 | Loop: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-PrimT Boolean; |
287 E,dt\<Turnstile>c\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
287 E,dt\<Turnstile>c\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
288 E,dt\<Turnstile>l\<bullet> While(e) c\<Colon>\<surd>" |
288 E,dt\<Turnstile>l\<bullet> While(e) c\<Colon>\<surd>" |
289 --{* cf. 14.13, 14.15, 14.16 *} |
289 \<comment>\<open>cf. 14.13, 14.15, 14.16\<close> |
290 | Jmp: "E,dt\<Turnstile>Jmp jump\<Colon>\<surd>" |
290 | Jmp: "E,dt\<Turnstile>Jmp jump\<Colon>\<surd>" |
291 |
291 |
292 --{* cf. 14.16 *} |
292 \<comment>\<open>cf. 14.16\<close> |
293 | Throw: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-Class tn; |
293 | Throw: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-Class tn; |
294 prg E\<turnstile>tn\<preceq>\<^sub>C SXcpt Throwable\<rbrakk> \<Longrightarrow> |
294 prg E\<turnstile>tn\<preceq>\<^sub>C SXcpt Throwable\<rbrakk> \<Longrightarrow> |
295 E,dt\<Turnstile>Throw e\<Colon>\<surd>" |
295 E,dt\<Turnstile>Throw e\<Colon>\<surd>" |
296 --{* cf. 14.18 *} |
296 \<comment>\<open>cf. 14.18\<close> |
297 | Try: "\<lbrakk>E,dt\<Turnstile>c1\<Colon>\<surd>; prg E\<turnstile>tn\<preceq>\<^sub>C SXcpt Throwable; |
297 | Try: "\<lbrakk>E,dt\<Turnstile>c1\<Colon>\<surd>; prg E\<turnstile>tn\<preceq>\<^sub>C SXcpt Throwable; |
298 lcl E (VName vn)=None; E \<lparr>lcl := lcl E(VName vn\<mapsto>Class tn)\<rparr>,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> |
298 lcl E (VName vn)=None; E \<lparr>lcl := lcl E(VName vn\<mapsto>Class tn)\<rparr>,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> |
299 \<Longrightarrow> |
299 \<Longrightarrow> |
300 E,dt\<Turnstile>Try c1 Catch(tn vn) c2\<Colon>\<surd>" |
300 E,dt\<Turnstile>Try c1 Catch(tn vn) c2\<Colon>\<surd>" |
301 |
301 |
302 --{* cf. 14.18 *} |
302 \<comment>\<open>cf. 14.18\<close> |
303 | Fin: "\<lbrakk>E,dt\<Turnstile>c1\<Colon>\<surd>; E,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
303 | Fin: "\<lbrakk>E,dt\<Turnstile>c1\<Colon>\<surd>; E,dt\<Turnstile>c2\<Colon>\<surd>\<rbrakk> \<Longrightarrow> |
304 E,dt\<Turnstile>c1 Finally c2\<Colon>\<surd>" |
304 E,dt\<Turnstile>c1 Finally c2\<Colon>\<surd>" |
305 |
305 |
306 | Init: "\<lbrakk>is_class (prg E) C\<rbrakk> \<Longrightarrow> |
306 | Init: "\<lbrakk>is_class (prg E) C\<rbrakk> \<Longrightarrow> |
307 E,dt\<Turnstile>Init C\<Colon>\<surd>" |
307 E,dt\<Turnstile>Init C\<Colon>\<surd>" |
308 --{* @{term Init} is created on the fly during evaluation (see Eval.thy). |
308 \<comment>\<open>@{term Init} is created on the fly during evaluation (see Eval.thy). |
309 The class isn't necessarily accessible from the points @{term Init} |
309 The class isn't necessarily accessible from the points @{term Init} |
310 is called. Therefor we only demand @{term is_class} and not |
310 is called. Therefor we only demand @{term is_class} and not |
311 @{term is_acc_class} here. |
311 @{term is_acc_class} here. |
312 *} |
312 \<close> |
313 |
313 |
314 --{* well-typed expressions *} |
314 \<comment>\<open>well-typed expressions\<close> |
315 |
315 |
316 --{* cf. 15.8 *} |
316 \<comment>\<open>cf. 15.8\<close> |
317 | NewC: "\<lbrakk>is_acc_class (prg E) (pkg E) C\<rbrakk> \<Longrightarrow> |
317 | NewC: "\<lbrakk>is_acc_class (prg E) (pkg E) C\<rbrakk> \<Longrightarrow> |
318 E,dt\<Turnstile>NewC C\<Colon>-Class C" |
318 E,dt\<Turnstile>NewC C\<Colon>-Class C" |
319 --{* cf. 15.9 *} |
319 \<comment>\<open>cf. 15.9\<close> |
320 | NewA: "\<lbrakk>is_acc_type (prg E) (pkg E) T; |
320 | NewA: "\<lbrakk>is_acc_type (prg E) (pkg E) T; |
321 E,dt\<Turnstile>i\<Colon>-PrimT Integer\<rbrakk> \<Longrightarrow> |
321 E,dt\<Turnstile>i\<Colon>-PrimT Integer\<rbrakk> \<Longrightarrow> |
322 E,dt\<Turnstile>New T[i]\<Colon>-T.[]" |
322 E,dt\<Turnstile>New T[i]\<Colon>-T.[]" |
323 |
323 |
324 --{* cf. 15.15 *} |
324 \<comment>\<open>cf. 15.15\<close> |
325 | Cast: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-T; is_acc_type (prg E) (pkg E) T'; |
325 | Cast: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-T; is_acc_type (prg E) (pkg E) T'; |
326 prg E\<turnstile>T\<preceq>? T'\<rbrakk> \<Longrightarrow> |
326 prg E\<turnstile>T\<preceq>? T'\<rbrakk> \<Longrightarrow> |
327 E,dt\<Turnstile>Cast T' e\<Colon>-T'" |
327 E,dt\<Turnstile>Cast T' e\<Colon>-T'" |
328 |
328 |
329 --{* cf. 15.19.2 *} |
329 \<comment>\<open>cf. 15.19.2\<close> |
330 | Inst: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-RefT T; is_acc_type (prg E) (pkg E) (RefT T'); |
330 | Inst: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-RefT T; is_acc_type (prg E) (pkg E) (RefT T'); |
331 prg E\<turnstile>RefT T\<preceq>? RefT T'\<rbrakk> \<Longrightarrow> |
331 prg E\<turnstile>RefT T\<preceq>? RefT T'\<rbrakk> \<Longrightarrow> |
332 E,dt\<Turnstile>e InstOf T'\<Colon>-PrimT Boolean" |
332 E,dt\<Turnstile>e InstOf T'\<Colon>-PrimT Boolean" |
333 |
333 |
334 --{* cf. 15.7.1 *} |
334 \<comment>\<open>cf. 15.7.1\<close> |
335 | Lit: "\<lbrakk>typeof dt x = Some T\<rbrakk> \<Longrightarrow> |
335 | Lit: "\<lbrakk>typeof dt x = Some T\<rbrakk> \<Longrightarrow> |
336 E,dt\<Turnstile>Lit x\<Colon>-T" |
336 E,dt\<Turnstile>Lit x\<Colon>-T" |
337 |
337 |
338 | UnOp: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-Te; wt_unop unop Te; T=PrimT (unop_type unop)\<rbrakk> |
338 | UnOp: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-Te; wt_unop unop Te; T=PrimT (unop_type unop)\<rbrakk> |
339 \<Longrightarrow> |
339 \<Longrightarrow> |
342 | BinOp: "\<lbrakk>E,dt\<Turnstile>e1\<Colon>-T1; E,dt\<Turnstile>e2\<Colon>-T2; wt_binop (prg E) binop T1 T2; |
342 | BinOp: "\<lbrakk>E,dt\<Turnstile>e1\<Colon>-T1; E,dt\<Turnstile>e2\<Colon>-T2; wt_binop (prg E) binop T1 T2; |
343 T=PrimT (binop_type binop)\<rbrakk> |
343 T=PrimT (binop_type binop)\<rbrakk> |
344 \<Longrightarrow> |
344 \<Longrightarrow> |
345 E,dt\<Turnstile>BinOp binop e1 e2\<Colon>-T" |
345 E,dt\<Turnstile>BinOp binop e1 e2\<Colon>-T" |
346 |
346 |
347 --{* cf. 15.10.2, 15.11.1 *} |
347 \<comment>\<open>cf. 15.10.2, 15.11.1\<close> |
348 | Super: "\<lbrakk>lcl E This = Some (Class C); C \<noteq> Object; |
348 | Super: "\<lbrakk>lcl E This = Some (Class C); C \<noteq> Object; |
349 class (prg E) C = Some c\<rbrakk> \<Longrightarrow> |
349 class (prg E) C = Some c\<rbrakk> \<Longrightarrow> |
350 E,dt\<Turnstile>Super\<Colon>-Class (super c)" |
350 E,dt\<Turnstile>Super\<Colon>-Class (super c)" |
351 |
351 |
352 --{* cf. 15.13.1, 15.10.1, 15.12 *} |
352 \<comment>\<open>cf. 15.13.1, 15.10.1, 15.12\<close> |
353 | Acc: "\<lbrakk>E,dt\<Turnstile>va\<Colon>=T\<rbrakk> \<Longrightarrow> |
353 | Acc: "\<lbrakk>E,dt\<Turnstile>va\<Colon>=T\<rbrakk> \<Longrightarrow> |
354 E,dt\<Turnstile>Acc va\<Colon>-T" |
354 E,dt\<Turnstile>Acc va\<Colon>-T" |
355 |
355 |
356 --{* cf. 15.25, 15.25.1 *} |
356 \<comment>\<open>cf. 15.25, 15.25.1\<close> |
357 | Ass: "\<lbrakk>E,dt\<Turnstile>va\<Colon>=T; va \<noteq> LVar This; |
357 | Ass: "\<lbrakk>E,dt\<Turnstile>va\<Colon>=T; va \<noteq> LVar This; |
358 E,dt\<Turnstile>v \<Colon>-T'; |
358 E,dt\<Turnstile>v \<Colon>-T'; |
359 prg E\<turnstile>T'\<preceq>T\<rbrakk> \<Longrightarrow> |
359 prg E\<turnstile>T'\<preceq>T\<rbrakk> \<Longrightarrow> |
360 E,dt\<Turnstile>va:=v\<Colon>-T'" |
360 E,dt\<Turnstile>va:=v\<Colon>-T'" |
361 |
361 |
362 --{* cf. 15.24 *} |
362 \<comment>\<open>cf. 15.24\<close> |
363 | Cond: "\<lbrakk>E,dt\<Turnstile>e0\<Colon>-PrimT Boolean; |
363 | Cond: "\<lbrakk>E,dt\<Turnstile>e0\<Colon>-PrimT Boolean; |
364 E,dt\<Turnstile>e1\<Colon>-T1; E,dt\<Turnstile>e2\<Colon>-T2; |
364 E,dt\<Turnstile>e1\<Colon>-T1; E,dt\<Turnstile>e2\<Colon>-T2; |
365 prg E\<turnstile>T1\<preceq>T2 \<and> T = T2 \<or> prg E\<turnstile>T2\<preceq>T1 \<and> T = T1\<rbrakk> \<Longrightarrow> |
365 prg E\<turnstile>T1\<preceq>T2 \<and> T = T2 \<or> prg E\<turnstile>T2\<preceq>T1 \<and> T = T1\<rbrakk> \<Longrightarrow> |
366 E,dt\<Turnstile>e0 ? e1 : e2\<Colon>-T" |
366 E,dt\<Turnstile>e0 ? e1 : e2\<Colon>-T" |
367 |
367 |
368 --{* cf. 15.11.1, 15.11.2, 15.11.3 *} |
368 \<comment>\<open>cf. 15.11.1, 15.11.2, 15.11.3\<close> |
369 | Call: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-RefT statT; |
369 | Call: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-RefT statT; |
370 E,dt\<Turnstile>ps\<Colon>\<doteq>pTs; |
370 E,dt\<Turnstile>ps\<Colon>\<doteq>pTs; |
371 max_spec (prg E) (cls E) statT \<lparr>name=mn,parTs=pTs\<rparr> |
371 max_spec (prg E) (cls E) statT \<lparr>name=mn,parTs=pTs\<rparr> |
372 = {((statDeclT,m),pTs')} |
372 = {((statDeclT,m),pTs')} |
373 \<rbrakk> \<Longrightarrow> |
373 \<rbrakk> \<Longrightarrow> |
375 |
375 |
376 | Methd: "\<lbrakk>is_class (prg E) C; |
376 | Methd: "\<lbrakk>is_class (prg E) C; |
377 methd (prg E) C sig = Some m; |
377 methd (prg E) C sig = Some m; |
378 E,dt\<Turnstile>Body (declclass m) (stmt (mbody (mthd m)))\<Colon>-T\<rbrakk> \<Longrightarrow> |
378 E,dt\<Turnstile>Body (declclass m) (stmt (mbody (mthd m)))\<Colon>-T\<rbrakk> \<Longrightarrow> |
379 E,dt\<Turnstile>Methd C sig\<Colon>-T" |
379 E,dt\<Turnstile>Methd C sig\<Colon>-T" |
380 --{* The class @{term C} is the dynamic class of the method call |
380 \<comment>\<open>The class @{term C} is the dynamic class of the method call |
381 (cf. Eval.thy). |
381 (cf. Eval.thy). |
382 It hasn't got to be directly accessible from the current package |
382 It hasn't got to be directly accessible from the current package |
383 @{term "(pkg E)"}. |
383 @{term "(pkg E)"}. |
384 Only the static class must be accessible (enshured indirectly by |
384 Only the static class must be accessible (enshured indirectly by |
385 @{term Call}). |
385 @{term Call}). |
386 Note that l is just a dummy value. It is only used in the smallstep |
386 Note that l is just a dummy value. It is only used in the smallstep |
387 semantics. To proof typesafety directly for the smallstep semantics |
387 semantics. To proof typesafety directly for the smallstep semantics |
388 we would have to assume conformance of l here! |
388 we would have to assume conformance of l here! |
389 *} |
389 \<close> |
390 |
390 |
391 | Body: "\<lbrakk>is_class (prg E) D; |
391 | Body: "\<lbrakk>is_class (prg E) D; |
392 E,dt\<Turnstile>blk\<Colon>\<surd>; |
392 E,dt\<Turnstile>blk\<Colon>\<surd>; |
393 (lcl E) Result = Some T; |
393 (lcl E) Result = Some T; |
394 is_type (prg E) T\<rbrakk> \<Longrightarrow> |
394 is_type (prg E) T\<rbrakk> \<Longrightarrow> |
395 E,dt\<Turnstile>Body D blk\<Colon>-T" |
395 E,dt\<Turnstile>Body D blk\<Colon>-T" |
396 --{* The class @{term D} implementing the method must not directly be |
396 \<comment>\<open>The class @{term D} implementing the method must not directly be |
397 accessible from the current package @{term "(pkg E)"}, but can also |
397 accessible from the current package @{term "(pkg E)"}, but can also |
398 be indirectly accessible due to inheritance (enshured in @{term Call}) |
398 be indirectly accessible due to inheritance (enshured in @{term Call}) |
399 The result type hasn't got to be accessible in Java! (If it is not |
399 The result type hasn't got to be accessible in Java! (If it is not |
400 accessible you can only assign it to Object). |
400 accessible you can only assign it to Object). |
401 For dummy value l see rule @{term Methd}. |
401 For dummy value l see rule @{term Methd}. |
402 *} |
402 \<close> |
403 |
403 |
404 --{* well-typed variables *} |
404 \<comment>\<open>well-typed variables\<close> |
405 |
405 |
406 --{* cf. 15.13.1 *} |
406 \<comment>\<open>cf. 15.13.1\<close> |
407 | LVar: "\<lbrakk>lcl E vn = Some T; is_acc_type (prg E) (pkg E) T\<rbrakk> \<Longrightarrow> |
407 | LVar: "\<lbrakk>lcl E vn = Some T; is_acc_type (prg E) (pkg E) T\<rbrakk> \<Longrightarrow> |
408 E,dt\<Turnstile>LVar vn\<Colon>=T" |
408 E,dt\<Turnstile>LVar vn\<Colon>=T" |
409 --{* cf. 15.10.1 *} |
409 \<comment>\<open>cf. 15.10.1\<close> |
410 | FVar: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-Class C; |
410 | FVar: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-Class C; |
411 accfield (prg E) (cls E) C fn = Some (statDeclC,f)\<rbrakk> \<Longrightarrow> |
411 accfield (prg E) (cls E) C fn = Some (statDeclC,f)\<rbrakk> \<Longrightarrow> |
412 E,dt\<Turnstile>{cls E,statDeclC,is_static f}e..fn\<Colon>=(type f)" |
412 E,dt\<Turnstile>{cls E,statDeclC,is_static f}e..fn\<Colon>=(type f)" |
413 --{* cf. 15.12 *} |
413 \<comment>\<open>cf. 15.12\<close> |
414 | AVar: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-T.[]; |
414 | AVar: "\<lbrakk>E,dt\<Turnstile>e\<Colon>-T.[]; |
415 E,dt\<Turnstile>i\<Colon>-PrimT Integer\<rbrakk> \<Longrightarrow> |
415 E,dt\<Turnstile>i\<Colon>-PrimT Integer\<rbrakk> \<Longrightarrow> |
416 E,dt\<Turnstile>e.[i]\<Colon>=T" |
416 E,dt\<Turnstile>e.[i]\<Colon>=T" |
417 |
417 |
418 |
418 |
419 --{* well-typed expression lists *} |
419 \<comment>\<open>well-typed expression lists\<close> |
420 |
420 |
421 --{* cf. 15.11.??? *} |
421 \<comment>\<open>cf. 15.11.???\<close> |
422 | Nil: "E,dt\<Turnstile>[]\<Colon>\<doteq>[]" |
422 | Nil: "E,dt\<Turnstile>[]\<Colon>\<doteq>[]" |
423 |
423 |
424 --{* cf. 15.11.??? *} |
424 \<comment>\<open>cf. 15.11.???\<close> |
425 | Cons: "\<lbrakk>E,dt\<Turnstile>e \<Colon>-T; |
425 | Cons: "\<lbrakk>E,dt\<Turnstile>e \<Colon>-T; |
426 E,dt\<Turnstile>es\<Colon>\<doteq>Ts\<rbrakk> \<Longrightarrow> |
426 E,dt\<Turnstile>es\<Colon>\<doteq>Ts\<rbrakk> \<Longrightarrow> |
427 E,dt\<Turnstile>e#es\<Colon>\<doteq>T#Ts" |
427 E,dt\<Turnstile>e#es\<Colon>\<doteq>T#Ts" |
428 |
428 |
429 |
429 |
606 by (auto, frule wt_Inj_elim, auto) |
606 by (auto, frule wt_Inj_elim, auto) |
607 |
607 |
608 lemma wt_stmt_eq: "E,dt\<Turnstile>In1r t\<Colon>U = (U=Inl(PrimT Void)\<and>E,dt\<Turnstile>t\<Colon>\<surd>)" |
608 lemma wt_stmt_eq: "E,dt\<Turnstile>In1r t\<Colon>U = (U=Inl(PrimT Void)\<and>E,dt\<Turnstile>t\<Colon>\<surd>)" |
609 by (auto, frule wt_Inj_elim, auto, frule wt_Inj_elim, auto) |
609 by (auto, frule wt_Inj_elim, auto, frule wt_Inj_elim, auto) |
610 |
610 |
611 simproc_setup wt_expr ("E,dt\<Turnstile>In1l t\<Colon>U") = {* |
611 simproc_setup wt_expr ("E,dt\<Turnstile>In1l t\<Colon>U") = \<open> |
612 fn _ => fn _ => fn ct => |
612 fn _ => fn _ => fn ct => |
613 (case Thm.term_of ct of |
613 (case Thm.term_of ct of |
614 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
614 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
615 | _ => SOME (mk_meta_eq @{thm wt_expr_eq})) *} |
615 | _ => SOME (mk_meta_eq @{thm wt_expr_eq}))\<close> |
616 |
616 |
617 simproc_setup wt_var ("E,dt\<Turnstile>In2 t\<Colon>U") = {* |
617 simproc_setup wt_var ("E,dt\<Turnstile>In2 t\<Colon>U") = \<open> |
618 fn _ => fn _ => fn ct => |
618 fn _ => fn _ => fn ct => |
619 (case Thm.term_of ct of |
619 (case Thm.term_of ct of |
620 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
620 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
621 | _ => SOME (mk_meta_eq @{thm wt_var_eq})) *} |
621 | _ => SOME (mk_meta_eq @{thm wt_var_eq}))\<close> |
622 |
622 |
623 simproc_setup wt_exprs ("E,dt\<Turnstile>In3 t\<Colon>U") = {* |
623 simproc_setup wt_exprs ("E,dt\<Turnstile>In3 t\<Colon>U") = \<open> |
624 fn _ => fn _ => fn ct => |
624 fn _ => fn _ => fn ct => |
625 (case Thm.term_of ct of |
625 (case Thm.term_of ct of |
626 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
626 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
627 | _ => SOME (mk_meta_eq @{thm wt_exprs_eq})) *} |
627 | _ => SOME (mk_meta_eq @{thm wt_exprs_eq}))\<close> |
628 |
628 |
629 simproc_setup wt_stmt ("E,dt\<Turnstile>In1r t\<Colon>U") = {* |
629 simproc_setup wt_stmt ("E,dt\<Turnstile>In1r t\<Colon>U") = \<open> |
630 fn _ => fn _ => fn ct => |
630 fn _ => fn _ => fn ct => |
631 (case Thm.term_of ct of |
631 (case Thm.term_of ct of |
632 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
632 (_ $ _ $ _ $ _ $ (Const _ $ _)) => NONE |
633 | _ => SOME (mk_meta_eq @{thm wt_stmt_eq})) *} |
633 | _ => SOME (mk_meta_eq @{thm wt_stmt_eq}))\<close> |
634 |
634 |
635 lemma wt_elim_BinOp: |
635 lemma wt_elim_BinOp: |
636 "\<lbrakk>E,dt\<Turnstile>In1l (BinOp binop e1 e2)\<Colon>T; |
636 "\<lbrakk>E,dt\<Turnstile>In1l (BinOp binop e1 e2)\<Colon>T; |
637 \<And>T1 T2 T3. |
637 \<And>T1 T2 T3. |
638 \<lbrakk>E,dt\<Turnstile>e1\<Colon>-T1; E,dt\<Turnstile>e2\<Colon>-T2; wt_binop (prg E) binop T1 T2; |
638 \<lbrakk>E,dt\<Turnstile>e1\<Colon>-T1; E,dt\<Turnstile>e2\<Colon>-T2; wt_binop (prg E) binop T1 T2; |
656 apply (cases "E", erule wt.induct) |
656 apply (cases "E", erule wt.induct) |
657 apply (safe del: disjE) |
657 apply (safe del: disjE) |
658 apply (simp_all (no_asm_use) split del: split_if_asm) |
658 apply (simp_all (no_asm_use) split del: split_if_asm) |
659 apply (safe del: disjE) |
659 apply (safe del: disjE) |
660 (* 17 subgoals *) |
660 (* 17 subgoals *) |
661 apply (tactic {* ALLGOALS (fn i => |
661 apply (tactic \<open>ALLGOALS (fn i => |
662 if i = 11 then EVERY' |
662 if i = 11 then EVERY' |
663 [Rule_Insts.thin_tac @{context} "E,dt\<Turnstile>e0\<Colon>-PrimT Boolean" [(@{binding E}, NONE, NoSyn)], |
663 [Rule_Insts.thin_tac @{context} "E,dt\<Turnstile>e0\<Colon>-PrimT Boolean" [(@{binding E}, NONE, NoSyn)], |
664 Rule_Insts.thin_tac @{context} "E,dt\<Turnstile>e1\<Colon>-T1" [(@{binding E}, NONE, NoSyn), (@{binding T1}, NONE, NoSyn)], |
664 Rule_Insts.thin_tac @{context} "E,dt\<Turnstile>e1\<Colon>-T1" [(@{binding E}, NONE, NoSyn), (@{binding T1}, NONE, NoSyn)], |
665 Rule_Insts.thin_tac @{context} "E,dt\<Turnstile>e2\<Colon>-T2" [(@{binding E}, NONE, NoSyn), (@{binding T2}, NONE, NoSyn)]] i |
665 Rule_Insts.thin_tac @{context} "E,dt\<Turnstile>e2\<Colon>-T2" [(@{binding E}, NONE, NoSyn), (@{binding T2}, NONE, NoSyn)]] i |
666 else Rule_Insts.thin_tac @{context} "All P" [(@{binding P}, NONE, NoSyn)] i) *}) |
666 else Rule_Insts.thin_tac @{context} "All P" [(@{binding P}, NONE, NoSyn)] i)\<close>) |
667 (*apply (safe del: disjE elim!: wt_elim_cases)*) |
667 (*apply (safe del: disjE elim!: wt_elim_cases)*) |
668 apply (tactic {*ALLGOALS (eresolve_tac @{context} @{thms wt_elim_cases})*}) |
668 apply (tactic \<open>ALLGOALS (eresolve_tac @{context} @{thms wt_elim_cases})\<close>) |
669 apply (simp_all (no_asm_use) split del: split_if_asm) |
669 apply (simp_all (no_asm_use) split del: split_if_asm) |
670 apply (erule_tac [12] V = "All P" for P in thin_rl) (* Call *) |
670 apply (erule_tac [12] V = "All P" for P in thin_rl) (* Call *) |
671 apply (blast del: equalityCE dest: sym [THEN trans])+ |
671 apply (blast del: equalityCE dest: sym [THEN trans])+ |
672 done |
672 done |
673 |
673 |