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
46985a88
Commit
46985a88
authored
14 years ago
by
Robin Steiger
Browse files
Options
Downloads
Patches
Plain Diff
Only changed whitespace (using a tool, of course).
parent
b6285436
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/orderedsets/TreeOperations.scala
+35
-36
35 additions, 36 deletions
src/orderedsets/TreeOperations.scala
with
35 additions
and
36 deletions
src/orderedsets/TreeOperations.scala
+
35
−
36
View file @
46985a88
...
...
@@ -9,13 +9,12 @@ import TypeTrees._
import
Definitions._
object
TreeOperations
{
def
dnf
(
expr
:
Expr
)
:
Stream
[
Seq
[
Expr
]]
=
expr
match
{
case
And
(
Nil
)
=>
Stream
(
Nil
)
case
And
(
c
::
Nil
)
=>
dnf
(
c
)
case
And
(
c
::
cs
)
=>
for
(
conj1
<-
dnf
(
c
);
conj2
<-
dnf
(
And
(
cs
)))
yield
conj1
++
conj2
yield
conj1
++
conj2
case
Or
(
Nil
)
=>
Stream
(
Seq
(
BooleanLiteral
(
false
)))
case
Or
(
d
::
Nil
)
=>
dnf
(
d
)
case
Or
(
d
::
ds
)
=>
dnf
(
d
)
append
dnf
(
Or
(
ds
))
...
...
@@ -29,78 +28,78 @@ object TreeOperations {
dnf
(
negate
(
e
))
case
_
=>
Stream
(
expr
::
Nil
)
}
def
searchAndReplace
(
subst
:
Expr
=>
Option
[
Expr
],
recursive
:
Boolean
=
true
)(
expr
:
Expr
)
=
{
def
rec
(
ex
:
Expr
,
skip
:
Expr
=
null
)
:
Expr
=
(
if
(
ex
==
skip
)
None
else
subst
(
ex
))
match
{
def
searchAndReplace
(
subst
:
Expr
=>
Option
[
Expr
],
recursive
:
Boolean
=
true
)(
expr
:
Expr
)
=
{
def
rec
(
ex
:
Expr
,
skip
:
Expr
=
null
)
:
Expr
=
(
if
(
ex
==
skip
)
None
else
subst
(
ex
))
match
{
case
Some
(
newExpr
)
=>
{
if
(
newExpr
.
getType
==
NoType
)
{
Settings
.
reporter
.
warning
(
"REPLACING IN EXPRESSION WITH AN UNTYPED TREE ! "
+
ex
+
" --to--> "
+
newExpr
)
}
if
(
ex
==
newExpr
)
if
(
recursive
)
rec
(
ex
,
ex
)
else
ex
else
if
(
recursive
)
rec
(
newExpr
)
else
newExpr
if
(
newExpr
.
getType
==
NoType
)
{
Settings
.
reporter
.
warning
(
"REPLACING IN EXPRESSION WITH AN UNTYPED TREE ! "
+
ex
+
" --to--> "
+
newExpr
)
}
if
(
ex
==
newExpr
)
if
(
recursive
)
rec
(
ex
,
ex
)
else
ex
else
if
(
recursive
)
rec
(
newExpr
)
else
newExpr
}
case
None
=>
ex
match
{
case
l
@
Let
(
i
,
e
,
b
)
=>
{
case
l
@
Let
(
i
,
e
,
b
)
=>
{
val
re
=
rec
(
e
)
val
rb
=
rec
(
b
)
if
(
re
!=
e
||
rb
!=
b
)
if
(
re
!=
e
||
rb
!=
b
)
Let
(
i
,
re
,
rb
).
setType
(
l
.
getType
)
else
l
}
case
f
@
FunctionInvocation
(
fd
,
args
)
=>
{
case
f
@
FunctionInvocation
(
fd
,
args
)
=>
{
var
change
=
false
val
rargs
=
args
.
map
(
a
=>
{
val
ra
=
rec
(
a
)
if
(
ra
!=
a
)
{
change
=
true
if
(
ra
!=
a
)
{
change
=
true
ra
}
else
{
a
}
}
})
if
(
change
)
if
(
change
)
FunctionInvocation
(
fd
,
rargs
).
setType
(
f
.
getType
)
else
f
}
case
i
@
IfExpr
(
t1
,
t2
,
t3
)
=>
IfExpr
(
rec
(
t1
),
rec
(
t2
),
rec
(
t3
)).
setType
(
i
.
getType
)
case
m
@
MatchExpr
(
scrut
,
cses
)
=>
MatchExpr
(
rec
(
scrut
),
cses
.
map
(
inCase
(
_
))).
setType
(
m
.
getType
)
case
i
@
IfExpr
(
t1
,
t2
,
t3
)
=>
IfExpr
(
rec
(
t1
),
rec
(
t2
),
rec
(
t3
)).
setType
(
i
.
getType
)
case
m
@
MatchExpr
(
scrut
,
cses
)
=>
MatchExpr
(
rec
(
scrut
),
cses
.
map
(
inCase
(
_
))).
setType
(
m
.
getType
)
case
And
(
exs
)
=>
And
(
exs
.
map
(
rec
(
_
)))
case
Or
(
exs
)
=>
Or
(
exs
.
map
(
rec
(
_
)))
case
Not
(
e
)
=>
Not
(
rec
(
e
))
case
u
@
UnaryOperator
(
t
,
recons
)
=>
{
case
u
@
UnaryOperator
(
t
,
recons
)
=>
{
val
r
=
rec
(
t
)
if
(
r
!=
t
)
if
(
r
!=
t
)
recons
(
r
).
setType
(
u
.
getType
)
else
u
}
case
b
@
BinaryOperator
(
t1
,
t2
,
recons
)
=>
{
case
b
@
BinaryOperator
(
t1
,
t2
,
recons
)
=>
{
val
r1
=
rec
(
t1
)
val
r2
=
rec
(
t2
)
if
(
r1
!=
t1
||
r2
!=
t2
)
recons
(
r1
,
r2
).
setType
(
b
.
getType
)
if
(
r1
!=
t1
||
r2
!=
t2
)
recons
(
r1
,
r2
).
setType
(
b
.
getType
)
else
b
}
case
c
@
CaseClass
(
cd
,
args
)
=>
{
case
c
@
CaseClass
(
cd
,
args
)
=>
{
CaseClass
(
cd
,
args
.
map
(
rec
(
_
))).
setType
(
c
.
getType
)
}
case
c
@
CaseClassSelector
(
cc
,
sel
)
=>
{
case
c
@
CaseClassSelector
(
cc
,
sel
)
=>
{
val
rc
=
rec
(
cc
)
if
(
rc
!=
cc
)
if
(
rc
!=
cc
)
CaseClassSelector
(
rc
,
sel
).
setType
(
c
.
getType
)
else
c
}
case
_
=>
ex
}
}
}
def
inCase
(
cse
:
MatchCase
)
:
MatchCase
=
cse
match
{
def
inCase
(
cse
:
MatchCase
)
:
MatchCase
=
cse
match
{
case
SimpleCase
(
pat
,
rhs
)
=>
SimpleCase
(
pat
,
rec
(
rhs
))
case
GuardedCase
(
pat
,
guard
,
rhs
)
=>
GuardedCase
(
pat
,
rec
(
guard
),
rec
(
rhs
))
}
...
...
@@ -108,16 +107,16 @@ object TreeOperations {
rec
(
expr
)
}
def
asCatamorphism
(
program
:
Program
,
f
:
FunDef
)
:
Option
[
Seq
[(
CaseClassDef
,
Identifier
,
Seq
[
Identifier
]
,
Expr
)]]
=
{
def
recCallsOnMatchedVars
(
l
:
(
CaseClassDef
,
Identifier
,
Seq
[
Identifier
],
Expr
))
=
{
def
asCatamorphism
(
program
:
Program
,
f
:
FunDef
)
:
Option
[
Seq
[(
CaseClassDef
,
Identifier
,
Seq
[
Identifier
]
,
Expr
)]]
=
{
def
recCallsOnMatchedVars
(
l
:
(
CaseClassDef
,
Identifier
,
Seq
[
Identifier
],
Expr
))
=
{
var
varSet
=
MutableSet
.
empty
[
Identifier
]
searchAndReplace
({
case
FunctionInvocation
(
_
,
Seq
(
Variable
(
id
)))
=>
varSet
+=
id
;
None
;
case
_
=>
None
})(
l
.
_4
)
searchAndReplace
({
case
FunctionInvocation
(
_
,
Seq
(
Variable
(
id
)))
=>
varSet
+=
id
;
None
;
case
_
=>
None
})(
l
.
_4
)
varSet
.
subsetOf
(
l
.
_3
.
toSet
)
}
val
c
=
program
.
callees
(
f
)
if
(
f
.
hasImplementation
&&
f
.
args
.
size
==
1
&&
c
.
size
==
1
&&
c
.
head
==
f
)
f
.
body
.
get
match
{
case
SimplePatternMatching
(
scrut
,
_
,
lstMatches
)
if
(
f
.
hasImplementation
&&
f
.
args
.
size
==
1
&&
c
.
size
==
1
&&
c
.
head
==
f
)
f
.
body
.
get
match
{
case
SimplePatternMatching
(
scrut
,
_
,
lstMatches
)
if
(
scrut
==
f
.
args
.
head
.
toVariable
)
&&
lstMatches
.
forall
(
recCallsOnMatchedVars
)
=>
Some
(
lstMatches
)
case
_
=>
None
}
else
{
...
...
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