fix a bug which is converting from for(;;) to while()
This commit is contained in:
committed by
Pavel V. Talanov
parent
55c00b08e7
commit
8c66f744b4
@@ -4,7 +4,7 @@ import java.util.LinkedList
|
|||||||
|
|
||||||
public open class Block(val statements: List<Element>, val notEmpty: Boolean = false): Statement() {
|
public open class Block(val statements: List<Element>, val notEmpty: Boolean = false): Statement() {
|
||||||
public override fun isEmpty(): Boolean {
|
public override fun isEmpty(): Boolean {
|
||||||
return !notEmpty && statements.size() == 0
|
return !notEmpty && (statements.size() == 0 || statements.all { it == Statement.EMPTY_STATEMENT })
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun toKotlin(): String {
|
public override fun toKotlin(): String {
|
||||||
|
|||||||
@@ -99,9 +99,13 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
|||||||
else {
|
else {
|
||||||
var forStatements = ArrayList<Element>()
|
var forStatements = ArrayList<Element>()
|
||||||
forStatements.add(getConverter().statementToStatement(initialization))
|
forStatements.add(getConverter().statementToStatement(initialization))
|
||||||
forStatements.add(WhileStatement(getConverter().expressionToExpression(condition),
|
forStatements.add(WhileStatement(
|
||||||
Block(arrayList(getConverter().statementToStatement(body),
|
if (condition == null)
|
||||||
Block(arrayList(getConverter().statementToStatement(update)), false)), false)))
|
LiteralExpression("true")
|
||||||
|
else
|
||||||
|
getConverter().expressionToExpression(condition)
|
||||||
|
, Block(arrayListOf(getConverter().statementToStatement(body),
|
||||||
|
Block(arrayListOf(getConverter().statementToStatement(update)), false)), false)))
|
||||||
myResult = Block(forStatements, false)
|
myResult = Block(forStatements, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
for (init(); ; update()) body();
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
init()
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
body()
|
||||||
|
{
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
for (; condition() ; update()) body();
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
while (condition())
|
||||||
|
{
|
||||||
|
body()
|
||||||
|
{
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
for (init(); condition(); ) body();
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
init()
|
||||||
|
while (condition())
|
||||||
|
{
|
||||||
|
body()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user