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
928b4793
Commit
928b4793
authored
13 years ago
by
Régis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
capture binding variables of pattern matching
parent
e4de585f
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/FunctionClosure.scala
+12
-8
12 additions, 8 deletions
src/main/scala/leon/FunctionClosure.scala
with
12 additions
and
8 deletions
src/main/scala/leon/FunctionClosure.scala
+
12
−
8
View file @
928b4793
...
@@ -118,17 +118,19 @@ object FunctionClosure extends Pass {
...
@@ -118,17 +118,19 @@ object FunctionClosure extends Pass {
val
scrutRec
=
functionClosure
(
scrut
,
bindedVars
,
id2freshId
,
fd2FreshFd
)
val
scrutRec
=
functionClosure
(
scrut
,
bindedVars
,
id2freshId
,
fd2FreshFd
)
val
csesRec
=
cses
.
map
{
val
csesRec
=
cses
.
map
{
case
SimpleCase
(
pat
,
rhs
)
=>
{
case
SimpleCase
(
pat
,
rhs
)
=>
{
val
binders
=
pat
.
binders
val
cond
=
conditionForPattern
(
scrut
,
pat
)
val
cond
=
conditionForPattern
(
scrut
,
pat
)
pathConstraints
::=
cond
pathConstraints
::=
cond
val
rRhs
=
functionClosure
(
rhs
,
bindedVars
,
id2freshId
,
fd2FreshFd
)
val
rRhs
=
functionClosure
(
rhs
,
bindedVars
++
binders
,
id2freshId
,
fd2FreshFd
)
pathConstraints
=
pathConstraints
.
tail
pathConstraints
=
pathConstraints
.
tail
SimpleCase
(
pat
,
rRhs
)
SimpleCase
(
pat
,
rRhs
)
}
}
case
GuardedCase
(
pat
,
guard
,
rhs
)
=>
{
case
GuardedCase
(
pat
,
guard
,
rhs
)
=>
{
val
binders
=
pat
.
binders
val
cond
=
conditionForPattern
(
scrut
,
pat
)
val
cond
=
conditionForPattern
(
scrut
,
pat
)
pathConstraints
::=
cond
pathConstraints
::=
cond
val
rRhs
=
functionClosure
(
rhs
,
bindedVars
,
id2freshId
,
fd2FreshFd
)
val
rRhs
=
functionClosure
(
rhs
,
bindedVars
++
binders
,
id2freshId
,
fd2FreshFd
)
val
rGuard
=
functionClosure
(
guard
,
bindedVars
,
id2freshId
,
fd2FreshFd
)
val
rGuard
=
functionClosure
(
guard
,
bindedVars
++
binders
,
id2freshId
,
fd2FreshFd
)
pathConstraints
=
pathConstraints
.
tail
pathConstraints
=
pathConstraints
.
tail
GuardedCase
(
pat
,
rGuard
,
rRhs
)
GuardedCase
(
pat
,
rGuard
,
rRhs
)
}
}
...
@@ -140,15 +142,17 @@ object FunctionClosure extends Pass {
...
@@ -140,15 +142,17 @@ object FunctionClosure extends Pass {
case
None
=>
v
case
None
=>
v
case
Some
(
nid
)
=>
Variable
(
nid
)
case
Some
(
nid
)
=>
Variable
(
nid
)
}
}
/*replace(
id2freshId.map(p => (p._1.toVariable, p._2.toVariable)),
enclosingLets.foldLeft(v: Expr){
case (expr, (id, value)) => replace(Map(id.toVariable -> value), expr)
})*/
case
t
if
t
.
isInstanceOf
[
Terminal
]
=>
t
case
t
if
t
.
isInstanceOf
[
Terminal
]
=>
t
case
unhandled
=>
scala
.
sys
.
error
(
"Non-terminal case should be handled in FunctionClosure: "
+
unhandled
)
case
unhandled
=>
scala
.
sys
.
error
(
"Non-terminal case should be handled in FunctionClosure: "
+
unhandled
)
}
}
def
freshIdInPat
(
pat
:
Pattern
,
id2freshId
:
Map
[
Identifier
,
Identifier
])
:
Pattern
=
pat
match
{
case
InstanceOfPattern
(
binder
,
classTypeDef
)
=>
InstanceOfPattern
(
binder
.
map
(
id2freshId
(
_
)),
classTypeDef
)
case
WildcardPattern
(
binder
)
=>
WildcardPattern
(
binder
.
map
(
id2freshId
(
_
)))
case
CaseClassPattern
(
binder
,
caseClassDef
,
subPatterns
)
=>
CaseClassPattern
(
binder
.
map
(
id2freshId
(
_
)),
caseClassDef
,
subPatterns
.
map
(
freshIdInPat
(
_
,
id2freshId
)))
case
TuplePattern
(
binder
,
subPatterns
)
=>
TuplePattern
(
binder
.
map
(
id2freshId
(
_
)),
subPatterns
.
map
(
freshIdInPat
(
_
,
id2freshId
)))
}
//filter the list of constraints, only keeping those relevant to the set of variables
//filter the list of constraints, only keeping those relevant to the set of variables
def
filterConstraints
(
vars
:
Set
[
Identifier
])
:
(
List
[
Expr
],
Set
[
Identifier
])
=
{
def
filterConstraints
(
vars
:
Set
[
Identifier
])
:
(
List
[
Expr
],
Set
[
Identifier
])
=
{
var
allVars
=
vars
var
allVars
=
vars
...
...
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