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
1a5b63df
Commit
1a5b63df
authored
9 years ago
by
Mikaël Mayer
Browse files
Options
Downloads
Patches
Plain Diff
Added a way to add examples to the postcondition of functions.
parent
32eb10be
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/synthesis/ExamplesAdder.scala
+63
-0
63 additions, 0 deletions
src/main/scala/leon/synthesis/ExamplesAdder.scala
with
63 additions
and
0 deletions
src/main/scala/leon/synthesis/ExamplesAdder.scala
0 → 100644
+
63
−
0
View file @
1a5b63df
/* Copyright 2009-2015 EPFL, Lausanne */
package
leon
package
synthesis
import
leon.LeonContext
import
leon.purescala.Expressions._
import
purescala.Common.FreshIdentifier
import
purescala.Constructors.
{
and
,
tupleWrap
}
import
purescala.Definitions.
{
FunDef
,
Program
,
ValDef
}
import
purescala.ExprOps.expressionToPattern
import
purescala.Expressions.
{
BooleanLiteral
,
Equals
,
Expr
,
Lambda
,
MatchCase
,
Passes
,
Variable
,
WildcardPattern
}
import
purescala.Extractors.TopLevelAnds
/**
* @author Mikael
*/
class
ExamplesAdder
(
ctx0
:
LeonContext
,
program
:
Program
)
{
/** Adds the given input/output examples to the function definitions */
def
addToFunDef
(
fd
:
FunDef
,
examples
:
Seq
[(
Expr
,
Expr
)])
=
{
val
inputVariables
=
tupleWrap
(
fd
.
params
.
map
(
p
=>
Variable
(
p
.
id
)
:
Expr
))
val
newCases
=
examples
.
map
{
case
(
in
,
out
)
=>
exampleToCase
(
in
,
out
)
}
fd
.
postcondition
match
{
case
Some
(
Lambda
(
Seq
(
ValDef
(
id
,
tpe
)),
post
))
=>
if
(
fd
.
postcondition
.
exists
{
e
=>
purescala
.
ExprOps
.
exists
(
_
.
isInstanceOf
[
Passes
])(
e
)
})
{
post
match
{
case
TopLevelAnds
(
exprs
)
=>
val
i
=
exprs
.
lastIndexWhere
{
x
=>
x
match
{
case
Passes
(
in
,
out
,
cases
)
if
in
==
inputVariables
&&
out
==
Variable
(
id
)
=>
true
case
_
=>
false
}
}
if
(
i
==
-
1
)
{
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
,
tpe
)),
and
(
post
,
Passes
(
inputVariables
,
Variable
(
id
),
newCases
))))
}
else
{
val
newPasses
=
exprs
(
i
)
match
{
case
Passes
(
in
,
out
,
cases
)
=>
Passes
(
in
,
out
,
cases
++
newCases
)
case
_
=>
???
}
val
newPost
=
and
(
exprs
.
updated
(
i
,
newPasses
)
:
_
*
)
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
,
tpe
)),
newPost
))
}
}
}
else
{
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
,
tpe
)),
and
(
post
,
Passes
(
inputVariables
,
Variable
(
id
),
newCases
))))
}
case
None
=>
val
id
=
FreshIdentifier
(
"res"
,
fd
.
returnType
,
false
)
fd
.
postcondition
=
Some
(
Lambda
(
Seq
(
ValDef
(
id
,
None
)),
Passes
(
inputVariables
,
Variable
(
id
),
newCases
)))
}
}
private
def
exampleToCase
(
in
:
Expr
,
out
:
Expr
)
:
MatchCase
=
{
val
(
inPattern
,
inGuard
)
=
expressionToPattern
(
in
)
if
(
inGuard
!=
BooleanLiteral
(
true
))
{
val
id
=
FreshIdentifier
(
"out"
,
in
.
getType
,
true
)
MatchCase
(
WildcardPattern
(
Some
(
id
)),
Some
(
Equals
(
Variable
(
id
),
in
)),
out
)
}
else
{
MatchCase
(
inPattern
,
None
,
out
)
}
}
}
\ No newline at end of file
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