# HG changeset patch # User oheimb # Date 1000136122 -7200 # Node ID 6539627881e86e3be4aba3d07fa3e232fab85f0f # Parent 66b62cbeaab35e24501b0b5dd2ee42e0ef9a4da8 simplified vnam/vname, introduced fname, improved comments diff -r 66b62cbeaab3 -r 6539627881e8 src/HOL/NanoJava/AxSem.thy --- a/src/HOL/NanoJava/AxSem.thy Mon Sep 10 13:57:57 2001 +0200 +++ b/src/HOL/NanoJava/AxSem.thy Mon Sep 10 17:35:22 2001 +0200 @@ -38,7 +38,7 @@ translations "A |\ C" \ "(A,C) \ hoare" "A \ {P}c{Q}" \ "A |\ {(P,c,Q)}" "A |\\<^sub>e t" \ "(A,t) \ ehoare" - "A |\\<^sub>e (P,e,Q)" \ "(A,P,e,Q) \ ehoare" (** shouldn't be necess.**) + "A |\\<^sub>e (P,e,Q)" \ "(A,P,e,Q) \ ehoare" (* shouldn't be necessary *) "A \\<^sub>e {P}e{Q}" \ "A |\\<^sub>e (P,e,Q)" @@ -77,7 +77,7 @@ Call: "[| A |-e {P} e1 {Q}; \a. A |-e {Q a} e2 {R a}; \a p l. A |- {\s'. \s. R a p s \ l = s \ - s' = lupd(This\a)(lupd(Param\p)(reset_locs s))} + s' = lupd(This\a)(lupd(Par\p)(reset_locs s))} Meth (C,m) {\s. S (s) (set_locs l s)} |] ==> A |-e {P} {C}e1..m(e2) {S}" @@ -86,13 +86,13 @@ Impl (D,m) {Q} ==> A |- {P} Meth (C,m) {Q}" - (*\z instead of \z in the conclusion and - z restricted to type state due to limitations of the inductive package *) + --{*\z instead of \z in the conclusion and + z restricted to type state due to limitations of the inductive package *} Impl: "\z::state. A\ (\z. (\Cm. (P z Cm, Impl Cm, Q z Cm))`Ms) ||- (\Cm. (P z Cm, body Cm, Q z Cm))`Ms ==> A ||- (\Cm. (P z Cm, Impl Cm, Q z Cm))`Ms" -(* structural rules *) +--{* structural rules *} Asm: " a \ A ==> A ||- {a}" @@ -104,7 +104,7 @@ \s t. (\z. P' z s --> Q' z t) --> (P s --> Q t) |] ==> A |- {P} c {Q }" - (* z restricted to type state due to limitations of the inductive package *) + --{* z restricted to type state due to limitations of the inductive package *} eConseq:"[| \z::state. A |-e {P' z} c {Q' z}; \s v t. (\z. P' z s --> Q' z v t) --> (P s --> Q v t) |] ==> A |-e {P} c {Q }" diff -r 66b62cbeaab3 -r 6539627881e8 src/HOL/NanoJava/Decl.thy --- a/src/HOL/NanoJava/Decl.thy Mon Sep 10 13:57:57 2001 +0200 +++ b/src/HOL/NanoJava/Decl.thy Mon Sep 10 17:35:22 2001 +0200 @@ -9,34 +9,37 @@ theory Decl = Term: datatype ty - = NT (* null type *) - | Class cname (* class type *) + = NT --{* null type *} + | Class cname --{* class type *} -types fdecl (* field declaration *) - = "vnam \ ty" +text{* field declaration *} +types fdecl + = "fname \ ty" -record methd (* method declaration *) +record methd = par :: ty res :: ty lcl ::"(vname \ ty) list" bdy :: stmt -types mdecl (* method declaration *) +text{* method declaration *} +types mdecl = "mname \ methd" -record class (* class *) +record class = super :: cname fields ::"fdecl list" methods ::"mdecl list" -types cdecl (* class declaration *) +text{* class declaration *} +types cdecl = "cname \ class" types prog = "cdecl list" translations - "fdecl" \ (type)"vname \ ty" + "fdecl" \ (type)"fname \ ty" "mdecl" \ (type)"mname \ ty \ ty \ stmt" "class" \ (type)"cname \ fdecl list \ mdecl list" "cdecl" \ (type)"cname \ class" @@ -44,8 +47,8 @@ consts - Prog :: prog (* program as a global value *) - Object :: cname (* name of root class *) + Prog :: prog --{* program as a global value *} + Object :: cname --{* name of root class *} constdefs diff -r 66b62cbeaab3 -r 6539627881e8 src/HOL/NanoJava/OpSem.thy --- a/src/HOL/NanoJava/OpSem.thy Mon Sep 10 13:57:57 2001 +0200 +++ b/src/HOL/NanoJava/OpSem.thy Mon Sep 10 17:35:22 2001 +0200 @@ -54,7 +54,7 @@ s -Cast C e>v-n-> s'" Call: "[| s0 -e1>a-n-> s1; s1 -e2>p-n-> s2; - lupd(This\a)(lupd(Param\p)(reset_locs s2)) -Meth (C,m)-n-> s3 + lupd(This\a)(lupd(Par\p)(reset_locs s2)) -Meth (C,m)-n-> s3 |] ==> s0 -{C}e1..m(e2)>s3-n-> set_locs s2 s3" Meth: "[| s = Addr a; D = obj_class s a; D\C C; diff -r 66b62cbeaab3 -r 6539627881e8 src/HOL/NanoJava/State.thy --- a/src/HOL/NanoJava/State.thy Mon Sep 10 13:57:57 2001 +0200 +++ b/src/HOL/NanoJava/State.thy Mon Sep 10 17:35:22 2001 +0200 @@ -17,17 +17,17 @@ typedecl loc datatype val - = Null (* null reference *) - | Addr loc (* address, i.e. location of object *) + = Null --{* null reference *} + | Addr loc --{* address, i.e. location of object *} types fields - = "(vnam \ val)" + = "(fname \ val)" obj = "cname \ fields" translations - "fields" \ (type)"vnam \ val option" + "fields" \ (type)"fname => val option" "obj" \ (type)"cname \ fields" constdefs @@ -67,35 +67,33 @@ get_local :: "state => vname => val" ("_<_>" [99,0] 99) "get_local s x \ the (locals s x)" -(* local function: *) +--{* local function: *} get_obj :: "state => loc => obj" "get_obj s a \ the (heap s a)" obj_class :: "state => loc => cname" "obj_class s a \ fst (get_obj s a)" - get_field :: "state => loc => vnam => val" + get_field :: "state => loc => fname => val" "get_field s a f \ the (snd (get_obj s a) f)" +--{* local function: *} + hupd :: "loc => obj => state => state" ("hupd'(_|->_')" [10,10] 1000) + "hupd a obj s \ s (| heap := ((heap s)(a\obj))|)" + + lupd :: "vname => val => state => state" ("lupd'(_|->_')" [10,10] 1000) + "lupd x v s \ s (| locals := ((locals s)(x\v ))|)" + +syntax (xsymbols) + hupd :: "loc => obj => state => state" ("hupd'(_\_')" [10,10] 1000) + lupd :: "vname => val => state => state" ("lupd'(_\_')" [10,10] 1000) + constdefs -(* local function: *) - hupd :: "loc \ obj \ state \ state" ("hupd'(_|->_')" [10,10] 1000) - "hupd a obj s \ s (| heap := ((heap s)(a\obj))|)" - - lupd :: "vname \ val \ state \ state" ("lupd'(_|->_')" [10,10] 1000) - "lupd x v s \ s (| locals := ((locals s)(x\v ))|)" - -syntax (xsymbols) - hupd :: "loc \ obj \ state \ state" ("hupd'(_\_')" [10,10] 1000) - lupd :: "vname \ val \ state \ state" ("lupd'(_\_')" [10,10] 1000) - -constdefs - - new_obj :: "loc \ cname \ state \ state" + new_obj :: "loc => cname => state => state" "new_obj a C \ hupd(a\(C,init_vars (field C)))" - upd_obj :: "loc \ vnam \ val \ state \ state" + upd_obj :: "loc => fname => val => state => state" "upd_obj a f v s \ let (C,fs) = the (heap s a) in hupd(a\(C,fs(f\v))) s" new_Addr :: "state => val" diff -r 66b62cbeaab3 -r 6539627881e8 src/HOL/NanoJava/Term.thy --- a/src/HOL/NanoJava/Term.thy Mon Sep 10 13:57:57 2001 +0200 +++ b/src/HOL/NanoJava/Term.thy Mon Sep 10 17:35:22 2001 +0200 @@ -8,32 +8,40 @@ theory Term = Main: -typedecl cname (* class name *) -typedecl vnam (* variable or field name *) -typedecl mname (* method name *) +typedecl cname --{* class name *} +typedecl mname --{* method name *} +typedecl fname --{* field name *} +typedecl vname --{* variable name *} -datatype vname (* variable for special names *) - = This (* This pointer *) - | Param (* method parameter *) - | Res (* method result *) - | VName vnam +consts + This :: vname --{* This pointer *} + Par :: vname --{* method parameter *} + Res :: vname --{* method result *} + +text {* Inequality axioms not required here *} +(* +axioms + This_neq_Par [simp]: "This \ Par" + Par_neq_Res [simp]: "Par \ Res" + Res_neq_This [simp]: "Res \ This" +*) datatype stmt - = Skip (* empty statement *) + = Skip --{* empty statement *} | Comp stmt stmt ("_;; _" [91,90 ] 90) | Cond expr stmt stmt ("If '(_') _ Else _" [99,91,91] 91) | Loop vname stmt ("While '(_') _" [99,91 ] 91) - | LAss vname expr ("_ :== _" [99, 95] 94) (* local ass. *) - | FAss expr vnam expr ("_.._:==_" [95,99,95] 94) (* field ass. *) - | Meth "cname \ mname" (* virtual method *) - | Impl "cname \ mname" (* method implementation *) + | LAss vname expr ("_ :== _" [99, 95] 94) --{* local ass.*} + | FAss expr fname expr ("_.._:==_" [95,99,95] 94) --{* field ass.*} + | Meth "cname \ mname" --{* virtual method *} + | Impl "cname \ mname" --{* method implementation *} and expr - = NewC cname ("new _" [ 99] 95) (* object creation *) - | Cast cname expr (* type cast *) - | LAcc vname (* local access *) - | FAcc expr vnam ("_.._" [95,99] 95) (* field access *) - | Call cname expr mname expr (* method call *) - ("{_}_.._'(_')" [99,95,99,95] 95) + = NewC cname ("new _" [ 99] 95) --{* object creation *} + | Cast cname expr --{* type cast *} + | LAcc vname --{* local access *} + | FAcc expr fname ("_.._" [95,99] 95) --{* field access *} + | Call cname expr mname expr + ("{_}_.._'(_')" [99,95,99,95] 95) --{* method call *} end diff -r 66b62cbeaab3 -r 6539627881e8 src/HOL/NanoJava/TypeRel.thy --- a/src/HOL/NanoJava/TypeRel.thy Mon Sep 10 13:57:57 2001 +0200 +++ b/src/HOL/NanoJava/TypeRel.thy Mon Sep 10 17:35:22 2001 +0200 @@ -9,8 +9,8 @@ theory TypeRel = Decl: consts - widen :: "(ty \ ty ) set" (* widening *) - subcls1 :: "(cname \ cname) set" (* subclass *) + widen :: "(ty \ ty ) set" --{* widening *} + subcls1 :: "(cname \ cname) set" --{* subclass *} syntax (xsymbols) widen :: "[ty , ty ] => bool" ("_ \ _" [71,71] 70) @@ -28,17 +28,17 @@ consts method :: "cname => (mname \ methd)" - field :: "cname => (vnam \ ty)" + field :: "cname => (fname \ ty)" text {* The rest of this theory is not actually used. *} +text{* direct subclass relation *} defs - (* direct subclass relation *) subcls1_def: "subcls1 \ {(C,D). C\Object \ (\c. class C = Some c \ super c=D)}" - -inductive widen intros (*widening, viz. method invocation conversion, - i.e. sort of syntactic subtyping *) + +text{* widening, viz. method invocation conversion *} +inductive widen intros refl [intro!, simp]: "T \ T" subcls : "C\C D \ Class C \ Class D" null [intro!]: "NT \ R" @@ -121,7 +121,7 @@ apply simp done -(* methods of a class, with inheritance and hiding *) +--{* methods of a class, with inheritance and hiding *} defs method_def: "method C \ class_rec C methods" lemma method_rec: "\class C = Some m; ws_prog\ \ @@ -132,7 +132,7 @@ done -(* fields of a class, with inheritance and hiding *) +--{* fields of a class, with inheritance and hiding *} defs field_def: "field C \ class_rec C fields" lemma fields_rec: "\class C = Some m; ws_prog\ \