Docsity

Java Program Verification: Lecture 15 by Josè Meseguer - Prof. Jose Meseguer, Study notes of Computer Science

Partial preview of the text

Download Java Program Verification: Lecture 15 by Josè Meseguer - Prof. Jose Meseguer and more Study notes Computer Science in PDF only on Docsity!

Program Verification:

Lecture 15

Jos´

e Meseguer

Computer Science Department

University of Illinois at Urbana-Champaign

The Infrastructure for Java:

Continuations

Within

continuations

all the execution context is stored.

This can be viewed as “the rest of the program” whichneeds to be executed. The two operators shown here arethe ending point of an execution. Within the semantics wewill define other operators with co-domain

Continuation

as

needed. fmod CONTINUATION is

sort Continuation .op stop : -> Continuation .op res : -> Continuation. endfm

The Infrastructure for Java:

Outputs

The

outputs

of our language are values, wrapped in specific

operators and connected as below: fmod OUTPUT is ex VALUE.

ex STORE .sort Output .op O : Value -> Output .op O : Value Store -> Output .op noOutput : -> Output .op , : Output Output -> Output [assoc id: noOutput]. endfm

The Infrastructure for Java:

State

The

state

is made up of state attributes which are the

environment, store, output and a counter for the next freememory location each wrapped in some operator. It has theusual multiset union composition operator. fmod STATE is extending ENVIRONMENT. extending STORE.

extending CONTINUATION. ex OUTPUT .sorts StateAttribute MyState .subsort StateAttribute < MyState .op empty : -> MyState .op , : MyState MyState -> MyState [assoc comm id: empty] .op e : Env -> StateAttribute .op n : Nat -> StateAttribute .op m : Store -> StateAttribute .op out : Output -> StateAttribute.

The Infrastructure for Java:

Helpers

There are a few helper functionalities which are needed thatare not part of Java but which we use in our evaluation ofJava code. This operator returns the value of a variable ina given state.

var MYS : MyState. var V : Value. var X : Name .var L : Location. var Env : Env. var M : Store .op [] : WrappedState Name -> Value .eq state((MYS, e([X,L] Env), m([L,V] M)))[X]

= V.

The Infrastructure for Java:

Helpers (II)

These equations are needed to get non-ground termreduced in the decision procedure we use for provingproperties of programs.

vars I J I’ : Int .eq 0 + I = I .eq -(I, J) = I + (- J) .eq I’ * (I + J) = (I’ * I) + (I’ * J).

The Semantics of Java:

Generic Expressions

The first two operators allow for expression and value listson the top of a continuation. The

int

operator creates a

value of an integer. The semantics of an integer expressionis to become an integer value. This module is thefoundation upon which all the following semantic equationsrely. Most equations here transform non-Java syntaxintermediate continuations which are created by the rulesfor each feature. fmod GENERIC-EXP-SEMANTICS is protecting GENERIC-EXP-SYNTAX.

protecting STATE .op -> : Exps Continuation -> Continuation .op -> : ValueList Continuation -> Continuation .op int : Int -> Value .op str : String -> Value.

The Semantics of Java:

Generic Expressions (II)

Integer and string expressions become integer, respectivelystring, values.

vars E E’ : Exp.

var El : Exps.

vars V V’ : Value.

var Vl Vl’ : ValueList.

var L : Location.

var Ll : LocationList.

var I : Int.

var K : Continuation.

var M : Store.

vars Env Env’ : Env.

