19 text {* |
19 text {* |
20 Primitive types are always accessible, interfaces and classes are accessible |
20 Primitive types are always accessible, interfaces and classes are accessible |
21 in their package or if they are defined public, an array type is accessible if |
21 in their package or if they are defined public, an array type is accessible if |
22 its element type is accessible *} |
22 its element type is accessible *} |
23 |
23 |
24 consts accessible_in :: "prog \<Rightarrow> ty \<Rightarrow> pname \<Rightarrow> bool" |
|
25 ("_ \<turnstile> _ accessible'_in _" [61,61,61] 60) |
|
26 rt_accessible_in:: "prog \<Rightarrow> ref_ty \<Rightarrow> pname \<Rightarrow> bool" |
|
27 ("_ \<turnstile> _ accessible'_in' _" [61,61,61] 60) |
|
28 primrec |
24 primrec |
29 "G\<turnstile>(PrimT p) accessible_in pack = True" |
25 accessible_in :: "prog \<Rightarrow> ty \<Rightarrow> pname \<Rightarrow> bool" ("_ \<turnstile> _ accessible'_in _" [61,61,61] 60) and |
30 accessible_in_RefT_simp: |
26 rt_accessible_in :: "prog \<Rightarrow> ref_ty \<Rightarrow> pname \<Rightarrow> bool" ("_ \<turnstile> _ accessible'_in' _" [61,61,61] 60) |
31 "G\<turnstile>(RefT r) accessible_in pack = G\<turnstile>r accessible_in' pack" |
27 where |
32 |
28 "G\<turnstile>(PrimT p) accessible_in pack = True" |
33 "G\<turnstile>(NullT) accessible_in' pack = True" |
29 | accessible_in_RefT_simp: |
34 "G\<turnstile>(IfaceT I) accessible_in' pack = ((pid I = pack) \<or> is_public G I)" |
30 "G\<turnstile>(RefT r) accessible_in pack = G\<turnstile>r accessible_in' pack" |
35 "G\<turnstile>(ClassT C) accessible_in' pack = ((pid C = pack) \<or> is_public G C)" |
31 | "G\<turnstile>(NullT) accessible_in' pack = True" |
36 "G\<turnstile>(ArrayT ty) accessible_in' pack = G\<turnstile>ty accessible_in pack" |
32 | "G\<turnstile>(IfaceT I) accessible_in' pack = ((pid I = pack) \<or> is_public G I)" |
|
33 | "G\<turnstile>(ClassT C) accessible_in' pack = ((pid C = pack) \<or> is_public G C)" |
|
34 | "G\<turnstile>(ArrayT ty) accessible_in' pack = G\<turnstile>ty accessible_in pack" |
37 |
35 |
38 declare accessible_in_RefT_simp [simp del] |
36 declare accessible_in_RefT_simp [simp del] |
39 |
37 |
40 definition is_acc_class :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> bool" where |
38 definition |
41 "is_acc_class G P C \<equiv> is_class G C \<and> G\<turnstile>(Class C) accessible_in P" |
39 is_acc_class :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> bool" |
42 |
40 where "is_acc_class G P C = (is_class G C \<and> G\<turnstile>(Class C) accessible_in P)" |
43 definition is_acc_iface :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> bool" where |
41 |
44 "is_acc_iface G P I \<equiv> is_iface G I \<and> G\<turnstile>(Iface I) accessible_in P" |
42 definition |
45 |
43 is_acc_iface :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> bool" |
46 definition is_acc_type :: "prog \<Rightarrow> pname \<Rightarrow> ty \<Rightarrow> bool" where |
44 where "is_acc_iface G P I = (is_iface G I \<and> G\<turnstile>(Iface I) accessible_in P)" |
47 "is_acc_type G P T \<equiv> is_type G T \<and> G\<turnstile>T accessible_in P" |
45 |
48 |
46 definition |
49 definition is_acc_reftype :: "prog \<Rightarrow> pname \<Rightarrow> ref_ty \<Rightarrow> bool" where |
47 is_acc_type :: "prog \<Rightarrow> pname \<Rightarrow> ty \<Rightarrow> bool" |
50 "is_acc_reftype G P T \<equiv> isrtype G T \<and> G\<turnstile>T accessible_in' P" |
48 where "is_acc_type G P T = (is_type G T \<and> G\<turnstile>T accessible_in P)" |
|
49 |
|
50 definition |
|
51 is_acc_reftype :: "prog \<Rightarrow> pname \<Rightarrow> ref_ty \<Rightarrow> bool" |
|
52 where "is_acc_reftype G P T = (isrtype G T \<and> G\<turnstile>T accessible_in' P)" |
51 |
53 |
52 lemma is_acc_classD: |
54 lemma is_acc_classD: |
53 "is_acc_class G P C \<Longrightarrow> is_class G C \<and> G\<turnstile>(Class C) accessible_in P" |
55 "is_acc_class G P C \<Longrightarrow> is_class G C \<and> G\<turnstile>(Class C) accessible_in P" |
54 by (simp add: is_acc_class_def) |
56 by (simp add: is_acc_class_def) |
55 |
57 |
244 lemma mhead_static_simp [simp]: "is_static (mhead m) = is_static m" |
246 lemma mhead_static_simp [simp]: "is_static (mhead m) = is_static m" |
245 by (cases m) (simp add: mhead_def member_is_static_simp) |
247 by (cases m) (simp add: mhead_def member_is_static_simp) |
246 |
248 |
247 -- {* some mnemotic selectors for various pairs *} |
249 -- {* some mnemotic selectors for various pairs *} |
248 |
250 |
249 definition decliface :: "qtname \<times> 'a decl_scheme \<Rightarrow> qtname" where |
251 definition |
|
252 decliface :: "qtname \<times> 'a decl_scheme \<Rightarrow> qtname" where |
250 "decliface = fst" --{* get the interface component *} |
253 "decliface = fst" --{* get the interface component *} |
251 |
254 |
252 definition mbr :: "qtname \<times> memberdecl \<Rightarrow> memberdecl" where |
255 definition |
|
256 mbr :: "qtname \<times> memberdecl \<Rightarrow> memberdecl" where |
253 "mbr = snd" --{* get the memberdecl component *} |
257 "mbr = snd" --{* get the memberdecl component *} |
254 |
258 |
255 definition mthd :: "'b \<times> 'a \<Rightarrow> 'a" where |
259 definition |
|
260 mthd :: "'b \<times> 'a \<Rightarrow> 'a" where |
256 "mthd = snd" --{* get the method component *} |
261 "mthd = snd" --{* get the method component *} |
257 --{* also used for mdecl, mhead *} |
262 --{* also used for mdecl, mhead *} |
258 |
263 |
259 definition fld :: "'b \<times> 'a decl_scheme \<Rightarrow> 'a decl_scheme" where |
264 definition |
|
265 fld :: "'b \<times> 'a decl_scheme \<Rightarrow> 'a decl_scheme" where |
260 "fld = snd" --{* get the field component *} |
266 "fld = snd" --{* get the field component *} |
261 --{* also used for @{text "((vname \<times> qtname)\<times> field)"} *} |
267 --{* also used for @{text "((vname \<times> qtname)\<times> field)"} *} |
262 |
268 |
263 -- {* some mnemotic selectors for @{text "(vname \<times> qtname)"} *} |
269 -- {* some mnemotic selectors for @{text "(vname \<times> qtname)"} *} |
264 |
270 |
265 definition fname:: "vname \<times> 'a \<Rightarrow> vname" where |
271 definition |
266 "fname = fst" |
272 fname:: "vname \<times> 'a \<Rightarrow> vname" |
|
273 where "fname = fst" |
267 --{* also used for fdecl *} |
274 --{* also used for fdecl *} |
268 |
275 |
269 definition declclassf:: "(vname \<times> qtname) \<Rightarrow> qtname" where |
276 definition |
270 "declclassf = snd" |
277 declclassf:: "(vname \<times> qtname) \<Rightarrow> qtname" |
|
278 where "declclassf = snd" |
271 |
279 |
272 |
280 |
273 lemma decliface_simp[simp]: "decliface (I,m) = I" |
281 lemma decliface_simp[simp]: "decliface (I,m) = I" |
274 by (simp add: decliface_def) |
282 by (simp add: decliface_def) |
275 |
283 |
318 lemma declclassf_simp[simp]:"declclassf (n,c) = c" |
326 lemma declclassf_simp[simp]:"declclassf (n,c) = c" |
319 by (simp add: declclassf_def) |
327 by (simp add: declclassf_def) |
320 |
328 |
321 --{* some mnemotic selectors for @{text "(vname \<times> qtname)"} *} |
329 --{* some mnemotic selectors for @{text "(vname \<times> qtname)"} *} |
322 |
330 |
323 definition fldname :: "vname \<times> qtname \<Rightarrow> vname" where |
331 definition |
324 "fldname = fst" |
332 fldname :: "vname \<times> qtname \<Rightarrow> vname" |
325 |
333 where "fldname = fst" |
326 definition fldclass :: "vname \<times> qtname \<Rightarrow> qtname" where |
334 |
327 "fldclass = snd" |
335 definition |
|
336 fldclass :: "vname \<times> qtname \<Rightarrow> qtname" |
|
337 where "fldclass = snd" |
328 |
338 |
329 lemma fldname_simp[simp]: "fldname (n,c) = n" |
339 lemma fldname_simp[simp]: "fldname (n,c) = n" |
330 by (simp add: fldname_def) |
340 by (simp add: fldname_def) |
331 |
341 |
332 lemma fldclass_simp[simp]: "fldclass (n,c) = c" |
342 lemma fldclass_simp[simp]: "fldclass (n,c) = c" |
336 by (simp add: fldname_def fldclass_def) |
346 by (simp add: fldname_def fldclass_def) |
337 |
347 |
338 text {* Convert a qualified method declaration (qualified with its declaring |
348 text {* Convert a qualified method declaration (qualified with its declaring |
339 class) to a qualified member declaration: @{text methdMembr} *} |
349 class) to a qualified member declaration: @{text methdMembr} *} |
340 |
350 |
341 definition methdMembr :: "qtname \<times> mdecl \<Rightarrow> qtname \<times> memberdecl" where |
351 definition |
342 "methdMembr m = (fst m, mdecl (snd m))" |
352 methdMembr :: "qtname \<times> mdecl \<Rightarrow> qtname \<times> memberdecl" |
|
353 where "methdMembr m = (fst m, mdecl (snd m))" |
343 |
354 |
344 lemma methdMembr_simp[simp]: "methdMembr (c,m) = (c,mdecl m)" |
355 lemma methdMembr_simp[simp]: "methdMembr (c,m) = (c,mdecl m)" |
345 by (simp add: methdMembr_def) |
356 by (simp add: methdMembr_def) |
346 |
357 |
347 lemma accmodi_methdMembr_simp[simp]: "accmodi (methdMembr m) = accmodi m" |
358 lemma accmodi_methdMembr_simp[simp]: "accmodi (methdMembr m) = accmodi m" |
354 by (cases m) (simp add: methdMembr_def) |
365 by (cases m) (simp add: methdMembr_def) |
355 |
366 |
356 text {* Convert a qualified method (qualified with its declaring |
367 text {* Convert a qualified method (qualified with its declaring |
357 class) to a qualified member declaration: @{text method} *} |
368 class) to a qualified member declaration: @{text method} *} |
358 |
369 |
359 definition method :: "sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> memberdecl)" where |
370 definition |
360 "method sig m \<equiv> (declclass m, mdecl (sig, mthd m))" |
371 method :: "sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> memberdecl)" |
|
372 where "method sig m = (declclass m, mdecl (sig, mthd m))" |
361 |
373 |
362 lemma method_simp[simp]: "method sig (C,m) = (C,mdecl (sig,m))" |
374 lemma method_simp[simp]: "method sig (C,m) = (C,mdecl (sig,m))" |
363 by (simp add: method_def) |
375 by (simp add: method_def) |
364 |
376 |
365 lemma accmodi_method_simp[simp]: "accmodi (method sig m) = accmodi m" |
377 lemma accmodi_method_simp[simp]: "accmodi (method sig m) = accmodi m" |
375 by (simp add: mbr_def method_def) |
387 by (simp add: mbr_def method_def) |
376 |
388 |
377 lemma memberid_method_simp[simp]: "memberid (method sig m) = mid sig" |
389 lemma memberid_method_simp[simp]: "memberid (method sig m) = mid sig" |
378 by (simp add: method_def) |
390 by (simp add: method_def) |
379 |
391 |
380 definition fieldm :: "vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> (qtname \<times> memberdecl)" where |
392 definition |
381 "fieldm n f \<equiv> (declclass f, fdecl (n, fld f))" |
393 fieldm :: "vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> (qtname \<times> memberdecl)" |
|
394 where "fieldm n f = (declclass f, fdecl (n, fld f))" |
382 |
395 |
383 lemma fieldm_simp[simp]: "fieldm n (C,f) = (C,fdecl (n,f))" |
396 lemma fieldm_simp[simp]: "fieldm n (C,f) = (C,fdecl (n,f))" |
384 by (simp add: fieldm_def) |
397 by (simp add: fieldm_def) |
385 |
398 |
386 lemma accmodi_fieldm_simp[simp]: "accmodi (fieldm n f) = accmodi f" |
399 lemma accmodi_fieldm_simp[simp]: "accmodi (fieldm n f) = accmodi f" |
399 by (simp add: fieldm_def) |
412 by (simp add: fieldm_def) |
400 |
413 |
401 text {* Select the signature out of a qualified method declaration: |
414 text {* Select the signature out of a qualified method declaration: |
402 @{text msig} *} |
415 @{text msig} *} |
403 |
416 |
404 definition msig :: "(qtname \<times> mdecl) \<Rightarrow> sig" where |
417 definition |
405 "msig m \<equiv> fst (snd m)" |
418 msig :: "(qtname \<times> mdecl) \<Rightarrow> sig" |
|
419 where "msig m = fst (snd m)" |
406 |
420 |
407 lemma msig_simp[simp]: "msig (c,(s,m)) = s" |
421 lemma msig_simp[simp]: "msig (c,(s,m)) = s" |
408 by (simp add: msig_def) |
422 by (simp add: msig_def) |
409 |
423 |
410 text {* Convert a qualified method (qualified with its declaring |
424 text {* Convert a qualified method (qualified with its declaring |
411 class) to a qualified method declaration: @{text qmdecl} *} |
425 class) to a qualified method declaration: @{text qmdecl} *} |
412 |
426 |
413 definition qmdecl :: "sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> mdecl)" where |
427 definition |
414 "qmdecl sig m \<equiv> (declclass m, (sig,mthd m))" |
428 qmdecl :: "sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> mdecl)" |
|
429 where "qmdecl sig m = (declclass m, (sig,mthd m))" |
415 |
430 |
416 lemma qmdecl_simp[simp]: "qmdecl sig (C,m) = (C,(sig,m))" |
431 lemma qmdecl_simp[simp]: "qmdecl sig (C,m) = (C,(sig,m))" |
417 by (simp add: qmdecl_def) |
432 by (simp add: qmdecl_def) |
418 |
433 |
419 lemma declclass_qmdecl_simp[simp]: "declclass (qmdecl sig m) = declclass m" |
434 lemma declclass_qmdecl_simp[simp]: "declclass (qmdecl sig m) = declclass m" |
501 declared with default (package) access, the package of the declaration |
516 declared with default (package) access, the package of the declaration |
502 class of m is also P. If the member m is declared with private access |
517 class of m is also P. If the member m is declared with private access |
503 it is not accessible for inheritance at all. |
518 it is not accessible for inheritance at all. |
504 \end{itemize} |
519 \end{itemize} |
505 *} |
520 *} |
506 definition inheritable_in :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> pname \<Rightarrow> bool" ("_ \<turnstile> _ inheritable'_in _" [61,61,61] 60) where |
521 definition |
507 |
522 inheritable_in :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> pname \<Rightarrow> bool" ("_ \<turnstile> _ inheritable'_in _" [61,61,61] 60) |
508 "G\<turnstile>membr inheritable_in pack |
523 where |
509 \<equiv> (case (accmodi membr) of |
524 "G\<turnstile>membr inheritable_in pack = |
510 Private \<Rightarrow> False |
525 (case (accmodi membr) of |
511 | Package \<Rightarrow> (pid (declclass membr)) = pack |
526 Private \<Rightarrow> False |
512 | Protected \<Rightarrow> True |
527 | Package \<Rightarrow> (pid (declclass membr)) = pack |
513 | Public \<Rightarrow> True)" |
528 | Protected \<Rightarrow> True |
|
529 | Public \<Rightarrow> True)" |
514 |
530 |
515 abbreviation |
531 abbreviation |
516 Method_inheritable_in_syntax:: |
532 Method_inheritable_in_syntax:: |
517 "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> pname \<Rightarrow> bool" |
533 "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> pname \<Rightarrow> bool" |
518 ("_ \<turnstile>Method _ inheritable'_in _ " [61,61,61] 60) |
534 ("_ \<turnstile>Method _ inheritable'_in _ " [61,61,61] 60) |
524 ("_ \<turnstile>Methd _ _ inheritable'_in _ " [61,61,61,61] 60) |
540 ("_ \<turnstile>Methd _ _ inheritable'_in _ " [61,61,61,61] 60) |
525 where "G\<turnstile>Methd s m inheritable_in p == G\<turnstile>(method s m) inheritable_in p" |
541 where "G\<turnstile>Methd s m inheritable_in p == G\<turnstile>(method s m) inheritable_in p" |
526 |
542 |
527 subsubsection "declared-in/undeclared-in" |
543 subsubsection "declared-in/undeclared-in" |
528 |
544 |
529 definition cdeclaredmethd :: "prog \<Rightarrow> qtname \<Rightarrow> (sig,methd) table" where |
545 definition |
530 "cdeclaredmethd G C |
546 cdeclaredmethd :: "prog \<Rightarrow> qtname \<Rightarrow> (sig,methd) table" where |
531 \<equiv> (case class G C of |
547 "cdeclaredmethd G C = |
|
548 (case class G C of |
532 None \<Rightarrow> \<lambda> sig. None |
549 None \<Rightarrow> \<lambda> sig. None |
533 | Some c \<Rightarrow> table_of (methods c) |
550 | Some c \<Rightarrow> table_of (methods c))" |
534 )" |
551 |
535 |
552 definition |
536 definition cdeclaredfield :: "prog \<Rightarrow> qtname \<Rightarrow> (vname,field) table" where |
553 cdeclaredfield :: "prog \<Rightarrow> qtname \<Rightarrow> (vname,field) table" where |
537 "cdeclaredfield G C |
554 "cdeclaredfield G C = |
538 \<equiv> (case class G C of |
555 (case class G C of |
539 None \<Rightarrow> \<lambda> sig. None |
556 None \<Rightarrow> \<lambda> sig. None |
540 | Some c \<Rightarrow> table_of (cfields c) |
557 | Some c \<Rightarrow> table_of (cfields c))" |
541 )" |
558 |
542 |
559 definition |
543 definition declared_in :: "prog \<Rightarrow> memberdecl \<Rightarrow> qtname \<Rightarrow> bool" ("_\<turnstile> _ declared'_in _" [61,61,61] 60) where |
560 declared_in :: "prog \<Rightarrow> memberdecl \<Rightarrow> qtname \<Rightarrow> bool" ("_\<turnstile> _ declared'_in _" [61,61,61] 60) |
544 "G\<turnstile>m declared_in C \<equiv> (case m of |
561 where |
545 fdecl (fn,f ) \<Rightarrow> cdeclaredfield G C fn = Some f |
562 "G\<turnstile>m declared_in C = (case m of |
546 | mdecl (sig,m) \<Rightarrow> cdeclaredmethd G C sig = Some m)" |
563 fdecl (fn,f ) \<Rightarrow> cdeclaredfield G C fn = Some f |
|
564 | mdecl (sig,m) \<Rightarrow> cdeclaredmethd G C sig = Some m)" |
547 |
565 |
548 abbreviation |
566 abbreviation |
549 method_declared_in:: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> bool" |
567 method_declared_in:: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> qtname \<Rightarrow> bool" |
550 ("_\<turnstile>Method _ declared'_in _" [61,61,61] 60) |
568 ("_\<turnstile>Method _ declared'_in _" [61,61,61] 60) |
551 where "G\<turnstile>Method m declared_in C == G\<turnstile>mdecl (mthd m) declared_in C" |
569 where "G\<turnstile>Method m declared_in C == G\<turnstile>mdecl (mthd m) declared_in C" |
558 lemma declared_in_classD: |
576 lemma declared_in_classD: |
559 "G\<turnstile>m declared_in C \<Longrightarrow> is_class G C" |
577 "G\<turnstile>m declared_in C \<Longrightarrow> is_class G C" |
560 by (cases m) |
578 by (cases m) |
561 (auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def) |
579 (auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def) |
562 |
580 |
563 definition undeclared_in :: "prog \<Rightarrow> memberid \<Rightarrow> qtname \<Rightarrow> bool" ("_\<turnstile> _ undeclared'_in _" [61,61,61] 60) where |
581 definition |
564 "G\<turnstile>m undeclared_in C \<equiv> (case m of |
582 undeclared_in :: "prog \<Rightarrow> memberid \<Rightarrow> qtname \<Rightarrow> bool" ("_\<turnstile> _ undeclared'_in _" [61,61,61] 60) |
565 fid fn \<Rightarrow> cdeclaredfield G C fn = None |
583 where |
566 | mid sig \<Rightarrow> cdeclaredmethd G C sig = None)" |
584 "G\<turnstile>m undeclared_in C = (case m of |
|
585 fid fn \<Rightarrow> cdeclaredfield G C fn = None |
|
586 | mid sig \<Rightarrow> cdeclaredmethd G C sig = None)" |
567 |
587 |
568 |
588 |
569 subsubsection "members" |
589 subsubsection "members" |
570 |
590 |
571 (* Can't just take a function: prog \<Rightarrow> qtname \<Rightarrow> memberdecl set because |
591 (* Can't just take a function: prog \<Rightarrow> qtname \<Rightarrow> memberdecl set because |
605 abbreviation |
625 abbreviation |
606 fieldm_member_of:: "prog \<Rightarrow> vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> qtname \<Rightarrow> bool" |
626 fieldm_member_of:: "prog \<Rightarrow> vname \<Rightarrow> (qtname \<times> field) \<Rightarrow> qtname \<Rightarrow> bool" |
607 ("_ \<turnstile>Field _ _ member'_of _" [61,61,61] 60) |
627 ("_ \<turnstile>Field _ _ member'_of _" [61,61,61] 60) |
608 where "G\<turnstile>Field n f member_of C == G\<turnstile>fieldm n f member_of C" |
628 where "G\<turnstile>Field n f member_of C == G\<turnstile>fieldm n f member_of C" |
609 |
629 |
610 definition inherits :: "prog \<Rightarrow> qtname \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> bool" ("_ \<turnstile> _ inherits _" [61,61,61] 60) where |
630 definition |
611 "G\<turnstile>C inherits m |
631 inherits :: "prog \<Rightarrow> qtname \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> bool" ("_ \<turnstile> _ inherits _" [61,61,61] 60) |
612 \<equiv> G\<turnstile>m inheritable_in (pid C) \<and> G\<turnstile>memberid m undeclared_in C \<and> |
632 where |
613 (\<exists> S. G\<turnstile>C \<prec>\<^sub>C1 S \<and> G\<turnstile>(Class S) accessible_in (pid C) \<and> G\<turnstile>m member_of S)" |
633 "G\<turnstile>C inherits m = |
|
634 (G\<turnstile>m inheritable_in (pid C) \<and> G\<turnstile>memberid m undeclared_in C \<and> |
|
635 (\<exists>S. G\<turnstile>C \<prec>\<^sub>C1 S \<and> G\<turnstile>(Class S) accessible_in (pid C) \<and> G\<turnstile>m member_of S))" |
614 |
636 |
615 lemma inherits_member: "G\<turnstile>C inherits m \<Longrightarrow> G\<turnstile>m member_of C" |
637 lemma inherits_member: "G\<turnstile>C inherits m \<Longrightarrow> G\<turnstile>m member_of C" |
616 by (auto simp add: inherits_def intro: members.Inherited) |
638 by (auto simp add: inherits_def intro: members.Inherited) |
617 |
639 |
618 |
640 |
619 definition member_in :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> bool" ("_ \<turnstile> _ member'_in _" [61,61,61] 60) where |
641 definition |
620 "G\<turnstile>m member_in C \<equiv> \<exists> provC. G\<turnstile> C \<preceq>\<^sub>C provC \<and> G \<turnstile> m member_of provC" |
642 member_in :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> bool" ("_ \<turnstile> _ member'_in _" [61,61,61] 60) |
|
643 where "G\<turnstile>m member_in C = (\<exists> provC. G\<turnstile> C \<preceq>\<^sub>C provC \<and> G \<turnstile> m member_of provC)" |
621 text {* A member is in a class if it is member of the class or a superclass. |
644 text {* A member is in a class if it is member of the class or a superclass. |
622 If a member is in a class we can select this member. This additional notion |
645 If a member is in a class we can select this member. This additional notion |
623 is necessary since not all members are inherited to subclasses. So such |
646 is necessary since not all members are inherited to subclasses. So such |
624 members are not member-of the subclass but member-in the subclass.*} |
647 members are not member-of the subclass but member-in the subclass.*} |
625 |
648 |
701 ("_,_\<turnstile> _ overrides _" [61,61,61,61] 60) |
724 ("_,_\<turnstile> _ overrides _" [61,61,61,61] 60) |
702 where "G,s\<turnstile>new overrides old == G\<turnstile>(qmdecl s new) overrides (qmdecl s old)" |
725 where "G,s\<turnstile>new overrides old == G\<turnstile>(qmdecl s new) overrides (qmdecl s old)" |
703 |
726 |
704 subsubsection "Hiding" |
727 subsubsection "Hiding" |
705 |
728 |
706 definition hides :: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> bool" ("_\<turnstile> _ hides _" [61,61,61] 60) where |
729 definition |
707 "G\<turnstile>new hides old |
730 hides :: "prog \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> (qtname \<times> mdecl) \<Rightarrow> bool" ("_\<turnstile> _ hides _" [61,61,61] 60) |
708 \<equiv> is_static new \<and> msig new = msig old \<and> |
731 where |
709 G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and> |
732 "G\<turnstile>new hides old = |
710 G\<turnstile>Method new declared_in (declclass new) \<and> |
733 (is_static new \<and> msig new = msig old \<and> |
711 G\<turnstile>Method old declared_in (declclass old) \<and> |
734 G\<turnstile>(declclass new) \<prec>\<^sub>C (declclass old) \<and> |
712 G\<turnstile>Method old inheritable_in pid (declclass new)" |
735 G\<turnstile>Method new declared_in (declclass new) \<and> |
|
736 G\<turnstile>Method old declared_in (declclass old) \<and> |
|
737 G\<turnstile>Method old inheritable_in pid (declclass new))" |
713 |
738 |
714 abbreviation |
739 abbreviation |
715 sig_hides:: "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> methd) \<Rightarrow> bool" |
740 sig_hides:: "prog \<Rightarrow> sig \<Rightarrow> (qtname \<times> methd) \<Rightarrow> (qtname \<times> methd) \<Rightarrow> bool" |
716 ("_,_\<turnstile> _ hides _" [61,61,61,61] 60) |
741 ("_,_\<turnstile> _ hides _" [61,61,61,61] 60) |
717 where "G,s\<turnstile>new hides old == G\<turnstile>(qmdecl s new) hides (qmdecl s old)" |
742 where "G,s\<turnstile>new hides old == G\<turnstile>(qmdecl s new) hides (qmdecl s old)" |
760 lemma hides_eq_sigD: |
785 lemma hides_eq_sigD: |
761 "\<lbrakk>G\<turnstile>new hides old\<rbrakk> \<Longrightarrow> msig old=msig new" |
786 "\<lbrakk>G\<turnstile>new hides old\<rbrakk> \<Longrightarrow> msig old=msig new" |
762 by (auto simp add: hides_def) |
787 by (auto simp add: hides_def) |
763 |
788 |
764 subsubsection "permits access" |
789 subsubsection "permits access" |
765 definition permits_acc :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool" ("_ \<turnstile> _ in _ permits'_acc'_from _" [61,61,61,61] 60) where |
790 definition |
766 "G\<turnstile>membr in cls permits_acc_from accclass |
791 permits_acc :: "prog \<Rightarrow> (qtname \<times> memberdecl) \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> bool" ("_ \<turnstile> _ in _ permits'_acc'_from _" [61,61,61,61] 60) |
767 \<equiv> (case (accmodi membr) of |
792 where |
768 Private \<Rightarrow> (declclass membr = accclass) |
793 "G\<turnstile>membr in cls permits_acc_from accclass = |
769 | Package \<Rightarrow> (pid (declclass membr) = pid accclass) |
794 (case (accmodi membr) of |
770 | Protected \<Rightarrow> (pid (declclass membr) = pid accclass) |
795 Private \<Rightarrow> (declclass membr = accclass) |
|
796 | Package \<Rightarrow> (pid (declclass membr) = pid accclass) |
|
797 | Protected \<Rightarrow> (pid (declclass membr) = pid accclass) |
771 \<or> |
798 \<or> |
772 (G\<turnstile>accclass \<prec>\<^sub>C declclass membr |
799 (G\<turnstile>accclass \<prec>\<^sub>C declclass membr |
773 \<and> (G\<turnstile>cls \<preceq>\<^sub>C accclass \<or> is_static membr)) |
800 \<and> (G\<turnstile>cls \<preceq>\<^sub>C accclass \<or> is_static membr)) |
774 | Public \<Rightarrow> True)" |
801 | Public \<Rightarrow> True)" |
775 text {* |
802 text {* |
776 The subcondition of the @{term "Protected"} case: |
803 The subcondition of the @{term "Protected"} case: |
777 @{term "G\<turnstile>accclass \<prec>\<^sub>C declclass membr"} could also be relaxed to: |
804 @{term "G\<turnstile>accclass \<prec>\<^sub>C declclass membr"} could also be relaxed to: |
778 @{term "G\<turnstile>accclass \<preceq>\<^sub>C declclass membr"} since in case both classes are the |
805 @{term "G\<turnstile>accclass \<preceq>\<^sub>C declclass membr"} since in case both classes are the |
779 same the other condition @{term "(pid (declclass membr) = pid accclass)"} |
806 same the other condition @{term "(pid (declclass membr) = pid accclass)"} |
1378 fspec = "vname \<times> qtname" |
1405 fspec = "vname \<times> qtname" |
1379 |
1406 |
1380 translations |
1407 translations |
1381 (type) "fspec" <= (type) "vname \<times> qtname" |
1408 (type) "fspec" <= (type) "vname \<times> qtname" |
1382 |
1409 |
1383 definition imethds :: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables" where |
1410 definition |
1384 "imethds G I |
1411 imethds :: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables" where |
1385 \<equiv> iface_rec G I |
1412 "imethds G I = |
1386 (\<lambda>I i ts. (Un_tables ts) \<oplus>\<oplus> |
1413 iface_rec G I (\<lambda>I i ts. (Un_tables ts) \<oplus>\<oplus> |
1387 (Option.set \<circ> table_of (map (\<lambda>(s,m). (s,I,m)) (imethods i))))" |
1414 (Option.set \<circ> table_of (map (\<lambda>(s,m). (s,I,m)) (imethods i))))" |
1388 text {* methods of an interface, with overriding and inheritance, cf. 9.2 *} |
1415 text {* methods of an interface, with overriding and inheritance, cf. 9.2 *} |
1389 |
1416 |
1390 definition accimethds :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables" where |
1417 definition |
1391 "accimethds G pack I |
1418 accimethds :: "prog \<Rightarrow> pname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> mhead) tables" where |
1392 \<equiv> if G\<turnstile>Iface I accessible_in pack |
1419 "accimethds G pack I = |
1393 then imethds G I |
1420 (if G\<turnstile>Iface I accessible_in pack |
1394 else (\<lambda> k. {})" |
1421 then imethds G I |
|
1422 else (\<lambda> k. {}))" |
1395 text {* only returns imethds if the interface is accessible *} |
1423 text {* only returns imethds if the interface is accessible *} |
1396 |
1424 |
1397 definition methd :: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1425 definition |
1398 |
1426 methd :: "prog \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1399 "methd G C |
1427 "methd G C = |
1400 \<equiv> class_rec G C empty |
1428 class_rec G C empty |
1401 (\<lambda>C c subcls_mthds. |
1429 (\<lambda>C c subcls_mthds. |
1402 filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m) |
1430 filter_tab (\<lambda>sig m. G\<turnstile>C inherits method sig m) |
1403 subcls_mthds |
1431 subcls_mthds |
1404 ++ |
1432 ++ |
1405 table_of (map (\<lambda>(s,m). (s,C,m)) (methods c)))" |
1433 table_of (map (\<lambda>(s,m). (s,C,m)) (methods c)))" |
1407 with inheritance and hiding cf. 8.4.6; |
1435 with inheritance and hiding cf. 8.4.6; |
1408 Overriding is captured by @{text dynmethd}. |
1436 Overriding is captured by @{text dynmethd}. |
1409 Every new method with the same signature coalesces the |
1437 Every new method with the same signature coalesces the |
1410 method of a superclass. *} |
1438 method of a superclass. *} |
1411 |
1439 |
1412 definition accmethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1440 definition |
1413 "accmethd G S C |
1441 accmethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1414 \<equiv> filter_tab (\<lambda>sig m. G\<turnstile>method sig m of C accessible_from S) |
1442 "accmethd G S C = |
1415 (methd G C)" |
1443 filter_tab (\<lambda>sig m. G\<turnstile>method sig m of C accessible_from S) (methd G C)" |
1416 text {* @{term "accmethd G S C"}: only those methods of @{term "methd G C"}, |
1444 text {* @{term "accmethd G S C"}: only those methods of @{term "methd G C"}, |
1417 accessible from S *} |
1445 accessible from S *} |
1418 |
1446 |
1419 text {* Note the class component in the accessibility filter. The class where |
1447 text {* Note the class component in the accessibility filter. The class where |
1420 method @{term m} is declared (@{term declC}) isn't necessarily accessible |
1448 method @{term m} is declared (@{term declC}) isn't necessarily accessible |
1421 from the current scope @{term S}. The method can be made accessible |
1449 from the current scope @{term S}. The method can be made accessible |
1422 through inheritance, too. |
1450 through inheritance, too. |
1423 So we must test accessibility of method @{term m} of class @{term C} |
1451 So we must test accessibility of method @{term m} of class @{term C} |
1424 (not @{term "declclass m"}) *} |
1452 (not @{term "declclass m"}) *} |
1425 |
1453 |
1426 definition dynmethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1454 definition |
1427 "dynmethd G statC dynC |
1455 dynmethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1428 \<equiv> \<lambda> sig. |
1456 "dynmethd G statC dynC = |
1429 (if G\<turnstile>dynC \<preceq>\<^sub>C statC |
1457 (\<lambda>sig. |
1430 then (case methd G statC sig of |
1458 (if G\<turnstile>dynC \<preceq>\<^sub>C statC |
1431 None \<Rightarrow> None |
1459 then (case methd G statC sig of |
1432 | Some statM |
1460 None \<Rightarrow> None |
1433 \<Rightarrow> (class_rec G dynC empty |
1461 | Some statM |
1434 (\<lambda>C c subcls_mthds. |
1462 \<Rightarrow> (class_rec G dynC empty |
1435 subcls_mthds |
1463 (\<lambda>C c subcls_mthds. |
1436 ++ |
1464 subcls_mthds |
1437 (filter_tab |
1465 ++ |
1438 (\<lambda> _ dynM. G,sig\<turnstile>dynM overrides statM \<or> dynM=statM) |
1466 (filter_tab |
1439 (methd G C) )) |
1467 (\<lambda> _ dynM. G,sig\<turnstile>dynM overrides statM \<or> dynM=statM) |
1440 ) sig |
1468 (methd G C) )) |
1441 ) |
1469 ) sig |
1442 else None)" |
1470 ) |
|
1471 else None))" |
1443 |
1472 |
1444 text {* @{term "dynmethd G statC dynC"}: dynamic method lookup of a reference |
1473 text {* @{term "dynmethd G statC dynC"}: dynamic method lookup of a reference |
1445 with dynamic class @{term dynC} and static class @{term statC} *} |
1474 with dynamic class @{term dynC} and static class @{term statC} *} |
1446 text {* Note some kind of duality between @{term methd} and @{term dynmethd} |
1475 text {* Note some kind of duality between @{term methd} and @{term dynmethd} |
1447 in the @{term class_rec} arguments. Whereas @{term methd} filters the |
1476 in the @{term class_rec} arguments. Whereas @{term methd} filters the |
1448 subclass methods (to get only the inherited ones), @{term dynmethd} |
1477 subclass methods (to get only the inherited ones), @{term dynmethd} |
1449 filters the new methods (to get only those methods which actually |
1478 filters the new methods (to get only those methods which actually |
1450 override the methods of the static class) *} |
1479 override the methods of the static class) *} |
1451 |
1480 |
1452 definition dynimethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1481 definition |
1453 "dynimethd G I dynC |
1482 dynimethd :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1454 \<equiv> \<lambda> sig. if imethds G I sig \<noteq> {} |
1483 "dynimethd G I dynC = |
1455 then methd G dynC sig |
1484 (\<lambda>sig. if imethds G I sig \<noteq> {} |
1456 else dynmethd G Object dynC sig" |
1485 then methd G dynC sig |
|
1486 else dynmethd G Object dynC sig)" |
1457 text {* @{term "dynimethd G I dynC"}: dynamic method lookup of a reference with |
1487 text {* @{term "dynimethd G I dynC"}: dynamic method lookup of a reference with |
1458 dynamic class dynC and static interface type I *} |
1488 dynamic class dynC and static interface type I *} |
1459 text {* |
1489 text {* |
1460 When calling an interface method, we must distinguish if the method signature |
1490 When calling an interface method, we must distinguish if the method signature |
1461 was defined in the interface or if it must be an Object method in the other |
1491 was defined in the interface or if it must be an Object method in the other |
1466 effects like in case of dynmethd. The method will be inherited or |
1496 effects like in case of dynmethd. The method will be inherited or |
1467 overridden in all classes from the first class implementing the interface |
1497 overridden in all classes from the first class implementing the interface |
1468 down to the actual dynamic class. |
1498 down to the actual dynamic class. |
1469 *} |
1499 *} |
1470 |
1500 |
1471 definition dynlookup :: "prog \<Rightarrow> ref_ty \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1501 definition |
1472 "dynlookup G statT dynC |
1502 dynlookup :: "prog \<Rightarrow> ref_ty \<Rightarrow> qtname \<Rightarrow> (sig,qtname \<times> methd) table" where |
1473 \<equiv> (case statT of |
1503 "dynlookup G statT dynC = |
1474 NullT \<Rightarrow> empty |
1504 (case statT of |
1475 | IfaceT I \<Rightarrow> dynimethd G I dynC |
1505 NullT \<Rightarrow> empty |
1476 | ClassT statC \<Rightarrow> dynmethd G statC dynC |
1506 | IfaceT I \<Rightarrow> dynimethd G I dynC |
1477 | ArrayT ty \<Rightarrow> dynmethd G Object dynC)" |
1507 | ClassT statC \<Rightarrow> dynmethd G statC dynC |
|
1508 | ArrayT ty \<Rightarrow> dynmethd G Object dynC)" |
1478 text {* @{term "dynlookup G statT dynC"}: dynamic lookup of a method within the |
1509 text {* @{term "dynlookup G statT dynC"}: dynamic lookup of a method within the |
1479 static reference type statT and the dynamic class dynC. |
1510 static reference type statT and the dynamic class dynC. |
1480 In a wellformd context statT will not be NullT and in case |
1511 In a wellformd context statT will not be NullT and in case |
1481 statT is an array type, dynC=Object *} |
1512 statT is an array type, dynC=Object *} |
1482 |
1513 |
1483 definition fields :: "prog \<Rightarrow> qtname \<Rightarrow> ((vname \<times> qtname) \<times> field) list" where |
1514 definition |
1484 "fields G C |
1515 fields :: "prog \<Rightarrow> qtname \<Rightarrow> ((vname \<times> qtname) \<times> field) list" where |
1485 \<equiv> class_rec G C [] (\<lambda>C c ts. map (\<lambda>(n,t). ((n,C),t)) (cfields c) @ ts)" |
1516 "fields G C = |
|
1517 class_rec G C [] (\<lambda>C c ts. map (\<lambda>(n,t). ((n,C),t)) (cfields c) @ ts)" |
1486 text {* @{term "fields G C"} |
1518 text {* @{term "fields G C"} |
1487 list of fields of a class, including all the fields of the superclasses |
1519 list of fields of a class, including all the fields of the superclasses |
1488 (private, inherited and hidden ones) not only the accessible ones |
1520 (private, inherited and hidden ones) not only the accessible ones |
1489 (an instance of a object allocates all these fields *} |
1521 (an instance of a object allocates all these fields *} |
1490 |
1522 |
1491 definition accfield :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (vname, qtname \<times> field) table" where |
1523 definition |
1492 "accfield G S C |
1524 accfield :: "prog \<Rightarrow> qtname \<Rightarrow> qtname \<Rightarrow> (vname, qtname \<times> field) table" where |
1493 \<equiv> let field_tab = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (fields G C)) |
1525 "accfield G S C = |
1494 in filter_tab (\<lambda>n (declC,f). G\<turnstile> (declC,fdecl (n,f)) of C accessible_from S) |
1526 (let field_tab = table_of((map (\<lambda>((n,d),f).(n,(d,f)))) (fields G C)) |
1495 field_tab" |
1527 in filter_tab (\<lambda>n (declC,f). G\<turnstile> (declC,fdecl (n,f)) of C accessible_from S) |
|
1528 field_tab)" |
1496 text {* @{term "accfield G C S"}: fields of a class @{term C} which are |
1529 text {* @{term "accfield G C S"}: fields of a class @{term C} which are |
1497 accessible from scope of class |
1530 accessible from scope of class |
1498 @{term S} with inheritance and hiding, cf. 8.3 *} |
1531 @{term S} with inheritance and hiding, cf. 8.3 *} |
1499 text {* note the class component in the accessibility filter (see also |
1532 text {* note the class component in the accessibility filter (see also |
1500 @{term methd}). |
1533 @{term methd}). |
1501 The class declaring field @{term f} (@{term declC}) isn't necessarily |
1534 The class declaring field @{term f} (@{term declC}) isn't necessarily |
1502 accessible from scope @{term S}. The field can be made visible through |
1535 accessible from scope @{term S}. The field can be made visible through |
1503 inheritance, too. So we must test accessibility of field @{term f} of class |
1536 inheritance, too. So we must test accessibility of field @{term f} of class |
1504 @{term C} (not @{term "declclass f"}) *} |
1537 @{term C} (not @{term "declclass f"}) *} |
1505 |
1538 |
1506 definition is_methd :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> bool" where |
1539 definition |
1507 "is_methd G \<equiv> \<lambda>C sig. is_class G C \<and> methd G C sig \<noteq> None" |
1540 is_methd :: "prog \<Rightarrow> qtname \<Rightarrow> sig \<Rightarrow> bool" |
1508 |
1541 where "is_methd G = (\<lambda>C sig. is_class G C \<and> methd G C sig \<noteq> None)" |
1509 definition efname :: "((vname \<times> qtname) \<times> field) \<Rightarrow> (vname \<times> qtname)" where |
1542 |
1510 "efname \<equiv> fst" |
1543 definition |
|
1544 efname :: "((vname \<times> qtname) \<times> field) \<Rightarrow> (vname \<times> qtname)" |
|
1545 where "efname = fst" |
1511 |
1546 |
1512 lemma efname_simp[simp]:"efname (n,f) = n" |
1547 lemma efname_simp[simp]:"efname (n,f) = n" |
1513 by (simp add: efname_def) |
1548 by (simp add: efname_def) |
1514 |
1549 |
1515 |
1550 |