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
4ec4aec2
Commit
4ec4aec2
authored
10 years ago
by
Emmanouil (Manos) Koukoutos
Committed by
Etienne Kneuss
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Function mapping
parent
a0dff8f4
Branches
Branches containing commit
Tags
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/FunctionMapping.scala
+68
-0
68 additions, 0 deletions
src/main/scala/leon/purescala/FunctionMapping.scala
with
68 additions
and
0 deletions
src/main/scala/leon/purescala/FunctionMapping.scala
0 → 100644
+
68
−
0
View file @
4ec4aec2
/* Copyright 2009-2014 EPFL, Lausanne */
package
leon
package
purescala
import
Common._
import
Definitions._
import
Trees._
import
Extractors._
import
TreeOps._
import
TypeTrees._
abstract
class
FunctionMapping
extends
TransformationPhase
{
val
functionToFunction
:
Map
[
FunDef
,
FunctionTransformer
]
case
class
FunctionTransformer
(
to
:
FunDef
,
onArgs
:
Seq
[
Expr
]
=>
List
[
Expr
],
onTypes
:
Seq
[
TypeTree
]
=>
List
[
TypeTree
]
)
val
name
=
"Function Mapping"
val
description
=
"Replace functions and their invocations according to a given mapping"
private
def
replaceCalls
(
e
:
Expr
)
:
Expr
=
preMap
{
case
fi
@FunctionInvocation
(
TypedFunDef
(
fd
,
tps
),
args
)
if
functionToFunction
contains
fd
=>
val
FunctionTransformer
(
to
,
onArgs
,
onTypes
)
=
functionToFunction
(
fd
)
Some
(
FunctionInvocation
(
TypedFunDef
(
to
,
onTypes
(
tps
)),
onArgs
(
args
)).
setPos
(
fi
))
// case MethodInvocation
case
_
=>
None
}(
e
)
def
apply
(
ctx
:
LeonContext
,
program
:
Program
)
:
Program
=
{
val
newP
=
program
.
copy
(
units
=
for
(
u
<-
program
.
units
)
yield
{
u
.
copy
(
modules
=
for
(
m
<-
u
.
modules
)
yield
{
m
.
copy
(
defs
=
for
(
df
<-
m
.
defs
)
yield
{
df
match
{
case
f
:
FunDef
=>
val
newF
=
functionToFunction
.
get
(
f
).
map
{
_
.
to
}.
getOrElse
(
f
)
newF
.
fullBody
=
replaceCalls
(
f
.
fullBody
)
newF
case
c
:
ClassDef
=>
// val oldMethods = c.methods
// c.clearMethods()
// for (m <- oldMethods) {
// c.registerMethod(functionToFunction.get(m).map{_.to}.getOrElse(m))
// }
c
}
})
},
imports
=
u
.
imports
map
{
case
SingleImport
(
fd
:
FunDef
)
=>
SingleImport
(
functionToFunction
.
get
(
fd
).
map
{
_
.
to
}.
getOrElse
(
fd
))
case
other
=>
other
}
)
})
newP
}
}
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