flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject [01/14] git commit: [flex-falcon] [refs/heads/develop] - In JS, initial property (non-literal) value assignments must take place in the constructor, not on the property definition itself
Date Fri, 31 Oct 2014 16:50:35 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop f05424470 -> bd111dd43


In JS, initial property (non-literal) value assignments must take place in the constructor,
not on the property definition itself

Signed-off-by: Erik de Bruin <erik@ixsoftware.nl>


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/af39216a
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/af39216a
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/af39216a

Branch: refs/heads/develop
Commit: af39216ad987f80d16888b3f77929c504b15a084
Parents: 0734ae4
Author: Erik de Bruin <erik@ixsoftware.nl>
Authored: Fri Oct 31 17:36:56 2014 +0100
Committer: Erik de Bruin <erik@ixsoftware.nl>
Committed: Fri Oct 31 17:44:03 2014 +0100

----------------------------------------------------------------------
 .../codegen/js/vf2js/JSVF2JSEmitter.java        | 83 +++++++++++++++++++-
 1 file changed, 80 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/af39216a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
index 1ff495c..939b2bf 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
@@ -33,12 +33,14 @@ import org.apache.flex.compiler.codegen.IDocEmitter;
 import org.apache.flex.compiler.codegen.js.vf2js.IJSVF2JSEmitter;
 import org.apache.flex.compiler.common.ASModifier;
 import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition.FunctionClassification;
 import org.apache.flex.compiler.definitions.INamespaceDefinition;
 import org.apache.flex.compiler.definitions.IPackageDefinition;
+import org.apache.flex.compiler.definitions.IParameterDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
@@ -71,6 +73,7 @@ import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IEmbedNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
@@ -80,6 +83,7 @@ import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.apache.flex.compiler.tree.as.IKeywordNode;
 import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode;
 import org.apache.flex.compiler.tree.as.ILiteralNode;
 import org.apache.flex.compiler.tree.as.ILiteralNode.LiteralType;
@@ -256,11 +260,81 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
     }
 
     @Override
+    public void emitFunctionBlockHeader(IFunctionNode node)
+    {
+        IDefinition def = node.getDefinition();
+        boolean isStatic = false;
+        if (def != null && def.isStatic())
+            isStatic = true;
+        boolean isLocal = false;
+        if (node.getFunctionClassification() == IFunctionDefinition.FunctionClassification.LOCAL)
+            isLocal = true;
+        if (hasBody(node) && !isStatic && !isLocal)
+            emitSelfReference(node);
+
+        emitRestParameterCodeBlock(node);
+
+        emitDefaultParameterCodeBlock(node);
+
+        if (node.isConstructor())
+        {
+        	emitVarNonLiteralAssignments();
+        }
+        
+        if (node.isConstructor()
+                && hasSuperClass(node) && !hasSuperCall(node.getScopedNode()))
+            emitSuperCall(node, CONSTRUCTOR_FULL);
+    }
+
+    private void emitVarNonLiteralAssignments()
+    {
+        // (erikdebruin): If the initial value of a variable is set using
+        //                a method, JS needs this initialization to be done
+        //                in the constructor
+    	IClassNode cdnode = (IClassNode) thisClass.getNode();
+        IDefinitionNode[] dnodes = cdnode.getAllMemberNodes();
+        for (IDefinitionNode dnode : dnodes)
+        {
+            if (dnode.getNodeID() == ASTNodeID.VariableID)
+            {
+            	IVariableNode vnode = (IVariableNode) dnode;
+            	IExpressionNode avnode = vnode.getAssignedValueNode();
+                if (avnode != null && 
+            		!(avnode instanceof ILiteralNode) && 
+            		!(avnode instanceof IEmbedNode))
+                {
+                	writeNewline("", true);
+                	if (vnode.hasModifier(ASModifier.STATIC))
+                	{
+                		write(cdnode.getQualifiedName());
+                	}
+                	else
+                	{
+                		write(ASEmitterTokens.THIS);
+                	}
+                	write(ASEmitterTokens.MEMBER_ACCESS);
+                	writeToken(vnode.getName());
+                	writeToken(ASEmitterTokens.EQUAL);
+                	getWalker().walk(avnode);
+                	indentPop();
+                	writeNewline(ASEmitterTokens.SEMICOLON);
+                }
+            }
+        }
+    }
+    
+    @Override
     public void emitVarDeclaration(IVariableNode node)
     {
         if (!(node instanceof ChainedVariableNode))
         {
-            emitMemberKeyword(node);
+        	// (erikdebruin): check for 'var i:int = 0, j:int = 0' containers
+        	IASNode pnode = node.getParent();
+        	if (!(pnode instanceof IVariableExpressionNode) || 
+        			node.getChild(0) instanceof IKeywordNode)
+        	{
+        		emitMemberKeyword(node);
+        	}
         }
 
         IExpressionNode avnode = node.getAssignedValueNode();
@@ -332,7 +406,7 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
                 + node.getName());
 
         IExpressionNode vnode = node.getAssignedValueNode();
-        if (vnode != null && !(vnode instanceof IEmbedNode))
+        if (vnode != null && vnode instanceof ILiteralNode)
         {
             write(ASEmitterTokens.SPACE);
             writeToken(ASEmitterTokens.EQUAL);
@@ -454,9 +528,12 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
         {
             write(ASEmitterTokens.SPACE);
             write(ASEmitterTokens.BLOCK_OPEN);
+            emitVarNonLiteralAssignments();
             if (hasSuperClass)
+            {
                 emitSuperCall(node, CONSTRUCTOR_EMPTY);
-            writeNewline();
+                writeNewline();
+            }
             write(ASEmitterTokens.BLOCK_CLOSE);
         }
 


Mime
View raw message