# HG changeset patch # User wenzelm # Date 1280161519 -7200 # Node ID a79abb22ca9c46a4e7e9d7a8977233255b5b0096 # Parent d9549f9da77933fb75fd542a0e2c6385d7b2f6ac# Parent 00e848690339ceb039eeb8b3f9ccb4af021f2aa8 merged diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/AxCompl.thy --- a/src/HOL/Bali/AxCompl.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/AxCompl.thy Mon Jul 26 18:25:19 2010 +0200 @@ -20,8 +20,9 @@ section "set of not yet initialzed classes" -definition nyinitcls :: "prog \ state \ qtname set" where - "nyinitcls G s \ {C. is_class G C \ \ initd C s}" +definition + nyinitcls :: "prog \ state \ qtname set" + where "nyinitcls G s = {C. is_class G C \ \ initd C s}" lemma nyinitcls_subset_class: "nyinitcls G s \ {C. is_class G C}" apply (unfold nyinitcls_def) @@ -113,8 +114,9 @@ section "init-le" -definition init_le :: "prog \ nat \ state \ bool" ("_\init\_" [51,51] 50) where - "G\init\n \ \s. card (nyinitcls G s) \ n" +definition + init_le :: "prog \ nat \ state \ bool" ("_\init\_" [51,51] 50) + where "G\init\n = (\s. card (nyinitcls G s) \ n)" lemma init_le_def2 [simp]: "(G\init\n) s = (card (nyinitcls G s)\n)" apply (unfold init_le_def) @@ -132,27 +134,22 @@ section "Most General Triples and Formulas" -definition remember_init_state :: "state assn" ("\") where - "\ \ \Y s Z. s = Z" +definition + remember_init_state :: "state assn" ("\") + where "\ \ \Y s Z. s = Z" lemma remember_init_state_def2 [simp]: "\ Y = op =" apply (unfold remember_init_state_def) apply (simp (no_asm)) done -consts - +definition MGF ::"[state assn, term, prog] \ state triple" ("{_} _\ {_\}"[3,65,3]62) - MGFn::"[nat , term, prog] \ state triple" ("{=:_} _\ {_\}"[3,65,3]62) + where "{P} t\ {G\} = {P} t\ {\Y s' s. G\s \t\\ (Y,s')}" -defs - - - MGF_def: - "{P} t\ {G\} \ {P} t\ {\Y s' s. G\s \t\\ (Y,s')}" - - MGFn_def: - "{=:n} t\ {G\} \ {\ \. G\init\n} t\ {G\}" +definition + MGFn :: "[nat, term, prog] \ state triple" ("{=:_} _\ {_\}"[3,65,3]62) + where "{=:n} t\ {G\} = {\ \. G\init\n} t\ {G\}" (* unused *) lemma MGF_valid: "wf_prog G \ G,{}\{\} t\ {G\}" @@ -574,9 +571,9 @@ unroll the loop in iterated evaluations of the expression and evaluations of the loop body. *} -definition unroll :: "prog \ label \ expr \ stmt \ (state \ state) set" where - - "unroll G l e c \ {(s,t). \ v s1 s2. +definition + unroll :: "prog \ label \ expr \ stmt \ (state \ state) set" where + "unroll G l e c = {(s,t). \ v s1 s2. G\s \e-\v\ s1 \ the_Bool v \ normal s1 \ G\s1 \c\ s2 \ t=(abupd (absorb (Cont l)) s2)}" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/AxExample.thy --- a/src/HOL/Bali/AxExample.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/AxExample.thy Mon Jul 26 18:25:19 2010 +0200 @@ -8,10 +8,11 @@ imports AxSem Example begin -definition arr_inv :: "st \ bool" where - "arr_inv \ \s. \obj a T el. globs s (Stat Base) = Some obj \ +definition + arr_inv :: "st \ bool" where + "arr_inv = (\s. \obj a T el. globs s (Stat Base) = Some obj \ values obj (Inl (arr, Base)) = Some (Addr a) \ - heap s a = Some \tag=Arr T 2,values=el\" + heap s a = Some \tag=Arr T 2,values=el\)" lemma arr_inv_new_obj: "\a. \arr_inv s; new_Addr (heap s)=Some a\ \ arr_inv (gupd(Inl a\x) s)" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/AxSem.thy --- a/src/HOL/Bali/AxSem.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/AxSem.thy Mon Jul 26 18:25:19 2010 +0200 @@ -62,8 +62,9 @@ translations (type) "'a assn" <= (type) "vals \ state \ 'a \ bool" -definition assn_imp :: "'a assn \ 'a assn \ bool" (infixr "\" 25) where - "P \ Q \ \Y s Z. P Y s Z \ Q Y s Z" +definition + assn_imp :: "'a assn \ 'a assn \ bool" (infixr "\" 25) + where "(P \ Q) = (\Y s Z. P Y s Z \ Q Y s Z)" lemma assn_imp_def2 [iff]: "(P \ Q) = (\Y s Z. P Y s Z \ Q Y s Z)" apply (unfold assn_imp_def) @@ -75,8 +76,9 @@ subsection "peek-and" -definition peek_and :: "'a assn \ (state \ bool) \ 'a assn" (infixl "\." 13) where - "P \. p \ \Y s Z. P Y s Z \ p s" +definition + peek_and :: "'a assn \ (state \ bool) \ 'a assn" (infixl "\." 13) + where "(P \. p) = (\Y s Z. P Y s Z \ p s)" lemma peek_and_def2 [simp]: "peek_and P p Y s = (\Z. (P Y s Z \ p s))" apply (unfold peek_and_def) @@ -114,8 +116,9 @@ subsection "assn-supd" -definition assn_supd :: "'a assn \ (state \ state) \ 'a assn" (infixl ";." 13) where - "P ;. f \ \Y s' Z. \s. P Y s Z \ s' = f s" +definition + assn_supd :: "'a assn \ (state \ state) \ 'a assn" (infixl ";." 13) + where "(P ;. f) = (\Y s' Z. \s. P Y s Z \ s' = f s)" lemma assn_supd_def2 [simp]: "assn_supd P f Y s' Z = (\s. P Y s Z \ s' = f s)" apply (unfold assn_supd_def) @@ -124,8 +127,9 @@ subsection "supd-assn" -definition supd_assn :: "(state \ state) \ 'a assn \ 'a assn" (infixr ".;" 13) where - "f .; P \ \Y s. P Y (f s)" +definition + supd_assn :: "(state \ state) \ 'a assn \ 'a assn" (infixr ".;" 13) + where "(f .; P) = (\Y s. P Y (f s))" lemma supd_assn_def2 [simp]: "(f .; P) Y s = P Y (f s)" @@ -143,8 +147,9 @@ subsection "subst-res" -definition subst_res :: "'a assn \ res \ 'a assn" ("_\_" [60,61] 60) where - "P\w \ \Y. P w" +definition + subst_res :: "'a assn \ res \ 'a assn" ("_\_" [60,61] 60) + where "P\w = (\Y. P w)" lemma subst_res_def2 [simp]: "(P\w) Y = P w" apply (unfold subst_res_def) @@ -178,8 +183,9 @@ subsection "subst-Bool" -definition subst_Bool :: "'a assn \ bool \ 'a assn" ("_\=_" [60,61] 60) where - "P\=b \ \Y s Z. \v. P (Val v) s Z \ (normal s \ the_Bool v=b)" +definition + subst_Bool :: "'a assn \ bool \ 'a assn" ("_\=_" [60,61] 60) + where "P\=b = (\Y s Z. \v. P (Val v) s Z \ (normal s \ the_Bool v=b))" lemma subst_Bool_def2 [simp]: "(P\=b) Y s Z = (\v. P (Val v) s Z \ (normal s \ the_Bool v=b))" @@ -193,8 +199,9 @@ subsection "peek-res" -definition peek_res :: "(res \ 'a assn) \ 'a assn" where - "peek_res Pf \ \Y. Pf Y Y" +definition + peek_res :: "(res \ 'a assn) \ 'a assn" + where "peek_res Pf = (\Y. Pf Y Y)" syntax "_peek_res" :: "pttrn \ 'a assn \ 'a assn" ("\_:. _" [0,3] 3) @@ -221,8 +228,9 @@ subsection "ign-res" -definition ign_res :: " 'a assn \ 'a assn" ("_\" [1000] 1000) where - "P\ \ \Y s Z. \Y. P Y s Z" +definition + ign_res :: "'a assn \ 'a assn" ("_\" [1000] 1000) + where "P\ = (\Y s Z. \Y. P Y s Z)" lemma ign_res_def2 [simp]: "P\ Y s Z = (\Y. P Y s Z)" apply (unfold ign_res_def) @@ -252,8 +260,9 @@ subsection "peek-st" -definition peek_st :: "(st \ 'a assn) \ 'a assn" where - "peek_st P \ \Y s. P (store s) Y s" +definition + peek_st :: "(st \ 'a assn) \ 'a assn" + where "peek_st P = (\Y s. P (store s) Y s)" syntax "_peek_st" :: "pttrn \ 'a assn \ 'a assn" ("\_.. _" [0,3] 3) @@ -296,8 +305,9 @@ subsection "ign-res-eq" -definition ign_res_eq :: "'a assn \ res \ 'a assn" ("_\=_" [60,61] 60) where - "P\=w \ \Y:. P\ \. (\s. Y=w)" +definition + ign_res_eq :: "'a assn \ res \ 'a assn" ("_\=_" [60,61] 60) + where "P\=w \ (\Y:. P\ \. (\s. Y=w))" lemma ign_res_eq_def2 [simp]: "(P\=w) Y s Z = ((\Y. P Y s Z) \ Y=w)" apply (unfold ign_res_eq_def) @@ -326,8 +336,9 @@ subsection "RefVar" -definition RefVar :: "(state \ vvar \ state) \ 'a assn \ 'a assn" (infixr "..;" 13) where - "vf ..; P \ \Y s. let (v,s') = vf s in P (Var v) s'" +definition + RefVar :: "(state \ vvar \ state) \ 'a assn \ 'a assn" (infixr "..;" 13) + where "(vf ..; P) = (\Y s. let (v,s') = vf s in P (Var v) s')" lemma RefVar_def2 [simp]: "(vf ..; P) Y s = P (Var (fst (vf s))) (snd (vf s))" @@ -337,12 +348,13 @@ subsection "allocation" -definition Alloc :: "prog \ obj_tag \ 'a assn \ 'a assn" where - "Alloc G otag P \ \Y s Z. - \s' a. G\s \halloc otag\a\ s'\ P (Val (Addr a)) s' Z" +definition + Alloc :: "prog \ obj_tag \ 'a assn \ 'a assn" + where "Alloc G otag P = (\Y s Z. \s' a. G\s \halloc otag\a\ s'\ P (Val (Addr a)) s' Z)" -definition SXAlloc :: "prog \ 'a assn \ 'a assn" where - "SXAlloc G P \ \Y s Z. \s'. G\s \sxalloc\ s' \ P Y s' Z" +definition + SXAlloc :: "prog \ 'a assn \ 'a assn" + where "SXAlloc G P = (\Y s Z. \s'. G\s \sxalloc\ s' \ P Y s' Z)" lemma Alloc_def2 [simp]: "Alloc G otag P Y s Z = @@ -359,11 +371,12 @@ section "validity" -definition type_ok :: "prog \ term \ state \ bool" where - "type_ok G t s \ - \L T C A. (normal s \ \prg=G,cls=C,lcl=L\\t\T \ - \prg=G,cls=C,lcl=L\\dom (locals (store s))\t\A ) - \ s\\(G,L)" +definition + type_ok :: "prog \ term \ state \ bool" where + "type_ok G t s = + (\L T C A. (normal s \ \prg=G,cls=C,lcl=L\\t\T \ + \prg=G,cls=C,lcl=L\\dom (locals (store s))\t\A ) + \ s\\(G,L))" datatype 'a triple = triple "('a assn)" "term" "('a assn)" (** should be something like triple = \'a. triple ('a assn) term ('a assn) **) @@ -407,34 +420,35 @@ definition mtriples :: "('c \ 'sig \ 'a assn) \ ('c \ 'sig \ expr) \ ('c \ 'sig \ 'a assn) \ ('c \ 'sig) set \ 'a triples" ("{{(1_)}/ _-\/ {(1_)} | _}"[3,65,3,65]75) where - "{{P} tf-\ {Q} | ms} \ (\(C,sig). {Normal(P C sig)} tf C sig-\ {Q C sig})`ms" + "{{P} tf-\ {Q} | ms} = (\(C,sig). {Normal(P C sig)} tf C sig-\ {Q C sig})`ms" -consts - - triple_valid :: "prog \ nat \ 'a triple \ bool" - ( "_\_:_" [61,0, 58] 57) - ax_valids :: "prog \ 'b triples \ 'a triples \ bool" - ("_,_|\_" [61,58,58] 57) +definition + triple_valid :: "prog \ nat \ 'a triple \ bool" ("_\_:_" [61,0, 58] 57) + where + "G\n:t = + (case t of {P} t\ {Q} \ + \Y s Z. P Y s Z \ type_ok G t s \ + (\Y' s'. G\s \t\\n\ (Y',s') \ Q Y' s' Z))" abbreviation - triples_valid:: "prog \ nat \ 'a triples \ bool" - ( "_||=_:_" [61,0, 58] 57) - where "G||=n:ts == Ball ts (triple_valid G n)" + triples_valid:: "prog \ nat \ 'a triples \ bool" ( "_||=_:_" [61,0, 58] 57) + where "G||=n:ts == Ball ts (triple_valid G n)" + +notation (xsymbols) + triples_valid ("_|\_:_" [61,0, 58] 57) + + +definition + ax_valids :: "prog \ 'b triples \ 'a triples \ bool" ("_,_|\_" [61,58,58] 57) + where "(G,A|\ts) = (\n. G|\n:A \ G|\n:ts)" abbreviation - ax_valid :: "prog \ 'b triples \ 'a triple \ bool" - ( "_,_|=_" [61,58,58] 57) - where "G,A |=t == G,A|\{t}" + ax_valid :: "prog \ 'b triples \ 'a triple \ bool" ( "_,_|=_" [61,58,58] 57) + where "G,A |=t == G,A|\{t}" notation (xsymbols) - triples_valid ("_|\_:_" [61,0, 58] 57) and ax_valid ("_,_\_" [61,58,58] 57) -defs triple_valid_def: "G\n:t \ case t of {P} t\ {Q} \ - \Y s Z. P Y s Z \ type_ok G t s \ - (\Y' s'. G\s \t\\n\ (Y',s') \ Q Y' s' Z)" - -defs ax_valids_def:"G,A|\ts \ \n. G|\n:A \ G|\n:ts" lemma triple_valid_def2: "G\n:{P} t\ {Q} = (\Y s Z. P Y s Z @@ -625,8 +639,9 @@ axioms *) -definition adapt_pre :: "'a assn \ 'a assn \ 'a assn \ 'a assn" where -"adapt_pre P Q Q'\\Y s Z. \Y' s'. \Z'. P Y s Z' \ (Q Y' s' Z' \ Q' Y' s' Z)" +definition + adapt_pre :: "'a assn \ 'a assn \ 'a assn \ 'a assn" + where "adapt_pre P Q Q' = (\Y s Z. \Y' s'. \Z'. P Y s Z' \ (Q Y' s' Z' \ Q' Y' s' Z))" section "rules derived by induction" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/AxSound.thy --- a/src/HOL/Bali/AxSound.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/AxSound.thy Mon Jul 26 18:25:19 2010 +0200 @@ -9,18 +9,15 @@ section "validity" -consts - - triple_valid2:: "prog \ nat \ 'a triple \ bool" - ( "_\_\_"[61,0, 58] 57) - ax_valids2:: "prog \ 'a triples \ 'a triples \ bool" - ("_,_|\\_" [61,58,58] 57) - -defs triple_valid2_def: "G\n\t \ case t of {P} t\ {Q} \ - \Y s Z. P Y s Z \ (\L. s\\(G,L) - \ (\T C A. (normal s \ (\prg=G,cls=C,lcl=L\\t\T \ - \prg=G,cls=C,lcl=L\\dom (locals (store s))\t\A)) \ - (\Y' s'. G\s \t\\n\ (Y',s') \ Q Y' s' Z \ s'\\(G,L))))" +definition + triple_valid2 :: "prog \ nat \ 'a triple \ bool" ("_\_\_"[61,0, 58] 57) + where + "G\n\t = + (case t of {P} t\ {Q} \ + \Y s Z. P Y s Z \ (\L. s\\(G,L) + \ (\T C A. (normal s \ (\prg=G,cls=C,lcl=L\\t\T \ + \prg=G,cls=C,lcl=L\\dom (locals (store s))\t\A)) \ + (\Y' s'. G\s \t\\n\ (Y',s') \ Q Y' s' Z \ s'\\(G,L)))))" text {* This definition differs from the ordinary @{text triple_valid_def} manly in the conclusion: We also ensures conformance of the result state. So @@ -29,8 +26,10 @@ proof of the axiomatic semantics, in the end we will conclude to the ordinary definition. *} - -defs ax_valids2_def: "G,A|\\ts \ \n. (\t\A. G\n\t) \ (\t\ts. G\n\t)" + +definition + ax_valids2 :: "prog \ 'a triples \ 'a triples \ bool" ("_,_|\\_" [61,58,58] 57) + where "G,A|\\ts = (\n. (\t\A. G\n\t) \ (\t\ts. G\n\t))" lemma triple_valid2_def2: "G\n\{P} t\ {Q} = (\Y s Z. P Y s Z \ (\Y' s'. G\s \t\\n\ (Y',s')\ diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Basis.thy --- a/src/HOL/Bali/Basis.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Basis.thy Mon Jul 26 18:25:19 2010 +0200 @@ -180,31 +180,34 @@ notation sum_case (infixr "'(+')"80) -consts the_Inl :: "'a + 'b \ 'a" - the_Inr :: "'a + 'b \ 'b" -primrec "the_Inl (Inl a) = a" -primrec "the_Inr (Inr b) = b" +primrec the_Inl :: "'a + 'b \ 'a" + where "the_Inl (Inl a) = a" + +primrec the_Inr :: "'a + 'b \ 'b" + where "the_Inr (Inr b) = b" datatype ('a, 'b, 'c) sum3 = In1 'a | In2 'b | In3 'c -consts the_In1 :: "('a, 'b, 'c) sum3 \ 'a" - the_In2 :: "('a, 'b, 'c) sum3 \ 'b" - the_In3 :: "('a, 'b, 'c) sum3 \ 'c" -primrec "the_In1 (In1 a) = a" -primrec "the_In2 (In2 b) = b" -primrec "the_In3 (In3 c) = c" +primrec the_In1 :: "('a, 'b, 'c) sum3 \ 'a" + where "the_In1 (In1 a) = a" + +primrec the_In2 :: "('a, 'b, 'c) sum3 \ 'b" + where "the_In2 (In2 b) = b" + +primrec the_In3 :: "('a, 'b, 'c) sum3 \ 'c" + where "the_In3 (In3 c) = c" abbreviation In1l :: "'al \ ('al + 'ar, 'b, 'c) sum3" - where "In1l e == In1 (Inl e)" + where "In1l e == In1 (Inl e)" abbreviation In1r :: "'ar \ ('al + 'ar, 'b, 'c) sum3" - where "In1r c == In1 (Inr c)" + where "In1r c == In1 (Inr c)" abbreviation the_In1l :: "('al + 'ar, 'b, 'c) sum3 \ 'al" - where "the_In1l == the_Inl \ the_In1" + where "the_In1l == the_Inl \ the_In1" abbreviation the_In1r :: "('al + 'ar, 'b, 'c) sum3 \ 'ar" - where "the_In1r == the_Inr \ the_In1" + where "the_In1r == the_Inr \ the_In1" ML {* fun sum3_instantiate ctxt thm = map (fn s => @@ -232,8 +235,9 @@ text{* Deemed too special for theory Map. *} -definition chg_map :: "('b => 'b) => 'a => ('a ~=> 'b) => ('a ~=> 'b)" where - "chg_map f a m == case m a of None => m | Some b => m(a|->f b)" +definition + chg_map :: "('b => 'b) => 'a => ('a ~=> 'b) => ('a ~=> 'b)" + where "chg_map f a m = (case m a of None => m | Some b => m(a|->f b))" lemma chg_map_new[simp]: "m a = None ==> chg_map f a m = m" by (unfold chg_map_def, auto) @@ -247,8 +251,9 @@ section "unique association lists" -definition unique :: "('a \ 'b) list \ bool" where - "unique \ distinct \ map fst" +definition + unique :: "('a \ 'b) list \ bool" + where "unique = distinct \ map fst" lemma uniqueD [rule_format (no_asm)]: "unique l--> (!x y. (x,y):set l --> (!x' y'. (x',y'):set l --> x=x'--> y=y'))" @@ -296,11 +301,11 @@ section "list patterns" -consts - lsplit :: "[['a, 'a list] => 'b, 'a list] => 'b" -defs - lsplit_def: "lsplit == %f l. f (hd l) (tl l)" -(* list patterns -- extends pre-defined type "pttrn" used in abstractions *) +definition + lsplit :: "[['a, 'a list] => 'b, 'a list] => 'b" where + "lsplit = (\f l. f (hd l) (tl l))" + +text {* list patterns -- extends pre-defined type "pttrn" used in abstractions *} syntax "_lpttrn" :: "[pttrn,pttrn] => pttrn" ("_#/_" [901,900] 900) translations diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Conform.thy --- a/src/HOL/Bali/Conform.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Conform.thy Mon Jul 26 18:25:19 2010 +0200 @@ -96,8 +96,8 @@ section "value conformance" -definition conf :: "prog \ st \ val \ ty \ bool" ("_,_\_\\_" [71,71,71,71] 70) where - "G,s\v\\T \ \T'\typeof (\a. Option.map obj_ty (heap s a)) v:G\T'\T" +definition conf :: "prog \ st \ val \ ty \ bool" ("_,_\_\\_" [71,71,71,71] 70) + where "G,s\v\\T = (\T'\typeof (\a. Option.map obj_ty (heap s a)) v:G\T'\T)" lemma conf_cong [simp]: "G,set_locals l s\v\\T = G,s\v\\T" by (auto simp: conf_def) @@ -177,8 +177,9 @@ section "value list conformance" -definition lconf :: "prog \ st \ ('a, val) table \ ('a, ty) table \ bool" ("_,_\_[\\]_" [71,71,71,71] 70) where - "G,s\vs[\\]Ts \ \n. \T\Ts n: \v\vs n: G,s\v\\T" +definition + lconf :: "prog \ st \ ('a, val) table \ ('a, ty) table \ bool" ("_,_\_[\\]_" [71,71,71,71] 70) + where "G,s\vs[\\]Ts = (\n. \T\Ts n: \v\vs n: G,s\v\\T)" lemma lconfD: "\G,s\vs[\\]Ts; Ts n = Some T\ \ G,s\(the (vs n))\\T" by (force simp: lconf_def) @@ -260,8 +261,9 @@ *} -definition wlconf :: "prog \ st \ ('a, val) table \ ('a, ty) table \ bool" ("_,_\_[\\\]_" [71,71,71,71] 70) where - "G,s\vs[\\\]Ts \ \n. \T\Ts n: \ v\vs n: G,s\v\\T" +definition + wlconf :: "prog \ st \ ('a, val) table \ ('a, ty) table \ bool" ("_,_\_[\\\]_" [71,71,71,71] 70) + where "G,s\vs[\\\]Ts = (\n. \T\Ts n: \ v\vs n: G,s\v\\T)" lemma wlconfD: "\G,s\vs[\\\]Ts; Ts n = Some T; vs n = Some v\ \ G,s\v\\T" by (auto simp: wlconf_def) @@ -338,11 +340,12 @@ section "object conformance" -definition oconf :: "prog \ st \ obj \ oref \ bool" ("_,_\_\\\_" [71,71,71,71] 70) where - "G,s\obj\\\r \ G,s\values obj[\\]var_tys G (tag obj) r \ +definition + oconf :: "prog \ st \ obj \ oref \ bool" ("_,_\_\\\_" [71,71,71,71] 70) where + "(G,s\obj\\\r) = (G,s\values obj[\\]var_tys G (tag obj) r \ (case r of Heap a \ is_type G (obj_ty obj) - | Stat C \ True)" + | Stat C \ True))" lemma oconf_is_type: "G,s\obj\\\Heap a \ is_type G (obj_ty obj)" @@ -373,12 +376,14 @@ section "state conformance" -definition conforms :: "state \ env' \ bool" ("_\\_" [71,71] 70) where - "xs\\E \ let (G, L) = E; s = snd xs; l = locals s in - (\r. \obj\globs s r: G,s\obj \\\r) \ - \ G,s\l [\\\]L\ \ - (\a. fst xs=Some(Xcpt (Loc a)) \ G,s\Addr a\\ Class (SXcpt Throwable)) \ - (fst xs=Some(Jump Ret) \ l Result \ None)" +definition + conforms :: "state \ env' \ bool" ("_\\_" [71,71] 70) where + "xs\\E = + (let (G, L) = E; s = snd xs; l = locals s in + (\r. \obj\globs s r: G,s\obj \\\r) \ + \ G,s\l [\\\]L\ \ + (\a. fst xs=Some(Xcpt (Loc a)) \ G,s\Addr a\\ Class (SXcpt Throwable)) \ + (fst xs=Some(Jump Ret) \ l Result \ None))" section "conforms" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Decl.thy --- a/src/HOL/Bali/Decl.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Decl.thy Mon Jul 26 18:25:19 2010 +0200 @@ -206,8 +206,9 @@ (type) "mdecl" <= (type) "sig \ methd" -definition mhead :: "methd \ mhead" where - "mhead m \ \access=access m, static=static m, pars=pars m, resT=resT m\" +definition + mhead :: "methd \ mhead" + where "mhead m = \access=access m, static=static m, pars=pars m, resT=resT m\" lemma access_mhead [simp]:"access (mhead m) = access m" by (simp add: mhead_def) @@ -237,7 +238,7 @@ definition memberdecl_memberid_def: - "memberid m \ (case m of + "memberid m = (case m of fdecl (vn,f) \ fid vn | mdecl (sig,m) \ mid sig)" @@ -262,7 +263,7 @@ definition pair_memberid_def: - "memberid p \ memberid (snd p)" + "memberid p = memberid (snd p)" instance .. @@ -274,8 +275,9 @@ lemma memberid_pair_simp1: "memberid p = memberid (snd p)" by (simp add: pair_memberid_def) -definition is_field :: "qtname \ memberdecl \ bool" where -"is_field m \ \ declC f. m=(declC,fdecl f)" +definition + is_field :: "qtname \ memberdecl \ bool" + where "is_field m = (\ declC f. m=(declC,fdecl f))" lemma is_fieldD: "is_field m \ \ declC f. m=(declC,fdecl f)" by (simp add: is_field_def) @@ -283,8 +285,9 @@ lemma is_fieldI: "is_field (C,fdecl f)" by (simp add: is_field_def) -definition is_method :: "qtname \ memberdecl \ bool" where -"is_method membr \ \ declC m. membr=(declC,mdecl m)" +definition + is_method :: "qtname \ memberdecl \ bool" + where "is_method membr = (\declC m. membr=(declC,mdecl m))" lemma is_methodD: "is_method membr \ \ declC m. membr=(declC,mdecl m)" by (simp add: is_method_def) @@ -314,8 +317,9 @@ isuperIfs::qtname list,\::'a\" (type) "idecl" <= (type) "qtname \ iface" -definition ibody :: "iface \ ibody" where - "ibody i \ \access=access i,imethods=imethods i\" +definition + ibody :: "iface \ ibody" + where "ibody i = \access=access i,imethods=imethods i\" lemma access_ibody [simp]: "(access (ibody i)) = access i" by (simp add: ibody_def) @@ -349,8 +353,9 @@ super::qtname,superIfs::qtname list,\::'a\" (type) "cdecl" <= (type) "qtname \ class" -definition cbody :: "class \ cbody" where - "cbody c \ \access=access c, cfields=cfields c,methods=methods c,init=init c\" +definition + cbody :: "class \ cbody" + where "cbody c = \access=access c, cfields=cfields c,methods=methods c,init=init c\" lemma access_cbody [simp]:"access (cbody c) = access c" by (simp add: cbody_def) @@ -368,18 +373,17 @@ section "standard classes" consts - Object_mdecls :: "mdecl list" --{* methods of Object *} SXcpt_mdecls :: "mdecl list" --{* methods of SXcpts *} - ObjectC :: "cdecl" --{* declaration of root class *} - SXcptC ::"xname \ cdecl" --{* declarations of throwable classes *} - -defs +definition + ObjectC :: "cdecl" --{* declaration of root class *} where + "ObjectC = (Object,\access=Public,cfields=[],methods=Object_mdecls, + init=Skip,super=undefined,superIfs=[]\)" -ObjectC_def:"ObjectC \ (Object,\access=Public,cfields=[],methods=Object_mdecls, - init=Skip,super=undefined,superIfs=[]\)" -SXcptC_def:"SXcptC xn\ (SXcpt xn,\access=Public,cfields=[],methods=SXcpt_mdecls, +definition + SXcptC ::"xname \ cdecl" --{* declarations of throwable classes *} where + "SXcptC xn = (SXcpt xn,\access=Public,cfields=[],methods=SXcpt_mdecls, init=Skip, super=if xn = Throwable then Object else SXcpt Throwable, @@ -391,8 +395,9 @@ lemma SXcptC_inject [simp]: "(SXcptC xn = SXcptC xm) = (xn = xm)" by (simp add: SXcptC_def) -definition standard_classes :: "cdecl list" where - "standard_classes \ [ObjectC, SXcptC Throwable, +definition + standard_classes :: "cdecl list" where + "standard_classes = [ObjectC, SXcptC Throwable, SXcptC NullPointer, SXcptC OutOfMemory, SXcptC ClassCast, SXcptC NegArrSize , SXcptC IndOutBound, SXcptC ArrStore]" @@ -426,16 +431,15 @@ section "is type" -consts - is_type :: "prog \ ty \ bool" - isrtype :: "prog \ ref_ty \ bool" - -primrec "is_type G (PrimT pt) = True" - "is_type G (RefT rt) = isrtype G rt" - "isrtype G (NullT ) = True" - "isrtype G (IfaceT tn) = is_iface G tn" - "isrtype G (ClassT tn) = is_class G tn" - "isrtype G (ArrayT T ) = is_type G T" +primrec is_type :: "prog \ ty \ bool" + and isrtype :: "prog \ ref_ty \ bool" +where + "is_type G (PrimT pt) = True" +| "is_type G (RefT rt) = isrtype G rt" +| "isrtype G (NullT) = True" +| "isrtype G (IfaceT tn) = is_iface G tn" +| "isrtype G (ClassT tn) = is_class G tn" +| "isrtype G (ArrayT T ) = is_type G T" lemma type_is_iface: "is_type G (Iface I) \ is_iface G I" by auto @@ -446,13 +450,13 @@ section "subinterface and subclass relation, in anticipation of TypeRel.thy" -consts +definition subint1 :: "prog \ (qtname \ qtname) set" --{* direct subinterface *} - subcls1 :: "prog \ (qtname \ qtname) set" --{* direct subclass *} + where "subint1 G = {(I,J). \i\iface G I: J\set (isuperIfs i)}" -defs - subint1_def: "subint1 G \ {(I,J). \i\iface G I: J\set (isuperIfs i)}" - subcls1_def: "subcls1 G \ {(C,D). C\Object \ (\c\class G C: super c = D)}" +definition + subcls1 :: "prog \ (qtname \ qtname) set" --{* direct subclass *} + where "subcls1 G = {(C,D). C\Object \ (\c\class G C: super c = D)}" abbreviation subcls1_syntax :: "prog => [qtname, qtname] => bool" ("_|-_<:C1_" [71,71,71] 70) @@ -517,15 +521,18 @@ section "well-structured programs" -definition ws_idecl :: "prog \ qtname \ qtname list \ bool" where - "ws_idecl G I si \ \J\set si. is_iface G J \ (J,I)\(subint1 G)^+" +definition + ws_idecl :: "prog \ qtname \ qtname list \ bool" + where "ws_idecl G I si = (\J\set si. is_iface G J \ (J,I)\(subint1 G)^+)" -definition ws_cdecl :: "prog \ qtname \ qtname \ bool" where - "ws_cdecl G C sc \ C\Object \ is_class G sc \ (sc,C)\(subcls1 G)^+" +definition + ws_cdecl :: "prog \ qtname \ qtname \ bool" + where "ws_cdecl G C sc = (C\Object \ is_class G sc \ (sc,C)\(subcls1 G)^+)" -definition ws_prog :: "prog \ bool" where - "ws_prog G \ (\(I,i)\set (ifaces G). ws_idecl G I (isuperIfs i)) \ - (\(C,c)\set (classes G). ws_cdecl G C (super c))" +definition + ws_prog :: "prog \ bool" where + "ws_prog G = ((\(I,i)\set (ifaces G). ws_idecl G I (isuperIfs i)) \ + (\(C,c)\set (classes G). ws_cdecl G C (super c)))" lemma ws_progI: @@ -810,10 +817,10 @@ apply simp done -definition imethds :: "prog \ qtname \ (sig,qtname \ mhead) tables" where +definition + imethds :: "prog \ qtname \ (sig,qtname \ mhead) tables" where --{* methods of an interface, with overriding and inheritance, cf. 9.2 *} -"imethds G I - \ iface_rec G I + "imethds G I = iface_rec G I (\I i ts. (Un_tables ts) \\ (Option.set \ table_of (map (\(s,m). (s,I,m)) (imethods i))))" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/DeclConcepts.thy --- a/src/HOL/Bali/DeclConcepts.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/DeclConcepts.thy Mon Jul 26 18:25:19 2010 +0200 @@ -9,7 +9,7 @@ section "access control (cf. 6.6), overriding and hiding (cf. 8.4.6.1)" definition is_public :: "prog \ qtname \ bool" where -"is_public G qn \ (case class G qn of +"is_public G qn = (case class G qn of None \ (case iface G qn of None \ False | Some i \ access i = Public) @@ -21,33 +21,35 @@ in their package or if they are defined public, an array type is accessible if its element type is accessible *} -consts accessible_in :: "prog \ ty \ pname \ bool" - ("_ \ _ accessible'_in _" [61,61,61] 60) - rt_accessible_in:: "prog \ ref_ty \ pname \ bool" - ("_ \ _ accessible'_in' _" [61,61,61] 60) primrec -"G\(PrimT p) accessible_in pack = True" -accessible_in_RefT_simp: -"G\(RefT r) accessible_in pack = G\r accessible_in' pack" - -"G\(NullT) accessible_in' pack = True" -"G\(IfaceT I) accessible_in' pack = ((pid I = pack) \ is_public G I)" -"G\(ClassT C) accessible_in' pack = ((pid C = pack) \ is_public G C)" -"G\(ArrayT ty) accessible_in' pack = G\ty accessible_in pack" + accessible_in :: "prog \ ty \ pname \ bool" ("_ \ _ accessible'_in _" [61,61,61] 60) and + rt_accessible_in :: "prog \ ref_ty \ pname \ bool" ("_ \ _ accessible'_in' _" [61,61,61] 60) +where + "G\(PrimT p) accessible_in pack = True" +| accessible_in_RefT_simp: + "G\(RefT r) accessible_in pack = G\r accessible_in' pack" +| "G\(NullT) accessible_in' pack = True" +| "G\(IfaceT I) accessible_in' pack = ((pid I = pack) \ is_public G I)" +| "G\(ClassT C) accessible_in' pack = ((pid C = pack) \ is_public G C)" +| "G\(ArrayT ty) accessible_in' pack = G\ty accessible_in pack" declare accessible_in_RefT_simp [simp del] -definition is_acc_class :: "prog \ pname \ qtname \ bool" where - "is_acc_class G P C \ is_class G C \ G\(Class C) accessible_in P" +definition + is_acc_class :: "prog \ pname \ qtname \ bool" + where "is_acc_class G P C = (is_class G C \ G\(Class C) accessible_in P)" -definition is_acc_iface :: "prog \ pname \ qtname \ bool" where - "is_acc_iface G P I \ is_iface G I \ G\(Iface I) accessible_in P" +definition + is_acc_iface :: "prog \ pname \ qtname \ bool" + where "is_acc_iface G P I = (is_iface G I \ G\(Iface I) accessible_in P)" -definition is_acc_type :: "prog \ pname \ ty \ bool" where - "is_acc_type G P T \ is_type G T \ G\T accessible_in P" +definition + is_acc_type :: "prog \ pname \ ty \ bool" + where "is_acc_type G P T = (is_type G T \ G\T accessible_in P)" -definition is_acc_reftype :: "prog \ pname \ ref_ty \ bool" where - "is_acc_reftype G P T \ isrtype G T \ G\T accessible_in' P" +definition + is_acc_reftype :: "prog \ pname \ ref_ty \ bool" + where "is_acc_reftype G P T = (isrtype G T \ G\T accessible_in' P)" lemma is_acc_classD: "is_acc_class G P C \ is_class G C \ G\(Class C) accessible_in P" @@ -87,7 +89,7 @@ begin definition - acc_modi_accmodi_def: "accmodi (a::acc_modi) \ a" + acc_modi_accmodi_def: "accmodi (a::acc_modi) = a" instance .. @@ -100,7 +102,7 @@ begin definition - decl_acc_modi_def: "accmodi (d::('a:: type) decl_scheme) \ access d" + decl_acc_modi_def: "accmodi (d::('a:: type) decl_scheme) = access d" instance .. @@ -113,7 +115,7 @@ begin definition - pair_acc_modi_def: "accmodi p \ (accmodi (snd p))" + pair_acc_modi_def: "accmodi p = accmodi (snd p)" instance .. @@ -126,7 +128,7 @@ begin definition - memberdecl_acc_modi_def: "accmodi m \ (case m of + memberdecl_acc_modi_def: "accmodi m = (case m of fdecl f \ accmodi f | mdecl m \ accmodi m)" @@ -152,7 +154,7 @@ begin definition - "declclass q \ \ pid = pid q, tid = tid q \" + "declclass q = \ pid = pid q, tid = tid q \" instance .. @@ -169,7 +171,7 @@ begin definition - pair_declclass_def: "declclass p \ declclass (fst p)" + pair_declclass_def: "declclass p = declclass (fst p)" instance .. @@ -208,7 +210,7 @@ begin definition - pair_is_static_def: "is_static p \ is_static (snd p)" + pair_is_static_def: "is_static p = is_static (snd p)" instance .. @@ -225,7 +227,7 @@ definition memberdecl_is_static_def: - "is_static m \ (case m of + "is_static m = (case m of fdecl f \ is_static f | mdecl m \ is_static m)" @@ -246,28 +248,34 @@ -- {* some mnemotic selectors for various pairs *} -definition decliface :: "qtname \ 'a decl_scheme \ qtname" where +definition + decliface :: "qtname \ 'a decl_scheme \ qtname" where "decliface = fst" --{* get the interface component *} -definition mbr :: "qtname \ memberdecl \ memberdecl" where +definition + mbr :: "qtname \ memberdecl \ memberdecl" where "mbr = snd" --{* get the memberdecl component *} -definition mthd :: "'b \ 'a \ 'a" where +definition + mthd :: "'b \ 'a \ 'a" where "mthd = snd" --{* get the method component *} --{* also used for mdecl, mhead *} -definition fld :: "'b \ 'a decl_scheme \ 'a decl_scheme" where +definition + fld :: "'b \ 'a decl_scheme \ 'a decl_scheme" where "fld = snd" --{* get the field component *} --{* also used for @{text "((vname \ qtname)\ field)"} *} -- {* some mnemotic selectors for @{text "(vname \ qtname)"} *} -definition fname:: "vname \ 'a \ vname" where - "fname = fst" +definition + fname:: "vname \ 'a \ vname" + where "fname = fst" --{* also used for fdecl *} -definition declclassf:: "(vname \ qtname) \ qtname" where - "declclassf = snd" +definition + declclassf:: "(vname \ qtname) \ qtname" + where "declclassf = snd" lemma decliface_simp[simp]: "decliface (I,m) = I" @@ -320,11 +328,13 @@ --{* some mnemotic selectors for @{text "(vname \ qtname)"} *} -definition fldname :: "vname \ qtname \ vname" where - "fldname = fst" +definition + fldname :: "vname \ qtname \ vname" + where "fldname = fst" -definition fldclass :: "vname \ qtname \ qtname" where - "fldclass = snd" +definition + fldclass :: "vname \ qtname \ qtname" + where "fldclass = snd" lemma fldname_simp[simp]: "fldname (n,c) = n" by (simp add: fldname_def) @@ -338,8 +348,9 @@ text {* Convert a qualified method declaration (qualified with its declaring class) to a qualified member declaration: @{text methdMembr} *} -definition methdMembr :: "qtname \ mdecl \ qtname \ memberdecl" where - "methdMembr m = (fst m, mdecl (snd m))" +definition + methdMembr :: "qtname \ mdecl \ qtname \ memberdecl" + where "methdMembr m = (fst m, mdecl (snd m))" lemma methdMembr_simp[simp]: "methdMembr (c,m) = (c,mdecl m)" by (simp add: methdMembr_def) @@ -356,8 +367,9 @@ text {* Convert a qualified method (qualified with its declaring class) to a qualified member declaration: @{text method} *} -definition method :: "sig \ (qtname \ methd) \ (qtname \ memberdecl)" where -"method sig m \ (declclass m, mdecl (sig, mthd m))" +definition + method :: "sig \ (qtname \ methd) \ (qtname \ memberdecl)" + where "method sig m = (declclass m, mdecl (sig, mthd m))" lemma method_simp[simp]: "method sig (C,m) = (C,mdecl (sig,m))" by (simp add: method_def) @@ -377,8 +389,9 @@ lemma memberid_method_simp[simp]: "memberid (method sig m) = mid sig" by (simp add: method_def) -definition fieldm :: "vname \ (qtname \ field) \ (qtname \ memberdecl)" where -"fieldm n f \ (declclass f, fdecl (n, fld f))" +definition + fieldm :: "vname \ (qtname \ field) \ (qtname \ memberdecl)" + where "fieldm n f = (declclass f, fdecl (n, fld f))" lemma fieldm_simp[simp]: "fieldm n (C,f) = (C,fdecl (n,f))" by (simp add: fieldm_def) @@ -401,8 +414,9 @@ text {* Select the signature out of a qualified method declaration: @{text msig} *} -definition msig :: "(qtname \ mdecl) \ sig" where -"msig m \ fst (snd m)" +definition + msig :: "(qtname \ mdecl) \ sig" + where "msig m = fst (snd m)" lemma msig_simp[simp]: "msig (c,(s,m)) = s" by (simp add: msig_def) @@ -410,8 +424,9 @@ text {* Convert a qualified method (qualified with its declaring class) to a qualified method declaration: @{text qmdecl} *} -definition qmdecl :: "sig \ (qtname \ methd) \ (qtname \ mdecl)" where -"qmdecl sig m \ (declclass m, (sig,mthd m))" +definition + qmdecl :: "sig \ (qtname \ methd) \ (qtname \ mdecl)" + where "qmdecl sig m = (declclass m, (sig,mthd m))" lemma qmdecl_simp[simp]: "qmdecl sig (C,m) = (C,(sig,m))" by (simp add: qmdecl_def) @@ -476,7 +491,7 @@ begin definition - pair_resTy_def: "resTy p \ resTy (snd p)" + pair_resTy_def: "resTy p = resTy (snd p)" instance .. @@ -503,14 +518,15 @@ it is not accessible for inheritance at all. \end{itemize} *} -definition inheritable_in :: "prog \ (qtname \ memberdecl) \ pname \ bool" ("_ \ _ inheritable'_in _" [61,61,61] 60) where - -"G\membr inheritable_in pack - \ (case (accmodi membr) of - Private \ False - | Package \ (pid (declclass membr)) = pack - | Protected \ True - | Public \ True)" +definition + inheritable_in :: "prog \ (qtname \ memberdecl) \ pname \ bool" ("_ \ _ inheritable'_in _" [61,61,61] 60) +where +"G\membr inheritable_in pack = + (case (accmodi membr) of + Private \ False + | Package \ (pid (declclass membr)) = pack + | Protected \ True + | Public \ True)" abbreviation Method_inheritable_in_syntax:: @@ -526,24 +542,26 @@ subsubsection "declared-in/undeclared-in" -definition cdeclaredmethd :: "prog \ qtname \ (sig,methd) table" where -"cdeclaredmethd G C - \ (case class G C of +definition + cdeclaredmethd :: "prog \ qtname \ (sig,methd) table" where + "cdeclaredmethd G C = + (case class G C of None \ \ sig. None - | Some c \ table_of (methods c) - )" + | Some c \ table_of (methods c))" -definition cdeclaredfield :: "prog \ qtname \ (vname,field) table" where -"cdeclaredfield G C - \ (case class G C of - None \ \ sig. None - | Some c \ table_of (cfields c) - )" +definition + cdeclaredfield :: "prog \ qtname \ (vname,field) table" where + "cdeclaredfield G C = + (case class G C of + None \ \ sig. None + | Some c \ table_of (cfields c))" -definition declared_in :: "prog \ memberdecl \ qtname \ bool" ("_\ _ declared'_in _" [61,61,61] 60) where -"G\m declared_in C \ (case m of - fdecl (fn,f ) \ cdeclaredfield G C fn = Some f - | mdecl (sig,m) \ cdeclaredmethd G C sig = Some m)" +definition + declared_in :: "prog \ memberdecl \ qtname \ bool" ("_\ _ declared'_in _" [61,61,61] 60) +where + "G\m declared_in C = (case m of + fdecl (fn,f ) \ cdeclaredfield G C fn = Some f + | mdecl (sig,m) \ cdeclaredmethd G C sig = Some m)" abbreviation method_declared_in:: "prog \ (qtname \ mdecl) \ qtname \ bool" @@ -560,10 +578,12 @@ by (cases m) (auto simp add: declared_in_def cdeclaredmethd_def cdeclaredfield_def) -definition undeclared_in :: "prog \ memberid \ qtname \ bool" ("_\ _ undeclared'_in _" [61,61,61] 60) where -"G\m undeclared_in C \ (case m of - fid fn \ cdeclaredfield G C fn = None - | mid sig \ cdeclaredmethd G C sig = None)" +definition + undeclared_in :: "prog \ memberid \ qtname \ bool" ("_\ _ undeclared'_in _" [61,61,61] 60) +where + "G\m undeclared_in C = (case m of + fid fn \ cdeclaredfield G C fn = None + | mid sig \ cdeclaredmethd G C sig = None)" subsubsection "members" @@ -607,17 +627,20 @@ ("_ \Field _ _ member'_of _" [61,61,61] 60) where "G\Field n f member_of C == G\fieldm n f member_of C" -definition inherits :: "prog \ qtname \ (qtname \ memberdecl) \ bool" ("_ \ _ inherits _" [61,61,61] 60) where -"G\C inherits m - \ G\m inheritable_in (pid C) \ G\memberid m undeclared_in C \ - (\ S. G\C \\<^sub>C1 S \ G\(Class S) accessible_in (pid C) \ G\m member_of S)" +definition + inherits :: "prog \ qtname \ (qtname \ memberdecl) \ bool" ("_ \ _ inherits _" [61,61,61] 60) +where + "G\C inherits m = + (G\m inheritable_in (pid C) \ G\memberid m undeclared_in C \ + (\S. G\C \\<^sub>C1 S \ G\(Class S) accessible_in (pid C) \ G\m member_of S))" lemma inherits_member: "G\C inherits m \ G\m member_of C" by (auto simp add: inherits_def intro: members.Inherited) -definition member_in :: "prog \ (qtname \ memberdecl) \ qtname \ bool" ("_ \ _ member'_in _" [61,61,61] 60) where -"G\m member_in C \ \ provC. G\ C \\<^sub>C provC \ G \ m member_of provC" +definition + member_in :: "prog \ (qtname \ memberdecl) \ qtname \ bool" ("_ \ _ member'_in _" [61,61,61] 60) + where "G\m member_in C = (\ provC. G\ C \\<^sub>C provC \ G \ m member_of provC)" text {* A member is in a class if it is member of the class or a superclass. If a member is in a class we can select this member. This additional notion is necessary since not all members are inherited to subclasses. So such @@ -703,13 +726,15 @@ subsubsection "Hiding" -definition hides :: "prog \ (qtname \ mdecl) \ (qtname \ mdecl) \ bool" ("_\ _ hides _" [61,61,61] 60) where -"G\new hides old - \ is_static new \ msig new = msig old \ - G\(declclass new) \\<^sub>C (declclass old) \ - G\Method new declared_in (declclass new) \ - G\Method old declared_in (declclass old) \ - G\Method old inheritable_in pid (declclass new)" +definition + hides :: "prog \ (qtname \ mdecl) \ (qtname \ mdecl) \ bool" ("_\ _ hides _" [61,61,61] 60) +where + "G\new hides old = + (is_static new \ msig new = msig old \ + G\(declclass new) \\<^sub>C (declclass old) \ + G\Method new declared_in (declclass new) \ + G\Method old declared_in (declclass old) \ + G\Method old inheritable_in pid (declclass new))" abbreviation sig_hides:: "prog \ sig \ (qtname \ methd) \ (qtname \ methd) \ bool" @@ -762,16 +787,18 @@ by (auto simp add: hides_def) subsubsection "permits access" -definition permits_acc :: "prog \ (qtname \ memberdecl) \ qtname \ qtname \ bool" ("_ \ _ in _ permits'_acc'_from _" [61,61,61,61] 60) where -"G\membr in cls permits_acc_from accclass - \ (case (accmodi membr) of - Private \ (declclass membr = accclass) - | Package \ (pid (declclass membr) = pid accclass) - | Protected \ (pid (declclass membr) = pid accclass) +definition + permits_acc :: "prog \ (qtname \ memberdecl) \ qtname \ qtname \ bool" ("_ \ _ in _ permits'_acc'_from _" [61,61,61,61] 60) +where + "G\membr in cls permits_acc_from accclass = + (case (accmodi membr) of + Private \ (declclass membr = accclass) + | Package \ (pid (declclass membr) = pid accclass) + | Protected \ (pid (declclass membr) = pid accclass) \ (G\accclass \\<^sub>C declclass membr \ (G\cls \\<^sub>C accclass \ is_static membr)) - | Public \ True)" + | Public \ True)" text {* The subcondition of the @{term "Protected"} case: @{term "G\accclass \\<^sub>C declclass membr"} could also be relaxed to: @@ -1380,24 +1407,25 @@ translations (type) "fspec" <= (type) "vname \ qtname" -definition imethds :: "prog \ qtname \ (sig,qtname \ mhead) tables" where -"imethds G I - \ iface_rec G I - (\I i ts. (Un_tables ts) \\ +definition + imethds :: "prog \ qtname \ (sig,qtname \ mhead) tables" where + "imethds G I = + iface_rec G I (\I i ts. (Un_tables ts) \\ (Option.set \ table_of (map (\(s,m). (s,I,m)) (imethods i))))" text {* methods of an interface, with overriding and inheritance, cf. 9.2 *} -definition accimethds :: "prog \ pname \ qtname \ (sig,qtname \ mhead) tables" where -"accimethds G pack I - \ if G\Iface I accessible_in pack - then imethds G I - else (\ k. {})" +definition + accimethds :: "prog \ pname \ qtname \ (sig,qtname \ mhead) tables" where + "accimethds G pack I = + (if G\Iface I accessible_in pack + then imethds G I + else (\ k. {}))" text {* only returns imethds if the interface is accessible *} -definition methd :: "prog \ qtname \ (sig,qtname \ methd) table" where - -"methd G C - \ class_rec G C empty +definition + methd :: "prog \ qtname \ (sig,qtname \ methd) table" where + "methd G C = + class_rec G C empty (\C c subcls_mthds. filter_tab (\sig m. G\C inherits method sig m) subcls_mthds @@ -1409,10 +1437,10 @@ Every new method with the same signature coalesces the method of a superclass. *} -definition accmethd :: "prog \ qtname \ qtname \ (sig,qtname \ methd) table" where -"accmethd G S C - \ filter_tab (\sig m. G\method sig m of C accessible_from S) - (methd G C)" +definition + accmethd :: "prog \ qtname \ qtname \ (sig,qtname \ methd) table" where + "accmethd G S C = + filter_tab (\sig m. G\method sig m of C accessible_from S) (methd G C)" text {* @{term "accmethd G S C"}: only those methods of @{term "methd G C"}, accessible from S *} @@ -1423,23 +1451,24 @@ So we must test accessibility of method @{term m} of class @{term C} (not @{term "declclass m"}) *} -definition dynmethd :: "prog \ qtname \ qtname \ (sig,qtname \ methd) table" where -"dynmethd G statC dynC - \ \ sig. - (if G\dynC \\<^sub>C statC - then (case methd G statC sig of - None \ None - | Some statM - \ (class_rec G dynC empty - (\C c subcls_mthds. - subcls_mthds - ++ - (filter_tab - (\ _ dynM. G,sig\dynM overrides statM \ dynM=statM) - (methd G C) )) - ) sig - ) - else None)" +definition + dynmethd :: "prog \ qtname \ qtname \ (sig,qtname \ methd) table" where + "dynmethd G statC dynC = + (\sig. + (if G\dynC \\<^sub>C statC + then (case methd G statC sig of + None \ None + | Some statM + \ (class_rec G dynC empty + (\C c subcls_mthds. + subcls_mthds + ++ + (filter_tab + (\ _ dynM. G,sig\dynM overrides statM \ dynM=statM) + (methd G C) )) + ) sig + ) + else None))" text {* @{term "dynmethd G statC dynC"}: dynamic method lookup of a reference with dynamic class @{term dynC} and static class @{term statC} *} @@ -1449,11 +1478,12 @@ filters the new methods (to get only those methods which actually override the methods of the static class) *} -definition dynimethd :: "prog \ qtname \ qtname \ (sig,qtname \ methd) table" where -"dynimethd G I dynC - \ \ sig. if imethds G I sig \ {} - then methd G dynC sig - else dynmethd G Object dynC sig" +definition + dynimethd :: "prog \ qtname \ qtname \ (sig,qtname \ methd) table" where + "dynimethd G I dynC = + (\sig. if imethds G I sig \ {} + then methd G dynC sig + else dynmethd G Object dynC sig)" text {* @{term "dynimethd G I dynC"}: dynamic method lookup of a reference with dynamic class dynC and static interface type I *} text {* @@ -1468,31 +1498,34 @@ down to the actual dynamic class. *} -definition dynlookup :: "prog \ ref_ty \ qtname \ (sig,qtname \ methd) table" where -"dynlookup G statT dynC - \ (case statT of - NullT \ empty - | IfaceT I \ dynimethd G I dynC - | ClassT statC \ dynmethd G statC dynC - | ArrayT ty \ dynmethd G Object dynC)" +definition + dynlookup :: "prog \ ref_ty \ qtname \ (sig,qtname \ methd) table" where + "dynlookup G statT dynC = + (case statT of + NullT \ empty + | IfaceT I \ dynimethd G I dynC + | ClassT statC \ dynmethd G statC dynC + | ArrayT ty \ dynmethd G Object dynC)" text {* @{term "dynlookup G statT dynC"}: dynamic lookup of a method within the static reference type statT and the dynamic class dynC. In a wellformd context statT will not be NullT and in case statT is an array type, dynC=Object *} -definition fields :: "prog \ qtname \ ((vname \ qtname) \ field) list" where -"fields G C - \ class_rec G C [] (\C c ts. map (\(n,t). ((n,C),t)) (cfields c) @ ts)" +definition + fields :: "prog \ qtname \ ((vname \ qtname) \ field) list" where + "fields G C = + class_rec G C [] (\C c ts. map (\(n,t). ((n,C),t)) (cfields c) @ ts)" text {* @{term "fields G C"} list of fields of a class, including all the fields of the superclasses (private, inherited and hidden ones) not only the accessible ones (an instance of a object allocates all these fields *} -definition accfield :: "prog \ qtname \ qtname \ (vname, qtname \ field) table" where -"accfield G S C - \ let field_tab = table_of((map (\((n,d),f).(n,(d,f)))) (fields G C)) - in filter_tab (\n (declC,f). G\ (declC,fdecl (n,f)) of C accessible_from S) - field_tab" +definition + accfield :: "prog \ qtname \ qtname \ (vname, qtname \ field) table" where + "accfield G S C = + (let field_tab = table_of((map (\((n,d),f).(n,(d,f)))) (fields G C)) + in filter_tab (\n (declC,f). G\ (declC,fdecl (n,f)) of C accessible_from S) + field_tab)" text {* @{term "accfield G C S"}: fields of a class @{term C} which are accessible from scope of class @{term S} with inheritance and hiding, cf. 8.3 *} @@ -1503,11 +1536,13 @@ inheritance, too. So we must test accessibility of field @{term f} of class @{term C} (not @{term "declclass f"}) *} -definition is_methd :: "prog \ qtname \ sig \ bool" where - "is_methd G \ \C sig. is_class G C \ methd G C sig \ None" +definition + is_methd :: "prog \ qtname \ sig \ bool" + where "is_methd G = (\C sig. is_class G C \ methd G C sig \ None)" -definition efname :: "((vname \ qtname) \ field) \ (vname \ qtname)" where -"efname \ fst" +definition + efname :: "((vname \ qtname) \ field) \ (vname \ qtname)" + where "efname = fst" lemma efname_simp[simp]:"efname (n,f) = n" by (simp add: efname_def) @@ -2270,8 +2305,9 @@ section "calculation of the superclasses of a class" -definition superclasses :: "prog \ qtname \ qtname set" where - "superclasses G C \ class_rec G C {} +definition + superclasses :: "prog \ qtname \ qtname set" where + "superclasses G C = class_rec G C {} (\ C c superclss. (if C=Object then {} else insert (super c) superclss))" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/DefiniteAssignment.thy --- a/src/HOL/Bali/DefiniteAssignment.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/DefiniteAssignment.thy Mon Jul 26 18:25:19 2010 +0200 @@ -49,33 +49,33 @@ with a jump, since no breaks, continues or returns are allowed in an expression. *} -consts jumpNestingOkS :: "jump set \ stmt \ bool" -primrec -"jumpNestingOkS jmps (Skip) = True" -"jumpNestingOkS jmps (Expr e) = True" -"jumpNestingOkS jmps (j\ s) = jumpNestingOkS ({j} \ jmps) s" -"jumpNestingOkS jmps (c1;;c2) = (jumpNestingOkS jmps c1 \ - jumpNestingOkS jmps c2)" -"jumpNestingOkS jmps (If(e) c1 Else c2) = (jumpNestingOkS jmps c1 \ - jumpNestingOkS jmps c2)" -"jumpNestingOkS jmps (l\ While(e) c) = jumpNestingOkS ({Cont l} \ jmps) c" +primrec jumpNestingOkS :: "jump set \ stmt \ bool" +where + "jumpNestingOkS jmps (Skip) = True" +| "jumpNestingOkS jmps (Expr e) = True" +| "jumpNestingOkS jmps (j\ s) = jumpNestingOkS ({j} \ jmps) s" +| "jumpNestingOkS jmps (c1;;c2) = (jumpNestingOkS jmps c1 \ + jumpNestingOkS jmps c2)" +| "jumpNestingOkS jmps (If(e) c1 Else c2) = (jumpNestingOkS jmps c1 \ + jumpNestingOkS jmps c2)" +| "jumpNestingOkS jmps (l\ While(e) c) = jumpNestingOkS ({Cont l} \ jmps) c" --{* The label of the while loop only handles continue jumps. Breaks are only handled by @{term Lab} *} -"jumpNestingOkS jmps (Jmp j) = (j \ jmps)" -"jumpNestingOkS jmps (Throw e) = True" -"jumpNestingOkS jmps (Try c1 Catch(C vn) c2) = (jumpNestingOkS jmps c1 \ - jumpNestingOkS jmps c2)" -"jumpNestingOkS jmps (c1 Finally c2) = (jumpNestingOkS jmps c1 \ - jumpNestingOkS jmps c2)" -"jumpNestingOkS jmps (Init C) = True" +| "jumpNestingOkS jmps (Jmp j) = (j \ jmps)" +| "jumpNestingOkS jmps (Throw e) = True" +| "jumpNestingOkS jmps (Try c1 Catch(C vn) c2) = (jumpNestingOkS jmps c1 \ + jumpNestingOkS jmps c2)" +| "jumpNestingOkS jmps (c1 Finally c2) = (jumpNestingOkS jmps c1 \ + jumpNestingOkS jmps c2)" +| "jumpNestingOkS jmps (Init C) = True" --{* wellformedness of the program must enshure that for all initializers jumpNestingOkS {} holds *} --{* Dummy analysis for intermediate smallstep term @{term FinA} *} -"jumpNestingOkS jmps (FinA a c) = False" +| "jumpNestingOkS jmps (FinA a c) = False" definition jumpNestingOk :: "jump set \ term \ bool" where -"jumpNestingOk jmps t \ (case t of +"jumpNestingOk jmps t = (case t of In1 se \ (case se of Inl e \ True | Inr s \ jumpNestingOkS jmps s) @@ -116,48 +116,46 @@ subsection {* Very restricted calculation fallback calculation *} -consts the_LVar_name:: "var \ lname" -primrec -"the_LVar_name (LVar n) = n" +primrec the_LVar_name :: "var \ lname" + where "the_LVar_name (LVar n) = n" -consts assignsE :: "expr \ lname set" - assignsV :: "var \ lname set" - assignsEs:: "expr list \ lname set" -text {* *} -primrec -"assignsE (NewC c) = {}" -"assignsE (NewA t e) = assignsE e" -"assignsE (Cast t e) = assignsE e" -"assignsE (e InstOf r) = assignsE e" -"assignsE (Lit val) = {}" -"assignsE (UnOp unop e) = assignsE e" -"assignsE (BinOp binop e1 e2) = (if binop=CondAnd \ binop=CondOr - then (assignsE e1) - else (assignsE e1) \ (assignsE e2))" -"assignsE (Super) = {}" -"assignsE (Acc v) = assignsV v" -"assignsE (v:=e) = (assignsV v) \ (assignsE e) \ - (if \ n. v=(LVar n) then {the_LVar_name v} - else {})" -"assignsE (b? e1 : e2) = (assignsE b) \ ((assignsE e1) \ (assignsE e2))" -"assignsE ({accC,statT,mode}objRef\mn({pTs}args)) - = (assignsE objRef) \ (assignsEs args)" +primrec assignsE :: "expr \ lname set" + and assignsV :: "var \ lname set" + and assignsEs:: "expr list \ lname set" +where + "assignsE (NewC c) = {}" +| "assignsE (NewA t e) = assignsE e" +| "assignsE (Cast t e) = assignsE e" +| "assignsE (e InstOf r) = assignsE e" +| "assignsE (Lit val) = {}" +| "assignsE (UnOp unop e) = assignsE e" +| "assignsE (BinOp binop e1 e2) = (if binop=CondAnd \ binop=CondOr + then (assignsE e1) + else (assignsE e1) \ (assignsE e2))" +| "assignsE (Super) = {}" +| "assignsE (Acc v) = assignsV v" +| "assignsE (v:=e) = (assignsV v) \ (assignsE e) \ + (if \ n. v=(LVar n) then {the_LVar_name v} + else {})" +| "assignsE (b? e1 : e2) = (assignsE b) \ ((assignsE e1) \ (assignsE e2))" +| "assignsE ({accC,statT,mode}objRef\mn({pTs}args)) + = (assignsE objRef) \ (assignsEs args)" -- {* Only dummy analysis for intermediate expressions @{term Methd}, @{term Body}, @{term InsInitE} and @{term Callee} *} -"assignsE (Methd C sig) = {}" -"assignsE (Body C s) = {}" -"assignsE (InsInitE s e) = {}" -"assignsE (Callee l e) = {}" +| "assignsE (Methd C sig) = {}" +| "assignsE (Body C s) = {}" +| "assignsE (InsInitE s e) = {}" +| "assignsE (Callee l e) = {}" -"assignsV (LVar n) = {}" -"assignsV ({accC,statDeclC,stat}objRef..fn) = assignsE objRef" -"assignsV (e1.[e2]) = assignsE e1 \ assignsE e2" +| "assignsV (LVar n) = {}" +| "assignsV ({accC,statDeclC,stat}objRef..fn) = assignsE objRef" +| "assignsV (e1.[e2]) = assignsE e1 \ assignsE e2" -"assignsEs [] = {}" -"assignsEs (e#es) = assignsE e \ assignsEs es" +| "assignsEs [] = {}" +| "assignsEs (e#es) = assignsE e \ assignsEs es" definition assigns :: "term \ lname set" where -"assigns t \ (case t of +"assigns t = (case t of In1 se \ (case se of Inl e \ assignsE e | Inr s \ {}) @@ -190,42 +188,42 @@ subsection "Analysis of constant expressions" -consts constVal :: "expr \ val option" -primrec -"constVal (NewC c) = None" -"constVal (NewA t e) = None" -"constVal (Cast t e) = None" -"constVal (Inst e r) = None" -"constVal (Lit val) = Some val" -"constVal (UnOp unop e) = (case (constVal e) of - None \ None - | Some v \ Some (eval_unop unop v))" -"constVal (BinOp binop e1 e2) = (case (constVal e1) of - None \ None - | Some v1 \ (case (constVal e2) of - None \ None - | Some v2 \ Some (eval_binop - binop v1 v2)))" -"constVal (Super) = None" -"constVal (Acc v) = None" -"constVal (Ass v e) = None" -"constVal (Cond b e1 e2) = (case (constVal b) of +primrec constVal :: "expr \ val option" +where + "constVal (NewC c) = None" +| "constVal (NewA t e) = None" +| "constVal (Cast t e) = None" +| "constVal (Inst e r) = None" +| "constVal (Lit val) = Some val" +| "constVal (UnOp unop e) = (case (constVal e) of None \ None - | Some bv\ (case the_Bool bv of - True \ (case (constVal e2) of - None \ None - | Some v \ constVal e1) - | False\ (case (constVal e1) of - None \ None - | Some v \ constVal e2)))" + | Some v \ Some (eval_unop unop v))" +| "constVal (BinOp binop e1 e2) = (case (constVal e1) of + None \ None + | Some v1 \ (case (constVal e2) of + None \ None + | Some v2 \ Some (eval_binop + binop v1 v2)))" +| "constVal (Super) = None" +| "constVal (Acc v) = None" +| "constVal (Ass v e) = None" +| "constVal (Cond b e1 e2) = (case (constVal b) of + None \ None + | Some bv\ (case the_Bool bv of + True \ (case (constVal e2) of + None \ None + | Some v \ constVal e1) + | False\ (case (constVal e1) of + None \ None + | Some v \ constVal e2)))" --{* Note that @{text "constVal (Cond b e1 e2)"} is stricter as it could be. It requires that all tree expressions are constant even if we can decide which branch to choose, provided the constant value of @{term b} *} -"constVal (Call accC statT mode objRef mn pTs args) = None" -"constVal (Methd C sig) = None" -"constVal (Body C s) = None" -"constVal (InsInitE s e) = None" -"constVal (Callee l e) = None" +| "constVal (Call accC statT mode objRef mn pTs args) = None" +| "constVal (Methd C sig) = None" +| "constVal (Body C s) = None" +| "constVal (InsInitE s e) = None" +| "constVal (Callee l e) = None" lemma constVal_Some_induct [consumes 1, case_names Lit UnOp BinOp CondL CondR]: assumes const: "constVal e = Some v" and @@ -282,55 +280,55 @@ to a specific boolean value. If the expression cannot evaluate to a @{term Boolean} value UNIV is returned. If we expect true/false the opposite constant false/true will also lead to UNIV. *} -consts assigns_if:: "bool \ expr \ lname set" -primrec -"assigns_if b (NewC c) = UNIV" --{*can never evaluate to Boolean*} -"assigns_if b (NewA t e) = UNIV" --{*can never evaluate to Boolean*} -"assigns_if b (Cast t e) = assigns_if b e" -"assigns_if b (Inst e r) = assignsE e" --{*Inst has type Boolean but - e is a reference type*} -"assigns_if b (Lit val) = (if val=Bool b then {} else UNIV)" -"assigns_if b (UnOp unop e) = (case constVal (UnOp unop e) of - None \ (if unop = UNot - then assigns_if (\b) e - else UNIV) - | Some v \ (if v=Bool b - then {} - else UNIV))" -"assigns_if b (BinOp binop e1 e2) - = (case constVal (BinOp binop e1 e2) of - None \ (if binop=CondAnd then - (case b of - True \ assigns_if True e1 \ assigns_if True e2 - | False \ assigns_if False e1 \ - (assigns_if True e1 \ assigns_if False e2)) - else - (if binop=CondOr then - (case b of - True \ assigns_if True e1 \ - (assigns_if False e1 \ assigns_if True e2) - | False \ assigns_if False e1 \ assigns_if False e2) - else assignsE e1 \ assignsE e2)) - | Some v \ (if v=Bool b then {} else UNIV))" +primrec assigns_if :: "bool \ expr \ lname set" +where + "assigns_if b (NewC c) = UNIV" --{*can never evaluate to Boolean*} +| "assigns_if b (NewA t e) = UNIV" --{*can never evaluate to Boolean*} +| "assigns_if b (Cast t e) = assigns_if b e" +| "assigns_if b (Inst e r) = assignsE e" --{*Inst has type Boolean but + e is a reference type*} +| "assigns_if b (Lit val) = (if val=Bool b then {} else UNIV)" +| "assigns_if b (UnOp unop e) = (case constVal (UnOp unop e) of + None \ (if unop = UNot + then assigns_if (\b) e + else UNIV) + | Some v \ (if v=Bool b + then {} + else UNIV))" +| "assigns_if b (BinOp binop e1 e2) + = (case constVal (BinOp binop e1 e2) of + None \ (if binop=CondAnd then + (case b of + True \ assigns_if True e1 \ assigns_if True e2 + | False \ assigns_if False e1 \ + (assigns_if True e1 \ assigns_if False e2)) + else + (if binop=CondOr then + (case b of + True \ assigns_if True e1 \ + (assigns_if False e1 \ assigns_if True e2) + | False \ assigns_if False e1 \ assigns_if False e2) + else assignsE e1 \ assignsE e2)) + | Some v \ (if v=Bool b then {} else UNIV))" -"assigns_if b (Super) = UNIV" --{*can never evaluate to Boolean*} -"assigns_if b (Acc v) = (assignsV v)" -"assigns_if b (v := e) = (assignsE (Ass v e))" -"assigns_if b (c? e1 : e2) = (assignsE c) \ - (case (constVal c) of - None \ (assigns_if b e1) \ - (assigns_if b e2) - | Some bv \ (case the_Bool bv of - True \ assigns_if b e1 - | False \ assigns_if b e2))" -"assigns_if b ({accC,statT,mode}objRef\mn({pTs}args)) - = assignsE ({accC,statT,mode}objRef\mn({pTs}args)) " +| "assigns_if b (Super) = UNIV" --{*can never evaluate to Boolean*} +| "assigns_if b (Acc v) = (assignsV v)" +| "assigns_if b (v := e) = (assignsE (Ass v e))" +| "assigns_if b (c? e1 : e2) = (assignsE c) \ + (case (constVal c) of + None \ (assigns_if b e1) \ + (assigns_if b e2) + | Some bv \ (case the_Bool bv of + True \ assigns_if b e1 + | False \ assigns_if b e2))" +| "assigns_if b ({accC,statT,mode}objRef\mn({pTs}args)) + = assignsE ({accC,statT,mode}objRef\mn({pTs}args)) " -- {* Only dummy analysis for intermediate expressions @{term Methd}, @{term Body}, @{term InsInitE} and @{term Callee} *} -"assigns_if b (Methd C sig) = {}" -"assigns_if b (Body C s) = {}" -"assigns_if b (InsInitE s e) = {}" -"assigns_if b (Callee l e) = {}" +| "assigns_if b (Methd C sig) = {}" +| "assigns_if b (Body C s) = {}" +| "assigns_if b (InsInitE s e) = {}" +| "assigns_if b (Callee l e) = {}" lemma assigns_if_const_b_simp: assumes boolConst: "constVal e = Some (Bool b)" (is "?Const b e") @@ -429,14 +427,17 @@ subsection {* Lifting set operations to range of tables (map to a set) *} -definition union_ts :: "('a,'b) tables \ ('a,'b) tables \ ('a,'b) tables" ("_ \\ _" [67,67] 65) where - "A \\ B \ \ k. A k \ B k" +definition + union_ts :: "('a,'b) tables \ ('a,'b) tables \ ('a,'b) tables" ("_ \\ _" [67,67] 65) + where "A \\ B = (\ k. A k \ B k)" -definition intersect_ts :: "('a,'b) tables \ ('a,'b) tables \ ('a,'b) tables" ("_ \\ _" [72,72] 71) where - "A \\ B \ \ k. A k \ B k" +definition + intersect_ts :: "('a,'b) tables \ ('a,'b) tables \ ('a,'b) tables" ("_ \\ _" [72,72] 71) + where "A \\ B = (\k. A k \ B k)" -definition all_union_ts :: "('a,'b) tables \ 'b set \ ('a,'b) tables" (infixl "\\\<^sub>\" 40) where - "A \\\<^sub>\ B \ \ k. A k \ B" +definition + all_union_ts :: "('a,'b) tables \ 'b set \ ('a,'b) tables" (infixl "\\\<^sub>\" 40) + where "(A \\\<^sub>\ B) = (\ k. A k \ B)" subsubsection {* Binary union of tables *} @@ -507,16 +508,19 @@ brk :: "breakass" --{* Definetly assigned variables for abrupt completion with a break *} -definition rmlab :: "'a \ ('a,'b) tables \ ('a,'b) tables" where -"rmlab k A \ \ x. if x=k then UNIV else A x" +definition + rmlab :: "'a \ ('a,'b) tables \ ('a,'b) tables" + where "rmlab k A = (\x. if x=k then UNIV else A x)" (* -definition setbrk :: "breakass \ assigned \ breakass set" where -"setbrk b A \ {b} \ {a| a. a\ brk A \ lab a \ lab b}" +definition + setbrk :: "breakass \ assigned \ breakass set" where + "setbrk b A = {b} \ {a| a. a\ brk A \ lab a \ lab b}" *) -definition range_inter_ts :: "('a,'b) tables \ 'b set" ("\\_" 80) where - "\\A \ {x |x. \ k. x \ A k}" +definition + range_inter_ts :: "('a,'b) tables \ 'b set" ("\\_" 80) + where "\\A = {x |x. \ k. x \ A k}" text {* In @{text "E\ B \t\ A"}, diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Eval.thy --- a/src/HOL/Bali/Eval.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Eval.thy Mon Jul 26 18:25:19 2010 +0200 @@ -141,7 +141,7 @@ where "\es\\<^sub>l == In3 es" definition undefined3 :: "('al + 'ar, 'b, 'c) sum3 \ vals" where - "undefined3 \ sum3_case (In1 \ sum_case (\x. undefined) (\x. Unit)) + "undefined3 = sum3_case (In1 \ sum_case (\x. undefined) (\x. Unit)) (\x. In2 undefined) (\x. In3 undefined)" lemma [simp]: "undefined3 (In1l x) = In1 undefined" @@ -159,8 +159,9 @@ section "exception throwing and catching" -definition throw :: "val \ abopt \ abopt" where - "throw a' x \ abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" +definition + throw :: "val \ abopt \ abopt" where + "throw a' x = abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" lemma throw_def2: "throw a' x = abrupt_if True (Some (Xcpt (Loc (the_Addr a')))) (np a' x)" @@ -168,8 +169,9 @@ apply (simp (no_asm)) done -definition fits :: "prog \ st \ val \ ty \ bool" ("_,_\_ fits _"[61,61,61,61]60) where - "G,s\a' fits T \ (\rt. T=RefT rt) \ a'=Null \ G\obj_ty(lookup_obj s a')\T" +definition + fits :: "prog \ st \ val \ ty \ bool" ("_,_\_ fits _"[61,61,61,61]60) + where "G,s\a' fits T = ((\rt. T=RefT rt) \ a'=Null \ G\obj_ty(lookup_obj s a')\T)" lemma fits_Null [simp]: "G,s\Null fits T" by (simp add: fits_def) @@ -192,9 +194,10 @@ apply iprover done -definition catch :: "prog \ state \ qtname \ bool" ("_,_\catch _"[61,61,61]60) where - "G,s\catch C\\xc. abrupt s=Some (Xcpt xc) \ - G,store s\Addr (the_Loc xc) fits Class C" +definition + catch :: "prog \ state \ qtname \ bool" ("_,_\catch _"[61,61,61]60) where + "G,s\catch C = (\xc. abrupt s=Some (Xcpt xc) \ + G,store s\Addr (the_Loc xc) fits Class C)" lemma catch_Norm [simp]: "\G,Norm s\catch tn" apply (unfold catch_def) @@ -217,9 +220,9 @@ apply (simp (no_asm)) done -definition new_xcpt_var :: "vname \ state \ state" where - "new_xcpt_var vn \ - \(x,s). Norm (lupd(VName vn\Addr (the_Loc (the_Xcpt (the x)))) s)" +definition + new_xcpt_var :: "vname \ state \ state" where + "new_xcpt_var vn = (\(x,s). Norm (lupd(VName vn\Addr (the_Loc (the_Xcpt (the x)))) s))" lemma new_xcpt_var_def2 [simp]: "new_xcpt_var vn (x,s) = @@ -232,9 +235,10 @@ section "misc" -definition assign :: "('a \ state \ state) \ 'a \ state \ state" where - "assign f v \ \(x,s). let (x',s') = (if x = None then f v else id) (x,s) - in (x',if x' = None then s' else s)" +definition + assign :: "('a \ state \ state) \ 'a \ state \ state" where + "assign f v = (\(x,s). let (x',s') = (if x = None then f v else id) (x,s) + in (x',if x' = None then s' else s))" (* lemma assign_Norm_Norm [simp]: @@ -293,26 +297,29 @@ done *) -definition init_comp_ty :: "ty \ stmt" where - "init_comp_ty T \ if (\C. T = Class C) then Init (the_Class T) else Skip" +definition + init_comp_ty :: "ty \ stmt" + where "init_comp_ty T = (if (\C. T = Class C) then Init (the_Class T) else Skip)" lemma init_comp_ty_PrimT [simp]: "init_comp_ty (PrimT pt) = Skip" apply (unfold init_comp_ty_def) apply (simp (no_asm)) done -definition invocation_class :: "inv_mode \ st \ val \ ref_ty \ qtname" where - "invocation_class m s a' statT - \ (case m of - Static \ if (\ statC. statT = ClassT statC) - then the_Class (RefT statT) - else Object - | SuperM \ the_Class (RefT statT) - | IntVir \ obj_class (lookup_obj s a'))" +definition + invocation_class :: "inv_mode \ st \ val \ ref_ty \ qtname" where + "invocation_class m s a' statT = + (case m of + Static \ if (\ statC. statT = ClassT statC) + then the_Class (RefT statT) + else Object + | SuperM \ the_Class (RefT statT) + | IntVir \ obj_class (lookup_obj s a'))" -definition invocation_declclass::"prog \ inv_mode \ st \ val \ ref_ty \ sig \ qtname" where -"invocation_declclass G m s a' statT sig - \ declclass (the (dynlookup G statT +definition + invocation_declclass :: "prog \ inv_mode \ st \ val \ ref_ty \ sig \ qtname" where + "invocation_declclass G m s a' statT sig = + declclass (the (dynlookup G statT (invocation_class m s a' statT) sig))" @@ -330,10 +337,11 @@ else Object)" by (simp add: invocation_class_def) -definition init_lvars :: "prog \ qtname \ sig \ inv_mode \ val \ val list \ - state \ state" where - "init_lvars G C sig mode a' pvs - \ \ (x,s). +definition + init_lvars :: "prog \ qtname \ sig \ inv_mode \ val \ val list \ state \ state" +where + "init_lvars G C sig mode a' pvs = + (\(x,s). let m = mthd (the (methd G C sig)); l = \ k. (case k of @@ -343,7 +351,7 @@ | Res \ None) | This \ (if mode=Static then None else Some a')) - in set_lvars l (if mode = Static then x else np a' x,s)" + in set_lvars l (if mode = Static then x else np a' x,s))" @@ -364,9 +372,11 @@ apply (simp (no_asm) add: Let_def) done -definition body :: "prog \ qtname \ sig \ expr" where - "body G C sig \ let m = the (methd G C sig) - in Body (declclass m) (stmt (mbody (mthd m)))" +definition + body :: "prog \ qtname \ sig \ expr" where + "body G C sig = + (let m = the (methd G C sig) + in Body (declclass m) (stmt (mbody (mthd m))))" lemma body_def2: --{* better suited for simplification *} "body G C sig = Body (declclass (the (methd G C sig))) @@ -377,28 +387,30 @@ section "variables" -definition lvar :: "lname \ st \ vvar" where - "lvar vn s \ (the (locals s vn), \v. supd (lupd(vn\v)))" +definition + lvar :: "lname \ st \ vvar" + where "lvar vn s = (the (locals s vn), \v. supd (lupd(vn\v)))" -definition fvar :: "qtname \ bool \ vname \ val \ state \ vvar \ state" where - "fvar C stat fn a' s - \ let (oref,xf) = if stat then (Stat C,id) - else (Heap (the_Addr a'),np a'); +definition + fvar :: "qtname \ bool \ vname \ val \ state \ vvar \ state" where + "fvar C stat fn a' s = + (let (oref,xf) = if stat then (Stat C,id) + else (Heap (the_Addr a'),np a'); n = Inl (fn,C); f = (\v. supd (upd_gobj oref n v)) - in ((the (values (the (globs (store s) oref)) n),f),abupd xf s)" + in ((the (values (the (globs (store s) oref)) n),f),abupd xf s))" -definition avar :: "prog \ val \ val \ state \ vvar \ state" where - "avar G i' a' s - \ let oref = Heap (the_Addr a'); - i = the_Intg i'; - n = Inr i; - (T,k,cs) = the_Arr (globs (store s) oref); - f = (\v (x,s). (raise_if (\G,s\v fits T) +definition + avar :: "prog \ val \ val \ state \ vvar \ state" where + "avar G i' a' s = + (let oref = Heap (the_Addr a'); + i = the_Intg i'; + n = Inr i; + (T,k,cs) = the_Arr (globs (store s) oref); + f = (\v (x,s). (raise_if (\G,s\v fits T) ArrStore x ,upd_gobj oref n v s)) - in ((the (cs n),f) - ,abupd (raise_if (\i in_bounds k) IndOutBound \ np a') s)" + in ((the (cs n),f),abupd (raise_if (\i in_bounds k) IndOutBound \ np a') s))" lemma fvar_def2: --{* better suited for simplification *} "fvar C stat fn a' s = @@ -431,27 +443,29 @@ apply (simp (no_asm) add: Let_def split_beta) done -definition check_field_access :: "prog \ qtname \ qtname \ vname \ bool \ val \ state \ state" where -"check_field_access G accC statDeclC fn stat a' s - \ let oref = if stat then Stat statDeclC - else Heap (the_Addr a'); - dynC = case oref of +definition + check_field_access :: "prog \ qtname \ qtname \ vname \ bool \ val \ state \ state" where + "check_field_access G accC statDeclC fn stat a' s = + (let oref = if stat then Stat statDeclC + else Heap (the_Addr a'); + dynC = case oref of Heap a \ obj_class (the (globs (store s) oref)) | Stat C \ C; - f = (the (table_of (DeclConcepts.fields G dynC) (fn,statDeclC))) - in abupd + f = (the (table_of (DeclConcepts.fields G dynC) (fn,statDeclC))) + in abupd (error_if (\ G\Field fn (statDeclC,f) in dynC dyn_accessible_from accC) AccessViolation) - s" + s)" -definition check_method_access :: "prog \ qtname \ ref_ty \ inv_mode \ sig \ val \ state \ state" where -"check_method_access G accC statT mode sig a' s - \ let invC = invocation_class mode (store s) a' statT; +definition + check_method_access :: "prog \ qtname \ ref_ty \ inv_mode \ sig \ val \ state \ state" where + "check_method_access G accC statT mode sig a' s = + (let invC = invocation_class mode (store s) a' statT; dynM = the (dynlookup G statT invC sig) - in abupd + in abupd (error_if (\ G\Methd sig dynM in invC dyn_accessible_from accC) AccessViolation) - s" + s)" section "evaluation judgments" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Example.thy --- a/src/HOL/Bali/Example.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Example.thy Mon Jul 26 18:25:19 2010 +0200 @@ -70,22 +70,21 @@ datatype vnam' = arr' | vee' | z' | e' datatype label' = lab1' -consts - - tnam' :: "tnam' \ tnam" - vnam' :: "vnam' \ vname" +axiomatization + tnam' :: "tnam' \ tnam" and + vnam' :: "vnam' \ vname" and label':: "label' \ label" -axioms (** tnam', vnam' and label are intended to be isomorphic +where + (** tnam', vnam' and label are intended to be isomorphic to tnam, vname and label **) - inj_tnam' [simp]: "(tnam' x = tnam' y) = (x = y)" - inj_vnam' [simp]: "(vnam' x = vnam' y) = (x = y)" - inj_label' [simp]: "(label' x = label' y) = (x = y)" - - - surj_tnam': "\m. n = tnam' m" - surj_vnam': "\m. n = vnam' m" - surj_label':" \m. n = label' m" + inj_tnam' [simp]: "\x y. (tnam' x = tnam' y) = (x = y)" and + inj_vnam' [simp]: "\x y. (vnam' x = vnam' y) = (x = y)" and + inj_label' [simp]: "\x y. (label' x = label' y) = (x = y)" and + + surj_tnam': "\n. \m. n = tnam' m" and + surj_vnam': "\n. \m. n = vnam' m" and + surj_label':" \n. \m. n = label' m" abbreviation HasFoo :: qtname where @@ -149,22 +148,24 @@ Object_mdecls_def: "Object_mdecls \ []" SXcpt_mdecls_def: "SXcpt_mdecls \ []" -consts - +axiomatization foo :: mname -definition foo_sig :: sig - where "foo_sig \ \name=foo,parTs=[Class Base]\" +definition + foo_sig :: sig + where "foo_sig = \name=foo,parTs=[Class Base]\" -definition foo_mhead :: mhead - where "foo_mhead \ \access=Public,static=False,pars=[z],resT=Class Base\" +definition + foo_mhead :: mhead + where "foo_mhead = \access=Public,static=False,pars=[z],resT=Class Base\" -definition Base_foo :: mdecl - where "Base_foo \ (foo_sig, \access=Public,static=False,pars=[z],resT=Class Base, +definition + Base_foo :: mdecl + where "Base_foo = (foo_sig, \access=Public,static=False,pars=[z],resT=Class Base, mbody=\lcls=[],stmt=Return (!!z)\\)" definition Ext_foo :: mdecl - where "Ext_foo \ (foo_sig, + where "Ext_foo = (foo_sig, \access=Public,static=False,pars=[z],resT=Class Ext, mbody=\lcls=[] ,stmt=Expr({Ext,Ext,False}Cast (Class Ext) (!!z)..vee := @@ -172,11 +173,13 @@ Return (Lit Null)\ \)" -definition arr_viewed_from :: "qtname \ qtname \ var" where -"arr_viewed_from accC C \ {accC,Base,True}StatRef (ClassT C)..arr" +definition + arr_viewed_from :: "qtname \ qtname \ var" + where "arr_viewed_from accC C = {accC,Base,True}StatRef (ClassT C)..arr" -definition BaseCl :: "class" where -"BaseCl \ \access=Public, +definition + BaseCl :: "class" where + "BaseCl = \access=Public, cfields=[(arr, \access=Public,static=True ,type=PrimT Boolean.[]\), (vee, \access=Public,static=False,type=Iface HasFoo \)], methods=[Base_foo], @@ -185,16 +188,18 @@ super=Object, superIfs=[HasFoo]\" -definition ExtCl :: "class" where -"ExtCl \ \access=Public, +definition + ExtCl :: "class" where + "ExtCl = \access=Public, cfields=[(vee, \access=Public,static=False,type= PrimT Integer\)], methods=[Ext_foo], init=Skip, super=Base, superIfs=[]\" -definition MainCl :: "class" where -"MainCl \ \access=Public, +definition + MainCl :: "class" where + "MainCl = \access=Public, cfields=[], methods=[], init=Skip, @@ -202,14 +207,17 @@ superIfs=[]\" (* The "main" method is modeled seperately (see tprg) *) -definition HasFooInt :: iface - where "HasFooInt \ \access=Public,imethods=[(foo_sig, foo_mhead)],isuperIfs=[]\" +definition + HasFooInt :: iface + where "HasFooInt = \access=Public,imethods=[(foo_sig, foo_mhead)],isuperIfs=[]\" -definition Ifaces ::"idecl list" - where "Ifaces \ [(HasFoo,HasFooInt)]" +definition + Ifaces ::"idecl list" + where "Ifaces = [(HasFoo,HasFooInt)]" -definition "Classes" ::"cdecl list" - where "Classes \ [(Base,BaseCl),(Ext,ExtCl),(Main,MainCl)]@standard_classes" +definition + "Classes" ::"cdecl list" + where "Classes = [(Base,BaseCl),(Ext,ExtCl),(Main,MainCl)]@standard_classes" lemmas table_classes_defs = Classes_def standard_classes_def ObjectC_def SXcptC_def @@ -264,12 +272,13 @@ tprg :: prog where "tprg == \ifaces=Ifaces,classes=Classes\" -definition test :: "(ty)list \ stmt" where - "test pTs \ e:==NewC Ext;; +definition + test :: "(ty)list \ stmt" where + "test pTs = (e:==NewC Ext;; \ Try Expr({Main,ClassT Base,IntVir}!!e\foo({pTs}[Lit Null])) \ Catch((SXcpt NullPointer) z) (lab1\ While(Acc - (Acc (arr_viewed_from Main Ext).[Lit (Intg 2)])) Skip)" + (Acc (arr_viewed_from Main Ext).[Lit (Intg 2)])) Skip))" section "well-structuredness" @@ -1185,9 +1194,9 @@ rewrite_rule [@{thm assign_def}, @{thm Let_def}]) @{thms eval.intros}) *} lemmas eval_Is = eval_Init eval_StatRef AbruptIs eval_intros -consts - a :: loc - b :: loc +axiomatization + a :: loc and + b :: loc and c :: loc abbreviation "one == Suc 0" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Name.thy --- a/src/HOL/Bali/Name.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Name.thy Mon Jul 26 18:25:19 2010 +0200 @@ -68,14 +68,14 @@ begin definition - tname_tname_def: "tname (t::tname) \ t" + tname_tname_def: "tname (t::tname) = t" instance .. end definition - qtname_qtname_def: "qtname (q::'a qtname_ext_type) \ q" + qtname_qtname_def: "qtname (q::'a qtname_ext_type) = q" translations (type) "qtname" <= (type) "\pid::pname,tid::tname\" @@ -84,16 +84,17 @@ axiomatization java_lang::pname --{* package java.lang *} -consts +definition Object :: qtname - SXcpt :: "xname \ qtname" -defs - Object_def: "Object \ \pid = java_lang, tid = Object'\" - SXcpt_def: "SXcpt \ \x. \pid = java_lang, tid = SXcpt' x\" + where "Object = \pid = java_lang, tid = Object'\" + +definition SXcpt :: "xname \ qtname" + where "SXcpt = (\x. \pid = java_lang, tid = SXcpt' x\)" lemma Object_neq_SXcpt [simp]: "Object \ SXcpt xn" by (simp add: Object_def SXcpt_def) lemma SXcpt_inject [simp]: "(SXcpt xn = SXcpt xm) = (xn = xm)" by (simp add: SXcpt_def) + end diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/State.thy --- a/src/HOL/Bali/State.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/State.thy Mon Jul 26 18:25:19 2010 +0200 @@ -38,8 +38,9 @@ (type) "obj" <= (type) "\tag::obj_tag, values::vn \ val option\" (type) "obj" <= (type) "\tag::obj_tag, values::vn \ val option,\::'a\" -definition the_Arr :: "obj option \ ty \ int \ (vn, val) table" where - "the_Arr obj \ SOME (T,k,t). obj = Some \tag=Arr T k,values=t\" +definition + the_Arr :: "obj option \ ty \ int \ (vn, val) table" + where "the_Arr obj = (SOME (T,k,t). obj = Some \tag=Arr T k,values=t\)" lemma the_Arr_Arr [simp]: "the_Arr (Some \tag=Arr T k,values=cs\) = (T,k,cs)" apply (auto simp: the_Arr_def) @@ -50,18 +51,20 @@ apply (auto simp add: the_Arr_def) done -definition upd_obj :: "vn \ val \ obj \ obj" where - "upd_obj n v \ \ obj . obj \values:=(values obj)(n\v)\" +definition + upd_obj :: "vn \ val \ obj \ obj" + where "upd_obj n v = (\obj. obj \values:=(values obj)(n\v)\)" lemma upd_obj_def2 [simp]: "upd_obj n v obj = obj \values:=(values obj)(n\v)\" apply (auto simp: upd_obj_def) done -definition obj_ty :: "obj \ ty" where - "obj_ty obj \ case tag obj of - CInst C \ Class C - | Arr T k \ T.[]" +definition + obj_ty :: "obj \ ty" where + "obj_ty obj = (case tag obj of + CInst C \ Class C + | Arr T k \ T.[])" lemma obj_ty_eq [intro!]: "obj_ty \tag=oi,values=x\ = obj_ty \tag=oi,values=y\" by (simp add: obj_ty_def) @@ -97,10 +100,11 @@ apply (auto split add: obj_tag.split_asm) done -definition obj_class :: "obj \ qtname" where - "obj_class obj \ case tag obj of - CInst C \ C - | Arr T k \ Object" +definition + obj_class :: "obj \ qtname" where + "obj_class obj = (case tag obj of + CInst C \ C + | Arr T k \ Object)" lemma obj_class_CInst [simp]: "obj_class \tag=CInst C,values=vs\ = C" @@ -136,9 +140,10 @@ "Stat" => "CONST Inr" (type) "oref" <= (type) "loc + qtname" -definition fields_table :: "prog \ qtname \ (fspec \ field \ bool) \ (fspec, ty) table" where - "fields_table G C P - \ Option.map type \ table_of (filter (split P) (DeclConcepts.fields G C))" +definition + fields_table :: "prog \ qtname \ (fspec \ field \ bool) \ (fspec, ty) table" where + "fields_table G C P = + Option.map type \ table_of (filter (split P) (DeclConcepts.fields G C))" lemma fields_table_SomeI: "\table_of (DeclConcepts.fields G C) n = Some f; P n f\ @@ -173,20 +178,23 @@ apply simp done -definition in_bounds :: "int \ int \ bool" ("(_/ in'_bounds _)" [50, 51] 50) where - "i in_bounds k \ 0 \ i \ i < k" +definition + in_bounds :: "int \ int \ bool" ("(_/ in'_bounds _)" [50, 51] 50) + where "i in_bounds k = (0 \ i \ i < k)" -definition arr_comps :: "'a \ int \ int \ 'a option" where - "arr_comps T k \ \i. if i in_bounds k then Some T else None" +definition + arr_comps :: "'a \ int \ int \ 'a option" + where "arr_comps T k = (\i. if i in_bounds k then Some T else None)" -definition var_tys :: "prog \ obj_tag \ oref \ (vn, ty) table" where -"var_tys G oi r - \ case r of +definition + var_tys :: "prog \ obj_tag \ oref \ (vn, ty) table" where + "var_tys G oi r = + (case r of Heap a \ (case oi of CInst C \ fields_table G C (\n f. \static f) (+) empty | Arr T k \ empty (+) arr_comps T k) | Stat C \ fields_table G C (\fn f. declclassf fn = C \ static f) - (+) empty" + (+) empty)" lemma var_tys_Some_eq: "var_tys G oi r n = Some T @@ -222,14 +230,16 @@ subsection "access" -definition globs :: "st \ globs" where - "globs \ st_case (\g l. g)" +definition + globs :: "st \ globs" + where "globs = st_case (\g l. g)" -definition locals :: "st \ locals" where - "locals \ st_case (\g l. l)" +definition + locals :: "st \ locals" + where "locals = st_case (\g l. l)" -definition heap :: "st \ heap" where - "heap s \ globs s \ Heap" +definition heap :: "st \ heap" where + "heap s = globs s \ Heap" lemma globs_def2 [simp]: " globs (st g l) = g" @@ -250,8 +260,9 @@ subsection "memory allocation" -definition new_Addr :: "heap \ loc option" where - "new_Addr h \ if (\a. h a \ None) then None else Some (SOME a. h a = None)" +definition + new_Addr :: "heap \ loc option" where + "new_Addr h = (if (\a. h a \ None) then None else Some (SOME a. h a = None))" lemma new_AddrD: "new_Addr h = Some a \ h a = None" apply (auto simp add: new_Addr_def) @@ -290,20 +301,25 @@ subsection "update" -definition gupd :: "oref \ obj \ st \ st" ("gupd'(_\_')"[10,10]1000) where - "gupd r obj \ st_case (\g l. st (g(r\obj)) l)" +definition + gupd :: "oref \ obj \ st \ st" ("gupd'(_\_')" [10, 10] 1000) + where "gupd r obj = st_case (\g l. st (g(r\obj)) l)" -definition lupd :: "lname \ val \ st \ st" ("lupd'(_\_')"[10,10]1000) where - "lupd vn v \ st_case (\g l. st g (l(vn\v)))" +definition + lupd :: "lname \ val \ st \ st" ("lupd'(_\_')" [10, 10] 1000) + where "lupd vn v = st_case (\g l. st g (l(vn\v)))" -definition upd_gobj :: "oref \ vn \ val \ st \ st" where - "upd_gobj r n v \ st_case (\g l. st (chg_map (upd_obj n v) r g) l)" +definition + upd_gobj :: "oref \ vn \ val \ st \ st" + where "upd_gobj r n v = st_case (\g l. st (chg_map (upd_obj n v) r g) l)" -definition set_locals :: "locals \ st \ st" where - "set_locals l \ st_case (\g l'. st g l)" +definition + set_locals :: "locals \ st \ st" + where "set_locals l = st_case (\g l'. st g l)" -definition init_obj :: "prog \ obj_tag \ oref \ st \ st" where - "init_obj G oi r \ gupd(r\\tag=oi, values=init_vals (var_tys G oi r)\)" +definition + init_obj :: "prog \ obj_tag \ oref \ st \ st" + where "init_obj G oi r = gupd(r\\tag=oi, values=init_vals (var_tys G oi r)\)" abbreviation init_class_obj :: "prog \ qtname \ st \ st" @@ -447,23 +463,22 @@ -consts +primrec the_Xcpt :: "abrupt \ xcpt" + where "the_Xcpt (Xcpt x) = x" - the_Xcpt :: "abrupt \ xcpt" - the_Jump :: "abrupt => jump" - the_Loc :: "xcpt \ loc" - the_Std :: "xcpt \ xname" +primrec the_Jump :: "abrupt => jump" + where "the_Jump (Jump j) = j" -primrec "the_Xcpt (Xcpt x) = x" -primrec "the_Jump (Jump j) = j" -primrec "the_Loc (Loc a) = a" -primrec "the_Std (Std x) = x" +primrec the_Loc :: "xcpt \ loc" + where "the_Loc (Loc a) = a" - +primrec the_Std :: "xcpt \ xname" + where "the_Std (Std x) = x" -definition abrupt_if :: "bool \ abopt \ abopt \ abopt" where - "abrupt_if c x' x \ if c \ (x = None) then x' else x" +definition + abrupt_if :: "bool \ abopt \ abopt \ abopt" + where "abrupt_if c x' x = (if c \ (x = None) then x' else x)" lemma abrupt_if_True_None [simp]: "abrupt_if True x None = x" by (simp add: abrupt_if_def) @@ -542,8 +557,9 @@ apply auto done -definition absorb :: "jump \ abopt \ abopt" where - "absorb j a \ if a=Some (Jump j) then None else a" +definition + absorb :: "jump \ abopt \ abopt" + where "absorb j a = (if a=Some (Jump j) then None else a)" lemma absorb_SomeD [dest!]: "absorb j a = Some x \ a = Some x" by (auto simp add: absorb_def) @@ -593,16 +609,18 @@ apply clarsimp done -definition normal :: "state \ bool" where - "normal \ \s. abrupt s = None" +definition + normal :: "state \ bool" + where "normal = (\s. abrupt s = None)" lemma normal_def2 [simp]: "normal s = (abrupt s = None)" apply (unfold normal_def) apply (simp (no_asm)) done -definition heap_free :: "nat \ state \ bool" where - "heap_free n \ \s. atleast_free (heap (store s)) n" +definition + heap_free :: "nat \ state \ bool" + where "heap_free n = (\s. atleast_free (heap (store s)) n)" lemma heap_free_def2 [simp]: "heap_free n s = atleast_free (heap (store s)) n" apply (unfold heap_free_def) @@ -611,11 +629,13 @@ subsection "update" -definition abupd :: "(abopt \ abopt) \ state \ state" where - "abupd f \ prod_fun f id" +definition + abupd :: "(abopt \ abopt) \ state \ state" + where "abupd f = prod_fun f id" -definition supd :: "(st \ st) \ state \ state" where - "supd \ prod_fun id" +definition + supd :: "(st \ st) \ state \ state" + where "supd = prod_fun id" lemma abupd_def2 [simp]: "abupd f (x,s) = (f x,s)" by (simp add: abupd_def) @@ -669,11 +689,13 @@ section "initialisation test" -definition inited :: "qtname \ globs \ bool" where - "inited C g \ g (Stat C) \ None" +definition + inited :: "qtname \ globs \ bool" + where "inited C g = (g (Stat C) \ None)" -definition initd :: "qtname \ state \ bool" where - "initd C \ inited C \ globs \ store" +definition + initd :: "qtname \ state \ bool" + where "initd C = inited C \ globs \ store" lemma not_inited_empty [simp]: "\inited C empty" apply (unfold inited_def) @@ -706,8 +728,10 @@ done section {* @{text error_free} *} -definition error_free :: "state \ bool" where -"error_free s \ \ (\ err. abrupt s = Some (Error err))" + +definition + error_free :: "state \ bool" + where "error_free s = (\ (\ err. abrupt s = Some (Error err)))" lemma error_free_Norm [simp,intro]: "error_free (Norm s)" by (simp add: error_free_def) diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Table.thy --- a/src/HOL/Bali/Table.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Table.thy Mon Jul 26 18:25:19 2010 +0200 @@ -54,15 +54,15 @@ --{* when merging tables old and new, only override an entry of table old when the condition cond holds *} -"cond_override cond old new \ - \ k. +"cond_override cond old new = + (\k. (case new k of None \ old k | Some new_val \ (case old k of None \ Some new_val | Some old_val \ (if cond new_val old_val then Some new_val - else Some old_val)))" + else Some old_val))))" lemma cond_override_empty1[simp]: "cond_override c empty t = t" by (simp add: cond_override_def expand_fun_eq) @@ -95,10 +95,11 @@ section {* Filter on Tables *} -definition filter_tab :: "('a \ 'b \ bool) \ ('a, 'b) table \ ('a, 'b) table" where -"filter_tab c t \ \ k. (case t k of +definition + filter_tab :: "('a \ 'b \ bool) \ ('a, 'b) table \ ('a, 'b) table" where + "filter_tab c t = (\k. (case t k of None \ None - | Some x \ if c k x then Some x else None)" + | Some x \ if c k x then Some x else None))" lemma filter_tab_empty[simp]: "filter_tab c empty = empty" by (simp add: filter_tab_def empty_def) @@ -279,27 +280,31 @@ done -consts - Un_tables :: "('a, 'b) tables set \ ('a, 'b) tables" - overrides_t :: "('a, 'b) tables \ ('a, 'b) tables \ - ('a, 'b) tables" (infixl "\\" 100) - hidings_entails:: "('a, 'b) tables \ ('a, 'c) tables \ - ('b \ 'c \ bool) \ bool" ("_ hidings _ entails _" 20) +definition + Un_tables :: "('a, 'b) tables set \ ('a, 'b) tables" + where "Un_tables ts\\= (\k. \t\ts. t k)" + +definition + overrides_t :: "('a, 'b) tables \ ('a, 'b) tables \ ('a, 'b) tables" (infixl "\\" 100) + where "s \\ t = (\k. if t k = {} then s k else t k)" + +definition + hidings_entails :: "('a, 'b) tables \ ('a, 'c) tables \ ('b \ 'c \ bool) \ bool" + ("_ hidings _ entails _" 20) + where "(t hidings s entails R) = (\k. \x\t k. \y\s k. R x y)" + +definition --{* variant for unique table: *} - hiding_entails :: "('a, 'b) table \ ('a, 'c) table \ - ('b \ 'c \ bool) \ bool" ("_ hiding _ entails _" 20) + hiding_entails :: "('a, 'b) table \ ('a, 'c) table \ ('b \ 'c \ bool) \ bool" + ("_ hiding _ entails _" 20) + where "(t hiding s entails R) = (\k. \x\t k: \y\s k: R x y)" + +definition --{* variant for a unique table and conditional overriding: *} cond_hiding_entails :: "('a, 'b) table \ ('a, 'c) table \ ('b \ 'c \ bool) \ ('b \ 'c \ bool) \ bool" ("_ hiding _ under _ entails _" 20) - -defs - Un_tables_def: "Un_tables ts\\\ \k. \t\ts. t k" - overrides_t_def: "s \\ t \ \k. if t k = {} then s k else t k" - hidings_entails_def: "t hidings s entails R \ \k. \x\t k. \y\s k. R x y" - hiding_entails_def: "t hiding s entails R \ \k. \x\t k: \y\s k: R x y" - cond_hiding_entails_def: "t hiding s under C entails R - \ \k. \x\t k: \y\s k: C x y \ R x y" + where "(t hiding s under C entails R) = (\k. \x\t k: \y\s k: C x y \ R x y)" section "Untables" @@ -383,12 +388,10 @@ (*###TO Map?*) -consts - atleast_free :: "('a ~=> 'b) => nat => bool" -primrec - "atleast_free m 0 = True" - atleast_free_Suc: - "atleast_free m (Suc n) = (? a. m a = None & (!b. atleast_free (m(a|->b)) n))" +primrec atleast_free :: "('a ~=> 'b) => nat => bool" +where + "atleast_free m 0 = True" +| atleast_free_Suc: "atleast_free m (Suc n) = (\a. m a = None & (!b. atleast_free (m(a|->b)) n))" lemma atleast_free_weaken [rule_format (no_asm)]: "!m. atleast_free m (Suc n) \ atleast_free m n" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Term.thy --- a/src/HOL/Bali/Term.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Term.thy Mon Jul 26 18:25:19 2010 +0200 @@ -258,8 +258,9 @@ StatRef :: "ref_ty \ expr" where "StatRef rt == Cast (RefT rt) (Lit Null)" -definition is_stmt :: "term \ bool" where - "is_stmt t \ \c. t=In1r c" +definition + is_stmt :: "term \ bool" + where "is_stmt t = (\c. t=In1r c)" ML {* bind_thms ("is_stmt_rews", sum3_instantiate @{context} @{thm is_stmt_def}) *} @@ -307,7 +308,7 @@ begin definition - stmt_inj_term_def: "\c::stmt\ \ In1r c" + stmt_inj_term_def: "\c::stmt\ = In1r c" instance .. @@ -323,7 +324,7 @@ begin definition - expr_inj_term_def: "\e::expr\ \ In1l e" + expr_inj_term_def: "\e::expr\ = In1l e" instance .. @@ -339,7 +340,7 @@ begin definition - var_inj_term_def: "\v::var\ \ In2 v" + var_inj_term_def: "\v::var\ = In2 v" instance .. @@ -368,7 +369,7 @@ begin definition - "\es::'a list\ \ In3 (map expr_of es)" + "\es::'a list\ = In3 (map expr_of es)" instance .. @@ -425,46 +426,47 @@ done section {* Evaluation of unary operations *} -consts eval_unop :: "unop \ val \ val" -primrec -"eval_unop UPlus v = Intg (the_Intg v)" -"eval_unop UMinus v = Intg (- (the_Intg v))" -"eval_unop UBitNot v = Intg 42" -- "FIXME: Not yet implemented" -"eval_unop UNot v = Bool (\ the_Bool v)" +primrec eval_unop :: "unop \ val \ val" +where + "eval_unop UPlus v = Intg (the_Intg v)" +| "eval_unop UMinus v = Intg (- (the_Intg v))" +| "eval_unop UBitNot v = Intg 42" -- "FIXME: Not yet implemented" +| "eval_unop UNot v = Bool (\ the_Bool v)" section {* Evaluation of binary operations *} -consts eval_binop :: "binop \ val \ val \ val" -primrec -"eval_binop Mul v1 v2 = Intg ((the_Intg v1) * (the_Intg v2))" -"eval_binop Div v1 v2 = Intg ((the_Intg v1) div (the_Intg v2))" -"eval_binop Mod v1 v2 = Intg ((the_Intg v1) mod (the_Intg v2))" -"eval_binop Plus v1 v2 = Intg ((the_Intg v1) + (the_Intg v2))" -"eval_binop Minus v1 v2 = Intg ((the_Intg v1) - (the_Intg v2))" +primrec eval_binop :: "binop \ val \ val \ val" +where + "eval_binop Mul v1 v2 = Intg ((the_Intg v1) * (the_Intg v2))" +| "eval_binop Div v1 v2 = Intg ((the_Intg v1) div (the_Intg v2))" +| "eval_binop Mod v1 v2 = Intg ((the_Intg v1) mod (the_Intg v2))" +| "eval_binop Plus v1 v2 = Intg ((the_Intg v1) + (the_Intg v2))" +| "eval_binop Minus v1 v2 = Intg ((the_Intg v1) - (the_Intg v2))" -- "Be aware of the explicit coercion of the shift distance to nat" -"eval_binop LShift v1 v2 = Intg ((the_Intg v1) * (2^(nat (the_Intg v2))))" -"eval_binop RShift v1 v2 = Intg ((the_Intg v1) div (2^(nat (the_Intg v2))))" -"eval_binop RShiftU v1 v2 = Intg 42" --"FIXME: Not yet implemented" +| "eval_binop LShift v1 v2 = Intg ((the_Intg v1) * (2^(nat (the_Intg v2))))" +| "eval_binop RShift v1 v2 = Intg ((the_Intg v1) div (2^(nat (the_Intg v2))))" +| "eval_binop RShiftU v1 v2 = Intg 42" --"FIXME: Not yet implemented" -"eval_binop Less v1 v2 = Bool ((the_Intg v1) < (the_Intg v2))" -"eval_binop Le v1 v2 = Bool ((the_Intg v1) \ (the_Intg v2))" -"eval_binop Greater v1 v2 = Bool ((the_Intg v2) < (the_Intg v1))" -"eval_binop Ge v1 v2 = Bool ((the_Intg v2) \ (the_Intg v1))" +| "eval_binop Less v1 v2 = Bool ((the_Intg v1) < (the_Intg v2))" +| "eval_binop Le v1 v2 = Bool ((the_Intg v1) \ (the_Intg v2))" +| "eval_binop Greater v1 v2 = Bool ((the_Intg v2) < (the_Intg v1))" +| "eval_binop Ge v1 v2 = Bool ((the_Intg v2) \ (the_Intg v1))" -"eval_binop Eq v1 v2 = Bool (v1=v2)" -"eval_binop Neq v1 v2 = Bool (v1\v2)" -"eval_binop BitAnd v1 v2 = Intg 42" -- "FIXME: Not yet implemented" -"eval_binop And v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" -"eval_binop BitXor v1 v2 = Intg 42" -- "FIXME: Not yet implemented" -"eval_binop Xor v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" -"eval_binop BitOr v1 v2 = Intg 42" -- "FIXME: Not yet implemented" -"eval_binop Or v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" -"eval_binop CondAnd v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" -"eval_binop CondOr v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +| "eval_binop Eq v1 v2 = Bool (v1=v2)" +| "eval_binop Neq v1 v2 = Bool (v1\v2)" +| "eval_binop BitAnd v1 v2 = Intg 42" -- "FIXME: Not yet implemented" +| "eval_binop And v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +| "eval_binop BitXor v1 v2 = Intg 42" -- "FIXME: Not yet implemented" +| "eval_binop Xor v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +| "eval_binop BitOr v1 v2 = Intg 42" -- "FIXME: Not yet implemented" +| "eval_binop Or v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +| "eval_binop CondAnd v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" +| "eval_binop CondOr v1 v2 = Bool ((the_Bool v1) \ (the_Bool v2))" -definition need_second_arg :: "binop \ val \ bool" where -"need_second_arg binop v1 \ \ ((binop=CondAnd \ \ the_Bool v1) \ - (binop=CondOr \ the_Bool v1))" +definition + need_second_arg :: "binop \ val \ bool" where + "need_second_arg binop v1 = (\ ((binop=CondAnd \ \ the_Bool v1) \ + (binop=CondOr \ the_Bool v1)))" text {* @{term CondAnd} and @{term CondOr} only evalulate the second argument if the value isn't already determined by the first argument*} diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Trans.thy --- a/src/HOL/Bali/Trans.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Trans.thy Mon Jul 26 18:25:19 2010 +0200 @@ -9,12 +9,13 @@ theory Trans imports Evaln begin -definition groundVar :: "var \ bool" where -"groundVar v \ (case v of - LVar ln \ True - | {accC,statDeclC,stat}e..fn \ \ a. e=Lit a - | e1.[e2] \ \ a i. e1= Lit a \ e2 = Lit i - | InsInitV c v \ False)" +definition + groundVar :: "var \ bool" where + "groundVar v \ (case v of + LVar ln \ True + | {accC,statDeclC,stat}e..fn \ \ a. e=Lit a + | e1.[e2] \ \ a i. e1= Lit a \ e2 = Lit i + | InsInitV c v \ False)" lemma groundVar_cases [consumes 1, case_names LVar FVar AVar]: assumes ground: "groundVar v" and @@ -34,14 +35,15 @@ done qed -definition groundExprs :: "expr list \ bool" where - "groundExprs es \ (\e \ set es. \v. e = Lit v)" +definition + groundExprs :: "expr list \ bool" + where "groundExprs es \ (\e \ set es. \v. e = Lit v)" -primrec the_val:: "expr \ val" where - "the_val (Lit v) = v" +primrec the_val:: "expr \ val" + where "the_val (Lit v) = v" primrec the_var:: "prog \ state \ var \ (vvar \ state)" where - "the_var G s (LVar ln) =(lvar ln (store s),s)" + "the_var G s (LVar ln) = (lvar ln (store s),s)" | the_var_FVar_def: "the_var G s ({accC,statDeclC,stat}a..fn) =fvar statDeclC stat fn (the_val a) s" | the_var_AVar_def: "the_var G s(a.[i]) =avar G (the_val i) (the_val a) s" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Type.thy --- a/src/HOL/Bali/Type.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Type.thy Mon Jul 26 18:25:19 2010 +0200 @@ -36,8 +36,9 @@ abbreviation Array :: "ty \ ty" ("_.[]" [90] 90) where "T.[] == RefT (ArrayT T)" -definition the_Class :: "ty \ qtname" where - "the_Class T \ SOME C. T = Class C" (** primrec not possible here **) +definition + the_Class :: "ty \ qtname" + where "the_Class T = (SOME C. T = Class C)" (** primrec not possible here **) lemma the_Class_eq [simp]: "the_Class (Class C)= C" by (auto simp add: the_Class_def) diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/TypeRel.thy --- a/src/HOL/Bali/TypeRel.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/TypeRel.thy Mon Jul 26 18:25:19 2010 +0200 @@ -25,14 +25,17 @@ \end{itemize} *} -consts - (*subint1, in Decl.thy*) (* direct subinterface *) (*subint , by translation*) (* subinterface (+ identity) *) (*subcls1, in Decl.thy*) (* direct subclass *) (*subcls , by translation*) (* subclass *) (*subclseq, by translation*) (* subclass + identity *) - implmt1 :: "prog \ (qtname \ qtname) set" --{* direct implementation *} + +definition + implmt1 :: "prog \ (qtname \ qtname) set" --{* direct implementation *} + --{* direct implementation, cf. 8.1.3 *} + where "implmt1 G = {(C,I). C\Object \ (\c\class G C: I\set (superIfs c))}" + abbreviation subint1_syntax :: "prog => [qtname, qtname] => bool" ("_|-_<:I1_" [71,71,71] 70) @@ -325,16 +328,11 @@ section "implementation relation" -defs - --{* direct implementation, cf. 8.1.3 *} -implmt1_def:"implmt1 G\{(C,I). C\Object \ (\c\class G C: I\set (superIfs c))}" - lemma implmt1D: "G\C\1I \ C\Object \ (\c\class G C: I\set (superIfs c))" apply (unfold implmt1_def) apply auto done - inductive --{* implementation, cf. 8.1.4 *} implmt :: "prog \ qtname \ qtname \ bool" ("_\_\_" [71,71,71] 70) for G :: prog @@ -568,8 +566,9 @@ apply (fast dest: widen_Class_Class widen_Class_Iface) done -definition widens :: "prog \ [ty list, ty list] \ bool" ("_\_[\]_" [71,71,71] 70) where - "G\Ts[\]Ts' \ list_all2 (\T T'. G\T\T') Ts Ts'" +definition + widens :: "prog \ [ty list, ty list] \ bool" ("_\_[\]_" [71,71,71] 70) + where "G\Ts[\]Ts' = list_all2 (\T T'. G\T\T') Ts Ts'" lemma widens_Nil [simp]: "G\[][\][]" apply (unfold widens_def) diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/TypeSafe.thy --- a/src/HOL/Bali/TypeSafe.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/TypeSafe.thy Mon Jul 26 18:25:19 2010 +0200 @@ -93,23 +93,27 @@ section "result conformance" -definition assign_conforms :: "st \ (val \ state \ state) \ ty \ env' \ bool" ("_\|_\_\\_" [71,71,71,71] 70) where -"s\|f\T\\E \ - (\s' w. Norm s'\\E \ fst E,s'\w\\T \ s\|s' \ assign f w (Norm s')\\E) \ - (\s' w. error_free s' \ (error_free (assign f w s')))" +definition + assign_conforms :: "st \ (val \ state \ state) \ ty \ env' \ bool" ("_\|_\_\\_" [71,71,71,71] 70) +where + "s\|f\T\\E = + ((\s' w. Norm s'\\E \ fst E,s'\w\\T \ s\|s' \ assign f w (Norm s')\\E) \ + (\s' w. error_free s' \ (error_free (assign f w s'))))" -definition rconf :: "prog \ lenv \ st \ term \ vals \ tys \ bool" ("_,_,_\_\_\\_" [71,71,71,71,71,71] 70) where - "G,L,s\t\v\\T - \ case T of - Inl T \ if (\ var. t=In2 var) - then (\ n. (the_In2 t) = LVar n - \ (fst (the_In2 v) = the (locals s n)) \ - (locals s n \ None \ G,s\fst (the_In2 v)\\T)) \ - (\ (\ n. the_In2 t=LVar n) \ (G,s\fst (the_In2 v)\\T))\ - (s\|snd (the_In2 v)\T\\(G,L)) - else G,s\the_In1 v\\T - | Inr Ts \ list_all2 (conf G s) (the_In3 v) Ts" +definition + rconf :: "prog \ lenv \ st \ term \ vals \ tys \ bool" ("_,_,_\_\_\\_" [71,71,71,71,71,71] 70) +where + "G,L,s\t\v\\T = + (case T of + Inl T \ if (\ var. t=In2 var) + then (\ n. (the_In2 t) = LVar n + \ (fst (the_In2 v) = the (locals s n)) \ + (locals s n \ None \ G,s\fst (the_In2 v)\\T)) \ + (\ (\ n. the_In2 t=LVar n) \ (G,s\fst (the_In2 v)\\T))\ + (s\|snd (the_In2 v)\T\\(G,L)) + else G,s\the_In1 v\\T + | Inr Ts \ list_all2 (conf G s) (the_In3 v) Ts)" text {* With @{term rconf} we describe the conformance of the result value of a term. @@ -324,9 +328,11 @@ declare fun_upd_apply [simp del] -definition DynT_prop :: "[prog,inv_mode,qtname,ref_ty] \ bool" ("_\_\_\_"[71,71,71,71]70) where - "G\mode\D\t \ mode = IntVir \ is_class G D \ - (if (\T. t=ArrayT T) then D=Object else G\Class D\RefT t)" +definition + DynT_prop :: "[prog,inv_mode,qtname,ref_ty] \ bool" ("_\_\_\_"[71,71,71,71]70) +where + "G\mode\D\t = (mode = IntVir \ is_class G D \ + (if (\T. t=ArrayT T) then D=Object else G\Class D\RefT t))" lemma DynT_propI: "\(x,s)\\(G, L); G,s\a'\\RefT statT; wf_prog G; mode = IntVir \ a' \ Null\ diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/Value.thy --- a/src/HOL/Bali/Value.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/Value.thy Mon Jul 26 18:25:19 2010 +0200 @@ -17,29 +17,34 @@ | Addr loc --{* addresses, i.e. locations of objects *} -consts the_Bool :: "val \ bool" -primrec "the_Bool (Bool b) = b" -consts the_Intg :: "val \ int" -primrec "the_Intg (Intg i) = i" -consts the_Addr :: "val \ loc" -primrec "the_Addr (Addr a) = a" +primrec the_Bool :: "val \ bool" + where "the_Bool (Bool b) = b" + +primrec the_Intg :: "val \ int" + where "the_Intg (Intg i) = i" + +primrec the_Addr :: "val \ loc" + where "the_Addr (Addr a) = a" types dyn_ty = "loc \ ty option" -consts - typeof :: "dyn_ty \ val \ ty option" - defpval :: "prim_ty \ val" --{* default value for primitive types *} - default_val :: " ty \ val" --{* default value for all types *} + +primrec typeof :: "dyn_ty \ val \ ty option" +where + "typeof dt Unit = Some (PrimT Void)" +| "typeof dt (Bool b) = Some (PrimT Boolean)" +| "typeof dt (Intg i) = Some (PrimT Integer)" +| "typeof dt Null = Some NT" +| "typeof dt (Addr a) = dt a" -primrec "typeof dt Unit = Some (PrimT Void)" - "typeof dt (Bool b) = Some (PrimT Boolean)" - "typeof dt (Intg i) = Some (PrimT Integer)" - "typeof dt Null = Some NT" - "typeof dt (Addr a) = dt a" +primrec defpval :: "prim_ty \ val" --{* default value for primitive types *} +where + "defpval Void = Unit" +| "defpval Boolean = Bool False" +| "defpval Integer = Intg 0" -primrec "defpval Void = Unit" - "defpval Boolean = Bool False" - "defpval Integer = Intg 0" -primrec "default_val (PrimT pt) = defpval pt" - "default_val (RefT r ) = Null" +primrec default_val :: "ty \ val" --{* default value for all types *} +where + "default_val (PrimT pt) = defpval pt" +| "default_val (RefT r ) = Null" end diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/WellForm.thy --- a/src/HOL/Bali/WellForm.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/WellForm.thy Mon Jul 26 18:25:19 2010 +0200 @@ -31,8 +31,9 @@ text {* well-formed field declaration (common part for classes and interfaces), cf. 8.3 and (9.3) *} -definition wf_fdecl :: "prog \ pname \ fdecl \ bool" where - "wf_fdecl G P \ \(fn,f). is_acc_type G P (type f)" +definition + wf_fdecl :: "prog \ pname \ fdecl \ bool" + where "wf_fdecl G P = (\(fn,f). is_acc_type G P (type f))" lemma wf_fdecl_def2: "\fd. wf_fdecl G P fd = is_acc_type G P (type (snd fd))" apply (unfold wf_fdecl_def) @@ -54,11 +55,12 @@ \item the parameter names are unique \end{itemize} *} -definition wf_mhead :: "prog \ pname \ sig \ mhead \ bool" where - "wf_mhead G P \ \ sig mh. length (parTs sig) = length (pars mh) \ +definition + wf_mhead :: "prog \ pname \ sig \ mhead \ bool" where + "wf_mhead G P = (\ sig mh. length (parTs sig) = length (pars mh) \ \ ( \T\set (parTs sig). is_acc_type G P T) \ is_acc_type G P (resTy mh) \ - \ distinct (pars mh)" + \ distinct (pars mh))" text {* @@ -76,23 +78,25 @@ \end{itemize} *} -definition callee_lcl :: "qtname \ sig \ methd \ lenv" where -"callee_lcl C sig m - \ \ k. (case k of +definition + callee_lcl :: "qtname \ sig \ methd \ lenv" where + "callee_lcl C sig m = + (\k. (case k of EName e \ (case e of VNam v \(table_of (lcls (mbody m))((pars m)[\](parTs sig))) v | Res \ Some (resTy m)) - | This \ if is_static m then None else Some (Class C))" + | This \ if is_static m then None else Some (Class C)))" -definition parameters :: "methd \ lname set" where -"parameters m \ set (map (EName \ VNam) (pars m)) - \ (if (static m) then {} else {This})" +definition + parameters :: "methd \ lname set" where + "parameters m = set (map (EName \ VNam) (pars m)) \ (if (static m) then {} else {This})" -definition wf_mdecl :: "prog \ qtname \ mdecl \ bool" where - "wf_mdecl G C \ - \(sig,m). +definition + wf_mdecl :: "prog \ qtname \ mdecl \ bool" where + "wf_mdecl G C = + (\(sig,m). wf_mhead G (pid C) sig (mhead m) \ unique (lcls (mbody m)) \ (\(vn,T)\set (lcls (mbody m)). is_acc_type G (pid C) T) \ @@ -102,7 +106,7 @@ \prg=G,cls=C,lcl=callee_lcl C sig m\\(stmt (mbody m))\\ \ (\ A. \prg=G,cls=C,lcl=callee_lcl C sig m\ \ parameters m \\stmt (mbody m)\\ A - \ Result \ nrm A)" + \ Result \ nrm A))" lemma callee_lcl_VNam_simp [simp]: "callee_lcl C sig m (EName (VNam v)) @@ -216,9 +220,10 @@ superinterfaces widens to each of the corresponding result types \end{itemize} *} -definition wf_idecl :: "prog \ idecl \ bool" where - "wf_idecl G \ - \(I,i). +definition + wf_idecl :: "prog \ idecl \ bool" where + "wf_idecl G = + (\(I,i). ws_idecl G I (isuperIfs i) \ \is_class G I \ (\(sig,mh)\set (imethods i). wf_mhead G (pid I) sig mh \ @@ -233,7 +238,7 @@ is_static new = is_static old)) \ (Option.set \ table_of (imethods i) hidings Un_tables((\J.(imethds G J))`set (isuperIfs i)) - entails (\new old. G\resTy new\resTy old))" + entails (\new old. G\resTy new\resTy old)))" lemma wf_idecl_mhead: "\wf_idecl G (I,i); (sig,mh)\set (imethods i)\ \ wf_mhead G (pid I) sig mh \ \is_static mh \ accmodi mh = Public" @@ -317,8 +322,9 @@ \end{itemize} *} (* to Table *) -definition entails :: "('a,'b) table \ ('b \ bool) \ bool" ("_ entails _" 20) where -"t entails P \ \k. \ x \ t k: P x" +definition + entails :: "('a,'b) table \ ('b \ bool) \ bool" ("_ entails _" 20) + where "(t entails P) = (\k. \ x \ t k: P x)" lemma entailsD: "\t entails P; t k = Some x\ \ P x" @@ -327,9 +333,10 @@ lemma empty_entails[simp]: "empty entails P" by (simp add: entails_def) -definition wf_cdecl :: "prog \ cdecl \ bool" where -"wf_cdecl G \ - \(C,c). +definition + wf_cdecl :: "prog \ cdecl \ bool" where + "wf_cdecl G = + (\(C,c). \is_iface G C \ (\I\set (superIfs c). is_acc_iface G (pid C) I \ (\s. \ im \ imethds G I s. @@ -352,7 +359,7 @@ (G,sig\new hides old \ (accmodi old \ accmodi new \ is_static old)))) - ))" + )))" (* definition wf_cdecl :: "prog \ cdecl \ bool" where @@ -511,13 +518,14 @@ \item all defined classes are wellformed \end{itemize} *} -definition wf_prog :: "prog \ bool" where - "wf_prog G \ let is = ifaces G; cs = classes G in +definition + wf_prog :: "prog \ bool" where + "wf_prog G = (let is = ifaces G; cs = classes G in ObjectC \ set cs \ (\ m\set Object_mdecls. accmodi m \ Package) \ (\xn. SXcptC xn \ set cs) \ (\i\set is. wf_idecl G i) \ unique is \ - (\c\set cs. wf_cdecl G c) \ unique cs" + (\c\set cs. wf_cdecl G c) \ unique cs)" lemma wf_prog_idecl: "\iface G I = Some i; wf_prog G\ \ wf_idecl G (I,i)" apply (unfold wf_prog_def Let_def) @@ -2095,16 +2103,16 @@ Class dynC Array Object *} -consts valid_lookup_cls:: "prog \ ref_ty \ qtname \ bool \ bool" +primrec valid_lookup_cls:: "prog \ ref_ty \ qtname \ bool \ bool" ("_,_ \ _ valid'_lookup'_cls'_for _" [61,61,61,61] 60) -primrec -"G,NullT \ dynC valid_lookup_cls_for static_membr = False" -"G,IfaceT I \ dynC valid_lookup_cls_for static_membr - = (if static_membr - then dynC=Object - else G\Class dynC\ Iface I)" -"G,ClassT C \ dynC valid_lookup_cls_for static_membr = G\Class dynC\ Class C" -"G,ArrayT T \ dynC valid_lookup_cls_for static_membr = (dynC=Object)" +where + "G,NullT \ dynC valid_lookup_cls_for static_membr = False" +| "G,IfaceT I \ dynC valid_lookup_cls_for static_membr + = (if static_membr + then dynC=Object + else G\Class dynC\ Iface I)" +| "G,ClassT C \ dynC valid_lookup_cls_for static_membr = G\Class dynC\ Class C" +| "G,ArrayT T \ dynC valid_lookup_cls_for static_membr = (dynC=Object)" lemma valid_lookup_cls_is_class: assumes dynC: "G,statT \ dynC valid_lookup_cls_for static_membr" and diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Bali/WellType.thy --- a/src/HOL/Bali/WellType.thy Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Bali/WellType.thy Mon Jul 26 18:25:19 2010 +0200 @@ -53,11 +53,13 @@ emhead = "ref_ty \ mhead" --{* Some mnemotic selectors for emhead *} -definition "declrefT" :: "emhead \ ref_ty" where - "declrefT \ fst" +definition + "declrefT" :: "emhead \ ref_ty" + where "declrefT = fst" -definition "mhd" :: "emhead \ mhead" where - "mhd \ snd" +definition + "mhd" :: "emhead \ mhead" + where "mhd \ snd" lemma declrefT_simp[simp]:"declrefT (r,m) = r" by (simp add: declrefT_def) @@ -77,50 +79,51 @@ lemma mhd_accmodi_simp [simp]: "accmodi (mhd m) = accmodi m" by (cases m) simp -consts - cmheads :: "prog \ qtname \ qtname \ sig \ emhead set" - Objectmheads :: "prog \ qtname \ sig \ emhead set" - accObjectmheads:: "prog \ qtname \ ref_ty \ sig \ emhead set" - mheads :: "prog \ qtname \ ref_ty \ sig \ emhead set" -defs - cmheads_def: -"cmheads G S C - \ \sig. (\(Cls,mthd). (ClassT Cls,(mhead mthd))) ` Option.set (accmethd G S C sig)" - Objectmheads_def: -"Objectmheads G S - \ \sig. (\(Cls,mthd). (ClassT Cls,(mhead mthd))) - ` Option.set (filter_tab (\sig m. accmodi m \ Private) (accmethd G S Object) sig)" - accObjectmheads_def: -"accObjectmheads G S T - \ if G\RefT T accessible_in (pid S) - then Objectmheads G S - else (\sig. {})" -primrec -"mheads G S NullT = (\sig. {})" -"mheads G S (IfaceT I) = (\sig. (\(I,h).(IfaceT I,h)) - ` accimethds G (pid S) I sig \ - accObjectmheads G S (IfaceT I) sig)" -"mheads G S (ClassT C) = cmheads G S C" -"mheads G S (ArrayT T) = accObjectmheads G S (ArrayT T)" +definition + cmheads :: "prog \ qtname \ qtname \ sig \ emhead set" + where "cmheads G S C = (\sig. (\(Cls,mthd). (ClassT Cls,(mhead mthd))) ` Option.set (accmethd G S C sig))" + +definition + Objectmheads :: "prog \ qtname \ sig \ emhead set" where + "Objectmheads G S = + (\sig. (\(Cls,mthd). (ClassT Cls,(mhead mthd))) + ` Option.set (filter_tab (\sig m. accmodi m \ Private) (accmethd G S Object) sig))" + +definition + accObjectmheads :: "prog \ qtname \ ref_ty \ sig \ emhead set" +where + "accObjectmheads G S T = + (if G\RefT T accessible_in (pid S) + then Objectmheads G S + else (\sig. {}))" + +primrec mheads :: "prog \ qtname \ ref_ty \ sig \ emhead set" +where + "mheads G S NullT = (\sig. {})" +| "mheads G S (IfaceT I) = (\sig. (\(I,h).(IfaceT I,h)) + ` accimethds G (pid S) I sig \ + accObjectmheads G S (IfaceT I) sig)" +| "mheads G S (ClassT C) = cmheads G S C" +| "mheads G S (ArrayT T) = accObjectmheads G S (ArrayT T)" definition --{* applicable methods, cf. 15.11.2.1 *} - appl_methds :: "prog \ qtname \ ref_ty \ sig \ (emhead \ ty list)\ set" where - "appl_methds G S rt = (\ sig. + appl_methds :: "prog \ qtname \ ref_ty \ sig \ (emhead \ ty list)\ set" where + "appl_methds G S rt = (\ sig. {(mh,pTs') |mh pTs'. mh \ mheads G S rt \name=name sig,parTs=pTs'\ \ G\(parTs sig)[\]pTs'})" definition --{* more specific methods, cf. 15.11.2.2 *} - more_spec :: "prog \ emhead \ ty list \ emhead \ ty list \ bool" where - "more_spec G = (\(mh,pTs). \(mh',pTs'). G\pTs[\]pTs')" + more_spec :: "prog \ emhead \ ty list \ emhead \ ty list \ bool" where + "more_spec G = (\(mh,pTs). \(mh',pTs'). G\pTs[\]pTs')" (*more_spec G \\((d,h),pTs). \((d',h'),pTs'). G\RefT d\RefT d'\G\pTs[\]pTs'*) definition --{* maximally specific methods, cf. 15.11.2.2 *} - max_spec :: "prog \ qtname \ ref_ty \ sig \ (emhead \ ty list)\ set" where - "max_spec G S rt sig = {m. m \appl_methds G S rt sig \ - (\m'\appl_methds G S rt sig. more_spec G m' m \ m'=m)}" + max_spec :: "prog \ qtname \ ref_ty \ sig \ (emhead \ ty list)\ set" where + "max_spec G S rt sig = {m. m \appl_methds G S rt sig \ + (\m'\appl_methds G S rt sig. more_spec G m' m \ m'=m)}" lemma max_spec2appl_meths: @@ -138,13 +141,15 @@ done -definition empty_dt :: "dyn_ty" where - "empty_dt \ \a. None" +definition + empty_dt :: "dyn_ty" + where "empty_dt = (\a. None)" -definition invmode :: "('a::type)member_scheme \ expr \ inv_mode" where -"invmode m e \ if is_static m +definition + invmode :: "('a::type)member_scheme \ expr \ inv_mode" where + "invmode m e = (if is_static m then Static - else if e=Super then SuperM else IntVir" + else if e=Super then SuperM else IntVir)" lemma invmode_nonstatic [simp]: "invmode \access=a,static=False,\=x\ (Acc (LVar e)) = IntVir" @@ -171,71 +176,71 @@ section "Typing for unary operations" -consts unop_type :: "unop \ prim_ty" -primrec -"unop_type UPlus = Integer" -"unop_type UMinus = Integer" -"unop_type UBitNot = Integer" -"unop_type UNot = Boolean" +primrec unop_type :: "unop \ prim_ty" +where + "unop_type UPlus = Integer" +| "unop_type UMinus = Integer" +| "unop_type UBitNot = Integer" +| "unop_type UNot = Boolean" -consts wt_unop :: "unop \ ty \ bool" -primrec -"wt_unop UPlus t = (t = PrimT Integer)" -"wt_unop UMinus t = (t = PrimT Integer)" -"wt_unop UBitNot t = (t = PrimT Integer)" -"wt_unop UNot t = (t = PrimT Boolean)" +primrec wt_unop :: "unop \ ty \ bool" +where + "wt_unop UPlus t = (t = PrimT Integer)" +| "wt_unop UMinus t = (t = PrimT Integer)" +| "wt_unop UBitNot t = (t = PrimT Integer)" +| "wt_unop UNot t = (t = PrimT Boolean)" section "Typing for binary operations" -consts binop_type :: "binop \ prim_ty" -primrec -"binop_type Mul = Integer" -"binop_type Div = Integer" -"binop_type Mod = Integer" -"binop_type Plus = Integer" -"binop_type Minus = Integer" -"binop_type LShift = Integer" -"binop_type RShift = Integer" -"binop_type RShiftU = Integer" -"binop_type Less = Boolean" -"binop_type Le = Boolean" -"binop_type Greater = Boolean" -"binop_type Ge = Boolean" -"binop_type Eq = Boolean" -"binop_type Neq = Boolean" -"binop_type BitAnd = Integer" -"binop_type And = Boolean" -"binop_type BitXor = Integer" -"binop_type Xor = Boolean" -"binop_type BitOr = Integer" -"binop_type Or = Boolean" -"binop_type CondAnd = Boolean" -"binop_type CondOr = Boolean" +primrec binop_type :: "binop \ prim_ty" +where + "binop_type Mul = Integer" +| "binop_type Div = Integer" +| "binop_type Mod = Integer" +| "binop_type Plus = Integer" +| "binop_type Minus = Integer" +| "binop_type LShift = Integer" +| "binop_type RShift = Integer" +| "binop_type RShiftU = Integer" +| "binop_type Less = Boolean" +| "binop_type Le = Boolean" +| "binop_type Greater = Boolean" +| "binop_type Ge = Boolean" +| "binop_type Eq = Boolean" +| "binop_type Neq = Boolean" +| "binop_type BitAnd = Integer" +| "binop_type And = Boolean" +| "binop_type BitXor = Integer" +| "binop_type Xor = Boolean" +| "binop_type BitOr = Integer" +| "binop_type Or = Boolean" +| "binop_type CondAnd = Boolean" +| "binop_type CondOr = Boolean" -consts wt_binop :: "prog \ binop \ ty \ ty \ bool" -primrec -"wt_binop G Mul t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Div t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Mod t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Plus t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Minus t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G LShift t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G RShift t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G RShiftU t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Less t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Le t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Greater t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Ge t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Eq t1 t2 = (G\t1\t2 \ G\t2\t1)" -"wt_binop G Neq t1 t2 = (G\t1\t2 \ G\t2\t1)" -"wt_binop G BitAnd t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G And t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" -"wt_binop G BitXor t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Xor t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" -"wt_binop G BitOr t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" -"wt_binop G Or t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" -"wt_binop G CondAnd t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" -"wt_binop G CondOr t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" +primrec wt_binop :: "prog \ binop \ ty \ ty \ bool" +where + "wt_binop G Mul t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Div t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Mod t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Plus t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Minus t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G LShift t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G RShift t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G RShiftU t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Less t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Le t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Greater t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Ge t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Eq t1 t2 = (G\t1\t2 \ G\t2\t1)" +| "wt_binop G Neq t1 t2 = (G\t1\t2 \ G\t2\t1)" +| "wt_binop G BitAnd t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G And t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" +| "wt_binop G BitXor t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Xor t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" +| "wt_binop G BitOr t1 t2 = ((t1 = PrimT Integer) \ (t2 = PrimT Integer))" +| "wt_binop G Or t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" +| "wt_binop G CondAnd t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" +| "wt_binop G CondOr t1 t2 = ((t1 = PrimT Boolean) \ (t2 = PrimT Boolean))" section "Typing for terms" @@ -244,9 +249,8 @@ (type) "tys" <= (type) "ty + ty list" -inductive - wt :: "env \ dyn_ty \ [term,tys] \ bool" ("_,_\_\_" [51,51,51,51] 50) - and wt_stmt :: "env \ dyn_ty \ stmt \ bool" ("_,_\_\\" [51,51,51 ] 50) +inductive wt :: "env \ dyn_ty \ [term,tys] \ bool" ("_,_\_\_" [51,51,51,51] 50) + and wt_stmt :: "env \ dyn_ty \ stmt \ bool" ("_,_\_\\" [51,51,51] 50) and ty_expr :: "env \ dyn_ty \ [expr ,ty ] \ bool" ("_,_\_\-_" [51,51,51,51] 50) and ty_var :: "env \ dyn_ty \ [var ,ty ] \ bool" ("_,_\_\=_" [51,51,51,51] 50) and ty_exprs :: "env \ dyn_ty \ [expr list, ty list] \ bool" diff -r d9549f9da779 -r a79abb22ca9c src/HOL/Tools/inductive.ML --- a/src/HOL/Tools/inductive.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/HOL/Tools/inductive.ML Mon Jul 26 18:25:19 2010 +0200 @@ -522,9 +522,9 @@ fun gen_inductive_cases prep_att prep_prop args lthy = let val thy = ProofContext.theory_of lthy; - val facts = args |> map (fn ((a, atts), props) => + val facts = args |> Par_List.map (fn ((a, atts), props) => ((a, map (prep_att thy) atts), - map (Thm.no_attributes o single o mk_cases lthy o prep_prop lthy) props)); + Par_List.map (Thm.no_attributes o single o mk_cases lthy o prep_prop lthy) props)); in lthy |> Local_Theory.notes facts |>> map snd end; val inductive_cases = gen_inductive_cases Attrib.intern_src Syntax.read_prop; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/isar_cmd.ML --- a/src/Pure/Isar/isar_cmd.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/isar_cmd.ML Mon Jul 26 18:25:19 2010 +0200 @@ -274,10 +274,8 @@ (* init and exit *) fun init_theory (name, imports, uses) = - Toplevel.init_theory name (Thy_Info.begin_theory name imports (map (apfst Path.explode) uses)) - (fn thy => - if Thy_Info.check_known_thy (Context.theory_name thy) - then Thy_Info.end_theory thy else ()); + Toplevel.init_theory name + (Thy_Info.begin_theory name imports (map (apfst Path.explode) uses)); val exit = Toplevel.keep (fn state => (Context.set_thread_data (try Toplevel.generic_theory_of state); diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/isar_document.ML --- a/src/Pure/Isar/isar_document.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/isar_document.ML Mon Jul 26 18:25:19 2010 +0200 @@ -181,7 +181,7 @@ fun begin_document (id: document_id) path = let - val (dir, name) = Thy_Load.split_thy_path path; + val (dir, name) = Thy_Header.split_thy_path path; val _ = define_document id (make_document dir name no_entries); in () end; @@ -192,13 +192,10 @@ val end_state = the_state (the (#state (#3 (the (first_entry (fn (_, {next, ...}) => is_none next) document))))); - val _ = (* FIXME regular execution (??) *) + val _ = (* FIXME regular execution (??), result (??) *) Future.fork (fn () => (case Lazy.force end_state of - SOME st => - (Toplevel.run_command name (Toplevel.put_id id (Toplevel.commit_exit Position.none)) st; - Thy_Info.touch_child_thys name; - Thy_Info.register_thy name) + SOME st => Toplevel.end_theory (Position.id_only id) st | NONE => error ("Failed to finish theory " ^ quote name))); in () end); diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/isar_syn.ML --- a/src/Pure/Isar/isar_syn.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/isar_syn.ML Mon Jul 26 18:25:19 2010 +0200 @@ -304,30 +304,23 @@ (* use ML text *) -fun propagate_env (context as Context.Proof lthy) = - Context.Proof (Local_Theory.map_contexts (ML_Env.inherit context) lthy) - | propagate_env context = context; - -fun propagate_env_prf prf = Proof.map_contexts - (Context.proof_map (ML_Env.inherit (Context.Proof (Proof.context_of prf)))) prf; - val _ = Outer_Syntax.command "use" "ML text from file" (Keyword.tag_ml Keyword.thy_decl) - (Parse.path >> - (fn path => Toplevel.generic_theory (Thy_Info.exec_file path #> propagate_env))); + (Parse.path >> (fn path => Toplevel.generic_theory (Thy_Load.exec_ml path))); val _ = Outer_Syntax.command "ML" "ML text within theory or local theory" (Keyword.tag_ml Keyword.thy_decl) (Parse.ML_source >> (fn (txt, pos) => Toplevel.generic_theory - (ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #> propagate_env))); + (ML_Context.exec (fn () => ML_Context.eval_text true pos txt) #> + Local_Theory.propagate_ml_env))); val _ = Outer_Syntax.command "ML_prf" "ML text within proof" (Keyword.tag_proof Keyword.prf_decl) (Parse.ML_source >> (fn (txt, pos) => Toplevel.proof (Proof.map_context (Context.proof_map - (ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> propagate_env_prf))); + (ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> Proof.propagate_ml_env))); val _ = Outer_Syntax.command "ML_val" "diagnostic ML text" (Keyword.tag_ml Keyword.diag) diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/local_theory.ML --- a/src/Pure/Isar/local_theory.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/local_theory.ML Mon Jul 26 18:25:19 2010 +0200 @@ -5,6 +5,7 @@ *) type local_theory = Proof.context; +type generic_theory = Context.generic; signature LOCAL_THEORY = sig @@ -25,6 +26,7 @@ val target_result: (Proof.context -> 'a * Proof.context) -> local_theory -> 'a * local_theory val target: (Proof.context -> Proof.context) -> local_theory -> local_theory val map_contexts: (Context.generic -> Context.generic) -> local_theory -> local_theory + val propagate_ml_env: generic_theory -> generic_theory val standard_morphism: local_theory -> Proof.context -> morphism val target_morphism: local_theory -> morphism val global_morphism: local_theory -> morphism @@ -173,6 +175,10 @@ target (Context.proof_map f) #> Context.proof_map f; +fun propagate_ml_env (context as Context.Proof lthy) = + Context.Proof (map_contexts (ML_Env.inherit context) lthy) + | propagate_ml_env context = context; + (* morphisms *) diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/outer_syntax.ML --- a/src/Pure/Isar/outer_syntax.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/outer_syntax.ML Mon Jul 26 18:25:19 2010 +0200 @@ -31,7 +31,7 @@ type isar val isar: bool -> isar val prepare_command: Position.T -> string -> Toplevel.transition - val load_thy: string -> Position.T -> string -> unit -> unit + val load_thy: string -> Position.T -> string -> (unit -> unit) * theory end; structure Outer_Syntax: OUTER_SYNTAX = @@ -204,7 +204,7 @@ fun process_file path thy = let val trs = parse (Path.position path) (File.read path); - val init = Toplevel.init_theory "" (K thy) (K ()) Toplevel.empty; + val init = Toplevel.init_theory "" (K thy) Toplevel.empty; val result = fold Toplevel.command (init :: trs) Toplevel.toplevel; in (case (Toplevel.is_theory result, Toplevel.generic_theory_of result) of @@ -285,14 +285,14 @@ (fn () => HTML.html_mode (implode o map Thy_Syntax.present_span) spans); val _ = if time then writeln ("\n**** Starting theory " ^ quote name ^ " ****") else (); - val results = cond_timeit time "" (fn () => Toplevel.excursion units); + val (results, thy) = cond_timeit time "" (fn () => Toplevel.excursion units); val _ = if time then writeln ("**** Finished theory " ^ quote name ^ " ****\n") else (); fun after_load () = Thy_Output.present_thy (#1 lexs) Keyword.command_tags is_markup (Lazy.force results) toks |> Buffer.content |> Present.theory_output name; - in after_load end; + in (after_load, thy) end; end; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/proof.ML --- a/src/Pure/Isar/proof.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/proof.ML Mon Jul 26 18:25:19 2010 +0200 @@ -17,6 +17,7 @@ val theory_of: state -> theory val map_context: (context -> context) -> state -> state val map_contexts: (context -> context) -> state -> state + val propagate_ml_env: state -> state val bind_terms: (indexname * term option) list -> state -> state val put_thms: bool -> string * thm list option -> state -> state val the_facts: state -> thm list @@ -207,6 +208,9 @@ fun map_contexts f = map_all (fn (ctxt, facts, mode, goal) => (f ctxt, facts, mode, goal)); +fun propagate_ml_env state = map_contexts + (Context.proof_map (ML_Env.inherit (Context.Proof (context_of state)))) state; + val bind_terms = map_context o ProofContext.bind_terms; val put_thms = map_context oo ProofContext.put_thms; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Isar/toplevel.ML --- a/src/Pure/Isar/toplevel.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Isar/toplevel.ML Mon Jul 26 18:25:19 2010 +0200 @@ -7,7 +7,6 @@ signature TOPLEVEL = sig exception UNDEF - type generic_theory type state val toplevel: state val is_toplevel: state -> bool @@ -22,6 +21,7 @@ val proof_of: state -> Proof.state val proof_position_of: state -> int val enter_proof_body: state -> Proof.state + val end_theory: Position.T -> state -> theory val print_state_context: state -> unit val print_state: bool -> state -> unit val pretty_abstract: state -> Pretty.T @@ -46,7 +46,7 @@ val interactive: bool -> transition -> transition val print: transition -> transition val no_timing: transition -> transition - val init_theory: string -> (bool -> theory) -> (theory -> unit) -> transition -> transition + val init_theory: string -> (bool -> theory) -> transition -> transition val exit: transition -> transition val keep: (state -> unit) -> transition -> transition val keep': (bool -> state -> unit) -> transition -> transition @@ -88,9 +88,8 @@ val add_hook: (transition -> state -> state -> unit) -> unit val transition: bool -> transition -> state -> (state * (exn * string) option) option val run_command: string -> transition -> state -> state option - val commit_exit: Position.T -> transition val command: transition -> state -> state - val excursion: (transition * transition list) list -> (transition * state) list lazy + val excursion: (transition * transition list) list -> (transition * state) list lazy * theory end; structure Toplevel: TOPLEVEL = @@ -103,8 +102,6 @@ (* local theory wrappers *) -type generic_theory = Context.generic; (*theory or local_theory*) - val loc_init = Theory_Target.context_cmd; val loc_exit = Local_Theory.exit_global; @@ -140,8 +137,7 @@ (* datatype state *) -type node_info = node * (theory -> unit); (*node with exit operation*) -datatype state = State of node_info option * node_info option; (*current, previous*) +datatype state = State of node option * node option; (*current, previous*) val toplevel = State (NONE, NONE); @@ -149,21 +145,21 @@ | is_toplevel _ = false; fun level (State (NONE, _)) = 0 - | level (State (SOME (Theory _, _), _)) = 0 - | level (State (SOME (Proof (prf, _), _), _)) = Proof.level (Proof_Node.current prf) - | level (State (SOME (SkipProof (d, _), _), _)) = d + 1; (*different notion of proof depth!*) + | level (State (SOME (Theory _), _)) = 0 + | level (State (SOME (Proof (prf, _)), _)) = Proof.level (Proof_Node.current prf) + | level (State (SOME (SkipProof (d, _)), _)) = d + 1; (*different notion of proof depth!*) fun str_of_state (State (NONE, _)) = "at top level" - | str_of_state (State (SOME (Theory (Context.Theory _, _), _), _)) = "in theory mode" - | str_of_state (State (SOME (Theory (Context.Proof _, _), _), _)) = "in local theory mode" - | str_of_state (State (SOME (Proof _, _), _)) = "in proof mode" - | str_of_state (State (SOME (SkipProof _, _), _)) = "in skipped proof mode"; + | str_of_state (State (SOME (Theory (Context.Theory _, _)), _)) = "in theory mode" + | str_of_state (State (SOME (Theory (Context.Proof _, _)), _)) = "in local theory mode" + | str_of_state (State (SOME (Proof _), _)) = "in proof mode" + | str_of_state (State (SOME (SkipProof _), _)) = "in skipped proof mode"; (* current node *) fun node_of (State (NONE, _)) = raise UNDEF - | node_of (State (SOME (node, _), _)) = node; + | node_of (State (SOME node, _)) = node; fun is_theory state = not (is_toplevel state) andalso is_some (theory_node (node_of state)); fun is_proof state = not (is_toplevel state) andalso is_some (proof_node (node_of state)); @@ -177,7 +173,7 @@ | NONE => raise UNDEF); fun previous_context_of (State (_, NONE)) = NONE - | previous_context_of (State (_, SOME (prev, _))) = SOME (context_node prev); + | previous_context_of (State (_, SOME prev)) = SOME (context_node prev); val context_of = node_case Context.proof_of Proof.context_of; val generic_theory_of = node_case I (Context.Proof o Proof.context_of); @@ -191,6 +187,9 @@ val enter_proof_body = node_case (Proof.init o Context.proof_of) Proof.enter_forward; +fun end_theory _ (State (NONE, SOME (Theory (Context.Theory thy, _)))) = Theory.end_theory thy + | end_theory pos _ = error ("Unfinished theory at end of input" ^ Position.str_of pos); + (* print state *) @@ -267,12 +266,12 @@ in -fun apply_transaction f g (node, exit) = +fun apply_transaction f g node = let val _ = is_draft_theory node andalso error "Illegal draft theory in toplevel state"; val cont_node = reset_presentation node; val back_node = map_theory (Theory.checkpoint o Theory.copy) cont_node; - fun state_error e nd = (State (SOME (nd, exit), SOME (node, exit)), e); + fun state_error e nd = (State (SOME nd, SOME node), e); val (result, err) = cont_node @@ -296,21 +295,18 @@ (* primitive transitions *) datatype trans = - Init of string * (bool -> theory) * (theory -> unit) | (*theory name, init, exit*) - Exit | (*formal exit of theory -- without committing*) - CommitExit | (*exit and commit final theory*) - Keep of bool -> state -> unit | (*peek at state*) + Init of string * (bool -> theory) | (*theory name, init*) + Exit | (*formal exit of theory*) + Keep of bool -> state -> unit | (*peek at state*) Transaction of (bool -> node -> node) * (state -> unit); (*node transaction and presentation*) local -fun apply_tr int (Init (_, f, exit)) (State (NONE, _)) = +fun apply_tr int (Init (_, f)) (State (NONE, _)) = State (SOME (Theory (Context.Theory - (Theory.checkpoint (Runtime.controlled_execution f int)), NONE), exit), NONE) - | apply_tr _ Exit (State (prev as SOME (Theory (Context.Theory _, _), _), _)) = + (Theory.checkpoint (Runtime.controlled_execution f int)), NONE)), NONE) + | apply_tr _ Exit (State (prev as SOME (Theory (Context.Theory _, _)), _)) = State (NONE, prev) - | apply_tr _ CommitExit (State (NONE, SOME (Theory (Context.Theory thy, _), exit))) = - (Runtime.controlled_execution exit thy; toplevel) | apply_tr int (Keep f) state = Runtime.controlled_execution (fn x => tap (f int) x) state | apply_tr int (Transaction (f, g)) (State (SOME state, _)) = @@ -355,7 +351,7 @@ (* diagnostics *) -fun init_of (Transition {trans = [Init (name, _, _)], ...}) = SOME name +fun init_of (Transition {trans = [Init (name, _)], ...}) = SOME name | init_of _ = NONE; fun name_of (Transition {name, ...}) = name; @@ -397,7 +393,7 @@ (* basic transitions *) -fun init_theory name f exit = add_trans (Init (name, f, exit)); +fun init_theory name f = add_trans (Init (name, f)); val exit = add_trans Exit; val keep' = add_trans o Keep; @@ -632,7 +628,7 @@ fun run_command thy_name tr st = (case (case init_of tr of - SOME name => Exn.capture (fn () => Thy_Load.consistent_name thy_name name) () + SOME name => Exn.capture (fn () => Thy_Header.consistent_name thy_name name) () | NONE => Exn.Result ()) of Exn.Result () => let val int = is_some (init_of tr) in @@ -646,15 +642,6 @@ | Exn.Exn exn => (error_msg tr (exn, at_command tr); status tr Markup.failed; NONE)); -(* commit final exit *) - -fun commit_exit pos = - name "end" empty - |> position pos - |> add_trans CommitExit - |> imperative (fn () => warning "Expected to find finished theory"); - - (* nested commands *) fun command tr st = @@ -696,8 +683,8 @@ (fn prf => Future.fork_pri ~1 (fn () => let val (states, result_state) = - (case st' of State (SOME (Proof (_, (_, orig_gthy)), exit), prev) - => State (SOME (Proof (Proof_Node.init prf, (finish, orig_gthy)), exit), prev)) + (case st' of State (SOME (Proof (_, (_, orig_gthy))), prev) + => State (SOME (Proof (Proof_Node.init prf, (finish, orig_gthy))), prev)) |> fold_map command_result body_trs ||> command (end_tr |> set_print false); in (states, presentation_context_of result_state) end)) @@ -718,14 +705,9 @@ fun excursion input = let val end_pos = if null input then error "No input" else pos_of (fst (List.last input)); - val immediate = not (Goal.future_enabled ()); val (results, end_state) = fold_map (proof_result immediate) input toplevel; - val _ = - (case end_state of - State (NONE, SOME (Theory (Context.Theory _, _), _)) => - command (commit_exit end_pos) end_state - | _ => error "Unfinished development at end of input"); - in Lazy.lazy (fn () => maps Lazy.force results) end; + val thy = end_theory end_pos end_state; + in (Lazy.lazy (fn () => maps Lazy.force results), thy) end; end; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/ProofGeneral/proof_general_emacs.ML --- a/src/Pure/ProofGeneral/proof_general_emacs.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/ProofGeneral/proof_general_emacs.ML Mon Jul 26 18:25:19 2010 +0200 @@ -137,12 +137,11 @@ val name = thy_name file; val _ = name = "" andalso error ("Bad file name: " ^ quote file); val _ = - if Thy_Info.check_known_thy name then - (Isar.>> (Toplevel.commit_exit Position.none); - Thy_Info.touch_child_thys name; Thy_Info.register_thy name) + if Thy_Info.known_thy name then + Thy_Info.register_thy (Toplevel.end_theory Position.none (Isar.state ())) handle ERROR msg => (warning (cat_lines ["Failed to register theory: " ^ quote name, msg]); - tell_file_retracted (Thy_Load.thy_path name)) + tell_file_retracted (Thy_Header.thy_path name)) else (); val _ = Isar.init (); in () end; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/ProofGeneral/proof_general_pgip.ML --- a/src/Pure/ProofGeneral/proof_general_pgip.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/ProofGeneral/proof_general_pgip.ML Mon Jul 26 18:25:19 2010 +0200 @@ -218,15 +218,14 @@ val thy_name = Path.implode o #1 o Path.split_ext o Path.base; val inform_file_retracted = Thy_Info.if_known_thy Thy_Info.remove_thy o thy_name; -val inform_file_processed = Thy_Info.if_known_thy Thy_Info.touch_child_thys o thy_name; -fun proper_inform_file_processed path state = +fun inform_file_processed path state = let val name = thy_name path in if Toplevel.is_toplevel state andalso Thy_Info.known_thy name then - (Thy_Info.touch_child_thys name; - Thy_Info.register_thy name handle ERROR msg => - (warning (cat_lines [msg, "Failed to register theory: " ^ quote name]); - tell_file_retracted true (Path.base path))) + Thy_Info.register_thy (Toplevel.end_theory Position.none state) + handle ERROR msg => + (warning (cat_lines [msg, "Failed to register theory: " ^ quote name]); + tell_file_retracted true (Path.base path)) else raise Toplevel.UNDEF end; @@ -819,7 +818,7 @@ fun closefile _ = case !currently_open_file of - SOME f => (proper_inform_file_processed f (Isar.state()); + SOME f => (inform_file_processed f (Isar.state ()); priority ("Finished working in file: " ^ PgipTypes.string_of_pgipurl f); currently_open_file := NONE) | NONE => raise PGIP (" when no file is open!") diff -r d9549f9da779 -r a79abb22ca9c src/Pure/ROOT.ML --- a/src/Pure/ROOT.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/ROOT.ML Mon Jul 26 18:25:19 2010 +0200 @@ -184,10 +184,8 @@ (*theory sources*) use "Thy/thy_header.ML"; -use "Thy/thy_load.ML"; use "Thy/html.ML"; use "Thy/latex.ML"; -use "Thy/present.ML"; (*basic proof engine*) use "Isar/proof_display.ML"; @@ -227,10 +225,12 @@ use "Isar/constdefs.ML"; (*toplevel transactions*) +use "Thy/thy_load.ML"; use "Isar/proof_node.ML"; use "Isar/toplevel.ML"; (*theory syntax*) +use "Thy/present.ML"; use "Thy/term_style.ML"; use "Thy/thy_output.ML"; use "Thy/thy_syntax.ML"; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Thy/thy_header.ML --- a/src/Pure/Thy/thy_header.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Thy/thy_header.ML Mon Jul 26 18:25:19 2010 +0200 @@ -8,6 +8,9 @@ sig val args: Token.T list -> (string * string list * (string * bool) list) * Token.T list val read: Position.T -> (string, 'a) Source.source -> string * string list * (string * bool) list + val thy_path: string -> Path.T + val split_thy_path: Path.T -> Path.T * string + val consistent_name: string -> string -> unit end; structure Thy_Header: THY_HEADER = @@ -63,4 +66,19 @@ | NONE => error ("Unexpected end of input" ^ Position.str_of pos)) end; + +(* file formats *) + +val thy_path = Path.ext "thy" o Path.basic; + +fun split_thy_path path = + (case Path.split_ext path of + (path', "thy") => (Path.dir path', Path.implode (Path.base path')) + | _ => error ("Bad theory file specification " ^ Path.implode path)); + +fun consistent_name name name' = + if name = name' then () + else error ("Filename " ^ quote (Path.implode (thy_path name)) ^ + " does not agree with theory name " ^ quote name'); + end; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Thy/thy_info.ML --- a/src/Pure/Thy/thy_info.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Thy/thy_info.ML Mon Jul 26 18:25:19 2010 +0200 @@ -11,7 +11,6 @@ val add_hook: (action -> string -> unit) -> unit val get_names: unit -> string list val known_thy: string -> bool - val check_known_thy: string -> bool val if_known_thy: (string -> unit) -> string -> unit val lookup_theory: string -> theory option val get_theory: string -> theory @@ -19,20 +18,13 @@ val master_directory: string -> Path.T val loaded_files: string -> Path.T list val touch_thy: string -> unit - val touch_child_thys: string -> unit val thy_ord: theory * theory -> order val remove_thy: string -> unit val kill_thy: string -> unit - val provide_file: Path.T -> string -> unit - val load_file: Path.T -> unit - val exec_file: Path.T -> Context.generic -> Context.generic - val use: string -> unit val use_thys: string list -> unit val use_thy: string -> unit val begin_theory: string -> string list -> (Path.T * bool) list -> bool -> theory - val end_theory: theory -> unit - val register_thy: string -> unit - val register_theory: theory -> unit + val register_thy: theory -> unit val finish: unit -> unit end; @@ -80,18 +72,15 @@ (* thy database *) type deps = - {update_time: int, (*symbolic time of update; negative value means outdated*) - master: (Path.T * File.ident) option, (*master dependencies for thy file*) - text: string, (*source text for thy*) - parents: string list, (*source specification of parents (partially qualified)*) - (*auxiliary files: source path, physical path + identifier*) - files: (Path.T * (Path.T * File.ident) option) list}; + {update_time: int, (*symbolic time of update; negative value means outdated*) + master: (Path.T * File.ident) option, (*master dependencies for thy file*) + text: string, (*source text for thy*) + parents: string list}; (*source specification of parents (partially qualified)*) -fun make_deps update_time master text parents files : deps = - {update_time = update_time, master = master, text = text, parents = parents, files = files}; +fun make_deps update_time master text parents : deps = + {update_time = update_time, master = master, text = text, parents = parents}; -fun init_deps master text parents files = - SOME (make_deps ~1 master text parents (map (rpair NONE) files)); +fun init_deps master text parents = SOME (make_deps ~1 master text parents); fun master_dir NONE = Path.current | master_dir (SOME (path, _)) = Path.dir path; @@ -123,8 +112,7 @@ SOME (thy_graph Graph.get_node name) handle Graph.UNDEF _ => NONE; val known_thy = is_some o lookup_thy; -fun check_known_thy name = known_thy name orelse (warning ("Unknown theory " ^ quote name); false); -fun if_known_thy f name = if check_known_thy name then f name else (); +fun if_known_thy f name = if known_thy name then f name else (); fun get_thy name = (case lookup_thy name of @@ -140,17 +128,11 @@ val lookup_deps = Option.map #1 o lookup_thy; val get_deps = #1 o get_thy; fun change_deps name f = change_thy name (fn (deps, x) => (f deps, x)); +fun put_theory name theory = change_thy name (fn (deps, _) => (deps, SOME theory)); val is_finished = is_none o get_deps; val master_directory = master_dir' o get_deps; -fun loaded_files name = - (case get_deps name of - NONE => [] - | SOME {master, files, ...} => - (case master of SOME (thy_path, _) => [thy_path] | NONE => []) @ - (map_filter (Option.map #1 o #2) files)); - fun get_parents name = thy_graph Graph.imm_preds name handle Graph.UNDEF _ => error (loader_msg "nothing known about theory" [name]); @@ -168,27 +150,18 @@ SOME theory => theory | _ => error (loader_msg "undefined theory entry for" [name])); +fun loaded_files name = + (case get_deps name of + NONE => [] + | SOME {master, ...} => + (case master of + NONE => [] + | SOME (thy_path, _) => thy_path :: Thy_Load.loaded_files (get_theory name))); + (** thy operations **) -(* check state *) - -fun check_unfinished fail name = - if known_thy name andalso is_finished name then - fail (loader_msg "cannot update finished theory" [name]) - else (); - -fun check_files name = - let - val files = (case get_deps name of SOME {files, ...} => files | NONE => []); - val missing_files = map_filter (fn (path, NONE) => SOME (Path.implode path) | _ => NONE) files; - val _ = null missing_files orelse - error (loader_msg "unresolved dependencies of theory" [name] ^ - " on file(s): " ^ commas_quote missing_files); - in () end; - - (* maintain update_time *) local @@ -207,14 +180,13 @@ fun outdate_thy name = if is_finished name orelse is_outdated name then () else CRITICAL (fn () => - (change_deps name (Option.map (fn {master, text, parents, files, ...} => - make_deps ~1 master text parents files)); perform Outdate name)); + (change_deps name (Option.map (fn {master, text, parents, ...} => + make_deps ~1 master text parents)); perform Outdate name)); fun touch_thys names = List.app outdate_thy (thy_graph Graph.all_succs (map_filter unfinished names)); fun touch_thy name = touch_thys [name]; -fun touch_child_thys name = touch_thys (thy_graph Graph.imm_succs name); end; @@ -266,52 +238,6 @@ val kill_thy = if_known_thy remove_thy; -(* load_file *) - -local - -fun provide path name info (SOME {update_time, master, text, parents, files}) = - (if AList.defined (op =) files path then () - else warning (loader_msg "undeclared dependency of theory" [name] ^ - " on file: " ^ quote (Path.implode path)); - SOME (make_deps update_time master text parents - (AList.update (op =) (path, SOME info) files))) - | provide _ _ _ NONE = NONE; - -fun run_file path = - (case Option.map (Context.theory_name o Context.the_theory) (Context.thread_data ()) of - NONE => (Thy_Load.load_ml Path.current path; ()) - | SOME name => - (case lookup_deps name of - SOME deps => - change_deps name (provide path name (Thy_Load.load_ml (master_dir' deps) path)) - | NONE => (Thy_Load.load_ml Path.current path; ()))); - -in - -fun provide_file path name = - let - val dir = master_directory name; - val _ = check_unfinished error name; - in change_deps name (provide path name (Thy_Load.check_file dir path)) end; - -fun load_file path = - if ! Output.timing then - let val name = Path.implode path in - timeit (fn () => - (priority ("\n**** Starting file " ^ quote name ^ " ****"); - run_file path; - priority ("**** Finished file " ^ quote name ^ " ****\n"))) - end - else run_file path; - -fun exec_file path = ML_Context.exec (fn () => load_file path); - -val use = load_file o Path.explode; - -end; - - (* load_thy *) fun required_by _ [] = "" @@ -321,22 +247,23 @@ let val _ = priority ("Loading theory " ^ quote name ^ required_by " " initiators); fun corrupted () = error (loader_msg "corrupted dependency information" [name]); - val (pos, text, _) = + val (pos, text) = (case get_deps name of - SOME {master = SOME (master_path, _), text, files, ...} => + SOME {master = SOME (master_path, _), text, ...} => if text = "" then corrupted () - else (Path.position master_path, text, files) + else (Path.position master_path, text) | _ => corrupted ()); val _ = touch_thy name; - val _ = CRITICAL (fn () => - change_deps name (Option.map (fn {master, text, parents, files, ...} => - make_deps upd_time master text parents files))); - val after_load = Outer_Syntax.load_thy name pos text; + val _ = + change_deps name (Option.map (fn {master, text, parents, ...} => + make_deps upd_time master text parents)); + val (after_load, theory) = Outer_Syntax.load_thy name pos text; + val _ = put_theory name theory; val _ = CRITICAL (fn () => (change_deps name - (Option.map (fn {update_time, master, parents, files, ...} => - make_deps update_time master "" parents files)); + (Option.map (fn {update_time, master, parents, ...} => + make_deps update_time master "" parents)); perform Update name)); in after_load end; @@ -410,43 +337,33 @@ local -fun check_file master (src_path, info) = - let val info' = - (case info of - NONE => NONE - | SOME (_, id) => - (case Thy_Load.test_file (master_dir master) src_path of - NONE => NONE - | SOME (path', id') => if id <> id' then NONE else SOME (path', id'))) - in (src_path, info') end; - fun check_deps dir name = (case lookup_deps name of SOME NONE => (true, NONE, get_parents name) | NONE => - let val {master, text, imports = parents, uses = files} = Thy_Load.deps_thy dir name - in (false, init_deps (SOME master) text parents files, parents) end - | SOME (SOME {update_time, master, text, parents, files}) => + let val {master, text, imports = parents, ...} = Thy_Load.deps_thy dir name + in (false, init_deps (SOME master) text parents, parents) end + | SOME (SOME {update_time, master, text, parents}) => let val (thy_path, thy_id) = Thy_Load.check_thy dir name; val master' = SOME (thy_path, thy_id); in if Option.map #2 master <> SOME thy_id then - let val {text = text', imports = parents', uses = files', ...} = - Thy_Load.deps_thy dir name; - in (false, init_deps master' text' parents' files', parents') end + let val {text = text', imports = parents', ...} = Thy_Load.deps_thy dir name; + in (false, init_deps master' text' parents', parents') end else let - val files' = map (check_file master') files; - val current = update_time >= 0 andalso can get_theory name - andalso forall (is_some o snd) files'; + val current = + (case lookup_theory name of + NONE => false + | SOME theory => update_time >= 0 andalso Thy_Load.all_current theory); val update_time' = if current then update_time else ~1; - val deps' = SOME (make_deps update_time' master' text parents files'); + val deps' = SOME (make_deps update_time' master' text parents); in (current, deps', parents) end end); -fun read_text (SOME {update_time, master = master as SOME (path, _), text = _, parents, files}) = - SOME (make_deps update_time master (File.read path) parents files); +fun read_text (SOME {update_time, master = master as SOME (path, _), text = _, parents}) = + SOME (make_deps update_time master (File.read path) parents); in @@ -495,28 +412,31 @@ schedule_tasks (snd (require_thys [] dir arg Graph.empty)); val use_thys = use_thys_dir Path.current; - -fun use_thy str = - let - val name = base_name str; - val _ = check_unfinished warning name; - in use_thys [str] end; +val use_thy = use_thys o single; -(* begin / end theory *) +(* begin theory *) + +fun check_unfinished name = + if known_thy name andalso is_finished name then + error (loader_msg "cannot update finished theory" [name]) + else (); fun begin_theory name parents uses int = let val parent_names = map base_name parents; val dir = master_dir'' (lookup_deps name); - val _ = check_unfinished error name; + val _ = check_unfinished name; val _ = if int then use_thys_dir dir parents else (); - val theory = Theory.begin_theory name (map get_theory parent_names); + val theory = + Theory.begin_theory name (map get_theory parent_names) + |> Thy_Load.init dir + |> fold (Thy_Load.require o fst) uses; val deps = if known_thy name then get_deps name - else init_deps NONE "" parents (map #1 uses); + else init_deps NONE "" parents; val _ = change_thys (new_deps name parent_names (deps, NONE)); val update_time = (case deps of NONE => 0 | SOME {update_time, ...} => update_time); @@ -527,59 +447,34 @@ val uses_now = map_filter (fn (x, true) => SOME x | _ => NONE) uses; val theory'' = - fold (fn x => Context.theory_map (exec_file x) o Theory.checkpoint) uses_now theory'; + fold (fn x => Context.theory_map (Thy_Load.exec_ml x) o Theory.checkpoint) uses_now theory'; in theory'' end; -fun end_theory theory = - let - val name = Context.theory_name theory; - val _ = check_files name; - val theory' = Theory.end_theory theory; - val _ = change_thy name (fn (deps, _) => (deps, SOME theory')); - in () end; - (* register existing theories *) -fun register_thy name = - let - val _ = priority ("Registering theory " ^ quote name); - val thy = get_theory name; - val _ = map get_theory (get_parents name); - val _ = check_unfinished error name; - val _ = touch_thy name; - val master = #master (Thy_Load.deps_thy Path.current name); - val upd_time = #2 (Management_Data.get thy); - in - CRITICAL (fn () => - (change_deps name (Option.map - (fn {parents, files, ...} => make_deps upd_time (SOME master) "" parents files)); - perform Update name)) - end; - -fun register_theory theory = +fun register_thy theory = let val name = Context.theory_name theory; - val parents = Theory.parents_of theory; - val parent_names = map Context.theory_name parents; - - fun err txt bads = - error (loader_msg txt bads ^ "\ncannot register theory " ^ quote name); + val _ = priority ("Registering theory " ^ quote name); + val parent_names = map Context.theory_name (Theory.parents_of theory); + val _ = map get_theory parent_names; - val nonfinished = filter_out is_finished parent_names; - fun get_variant (x, y_name) = - if Theory.eq_thy (x, get_theory y_name) then NONE - else SOME y_name; - val variants = map_filter get_variant (parents ~~ parent_names); - - fun register G = - (Graph.new_node (name, (NONE, SOME theory)) G - handle Graph.DUP _ => err "duplicate theory entry" []) - |> add_deps name parent_names; + val master = Thy_Load.check_thy (Thy_Load.master_directory theory) name; + val update_time = #2 (Management_Data.get theory); + val parents = + (case lookup_deps name of + SOME (SOME {parents, ...}) => parents + | _ => parent_names); + val deps = make_deps update_time (SOME master) "" parents; in - if not (null nonfinished) then err "non-finished parent theories" nonfinished - else if not (null variants) then err "different versions of parent theories" variants - else CRITICAL (fn () => (change_thys register; perform Update name)) + CRITICAL (fn () => + (if known_thy name then + (List.app remove_thy (thy_graph Graph.imm_succs name); + change_thys (Graph.del_nodes [name])) + else (); + change_thys (new_deps name parents (SOME deps, SOME theory)); + perform Update name)) end; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/Thy/thy_load.ML --- a/src/Pure/Thy/thy_load.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/Thy/thy_load.ML Mon Jul 26 18:25:19 2010 +0200 @@ -17,21 +17,65 @@ signature THY_LOAD = sig include BASIC_THY_LOAD - val ml_path: string -> Path.T - val thy_path: string -> Path.T - val split_thy_path: Path.T -> Path.T * string - val consistent_name: string -> string -> unit + val master_directory: theory -> Path.T + val init: Path.T -> theory -> theory + val require: Path.T -> theory -> theory + val provide: Path.T * (Path.T * File.ident) -> theory -> theory val test_file: Path.T -> Path.T -> (Path.T * File.ident) option val check_file: Path.T -> Path.T -> Path.T * File.ident val check_thy: Path.T -> string -> Path.T * File.ident val deps_thy: Path.T -> string -> {master: Path.T * File.ident, text: string, imports: string list, uses: Path.T list} - val load_ml: Path.T -> Path.T -> Path.T * File.ident + val loaded_files: theory -> Path.T list + val all_current: theory -> bool + val provide_file: Path.T -> theory -> theory + val use_ml: Path.T -> unit + val exec_ml: Path.T -> generic_theory -> generic_theory end; structure Thy_Load: THY_LOAD = struct +(* manage source files *) + +type files = + {master_dir: Path.T, (*master directory of theory source*) + required: Path.T list, (*source path*) + provided: (Path.T * (Path.T * File.ident)) list}; (*source path, physical path, identifier*) + +fun make_files (master_dir, required, provided): files = + {master_dir = master_dir, required = required, provided = provided}; + +structure Files = Theory_Data +( + type T = files; + val empty = make_files (Path.current, [], []); + fun extend _ = empty; + fun merge _ = empty; +); + +fun map_files f = + Files.map (fn {master_dir, required, provided} => + make_files (f (master_dir, required, provided))); + + +val master_directory = #master_dir o Files.get; + +fun init master_dir = map_files (fn _ => (master_dir, [], [])); + +fun require src_path = + map_files (fn (master_dir, required, provided) => + if member (op =) required src_path then + error ("Duplicate source file dependency: " ^ Path.implode src_path) + else (master_dir, src_path :: required, provided)); + +fun provide (src_path, path_info) = + map_files (fn (master_dir, required, provided) => + if AList.defined (op =) provided src_path then + error ("Duplicate resolution of source file dependency: " ^ Path.implode src_path) + else (master_dir, required, (src_path, path_info) :: provided)); + + (* maintain load path *) local val load_path = Unsynchronized.ref [Path.current] in @@ -56,22 +100,6 @@ end; -(* file formats *) - -val ml_path = Path.ext "ML" o Path.basic; -val thy_path = Path.ext "thy" o Path.basic; - -fun split_thy_path path = - (case Path.split_ext path of - (path', "thy") => (Path.dir path', Path.implode (Path.base path')) - | _ => error ("Bad theory file specification " ^ Path.implode path)); - -fun consistent_name name name' = - if name = name' then () - else error ("Filename " ^ quote (Path.implode (thy_path name)) ^ - " does not agree with theory name " ^ quote name'); - - (* check files *) local @@ -103,7 +131,7 @@ error ("Could not find file " ^ quote (Path.implode path) ^ "\nin " ^ commas_quote (map Path.implode prfxs)); -fun check_thy dir name = check_file dir (thy_path name); +fun check_thy dir name = check_file dir (Thy_Header.thy_path name); end; @@ -116,18 +144,63 @@ val text = File.read path; val (name', imports, uses) = Thy_Header.read (Path.position path) (Source.of_string_limited 8000 text); - val _ = consistent_name name name'; + val _ = Thy_Header.consistent_name name name'; val uses = map (Path.explode o #1) uses; in {master = master, text = text, imports = imports, uses = uses} end; -(* ML files *) + +(* loaded files *) + +val loaded_files = map (#1 o #2) o #provided o Files.get; -fun load_ml dir raw_path = +fun check_loaded thy = + let + val {required, provided, ...} = Files.get thy; + val provided_paths = map #1 provided; + val _ = + (case subtract (op =) provided_paths required of + [] => NONE + | bad => error ("Pending source file dependencies: " ^ commas (map Path.implode (rev bad)))); + val _ = + (case subtract (op =) required provided_paths of + [] => NONE + | bad => error ("Undeclared source file dependencies: " ^ commas (map Path.implode (rev bad)))); + in () end; + +fun all_current thy = let - val (path, id) = check_file dir raw_path; - val _ = ML_Context.eval_file path; - in (path, id) end; + val {master_dir, provided, ...} = Files.get thy; + fun current (src_path, path_info) = + (case test_file master_dir src_path of + NONE => false + | SOME path_info' => eq_snd (op =) (path_info, path_info')); + in can check_loaded thy andalso forall current provided end; + +val _ = Context.>> (Context.map_theory (Theory.at_end (fn thy => (check_loaded thy; NONE)))); + + +(* provide files *) + +fun provide_file src_path thy = + provide (src_path, check_file (master_directory thy) src_path) thy; + +fun use_ml src_path = + if is_none (Context.thread_data ()) then + ML_Context.eval_file (#1 (check_file Path.current src_path)) + else + let + val thy = ML_Context.the_global_context (); + val (path, info) = check_file (master_directory thy) src_path; + + val _ = ML_Context.eval_file path; + val _ = Context.>> Local_Theory.propagate_ml_env; + + val provide = provide (src_path, (path, info)); + val _ = Context.>> (Context.mapping provide (Local_Theory.theory provide)); + in () end + +fun exec_ml src_path = ML_Context.exec (fn () => use_ml src_path); end; diff -r d9549f9da779 -r a79abb22ca9c src/Pure/pure_setup.ML --- a/src/Pure/pure_setup.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Pure/pure_setup.ML Mon Jul 26 18:25:19 2010 +0200 @@ -4,14 +4,16 @@ Pure theory and ML toplevel setup. *) -(* the Pure theories *) +(* the Pure theory *) Context.>> (Context.map_theory (Outer_Syntax.process_file (Path.explode "Pure.thy") #> Theory.end_theory)); + structure Pure = struct val thy = ML_Context.the_global_context () end; + Context.set_thread_data NONE; -Thy_Info.register_theory Pure.thy; +Thy_Info.register_thy Pure.thy; (* ML toplevel pretty printing *) @@ -51,7 +53,8 @@ (* ML toplevel use commands *) -fun use name = Toplevel.program (fn () => Thy_Info.use name); +fun use name = Toplevel.program (fn () => Thy_Load.use_ml (Path.explode name)); + fun use_thys name = Toplevel.program (fn () => Thy_Info.use_thys name); fun use_thy name = Toplevel.program (fn () => Thy_Info.use_thy name); diff -r d9549f9da779 -r a79abb22ca9c src/Tools/Code/code_eval.ML --- a/src/Tools/Code/code_eval.ML Mon Jul 26 14:44:07 2010 +0200 +++ b/src/Tools/Code/code_eval.ML Mon Jul 26 18:25:19 2010 +0200 @@ -173,7 +173,8 @@ end | process (code_body, _) _ (SOME file_name) thy = let - val preamble = "(* Generated from " ^ Path.implode (Thy_Load.thy_path (Context.theory_name thy)) + val preamble = + "(* Generated from " ^ Path.implode (Thy_Header.thy_path (Context.theory_name thy)) ^ "; DO NOT EDIT! *)"; val _ = File.write (Path.explode file_name) (preamble ^ "\n\n" ^ code_body); in