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
921d4522
Commit
921d4522
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Printer fixes
parent
800df59d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/leon/purescala/PrettyPrinter.scala
+27
-28
27 additions, 28 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
src/main/scala/leon/solvers/templates/TemplateGenerator.scala
+1
-3
1 addition, 3 deletions
...main/scala/leon/solvers/templates/TemplateGenerator.scala
with
28 additions
and
31 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
+
27
−
28
View file @
921d4522
...
@@ -42,7 +42,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -42,7 +42,7 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
protected
def
printNameWithPath
(
df
:
Definition
)(
implicit
ctx
:
PrinterContext
)
{
protected
def
printNameWithPath
(
df
:
Definition
)(
implicit
ctx
:
PrinterContext
)
{
(
opgm
,
ctx
.
parents
.
collectFirst
{
case
(
d
:
Definition
)
=>
d
})
match
{
(
opgm
,
ctx
.
parents
.
collectFirst
{
case
(
d
:
Definition
)
if
!
d
.
isInstanceOf
[
ValDef
]
=>
d
})
match
{
case
(
Some
(
pgm
),
Some
(
scope
))
=>
case
(
Some
(
pgm
),
Some
(
scope
))
=>
sb
.
append
(
fullNameFrom
(
df
,
scope
,
opts
.
printUniqueIds
)(
pgm
))
sb
.
append
(
fullNameFrom
(
df
,
scope
,
opts
.
printUniqueIds
)(
pgm
))
...
@@ -192,7 +192,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -192,7 +192,7 @@ class PrettyPrinter(opts: PrinterOptions,
case
FcallMethodInvocation
(
rec
,
fd
,
id
,
tps
,
args
)
=>
case
FcallMethodInvocation
(
rec
,
fd
,
id
,
tps
,
args
)
=>
p
"$rec.$id${nary(tps, "
,
", "
[
"
,
"
]
")}"
p
"$rec.$id${nary(tps, "
,
", "
[
"
,
"
]
")}"
if
(
fd
.
isRealFunction
)
{
if
(
fd
.
isRealFunction
)
{
// The non-present arguments are synthetic function invocations
// The non-present arguments are synthetic function invocations
...
@@ -207,7 +207,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -207,7 +207,7 @@ class PrettyPrinter(opts: PrinterOptions,
case
FunctionInvocation
(
TypedFunDef
(
fd
,
tps
),
args
)
=>
case
FunctionInvocation
(
TypedFunDef
(
fd
,
tps
),
args
)
=>
printNameWithPath
(
fd
)
printNameWithPath
(
fd
)
p
"${nary(tps, "
,
", "
[
"
,
"
]
")}"
p
"${nary(tps, "
,
", "
[
"
,
"
]
")}"
if
(
fd
.
isRealFunction
)
{
if
(
fd
.
isRealFunction
)
{
// The non-present arguments are synthetic function invocations
// The non-present arguments are synthetic function invocations
...
@@ -398,11 +398,11 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -398,11 +398,11 @@ class PrettyPrinter(opts: PrinterOptions,
case
FunctionType
(
fts
,
tt
)
=>
p
"($fts) => $tt"
case
FunctionType
(
fts
,
tt
)
=>
p
"($fts) => $tt"
case
c
:
ClassType
=>
case
c
:
ClassType
=>
printNameWithPath
(
c
.
classDef
)
printNameWithPath
(
c
.
classDef
)
p
"${nary(c.tps, "
,
", "
[
"
,
"
]
")}"
p
"${nary(c.tps, "
,
", "
[
"
,
"
]
")}"
// Definitions
// Definitions
case
Program
(
units
)
=>
case
Program
(
units
)
=>
p
"""${nary(units
filter {_.isMainUnit}
, "\n\n")}"""
p
"""${nary(units, "\n\n")}"""
case
UnitDef
(
id
,
pack
,
imports
,
defs
,
_
)
=>
case
UnitDef
(
id
,
pack
,
imports
,
defs
,
_
)
=>
if
(
pack
.
nonEmpty
){
if
(
pack
.
nonEmpty
){
...
@@ -427,7 +427,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -427,7 +427,7 @@ class PrettyPrinter(opts: PrinterOptions,
|}"""
|}"""
case
acd
@
AbstractClassDef
(
id
,
tparams
,
parent
)
=>
case
acd
@
AbstractClassDef
(
id
,
tparams
,
parent
)
=>
p
"abstract class $id${nary(tparams, "
,
", "
[
"
,
"
]
")}"
p
"abstract class $id${nary(tparams, "
,
", "
[
"
,
"
]
")}"
parent
.
foreach
{
par
=>
parent
.
foreach
{
par
=>
p
" extends ${par.id}"
p
" extends ${par.id}"
...
@@ -446,7 +446,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -446,7 +446,7 @@ class PrettyPrinter(opts: PrinterOptions,
p
"case class $id"
p
"case class $id"
}
}
p
"${nary(tparams, "
,
", "
[
"
,
"
]
")}"
p
"${nary(tparams, "
,
", "
[
"
,
"
]
")}"
if
(!
isObj
)
{
if
(!
isObj
)
{
p
"(${ccd.fields})"
p
"(${ccd.fields})"
...
@@ -454,7 +454,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -454,7 +454,7 @@ class PrettyPrinter(opts: PrinterOptions,
parent
.
foreach
{
par
=>
parent
.
foreach
{
par
=>
// Remember child and parents tparams are simple bijection
// Remember child and parents tparams are simple bijection
p
" extends ${par.id}${nary(tparams, "
,
", "
[
"
,
"
]
")}"
p
" extends ${par.id}${nary(tparams, "
,
", "
[
"
,
"
]
")}"
}
}
if
(
ccd
.
methods
.
nonEmpty
)
{
if
(
ccd
.
methods
.
nonEmpty
)
{
...
@@ -464,14 +464,17 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -464,14 +464,17 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
case
fd
:
FunDef
=>
case
fd
:
FunDef
=>
p
"${nary(fd.annotations.toSeq, "
\
n
")}"
for
(
an
<-
fd
.
annotations
)
{
p
"""|@$an
|"""
}
if
(
fd
.
canBeStrictField
)
{
if
(
fd
.
canBeStrictField
)
{
p
"val ${fd.id} : "
p
"val ${fd.id} : "
}
else
if
(
fd
.
canBeLazyField
)
{
}
else
if
(
fd
.
canBeLazyField
)
{
p
"lazy val ${fd.id} : "
p
"lazy val ${fd.id} : "
}
else
{
}
else
{
p
"def ${fd.id}${nary(fd.tparams, "
,
", "
[
"
,
"
]
")}(${fd.params}): "
p
"def ${fd.id}${nary(fd.tparams, "
,
", "
[
"
,
"
]
")}(${fd.params}): "
}
}
p
"${fd.returnType} = ${fd.fullBody}"
p
"${fd.returnType} = ${fd.fullBody}"
...
@@ -519,11 +522,9 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -519,11 +522,9 @@ class PrettyPrinter(opts: PrinterOptions,
val
fname
=
fid
.
name
val
fname
=
fid
.
name
val
decoded
=
scala
.
reflect
.
NameTransformer
.
decode
(
fname
)
val
realtps
=
tfd
.
tps
.
drop
(
cd
.
tparams
.
size
)
val
realtps
=
tfd
.
tps
.
drop
(
cd
.
tparams
.
size
)
(
rec
,
tfd
.
fd
,
decoded
,
realtps
,
rargs
)
(
rec
,
tfd
.
fd
,
fname
,
realtps
,
rargs
)
}
}
}
}
}
}
...
@@ -552,23 +553,20 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -552,23 +553,20 @@ class PrettyPrinter(opts: PrinterOptions,
case
_
=>
true
case
_
=>
true
}
}
protected
def
noBracesSub
(
e
:
Expr
)
=
e
match
{
protected
def
noBracesSub
(
e
:
Expr
)
:
Seq
[
Expr
]
=
e
match
{
case
Assert
(
_
,
_
,
bd
)
=>
S
om
e
(
bd
)
case
Assert
(
_
,
_
,
bd
)
=>
Se
q
(
bd
)
case
Let
(
_
,
_
,
bd
)
=>
S
om
e
(
bd
)
case
Let
(
_
,
_
,
bd
)
=>
Se
q
(
bd
)
case
LetDef
(
_
,
bd
)
=>
S
om
e
(
bd
)
case
LetDef
(
_
,
bd
)
=>
Se
q
(
bd
)
case
Require
(
_
,
bd
)
=>
S
om
e
(
bd
)
case
Require
(
_
,
bd
)
=>
Se
q
(
bd
)
case
_
=>
None
case
_
=>
Seq
()
}
}
protected
def
requiresBraces
(
ex
:
Tree
,
within
:
Option
[
Tree
])
=
(
ex
,
within
)
match
{
protected
def
requiresBraces
(
ex
:
Tree
,
within
:
Option
[
Tree
])
=
(
ex
,
within
)
match
{
case
(
e
:
Expr
,
_
)
if
isSimpleExpr
(
e
)
=>
case
(
e
:
Expr
,
_
)
if
isSimpleExpr
(
e
)
=>
false
false
case
(
e
:
Expr
,
Some
(
within
:
Expr
))
if
noBracesSub
(
within
)
contains
e
=>
false
case
(
e
:
Expr
,
Some
(
within
:
Expr
))
if
noBracesSub
(
within
)
contains
e
=>
case
(
_:
Expr
,
Some
(
_:
MatchCase
))
=>
false
false
case
(
e
:
Expr
,
Some
(
_
))
=>
true
case
(
e
:
Expr
,
Some
(
_
))
=>
case
_
=>
false
true
case
_
=>
false
}
}
protected
def
precedence
(
ex
:
Expr
)
:
Int
=
ex
match
{
protected
def
precedence
(
ex
:
Expr
)
:
Int
=
ex
match
{
...
@@ -587,11 +585,12 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -587,11 +585,12 @@ class PrettyPrinter(opts: PrinterOptions,
protected
def
requiresParentheses
(
ex
:
Tree
,
within
:
Option
[
Tree
])
:
Boolean
=
(
ex
,
within
)
match
{
protected
def
requiresParentheses
(
ex
:
Tree
,
within
:
Option
[
Tree
])
:
Boolean
=
(
ex
,
within
)
match
{
case
(
pa
:
PrettyPrintable
,
_
)
=>
pa
.
printRequiresParentheses
(
within
)
case
(
pa
:
PrettyPrintable
,
_
)
=>
pa
.
printRequiresParentheses
(
within
)
case
(
_
,
None
)
=>
false
case
(
_
,
None
)
=>
false
case
(
me
:
MatchExpr
,
Some
(
_
:
Ensuring
))
=>
true
case
(
_
,
Some
(
_:
Ensuring
))
=>
false
case
(
_
,
Some
(
_:
Ensuring
))
=>
false
case
(
_
,
Some
(
_:
Assert
))
=>
false
case
(
_
,
Some
(
_:
Assert
))
=>
false
case
(
_
,
Some
(
_:
Require
))
=>
false
case
(
_
,
Some
(
_:
Require
))
=>
false
case
(
_
,
Some
(
_:
Definition
))
=>
false
case
(
_
,
Some
(
_:
Definition
))
=>
false
case
(
_
,
Some
(
_:
MatchExpr
|
_
:
MatchCase
|
_
:
Let
|
_
:
LetDef
|
_
:
IfExpr
|
_
:
CaseClass
))
=>
false
case
(
_
,
Some
(
_:
MatchExpr
|
_
:
MatchCase
|
_
:
Let
|
_
:
LetDef
|
_
:
IfExpr
|
_
:
CaseClass
|
_
:
Lambda
))
=>
false
case
(
b1
@
BinaryMethodCall
(
_
,
_
,
_
),
Some
(
b2
@
BinaryMethodCall
(
_
,
_
,
_
)))
if
precedence
(
b1
)
>
precedence
(
b2
)
=>
false
case
(
b1
@
BinaryMethodCall
(
_
,
_
,
_
),
Some
(
b2
@
BinaryMethodCall
(
_
,
_
,
_
)))
if
precedence
(
b1
)
>
precedence
(
b2
)
=>
false
case
(
BinaryMethodCall
(
_
,
_
,
_
),
Some
(
_:
FunctionInvocation
))
=>
true
case
(
BinaryMethodCall
(
_
,
_
,
_
),
Some
(
_:
FunctionInvocation
))
=>
true
case
(
_
,
Some
(
_:
FunctionInvocation
))
=>
false
case
(
_
,
Some
(
_:
FunctionInvocation
))
=>
false
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/solvers/templates/TemplateGenerator.scala
+
1
−
3
View file @
921d4522
...
@@ -12,8 +12,6 @@ import purescala.Types._
...
@@ -12,8 +12,6 @@ import purescala.Types._
import
purescala.Definitions._
import
purescala.Definitions._
import
purescala.Constructors._
import
purescala.Constructors._
import
evaluators._
class
TemplateGenerator
[
T
](
val
encoder
:
TemplateEncoder
[
T
],
class
TemplateGenerator
[
T
](
val
encoder
:
TemplateEncoder
[
T
],
val
assumePreHolds
:
Boolean
)
{
val
assumePreHolds
:
Boolean
)
{
private
var
cache
=
Map
[
TypedFunDef
,
FunctionTemplate
[
T
]]()
private
var
cache
=
Map
[
TypedFunDef
,
FunctionTemplate
[
T
]]()
...
@@ -140,7 +138,7 @@ class TemplateGenerator[T](val encoder: TemplateEncoder[T],
...
@@ -140,7 +138,7 @@ class TemplateGenerator[T](val encoder: TemplateEncoder[T],
// id => expr && ... && expr
// id => expr && ... && expr
var
guardedExprs
=
Map
[
Identifier
,
Seq
[
Expr
]]()
var
guardedExprs
=
Map
[
Identifier
,
Seq
[
Expr
]]()
def
storeGuarded
(
guardVar
:
Identifier
,
expr
:
Expr
)
:
Unit
=
{
def
storeGuarded
(
guardVar
:
Identifier
,
expr
:
Expr
)
:
Unit
=
{
assert
(
expr
.
getType
==
BooleanType
)
assert
(
expr
.
getType
==
BooleanType
,
expr
.
asString
(
Program
.
empty
)(
LeonContext
.
empty
)
)
val
prev
=
guardedExprs
.
getOrElse
(
guardVar
,
Nil
)
val
prev
=
guardedExprs
.
getOrElse
(
guardVar
,
Nil
)
...
...
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