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
987da1a7
Commit
987da1a7
authored
9 years ago
by
Marco Antognini
Committed by
Etienne Kneuss
9 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improve C Pretty Printer regarding semicolon
parent
13937ce4
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/genc/CAST.scala
+23
-5
23 additions, 5 deletions
src/main/scala/leon/genc/CAST.scala
src/main/scala/leon/genc/CPrinter.scala
+7
-16
7 additions, 16 deletions
src/main/scala/leon/genc/CPrinter.scala
with
30 additions
and
21 deletions
src/main/scala/leon/genc/CAST.scala
+
23
−
5
View file @
987da1a7
...
@@ -230,11 +230,29 @@ object CAST { // C Abstract Syntax Tree
...
@@ -230,11 +230,29 @@ object CAST { // C Abstract Syntax Tree
/* ------------------------------------------------------------- DSL ----- */
/* ------------------------------------------------------------- DSL ----- */
// Operator ~~ appends and flattens nested compounds
// Operator ~~ appends and flattens nested compounds
implicit
class
StmtOps
(
val
stmt
:
Stmt
)
{
implicit
class
StmtOps
(
val
stmt
:
Stmt
)
{
def
~
(
other
:
Stmt
)
=
(
stmt
,
other
)
match
{
// In addition to combining statements together in a compound
case
(
Compound
(
stmts
),
Compound
(
others
))
=>
Compound
(
stmts
++
others
)
// we remove the empty ones and if the resulting compound
case
(
stmt
,
Compound
(
others
))
=>
Compound
(
stmt
+:
others
)
// has only one statement we return this one without being
case
(
Compound
(
stmts
),
other
)
=>
Compound
(
stmts
:+
other
)
// wrapped into a Compound
case
(
stmt
,
other
)
=>
Compound
(
stmt
::
other
::
Nil
)
def
~
(
other
:
Stmt
)
=
{
val
stmts
=
(
stmt
,
other
)
match
{
case
(
Compound
(
stmts
),
Compound
(
others
))
=>
stmts
++
others
case
(
stmt
,
Compound
(
others
))
=>
stmt
+:
others
case
(
Compound
(
stmts
),
other
)
=>
stmts
:+
other
case
(
stmt
,
other
)
=>
stmt
::
other
::
Nil
}
def
isNoStmt
(
s
:
Stmt
)
=
s
match
{
case
NoStmt
=>
true
case
_
=>
false
}
val
compound
=
Compound
(
stmts
filterNot
isNoStmt
)
compound
match
{
case
Compound
(
stmts
)
if
stmts
.
length
==
0
=>
NoStmt
case
Compound
(
stmts
)
if
stmts
.
length
==
1
=>
stmts
.
head
case
compound
=>
compound
}
}
}
def
~~
(
others
:
Seq
[
Stmt
])
=
stmt
~
Compound
(
others
)
def
~~
(
others
:
Seq
[
Stmt
])
=
stmt
~
Compound
(
others
)
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/genc/CPrinter.scala
+
7
−
16
View file @
987da1a7
...
@@ -57,25 +57,16 @@ class CPrinter(val sb: StringBuffer = new StringBuffer) {
...
@@ -57,25 +57,16 @@ class CPrinter(val sb: StringBuffer = new StringBuffer) {
/* --------------------------------------------------------- Stmts ----- */
/* --------------------------------------------------------- Stmts ----- */
case
NoStmt
=>
c
"/* empty */"
case
NoStmt
=>
c
"/* empty */"
// Try to print new lines and semicolon somewhat correctly
case
Compound
(
stmts
)
if
stmts
.
isEmpty
=>
// should not happen
case
Compound
(
stmts
)
if
stmts
.
length
==
1
=>
stmts
.
head
match
{
case
s
:
Call
=>
c
"$s;"
// for function calls whose returned value is not saved
case
s
=>
c
"$s"
}
case
Compound
(
stmts
)
=>
case
Compound
(
stmts
)
=>
val
head
=
stmts
.
head
val
lastIdx
=
stmts
.
length
-
1
val
tail
=
Compound
(
stmts
.
tail
)
for
((
stmt
,
idx
)
<-
stmts
.
zipWithIndex
)
{
if
(
stmt
.
isValue
)
c
"$stmt;"
else
c
"$stmt"
head
match
{
if
(
idx
!=
lastIdx
)
case
s
:
Call
=>
c
"$s;"
// for function calls whose returned value is not saved
c
"$NewLine"
case
s
=>
c
"$s"
}
}
c
"$NewLine$tail"
case
Assert
(
pred
,
Some
(
error
))
=>
c
"assert($pred); /* $error */"
case
Assert
(
pred
,
Some
(
error
))
=>
c
"assert($pred); /* $error */"
case
Assert
(
pred
,
None
)
=>
c
"assert($pred);"
case
Assert
(
pred
,
None
)
=>
c
"assert($pred);"
...
...
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