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
5bf8a57c
Commit
5bf8a57c
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Improve printing
parent
859443eb
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/main/scala/leon/purescala/PrettyPrinter.scala
+47
-36
47 additions, 36 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
with
47 additions
and
36 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
+
47
−
36
View file @
5bf8a57c
...
@@ -4,14 +4,14 @@ package leon
...
@@ -4,14 +4,14 @@ package leon
package
purescala
package
purescala
import
leon.utils._
import
leon.utils._
import
leon.purescala.
Common._
import
Common._
import
leon.purescala.
DefOps._
import
DefOps._
import
leon.purescala.
Definitions._
import
Definitions._
import
leon.purescala.
Extractors._
import
Extractors._
import
leon.purescala.
PrinterHelpers._
import
PrinterHelpers._
import
leon.purescala.
ExprOps.
{
isListLiteral
,
simplestValue
}
import
ExprOps.
{
isListLiteral
,
simplestValue
}
import
leon.purescala.
Expressions._
import
Expressions._
import
leon.purescala.
Types._
import
Types._
case
class
PrinterContext
(
case
class
PrinterContext
(
current
:
Tree
,
current
:
Tree
,
...
@@ -52,6 +52,15 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -52,6 +52,15 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
def
pp
(
tree
:
Tree
)(
implicit
ctx
:
PrinterContext
)
:
Unit
=
{
def
pp
(
tree
:
Tree
)(
implicit
ctx
:
PrinterContext
)
:
Unit
=
{
if
(
requiresBraces
(
tree
,
ctx
.
parent
))
{
val
ctx1
:
PrinterContext
=
ctx
.
copy
(
parents
=
Nil
)
p
"""|{
| $tree
|}"""
(
ctx1
)
return
}
if
(
opts
.
printTypes
)
{
if
(
opts
.
printTypes
)
{
tree
match
{
tree
match
{
case
t
:
Expr
=>
case
t
:
Expr
=>
...
@@ -81,15 +90,8 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -81,15 +90,8 @@ class PrettyPrinter(opts: PrinterOptions,
p
"$id"
p
"$id"
case
Let
(
b
,
d
,
e
)
=>
case
Let
(
b
,
d
,
e
)
=>
if
(
isSimpleExpr
(
d
))
{
p
"""|val $b = $d
p
"""|val $b = $d
|$e"""
|$e"""
}
else
{
p
"""|val $b = {
| $d
|}
|$e"""
}
case
LetDef
(
fd
,
body
)
=>
case
LetDef
(
fd
,
body
)
=>
p
"""|$fd
p
"""|$fd
...
@@ -108,9 +110,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -108,9 +110,7 @@ class PrettyPrinter(opts: PrinterOptions,
|$body"""
|$body"""
case
Ensuring
(
body
,
post
)
=>
case
Ensuring
(
body
,
post
)
=>
p
"""|{
p
"""|$body ensuring {
| $body
|} ensuring {
| $post
| $post
|}"""
|}"""
...
@@ -340,17 +340,12 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -340,17 +340,12 @@ class PrettyPrinter(opts: PrinterOptions,
|}"""
|}"""
}
}
/*case LetPattern(p,s,rhs) =>
/*
if (isSimpleExpr(s)) {
case LetPattern(p,s,rhs) =>
p"""|val $p = $s
p"""|val $p = $s
|$rhs"""
|$rhs"""
} else {
p"""|val $p = {
| $s
|}
|$rhs"""
}
*/
*/
case
MatchExpr
(
s
,
csc
)
=>
case
MatchExpr
(
s
,
csc
)
=>
optP
{
optP
{
p
"""|$s match {
p
"""|$s match {
...
@@ -509,13 +504,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -509,13 +504,7 @@ class PrettyPrinter(opts: PrinterOptions,
p
"${fd.returnType} = "
p
"${fd.returnType} = "
if
(
isSimpleExpr
(
fd
.
fullBody
))
{
p
"${fd.fullBody}"
p
"${fd.fullBody}"
}
else
{
p
"""|{
| ${fd.fullBody}
|}"""
}
case
(
tree
:
PrettyPrintable
)
=>
tree
.
printWith
(
ctx
)
case
(
tree
:
PrettyPrintable
)
=>
tree
.
printWith
(
ctx
)
...
@@ -547,6 +536,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -547,6 +536,7 @@ class PrettyPrinter(opts: PrinterOptions,
p
"@(?)"
p
"@(?)"
}
}
}
}
}
}
object
FcallMethodInvocation
{
object
FcallMethodInvocation
{
...
@@ -587,10 +577,31 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -587,10 +577,31 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
def
isSimpleExpr
(
e
:
Expr
)
:
Boolean
=
e
match
{
def
isSimpleExpr
(
e
:
Expr
)
:
Boolean
=
e
match
{
case
_:
LetDef
|
_
:
Let
|
LetPattern
(
_
,
_
,
_
)
|
_:
Assert
=>
false
case
_:
LetDef
|
_
:
Let
|
LetPattern
(
_
,
_
,
_
)
|
_:
Assert
|
_
:
Require
=>
false
case
_
=>
true
case
_
=>
true
}
}
def
noBracesSub
(
e
:
Expr
)
=
e
match
{
case
Assert
(
_
,
_
,
bd
)
=>
Some
(
bd
)
case
Let
(
_
,
_
,
bd
)
=>
Some
(
bd
)
case
LetDef
(
_
,
bd
)
=>
Some
(
bd
)
case
Require
(
_
,
bd
)
=>
Some
(
bd
)
case
_
=>
None
}
def
requiresBraces
(
ex
:
Tree
,
within
:
Option
[
Tree
])
=
(
ex
,
within
)
match
{
case
(
e
:
Expr
,
_
)
if
isSimpleExpr
(
e
)
=>
false
case
(
_
,
None
)
=>
false
case
(
e
:
Expr
,
Some
(
within
:
Expr
))
if
noBracesSub
(
within
)
contains
e
=>
false
case
(
e
:
Expr
,
Some
(
_
))
=>
true
case
_
=>
false
}
def
precedence
(
ex
:
Expr
)
:
Int
=
ex
match
{
def
precedence
(
ex
:
Expr
)
:
Int
=
ex
match
{
case
(
pa
:
PrettyPrintable
)
=>
pa
.
printPrecedence
case
(
pa
:
PrettyPrintable
)
=>
pa
.
printPrecedence
case
(
_:
ElementOfSet
)
=>
0
case
(
_:
ElementOfSet
)
=>
0
...
...
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