Composite Objects in VDMSL - PowerPoint PPT Presentation

1 / 86
About This Presentation
Title:

Composite Objects in VDMSL

Description:

Use the composite object operators (make, selection and mu) Add an invariant to a ... Analysing the Block type further. Block. track: Integer. sector: Integer ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 87
Provided by: aaron63
Category:

less

Transcript and Presenter's Notes

Title: Composite Objects in VDMSL


1
Composite Objects in VDM-SL
2
Learning Outcomes
  • Identify when it is appropriate to use a
    composite object type
  • Use the composite object operators (make,
    selection and mu)
  • Add an invariant to a composite object type
  • Use the composite object type to help model
    systems in VDM-SL
  • Use a letin clause to simplify expressions in
    VDM-SL

3
So far
4
.. we have always associated a single type with
each item of data in our VDM specifications.
temp ? robot Status permission
Aircraft-set
5
Composite Types..
.. allow us to associate more than one type
with an object.
6
Defining Composite Object Types
types
TypeName

fieldname1
Type1
fieldname2
Type2

7
The Time Type
8
types
TypeName

fieldname1
Type1
fieldname2
Type2

9
types
Time

fieldname1
Type1
fieldname2
Type2

10
types
Time

hour
Type1
fieldname2
Type2

11
types
Time

hour
Type1
minute
Type2

12
types
Time

hour
Type1
minute
Type2
second
13
types
?
Time

hour
minute
Type2
second
14
types
?
Time

hour
minute
?
second
15
types
?
Time

hour
minute
?
second
?
16
This Time type can now be used like any other
type in your specification
someTime Time
importantTimes Time-set
17
Composite object operators
18
The make function
The make function that creates a new object of a
given composite type.
mk-CompositeObjectTypeName (parameter list)
Returning to the Time example
someTime mk-Time ( )
16
, 20
, 44
19
someTime mk-Time (36, 20, 44)
20
someTime mk-Time (36, 20, 44)
This should not be a valid time value?
21
someTime mk-Time (36, 20, 44)
Add an invariant to your object definition to
make these times invalid!
22
Time hour ? minute ? second ? inv
mk-Time (h, m, s) ?
h lt 24 ? m lt 60 ? s lt 60
23
Composite object selectors
We can refer to a particular field of a composite
object by using a selector operator. Individual
fields are selected by the dot operator '.'
followed by the name of a field. For example
someTime.minute someTime.hour
20
16
24
The mu function
The mu function returns one composite object from
another but with one or more fields changed.
newTime ? (someTime, hour ? 15)
thisTime ? (someTime, minute ? 0, second ? 0)
25
The DiskScanner class
26
The DiskScanner class
TRACKS
27
The DiskScanner class
SECTORS
28
The DiskScanner class
BLOCKS
29
DiskScanner damagedBlocks Block
addBlock(Integer, Integer) removeBlock
(Integer, Integer) isDamaged(Integer, Integer)
Boolean getBadSectors(Integer) Integer
30
DiskScanner damagedBlocks Block
addBlock(Integer, Integer) removeBlock
(Integer, Integer) isDamaged(Integer, Integer)
Boolean getBadSectors(Integer) Integer
31
Analysing the Block type further
Block track Integer sector Integer
32
Specifying the data model in VDM-SL
33
types state DiskScanner
of damagedBlocks init mk-DiskScanner (dB)
? end
Block track sector
?
?
Block-set
dB
34
DiskScanner damagedBlocks Block
addBlock(Integer, Integer) removeBlock
(Integer, Integer) isDamaged(Integer, Integer)
Boolean getBadSectors(Integer) Integer
35
addBlock (
) ext pre post
trackIn ?, sectorIn ?
wr
damagedBlocks Block-set
36
addBlock (
) ext pre post
trackIn ?, sectorIn ?
wr
damagedBlocks Block-set
37
addBlock (
) ext pre post
trackIn ?, sectorIn ?
wr
damagedBlocks Block-set
mk-Block (trackIn, sectorIn) ? damagedBlocks
38
DiskScanner damagedBlocks Block
addBlock(Integer, Integer) removeBlock
(Integer, Integer) isDamaged(Integer, Integer)
Boolean getBadSectors(Integer) Integer
39
removeBlock (
) ext pre post
trackIn ?, sectorIn ?
wr
damagedBlocks Block-set
mk-Block (trackIn, sectorIn) ? damagedBlocks
40
DiskScanner damagedBlocks Block
addBlock(Integer, Integer) removeBlock
(Integer, Integer) isDamaged(Integer, Integer)
Boolean getBadSectors(Integer) Integer
41
isDamaged (
) ext pre post
trackIn ?, sectorIn ?
query ?
damagedBlocks Block-set
rd
TRUE
query
?
mk-Block (trackIn, sectorIn) ? damagedBlocks
42
DiskScanner damagedBlocks Block
addBlock(Integer, Integer) removeBlock
(Integer, Integer) isDamaged(Integer, Integer)
Boolean getBadSectors(Integer) Integer
43
getBadSectors ( )
ext pre post
trackIn ?
list ?-set
rd
damagedBlocks Block-set
TRUE

