incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1423612 - 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 Tue, 18 Dec 2012 20:12:22 GMT
Author: mschmalle
Date: Tue Dec 18 20:12:21 2012
New Revision: 1423612

URL: http://svn.apache.org/viewvc?rev=1423612&view=rev
Log:
Flex:FalconJx:
- Cleaned up some garbage commented out
- Added anonymous FunctionObject in variable declaration and arguments

Modified:
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestExpressions.java
    incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestStatements.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/TestExpressions.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestExpressions.java?rev=1423612&r1=1423611&r2=1423612&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestExpressions.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestExpressions.java
Tue Dec 18 20:12:21 2012
@@ -25,11 +25,13 @@ import org.apache.flex.compiler.internal
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
 import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.tree.as.IIfNode;
 import org.apache.flex.compiler.tree.as.IIterationFlowNode;
 import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.IReturnNode;
 import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.junit.Ignore;
 import org.junit.Test;
 
@@ -465,6 +467,36 @@ public class TestExpressions extends Tes
     //----------------------------------
 
     @Test
+    public void testAnonymousFunction()
+    {
+        IVariableNode node = (IVariableNode) getNode("var a = function(){};",
+                IVariableNode.class);
+        visitor.visitVariable(node);
+        assertOut("var a:* = function() {\n}");
+    }
+
+    @Test
+    public void testAnonymousFunctionWithParamsReturn()
+    {
+        IVariableNode node = (IVariableNode) getNode(
+                "var a:Object = function(foo:int, bar:String = 'goo'):int{return -1;};",
+                IVariableNode.class);
+        visitor.visitVariable(node);
+        assertOut("var a:Object = function(foo:int, bar:String = 'goo'):int {\n\treturn -1;\n}");
+    }
+
+    @Test
+    public void testAnonymousFunctionAsArgument()
+    {
+        // TODO (mschmalle) using IIfNode in expressions test, any other way to do this without
statement?
+        IIfNode node = (IIfNode) getNode(
+                "if (a) {addListener('foo', function(event:Object):void{doit();});}",
+                IIfNode.class);
+        visitor.visitIf(node);
+        assertOut("if (a) {\n\taddListener('foo', function(event:Object):void {\n\t\tdoit();\n\t});\n}");
+    }
+
+    @Test
     public void testVisitDynamicAccessNode_1()
     {
         IDynamicAccessNode node = getDynamicAccessNode("a[b]");

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestStatements.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestStatements.java?rev=1423612&r1=1423611&r2=1423612&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestStatements.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/driver/TestStatements.java
Tue Dec 18 20:12:21 2012
@@ -445,7 +445,8 @@ public class TestStatements extends Test
                         + "if (b) { try { a; throw new Error('foo'); } catch (e:Error) {
"
                         + " switch(i){case 1: break; default: return;}"
                         + " } catch (f:Error) { c; eee.dd; } finally { "
-                        + "  d;  eee.dd; eee.dd; eee.dd; eee.dd;} }"
+                        + "  d;  var a:Object = function(foo:int, bar:String = 'goo'):int{return
-1;};"
+                        + "  eee.dd; eee.dd; eee.dd; eee.dd;} }"
                         + "foo: for each(var i:int in obj) break foo;",
                 IFileNode.class);
         visitor.visitFile(node);

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=1423612&r1=1423611&r2=1423612&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
Tue Dec 18 20:12:21 2012
@@ -21,6 +21,8 @@ package org.apache.flex.as;
 
 import java.io.Writer;
 
+import org.apache.flex.compiler.internal.tree.as.FunctionObjectNode;
+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.ISetterNode;
@@ -59,8 +61,6 @@ public interface IASEmitter
      */
     void indentPop();
 
-    void emitVarDeclaration(IVariableNode node);
-
     /**
      * Emit a documentation comment for a Class field or constant
      * {@link IVariableNode}.
@@ -118,4 +118,24 @@ public interface IASEmitter
      */
     void emitSetAccessor(ISetterNode node);
 
