Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
LARA
inox
Commits
7c5040bc
Commit
7c5040bc
authored
9 years ago
by
Mikaël Mayer
Browse files
Options
Downloads
Patches
Plain Diff
Factorized env function.
parent
edb9edb2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/leon/evaluators/Evaluator.scala
+12
-2
12 additions, 2 deletions
src/main/scala/leon/evaluators/Evaluator.scala
src/test/scala/leon/test/helpers/WithLikelyEq.scala
+2
-2
2 additions, 2 deletions
src/test/scala/leon/test/helpers/WithLikelyEq.scala
with
14 additions
and
4 deletions
src/main/scala/leon/evaluators/Evaluator.scala
+
12
−
2
View file @
7c5040bc
...
...
@@ -51,7 +51,7 @@ trait DeterministicEvaluator extends Evaluator {
final
def
evalEnvExpr
(
expr
:
Expr
,
mapping
:
Iterable
[(
Identifier
,
Expr
)])
:
EvaluationResult
=
{
if
(
mapping
.
forall
{
case
(
key
,
value
)
=>
purescala
.
ExprOps
.
isValue
(
value
)
})
{
eval
(
expr
,
mapping
.
toMap
)
}
else
(
evalEnv
(
mapping
)
match
{
}
else
(
_
evalEnv
(
mapping
)
match
{
case
Left
(
m
)
=>
eval
(
expr
,
m
)
case
Right
(
errorMessage
)
=>
val
m
=
mapping
.
filter
{
case
(
k
,
v
)
=>
purescala
.
ExprOps
.
isValue
(
v
)
}.
toMap
...
...
@@ -62,9 +62,19 @@ trait DeterministicEvaluator extends Evaluator {
})
}
/** Returns an evaluated environment. If it fails, removes all non-values from the environment. */
def
evalEnv
(
mapping
:
Iterable
[(
Identifier
,
Expr
)])
:
Map
[
Identifier
,
Value
]
=
{
if
(
mapping
.
forall
{
case
(
key
,
value
)
=>
purescala
.
ExprOps
.
isValue
(
value
)
})
{
mapping
.
toMap
}
else
(
_evalEnv
(
mapping
)
match
{
case
Left
(
m
)
=>
m
case
Right
(
msg
)
=>
mapping
.
filter
(
x
=>
purescala
.
ExprOps
.
isValue
(
x
.
_2
)).
toMap
})
}
/** From a not yet well evaluated context with dependencies between variables, returns a head where all exprs are values (as a Left())
* If this does not succeed, it provides an error message as Right()*/
private
def
evalEnv
(
mapping
:
Iterable
[(
Identifier
,
Expr
)])
:
Either
[
Map
[
Identifier
,
Value
]
,
String
]
=
{
private
def
_
evalEnv
(
mapping
:
Iterable
[(
Identifier
,
Expr
)])
:
Either
[
Map
[
Identifier
,
Value
]
,
String
]
=
{
var
f
=
mapping
.
toSet
var
mBuilder
=
collection
.
mutable
.
ListBuffer
[(
Identifier
,
Value
)]()
var
changed
=
true
...
...
This diff is collapsed.
Click to expand it.
src/test/scala/leon/test/helpers/WithLikelyEq.scala
+
2
−
2
View file @
7c5040bc
...
...
@@ -44,9 +44,9 @@ trait WithLikelyEq {
val
allValues
=
freeVars
.
map
(
id
=>
values
.
get
(
id
).
map
(
Seq
(
_
)).
getOrElse
(
typesValues
(
id
.
getType
)))
cartesianProduct
(
allValues
).
foreach
{
vs
=>
val
m
=
(
freeVars
zip
vs
)
.
toMap
val
m
=
evaluator
.
evalEnv
(
freeVars
zip
vs
)
val
doTest
=
pre
.
map
{
p
=>
evaluator
.
eval
EnvExpr
(
p
,
m
).
result
match
{
evaluator
.
eval
(
p
,
m
).
result
match
{
case
Some
(
BooleanLiteral
(
b
))
=>
b
case
_
=>
fail
(
"Precondition is not a boolean expression"
)
}
...
...
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