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
15c957e6
Commit
15c957e6
authored
9 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
XLang/PrettyPrintable are now in line with new printer
parent
5bf8a57c
Branches
Branches containing commit
Tags
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
+19
-20
19 additions, 20 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
src/main/scala/leon/xlang/Expressions.scala
+7
-7
7 additions, 7 deletions
src/main/scala/leon/xlang/Expressions.scala
with
26 additions
and
27 deletions
src/main/scala/leon/purescala/PrettyPrinter.scala
+
19
−
20
View file @
15c957e6
...
@@ -41,7 +41,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -41,7 +41,7 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
}
}
def
printWithPath
(
df
:
Definition
)(
implicit
ctx
:
PrinterContext
)
{
protected
def
printWithPath
(
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
))
...
@@ -135,7 +135,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -135,7 +135,7 @@ class PrettyPrinter(opts: PrinterOptions,
case
e
@
CaseClass
(
cct
,
args
)
=>
case
e
@
CaseClass
(
cct
,
args
)
=>
opgm
.
flatMap
{
pgm
=>
isListLiteral
(
e
)(
pgm
)
}
match
{
opgm
.
flatMap
{
pgm
=>
isListLiteral
(
e
)(
pgm
)
}
match
{
case
Some
((
tpe
,
elems
))
=>
case
Some
((
tpe
,
elems
))
=>
val
chars
=
elems
.
collect
{
case
CharLiteral
(
ch
)
=>
ch
}
val
chars
=
elems
.
collect
{
case
CharLiteral
(
ch
)
=>
ch
}
if
(
chars
.
length
==
elems
.
length
&&
tpe
==
CharType
)
{
if
(
chars
.
length
==
elems
.
length
&&
tpe
==
CharType
)
{
// String literal
// String literal
val
str
=
chars
mkString
""
val
str
=
chars
mkString
""
...
@@ -147,12 +147,12 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -147,12 +147,12 @@ class PrettyPrinter(opts: PrinterOptions,
p
"$lclass($elems)"
p
"$lclass($elems)"
}
}
case
None
=>
case
None
=>
if
(
cct
.
classDef
.
isCaseObject
)
{
if
(
cct
.
classDef
.
isCaseObject
)
{
p
"$cct"
p
"$cct"
}
else
{
}
else
{
p
"$cct($args)"
p
"$cct($args)"
}
}
}
}
case
And
(
exprs
)
=>
optP
{
p
"${nary(exprs, "
&&
")}"
}
case
And
(
exprs
)
=>
optP
{
p
"${nary(exprs, "
&&
")}"
}
...
@@ -502,9 +502,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -502,9 +502,7 @@ class PrettyPrinter(opts: PrinterOptions,
p
"def ${fd.id}(${fd.params}): "
p
"def ${fd.id}(${fd.params}): "
}
}
p
"${fd.returnType} = "
p
"${fd.returnType} = ${fd.fullBody}"
p
"${fd.fullBody}"
case
(
tree
:
PrettyPrintable
)
=>
tree
.
printWith
(
ctx
)
case
(
tree
:
PrettyPrintable
)
=>
tree
.
printWith
(
ctx
)
...
@@ -539,7 +537,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -539,7 +537,7 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
object
FcallMethodInvocation
{
protected
object
FcallMethodInvocation
{
def
unapply
(
fi
:
FunctionInvocation
)
:
Option
[(
Expr
,
FunDef
,
String
,
Seq
[
TypeTree
]
,
Seq
[
Expr
])]
=
{
def
unapply
(
fi
:
FunctionInvocation
)
:
Option
[(
Expr
,
FunDef
,
String
,
Seq
[
TypeTree
]
,
Seq
[
Expr
])]
=
{
val
FunctionInvocation
(
tfd
,
args
)
=
fi
val
FunctionInvocation
(
tfd
,
args
)
=
fi
tfd
.
fd
.
methodOwner
.
map
{
cd
=>
tfd
.
fd
.
methodOwner
.
map
{
cd
=>
...
@@ -558,7 +556,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -558,7 +556,7 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
}
}
object
BinaryMethodCall
{
protected
object
BinaryMethodCall
{
val
makeBinary
=
Set
(
"+"
,
"-"
,
"*"
,
"::"
,
"++"
,
"--"
,
"&&"
,
"||"
,
"/"
)
val
makeBinary
=
Set
(
"+"
,
"-"
,
"*"
,
"::"
,
"++"
,
"--"
,
"&&"
,
"||"
,
"/"
)
def
unapply
(
fi
:
FunctionInvocation
)
:
Option
[(
Expr
,
String
,
Expr
)]
=
fi
match
{
def
unapply
(
fi
:
FunctionInvocation
)
:
Option
[(
Expr
,
String
,
Expr
)]
=
fi
match
{
...
@@ -576,12 +574,13 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -576,12 +574,13 @@ class PrettyPrinter(opts: PrinterOptions,
}
}
}
}
def
isSimpleExpr
(
e
:
Expr
)
:
Boolean
=
e
match
{
protected
def
isSimpleExpr
(
e
:
Expr
)
:
Boolean
=
e
match
{
case
_:
LetDef
|
_
:
Let
|
LetPattern
(
_
,
_
,
_
)
|
_:
Assert
|
_
:
Require
=>
false
case
_:
LetDef
|
_
:
Let
|
LetPattern
(
_
,
_
,
_
)
|
_:
Assert
|
_
:
Require
=>
false
case
p
:
PrettyPrintable
=>
p
.
isSimpleExpr
case
_
=>
true
case
_
=>
true
}
}
def
noBracesSub
(
e
:
Expr
)
=
e
match
{
protected
def
noBracesSub
(
e
:
Expr
)
=
e
match
{
case
Assert
(
_
,
_
,
bd
)
=>
Some
(
bd
)
case
Assert
(
_
,
_
,
bd
)
=>
Some
(
bd
)
case
Let
(
_
,
_
,
bd
)
=>
Some
(
bd
)
case
Let
(
_
,
_
,
bd
)
=>
Some
(
bd
)
case
LetDef
(
_
,
bd
)
=>
Some
(
bd
)
case
LetDef
(
_
,
bd
)
=>
Some
(
bd
)
...
@@ -589,10 +588,10 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -589,10 +588,10 @@ class PrettyPrinter(opts: PrinterOptions,
case
_
=>
None
case
_
=>
None
}
}
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
)
=>
case
(
_
,
None
)
=>
false
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
...
@@ -602,7 +601,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -602,7 +601,7 @@ class PrettyPrinter(opts: PrinterOptions,
false
false
}
}
def
precedence
(
ex
:
Expr
)
:
Int
=
ex
match
{
protected
def
precedence
(
ex
:
Expr
)
:
Int
=
ex
match
{
case
(
pa
:
PrettyPrintable
)
=>
pa
.
printPrecedence
case
(
pa
:
PrettyPrintable
)
=>
pa
.
printPrecedence
case
(
_:
ElementOfSet
)
=>
0
case
(
_:
ElementOfSet
)
=>
0
case
(
_:
Modulo
)
=>
1
case
(
_:
Modulo
)
=>
1
...
@@ -615,7 +614,7 @@ class PrettyPrinter(opts: PrinterOptions,
...
@@ -615,7 +614,7 @@ class PrettyPrinter(opts: PrinterOptions,
case
_
=>
9
case
_
=>
9
}
}
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
(
_
,
Some
(
_:
Ensuring
))
=>
false
case
(
_
,
Some
(
_:
Ensuring
))
=>
false
...
@@ -640,7 +639,7 @@ trait PrettyPrintable {
...
@@ -640,7 +639,7 @@ trait PrettyPrintable {
def
printPrecedence
:
Int
=
1000
def
printPrecedence
:
Int
=
1000
def
printRequiresParentheses
(
within
:
Option
[
Tree
])
:
Boolean
=
false
def
printRequiresParentheses
(
within
:
Option
[
Tree
])
:
Boolean
=
false
def
printRequiresBraces
(
within
:
Option
[
Tree
])
:
Boolean
=
false
def
isSimpleExpr
:
Boolean
=
false
}
}
class
EquivalencePrettyPrinter
(
opts
:
PrinterOptions
,
opgm
:
Option
[
Program
])
extends
PrettyPrinter
(
opts
,
opgm
)
{
class
EquivalencePrettyPrinter
(
opts
:
PrinterOptions
,
opgm
:
Option
[
Program
])
extends
PrettyPrinter
(
opts
,
opgm
)
{
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/xlang/Expressions.scala
+
7
−
7
View file @
15c957e6
...
@@ -25,12 +25,12 @@ object Expressions {
...
@@ -25,12 +25,12 @@ object Expressions {
}
}
def
printWith
(
implicit
pctx
:
PrinterContext
)
{
def
printWith
(
implicit
pctx
:
PrinterContext
)
{
p
"""|{
p
"${nary(exprs :+ last, "
\
n
")}"
| ${nary(exprs :+ last, "\n")}
|}"""
}
}
val
getType
=
last
.
getType
val
getType
=
last
.
getType
override
def
isSimpleExpr
=
false
}
}
case
class
Assignment
(
varId
:
Identifier
,
expr
:
Expr
)
extends
XLangExpr
with
Extractable
with
PrettyPrintable
{
case
class
Assignment
(
varId
:
Identifier
,
expr
:
Expr
)
extends
XLangExpr
with
Extractable
with
PrettyPrintable
{
...
@@ -104,11 +104,11 @@ object Expressions {
...
@@ -104,11 +104,11 @@ object Expressions {
}
}
def
printWith
(
implicit
pctx
:
PrinterContext
)
{
def
printWith
(
implicit
pctx
:
PrinterContext
)
{
p
"""|locally {
p
"""|var $binder = $value
| var $binder = $value
|$body"""
| $body
|}"""
}
}
override
def
isSimpleExpr
=
false
}
}
case
class
Waypoint
(
i
:
Int
,
expr
:
Expr
,
tpe
:
TypeTree
)
extends
XLangExpr
with
Extractable
with
PrettyPrintable
{
case
class
Waypoint
(
i
:
Int
,
expr
:
Expr
,
tpe
:
TypeTree
)
extends
XLangExpr
with
Extractable
with
PrettyPrintable
{
...
...
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