+    //--------------------------------------------------------------------------
+    // Expressions
+    //--------------------------------------------------------------------------
+
+    /**
+     * Emit a variable declaration found in expression statements within scoped
+     * blocks.
+     * 
+     * @param node The {@link IVariableNode} or chain of variable nodes.
+     */
+    void emitVarDeclaration(IVariableNode node);
+
+    // TODO (mschmalle) we need IFunctionObjectNode API for FunctionObjectNode
+    /**
+     * Emit an anonymous {@link FunctionObjectNode}.
+     * 
+     * @param node The anonymous {@link FunctionObjectNode}.
+     */
+    void emitFunctionObject(IExpressionNode 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=1423612&r1=1423611&r2=1423612&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
Tue Dec 18 20:12:21 2012
@@ -21,7 +21,6 @@ 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;
@@ -32,7 +31,7 @@ import org.apache.flex.compiler.definiti
 import org.apache.flex.compiler.definitions.references.INamespaceReference;
 import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
-import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.internal.tree.as.FunctionObjectNode;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
@@ -247,10 +246,11 @@ public class ASEmitter implements IASEmi
             emitMethodDocumentation(node);
         }
 
-        FunctionNode fn = (FunctionNode) 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>());
+        // Figure out where this is getting parsed!
+//        fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
 
         IFunctionDefinition definition = node.getDefinition();
 
@@ -299,6 +299,21 @@ public class ASEmitter implements IASEmi
         emitMethod(node);
     }
 
