Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
javawlp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
impresshs
javawlp
Commits
cba45c87
Commit
cba45c87
authored
8 years ago
by
koen
Browse files
Options
Downloads
Patches
Plain Diff
switch
parent
a4e4cf39
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
WLP.hs
+14
-4
14 additions, 4 deletions
WLP.hs
with
14 additions
and
4 deletions
WLP.hs
+
14
−
4
View file @
cba45c87
...
...
@@ -75,10 +75,10 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
fBasicFor
init
e
incr
s
inh
@
(
acc
,
_
)
=
wlp'
inh
(
initToStmt
init
)
.
let
loop
=
fWhile
(
fromMaybeGuard
e
)
(
\
inh'
->
s
(
acc
,
loop
)
.
wlp'
inh'
(
incrToStmt
incr
))
inh
in
loop
fEnhancedFor
=
error
"TODO: EnhancedFor"
fEmpty
inh
=
id
fExpStmt
=
undefined
fAssert
=
undefined
fSwitch
=
undefined
fDo
=
undefined
fExpStmt
=
error
"TODO: ExpStmt"
fAssert
e
_
inh
=
(
e
&*
)
fSwitch
e
bs
inh
=
let
(
e'
,
s1
,
s2
)
=
desugarSwitch
e
bs
in
fIfThenElse
e'
(
flip
wlp'
s1
)
(
flip
wlp'
s2
)
inh
fDo
s
e
(
acc
,
_
)
=
let
loop
=
s
(
acc
,
loop
)
.
fWhile
e
s
(
acc
,
loop
)
in
loop
-- Do is just a while with the statement block executed one additional time. Break and continue still have to be handled in this additional execution.
fBreak
_
(
acc
,
_
)
=
acc
fContinue
_
(
acc
,
loop
)
=
loop
.
acc
fReturn
=
undefined
...
...
@@ -112,6 +112,16 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
incrToStmt
Nothing
=
Empty
incrToStmt
(
Just
es
)
=
StmtBlock
(
Block
(
map
(
BlockStmt
.
ExpStmt
)
es
))
-- Converts a switch into nested if-then-else statements. The switch is assumed to be non-trivial.
desugarSwitch
::
Exp
->
[
SwitchBlock
]
->
(
Exp
,
Stmt
,
Stmt
)
desugarSwitch
e
[
SwitchBlock
l
bs
]
=
case
l
of
SwitchCase
e'
->
(
BinOp
e
Equal
e'
,
StmtBlock
(
Block
bs
),
Empty
)
Default
->
(
true
,
StmtBlock
(
Block
bs
),
Empty
)
desugarSwitch
e
(
SwitchBlock
l
bs
:
sbs
)
=
case
l
of
SwitchCase
e'
->
(
BinOp
e
Equal
e'
,
StmtBlock
(
Block
bs
),
sbscode
)
Default
->
(
true
,
StmtBlock
(
Block
bs
),
sbscode
)
where
sbscode
=
let
(
e
,
s1
,
s2
)
=
desugarSwitch
e
sbs
in
IfThenElse
e
s1
s2
true
::
Exp
true
=
Lit
(
Boolean
True
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment