JML Model Fields Christian Engel ITI, Universit at Karlsruhe 08. - - PowerPoint PPT Presentation

jml model fields
SMART_READER_LITE
LIVE PREVIEW

JML Model Fields Christian Engel ITI, Universit at Karlsruhe 08. - - PowerPoint PPT Presentation

JML What are model fields? Translation to JavaDL Demo JML Model Fields Christian Engel ITI, Universit at Karlsruhe 08. Juni 2005 Christian Engel JML Model Fields JML What are model fields? Translation to JavaDL Demo Outline JML 1


slide-1
SLIDE 1

JML What are model fields? Translation to JavaDL Demo

JML Model Fields

Christian Engel

ITI, Universit¨ at Karlsruhe

  • 08. Juni 2005

Christian Engel JML Model Fields

slide-2
SLIDE 2

JML What are model fields? Translation to JavaDL Demo

Outline

1

JML

2

What are model fields?

3

Translation to JavaDL Axiomatic approach Interpretation as model methods/queries

4

Demo

Christian Engel JML Model Fields

slide-3
SLIDE 3

JML What are model fields? Translation to JavaDL Demo

JML

JML . . . . . . is a specification language tailored to Java.

Christian Engel JML Model Fields

slide-4
SLIDE 4

JML What are model fields? Translation to JavaDL Demo

JML

JML . . . . . . is a specification language tailored to Java. . . . serves as an input language for KeY.

Christian Engel JML Model Fields

slide-5
SLIDE 5

JML What are model fields? Translation to JavaDL Demo

JML

JML . . . . . . is a specification language tailored to Java. . . . serves as an input language for KeY. . . . can be used for specifying method contracts and loop invariants.

Christian Engel JML Model Fields

slide-6
SLIDE 6

JML What are model fields? Translation to JavaDL Demo

JML

JML . . . . . . is a specification language tailored to Java. . . . serves as an input language for KeY. . . . can be used for specifying method contracts and loop invariants. . . . allows declaring model methods and model fields.

Christian Engel JML Model Fields

slide-7
SLIDE 7

JML What are model fields? Translation to JavaDL Demo

Model fields

Model fields are only visible on the level of specification.

Christian Engel JML Model Fields

slide-8
SLIDE 8

JML What are model fields? Translation to JavaDL Demo

Model fields

Model fields are only visible on the level of specification. Example: //@ public model int a;

Christian Engel JML Model Fields

slide-9
SLIDE 9

JML What are model fields? Translation to JavaDL Demo

Model fields

Model fields are only visible on the level of specification. Example: //@ public model int a; The represents clause defines, how the value of a model field is related to the implementation.

Christian Engel JML Model Fields

slide-10
SLIDE 10

JML What are model fields? Translation to JavaDL Demo

Model fields

Model fields are only visible on the level of specification. Example: //@ public model int a; The represents clause defines, how the value of a model field is related to the implementation. /*@ public represents a \ such that 0<=a && a<size(); @*/

Christian Engel JML Model Fields

slide-11
SLIDE 11

JML What are model fields? Translation to JavaDL Demo

The represents clause

The represents clause defines a relation R(x, ~ q) between a model field x and a vector ~ q, consisting of fields and methods. //@ model t x; //@ represents x \ such that R(x,~ q);

Christian Engel JML Model Fields

slide-12
SLIDE 12

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach – a first attempt

A first attempt: We interpret R(x, ˜ q) as an axiom that holds in every state of the program.

Christian Engel JML Model Fields

slide-13
SLIDE 13

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach – a first attempt

A first attempt: We interpret R(x, ˜ q) as an axiom that holds in every state of the program. But: This is not possible, since there can be a state s, in which R(x, ˜ q) is equivalent to false.

Christian Engel JML Model Fields

slide-14
SLIDE 14

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach – a first attempt

A first attempt: We interpret R(x, ˜ q) as an axiom that holds in every state of the program. But: This is not possible, since there can be a state s, in which R(x, ˜ q) is equivalent to false. Solution: The axiom we have to use is: (∃a:t (R(a, ˜ q))) → R(x, ˜ q)

Christian Engel JML Model Fields