+    @Override
+    public void emitFunctionObject(IExpressionNode node)
+    {
+        FunctionObjectNode f = (FunctionObjectNode) node;
+        FunctionNode fnode = f.getFunctionNode();
+        write("function");
+        emitParamters(fnode.getParameterNodes());
+        emitType(fnode.getTypeNode());
+        emitFunctionScope(fnode.getScopedNode());
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
     protected void emitNamespace(IDefinition definition)
     {
         // namespace (public, protected, private, foo_bar)
@@ -396,4 +411,10 @@ public class ASEmitter implements IASEmi
         getWalker().walk(node);
         write(" ");
     }
+
+    protected void emitFunctionScope(IScopedNode node)
+    {
+        // TODO (mschmalle) FunctionObjectNode; does this need specific treatment?
+        emitMethodScope(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=1423612&r1=1423611&r2=1423612&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
Tue Dec 18 20:12:21 2012
@@ -20,29 +20,26 @@
 package org.apache.flex.compiler.internal.js.codgen;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import java.util.Stack;
 
 import org.apache.flex.as.IASEmitter;
 import org.apache.flex.compiler.definitions.IClassDefinition;
-import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IInterfaceDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
-import org.apache.flex.compiler.definitions.IVariableDefinition;
 import org.apache.flex.compiler.internal.semantics.SemanticUtils;
 import org.apache.flex.compiler.internal.tree.as.BaseLiteralContainerNode;
 import org.apache.flex.compiler.internal.tree.as.ContainerNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
-import org.apache.flex.compiler.internal.tree.as.FunctionNode;
+import org.apache.flex.compiler.internal.tree.as.FunctionObjectNode;
 import org.apache.flex.compiler.internal.tree.as.LabeledStatementNode;
 import org.apache.flex.compiler.internal.tree.as.NamespaceAccessExpressionNode;
 import org.apache.flex.compiler.internal.tree.as.VariableExpressionNode;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.projects.IASProject;
-import org.apache.flex.compiler.scopes.IASScope;
 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.IBinaryOperatorNode;
 import org.apache.flex.compiler.tree.as.IBlockNode;
 import org.apache.flex.compiler.tree.as.ICatchNode;
@@ -69,7 +66,6 @@ import org.apache.flex.compiler.tree.as.
 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;
-import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.INamespaceNode;
 import org.apache.flex.compiler.tree.as.INumericLiteralNode;
@@ -113,6 +109,8 @@ public class ASBlockWalker implements IA
      * The context can only contain what is beneath them, CLASS contains
      * FUNCTION.
      */
+    // TODO (mschmalle) definitely having second thoughts about TraverseContext
+    // now that I'm understanding the AST a bit more, this is just garbage overhead
     public enum TraverseContext
     {
         ROOT,
@@ -191,8 +189,6 @@ public class ASBlockWalker implements IA
     // currentType
     //----------------------------------
 
-    private String classQualifiedName;
-
     private ITypeDefinition typeDefinition;
 
     public ITypeDefinition getCurrentType()
@@ -272,7 +268,6 @@ public class ASBlockWalker implements IA
     public void visitClass(IClassNode node)
     {
         typeDefinition = node.getDefinition();
-        classQualifiedName = typeDefinition.getQualifiedName();
 
         debug("visitClass()");
         pushContext(TraverseContext.TYPE);
@@ -319,8 +314,7 @@ public class ASBlockWalker implements IA
     public void visitVariable(IVariableNode node)
     {
         debug("visitVariable()");
-        // inContext(TraverseContext.FIELD)
-
+        
         if (SemanticUtils.isMemberDefinition(node.getDefinition()))
         {
             emitter.emitField(node);
@@ -342,120 +336,6 @@ public class ASBlockWalker implements IA
             emitter.emitMethod(node);
             return; // TEMP
         }
-
-        FunctionNode fn = (FunctionNode) node;
-        fn.parseFunctionBody(new ArrayList<ICompilerProblem>());
-        if (!inContext(TraverseContext.FUNCTION))
-        {
-            //            emitter.emitJSDoc(node, project, node == currentConstructor,
-            //                    typeDefinition);
-            String key = "";
-            if (node instanceof IGetterNode)
-                key = "get_";
-            else if (node instanceof ISetterNode)
-                key = "set_";
-
-            String name = "." + key + node.getName();
-            if (inContext(TraverseContext.CONSTRUCTOR))
-                name = "";
-            // isConstructor
-            emitter.write(classQualifiedName + name + " = function");
-        }
-        else if (inContext(TraverseContext.FUNCTION))
-        {
-            emitter.write("function");
-        }
-
-        walkParamters(node.getParameterNodes());
-
-        IScopedNode scope = node.getScopedNode();
-
-        emitter.write("{");
-        if (scope.getChildCount() > 0)
-            emitter.indentPush();
-        emitter.write("\n");
-        for (int i = 0; i < scope.getChildCount(); i++)
-        {
-            IASNode child = scope.getChild(i);
-            if (i == 0)
-            {
-                IASNode sub = child.getChild(0);
-                // test to see if we are super which is ILanguageIdentifierNode
-                if (child.getNodeID() == ASTNodeID.FunctionCallID
-                        && sub.getNodeID() == ASTNodeID.SuperID)
-                {
-                    // [0] SuperID
-                    // [1] ContainerID
-                    // will emit 'goog.base'
-                    walk(child);
-                    emitter.write("\n");
-
-                    // emit private fields
-                    IClassDefinition parent = (IClassDefinition) node
-                            .getDefinition().getParent();
-                    IASScope ascope = parent.getContainedScope();
-                    Collection<IDefinition> sets = ascope
-                            .getAllLocalDefinitions();
-                    for (IDefinition ldef : sets)
-                    {
-                        if (!(ldef instanceof IVariableDefinition))
-                            continue;
-
-                        IVariableDefinition vdef = (IVariableDefinition) ldef;
-                        if (vdef.isPrivate())
-                        {
-                            emitter.write("this." + ldef.getBaseName());
-                            //Object value = vdef.resolveInitialValue(project);
-                            IVariableNode mnode = (IVariableNode) vdef
-                                    .getNode();
-                            IExpressionNode vnode = mnode
-                                    .getAssignedValueNode();
-                            if (vnode != null)
-                            {
-                                emitter.write(" = ");
-                                walk(vnode);
-                                emitter.write(";");
-
-                            }
-                            if (i != scope.getChildCount() - 1)
-                                emitter.write("\n");
-                            else
-                            {
-                                emitter.indentPop();
-                                emitter.write("\n");
-                            }
-                        }
-                    }
-                }
-                else
-                {
-                    walk(child);
-                    if (i != scope.getChildCount() - 1)
-                        emitter.write("\n");
-                    else
-                    {
-                        emitter.indentPop();
-                        emitter.write("\n");
-                    }
-                }
-            }
-            else
-            {
-                walk(child);
-                // XXX (mschmalle) this should check for 1 child and not add the \n
-                // because it's taken care of at the end
-                if (i != scope.getChildCount() - 1)
-                    emitter.write("\n");
-                else
-                {
-                    emitter.indentPop();
-                    emitter.write("\n");
-                }
-            }
-        }
-
-        emitter.write("}");
-        emitter.write(";");
     }
 
     @Override
@@ -473,20 +353,6 @@ public class ASBlockWalker implements IA
         }
     }
 
-    private void walkParamters(IParameterNode[] nodes)
-    {
-        emitter.write("(");
-        int len = nodes.length;
-        for (int i = 0; i < len; i++)
-        {
-            IParameterNode node = nodes[i];
-            walk(node);
-            if (i < len - 1)
-                emitter.write(", ");
-        }
-        emitter.write(")\n"); // XXX (mschmalle) what is this doing? param NL
-    }
-
     @Override
     public void visitGetter(IGetterNode node)
     {
@@ -610,7 +476,7 @@ public class ASBlockWalker implements IA
                 IContainerNode snode = (IContainerNode) enode
                         .getStatementContentsNode();
 
-                boolean isImplicit = snode.getContainerType() == ContainerType.IMPLICIT;
+                final boolean isImplicit = isImplicit(snode);
                 if (isImplicit)
                     emitter.write("\n");
                 else
@@ -633,7 +499,7 @@ public class ASBlockWalker implements IA
         {
             IContainerNode cnode = (IContainerNode) elseNode.getChild(0);
             // if an implicit if, add a newline with no space
-            boolean isImplicit = cnode.getContainerType() == ContainerType.IMPLICIT;
+            final boolean isImplicit = isImplicit(cnode);
             if (isImplicit)
                 emitter.write("\n");
             else
@@ -659,12 +525,6 @@ public class ASBlockWalker implements IA
     protected void visitForEach(IForLoopNode node)
     {
         debug("visitForEach()");
-        /*
-         * IForLoopNode
-         * [0] IContainerNode
-         *     - IBinaryOperatorInNode[] getConditionalsContainerNode() 
-         * [1] IBlockNode
-         */
         IContainerNode xnode = (IContainerNode) node.getChild(1);
         pushContext(TraverseContext.FOR);
         emitter.write("for");
@@ -687,12 +547,6 @@ public class ASBlockWalker implements IA
     protected void visitFor(IForLoopNode node)
     {
         debug("visitFor()");
-        /*
-         * IForLoopNode
-         * [0] IContainerNode
-         *     - IExpressionNode[] getConditionalsContainerNode() 
-         * [1] IBlockNode
-         */
         IContainerNode xnode = (IContainerNode) node.getChild(1);
         pushContext(TraverseContext.FOR);
         emitter.write("for");
@@ -715,7 +569,6 @@ public class ASBlockWalker implements IA
             emitter.write(" ");
         popContext(TraverseContext.FOR);
         walk(node.getStatementContentsNode());
-        //emitter.writeNewline();
     }
 
     protected void visitForInBody(IContainerNode node)
@@ -763,7 +616,6 @@ public class ASBlockWalker implements IA
             emitter.write(" ");
             walk(lnode);
         }
-        //emitter.write(";");
     }
 
     @Override
@@ -813,38 +665,6 @@ public class ASBlockWalker implements IA
             emitter.write("\n");
         }
         emitter.write("}");
-        //emitter.writeNewline();
-    }
-
-    public IConditionalNode[] getCaseNodes(ISwitchNode node)
-    {
-        IBlockNode block = (IBlockNode) node.getChild(1);
-        int childCount = block.getChildCount();
-        ArrayList<IConditionalNode> retVal = new ArrayList<IConditionalNode>(
-                childCount);
-
-        for (int i = 0; i < childCount; i++)
-        {
-            IASNode child = block.getChild(i);
-            if (child instanceof IConditionalNode)
-                retVal.add((IConditionalNode) child);
-        }
-
-        return retVal.toArray(new IConditionalNode[0]);
-    }
-
-    public ITerminalNode getDefaultNode(ISwitchNode node)
-    {
-        IBlockNode block = (IBlockNode) node.getChild(1);
-        int childCount = block.getChildCount();
-        for (int i = childCount - 1; i >= 0; i--)
-        {
-            IASNode child = block.getChild(i);
-            if (child instanceof ITerminalNode)
-                return (ITerminalNode) child;
-        }
-
-        return null;
     }
 
     @Override
@@ -880,7 +700,6 @@ public class ASBlockWalker implements IA
             walk(node.getConditionalExpressionNode());
             emitter.write(");");
         }
-        //emitter.writeNewline();
     }
 
     @Override
