flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - attempt #2 at some implicit type conversions
Date Tue, 09 Aug 2016 20:45:58 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 8f68c66d2 -> fff63d367


attempt #2 at some implicit type conversions


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

Branch: refs/heads/develop
Commit: fff63d3673d9b0a288778efa2ae04f2c52073889
Parents: 8f68c66
Author: Alex Harui <aharui@apache.org>
Authored: Tue Aug 9 13:45:41 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Aug 9 13:45:55 2016 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSDocEmitter.java   |  6 ++
 .../js/flexjs/JSFlexJSEmitterTokens.java        |  1 +
 .../codegen/js/jx/BinaryOperatorEmitter.java    | 23 +++++---
 .../codegen/js/jx/VarDeclarationEmitter.java    | 16 ++---
 .../utils/JSClosureCompilerWrapper.java         |  2 +-
 .../js/flexjs/TestFlexJSExpressions.java        | 62 +++++++++++++++++++-
 .../js/flexjs/TestFlexJSGlobalClasses.java      |  6 +-
 7 files changed, 96 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
index 057bcf1..b94d0b0 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSDocEmitter.java
@@ -50,6 +50,7 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
     private List<String> classIgnoreList;
     private List<String> ignoreList;
     private List<String> coercionList;
+    public boolean emitStringConversions = true;
 
     public JSFlexJSDocEmitter(IJSEmitter emitter)
     {
@@ -102,6 +103,7 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
     {
         coercionList = null;
         ignoreList = null;
+        emitStringConversions = true;
 
         IClassDefinition classDefinition = resolveClassDefinition(node);
 
@@ -167,6 +169,10 @@ public class JSFlexJSDocEmitter extends JSGoogDocEmitter
                         		.getToken();
 		                if (docText.contains(ignoreToken))
 		                    loadIgnores(docText);
+                        String noStringToken = JSFlexJSEmitterTokens.IGNORE_STRING_COERCION
+                        		.getToken();
+		                if (docText.contains(noStringToken))
+		                    emitStringConversions = false;
                         write(changeAnnotations(asDoc.commentNoEnd()));
                     }
                     else

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
index 67623a9..2e24236 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java
@@ -39,6 +39,7 @@ public enum JSFlexJSEmitterTokens implements IEmitterTokens
     EMIT_COERCION("@flexjsemitcoercion"),
     IGNORE_COERCION("@flexjsignorecoercion"),
     IGNORE_IMPORT("@flexjsignoreimport"),
+    IGNORE_STRING_COERCION("@flexjsnoimplicitstringconversion"),
     PREINCREMENT("preincrement"),
     PREDECREMENT("predecrement"),
     POSTINCREMENT("postincrement"),

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index 35e1364..87e07c5 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -19,12 +19,16 @@
 
 package org.apache.flex.compiler.internal.codegen.js.jx;
 
+import java.util.List;
+
+import org.apache.flex.compiler.asdoc.flexjs.ASDocComment;
 import org.apache.flex.compiler.codegen.ISubEmitter;
 import org.apache.flex.compiler.codegen.js.IJSEmitter;
 import org.apache.flex.compiler.constants.IASLanguageConstants;
 import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSDocEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
@@ -39,6 +43,7 @@ import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.utils.ASNodeUtils;
 
@@ -287,8 +292,8 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
             				fjs.isXMLList(mae);
             	}
             }
-            super_emitBinaryOperator(node, leftIsNumber, rightIsNumber);
-            if (leftDef != null && leftDef.getQualifiedName().equals(IASLanguageConstants.String))
+            String coercion = (leftIsNumber && !rightIsNumber) ? "Number(" : "";
+            if (isAssignment && leftDef != null && leftDef.getQualifiedName().equals(IASLanguageConstants.String))
             {
             	if (rNode.getNodeID() != ASTNodeID.LiteralStringID &&
             			rNode.getNodeID() != ASTNodeID.LiteralNullID)
@@ -299,11 +304,16 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
 		        			  (!isAssignment && rightIsNumber) ||
 		        			   rightDef.getQualifiedName().equals(IASLanguageConstants.Null))))
 		        	{
-		        		write(".toString()");
+		        		JSFlexJSDocEmitter docEmitter = (JSFlexJSDocEmitter)(getEmitter().getDocEmitter());
+		        		if (docEmitter.emitStringConversions)
+		        		{
+		        			coercion = "org.apache.flex.utils.Language.string(";
+		        		}
 		        	}
             	}
             }
