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
a2280006
Commit
a2280006
authored
8 years ago
by
Mikaël Mayer
Committed by
Ravi
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added postFlatmap for all tree operations.
parent
08a4c48c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/purescala/GenTreeOps.scala
+49
-1
49 additions, 1 deletion
src/main/scala/leon/purescala/GenTreeOps.scala
with
49 additions
and
1 deletion
src/main/scala/leon/purescala/GenTreeOps.scala
+
49
−
1
View file @
a2280006
...
@@ -186,9 +186,57 @@ trait GenTreeOps[SubTree <: Tree] {
...
@@ -186,9 +186,57 @@ trait GenTreeOps[SubTree <: Tree] {
}
else
{
}
else
{
f
(
newV
)
getOrElse
newV
f
(
newV
)
getOrElse
newV
}
}
}
}
/** Post-transformation of the tree using flattening methods.
*
* Takes a partial function of replacements.
* Substitutes '''after''' recursing down the trees.
*
* Supports two modes :
*
* - If applyRec is false (default), will only substitute once on each level.
* e.g.
* {{{
* Add(a, Minus(b, c)) with replacements: Minus(b,c) -> z, Minus(e,c) -> d, b -> e
* }}}
* will yield:
* {{{
* Add(a, Minus(e, c))
* }}}
*
* - If applyRec is true, it will substitute multiple times on each level:
* e.g.
* {{{
* Add(a, Minus(b, c)) with replacements: Minus(e,c) -> d, b -> e, d -> f
* }}}
* will yield:
* {{{
* Add(a, f)
* }}}
*
* @note The mode with applyRec true can diverge if f is not well formed (i.e. not convergent)
*/
def
postFlatmap
(
f
:
SubTree
=>
Option
[
Seq
[
SubTree
]],
applyRec
:
Boolean
=
false
)(
e
:
SubTree
)
:
Seq
[
SubTree
]
=
{
val
rec
=
postFlatmap
(
f
,
applyRec
)
_
val
Deconstructor
(
es
,
builder
)
=
e
val
newEss
=
es
.
map
(
rec
)
val
newVs
:
Seq
[
SubTree
]
=
leon
.
utils
.
SeqUtils
.
cartesianProduct
(
newEss
).
map
{
newEs
=>
if
((
newEs
zip
es
).
exists
{
case
(
bef
,
aft
)
=>
aft
ne
bef
})
{
builder
(
newEs
).
copiedFrom
(
e
)
}
else
{
e
}
}
if
(
applyRec
)
{
// Apply f as long as it returns Some()
fixpoint
{
(
e
:
Seq
[
SubTree
])
=>
e
.
flatMap
(
newV
=>
f
(
newV
)
getOrElse
Seq
(
newV
))
}
(
newVs
)
}
else
{
newVs
.
flatMap
((
newV
:
SubTree
)
=>
f
(
newV
)
getOrElse
Seq
(
newV
))
}
}
/** Applies functions and combines results in a generic way
/** Applies functions and combines results in a generic way
*
*
...
...
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