Added While loop missing block 'fix' to For loops, adjusted implementation to avoid GCC warning (which warns need of output of an explicit empty code block for the loop -this may be then removed again during minification).
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/ForLoopEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/ForLoopEmitter.java
index febe699..21ee8d9 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/ForLoopEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/ForLoopEmitter.java
@@ -39,7 +39,7 @@
@Override
public void emit(IForLoopNode node)
{
- IContainerNode xnode = (IContainerNode) node.getChild(1);
+ IContainerNode statementContentsNode = (IContainerNode) node.getStatementContentsNode();
startMapping(node);
writeToken(ASEmitterTokens.FOR);
@@ -60,11 +60,22 @@
startMapping(node, cnode);
write(ASEmitterTokens.PAREN_CLOSE);
- if (!EmitterUtils.isImplicit(xnode))
+ if (!EmitterUtils.isImplicit(statementContentsNode))
write(ASEmitterTokens.SPACE);
endMapping(node);
+ //if we have a for loop that has no body, then emit it with an explicit 'empty block'.
+ //Otherwise the loop body will be considered to be the following statement
+ //the empty block is to avoid this from GCC: "WARNING - If this if/for/while really shouldn't have a body, use {}"
+ if (EmitterUtils.isImplicit(statementContentsNode)
+ && statementContentsNode.getChildCount() == 0) {
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ writeToken(ASEmitterTokens.SEMICOLON);
+ } else {
+ getWalker().walk(statementContentsNode);
+ }
- getWalker().walk(node.getStatementContentsNode());
}
protected void emitForStatements(IContainerNode node)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/WhileLoopEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/WhileLoopEmitter.java
index 8395fc1..7fc27a6 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/WhileLoopEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/WhileLoopEmitter.java
@@ -54,11 +54,14 @@
if (!EmitterUtils.isImplicit(statementContentsNode))
write(ASEmitterTokens.SPACE);
endMapping(node);
- //if we have a while loop that has no body, then emit it the same way as it would be expressed
- //in the original as3 source, with a semicolon terminator.
+ //if we have a while loop that has no body, then emit it with an explicit 'empty block'.
//Otherwise the loop body will be considered to be the following statement
+ //the empty block is to avoid this from GCC: "WARNING - If this if/for/while really shouldn't have a body, use {}"
if (EmitterUtils.isImplicit(statementContentsNode)
&& statementContentsNode.getChildCount() == 0) {
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ write(ASEmitterTokens.BLOCK_CLOSE);
writeToken(ASEmitterTokens.SEMICOLON);
} else {
getWalker().walk(statementContentsNode);