@@ -917,15 +736,12 @@ public class ASBlockWalker implements IA
             walk(node.getCatchNode(i));
         }
         ITerminalNode fnode = node.getFinallyNode();
-        //if (fnode == null)
-        //     emitter.write("\n");
         if (fnode != null)
         {
             emitter.write(" ");
             emitter.write("finally");
             emitter.write(" ");
             walk(fnode);
-            //emitter.write("\n");
         }
     }
 
@@ -1119,11 +935,17 @@ public class ASBlockWalker implements IA
     public void visitExpression(IExpressionNode node)
     {
         debug("visitExpression()");
+        // TODO (mschmalle) I think these placements are temp, I am sure a visit method
+        // should exist for FunctionObjectNode, there is no interface for it right now
         if (node instanceof VariableExpressionNode)
         {
             VariableExpressionNode v = (VariableExpressionNode) node;
             walk(v.getTargetVariable());
         }
+        else if (node instanceof FunctionObjectNode)
+        {
+            emitter.emitFunctionObject(node);
+        }
     }
 
     @Override
@@ -1229,7 +1051,6 @@ public class ASBlockWalker implements IA
 
     protected void emitFields(IDefinitionNode[] members)
     {
-        //getWalker().pushContext(TraverseContext.FIELD);
         for (IDefinitionNode node : members)
         {
             if (node instanceof IVariableNode
@@ -1238,12 +1059,10 @@ public class ASBlockWalker implements IA
                 walk(node);
             }
         }
-        //getWalker().popContext(TraverseContext.FIELD);
     }
 
     protected void emitMethods(IDefinitionNode[] members)
     {
-        //getWalker().pushContext(TraverseContext.METHOD);
         for (IDefinitionNode node : members)
         {
             if (node instanceof IFunctionNode)
@@ -1252,10 +1071,9 @@ public class ASBlockWalker implements IA
                     walk(node);
             }
         }
