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
fab8ca8e
Commit
fab8ca8e
authored
14 years ago
by
Philippe Suter
Browse files
Options
Downloads
Patches
Plain Diff
improved extraction of parametric types. works for sets, for instance
parent
9b8f0149
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/funcheck/CodeExtraction.scala
+23
-14
23 additions, 14 deletions
src/funcheck/CodeExtraction.scala
src/purescala/PrettyPrinter.scala
+1
-0
1 addition, 0 deletions
src/purescala/PrettyPrinter.scala
with
24 additions
and
14 deletions
src/funcheck/CodeExtraction.scala
+
23
−
14
View file @
fab8ca8e
...
@@ -16,6 +16,8 @@ trait CodeExtraction extends Extractors {
...
@@ -16,6 +16,8 @@ trait CodeExtraction extends Extractors {
import
StructuralExtractors._
import
StructuralExtractors._
import
ExpressionExtractors._
import
ExpressionExtractors._
private
lazy
val
setTraitSym
=
definitions
.
getClass
(
"scala.collection.immutable.Set"
)
private
val
varSubsts
:
scala.collection.mutable.Map
[
Identifier
,
Function0
[
Expr
]]
=
scala
.
collection
.
mutable
.
Map
.
empty
[
Identifier
,
Function0
[
Expr
]]
private
val
varSubsts
:
scala.collection.mutable.Map
[
Identifier
,
Function0
[
Expr
]]
=
scala
.
collection
.
mutable
.
Map
.
empty
[
Identifier
,
Function0
[
Expr
]]
def
extractCode
(
unit
:
CompilationUnit
)
:
Program
=
{
def
extractCode
(
unit
:
CompilationUnit
)
:
Program
=
{
...
@@ -26,7 +28,7 @@ trait CodeExtraction extends Extractors {
...
@@ -26,7 +28,7 @@ trait CodeExtraction extends Extractors {
case
None
=>
stopIfErrors
;
scala
.
Predef
.
error
(
"unreachable error."
)
case
None
=>
stopIfErrors
;
scala
.
Predef
.
error
(
"unreachable error."
)
}
}
def
st2ps
(
tree
:
T
re
e
)
:
purescala.TypeTrees.TypeTree
=
toPureScalaType
(
unit
)(
tree
)
match
{
def
st2ps
(
tree
:
T
yp
e
)
:
purescala.TypeTrees.TypeTree
=
toPureScalaType
(
unit
)(
tree
)
match
{
case
Some
(
tt
)
=>
tt
case
Some
(
tt
)
=>
tt
case
None
=>
stopIfErrors
;
scala
.
Predef
.
error
(
"unreachable error."
)
case
None
=>
stopIfErrors
;
scala
.
Predef
.
error
(
"unreachable error."
)
}
}
...
@@ -90,7 +92,7 @@ trait CodeExtraction extends Extractors {
...
@@ -90,7 +92,7 @@ trait CodeExtraction extends Extractors {
var
reqCont
:
Option
[
Expr
]
=
None
var
reqCont
:
Option
[
Expr
]
=
None
var
ensCont
:
Option
[
Expr
]
=
None
var
ensCont
:
Option
[
Expr
]
=
None
val
ps
=
params
.
map
(
p
=>
VarDecl
(
p
.
name
.
toString
,
st2ps
(
p
.
tpt
)))
val
ps
=
params
.
map
(
p
=>
VarDecl
(
p
.
name
.
toString
,
st2ps
(
p
.
tpt
.
tpe
)))
realBody
match
{
realBody
match
{
case
ExEnsuredExpression
(
body2
,
resId
,
contract
)
=>
{
case
ExEnsuredExpression
(
body2
,
resId
,
contract
)
=>
{
...
@@ -111,7 +113,7 @@ trait CodeExtraction extends Extractors {
...
@@ -111,7 +113,7 @@ trait CodeExtraction extends Extractors {
case
_
=>
;
case
_
=>
;
}
}
FunDef
(
name
,
st2ps
(
tpt
),
ps
,
s2ps
(
realBody
),
reqCont
,
ensCont
)
FunDef
(
name
,
st2ps
(
tpt
.
tpe
),
ps
,
s2ps
(
realBody
),
reqCont
,
ensCont
)
}
}
// THE EXTRACTION CODE STARTS HERE
// THE EXTRACTION CODE STARTS HERE
...
@@ -140,7 +142,7 @@ trait CodeExtraction extends Extractors {
...
@@ -140,7 +142,7 @@ trait CodeExtraction extends Extractors {
}
}
}
}
def
toPureScalaType
(
unit
:
CompilationUnit
)(
typeTree
:
T
re
e
)
:
Option
[
purescala.TypeTrees.TypeTree
]
=
{
def
toPureScalaType
(
unit
:
CompilationUnit
)(
typeTree
:
T
yp
e
)
:
Option
[
purescala.TypeTrees.TypeTree
]
=
{
try
{
try
{
Some
(
scalaType2PureScala
(
unit
,
false
)(
typeTree
))
Some
(
scalaType2PureScala
(
unit
,
false
)(
typeTree
))
}
catch
{
}
catch
{
...
@@ -187,20 +189,27 @@ trait CodeExtraction extends Extractors {
...
@@ -187,20 +189,27 @@ trait CodeExtraction extends Extractors {
rec
(
tree
)
rec
(
tree
)
}
}
private
def
scalaType2PureScala
(
unit
:
CompilationUnit
,
silent
:
Boolean
)(
tree
:
Tree
)
:
purescala.TypeTrees.TypeTree
=
{
private
def
scalaType2PureScala
(
unit
:
CompilationUnit
,
silent
:
Boolean
)(
tree
:
Type
)
:
purescala.TypeTrees.TypeTree
=
{
tree
match
{
case
tt
:
TypeTree
if
tt.tpe
=
=
IntClass
.
tpe
=>
Int32Type
case
tt
:
TypeTree
if
tt.tpe
=
=
BooleanClass
.
tpe
=>
BooleanType
case
tt
:
TypeTree
=>
tt
.
tpe
match
{
case
TypeRef
(
_
,
sym
,
_
)
if
sym
==
setTraitSym
=>
XXXXXX
}
case
tt
=>
{
def
rec
(
tr
:
Type
)
:
purescala.TypeTrees.TypeTree
=
tr
match
{
case
tpe
if
tpe
==
IntClass
.
tpe
=>
Int32Type
case
tpe
if
tpe
==
BooleanClass
.
tpe
=>
BooleanType
case
TypeRef
(
_
,
sym
,
btt
::
Nil
)
if
sym
==
setTraitSym
=>
SetType
(
rec
(
btt
))
case
_
=>
{
if
(!
silent
)
{
if
(!
silent
)
{
unit
.
error
(
tree
.
pos
,
"Could not extract type as PureScala. ["
+
t
t
+
"]"
)
unit
.
error
(
NoPosition
,
"Could not extract type as PureScala. ["
+
t
r
+
"]"
)
}
}
throw
ImpureCodeEncounteredException
(
tree
)
throw
ImpureCodeEncounteredException
(
null
)
}
}
// case tt => {
// if(!silent) {
// unit.error(tree.pos, "This does not appear to be a type tree: [" + tt + "]")
// }
// throw ImpureCodeEncounteredException(tree)
// }
}
}
rec
(
tree
)
}
}
}
}
This diff is collapsed.
Click to expand it.
src/purescala/PrettyPrinter.scala
+
1
−
0
View file @
fab8ca8e
...
@@ -102,6 +102,7 @@ object PrettyPrinter {
...
@@ -102,6 +102,7 @@ object PrettyPrinter {
private
def
pp
(
tpe
:
TypeTree
,
sb
:
StringBuffer
)
:
StringBuffer
=
tpe
match
{
private
def
pp
(
tpe
:
TypeTree
,
sb
:
StringBuffer
)
:
StringBuffer
=
tpe
match
{
case
Int32Type
=>
sb
.
append
(
"Int"
)
case
Int32Type
=>
sb
.
append
(
"Int"
)
case
BooleanType
=>
sb
.
append
(
"Boolean"
)
case
BooleanType
=>
sb
.
append
(
"Boolean"
)
case
SetType
(
bt
)
=>
pp
(
bt
,
sb
.
append
(
"Set["
)).
append
(
"]"
)
case
_
=>
sb
.
append
(
"Type?"
)
case
_
=>
sb
.
append
(
"Type?"
)
}
}
...
...
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