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
014bf6ab
Commit
014bf6ab
authored
14 years ago
by
Philippe Suter
Browse files
Options
Downloads
Patches
Plain Diff
support for some set operations.
parent
33548380
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/funcheck/CodeExtraction.scala
+23
-2
23 additions, 2 deletions
src/funcheck/CodeExtraction.scala
src/funcheck/Extractors.scala
+40
-0
40 additions, 0 deletions
src/funcheck/Extractors.scala
src/purescala/PrettyPrinter.scala
+5
-0
5 additions, 0 deletions
src/purescala/PrettyPrinter.scala
with
68 additions
and
2 deletions
src/funcheck/CodeExtraction.scala
+
23
−
2
View file @
014bf6ab
...
@@ -307,8 +307,8 @@ trait CodeExtraction extends Extractors {
...
@@ -307,8 +307,8 @@ trait CodeExtraction extends Extractors {
}
}
def
rec
(
tr
:
Tree
)
:
Expr
=
tr
match
{
def
rec
(
tr
:
Tree
)
:
Expr
=
tr
match
{
case
ExInt32Literal
(
v
)
=>
IntLiteral
(
v
)
case
ExInt32Literal
(
v
)
=>
IntLiteral
(
v
)
.
setType
(
Int32Type
)
case
ExBooleanLiteral
(
v
)
=>
BooleanLiteral
(
v
)
case
ExBooleanLiteral
(
v
)
=>
BooleanLiteral
(
v
)
.
setType
(
BooleanType
)
case
ExIdentifier
(
sym
,
tpt
)
=>
varSubsts
.
get
(
sym
)
match
{
case
ExIdentifier
(
sym
,
tpt
)
=>
varSubsts
.
get
(
sym
)
match
{
case
Some
(
fun
)
=>
fun
()
case
Some
(
fun
)
=>
fun
()
case
None
=>
{
case
None
=>
{
...
@@ -337,10 +337,31 @@ trait CodeExtraction extends Extractors {
...
@@ -337,10 +337,31 @@ trait CodeExtraction extends Extractors {
case
ExTimes
(
l
,
r
)
=>
Times
(
rec
(
l
),
rec
(
r
)).
setType
(
Int32Type
)
case
ExTimes
(
l
,
r
)
=>
Times
(
rec
(
l
),
rec
(
r
)).
setType
(
Int32Type
)
case
ExDiv
(
l
,
r
)
=>
Division
(
rec
(
l
),
rec
(
r
)).
setType
(
Int32Type
)
case
ExDiv
(
l
,
r
)
=>
Division
(
rec
(
l
),
rec
(
r
)).
setType
(
Int32Type
)
case
ExEquals
(
l
,
r
)
=>
Equals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExEquals
(
l
,
r
)
=>
Equals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExNotEquals
(
l
,
r
)
=>
Not
(
Equals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)).
setType
(
BooleanType
)
case
ExGreaterThan
(
l
,
r
)
=>
GreaterThan
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExGreaterThan
(
l
,
r
)
=>
GreaterThan
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExGreaterEqThan
(
l
,
r
)
=>
GreaterEquals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExGreaterEqThan
(
l
,
r
)
=>
GreaterEquals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExLessThan
(
l
,
r
)
=>
LessThan
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExLessThan
(
l
,
r
)
=>
LessThan
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExLessEqThan
(
l
,
r
)
=>
LessEquals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExLessEqThan
(
l
,
r
)
=>
LessEquals
(
rec
(
l
),
rec
(
r
)).
setType
(
BooleanType
)
case
ExEmptySet
(
tt
)
=>
{
val
underlying
=
scalaType2PureScala
(
unit
,
silent
)(
tt
.
tpe
)
EmptySet
(
underlying
).
setType
(
SetType
(
underlying
))
}
case
ExUnion
(
t1
,
t2
)
=>
{
val
rl
=
rec
(
t1
)
val
rr
=
rec
(
t2
)
SetUnion
(
rl
,
rr
).
setType
(
rl
.
getType
)
// this is not entirely correct: should be a setype of LUB of underlying types of left and right.
}
case
ExIntersection
(
t1
,
t2
)
=>
{
val
rl
=
rec
(
t1
)
val
rr
=
rec
(
t2
)
SetIntersection
(
rl
,
rr
).
setType
(
rl
.
getType
)
// same as union
}
case
ExSetMinus
(
t1
,
t2
)
=>
{
val
rl
=
rec
(
t1
)
val
rr
=
rec
(
t2
)
SetDifference
(
rl
,
rr
).
setType
(
rl
.
getType
)
// same as union
}
case
ExIfThenElse
(
t1
,
t2
,
t3
)
=>
{
case
ExIfThenElse
(
t1
,
t2
,
t3
)
=>
{
val
r1
=
rec
(
t1
)
val
r1
=
rec
(
t1
)
val
r2
=
rec
(
t2
)
val
r2
=
rec
(
t2
)
...
...
This diff is collapsed.
Click to expand it.
src/funcheck/Extractors.scala
+
40
−
0
View file @
014bf6ab
...
@@ -10,6 +10,8 @@ trait Extractors {
...
@@ -10,6 +10,8 @@ trait Extractors {
import
global._
import
global._
import
global.definitions._
import
global.definitions._
private
lazy
val
setTraitSym
=
definitions
.
getClass
(
"scala.collection.immutable.Set"
)
object
StructuralExtractors
{
object
StructuralExtractors
{
object
ScalaPredef
{
object
ScalaPredef
{
/** Extracts method calls from scala.Predef. */
/** Extracts method calls from scala.Predef. */
...
@@ -286,5 +288,43 @@ trait Extractors {
...
@@ -286,5 +288,43 @@ trait Extractors {
def
unapply
(
tree
:
Match
)
:
Option
[(
Tree
,
List
[
CaseDef
])]
=
def
unapply
(
tree
:
Match
)
:
Option
[(
Tree
,
List
[
CaseDef
])]
=
if
(
tree
!=
null
)
Some
((
tree
.
selector
,
tree
.
cases
))
else
None
if
(
tree
!=
null
)
Some
((
tree
.
selector
,
tree
.
cases
))
else
None
}
}
object
ExEmptySet
{
def
unapply
(
tree
:
TypeApply
)
:
Option
[
Tree
]
=
tree
match
{
case
TypeApply
(
Select
(
Select
(
Select
(
Select
(
Ident
(
s
),
collectionName
),
immutableName
),
setName
),
emptyName
),
theTypeTree
::
Nil
)
if
(
collectionName
.
toString
==
"collection"
&&
immutableName
.
toString
==
"immutable"
&&
setName
.
toString
==
"Set"
&&
emptyName
.
toString
==
"empty"
)
=>
Some
(
theTypeTree
)
case
_
=>
None
}
}
object
ExUnion
{
def
unapply
(
tree
:
Apply
)
:
Option
[(
Tree
,
Tree
)]
=
tree
match
{
case
Apply
(
Select
(
lhs
,
n
),
List
(
rhs
))
if
(
n
==
nme
.
PLUSPLUS
)
=>
Some
((
lhs
,
rhs
))
case
_
=>
None
}
}
object
ExIntersection
{
def
unapply
(
tree
:
Apply
)
:
Option
[(
Tree
,
Tree
)]
=
tree
match
{
case
Apply
(
Select
(
lhs
,
n
),
List
(
rhs
))
if
(
n
==
encode
(
"**"
))
=>
Some
((
lhs
,
rhs
))
case
_
=>
None
}
}
object
ExSetMinus
{
def
unapply
(
tree
:
Apply
)
:
Option
[(
Tree
,
Tree
)]
=
tree
match
{
case
Apply
(
Select
(
lhs
,
n
),
List
(
rhs
))
if
(
n
==
encode
(
"--"
))
=>
Some
((
lhs
,
rhs
))
case
_
=>
None
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
src/purescala/PrettyPrinter.scala
+
5
−
0
View file @
014bf6ab
...
@@ -98,6 +98,10 @@ object PrettyPrinter {
...
@@ -98,6 +98,10 @@ object PrettyPrinter {
case
GreaterThan
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" > "
,
lvl
)
case
GreaterThan
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" > "
,
lvl
)
case
LessEquals
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" \u2264 "
,
lvl
)
// \leq
case
LessEquals
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" \u2264 "
,
lvl
)
// \leq
case
GreaterEquals
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" \u2265 "
,
lvl
)
// \geq
case
GreaterEquals
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" \u2265 "
,
lvl
)
// \geq
case
EmptySet
(
_
)
=>
sb
.
append
(
"Ø"
)
case
SetUnion
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" U "
,
lvl
)
case
SetDifference
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" \\ "
,
lvl
)
case
SetIntersection
(
l
,
r
)
=>
ppBinary
(
sb
,
l
,
r
,
" INT "
,
lvl
)
case
IfExpr
(
c
,
t
,
e
)
=>
{
case
IfExpr
(
c
,
t
,
e
)
=>
{
var
nsb
=
sb
var
nsb
=
sb
...
@@ -162,6 +166,7 @@ object PrettyPrinter {
...
@@ -162,6 +166,7 @@ object PrettyPrinter {
case
ResultVariable
()
=>
sb
.
append
(
"#res"
)
case
ResultVariable
()
=>
sb
.
append
(
"#res"
)
case
_
=>
sb
.
append
(
"Expr?"
)
case
_
=>
sb
.
append
(
"Expr?"
)
}
}
...
...
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