You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2020/06/24 02:26:16 UTC

[royale-compiler] branch develop updated: 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).

This is an automated email from the ASF dual-hosted git repository.

gregdove pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new cad319d  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).
cad319d is described below

commit cad319d019016dee25e1150c42e4356888d9c6a6
Author: greg-dove <gr...@gmail.com>
AuthorDate: Wed Jun 24 14:19:14 2020 +1200

    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).
---
 .../compiler/internal/codegen/js/jx/ForLoopEmitter.java | 17 ++++++++++++++---
 .../internal/codegen/js/jx/WhileLoopEmitter.java        |  7 +++++--
 2 files changed, 19 insertions(+), 5 deletions(-)

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 @@ public class ForLoopEmitter extends JSSubEmitter implements
     @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 @@ public class ForLoopEmitter extends JSSubEmitter implements
 
         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 @@ public class WhileLoopEmitter extends JSSubEmitter implements
         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);