-            if (leftIsNumber && !rightIsNumber)
+            super_emitBinaryOperator(node, coercion);
+            if (coercion.length() > 0)
             	write(")");
             	
             /*
@@ -372,7 +382,7 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
         }
     }
 
-    private void super_emitBinaryOperator(IBinaryOperatorNode node, boolean leftIsNumber,
boolean rightIsNumber)
+    private void super_emitBinaryOperator(IBinaryOperatorNode node, String coercion)
     {
         if (ASNodeUtils.hasParenOpen(node))
             write(ASEmitterTokens.PAREN_OPEN);
@@ -441,8 +451,7 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
             write(ASEmitterTokens.SPACE);
             endMapping(node);
 
-            if (leftIsNumber && !rightIsNumber)
-            	write("Number(");
+            write(coercion);
             /*
             IDefinition definition = node.getRightOperandNode().resolve(getProject());
         	if (definition instanceof FunctionDefinition &&

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
index 6beafcd..56c3fe9 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
@@ -132,15 +132,17 @@ public class VarDeclarationEmitter extends JSSubEmitter implements
             				fjs.isXMLList(mae);
             	}
             }
+            String coercion = "";
             if (varIsNumber && !valIsNumber)
-            	write("Number(");
-            fjs.emitAssignedValue(avnode);
+            	coercion = "Number(";
             if (variableTypeNode.getNodeID() == ASTNodeID.IdentifierID &&
-            	((IdentifierNode)variableTypeNode).getName().equals(IASLanguageConstants.String)
&&
-            	(avdef == null || (!avdef.getQualifiedName().equals(IASLanguageConstants.String)
&&
-            			            !avdef.getQualifiedName().equals(IASLanguageConstants.Null))))
-            	write(".toString()");
-            if (varIsNumber && !valIsNumber)
+                	((IdentifierNode)variableTypeNode).getName().equals(IASLanguageConstants.String)
&&
+                	(avdef == null || (!avdef.getQualifiedName().equals(IASLanguageConstants.String)
&&
+                			            !avdef.getQualifiedName().equals(IASLanguageConstants.Null))))
+                	coercion = "org.apache.flex.utils.Language.string(";
+            write(coercion);
+            fjs.emitAssignedValue(avnode);
+            if (coercion.length() > 0)
               	write(")");
         }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
index 4008b01..f39382d 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
@@ -172,7 +172,7 @@ public class JSClosureCompilerWrapper
         String[] asdocTags = new String[] {"productversion", 
         		"playerversion", "langversion", "copy", 
         		"asparam", "asreturn", "asprivate",
-        		"flexjsignoreimport", "flexjsignorecoercion"};
+        		"flexjsignoreimport", "flexjsignorecoercion", "flexjsnoimplicitstringconversion"};
         options_.setExtraAnnotationNames(Arrays.asList(asdocTags));
     }
     

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index 64b9cc2..20c16f1 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -19,11 +19,14 @@
 
 package org.apache.flex.compiler.internal.codegen.js.flexjs;
 
+import org.apache.flex.compiler.clients.MXMLJSC;
 import org.apache.flex.compiler.definitions.IClassDefinition;
 import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.exceptions.ConfigurationException;
 import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogExpressions;
 import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
 import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration;
+import org.apache.flex.compiler.internal.parsing.as.FlexJSASDocDelegate;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.ClassNode;
 import org.apache.flex.compiler.internal.tree.as.LiteralNode;
@@ -42,12 +45,21 @@ import org.junit.Test;
  * @author Erik de Bruin
  */
 public class TestFlexJSExpressions extends TestGoogExpressions