?

b ? damagedBlocks
b.sector
?
?
list
b.track trackIn
?
44
A process management system
45
timeout
admit
terminate
dispatch
block
wakeup
46
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
47
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
48
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
49
id ID status Status
50
id ID status Status
51
READY BLOCKED
52
Specifying the types in VDM-SL
53
types
ID
TOKEN
Status
ltREADYgt ltBLOCKEDgt
ID
Process

id
Status
status
54
Specifying the state in VDM-SL
55
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ?
init mk-ProcessManagement (run, wait) ?
end
ID
Process-set
56
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ?
init mk-ProcessManagement (run, wait) ?
end
ID
Process
57
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ? init
mk-ProcessManagement (run, wait) ?
end
ID
Process
run nil ? wait
58
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ? init
mk-ProcessManagement (run, wait) ?
end
ID
Process
run nil ? wait
59
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ? init
mk-ProcessManagement (run, wait) ?
end
ID
Process
P2
run nil ? wait
60
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ? (

) (

) init
mk-ProcessManagement (run, wait) ?
end
ID
Process
no waiting id should match the running id
?
the ids in the waiting queue should be unique
run nil ? wait
61
no waiting id should match the running id
P2
run
wait
?
??p ? elems wait ? p.id run
run nil
62
no waiting id should match the running id
P2
run
wait
?
??i ? inds wait ? wait(i).id run
run nil
63
the ids in the waiting queue should be unique
P2
run
wait
card elems wait len wait
64
the ids in the waiting queue should be unique
P2
run
wait
? i,j ? inds wait ? i ? j ? wait(i).id ?
wait(j).id
65
state ProcessManagement of running waiting inv
mk-ProcessManagement (run, wait) ? (

) (

) init
mk-ProcessManagement (run, wait) ?
end
ID
Process
??i ? inds wait ? wait(i).id run
run nil
?
?
? i,j ? inds wait ? i ? j ? wait(i).id ?
wait(j).id
run nil ? wait
66
Specifying a findPos function
P6
3
67
Specifying a findPos function
findPos(qIn Process, idIn ID) pos ? pre ?p
? elems qIn ? p.id idIn post qIn(pos).id
idIn
68
Specifying a findNext function
2
69
Specifying a findNext function
qIn Process
findNext( ) pre post
pos ?
?p ? elems qIn ? p.status ltREADYgt
?
qIn(pos).status ltREADYgt
??i ? 1,,pos-1 ? qIn(i).status ltREADYgt
70
Specifying a remove function
2
71
Specifying a remove function
remove(qIn Process, posIn ?) qOut
Process pre posIn ? inds qIn post qOut
qIn(1,, posIn-1) qIn(posIn1,,len qIn)
72
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
73
admit( idIn ID) ext pre post
waiting Process
wr
running ID
rd
(running nil ? idIn ? running ) ?
?p ? elems waiting ? p.id ? idIn
74
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
75
dispatch() ext pre post
running ID
wr
waiting Process
wr
running nil ?
?p ? elems waiting ? p.status ltREADYgt
76
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
77
timeOut() ext pre post
running ID
wr
waiting Process
wr
running ? nil
? running nil
78
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
79
block() ext pre post
running ID
wr
waiting Process
wr
running ? nil
? running nil
80
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
81
wakeUp( idIn ID) ext pre post
waiting Process
wr
waiting(findPos(waiting, idIn)).status
ltBLOCKEDgt
82
ProcessManagament running ID waiting
Process admit(ID) dispatch() timeOut() block()
wakeUp(ID) terminate()
83
terminate() ext pre post
running ID
wr
running ? nil
running nil
84
The letin clause
A letin clause takes the following general form
let name sub-expression in expression(name)
85
Re-writing postcondition of dispatch
86
Nested letin clauses
Write a Comment
User Comments (0)
About PowerShow.com