slide-15
SLIDE 15

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach expressed in JavaDL

Let φ(x) be a first order formula with occurences of x.

Christian Engel JML Model Fields

slide-16
SLIDE 16

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach expressed in JavaDL

Let φ(x) be a first order formula with occurences of x. x is the result of the translation of a model field x of type t.

Christian Engel JML Model Fields

slide-17
SLIDE 17

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach expressed in JavaDL

Let φ(x) be a first order formula with occurences of x. x is the result of the translation of a model field x of type t. R(x, ˜ q) is the formula provided by the represents clause.

Christian Engel JML Model Fields

slide-18
SLIDE 18

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

The axiomatic approach expressed in JavaDL

Let φ(x) be a first order formula with occurences of x. x is the result of the translation of a model field x of type t. R(x, ˜ q) is the formula provided by the represents clause. Then we get the formula: ∀x′ :t ({x := x′}(A(x) → φ(x))) with A(x) := (∃a:t (R(a, ˜ q))) → R(x, ˜ q)

Christian Engel JML Model Fields

slide-19
SLIDE 19

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Drawbacks of the axiomatic approach

bigger, less readable formulas

Christian Engel JML Model Fields

slide-20
SLIDE 20

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Drawbacks of the axiomatic approach

bigger, less readable formulas not applicable for recursively defined represents clauses

Christian Engel JML Model Fields

slide-21
SLIDE 21

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Drawbacks of the axiomatic approach

bigger, less readable formulas not applicable for recursively defined represents clauses One possible solution: Use Taclets Γ ⊢ φ(x()), ∆

Christian Engel JML Model Fields

slide-22
SLIDE 22

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Drawbacks of the axiomatic approach

bigger, less readable formulas not applicable for recursively defined represents clauses One possible solution: Use Taclets Γ ⊢ φ(x()), ∃x′ :t (R(x′, ˜ q)), ∆ Γ ⊢ φ(x()), ∆

Christian Engel JML Model Fields

slide-23
SLIDE 23

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Drawbacks of the axiomatic approach

bigger, less readable formulas not applicable for recursively defined represents clauses One possible solution: Use Taclets Γ ⊢ φ(x()), ∃x′ :t (R(x′, ˜ q)), ∆ Γ, R(x(),˜ q) ⊢ φ(x()), ∆ Γ ⊢ φ(x()), ∆

Christian Engel JML Model Fields

slide-24
SLIDE 24

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Representing model fields by model methods

Another approach: Model fields are represented by model method that are free of side effects and have a “suitable” specification.

Christian Engel JML Model Fields

slide-25
SLIDE 25

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Representing model fields by model methods

Another approach: Model fields are represented by model method that are free of side effects and have a “suitable” specification. Let φ(x) and R(x, q) be defined as on the previous slides. We get the formula: φ(m()) where m() is the model method associated with R(x, q).

Christian Engel JML Model Fields

slide-26
SLIDE 26

JML What are model fields? Translation to JavaDL Demo Axiomatic approach Interpretation as model methods/queries

Representing model fields by model methods

The specification of m(): /*@ public normal_behavior @ requires (\exists t x; R(x,q)); @ assignable \nothing; @ ensures R(\result, q); @*/

Christian Engel JML Model Fields

slide-27
SLIDE 27

JML What are model fields? Translation to JavaDL Demo

Demo

Christian Engel JML Model Fields

slide-28
SLIDE 28

JML What are model fields? Translation to JavaDL Demo

The interface LimitedIntContainer

public interface LimitedIntContainer{ /*@ @ public model int value; @ public model boolean regularState; @*/ /*@ public normal_behavior @ ensures regularState ==> \result == value; @*/ int /*@ pure @*/ available(); }

Christian Engel JML Model Fields

slide-29
SLIDE 29

JML What are model fields? Translation to JavaDL Demo

The class PayCard

public class PayCard implements LimitedIntContainer{ /*@ public represents value <- balance; @ public represents regularState <- @ (unsuccessfulOperations <= 3); @*/ public /*@pure@*/ int available() { if (unsuccessfulOperations<=3) return balance; return 0; } ... }

Christian Engel JML Model Fields