var str : String. var MYS : MyState .eq k(#i(I) -> K) = k(int(I) -> K) .eq k(#s(str) -> K) = k(str(str) -> K).

The Semantics of Java:

Generic Expressions (IV)

Lists of locations can also be on the top of a continuation,as well as the

change

operator which will change the value

at the given location to the given value. This will be helpfulto define assignments when no result is needed.

op -> : LocationList Continuation -> Continuation .op change (,) -> _ : Value Location Continuation -> Continuation .eq k(noVal -> noLoc -> K), state(m(M), MYS) = k(K), state(m(M), MYS) .eq k((V, Vl) -> (L, Ll) -> K), state(m([L, V’] M), MYS)

= k(change(V, L) -> (Vl -> Ll -> K)), state(m([L, V’] M), MYS).

eq k(change(V, L) -> K), state(m([L, V’] M), MYS)

= k(K), state(m([L, V] M), MYS).

The Semantics of Java:

Generic Expressions (V)

Here

set&fetch

creates a second copy of the values that are

assigned. Once all the values of the value list are assignedto the locations of the location list the only thing left(outside of the rest

K

) will be exactly the copy of the value

list. This allows assignments where the result is alsodirectly used afterwards.

op set&fetch_->_ : LocationList Continuation -> Continuation .eq k(Vl -> set&fetch(Ll) -> K) = k(Vl -> Ll -> Vl -> K).

The Semantics of Java:

Locations

This gives the semantics for locations on the continuationand will be used to get the location of a variable. fmod LOCATION-SEMANTICS is ex GENERIC-EXP-SEMANTICS. pr ARRAY-SYNTAX.

pr ARRAY .op loc_ -> _ : Exp Continuation -> Continuation .op loc -> _ : Continuation -> Continuation .vars E E’ : Exp. var L : Location. var X : Name .var I : Int.

var K : Continuation. var Env : Env.

var T : Type. var aEnv : ArrayEnv. var MYS : MyState .eq k(loc(X) -> K), state(e([X, L] Env), MYS)

= k(L -> K), state(e([X, L] Env), MYS).

eq k(loc(E [ E’ ]) -> K) = k((E, E’) -> loc -> K) .eq k((a(T, [I,L] aEnv), int(I)) -> loc -> K) = k(L -> K). endfm

The Semantics of Java:

Arithmetic Expressions

This gives the semantics for arithmetic expressions. Takefor example addition, here first the two arguments areevaluated and then, if they are both integers, they areadded together. All other operators are defined similarly. fmod ARITH-EXP-SEMANTICS is protecting ARITH-EXP-SYNTAX.

extending GENERIC-EXP-SEMANTICS .op + -> _ : Continuation -> Continuation .op - -> _ : Continuation -> Continuation .op * -> _ : Continuation -> Continuation .op / -> _ : Continuation -> Continuation .op % -> _ : Continuation -> Continuation .vars E E’ : Exp.

var K : Continuation.

vars I I’ : Int.

vars str str’ : String .eq k((E + E’) -> K) = k((E,E’) -> + -> K) .eq k((int(I), int(I’)) -> + -> K) = k(int(I + I’) -> K).

The Semantics of Java:

Comparisons

The semantics of comparisons are defined similarly to thoseof arithmetic expressions. First evaluate the subexpressionsand then compare the results. They are all defined similarly. fmod REXP-SEMANTICS is pr REXP-SYNTAX.

extending GENERIC-EXP-SEMANTICS .op bool : Bool -> Value .op == -> _ : Continuation -> Continuation .op != -> _ : Continuation -> Continuation .op < -> _

: Continuation -> Continuation.

op <= -> _ : Continuation -> Continuation .op > -> _

: Continuation -> Continuation.

op >= -> _ : Continuation -> Continuation .vars E E’ : Exp.

var K : Continuation.

vars I I’ : Int.

vars B B’ : Bool.

eq k(#b(B) -> K) = k(bool(B) -> K).

The Semantics of Java:

Comparisons (II)

eq k((E == E’) -> K) = k((E,E’) -> == -> K) .eq k((int(I),int(I’)) -> == -> K) = k(bool(I == I’) -> K) .eq k((E != E’) -> K) = k((E,E’) -> != -> K) .eq k((int(I),int(I’)) -> != -> K) = k(bool(not (I == I’)) -> K) .eq k((E >= E’) -> K) = k((E,E’) -> >= -> K) .eq k((int(I),int(I’)) -> >= -> K) = k(bool(I >= I’) -> K) .eq k((E > E’) -> K) = k((E,E’) -> > -> K) .eq k((int(I),int(I’)) -> > -> K) = k(bool(I > I’) -> K) .eq k((E <= E’) -> K) = k((E,E’) -> <= -> K) .eq k((int(I),int(I’)) -> <= -> K) = k(bool(I <= I’) -> K) .eq k((E < E’) -> K) = k((E,E’) -> < -> K) .eq k((int(I),int(I’)) -> < -> K) = k(bool(I < I’) -> K). endfm