flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1452955 [5/9] - in /flex/falcon/trunk: compiler.jx.tests/src/org/apache/flex/compiler/internal/as/ compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/ compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/ compile...
Date Tue, 05 Mar 2013 19:22:09 GMT
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/IBackend.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/IBackend.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/IBackend.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/IBackend.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,116 @@
+/*
+ *
+ *  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.compiler.driver;
+
+import java.io.File;
+import java.io.FilterWriter;
+import java.util.List;
+
+import org.apache.flex.compiler.clients.MXMLJSC;
+import org.apache.flex.compiler.codegen.IDocEmitter;
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.as.IASWriter;
+import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter;
+import org.apache.flex.compiler.config.Configurator;
+import org.apache.flex.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
+import org.apache.flex.compiler.internal.targets.JSTarget;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.projects.IASProject;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.targets.ITarget;
+import org.apache.flex.compiler.targets.ITargetProgressMonitor;
+import org.apache.flex.compiler.targets.ITargetSettings;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.visitor.IBlockWalker;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+import org.apache.flex.compiler.visitor.mxml.IMXMLBlockWalker;
+
+/**
+ * The backend strategy for the {@link MXMLJSC} javascript compiler.
+ * 
+ * @author Michael Schmalle
+ */
+public interface IBackend
+{
+
+    /**
+     * Returns the instance that is used to manage what type of
+     * {@link ICompilationUnit} is created during parsing.
+     * 
+     * @return The implemented {@link ISourceFileHandler}.
+     */
+    ISourceFileHandler getSourceFileHandlerInstance();
+
+    /**
+     * Returns the {@link File} extension used when saving compiled code.
+     */
+    String getOutputExtension();
+
+    /**
+     * Creates a {@link Configurator} for the specific compile session.
+     */
+    Configurator createConfigurator();
+
+    /**
+     * Creates a javascript target that will be used to build the compiled
+     * javascript source file.
+     * 
+     * @param project The current {@link ICompilerProject}.
+     * @param settings The target's custom settings.
+     * @param monitor The compilation monitor used during asynchronous parsing
+     * of {@link ICompilationUnit}s.
+     * @return A new {@link JSTarget} used during compilation.
+     */
+    ITarget createTarget(IASProject project, ITargetSettings settings,
+            ITargetProgressMonitor monitor);
+
+    IDocEmitter createDocEmitter(IASEmitter emitter);
+
+    IASEmitter createEmitter(FilterWriter writer);
+
+    IMXMLEmitter createMXMLEmitter(FilterWriter writer);
+
+    ASFilterWriter createWriterBuffer(IASProject project);
+
+    IASWriter createWriter(IASProject project, List<ICompilerProblem> errors,
+            ICompilationUnit compilationUnit, boolean enableDebug);
+
+    IASBlockWalker createWalker(IASProject project,
+            List<ICompilerProblem> errors, IASEmitter emitter);
+
+    /**
+     * Creates an AST walker capable of traversing MXML AST and calling back to
+     * the {@link IASBlockWalker} for ActionScript source code production.
+     * <p>
+     * Use the {@link #createWalker(IASProject, List, ASFilterWriter)} method
+     * first and pass that instance into this method's <code>walker</code>
+     * parameter.
+     * 
+     * @param project The current {@link IASProject}.
+     * @param errors The current {@link ICompilerProblem} list.
+     * @param emitter The current {@link IASEmitter} that is used for it's
+     * emitter and is available for callbacks to it's visit methods.
+     */
+    IMXMLBlockWalker createMXMLWalker(IASProject project,
+            List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter,
+            IASEmitter asEmitter, IBlockWalker asBlockWalker);
+
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/IBackend.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/js/IJSApplication.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/js/IJSApplication.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/js/IJSApplication.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/js/IJSApplication.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,33 @@
+/*
+ *
+ *  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.compiler.driver.js;
+
+import org.apache.flex.compiler.driver.IApplication;
+
+/**
+ * The JavaScript model interface used when implementing build targets that
+ * create javascript applications cross compiled from actionscript.
+ * 
+ * @author Michael Schmalle
+ */
+public interface IJSApplication extends IApplication
+{
+
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/driver/js/IJSApplication.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,234 @@
+/*
+ *
+ *  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.compiler.internal.codegen;
+
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.flex.compiler.codegen.IEmitter;
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.problems.ICompilerProblem;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+
+/**
+ * The base implementation for an ActionScript emitter.
+ * 
+ * @author Michael Schmalle
+ */
+public class Emitter implements IEmitter
+{
+    private final FilterWriter out;
+
+    private boolean bufferWrite;
+
+    protected boolean isBufferWrite()
+    {
+        return bufferWrite;
+    }
+
+    protected void setBufferWrite(boolean value)
+    {
+        bufferWrite = value;
+    }
+
+    private StringBuilder builder;
+
+    protected StringBuilder getBuilder()
+    {
+        return builder;
+    }
+
+    protected void flushBuilder()
+    {
+        setBufferWrite(false);
+        write(builder.toString());
+        builder.setLength(0);
+    }
+
+    protected List<ICompilerProblem> problems;
+
+    // (mschmalle) think about how this should be implemented, we can add our
+    // own problems to this, they don't just have to be parse problems
+    public List<ICompilerProblem> getProblems()
+    {
+        return problems;
+    }
+
+    //    private IDocEmitter docEmitter;
+    //
+    //    @Override
+    //    public IDocEmitter getDocEmitter()
+    //    {
+    //        return docEmitter;
+    //    }
+    //
+    //    @Override
+    //    public void setDocEmitter(IDocEmitter value)
+    //    {
+    //        docEmitter = value;
+    //    }
+
+    private int currentIndent = 0;
+
+    protected int getCurrentIndent()
+    {
+        return currentIndent;
+    }
+
+    private IASBlockWalker walker;
+
+    public IASBlockWalker getWalker()
+    {
+        return walker;
+    }
+
+    public void setWalker(IASBlockWalker value)
+    {
+        walker = value;
+    }
+
+    public Emitter(FilterWriter out)
+    {
+        this.out = out;
+        builder = new StringBuilder();
+        problems = new ArrayList<ICompilerProblem>();
+    }
+
+    @Override
+    public void write(IEmitterTokens value)
+    {
+        write(value.getToken());
+    }
+
+    @Override
+    public void write(String value)
+    {
+        try
+        {
+            if (!bufferWrite)
+                out.write(value);
+            else
+                builder.append(value);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected String getIndent(int numIndent)
+    {
+        final StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < numIndent; i++)
+            sb.append(ASEmitterTokens.INDENT.getToken());
+        return sb.toString();
+    }
+
+    @Override
+    public void indentPush()
+    {
+        currentIndent++;
+    }
+
+    @Override
+    public void indentPop()
+    {
+        currentIndent--;
+    }
+
+    @Override
+    public void writeNewline()
+    {
+        write(ASEmitterTokens.NEW_LINE);
+        write(getIndent(currentIndent));
+    }
+
+    @Override
+    public void writeNewline(IEmitterTokens value)
+    {
+        writeNewline(value.getToken());
+    }
+
+    @Override
+    public void writeNewline(String value)
+    {
+        write(value);
+        writeNewline();
+    }
+
+    @Override
+    public void writeNewline(IEmitterTokens value, boolean pushIndent)
+    {
+        writeNewline(value.getToken(), pushIndent);
+    }
+
+    @Override
+    public void writeNewline(String value, boolean pushIndent)
+    {
+        if (pushIndent)
+            indentPush();
+        else
+            indentPop();
+        write(value);
+        writeNewline();
+    }
+
+    public void writeSymbol(String value)
+    {
+        write(value);
+    }
+
+    @Override
+    public void writeToken(IEmitterTokens value)
+    {
+        writeToken(value.getToken());
+    }
+
+    @Override
+    public void writeToken(String value)
+    {
+        write(value);
+        write(ASEmitterTokens.SPACE);
+    }
+
+    /**
+     * Takes the node argument and created a String representation if it using
+     * the buffer temporarily.
+     * <p>
+     * Note; This method is still beta, it need more logic if an emitter is
+     * actually using the buffer!
+     * 
+     * @param node The node walk and create a String for.
+     * @return The node's output.
+     */
+    protected String stringifyNode(IASNode node)
+    {
+        setBufferWrite(true);
+        getWalker().walk(node);
+        String result = getBuilder().toString();
+        getBuilder().setLength(0);
+        setBufferWrite(false);
+        return result;
+    }
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,77 @@
+/*
+ *
+ *  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.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.codegen.IEmitter;
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+
+/**
+ * A concrete implementation of the {@link IASNodeStrategy} that allows
+ * {@link IASNode} processing after the current node handler.
+ * <p>
+ * The class has access to the current {@link IJSEmitter} instance being used to
+ * output source code to the current output buffer.
+ * 
+ * @author Michael Schmalle
+ */
+public class ASAfterNodeStrategy implements IASNodeStrategy
+{
+    private final IASEmitter emitter;
+
+    public ASAfterNodeStrategy(IASEmitter emitter)
+    {
+        this.emitter = emitter;
+    }
+
+    @Override
+    public void handle(IASNode node)
+    {
+        if (node.getNodeID() == ASTNodeID.BlockID)
+        {
+            IContainerNode container = (IContainerNode) node;
+            ContainerType type = container.getContainerType();
+            if (type != ContainerType.IMPLICIT
+                    && type != ContainerType.SYNTHESIZED)
+            {
+                if (node.getChildCount() != 0)
+                {
+                    emitter.indentPop();
+                    ((IEmitter) emitter).writeNewline();
+                }
+
+                ((IEmitter) emitter).write(ASEmitterTokens.BLOCK_CLOSE);
+            }
+            else if (type == ContainerType.IMPLICIT
+                    || type == ContainerType.SYNTHESIZED)
+            {
+                if (node.getChildCount() != 0)
+                {
+                    emitter.indentPop();
+                }
+            }
+        }
+    }
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASAfterNodeStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,74 @@
+/*
+ *
+ *  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.compiler.internal.codegen.as;
+
+import org.apache.flex.compiler.codegen.IEmitter;
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+
+/**
+ * A concrete implementation of the {@link IASNodeStrategy} that allows
+ * {@link IASNode} processing before the current node handler.
+ * 
+ * @author Michael Schmalle
+ */
+public class ASBeforeNodeStrategy implements IASNodeStrategy
+{
+    private final IASEmitter emitter;
+
+    public ASBeforeNodeStrategy(IASEmitter emitter)
+    {
+        this.emitter = emitter;
+    }
+
+    @Override
+    public void handle(IASNode node)
+    {
+        if (node.getNodeID() == ASTNodeID.BlockID)
+        {
+            IASNode parent = node.getParent();
+            IContainerNode container = (IContainerNode) node;
+            ContainerType type = container.getContainerType();
+
+            if (parent.getNodeID() != ASTNodeID.LabledStatementID)
+            {
+                if (node.getChildCount() != 0)
+                    emitter.indentPush();
+            }
+
+            // switch cases are SYNTHESIZED
+            if (type != ContainerType.IMPLICIT
+                    && type != ContainerType.SYNTHESIZED)
+            {
+                ((IEmitter) emitter).write(ASEmitterTokens.BLOCK_OPEN);
+            }
+
+            if (parent.getNodeID() != ASTNodeID.LabledStatementID)
+            {
+                ((IEmitter) emitter).writeNewline();
+            }
+        }
+    }
+
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBeforeNodeStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,597 @@
+/*
+ *
+ *  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.compiler.internal.codegen.as;
+
+import java.util.List;
+
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.definitions.IPackageDefinition;
+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.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.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IBlockNode;
+import org.apache.flex.compiler.tree.as.ICatchNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IDefaultXMLNamespaceNode;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IEmbedNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFileNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode.ForLoopKind;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+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.IIfNode;
+import org.apache.flex.compiler.tree.as.IImportNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.apache.flex.compiler.tree.as.IIterationFlowNode;
+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;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.INamespaceNode;
+import org.apache.flex.compiler.tree.as.INumericLiteralNode;
+import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode;
+import org.apache.flex.compiler.tree.as.IPackageNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
+import org.apache.flex.compiler.tree.as.IReturnNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
+import org.apache.flex.compiler.tree.as.ISwitchNode;
+import org.apache.flex.compiler.tree.as.ITerminalNode;
+import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IThrowNode;
+import org.apache.flex.compiler.tree.as.ITryNode;
+import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.compiler.tree.as.IWhileLoopNode;
+import org.apache.flex.compiler.tree.as.IWhileLoopNode.WhileLoopKind;
+import org.apache.flex.compiler.tree.as.IWithNode;
+import org.apache.flex.compiler.tree.metadata.IMetaTagNode;
+import org.apache.flex.compiler.tree.metadata.IMetaTagsNode;
+import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.utils.DefinitionUtils;
+import org.apache.flex.compiler.visitor.IASNodeStrategy;
+import org.apache.flex.compiler.visitor.as.IASBlockVisitor;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+
+/**
+ * A base implementation of the {@link IASBlockVisitor} that will walk the
+ * {@link ICompilationUnit}s AST {@link IASNode} hierarchy.
+ * 
+ * @author Michael Schmalle
+ */
+public class ASBlockWalker implements IASBlockVisitor, IASBlockWalker
+{
+    boolean isDebug;
+
+    private IASEmitter emitter;
+
+    @Override
+    public IASEmitter getEmitter()
+    {
+        return emitter;
+    }
+
+    private final List<ICompilerProblem> errors;
+
+    List<ICompilerProblem> getErrors()
+    {
+        return errors;
+    }
+
+    //----------------------------------
+    // strategy
+    //----------------------------------
+
+    private IASNodeStrategy strategy;
+
+    public IASNodeStrategy getStrategy()
+    {
+        return strategy;
+    }
+
+    public void setStrategy(IASNodeStrategy value)
+    {
+        strategy = value;
+    }
+
+    //----------------------------------
+    // project
+    //----------------------------------
+
+    private IASProject project;
+
+    @Override
+    public IASProject getProject()
+    {
+        return project;
+    }
+
+    public ASBlockWalker(List<ICompilerProblem> errors, IASProject project,
+            IASEmitter emitter)
+    {
+        this.errors = errors;
+        this.project = project;
+        this.emitter = emitter;
+        emitter.setWalker(this);
+    }
+
+    //--------------------------------------------------------------------------
+    // File level
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void walk(IASNode node)
+    {
+        getStrategy().handle(node);
+    }
+
+    @Override
+    public void visitCompilationUnit(ICompilationUnit unit)
+    {
+        debug("visitCompilationUnit()");
+        IFileNode node = null;
+        try
+        {
+            node = (IFileNode) unit.getSyntaxTreeRequest().get().getAST();
+        }
+        catch (InterruptedException e)
+        {
+            throw new RuntimeException(e);
+        }
+
+        walk(node);
+    }
+
+    @Override
+    public void visitFile(IFileNode node)
+    {
+        debug("visitFile()");
+        IASNode pnode = node.getChild(0);
+        if (pnode != null)
+        {
+            walk(pnode); // IPackageNode
+        }
+        else
+        {
+
+        }
+    }
+
+    @Override
+    public void visitPackage(IPackageNode node)
+    {
+        debug("visitPackage()");
+        IPackageDefinition definition = (IPackageDefinition) node
+                .getDefinition();
+        emitter.emitPackageHeader(definition);
+        emitter.emitPackageHeaderContents(definition);
+        emitter.emitPackageContents(definition);
+        emitter.emitPackageFooter(definition);
+    }
+
+    //--------------------------------------------------------------------------
+    // Type level
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void visitClass(IClassNode node)
+    {
+        debug("visitClass()");
+        emitter.emitClass(node);
+    }
+
+    @Override
+    public void visitInterface(IInterfaceNode node)
+    {
+        debug("visitInterface()");
+        emitter.emitInterface(node);
+    }
+
+    @Override
+    public void visitVariable(IVariableNode node)
+    {
+        debug("visitVariable()");
+        if (SemanticUtils.isMemberDefinition(node.getDefinition()))
+        {
+            emitter.emitField(node);
+        }
+        else
+        {
+            emitter.emitVarDeclaration(node);
+        }
+    }
+
+    @Override
+    public void visitFunction(IFunctionNode node)
+    {
+        debug("visitFunction()");
+        if (DefinitionUtils.isMemberDefinition(node.getDefinition()))
+        {
+            emitter.emitMethod(node);
+        }
+    }
+
+    @Override
+    public void visitParameter(IParameterNode node)
+    {
+        debug("visitParameter()");
+        emitter.emitParameter(node);
+    }
+
+    @Override
+    public void visitGetter(IGetterNode node)
+    {
+        debug("visitGetter()");
+        emitter.emitGetAccessor(node);
+    }
+
+    @Override
+    public void visitSetter(ISetterNode node)
+    {
+        debug("visitSetter()");
+        emitter.emitSetAccessor(node);
+    }
+
+    @Override
+    public void visitNamespace(INamespaceNode node)
+    {
+        debug("visitNamespace()");
+        emitter.emitNamespace(node);
+    }
+
+    @Override
+    public void visitFunctionCall(IFunctionCallNode node)
+    {
+        debug("visitFunctionCall()");
+        emitter.emitFunctionCall(node);
+    }
+
+    @Override
+    public void visitBlock(IBlockNode node)
+    {
+        debug("visitBlock()");
+        ASTNodeID pnodeId = node.getParent().getNodeID();
+        // (erikdebruin) 'goog' also needs access to the block header for
+        //               accessor function blocks
+        if (pnodeId == ASTNodeID.FunctionID || pnodeId == ASTNodeID.GetterID
+                || pnodeId == ASTNodeID.SetterID)
+        {
+            emitter.emitFunctionBlockHeader((IFunctionNode) node.getParent());
+        }
+
+        final int len = node.getChildCount();
+        for (int i = 0; i < len; i++)
+        {
+            emitter.emitStatement(node.getChild(i));
+        }
+    }
+
+    @Override
+    public void visitIf(IIfNode node)
+    {
+        debug("visitIf()");
+        emitter.emitIf(node);
+    }
+
+    @Override
+    public void visitForLoop(IForLoopNode node)
+    {
+        debug("visitForLoop(" + node.getKind() + ")");
+        if (node.getKind() == ForLoopKind.FOR)
+            visitFor(node);
+        else if (node.getKind() == ForLoopKind.FOR_EACH)
+            visitForEach(node);
+    }
+
+    protected void visitForEach(IForLoopNode node)
+    {
+        debug("visitForEach()");
+        emitter.emitForEachLoop(node);
+    }
+
+    protected void visitFor(IForLoopNode node)
+    {
+        debug("visitFor()");
+        emitter.emitForLoop(node);
+    }
+
+    @Override
+    public void visitSwitch(ISwitchNode node)
+    {
+        debug("visitSwitch()");
+        emitter.emitSwitch(node);
+    }
+
+    @Override
+    public void visitWhileLoop(IWhileLoopNode node)
+    {
+        debug("visitWhileLoopNode()");
+        if (node.getKind() == WhileLoopKind.WHILE)
+        {
+            emitter.emitWhileLoop(node);
+        }
+        else if (node.getKind() == WhileLoopKind.DO)
+        {
+            emitter.emitDoLoop(node);
+        }
+    }
+
+    @Override
+    public void visitWith(IWithNode node)
+    {
+        debug("visitWith()");
+        emitter.emitWith(node);
+    }
+
+    @Override
+    public void visitThrow(IThrowNode node)
+    {
+        debug("visitThrow()");
+        emitter.emitThrow(node);
+    }
+
+    @Override
+    public void visitTry(ITryNode node)
+    {
+        debug("visitTry()");
+        emitter.emitTry(node);
+    }
+
+    @Override
+    public void visitCatch(ICatchNode node)
+    {
+        debug("visitCatch()");
+        emitter.emitCatch(node);
+    }
+
+    @Override
+    public void visitIterationFlow(IIterationFlowNode node)
+    {
+        debug("visitIterationFlow()");
+        emitter.emitIterationFlow(node);
+    }
+
+    @Override
+    public void visitIdentifier(IIdentifierNode node)
+    {
+        debug("visitIdentifier(" + node.getName() + ")");
+        emitter.emitIdentifier(node);
+    }
+
+    @Override
+    public void visitNumericLiteral(INumericLiteralNode node)
+    {
+        debug("visitNumericLiteral(" + node.getNumericValue() + ")");
+        emitter.emitNumericLiteral(node);
+    }
+
+    @Override
+    public void visitDefaultXMLNamespace(IDefaultXMLNamespaceNode node)
+    {
+        debug("visitDefaultXMLNamespace()");
+        walk(node.getKeywordNode()); // default xml namespace
+        walk(node.getExpressionNode()); // "http://ns.whatever.com"
+    }
+
+    @Override
+    public void visitKeyword(IKeywordNode node)
+    {
+        debug("visitKeyword(" + node.getNodeID().getParaphrase() + ")");
+        emitter.emitKeyword(node);
+    }
+
+    @Override
+    public void visitLiteral(ILiteralNode node)
+    {
+        debug("visitLiteral(" + node.getValue() + ")");
+        // TODO (mschmalle) visitLiteral()
+        if (node.getLiteralType() == LiteralType.NUMBER
+                || node.getLiteralType() == LiteralType.BOOLEAN
+                || node.getLiteralType() == LiteralType.NULL
+                || node.getLiteralType() == LiteralType.NUMBER
+                || node.getLiteralType() == LiteralType.REGEXP
+                || node.getLiteralType() == LiteralType.STRING
+                || node.getLiteralType() == LiteralType.VOID)
+        {
+            emitter.emitLiteral(node);
+        }
+        else if (node.getLiteralType() == LiteralType.ARRAY
+                || node.getLiteralType() == LiteralType.OBJECT)
+        {
+            BaseLiteralContainerNode anode = (BaseLiteralContainerNode) node;
+            IContainerNode cnode = anode.getContentsNode();
+            emitter.emitLiteralContainer(cnode);
+        }
+    }
+
+    @Override
+    public void visitMemberAccessExpression(IMemberAccessExpressionNode node)
+    {
+        debug("visitMemberAccessExpression()");
+        emitter.emitMemberAccessExpression(node);
+    }
+
+    @Override
+    public void visitNamespaceAccessExpression(
+            NamespaceAccessExpressionNode node)
+    {
+        debug("visitNamespaceAccessExpression()");
+        emitter.emitNamespaceAccessExpression(node);
+    }
+
+    @Override
+    public void visitDynamicAccess(IDynamicAccessNode node)
+    {
+        debug("visitDynamicAccess()");
+        emitter.emitDynamicAccess(node);
+    }
+
+    @Override
+    public void visitTypedExpression(ITypedExpressionNode node)
+    {
+        debug("visitITypedExpression()");
+        emitter.emitTypedExpression(node);
+    }
+
+    @Override
+    public void visitAsOperator(IBinaryOperatorNode node)
+    {
+        debug("visitAsOperator()");
+        emitter.emitAsOperator(node);
+    }
+
+    @Override
+    public void visitIsOperator(IBinaryOperatorNode node)
+    {
+        debug("visitIsOperator()");
+        emitter.emitIsOperator(node);
+    }
+
+    @Override
+    public void visitBinaryOperator(IBinaryOperatorNode node)
+    {
+        debug("visitBinaryOperator(" + node.getOperator().getOperatorText()
+                + ")");
+        emitter.emitBinaryOperator(node);
+    }
+
+    @Override
+    public void visitUnaryOperator(IUnaryOperatorNode node)
+    {
+        debug("visitUnaryOperator()");
+        emitter.emitUnaryOperator(node);
+    }
+
+    @Override
+    public void visitTerminal(ITerminalNode node)
+    {
+        debug("visitTerminal(" + node.getKind() + ")");
+        walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    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
+    public void visitImport(IImportNode node)
+    {
+        debug("visitImport()");
+        emitter.emitImport(node);
+    }
+
+    @Override
+    public void visitMetaTags(IMetaTagsNode node)
+    {
+        debug("visitMetaTags()");
+        IMetaTagNode[] tags = node.getAllTags();
+        for (IMetaTagNode tag : tags)
+        {
+            walk(tag);
+        }
+    }
+
+    @Override
+    public void visitMetaTag(IMetaTagNode node)
+    {
+        debug("visitMetaTag(" + node.getTagName() + ")");
+        emitter.emitMetaTag(node);
+    }
+
+    @Override
+    public void visitEmbed(IEmbedNode node)
+    {
+        debug("visitEmbed(" + node.getAttributes()[0].getValue() + ")");
+        // TODO (mschmalle) visitEmbed() 
+    }
+
+    @Override
+    public void visitReturn(IReturnNode node)
+    {
+        debug("visitReturn()");
+        emitter.emitReturn(node);
+    }
+
+    @Override
+    public void visitTernaryOperator(ITernaryOperatorNode node)
+    {
+        debug("visitTernaryOperator()");
+        emitter.emitTernaryOperator(node);
+    }
+
+    @Override
+    public void visitLabeledStatement(LabeledStatementNode node)
+    {
+        debug("visitLabeledStatement()");
+        emitter.emitLabelStatement(node);
+    }
+
+    @Override
+    public void visitObjectLiteralValuePair(IObjectLiteralValuePairNode node)
+    {
+        debug("visitIObjectLiteralValuePair()");
+        emitter.emitObjectLiteralValuePair(node);
+    }
+
+    @Override
+    public void visitLanguageIdentifierNode(ILanguageIdentifierNode node)
+    {
+        emitter.emitLanguageIdentifier(node);
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    protected void debug(String message)
+    {
+        if (isDebug)
+        {
+            System.out.println(message);
+        }
+    }
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASBlockWalker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java?rev=1452955&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java Tue Mar  5 19:22:05 2013
@@ -0,0 +1,1430 @@
+/*
+ *
+ *  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.compiler.internal.codegen.as;
+
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.flex.compiler.codegen.IDocEmitter;
+import org.apache.flex.compiler.codegen.IEmitter;
+import org.apache.flex.compiler.codegen.IEmitterTokens;
+import org.apache.flex.compiler.codegen.as.IASEmitter;
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.common.IImportTarget;
+import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.constants.IASKeywordConstants;
+import org.apache.flex.compiler.definitions.IDefinition;
+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.definitions.IVariableDefinition;
+import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
+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.problems.ICompilerProblem;
+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.ICatchNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IConditionalNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IContainerNode.ContainerType;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+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.IIfNode;
+import org.apache.flex.compiler.tree.as.IImportNode;
+import org.apache.flex.compiler.tree.as.IInterfaceNode;
+import org.apache.flex.compiler.tree.as.IIterationFlowNode;
+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.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.tree.as.INamespaceNode;
+import org.apache.flex.compiler.tree.as.INumericLiteralNode;
+import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode;
+import org.apache.flex.compiler.tree.as.IPackageNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
+import org.apache.flex.compiler.tree.as.IReturnNode;
+import org.apache.flex.compiler.tree.as.IScopedNode;
+import org.apache.flex.compiler.tree.as.ISetterNode;
+import org.apache.flex.compiler.tree.as.IStatementNode;
+import org.apache.flex.compiler.tree.as.ISwitchNode;
+import org.apache.flex.compiler.tree.as.ITerminalNode;
+import org.apache.flex.compiler.tree.as.ITernaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IThrowNode;
+import org.apache.flex.compiler.tree.as.ITryNode;
+import org.apache.flex.compiler.tree.as.ITypeNode;
+import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
+import org.apache.flex.compiler.tree.as.IUnaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+import org.apache.flex.compiler.tree.as.IWhileLoopNode;
+import org.apache.flex.compiler.tree.as.IWithNode;
+import org.apache.flex.compiler.tree.metadata.IMetaTagNode;
+import org.apache.flex.compiler.utils.ASNodeUtils;
+import org.apache.flex.compiler.visitor.IBlockWalker;
+import org.apache.flex.compiler.visitor.as.IASBlockWalker;
+
+/**
+ * The base implementation for an ActionScript emitter.
+ * 
+ * @author Michael Schmalle
+ */
+public class ASEmitter implements IASEmitter, IEmitter
+{
+    private final FilterWriter out;
+
+    private boolean bufferWrite;
+
+    protected boolean isBufferWrite()
+    {
+        return bufferWrite;
+    }
+
+    protected void setBufferWrite(boolean value)
+    {
+        bufferWrite = value;
+    }
+
+    private StringBuilder builder;
+
+    protected StringBuilder getBuilder()
+    {
+        return builder;
+    }
+
+    protected void flushBuilder()
+    {
+        setBufferWrite(false);
+        write(builder.toString());
+        builder.setLength(0);
+    }
+
+    protected List<ICompilerProblem> problems;
+
+    // (mschmalle) think about how this should be implemented, we can add our
+    // own problems to this, they don't just have to be parse problems
+    public List<ICompilerProblem> getProblems()
+    {
+        return problems;
+    }
+
+    private int currentIndent = 0;
+
+    protected int getCurrentIndent()
+    {
+        return currentIndent;
+    }
+
+    private IASBlockWalker walker;
+
+    @Override
+    public IBlockWalker getWalker()
+    {
+        return (IBlockWalker) walker;
+    }
+
+    @Override
+    public void setWalker(IBlockWalker value)
+    {
+        walker = (IASBlockWalker) value;
+    }
+
+    @Override
+    public IDocEmitter getDocEmitter()
+    {
+        return null;
+    }
+
+    @Override
+    public void setDocEmitter(IDocEmitter value)
+    {
+    }
+
+    public ASEmitter(FilterWriter out)
+    {
+        this.out = out;
+        builder = new StringBuilder();
+        problems = new ArrayList<ICompilerProblem>();
+    }
+
+    @Override
+    public void write(IEmitterTokens value)
+    {
+        write(value.getToken());
+    }
+
+    @Override
+    public void write(String value)
+    {
+        try
+        {
+            if (!bufferWrite)
+                out.write(value);
+            else
+                builder.append(value);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    protected String getIndent(int numIndent)
+    {
+        final StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < numIndent; i++)
+            sb.append(ASEmitterTokens.INDENT.getToken());
+        return sb.toString();
+    }
+
+    @Override
+    public void indentPush()
+    {
+        currentIndent++;
+    }
+
+    @Override
+    public void indentPop()
+    {
+        currentIndent--;
+    }
+
+    @Override
+    public void writeNewline()
+    {
+        write(ASEmitterTokens.NEW_LINE);
+        write(getIndent(currentIndent));
+    }
+
+    @Override
+    public void writeNewline(IEmitterTokens value)
+    {
+        writeNewline(value.getToken());
+    }
+
+    @Override
+    public void writeNewline(String value)
+    {
+        write(value);
+        writeNewline();
+    }
+
+    @Override
+    public void writeNewline(IEmitterTokens value, boolean pushIndent)
+    {
+        writeNewline(value.getToken(), pushIndent);
+    }
+
+    @Override
+    public void writeNewline(String value, boolean pushIndent)
+    {
+        if (pushIndent)
+            indentPush();
+        else
+            indentPop();
+        write(value);
+        writeNewline();
+    }
+
+    public void writeSymbol(String value)
+    {
+        write(value);
+    }
+
+    @Override
+    public void writeToken(IEmitterTokens value)
+    {
+        writeToken(value.getToken());
+    }
+
+    @Override
+    public void writeToken(String value)
+    {
+        write(value);
+        write(ASEmitterTokens.SPACE);
+    }
+
+    //--------------------------------------------------------------------------
+    // IPackageNode
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitImport(IImportNode node)
+    {
+        IImportTarget target = node.getImportTarget();
+        writeToken(ASEmitterTokens.IMPORT);
+        write(target.toString());
+    }
+
+    @Override
+    public void emitPackageHeader(IPackageDefinition definition)
+    {
+        write(ASEmitterTokens.PACKAGE);
+
+        IPackageNode node = definition.getNode();
+        String name = node.getQualifiedName();
+        if (name != null && !name.equals(""))
+        {
+            write(ASEmitterTokens.SPACE);
+            getWalker().walk(node.getNameExpressionNode());
+        }
+
+        write(ASEmitterTokens.SPACE);
+        write(ASEmitterTokens.BLOCK_OPEN);
+    }
+
+    @Override
+    public void emitPackageHeaderContents(IPackageDefinition definition)
+    {
+    }
+
+    @Override
+    public void emitPackageContents(IPackageDefinition definition)
+    {
+        IPackageNode node = definition.getNode();
+        ITypeNode tnode = findTypeNode(node);
+        if (tnode != null)
+        {
+            indentPush();
+            writeNewline();
+            getWalker().walk(tnode); // IClassNode | IInterfaceNode
+        }
+    }
+
+    @Override
+    public void emitPackageFooter(IPackageDefinition definition)
+    {
+        indentPop();
+        writeNewline();
+        write(ASEmitterTokens.BLOCK_CLOSE);
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitClass(IClassNode node)
+    {
+        writeToken(node.getNamespace());
+
+        if (node.hasModifier(ASModifier.FINAL))
+        {
+            writeToken(ASEmitterTokens.FINAL);
+        }
+        else if (node.hasModifier(ASModifier.DYNAMIC))
+        {
+            writeToken(ASEmitterTokens.DYNAMIC);
+        }
+
+        writeToken(ASEmitterTokens.CLASS);
+        getWalker().walk(node.getNameExpressionNode());
+        write(ASEmitterTokens.SPACE);
+
+        IExpressionNode bnode = node.getBaseClassExpressionNode();
+        if (bnode != null)
+        {
+            writeToken(ASEmitterTokens.EXTENDS);
+            getWalker().walk(bnode);
+            write(ASEmitterTokens.SPACE);
+        }
+
+        IExpressionNode[] inodes = node.getImplementedInterfaceNodes();
+        final int ilen = inodes.length;
+        if (ilen != 0)
+        {
+            writeToken(ASEmitterTokens.IMPLEMENTS);
+            for (int i = 0; i < ilen; i++)
+            {
+                getWalker().walk(inodes[i]);
+                if (i < ilen - 1)
+                {
+                    writeToken(ASEmitterTokens.COMMA);
+                }
+            }
+            write(ASEmitterTokens.SPACE);
+        }
+
+        write(ASEmitterTokens.BLOCK_OPEN);
+
+        // fields, methods, namespaces
+        final IDefinitionNode[] members = node.getAllMemberNodes();
+        if (members.length > 0)
+        {
+            indentPush();
+            writeNewline();
+
+            final int len = members.length;
+            int i = 0;
+            for (IDefinitionNode mnode : members)
+            {
+                getWalker().walk(mnode);
+                if (mnode.getNodeID() == ASTNodeID.VariableID)
+                {
+                    write(ASEmitterTokens.SEMICOLON);
+                    if (i < len - 1)
+                        writeNewline();
+                }
+                else if (mnode.getNodeID() == ASTNodeID.FunctionID)
+                {
+                    if (i < len - 1)
+                        writeNewline();
+                }
+                else if (mnode.getNodeID() == ASTNodeID.GetterID
+                        || mnode.getNodeID() == ASTNodeID.SetterID)
+                {
+                    if (i < len - 1)
+                        writeNewline();
+                }
+                i++;
+            }
+
+            indentPop();
+        }
+
+        writeNewline();
+        write(ASEmitterTokens.BLOCK_CLOSE);
+    }
+
+    @Override
+    public void emitInterface(IInterfaceNode node)
+    {
+        writeToken(node.getNamespace());
+
+        writeToken(ASEmitterTokens.INTERFACE);
+        getWalker().walk(node.getNameExpressionNode());
+        write(ASEmitterTokens.SPACE);
+
+        IExpressionNode[] inodes = node.getExtendedInterfaceNodes();
+        final int ilen = inodes.length;
+        if (ilen != 0)
+        {
+            writeToken(ASEmitterTokens.EXTENDS);
+            for (int i = 0; i < ilen; i++)
+            {
+                getWalker().walk(inodes[i]);
+                if (i < ilen - 1)
+                {
+                    writeToken(ASEmitterTokens.COMMA);
+                }
+            }
+            write(ASEmitterTokens.SPACE);
+        }
+
+        write(ASEmitterTokens.BLOCK_OPEN);
+
+        final IDefinitionNode[] members = node.getAllMemberDefinitionNodes();
+        if (members.length > 0)
+        {
+            indentPush();
+            writeNewline();
+
+            final int len = members.length;
+            int i = 0;
+            for (IDefinitionNode mnode : members)
+            {
+                getWalker().walk(mnode);
+                write(ASEmitterTokens.SEMICOLON);
+                if (i < len - 1)
+                    writeNewline();
+                i++;
+            }
+
+            indentPop();
+        }
+
+        writeNewline();
+        write(ASEmitterTokens.BLOCK_CLOSE);
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitVarDeclaration(IVariableNode node)
+    {
+        if (!(node instanceof ChainedVariableNode))
+        {
+            emitMemberKeyword(node);
+        }
+
+        emitDeclarationName(node);
+        emitType(node.getVariableTypeNode());
+        emitAssignedValue(node.getAssignedValueNode());
+
+        if (!(node instanceof ChainedVariableNode))
+        {
+            // check for chained variables
+            int len = node.getChildCount();
+            for (int i = 0; i < len; i++)
+            {
+                IASNode child = node.getChild(i);
+                if (child instanceof ChainedVariableNode)
+                {
+                    writeToken(ASEmitterTokens.COMMA);
+                    emitVarDeclaration((IVariableNode) child);
+                }
+            }
+        }
+
+        // the client such as IASBlockWalker is responsible for the 
+        // semi-colon and newline handling
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitFieldDocumentation(IVariableNode node)
+    {
+    }
+
+    @Override
+    public void emitField(IVariableNode node)
+    {
+        emitFieldDocumentation(node);
+
+        IVariableDefinition definition = (IVariableDefinition) node
+                .getDefinition();
+
+        if (!(node instanceof ChainedVariableNode))
+        {
+            emitNamespaceIdentifier(node);
+            emitModifiers(definition);
+            emitMemberKeyword(node);
+        }
+
+        emitMemberName(node);
+        emitType(node.getVariableTypeNode());
+        emitAssignedValue(node.getAssignedValueNode());
+
+        if (!(node instanceof ChainedVariableNode))
+        {
+            // check for chained variables
+            int len = node.getChildCount();
+            for (int i = 0; i < len; i++)
+            {
+                IASNode child = node.getChild(i);
+                if (child instanceof ChainedVariableNode)
+                {
+                    writeToken(ASEmitterTokens.COMMA);
+                    emitField((IVariableNode) child);
+                }
+            }
+        }
+
+        // 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)
+    {
+        // see below, this is temp, I don't want a bunch of duplicated code
+        // at them moment, subclasses can refine anyways, we are generalizing
+        if (node instanceof IGetterNode)
+        {
+            emitGetAccessorDocumentation((IGetterNode) node);
+        }
+        else if (node instanceof ISetterNode)
+        {
+            emitSetAccessorDocumentation((ISetterNode) node);
+        }
+        else
+        {
+            emitMethodDocumentation(node);
+        }
+
+        FunctionNode fn = (FunctionNode) node;
+        fn.parseFunctionBody(problems);
+
+        IFunctionDefinition definition = node.getDefinition();
+
+        emitNamespaceIdentifier(node);
+        emitModifiers(definition);
+        emitMemberKeyword(node);
+
+        // I'm cheating right here, I haven't "seen" the light
+        // on how to properly and efficiently deal with accessors since they are SO alike
+        // I don't want to lump them in with methods because implementations in the
+        // future need to know the difference without loopholes
+        if (node instanceof IAccessorNode)
+        {
+            emitAccessorKeyword(((IAccessorNode) node).getAccessorKeywordNode());
+        }
+
+        emitMemberName(node);
+        emitParamters(node.getParameterNodes());
+        emitType(node.getReturnTypeNode());
+        if (node.getParent().getParent().getNodeID() == ASTNodeID.ClassID)
+        {
+            emitMethodScope(node.getScopedNode());
+        }
+
+        // the client such as IASBlockWalker is responsible for the 
+        // semi-colon and newline handling
+    }
+
+    @Override
+    public void emitGetAccessorDocumentation(IGetterNode node)
+    {
+    }
+
+    @Override
+    public void emitGetAccessor(IGetterNode node)
+    {
+        // just cheat for now, IGetterNode is a IFunctionNode
+        emitMethod(node);
+    }
+
+    @Override
+    public void emitSetAccessorDocumentation(ISetterNode node)
+    {
+    }
+
+    @Override
+    public void emitSetAccessor(ISetterNode node)
+    {
+        // just cheat for now, ISetterNode is a IFunctionNode
+        emitMethod(node);
+    }
+
+    @Override
+    public void emitFunctionObject(IExpressionNode node)
+    {
+        FunctionObjectNode f = (FunctionObjectNode) node;
+        FunctionNode fnode = f.getFunctionNode();
+        write(ASEmitterTokens.FUNCTION);
+        emitParamters(fnode.getParameterNodes());
+        emitType(fnode.getTypeNode());
+        emitFunctionScope(fnode.getScopedNode());
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitNamespace(INamespaceNode node)
+    {
+        emitNamespaceIdentifier(node);
+        writeToken(ASEmitterTokens.NAMESPACE);
+        emitMemberName(node);
+        write(ASEmitterTokens.SPACE);
+        writeToken(ASEmitterTokens.EQUAL);
+        getWalker().walk(node.getNamespaceURINode());
+    }
+
+    //--------------------------------------------------------------------------
+    // 
+    //--------------------------------------------------------------------------
+
+    protected void emitNamespaceIdentifier(IDefinitionNode node)
+    {
+        String namespace = node.getNamespace();
+        if (namespace != null
+                && !namespace.equals(IASKeywordConstants.INTERNAL))
+        {
+            writeToken(namespace);
+        }
+    }
+
+    protected void emitModifiers(IDefinition definition)
+    {
+        ModifiersSet modifierSet = definition.getModifiers();
+        if (modifierSet.hasModifiers())
+        {
+            for (ASModifier modifier : modifierSet.getAllModifiers())
+            {
+                writeToken(modifier.toString());
+            }
+        }
+    }
+
+    protected void emitMemberKeyword(IDefinitionNode node)
+    {
+        if (node instanceof IFunctionNode)
+        {
+            writeToken(ASEmitterTokens.FUNCTION);
+        }
+        else if (node instanceof IVariableNode)
+        {
+            writeToken(((IVariableNode) node).isConst() ? ASEmitterTokens.CONST
+                    : ASEmitterTokens.VAR);
+        }
+    }
+
+    protected void emitMemberName(IDefinitionNode node)
+    {
+        getWalker().walk(node.getNameExpressionNode());
+    }
+
+    protected void emitDeclarationName(IDefinitionNode node)
+    {
+        getWalker().walk(node.getNameExpressionNode());
+    }
+
+    protected void emitParamters(IParameterNode[] nodes)
+    {
+        write(ASEmitterTokens.PAREN_OPEN);
+        int len = nodes.length;
+        for (int i = 0; i < len; i++)
+        {
+            IParameterNode node = nodes[i];
+            getWalker().walk(node); //emitParameter
+            if (i < len - 1)
+            {
+                writeToken(ASEmitterTokens.COMMA);
+            }
+        }
+        write(ASEmitterTokens.PAREN_CLOSE);
+    }
+
+    @Override
+    public void emitParameter(IParameterNode node)
+    {
+        getWalker().walk(node.getNameExpressionNode());
+        write(ASEmitterTokens.COLON);
+        getWalker().walk(node.getVariableTypeNode());
+        IExpressionNode anode = node.getAssignedValueNode();
+        if (anode != null)
+        {
+            write(ASEmitterTokens.SPACE);
+            writeToken(ASEmitterTokens.EQUAL);
+            getWalker().walk(anode);
+        }
+    }
+
+    protected void emitType(IExpressionNode node)
+    {
+        // TODO (mschmalle) node.getVariableTypeNode() will return "*" if undefined, what to use?
+        // or node.getReturnTypeNode()
+        if (node != null)
+        {
+            write(ASEmitterTokens.COLON);
+            getWalker().walk(node);
+        }
+    }
+
+    protected void emitAssignedValue(IExpressionNode node)
+    {
+        if (node != null)
+        {
+            write(ASEmitterTokens.SPACE);
+            writeToken(ASEmitterTokens.EQUAL);
+            getWalker().walk(node);
+        }
+    }
+
+    @Override
+    public void emitFunctionBlockHeader(IFunctionNode node)
+    {
+        // nothing to do in AS
+    }
+
+    protected void emitMethodScope(IScopedNode node)
+    {
+        write(ASEmitterTokens.SPACE);
+        getWalker().walk(node);
+    }
+
+    protected void emitAccessorKeyword(IKeywordNode node)
+    {
+        getWalker().walk(node);
+        write(ASEmitterTokens.SPACE);
+    }
+
+    protected void emitFunctionScope(IScopedNode node)
+    {
+        emitMethodScope(node);
+    }
+
+    //--------------------------------------------------------------------------
+    // Statements
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitStatement(IASNode node)
+    {
+        getWalker().walk(node);
+        // XXX (mschmalle) this should be in the after handler?
+        if (node.getParent().getNodeID() != ASTNodeID.LabledStatementID
+                && !(node instanceof IStatementNode))
+        {
+            write(ASEmitterTokens.SEMICOLON);
+        }
+
+        if (!isLastStatement(node))
+            writeNewline();
+    }
+
+    @Override
+    public void emitIf(IIfNode node)
+    {
+        IConditionalNode conditional = (IConditionalNode) node.getChild(0);
+
+        IContainerNode xnode = (IContainerNode) conditional
+                .getStatementContentsNode();
+
+        writeToken(ASEmitterTokens.IF);
+        //write(SPACE);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(conditional.getChild(0)); // conditional expression
+        write(ASEmitterTokens.PAREN_CLOSE);
+        if (!isImplicit(xnode))
+            write(ASEmitterTokens.SPACE);
+
+        getWalker().walk(conditional.getChild(1)); // BlockNode
+        IConditionalNode[] nodes = node.getElseIfNodes();
+        if (nodes.length > 0)
+        {
+            for (int i = 0; i < nodes.length; i++)
+            {
+                IConditionalNode enode = nodes[i];
+                IContainerNode snode = (IContainerNode) enode
+                        .getStatementContentsNode();
+
+                final boolean isImplicit = isImplicit(snode);
+                if (isImplicit)
+                    writeNewline();
+                else
+                    write(ASEmitterTokens.SPACE);
+
+                writeToken(ASEmitterTokens.ELSE);
+                writeToken(ASEmitterTokens.IF);
+                write(ASEmitterTokens.PAREN_OPEN);
+                getWalker().walk(enode.getChild(0));
+                write(ASEmitterTokens.PAREN_CLOSE);
+                if (!isImplicit)
+                    write(ASEmitterTokens.SPACE);
+
+                getWalker().walk(enode.getChild(1)); // ConditionalNode
+            }
+        }
+
+        ITerminalNode elseNode = node.getElseNode();
+        if (elseNode != null)
+        {
+            IContainerNode cnode = (IContainerNode) elseNode.getChild(0);
+            // if an implicit if, add a newline with no space
+            final boolean isImplicit = isImplicit(cnode);
+            if (isImplicit)
+                writeNewline();
+            else
+                write(ASEmitterTokens.SPACE);
+            write(ASEmitterTokens.ELSE);
+            if (!isImplicit)
+                write(ASEmitterTokens.SPACE);
+
+            getWalker().walk(elseNode); // TerminalNode
+        }
+    }
+
+    @Override
+    public void emitForEachLoop(IForLoopNode node)
+    {
+        IContainerNode xnode = (IContainerNode) node.getChild(1);
+        writeToken(ASEmitterTokens.FOR);
+        writeToken(ASEmitterTokens.EACH);
+        write(ASEmitterTokens.PAREN_OPEN);
+
+        IContainerNode cnode = node.getConditionalsContainerNode();
+        getWalker().walk(cnode.getChild(0));
+
+        write(ASEmitterTokens.PAREN_CLOSE);
+        if (!isImplicit(xnode))
+            write(ASEmitterTokens.SPACE);
+
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    public void emitForLoop(IForLoopNode node)
+    {
+        IContainerNode xnode = (IContainerNode) node.getChild(1);
+
+        writeToken(ASEmitterTokens.FOR);
+        write(ASEmitterTokens.PAREN_OPEN);
+
+        IContainerNode cnode = node.getConditionalsContainerNode();
+        final IASNode node0 = cnode.getChild(0);
+        if (node0.getNodeID() == ASTNodeID.Op_InID)
+        {
+            getWalker().walk(cnode.getChild(0));
+        }
+        else
+        {
+            visitForBody(cnode);
+        }
+
+        write(ASEmitterTokens.PAREN_CLOSE);
+        if (!isImplicit(xnode))
+            write(ASEmitterTokens.SPACE);
+
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    public void emitSwitch(ISwitchNode node)
+    {
+        writeToken(ASEmitterTokens.SWITCH);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(node.getChild(0));
+        writeToken(ASEmitterTokens.PAREN_CLOSE);
+        writeNewline(ASEmitterTokens.BLOCK_OPEN, true);
+
+        IConditionalNode[] cnodes = ASNodeUtils.getCaseNodes(node);
+        ITerminalNode dnode = ASNodeUtils.getDefaultNode(node);
+
+        for (int i = 0; i < cnodes.length; i++)
+        {
+            IConditionalNode casen = cnodes[i];
+            IContainerNode cnode = (IContainerNode) casen.getChild(1);
+            writeToken(ASEmitterTokens.CASE);
+            getWalker().walk(casen.getConditionalExpressionNode());
+            write(ASEmitterTokens.COLON);
+            if (!isImplicit(cnode))
+                write(ASEmitterTokens.SPACE);
+            getWalker().walk(casen.getStatementContentsNode());
+            if (i == cnodes.length - 1 && dnode == null)
+            {
+                indentPop();
+                writeNewline();
+            }
+            else
+                writeNewline();
+        }
+        if (dnode != null)
+        {
+            IContainerNode cnode = (IContainerNode) dnode.getChild(0);
+            write(ASEmitterTokens.DEFAULT);
+            write(ASEmitterTokens.COLON);
+            if (!isImplicit(cnode))
+                write(ASEmitterTokens.SPACE);
+            getWalker().walk(dnode);
+            indentPop();
+            writeNewline();
+        }
+        write(ASEmitterTokens.BLOCK_CLOSE);
+    }
+
+    @Override
+    public void emitWhileLoop(IWhileLoopNode node)
+    {
+        IContainerNode cnode = (IContainerNode) node.getChild(1);
+        writeToken(ASEmitterTokens.WHILE);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(node.getConditionalExpressionNode());
+        write(ASEmitterTokens.PAREN_CLOSE);
+        if (!isImplicit(cnode))
+            write(ASEmitterTokens.SPACE);
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    public void emitDoLoop(IWhileLoopNode node)
+    {
+        IContainerNode cnode = (IContainerNode) node.getChild(0);
+        write(ASEmitterTokens.DO);
+        if (!isImplicit(cnode))
+            write(ASEmitterTokens.SPACE);
+        getWalker().walk(node.getStatementContentsNode());
+        if (!isImplicit(cnode))
+            write(ASEmitterTokens.SPACE);
+        else
+            writeNewline(); // TODO (mschmalle) there is something wrong here, block should NL
+        write(ASEmitterTokens.WHILE);
+        write(ASEmitterTokens.SPACE);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(node.getConditionalExpressionNode());
+        write(ASEmitterTokens.PAREN_CLOSE);
+        write(ASEmitterTokens.SEMICOLON);
+    }
+
+    @Override
+    public void emitWith(IWithNode node)
+    {
+        IContainerNode cnode = (IContainerNode) node.getChild(1);
+        writeToken(ASEmitterTokens.WITH);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(node.getTargetNode());
+        write(ASEmitterTokens.PAREN_CLOSE);
+        if (!isImplicit(cnode))
+            write(ASEmitterTokens.SPACE);
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    public void emitThrow(IThrowNode node)
+    {
+        writeToken(ASEmitterTokens.THROW);
+        getWalker().walk(node.getThrownExpressionNode());
+    }
+
+    @Override
+    public void emitTry(ITryNode node)
+    {
+        writeToken(ASEmitterTokens.TRY);
+        getWalker().walk(node.getStatementContentsNode());
+        for (int i = 0; i < node.getCatchNodeCount(); i++)
+        {
+            getWalker().walk(node.getCatchNode(i));
+        }
+        ITerminalNode fnode = node.getFinallyNode();
+        if (fnode != null)
+        {
+            write(ASEmitterTokens.SPACE);
+            writeToken(ASEmitterTokens.FINALLY);
+            getWalker().walk(fnode);
+        }
+    }
+
+    @Override
+    public void emitCatch(ICatchNode node)
+    {
+        write(ASEmitterTokens.SPACE);
+        writeToken(ASEmitterTokens.CATCH);
+        write(ASEmitterTokens.PAREN_OPEN);
+        getWalker().walk(node.getCatchParameterNode());
+        writeToken(ASEmitterTokens.PAREN_CLOSE);
+        getWalker().walk(node.getStatementContentsNode());
+    }
+
+    @Override
+    public void emitReturn(IReturnNode node)
+    {
+        write(ASEmitterTokens.RETURN);
+        IExpressionNode rnode = node.getReturnValueNode();
+        if (rnode != null && rnode.getNodeID() != ASTNodeID.NilID)
+        {
+            write(ASEmitterTokens.SPACE);
+            getWalker().walk(rnode);
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    // Expressions
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitFunctionCall(IFunctionCallNode node)
+    {
+        if (node.isNewExpression())
+        {
+            writeToken(ASEmitterTokens.NEW);
+        }
+
+        getWalker().walk(node.getNameNode());
+
+        write(ASEmitterTokens.PAREN_OPEN);
+        walkArguments(node.getArgumentNodes());
+        write(ASEmitterTokens.PAREN_CLOSE);
+    }
+
+    //--------------------------------------------------------------------------
+    // Operators
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void emitAsOperator(IBinaryOperatorNode node)
+    {
+        getWalker().walk(node.getLeftOperandNode());
+        write(ASEmitterTokens.SPACE);
+        writeToken(node.getOperator().getOperatorText());
+        getWalker().walk(node.getRightOperandNode());
+    }
+
+    @Override
+    public void emitIsOperator(IBinaryOperatorNode node)
+    {
+        getWalker().walk(node.getLeftOperandNode());
+        write(ASEmitterTokens.SPACE);
+        writeToken(node.getOperator().getOperatorText());
+        getWalker().walk(node.getRightOperandNode());
+    }
+
+    @Override
+    public void emitBinaryOperator(IBinaryOperatorNode node)
+    {
+        getWalker().walk(node.getLeftOperandNode());
+        if (node.getNodeID() != ASTNodeID.Op_CommaID)
+            write(ASEmitterTokens.SPACE);
+        writeToken(node.getOperator().getOperatorText());
+        getWalker().walk(node.getRightOperandNode());
+    }
+
+    //--------------------------------------------------------------------------
+    // Utility
+    //--------------------------------------------------------------------------
+
+    protected ITypeNode findTypeNode(IPackageNode node)
+    {
+        IScopedNode scope = node.getScopedNode();
+        for (int i = 0; i < scope.getChildCount(); i++)
+        {
+            IASNode child = scope.getChild(i);
+            if (child instanceof ITypeNode)
+                return (ITypeNode) child;
+        }
+        return null;
+    }
+
+    protected ITypeDefinition findType(Collection<IDefinition> definitions)
+    {
+        for (IDefinition definition : definitions)
+        {
+            if (definition instanceof ITypeDefinition)
+                return (ITypeDefinition) definition;
+        }
+        return null;
+    }
+
+    protected void walkArguments(IExpressionNode[] nodes)
+    {
+        int len = nodes.length;
+        for (int i = 0; i < len; i++)
+        {
+            IExpressionNode node = nodes[i];
+            getWalker().walk(node);
+            if (i < len - 1)
+            {
+                writeToken(ASEmitterTokens.COMMA);
+            }
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    // Static Utility
+    //--------------------------------------------------------------------------
+
+    protected static IFunctionNode getConstructor(IDefinitionNode[] members)
+    {
+        for (IDefinitionNode node : members)
+        {
+            if (node instanceof IFunctionNode)
+            {
+                IFunctionNode fnode = (IFunctionNode) node;
+                if (fnode.isConstructor())
+                    return fnode;
+            }
+        }
+        return null;
+    }
+
+    protected static boolean isLastStatement(IASNode node)
+    {
+        return getChildIndex(node.getParent(), node) == node.getParent()
+                .getChildCount() - 1;
+    }
+
+    // this is not fair that we have to do this if (i < len - 1)
+    private static int getChildIndex(IASNode parent, IASNode node)
+    {
+        final int len = parent.getChildCount();
+        for (int i = 0; i < len; i++)
+        {
+            if (parent.getChild(i) == node)
+                return i;
+        }
+        return -1;
+    }
+
+    protected static final boolean isImplicit(IContainerNode node)
+    {
+        return node.getContainerType() == ContainerType.IMPLICIT
+                || node.getContainerType() == ContainerType.SYNTHESIZED;
+    }
+
+    protected void visitForBody(IContainerNode node)
+    {
+        final IASNode node0 = node.getChild(0);
+        final IASNode node1 = node.getChild(1);
+        final IASNode node2 = node.getChild(2);
+
+        // initializer
+        if (node0 != null)
+        {
+            getWalker().walk(node0);
+            write(ASEmitterTokens.SEMICOLON);
+            if (node1.getNodeID() != ASTNodeID.NilID)
+                write(ASEmitterTokens.SPACE);
+        }
+        // condition or target
+        if (node1 != null)
+        {
+            getWalker().walk(node1);
+            write(ASEmitterTokens.SEMICOLON);
+            if (node2.getNodeID() != ASTNodeID.NilID)
+                write(ASEmitterTokens.SPACE);
+        }
+        // iterator
+        if (node2 != null)
+        {
+            getWalker().walk(node2);
+        }
+    }
+
+    @Override
+    public void emitLiteral(ILiteralNode node)
+    {
+        write(node.getValue(true));
+    }
+
+    @Override
+    public void emitLiteralContainer(IContainerNode node)
+    {
+        ContainerType type = node.getContainerType();
+        String postFix = "";
+
+        if (type == ContainerType.BRACES)
+        {
+            write(ASEmitterTokens.BLOCK_OPEN);
+            postFix = ASEmitterTokens.BLOCK_CLOSE.getToken();
+        }
+        else if (type == ContainerType.BRACKETS)
+        {
+            write(ASEmitterTokens.SQUARE_OPEN);
+            postFix = ASEmitterTokens.SQUARE_CLOSE.getToken();
+        }
+        else if (type == ContainerType.IMPLICIT)
+        {
+            // nothing to write, move along
+        }
+        else if (type == ContainerType.PARENTHESIS)
+        {
+            write(ASEmitterTokens.PAREN_OPEN);
+            postFix = ASEmitterTokens.PAREN_CLOSE.getToken();
+        }
+
+        final int len = node.getChildCount();
+        for (int i = 0; i < len; i++)
+        {
+            IASNode child = node.getChild(i);
+            getWalker().walk(child);
+            if (i < len - 1)
+                writeToken(ASEmitterTokens.COMMA);
+        }
+
+        if (postFix != "")
+            write(postFix);
+    }
+
+    @Override
+    public void emitIdentifier(IIdentifierNode node)
+    {
+        write(node.getName());
+    }
+
+    @Override
+    public void emitNumericLiteral(INumericLiteralNode node)
+    {
+        write(node.getNumericValue().toString());
+    }
+
+    @Override
+    public void emitKeyword(IKeywordNode node)
+    {
+        write(node.getNodeID().getParaphrase());
+    }
+
+    @Override
+    public void emitIterationFlow(IIterationFlowNode node)
+    {
+        write(node.getKind().toString().toLowerCase());
+        IIdentifierNode lnode = node.getLabelNode();
+        if (lnode != null)
+        {
+            write(ASEmitterTokens.SPACE);
+            getWalker().walk(lnode);
+        }
+    }
+
+    @Override
+    public void emitMemberAccessExpression(IMemberAccessExpressionNode node)
+    {
+        getWalker().walk(node.getLeftOperandNode());
+        write(node.getOperator().getOperatorText());
+        getWalker().walk(node.getRightOperandNode());
+    }
+
+    @Override
+    public void emitDynamicAccess(IDynamicAccessNode node)
+    {
+        getWalker().walk(node.getLeftOperandNode());
+        write(ASEmitterTokens.SQUARE_OPEN);
+        getWalker().walk(node.getRightOperandNode());
+        write(ASEmitterTokens.SQUARE_CLOSE);
+    }
+
+    @Override
+    public void emitTypedExpression(ITypedExpressionNode node)
+    {
+        getWalker().walk(node.getCollectionNode());
+        write(ASEmitterTokens.MEMBER_ACCESS);
+        write(ASEmitterTokens.LESS_THAN);
+        getWalker().walk(node.getTypeNode());
+        write(ASEmitterTokens.GREATER_THAN);
+    }
+
+    @Override
+    public void emitTernaryOperator(ITernaryOperatorNode node)
+    {
+        getWalker().walk(node.getConditionalNode());
+        write(ASEmitterTokens.SPACE);
+        writeToken(ASEmitterTokens.TERNARY);
+        getWalker().walk(node.getLeftOperandNode());
+        write(ASEmitterTokens.SPACE);
+        writeToken(ASEmitterTokens.COLON);
+        getWalker().walk(node.getRightOperandNode());
+    }
+
+    @Override
+    public void emitObjectLiteralValuePair(IObjectLiteralValuePairNode node)
+    {
+        getWalker().walk(node.getNameNode());
+        write(ASEmitterTokens.COLON);
+        getWalker().walk(node.getValueNode());
+    }
+
+    @Override
+    public void emitLabelStatement(LabeledStatementNode node)
+    {
+        writeToken(node.getLabel());
+        writeToken(ASEmitterTokens.COLON);
+        getWalker().walk(node.getLabeledStatement());
+    }
+
+    @Override
+    public void emitNamespaceAccessExpression(NamespaceAccessExpressionNode node)
+    {
+        getWalker().walk(node.getLeftOperandNode());
+        write(node.getOperator().getOperatorText());
+        getWalker().walk(node.getRightOperandNode());
+    }
+
+    @Override
+    public void emitUnaryOperator(IUnaryOperatorNode node)
+    {
+        if (node.getNodeID() == ASTNodeID.Op_PreIncrID
+                || node.getNodeID() == ASTNodeID.Op_PreDecrID
+                || node.getNodeID() == ASTNodeID.Op_BitwiseNotID
+                || node.getNodeID() == ASTNodeID.Op_LogicalNotID
+                || node.getNodeID() == ASTNodeID.Op_SubtractID
+                || node.getNodeID() == ASTNodeID.Op_AddID)
+        {
+            write(node.getOperator().getOperatorText());
+            getWalker().walk(node.getOperandNode());
+        }
+
+        else if (node.getNodeID() == ASTNodeID.Op_PostIncrID
+                || node.getNodeID() == ASTNodeID.Op_PostDecrID)
+        {
+            getWalker().walk(node.getOperandNode());
+            write(node.getOperator().getOperatorText());
+        }
+        else if (node.getNodeID() == ASTNodeID.Op_DeleteID
+                || node.getNodeID() == ASTNodeID.Op_VoidID)
+        {
+            writeToken(node.getOperator().getOperatorText());
+            getWalker().walk(node.getOperandNode());
+        }
+        else if (node.getNodeID() == ASTNodeID.Op_TypeOfID)
+        {
+            write(node.getOperator().getOperatorText());
+            write(ASEmitterTokens.PAREN_OPEN);
+            getWalker().walk(node.getOperandNode());
+            write(ASEmitterTokens.PAREN_CLOSE);
+        }
+    }
+
+    @Override
+    public void emitLanguageIdentifier(ILanguageIdentifierNode node)
+    {
+        if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.ANY_TYPE)
+        {
+            write(ASEmitterTokens.ANY_TYPE);
+        }
+        else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.REST)
+        {
+            write(ASEmitterTokens.ELLIPSIS);
+        }
+        else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.SUPER)
+        {
+            write(ASEmitterTokens.SUPER);
+        }
+        else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.THIS)
+        {
+            write(ASEmitterTokens.THIS);
+        }
+        else if (node.getKind() == ILanguageIdentifierNode.LanguageIdentifierKind.VOID)
+        {
+            write(ASEmitterTokens.VOID);
+        }
+    }
+
+    @Override
+    public void emitMetaTag(IMetaTagNode node)
+    {
+    }
+
+    /**
+     * Takes the node argument and created a String representation if it using
+     * the buffer temporarily.
+     * <p>
+     * Note; This method is still beta, it need more logic if an emitter is
+     * actually using the buffer!
+     * 
+     * @param node The node walk and create a String for.
+     * @return The node's output.
+     */
+    protected String stringifyNode(IASNode node)
+    {
+        setBufferWrite(true);
+        getWalker().walk(node);
+        String result = getBuilder().toString();
+        getBuilder().setLength(0);
+        setBufferWrite(false);
+        return result;
+    }
+}

Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message