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
dcd92c6a
Commit
dcd92c6a
authored
8 years ago
by
koen
Browse files
Options
Downloads
Patches
Plain Diff
switch example
parent
9f88a91d
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Settings.hs
+2
-2
2 additions, 2 deletions
Settings.hs
Tests/switch.java
+20
-0
20 additions, 0 deletions
Tests/switch.java
Tests/try-catch-finally.java
+1
-1
1 addition, 1 deletion
Tests/try-catch-finally.java
WLP.hs
+13
-7
13 additions, 7 deletions
WLP.hs
with
36 additions
and
10 deletions
Settings.hs
+
2
−
2
View file @
dcd92c6a
module
Settings
where
testFile
=
"
test
"
postCond
=
"
true
"
testFile
=
"
switch
"
postCond
=
"
x == 2
"
invariant
=
"true"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Tests/switch.java
0 → 100644
+
20
−
0
View file @
dcd92c6a
public
class
Class
{
public
static
void
main
(
String
[]
args
)
{
int
x
,
y
;
y
=
0
;
switch
(
y
)
{
case
0
:
x
=
0
;
case
1
:
x
=
1
;
break
;
case
2
:
x
=
2
;
break
;
default
:
x
=
2
;
break
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Tests/try-catch-finally.java
+
1
−
1
View file @
dcd92c6a
...
...
@@ -8,7 +8,7 @@ class MyExc3 extends MyExc2 {}
public
class
C1
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
try
{
x
=
1
;
int
x
=
1
;
try
{
...
...
This diff is collapsed.
Click to expand it.
WLP.hs
+
13
−
7
View file @
dcd92c6a
...
...
@@ -107,13 +107,19 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
-- 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
++
[
BlockStmt
sbscode
])),
sbscode
)
where
sbscode
=
let
(
e
,
s1
,
s2
)
=
desugarSwitch
e
sbs
in
IfThenElse
e
s1
s2
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
sbs
@
(
SwitchBlock
l
bs
:
sbs'
)
=
case
l
of
SwitchCase
e'
->
(
BinOp
e
Equal
e'
,
StmtBlock
(
switchBlockToBlock
sbs
),
otherCases
)
Default
->
(
true
,
StmtBlock
(
switchBlockToBlock
sbs
),
otherCases
)
where
otherCases
=
let
(
e'
,
s1
,
s2
)
=
desugarSwitch
e
sbs'
in
IfThenElse
e'
s1
s2
-- Gets the statements from a switch statement
switchBlockToBlock
::
[
SwitchBlock
]
->
Block
switchBlockToBlock
[]
=
Block
[]
switchBlockToBlock
(
SwitchBlock
l
bs
:
sbs
)
=
case
switchBlockToBlock
sbs
of
Block
b
->
Block
(
bs
++
b
)
throwException
::
Exp
->
Exp
throwException
e
=
false
...
...
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