incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1423226 - in /incubator/flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/js/internal/driver/ compiler.jx/src/org/apache/flex/as/ compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ compiler.jx/src/org/apa...
Date Mon, 17 Dec 2012 23:47:26 GMT
Author: mschmalle
Date: Mon Dec 17 23:47:25 2012
New Revision: 1423226

URL: http://svn.apache.org/viewvc?rev=1423226&view=rev
Log:
Flex:FalconJx
- Added TestMethodMembers for Class methods
- Refactored ASEmitter to share production methods with member emitters

Added:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestMethodMembers.java
  (with props)
Modified:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestFieldMembers.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestFieldMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestFieldMembers.java?rev=1423226&r1=1423225&r2=1423226&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestFieldMembers.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestFieldMembers.java
Mon Dec 17 23:47:25 2012
@@ -32,9 +32,7 @@ import org.junit.Test;
 public class TestFieldMembers extends TestWalkerBase
 {
     /*
-     * Field, Constant, Namespace
-     * 
-     * - config block
+     * Field, Constant, [Namespace]
      * 
      * var foo;
      * var foo:int;

Added: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestMethodMembers.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestMethodMembers.java?rev=1423226&view=auto
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestMethodMembers.java
(added)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestMethodMembers.java
Mon Dec 17 23:47:25 2012
@@ -0,0 +1,158 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.flex.js.internal.driver;
+
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * This class tests the production of valid ActionScript3 code for Class Method
+ * members.
+ * 
+ * @author Michael Schmalle
+ */
+public class TestMethodMembers extends TestWalkerBase
+{
+    /*
+     * Method
+     * 
+     * function foo(){}
+     * function foo():int{}
+     * function foo(bar):int{}
+     * function foo(bar:String):int{}
+     * function foo(bar:String = "baz"):int{}
+     * function foo(bar:String, baz:int = null):int{}
+     * function foo(bar:String, ...rest):int{}
+     * public function foo(bar:String, baz:int = null):int{}
+     * public static function foo(bar:String, baz:int = null):int{}
+     */
+
+    //--------------------------------------------------------------------------
+    // Method
+    //--------------------------------------------------------------------------
+
+    @Test
+    public void testMethod()
+    {
+        IFunctionNode node = getMethod("function foo(){}");
+        visitor.visitFunction(node);
+        assertOut("function foo() {\n}");
+    }
+
+    @Test
+    public void testMethod_withReturnType()
+    {
+        IFunctionNode node = getMethod("function foo():int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("function foo():int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testMethod_withParameterReturnType()
+    {
+        IFunctionNode node = getMethod("function foo(bar):int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("function foo(bar:*):int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testMethod_withParameterTypeReturnType()
+    {
+        IFunctionNode node = getMethod("function foo(bar:String):int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("function foo(bar:String):int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testMethod_withDefaultParameterTypeReturnType()
+    {
+        IFunctionNode node = getMethod("function foo(bar:String = \"baz\"):int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("function foo(bar:String = \"baz\"):int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testMethod_withMultipleDefaultParameterTypeReturnType()
+    {
+        IFunctionNode node = getMethod("function foo(bar:String, baz:int = null):int{\treturn
-1;}");
+        visitor.visitFunction(node);
+        assertOut("function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+    }
+
+    @Ignore
+    @Test
+    public void testMethod_withRestParameterTypeReturnType()
+    {
+        IFunctionNode node = getMethod("function foo(bar:String, ...rest):int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("function foo(bar:String, ...rest):int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testMethod_withNamespace()
+    {
+        IFunctionNode node = getMethod("public function foo(bar:String, baz:int = null):int{\treturn
-1;}");
+        visitor.visitFunction(node);
+        assertOut("public function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testMethod_withNamespaceCustom()
+    {
+        IFunctionNode node = getMethod("mx_internal function foo(bar:String, baz:int = null):int{\treturn
-1;}");
+        visitor.visitFunction(node);
+        assertOut("mx_internal function foo(bar:String, baz:int = null):int {\n\treturn -1;\n}");
+    }
+    
+    @Test
+    public void testMethod_withNamespaceModifiers()
+    {
+        IFunctionNode node = getMethod("public static function foo(bar:String, baz:int =
null):int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("public static function foo(bar:String, baz:int = null):int {\n\treturn
-1;\n}");
+    }
+
+    @Test
+    public void testMethod_withNamespaceModifierOverride()
+    {
+        IFunctionNode node = getMethod("public override function foo(bar:String, baz:int
= null):int{\treturn -1;}");
+        visitor.visitFunction(node);
+        assertOut("public override function foo(bar:String, baz:int = null):int {\n\treturn
-1;\n}");
+    }
+
+    @Test
+    public void testMethod_withNamespaceModifierOverrideBackwards()
+    {
+        IFunctionNode node = getMethod("override public function foo(bar:String, baz:int
= null):int{return -1;}");
+        visitor.visitFunction(node);
+        assertOut("public override function foo(bar:String, baz:int = null):int {\n\treturn
-1;\n}");
+    }
+
+    protected IFunctionNode getMethod(String code)
+    {
+        String source = "package {public class A {" + code + "}}";
+        IFileNode node = getFileNode(source);
+        IFunctionNode child = (IFunctionNode) findFirstDescendantOfType(node,
+                IFunctionNode.class);
+        return child;
+    }
+}

Propchange: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestMethodMembers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java?rev=1423226&r1=1423225&r2=1423226&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/as/IASEmitter.java
Mon Dec 17 23:47:25 2012
@@ -21,6 +21,7 @@ package org.apache.flex.as;
 
 import java.io.Writer;
 
+import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.visitor.IASNodeStrategy;
 
@@ -46,22 +47,37 @@ public interface IASEmitter
     void indentPush();
 
     /**
-     * Pops an indent from the emitter so after newlines are emitted, the
-     * output is correctly formatted.
+     * Pops an indent from the emitter so after newlines are emitted, the output
+     * is correctly formatted.
      */
     void indentPop();
-    
+
     /**
-     * Emit a documentation comment for a Class field {@link IVariableNode}.
+     * Emit a documentation comment for a Class field or constant
+     * {@link IVariableNode}.
      * 
      * @param node The {@link IVariableNode} class field member.
      */
-    void emitDocumentation(IVariableNode node);
-    
+    void emitFieldDocumentation(IVariableNode node);
+
     /**
      * Emit a full Class field member.
      * 
      * @param node The {@link IVariableNode} class field member.
      */
     void emitField(IVariableNode node);
+
+    /**
+     * Emit a documentation comment for a Class method {@link IFunctionNode}.
+     * 
+     * @param node The {@link IFunctionNode} class method member.
+     */
+    void emitMethodDocumentation(IFunctionNode node);
+
+    /**
+     * Emit a full Class or Interface method member.
+     * 
+     * @param node The {@link IFunctionNode} class method member.
+     */
+    void emitMethod(IFunctionNode node);
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java?rev=1423226&r1=1423225&r2=1423226&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/as/codegen/ASEmitter.java
Mon Dec 17 23:47:25 2012
@@ -21,13 +21,22 @@ package org.apache.flex.compiler.interna
 
 import java.io.FilterWriter;
 import java.io.IOException;
+import java.util.ArrayList;
 
 import org.apache.flex.as.IASEmitter;
 import org.apache.flex.compiler.common.ASModifier;
 import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.definitions.IVariableDefinition;
 import org.apache.flex.compiler.definitions.references.INamespaceReference;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+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.IParameterNode;
+import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.visitor.IASBlockWalker;
 
@@ -124,15 +133,64 @@ public class ASEmitter implements IASEmi
     //--------------------------------------------------------------------------
     // 
     //--------------------------------------------------------------------------
-    
+
+    @Override
+    public void emitFieldDocumentation(IVariableNode node)
+    {
+    }
+
     @Override
     public void emitField(IVariableNode node)
     {
-        emitDocumentation(node);
-        
+        emitFieldDocumentation(node);
+
         IVariableDefinition definition = (IVariableDefinition) node
                 .getDefinition();
-        
+
+        emitNamespace(definition);
+        emitModifiers(definition);
+        emitMemberKeyword(node);
+        emitMemberName(node);
+        emitType(node.getVariableTypeNode());
+        emitAssignedValue(node.getAssignedValueNode());
+        // the client such as IASBlockWalker is responsible for the 
+        // semi-colon and newline handling
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitMethodDocumentation(IFunctionNode node)
+    {
+    }
+
+    @Override
+    public void emitMethod(IFunctionNode node)
+    {
+        emitMethodDocumentation(node);
+
+        FunctionNode fn = (FunctionNode) node;
+        // XXX (mschmalle) parseFunctionBody() TEMP until I figure out the correct way to
do this
+        // will need to pass these problems back to the visitor
+        fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
+
+        IFunctionDefinition definition = node.getDefinition();
+
+        emitNamespace(definition);
+        emitModifiers(definition);
+        emitMemberKeyword(node);
+        emitMemberName(node);
+        emitParamters(node.getParameterNodes());
+        emitType(node.getReturnTypeNode());
+        emitMethodScope(node.getScopedNode());
+        // the client such as IASBlockWalker is responsible for the 
+        // semi-colon and newline handling
+    }
+
+    protected void emitNamespace(IDefinition definition)
+    {
         // namespace (public, protected, private, foo_bar)
         // TODO (mschmalle) figure out what to do if there is an explicit internal
         // right now if it's internal, code not produced (implied)
@@ -142,8 +200,10 @@ public class ASEmitter implements IASEmi
             write(reference.getBaseName());
             write(" ");
         }
-        
-        // madofiers (static)
+    }
+
+    protected void emitModifiers(IDefinition definition)
+    {
         ModifiersSet modifierSet = definition.getModifiers();
         if (modifierSet.hasModifiers())
         {
@@ -153,36 +213,66 @@ public class ASEmitter implements IASEmi
                 write(" ");
             }
         }
-        
-        // keyword
-        write(node.isConst() ? "const" : "var");
-        write(" ");
-        // name
+    }
+
+    protected void emitMemberKeyword(IDefinitionNode node)
+    {
+        if (node instanceof IVariableNode)
+        {
+            write(((IVariableNode) node).isConst() ? "const" : "var");
+            write(" ");
+        }
+        else if (node instanceof IFunctionNode)
+        {
+            write("function");
+            write(" ");
+        }
+    }
+
+    protected void emitMemberName(IDefinitionNode node)
+    {
         getVisitor().walk(node.getNameExpressionNode());
-        
-        // type
-        IExpressionNode tnode = node.getVariableTypeNode();
+    }
+
+    protected void emitParamters(IParameterNode[] nodes)
+    {
+        write("(");
+        int len = nodes.length;
+        for (int i = 0; i < len; i++)
+        {
+            IParameterNode node = nodes[i];
+            getVisitor().walk(node);
+            if (i < len - 1)
+                write(", ");
+        }
+        write(")");
+    }
+
+    protected void emitType(IExpressionNode node)
+    {
         // TODO (mschmalle) node.getVariableTypeNode() will return "*" if undefined, what
to use?
-        if (tnode != null)
+        // or node.getReturnTypeNode()
+        if (node != null)
         {
             write(":");
-            getVisitor().walk(tnode);
+            getVisitor().walk(node);
         }
-        
-        // assigned value
-        IExpressionNode vnode = node.getAssignedValueNode();
-        if (vnode != null)
+    }
+
+    protected void emitAssignedValue(IExpressionNode node)
+    {
+        if (node != null)
         {
             write(" ");
             write("=");
             write(" ");
-            getVisitor().walk(vnode);
+            getVisitor().walk(node);
         }
-        // the client such as IASBlockWalker is responsible for the 
-        // semi-colon and newline handling
     }
 
-    public void emitDocumentation(IVariableNode node)
+    protected void emitMethodScope(IScopedNode node)
     {
+        write(" ");
+        getVisitor().walk(node);
     }
 }

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java?rev=1423226&r1=1423225&r2=1423226&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/ASBlockWalker.java
Mon Dec 17 23:47:25 2012
@@ -321,9 +321,6 @@ public class ASBlockWalker implements IA
 
         if (SemanticUtils.isMemberDefinition(node.getDefinition()))
         {
-            //if (node.hasNamespace("private"))
-            //    return;
-
             emitter.emitField(node);
         }
         else
@@ -337,6 +334,13 @@ public class ASBlockWalker implements IA
     {
         // XXX (mschmalle) visitFunction() refactor, this is a mess
         debug("visitFunction()");
+        
+        if (SemanticUtils.isMemberDefinition(node.getDefinition()))
+        {
+            emitter.emitMethod(node);
+            return; // TEMP
+        }
+        
         FunctionNode fn = (FunctionNode) node;
         fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
         if (!inContext(TraverseContext.FUNCTION))



Mime
View raw message