-        //getWalker().popContext(TraverseContext.METHOD);
     }
 
-    private IFunctionNode getConstructor(IDefinitionNode[] members)
+    protected IFunctionNode getConstructor(IDefinitionNode[] members)
     {
         for (IDefinitionNode node : members)
         {
@@ -1269,7 +1087,7 @@ public class ASBlockWalker implements IA
         return null;
     }
 
-    private void debug(String message)
+    protected void debug(String message)
     {
         System.out.println(message);
     }
@@ -1327,4 +1145,36 @@ public class ASBlockWalker implements IA
                 || node.getContainerType() == ContainerType.SYNTHESIZED;
     }
 
+    // there seems to be a bug in the ISwitchNode.getCaseNodes(), need to file a bug
+    public IConditionalNode[] getCaseNodes(ISwitchNode node)
+    {
+        IBlockNode block = (IBlockNode) node.getChild(1);
+        int childCount = block.getChildCount();
+        ArrayList<IConditionalNode> retVal = new ArrayList<IConditionalNode>(
+                childCount);
+
+        for (int i = 0; i < childCount; i++)
+        {
+            IASNode child = block.getChild(i);
+            if (child instanceof IConditionalNode)
+                retVal.add((IConditionalNode) child);
+        }
+
+        return retVal.toArray(new IConditionalNode[0]);
+    }
+
+    // there seems to be a bug in the ISwitchNode.getDefaultNode(), need to file a bug
+    public ITerminalNode getDefaultNode(ISwitchNode node)
+    {
+        IBlockNode block = (IBlockNode) node.getChild(1);
+        int childCount = block.getChildCount();
+        for (int i = childCount - 1; i >= 0; i--)
+        {
+            IASNode child = block.getChild(i);
+            if (child instanceof ITerminalNode)
+                return (ITerminalNode) child;
+        }
+
+        return null;
+    }
 }



Mime
View raw message