incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1427024 - in /incubator/flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/ compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ compiler.jx/src/org/apache/flex/compiler/int...
Date Mon, 31 Dec 2012 00:18:35 GMT
Author: mschmalle
Date: Mon Dec 31 00:18:35 2012
New Revision: 1427024

URL: http://svn.apache.org/viewvc?rev=1427024&view=rev
Log:
Flex:FalconJx
- added initial support for getter/setter accessors in 'goog' production

Modified:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java?rev=1427024&r1=1427023&r2=1427024&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogAccessorMembers.java
Mon Dec 31 00:18:35 2012
@@ -23,10 +23,11 @@ import org.apache.flex.compiler.clients.
 import org.apache.flex.compiler.internal.as.codegen.TestAccessorMembers;
 import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.junit.Test;
 
 /**
- * This class tests the production of valid 'goog' JS code for Class Accessor 
+ * This class tests the production of valid 'goog' JS code for Class Accessor
  * members.
  * 
  * @author Michael Schmalle
@@ -34,24 +35,34 @@ import org.junit.Test;
  */
 public class TestGoogAccessorMembers extends TestAccessorMembers
 {
-	// TODO (erikdebruin)
-	//  1) do we have to compile with '--language_in=ECMASCRIPT5'?
-	
+    // TODO (erikdebruin)
+    //  1) do we have to compile with '--language_in=ECMASCRIPT5'?
+
     @Override
     @Test
     public void testGetAccessor()
     {
-    	IAccessorNode node = getAccessor("function get foo():int{return -1;}");
-        visitor.visitFunction(node);
-        //assertOut("Object.defineProperty(A.prototype, 'foo', {get: function() {return -1;},
configurable: true});");
+        /*
+        Object.defineProperty(
+            A.prototype, 
+            'foo', 
+            {get:function() {
+                return -1;
+            }, configurable:true}
+        )
+         */
+        IGetterNode node = (IGetterNode) getAccessor("function get foo():int{return -1;}");
+        visitor.visitGetter(node);
+        assertOut("Object.defineProperty(\n\tA.prototype, \n\t'foo', "
+                + "\n\t{get:function() {\n\t\treturn -1;\n\t}, configurable:true}\n)");
     }
 
     @Override
     @Test
     public void testGetAccessor_withNamespace()
     {
-        IAccessorNode node = getAccessor("public function get foo():int{return -1;}");
-        visitor.visitFunction(node);
+        IGetterNode node = (IGetterNode) getAccessor("public function get foo():int{return
-1;}");
+        visitor.visitGetter(node);
         //assertOut("");
     }
 
@@ -77,7 +88,7 @@ public class TestGoogAccessorMembers ext
     @Test
     public void testSetAccessor()
     {
-    	IAccessorNode node = getAccessor("function set foo(value:int):void{}");
+        IAccessorNode node = getAccessor("function set foo(value:int):void{}");
         visitor.visitFunction(node);
         //assertOut("Object.defineProperty(A.prototype, 'foo', {set: function(value) {},
configurable: true});");
     }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java?rev=1427024&r1=1427023&r2=1427024&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASBlockWalker.java
Mon Dec 31 00:18:35 2012
@@ -489,14 +489,14 @@ public class ASBlockWalker implements IA
     public void visitGetter(IGetterNode node)
     {
         debug("visitGetter()");
-        visitFunction(node);
+        emitter.emitGetAccessor(node);
     }
 
     @Override
     public void visitSetter(ISetterNode node)
     {
         debug("visitSetter()");
-        visitFunction(node);
+        emitter.emitSetAccessor(node);
     }
 
     @Override

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java?rev=1427024&r1=1427023&r2=1427024&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
Mon Dec 31 00:18:35 2012
@@ -28,6 +28,7 @@ import java.util.Map;
 
 import org.apache.flex.compiler.common.ASModifier;
 import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.definitions.IPackageDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.js.codegen.JSEmitter;
@@ -38,11 +39,14 @@ import org.apache.flex.compiler.js.codeg
 import org.apache.flex.compiler.js.codegen.goog.IJSGoogEmitter;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
@@ -292,6 +296,12 @@ public class JSGoogEmitter extends JSEmi
     }
 
     @Override
+    public void emitGetAccessor(IGetterNode node)
+    {
+        emitObjectDefineProperty(node);
+    }
+
+    @Override
     public void emitMethod(IFunctionNode node)
     {
         if (node.isConstructor())
@@ -549,4 +559,55 @@ public class JSGoogEmitter extends JSEmi
 
         return false;
     }
+
+    private void emitObjectDefineProperty(IAccessorNode node)
+    {
+        /*
+        Object.defineProperty(
+            A.prototype, 
+            'foo', 
+            {get: function() {return -1;}, 
+            configurable: true}
+         );
+        */
+        // head
+        write("Object.defineProperty(");
+        indentPush();
+        write("\n");
+
+        // Type
+        IFunctionDefinition definition = node.getDefinition();
+        ITypeDefinition type = (ITypeDefinition) definition.getParent();
+        write(type.getQualifiedName());
+        write(".");
+        write("prototype");
+        write(", ");
+        write("\n");
+
+        // name
+        write("'");
+        write(definition.getBaseName());
+        write("'");
+        write(", ");
+        write("\n");
+
+        // info object
+        // declaration
+        write("{");
+        write(node.getNodeID() == ASTNodeID.GetterID ? "get" : "set");
+        write(":");
+        write("function");
+        emitParamters(node.getParameterNodes());
+
+        emitMethodScope(node.getScopedNode());
+
+        write(", ");
+        write("configurable:true");
+        write("}");
+        indentPop();
+        write("\n");
+
+        // tail, no colon; parent container will add it
+        write(")");
+    }
 }



Mime
View raw message