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
96fb0437
Commit
96fb0437
authored
8 years ago
by
koen
Browse files
Options
Downloads
Patches
Plain Diff
more array examples
parent
a875c69a
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
+1
-1
1 addition, 1 deletion
Settings.hs
Tests/arrays2.java
+31
-0
31 additions, 0 deletions
Tests/arrays2.java
Tests/arrays3.java
+43
-0
43 additions, 0 deletions
Tests/arrays3.java
WLP.hs
+2
-1
2 additions, 1 deletion
WLP.hs
with
77 additions
and
2 deletions
Settings.hs
+
1
−
1
View file @
96fb0437
module
Settings
where
module
Settings
where
testFile
,
postCond
::
String
testFile
,
postCond
::
String
testFile
=
"arrays
1
"
testFile
=
"arrays
3
"
postCond
=
"(true)"
postCond
=
"(true)"
nrOfUnroll
::
Int
nrOfUnroll
::
Int
...
...
This diff is collapsed.
Click to expand it.
Tests/arrays2.java
0 → 100644
+
31
−
0
View file @
96fb0437
//https://www.tutorialspoint.com/java/java_arrays.htm
public
class
TestArray
{
public
static
void
main
(
String
[]
args
)
{
double
[]
myList
=
new
double
[
4
];
myList
[
0
]
=
1.9
;
myList
[
1
]
=
2.9
;
myList
[
2
]
=
3.4
;
myList
[
3
]
=
3.5
;
// Print all the array elements
for
(
int
i
=
0
;
i
<
myList
.
length
;
i
++)
{
System
.
out
.
println
(
myList
[
i
]
+
" "
);
}
// Summing all elements
double
total
=
0
;
for
(
int
j
=
0
;
j
<
myList
.
length
;
j
++)
{
total
+=
myList
[
j
];
}
System
.
out
.
println
(
"Total is "
+
total
);
// Finding the largest element
double
max
=
myList
[
0
];
for
(
int
k
=
1
;
k
<
myList
.
length
;
k
++)
{
if
(
myList
[
k
]
>
max
)
max
=
myList
[
k
];
}
System
.
out
.
println
(
"Max is "
+
max
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Tests/arrays3.java
0 → 100644
+
43
−
0
View file @
96fb0437
//https://examples.javacodegeeks.com/java-basics/arrays-java-basics/java-string-array-example/
package
com.javacodegeeks.javabasics.stringarray
;
public
class
JavaStringArrayExample
{
public
static
void
main
(
String
args
[])
{
// declare a string array with initial size
String
[]
schoolbag
=
new
String
[
4
];
// add elements to the array
schoolbag
[
0
]
=
"Books"
;
schoolbag
[
1
]
=
"Pens"
;
schoolbag
[
2
]
=
"Pencils"
;
schoolbag
[
3
]
=
"Notebooks"
;
// this will cause ArrayIndexOutOfBoundsException
// schoolbag[4] = "Notebooks";
// declare a string array with no initial size
// String[] schoolbag;
// declare string array and initialize with values in one step
String
[]
schoolbag2
=
new
String
[
4
];
schoolbag2
[
0
]
=
"Books"
;
schoolbag2
[
1
]
=
"Pens"
;
schoolbag2
[
2
]
=
"Pencils"
;
schoolbag2
[
3
]
=
"Notebooks"
;
// print the third element of the string array
System
.
out
.
println
(
"The third element is: "
+
schoolbag2
[
2
]);
// iterate all the elements of the array
int
size
=
schoolbag2
.
length
;
System
.
out
.
println
(
"The size of array is: "
+
size
);
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
System
.
out
.
println
(
"Index["
+
i
+
"] = "
+
schoolbag2
[
i
]);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
WLP.hs
+
2
−
1
View file @
96fb0437
...
@@ -87,6 +87,7 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
...
@@ -87,6 +87,7 @@ wlpStmtAlgebra = (fStmtBlock, fIfThen, fIfThenElse, fWhile, fBasicFor, fEnhanced
-- We don't initialize ref types to null, because we want to keep pointer information
-- We don't initialize ref types to null, because we want to keep pointer information
RefType
_
->
acc
inh
RefType
_
->
acc
inh
wlpDeclAssignment
t
inh
(
VarDecl
(
VarId
ident
)
(
Just
(
InitExp
e
)))
=
snd
(
foldExp
wlpExpAlgebra
(
Assign
(
NameLhs
(
Name
[
ident
]))
EqualA
e
)
inh
)
wlpDeclAssignment
t
inh
(
VarDecl
(
VarId
ident
)
(
Just
(
InitExp
e
)))
=
snd
(
foldExp
wlpExpAlgebra
(
Assign
(
NameLhs
(
Name
[
ident
]))
EqualA
e
)
inh
)
wlpDeclAssignment
_
_
_
=
error
"ArrayCreateInit is not supported"
-- Unrolls a while-loop a finite amount of times
-- Unrolls a while-loop a finite amount of times
unrollLoop
::
Inh
->
Int
->
Exp
->
(
Exp
->
Exp
)
->
(
Exp
->
Exp
)
->
Exp
->
Exp
unrollLoop
::
Inh
->
Int
->
Exp
->
(
Exp
->
Exp
)
->
(
Exp
->
Exp
)
->
Exp
->
Exp
...
@@ -159,7 +160,7 @@ wlpExpAlgebra = (fLit, fClassLit, fThis, fThisClass, fInstanceCreation, fQualIns
...
@@ -159,7 +160,7 @@ wlpExpAlgebra = (fLit, fClassLit, fThis, fThisClass, fInstanceCreation, fQualIns
in
(
ExpName
var
,
(
substVar
(
env
inh
)
(
decls
inh
)
(
NameLhs
var
)
(
InstanceCreation
typeArgs
t
[
ExpName
(
Name
[
Ident
"#"
])]
mBody
)
.
snd
((
fMethodInv
invocation
)
inh
{
acc
=
id
})
.
acc
inh
))
in
(
ExpName
var
,
(
substVar
(
env
inh
)
(
decls
inh
)
(
NameLhs
var
)
(
InstanceCreation
typeArgs
t
[
ExpName
(
Name
[
Ident
"#"
])]
mBody
)
.
snd
((
fMethodInv
invocation
)
inh
{
acc
=
id
})
.
acc
inh
))
fQualInstanceCreation
e
typeArgs
t
args
mBody
inh
=
error
"fQualInstanceCreation"
fQualInstanceCreation
e
typeArgs
t
args
mBody
inh
=
error
"fQualInstanceCreation"
fArrayCreate
t
dimLengths
dim
inh
=
(
ArrayCreate
t
(
map
(
\
e
->
fst
(
e
inh
))
dimLengths
)
dim
,
acc
inh
)
fArrayCreate
t
dimLengths
dim
inh
=
(
ArrayCreate
t
(
map
(
\
e
->
fst
(
e
inh
))
dimLengths
)
dim
,
acc
inh
)
fArrayCreateInit
t
dim
init
inh
=
(
ArrayCreateInit
t
dim
init
,
acc
inh
)
fArrayCreateInit
t
dim
init
inh
=
error
"ArrayCreateInit"
--
(ArrayCreateInit t dim init, acc inh)
fFieldAccess
fieldAccess
inh
=
(
ExpName
(
foldFieldAccess
inh
fieldAccess
),
(
acc
inh
))
fFieldAccess
fieldAccess
inh
=
(
ExpName
(
foldFieldAccess
inh
fieldAccess
),
(
acc
inh
))
fMethodInv
invocation
inh
=
case
invocation
of
fMethodInv
invocation
inh
=
case
invocation
of
MethodCall
(
Name
[
Ident
"*assume"
])
[
e
]
->
(
false
,
(
if
e
==
false
then
const
true
else
imp
e
))
-- *assume is the regular assume function
MethodCall
(
Name
[
Ident
"*assume"
])
[
e
]
->
(
false
,
(
if
e
==
false
then
const
true
else
imp
e
))
-- *assume is the regular assume function
...
...
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