-{
+ {
     @Override
     public void setUp()
     {
     	project = new FlexJSProject(workspace);
-    	((FlexJSProject)project).config = new JSGoogConfiguration();
+        workspace.setASDocDelegate(new FlexJSASDocDelegate());
+    	JSGoogConfiguration config = new JSGoogConfiguration();
+    	try {
+			config.setKeepASDoc(null, true);
+		} catch (ConfigurationException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		MXMLJSC.keepASDoc = true;
+    	((FlexJSProject)project).config = config;
         super.setUp();
     }
 
@@ -556,6 +568,52 @@ public class TestFlexJSExpressions extends TestGoogExpressions
     }
 
     @Test
+    public void testVisitBinaryOperatorNode_StringVarAssignmentFromObject()
+    {
+        IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+                "public class B {public var b:String; public var c:Object; public function
d() { b = c; }}",
+                IBinaryOperatorNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("this.b = org.apache.flex.utils.Language.string(this.c)");
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_StringVarAssignmentFromObjectSupressed()
+    {
+        IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+                "public class B {public var b:String; public var c:Object; /**\n * @flexjsnoimplicitstringconversion\n
*/\npublic function d() { b = c; }}",
+                IBinaryOperatorNode.class, WRAP_LEVEL_PACKAGE);
+        JSFlexJSDocEmitter docEmitter = (JSFlexJSDocEmitter)(asBlockWalker.getEmitter().getDocEmitter());
+        IFunctionNode methodNode = (IFunctionNode)(node.getAncestorOfType(IFunctionNode.class));
+        
+        // this adds '/**\n * @flexjsnoimplicitstringconversion\n * @export\n */' to the
output but parses
+        // the asdoc so the emitter will suppress the output
+        docEmitter.emitMethodDoc(methodNode, asBlockWalker.getProject());
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("/**\n * @flexjsnoimplicitstringconversion\n * @export\n */\nthis.b = this.c");
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_StringVarCompareWithObject()
+    {
+        IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+                "public class B {public var b:String; public var c:Object; public function
c() { b == c; }}",
+                IBinaryOperatorNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("this.b == this.c");
+    }
+
+    @Test
+    public void testVisitBinaryOperatorNode_StringVarInObject()
+    {
+        IBinaryOperatorNode node = (IBinaryOperatorNode) getNode(
+                "public class B {public var b:String; public var c:Object; public function
c() { if (b in c); }}",
+                IBinaryOperatorNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitBinaryOperator(node);
+        assertOut("this.b in this.c");
+    }
+
+    @Test
     public void testNamedFunctionAsArgument()
     {
         IFunctionNode node = (IFunctionNode) getNode(

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fff63d36/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index 5e2d3a9..fa17867 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -480,7 +480,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         IASNode parentNode = node.getParent();
         node = (IVariableNode) parentNode.getChild(1);
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {string} */ b = a.name().toString()");
+        assertOut("var /** @type {string} */ b = org.apache.flex.utils.Language.string(a.name())");
     }
     
     @Test
@@ -520,7 +520,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         IASNode parentNode = node.getParent();
         node = (IVariableNode) parentNode.getChild(1);
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {string} */ b = a.attribute('attr1').toString()");
+        assertOut("var /** @type {string} */ b = org.apache.flex.utils.Language.string(a.attribute('attr1'))");
     }
     
     @Test
@@ -528,7 +528,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
     	IBinaryOperatorNode node = (IBinaryOperatorNode)getNode("var a:XML = new XML(\"<top
attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");var
b:String; b = a.@attr1;", IBinaryOperatorNode.class);
         asBlockWalker.visitBinaryOperator(node);
-        assertOut("b = a.attribute('attr1').toString()");
+        assertOut("b = org.apache.flex.utils.Language.string(a.attribute('attr1'))");
     }
     
     @Test


Mime
View raw message