(* Title: HOL/Bali/Term.thy Author: David von Oheimb *)
subsection‹Java expressions and statements›
theoryTermimportsValue Table begin
text‹ design issues: \begin{itemize} \item invocation frames for local variables could be reduced to special static objects (one per method). This would reduce redundancy, but yield a rather non-standard execution model more difficult to understand. \item method bodies separated from calls to handle assumptions in axiomat. semantics NB: Body is intended to be in the environment of the called method. \item class initialization is regarded as (auxiliary) statement (required for AxSem) \item result expression of method return is handled by a special result variable result variable is treated uniformly with local variables \begin{itemize} \item[+] welltypedness and existence of the result/return expression is ensured without extra efford \end{itemize} \end{itemize} simplifications: \begin{itemize} \item expression statement allowed for any expression \item This is modeled as a special non-assignable local variable \item Super is modeled as a general expression with the same value as This \item access to field x in current class via This.x \item NewA creates only one-dimensional arrays; initialization of further subarrays may be simulated with nested NewAs \item The 'Lit' constructor is allowed to contain a reference value. But this is assumed to be prohibited in the input language, which is enforced by the type-checking rules. \item a call of a static method via a type name may be simulated by a dummy variable \item no nested blocks with inner local variables \item no synchronized statements \item no secondary forms of if, while (e.g. no for) (may be easily simulated) \item no switch (may be simulated with if) \item the ‹try_catch_finally›statement is divided into the ‹try_catch›statement and a finally statement, which may be considered as try..finally with empty catch \item the ‹try_catch›statement has exactly one catch clause; multiple ones can be simulated with instanceof \item the compiler is supposed to add the annotations {‹_›} during type-checking. This transformation is left out as its result is checked by the type rules anyway \end{itemize} ›
datatype jump
= Break label 🍋‹break›
| Cont label 🍋‹continue›
| Ret 🍋‹return from method›
datatype xcpt 🍋‹exception›
= Loc loc 🍋‹location of allocated execption object›
| Std xname 🍋‹intermediate standard exception, see Eval.thy›
datatype error
= AccessViolation 🍋‹Access to a member that isn't permitted›
| CrossMethodJump 🍋‹Method exits with a break or continue›
datatype abrupt 🍋‹abrupt completion›
= Xcpt xcpt 🍋‹exception›
| Jump jump 🍋‹break, continue, return›
| Error error 🍋‹runtime errors, we wan't to detect and proof absent in welltyped programms› type_synonym
abopt = "abrupt option"
text‹Local variable store and exception. Anticipation of State.thy used by smallstep semantics. For a method call, we save the local variables of the caller in the term Callee to restore them after method return. Also an exception must be restored after the finally statement›
🍋‹function codes for binary operations› datatype binop = Mul 🍋‹{\tt *} multiplication›
| Div 🍋‹{\tt /} division›
| Mod 🍋‹{\tt\%} remainder›
| Plus 🍋‹{\tt +} addition›
| Minus 🍋‹{\tt -} subtraction›
| LShift 🍋‹{\tt🚫 left shift›
| RShift 🍋‹{\tt >>} signed right shift›
| RShiftU 🍋‹{\tt >>>} unsigned right shift›
| Less 🍋‹{\tt🚫less than›
| Le 🍋‹{\tt🚫 less than or equal›
| Greater 🍋‹{\tt >} greater than›
| Ge 🍋‹{\tt >=} greater than or equal›
| Eq 🍋‹{\tt ==} equal›
| Neq 🍋‹{\tt !=} not equal›
| BitAnd 🍋‹{\tt\&} bitwise AND›
| And🍋‹{\tt\&} boolean AND›
| BitXor 🍋‹{\texttt\^} bitwise Xor›
| Xor 🍋‹{\texttt\^} boolean Xor›
| BitOr 🍋‹{\tt |} bitwise Or›
| Or 🍋‹{\tt |} boolean Or›
| CondAnd 🍋‹{\tt\&\&} conditional And›
| CondOr 🍋‹{\tt ||} conditional Or› text‹The boolean operators {\tt\&} and {\tt |} strictly evaluate both of their arguments. The conditional operators {\tt\&\&} and {\tt ||} only evaluate the second argument if the value of the whole expression isn't allready determined by the first argument. e.g.: {\tt false \&\& e} e is not evaluated; {\tt true || e} e is not evaluated; ›
datatype var
= LVar lname 🍋‹local variable (incl. parameters)›
| FVar qtname qtname bool expr vname (‹{_,_,_}_.._›[10,10,10,85,99]90) 🍋‹class field› 🍋‹🍋‹{accC,statDeclC,stat}e..fn›\› 🍋‹‹accC›: accessing class (static class were› 🍋‹the code is declared. Annotation only needed for› 🍋‹evaluation to check accessibility)› 🍋‹‹statDeclC›: static declaration class of field› 🍋‹‹stat›: static or instance field?› 🍋‹‹e›: reference to object› 🍋‹‹fn›: field name›
| AVar expr expr (‹_.[_]›[90,10 ]90) 🍋‹array component› 🍋‹🍋‹e1.[e2]›: e1 array reference; e2 index›
| InsInitV stmt var 🍋‹insertion of initialization before evaluation› 🍋‹of var (technical term for smallstep semantics.)›
| Super 🍋‹special Super keyword›
| Acc var 🍋‹variable access›
| Ass var expr (‹_:=_› [90,85 ]85) 🍋‹variable assign›
| Cond expr expr expr (‹_ ? _ : _› [85,85,80]80) 🍋‹conditional›
| Call qtname ref_ty inv_mode expr mname "(ty list)""(expr list)"
(‹{_,_,_}_⋅_'( {_}_')›[10,10,10,85,99,10,10]85) 🍋‹method call› 🍋‹🍋‹{accC,statT,mode}e⋅mn({pTs}args)›"› 🍋‹‹accC›: accessing class (static class were› 🍋‹the call code is declared. Annotation only needed for› 🍋‹evaluation to check accessibility)› 🍋‹‹statT›: static declaration class/interface of› 🍋‹method› 🍋‹‹mode›: invocation mode› 🍋‹‹e›: reference to object› 🍋‹‹mn›: field name› 🍋‹‹pTs›: types of parameters› 🍋‹‹args›: the actual parameters/arguments›
| Methd qtname sig 🍋‹(folded) method (see below)›
| Body qtname stmt 🍋‹(unfolded) method body›
| InsInitE stmt expr 🍋‹insertion of initialization before› 🍋‹evaluation of expr (technical term for smallstep sem.)›
| Callee locals expr 🍋‹save callers locals in callee-Frame› 🍋‹(technical term for smallstep semantics)› and stmt
= Skip 🍋‹empty statement›
| Expr expr 🍋‹expression statement›
| Lab jump stmt (‹_∙ _› [ 99,66]66) 🍋‹labeled statement; handles break›
| Comp stmt stmt (‹_;; _› [ 66,65]65)
| If' expr stmt stmt (‹If'(_') _ Else _› [ 80,79,79]70)
| Loop label expr stmt (‹_∙ While'(_') _› [ 99,80,79]70)
| Jmp jump 🍋‹break, continue, return›
| Throw expr
| TryC stmt qtname vname stmt (‹Try _ Catch'(_ _') _› [79,99,80,79]70) 🍋‹🍋‹Try c1 Catch(C vn) c2›\› 🍋‹‹c1›: block were exception may be thrown› 🍋‹‹C›: execption class to catch› 🍋‹‹vn›: local name for exception used in ‹c2›\› 🍋‹‹c2›: block to execute when exception is cateched›
| Fin stmt stmt (‹_ Finally _› [ 79,79]70)
| FinA abopt stmt 🍋‹Save abruption of first statement› 🍋‹technical term for smallstep sem.)›
| Init qtname 🍋‹class initialization›
datatype_compat var expr stmt
text‹ The expressions Methd and Body are artificial program constructs, in the sense that they are not used to define a concrete Bali program. In the operational semantic's they are "generated on the fly" to decompose the task to define the behaviour of the Call expression. They are crucial for the axiomatic semantics to give a syntactic hook to insert some assertions (cf. AxSem.thy, Eval.thy). The Init statement (to initialize a class on its first use) is inserted in various places by the semantics. Callee, InsInitV, InsInitE,FinA are only needed as intermediate steps in the smallstep (transition) semantics (cf. Trans.thy). Callee is used to save the local variables of the caller for method return. So ve avoid modelling a frame stack. The InsInitV/E terms are only used by the smallstep semantics to model the intermediate steps of class-initialisation. ›
text‹It seems to be more elegant to have an overloaded injection like the following. ›
class inj_term = fixes inj_term:: "'a ==> term" (‹⟨_⟩› 1000)
text‹How this overloaded injections work can be seen in the theory ‹DefiniteAssignment›. Other big inductive relations on terms defined in theories ‹WellType›,‹Eval›, ‹Evaln› and ‹AxSem›don't follow this convention right now, but introduce subtle syntactic sugar in the relations themselves to make a distinction on expressions, statements and so on. So unfortunately you will encounter a mixture of dealing with these injections. The abbreviations above are used as bridge between the different conventions. ›
definition
need_second_arg :: "binop ==> val ==> bool"where "need_second_arg binop v1 = (¬ ((binop=CondAnd ∧¬ the_Bool v1) ∨ (binop=CondOr ∧ the_Bool v1)))" text‹🍋‹CondAnd›and 🍋‹CondOr› only evalulate the second argument if the value isn't already determined by the first argument›
lemma need_second_arg_CondAnd [simp]: "need_second_arg CondAnd (Bool b) = b" by (simp add: need_second_arg_def)
lemma need_second_arg_CondOr [simp]: "need_second_arg CondOr (Bool b) = (¬ b)" by (simp add: need_second_arg_def)
lemma need_second_arg_strict[simp]: "[binop≠CondAnd; binop≠CondOr]==> need_second_arg binop b" by (cases binop)
(simp_all add: need_second_arg_def) end
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-04-26)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.