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
d7926296
Commit
d7926296
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Improve printer
parent
c29501e8
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/main/scala/leon/purescala/PrettyPrinter.scala
+15
-41
15 additions, 41 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
src/main/scala/leon/purescala/PrinterHelpers.scala
+3
-2
3 additions, 2 deletions
src/main/scala/leon/purescala/PrinterHelpers.scala
with
18 additions
and
43 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
+
15
−
41
View file @
d7926296
...
@@ -41,7 +41,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -41,7 +41,7 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
}
}
protected
def
printWithPath
(
df
:
Definition
)(
implicit
ctx
:
PrinterContext
)
{
protected
def
print
Name
WithPath
(
df
:
Definition
)(
implicit
ctx
:
PrinterContext
)
{
(
opgm
,
ctx
.
parents
.
collectFirst
{
case
(
d
:
Definition
)
=>
d
})
match
{
(
opgm
,
ctx
.
parents
.
collectFirst
{
case
(
d
:
Definition
)
=>
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
))
...
@@ -175,12 +175,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -175,12 +175,7 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
case
CaseClassSelector
(
_
,
e
,
id
)
=>
p
"$e.$id"
case
CaseClassSelector
(
_
,
e
,
id
)
=>
p
"$e.$id"
case
MethodInvocation
(
rec
,
_
,
tfd
,
args
)
=>
case
MethodInvocation
(
rec
,
_
,
tfd
,
args
)
=>
p
"$rec.${tfd.id}"
p
"$rec.${tfd.id}${nary(tfd.tps, "
,
", "
[
"
,
"
]
")}"
if
(
tfd
.
tps
.
nonEmpty
)
{
p
"[${tfd.tps}]"
}
// No () for fields
// No () for fields
if
(
tfd
.
fd
.
isRealFunction
)
{
if
(
tfd
.
fd
.
isRealFunction
)
{
// The non-present arguments are synthetic function invocations
// The non-present arguments are synthetic function invocations
...
@@ -197,10 +192,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -197,10 +192,7 @@ class PrettyPrinter(opts: PrinterOptions,
case
FcallMethodInvocation
(
rec
,
fd
,
id
,
tps
,
args
)
=>
case
FcallMethodInvocation
(
rec
,
fd
,
id
,
tps
,
args
)
=>
p
"$rec.$id"
p
"$rec.$id${nary(tps, "
,
", "
[
"
,
"
]
")}"
if
(
tps
.
nonEmpty
)
{
p
"[$tps]"
}
if
(
fd
.
isRealFunction
)
{
if
(
fd
.
isRealFunction
)
{
// The non-present arguments are synthetic function invocations
// The non-present arguments are synthetic function invocations
...
@@ -213,11 +205,9 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -213,11 +205,9 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
case
FunctionInvocation
(
TypedFunDef
(
fd
,
tps
),
args
)
=>
case
FunctionInvocation
(
TypedFunDef
(
fd
,
tps
),
args
)
=>
printWithPath
(
fd
)
print
Name
WithPath
(
fd
)
if
(
tps
.
nonEmpty
)
{
p
"${nary(tps, "
,
", "
[
"
,
"
]
")}"
p
"[$tps]"
}
if
(
fd
.
isRealFunction
)
{
if
(
fd
.
isRealFunction
)
{
// The non-present arguments are synthetic function invocations
// The non-present arguments are synthetic function invocations
...
@@ -357,7 +347,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -357,7 +347,7 @@ class PrettyPrinter(opts: PrinterOptions,
case
CaseClassPattern
(
ob
,
cct
,
subps
)
=>
case
CaseClassPattern
(
ob
,
cct
,
subps
)
=>
ob
.
foreach
{
b
=>
p
"$b @ "
}
ob
.
foreach
{
b
=>
p
"$b @ "
}
// Print only the classDef because we don't want type parameters in patterns
// Print only the classDef because we don't want type parameters in patterns
printWithPath
(
cct
.
classDef
)
print
Name
WithPath
(
cct
.
classDef
)
if
(!
cct
.
classDef
.
isCaseObject
)
p
"($subps)"
if
(!
cct
.
classDef
.
isCaseObject
)
p
"($subps)"
case
InstanceOfPattern
(
ob
,
cct
)
=>
case
InstanceOfPattern
(
ob
,
cct
)
=>
...
@@ -382,7 +372,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -382,7 +372,7 @@ class PrettyPrinter(opts: PrinterOptions,
mod
<-
p
.
modules
.
find
(
_
.
definedFunctions
contains
tfd
.
fd
)
mod
<-
p
.
modules
.
find
(
_
.
definedFunctions
contains
tfd
.
fd
)
}
yield
mod
)
match
{
}
yield
mod
)
match
{
case
Some
(
obj
)
=>
case
Some
(
obj
)
=>
printWithPath
(
obj
)
print
Name
WithPath
(
obj
)
case
None
=>
case
None
=>
p
"<unknown object>"
p
"<unknown object>"
}
}
...
@@ -407,10 +397,8 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -407,10 +397,8 @@ class PrettyPrinter(opts: PrinterOptions,
case
TupleType
(
tpes
)
=>
p
"($tpes)"
case
TupleType
(
tpes
)
=>
p
"($tpes)"
case
FunctionType
(
fts
,
tt
)
=>
p
"($fts) => $tt"
case
FunctionType
(
fts
,
tt
)
=>
p
"($fts) => $tt"
case
c
:
ClassType
=>
case
c
:
ClassType
=>
printWithPath
(
c
.
classDef
)
printNameWithPath
(
c
.
classDef
)
if
(
c
.
tps
.
nonEmpty
)
{
p
"${nary(c.tps, "
,
", "
[
"
,
"
]
")}"
p
"[${c.tps}]"
}
// Definitions
// Definitions
case
Program
(
units
)
=>
case
Program
(
units
)
=>
...
@@ -439,11 +427,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -439,11 +427,7 @@ class PrettyPrinter(opts: PrinterOptions,
|}"""
|}"""
case
acd
@
AbstractClassDef
(
id
,
tparams
,
parent
)
=>
case
acd
@
AbstractClassDef
(
id
,
tparams
,
parent
)
=>
p
"abstract class $id"
p
"abstract class $id${nary(tparams, "
,
", "
[
"
,
"
]
")}"
if
(
tparams
.
nonEmpty
)
{
p
"[$tparams]"
}
parent
.
foreach
{
par
=>
parent
.
foreach
{
par
=>
p
" extends ${par.id}"
p
" extends ${par.id}"
...
@@ -462,21 +446,15 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -462,21 +446,15 @@ class PrettyPrinter(opts: PrinterOptions,
p
"case class $id"
p
"case class $id"
}
}
if
(
tparams
.
nonEmpty
)
{
p
"${nary(tparams, "
,
", "
[
"
,
"
]
")}"
p
"[$tparams]"
}
if
(!
isObj
)
{
if
(!
isObj
)
{
p
"(${ccd.fields})"
p
"(${ccd.fields})"
}
}
parent
.
foreach
{
par
=>
parent
.
foreach
{
par
=>
if
(
par
.
tps
.
nonEmpty
){
// 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}[$tparams]"
}
else
{
p
" extends ${par.id}"
}
}
}
if
(
ccd
.
methods
.
nonEmpty
)
{
if
(
ccd
.
methods
.
nonEmpty
)
{
...
@@ -492,10 +470,8 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -492,10 +470,8 @@ class PrettyPrinter(opts: PrinterOptions,
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
if
(
fd
.
tparams
.
nonEmpty
)
{
p
"def ${fd.id}[${nary(fd.tparams, "
,
")}](${fd.params}): "
}
else
{
}
else
{
p
"def ${fd.id}(${fd.params}): "
p
"def ${fd.id}
${nary(fd.tparams, "
,
", "
[
"
,
"
]
")}
(${fd.params}): "
}
}
p
"${fd.returnType} = ${fd.fullBody}"
p
"${fd.returnType} = ${fd.fullBody}"
...
@@ -587,8 +563,6 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -587,8 +563,6 @@ class PrettyPrinter(opts: PrinterOptions,
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
(
_
,
None
)
=>
false
case
(
e
:
Expr
,
Some
(
within
:
Expr
))
if
noBracesSub
(
within
)
contains
e
=>
case
(
e
:
Expr
,
Some
(
within
:
Expr
))
if
noBracesSub
(
within
)
contains
e
=>
false
false
case
(
e
:
Expr
,
Some
(
_
))
=>
case
(
e
:
Expr
,
Some
(
_
))
=>
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/purescala/PrinterHelpers.scala
+
3
−
2
View file @
d7926296
...
@@ -74,8 +74,9 @@ object PrinterHelpers {
...
@@ -74,8 +74,9 @@ object PrinterHelpers {
}
}
}
}
def
nary
(
ls
:
Seq
[
Any
],
sep
:
String
=
", "
)
:
Printable
=
{
def
nary
(
ls
:
Seq
[
Any
],
sep
:
String
=
", "
,
init
:
String
=
""
,
closing
:
String
=
""
)
:
Printable
=
{
val
strs
=
List
(
""
)
:::
List
.
fill
(
ls
.
size
-
1
)(
sep
)
val
(
i
,
c
)
=
if
(
ls
.
isEmpty
)
(
""
,
""
)
else
(
init
,
closing
)
val
strs
=
i
+:
List
.
fill
(
ls
.
size
-
1
)(
sep
)
:+
c
implicit
pctx
:
PrinterContext
=>
implicit
pctx
:
PrinterContext
=>
new
StringContext
(
strs
:
_
*
).
p
(
ls
:
_
*
)
new
StringContext
(
strs
:
_
*
).
p
(
ls
:
_
*
)
...
...
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