You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2016/04/13 20:56:32 UTC
[40/51] [partial] git commit: [flex-falcon]
[refs/heads/feature/maven-migration-test] - - Check-In of the migrated
project to make error analysis easier
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
new file mode 100644
index 0000000..6e5cc75
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -0,0 +1,504 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
+import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+import org.apache.flex.compiler.internal.tree.as.UnaryOperatorAtNode;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.utils.ASNodeUtils;
+
+public class BinaryOperatorEmitter extends JSSubEmitter implements
+ ISubEmitter<IBinaryOperatorNode>
+{
+
+ public BinaryOperatorEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IBinaryOperatorNode node)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ ASTNodeID id = node.getNodeID();
+ /*
+ if (id == ASTNodeID.Op_InID
+ || id == ASTNodeID.Op_LogicalAndAssignID
+ || id == ASTNodeID.Op_LogicalOrAssignID)
+ {
+ super.emitBinaryOperator(node);
+ }
+ else */if (id == ASTNodeID.Op_IsID || id == ASTNodeID.Op_AsID)
+ {
+ fjs.emitIsAs(node, node.getLeftOperandNode(), node.getRightOperandNode(),
+ id, false);
+ }
+ else if (id == ASTNodeID.Op_InstanceOfID)
+ {
+ getWalker().walk(node.getLeftOperandNode());
+
+ startMapping(node, node.getLeftOperandNode());
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.INSTANCEOF);
+ endMapping(node);
+
+ IDefinition dnode = (node.getRightOperandNode())
+ .resolve(getProject());
+ if (dnode != null)
+ write(getEmitter()
+ .formatQualifiedName(dnode.getQualifiedName()));
+ else
+ getWalker().walk(node.getRightOperandNode());
+ }
+ else
+ {
+ IExpressionNode leftSide = node.getLeftOperandNode();
+ if (leftSide.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+ {
+ IASNode lnode = leftSide.getChild(0);
+ IASNode rnode = leftSide.getChild(1);
+ IDefinition rnodeDef = (rnode instanceof IIdentifierNode) ?
+ ((IIdentifierNode) rnode).resolve(getWalker().getProject()) :
+ null;
+ if (lnode.getNodeID() == ASTNodeID.SuperID
+ && rnodeDef instanceof AccessorDefinition)
+ {
+ String op = node.getOperator().getOperatorText();
+ boolean isAssignment = op.contains("=")
+ && !op.contains("==")
+ && !(op.startsWith("<") || op.startsWith(">") || op
+ .startsWith("!"));
+ if (isAssignment)
+ {
+ ICompilerProject project = this.getProject();
+ if (project instanceof FlexJSProject)
+ ((FlexJSProject)project).needLanguage = true;
+
+ write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSFlexJSEmitterTokens.SUPERSETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ IClassNode cnode = (IClassNode) node
+ .getAncestorOfType(IClassNode.class);
+ write(getEmitter().formatQualifiedName(
+ cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(rnodeDef.getBaseName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ writeToken(ASEmitterTokens.COMMA);
+
+ if (op.length() > 1) // += and things like that
+ {
+ write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSFlexJSEmitterTokens.SUPERSETTER);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(getEmitter().formatQualifiedName(
+ cnode.getQualifiedName()));
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(rnodeDef.getBaseName());
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(op.substring(0, 1));
+ }
+
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ }
+ else if (((JSFlexJSEmitter)getEmitter()).isXMLList((MemberAccessExpressionNode)leftSide))
+ {
+ MemberAccessExpressionNode xmlNode = (MemberAccessExpressionNode)leftSide;
+ if (node.getNodeID() == ASTNodeID.Op_AssignId)
+ {
+ getWalker().walk(xmlNode.getLeftOperandNode());
+ IExpressionNode rightSide = xmlNode.getRightOperandNode();
+ if (rightSide instanceof UnaryOperatorAtNode)
+ {
+ write(".setAttribute('");
+ getWalker().walk(((UnaryOperatorAtNode)rightSide).getChild(0));
+ }
+ else
+ {
+ write(".setChild('");
+ getWalker().walk(rightSide);
+ }
+ write("', ");
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ else if (node.getNodeID() == ASTNodeID.Op_AddAssignID)
+ {
+ getWalker().walk(xmlNode);
+ write(".concat(");
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ else if (node.getNodeID() == ASTNodeID.Op_AddID)
+ {
+ getWalker().walk(xmlNode);
+ write(".copy().concat(");
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ }
+ else if (((JSFlexJSEmitter)getEmitter()).isProxy((MemberAccessExpressionNode)leftSide))
+ {
+ MemberAccessExpressionNode proxyNode = (MemberAccessExpressionNode)leftSide;
+ if (node.getNodeID() == ASTNodeID.Op_AssignId)
+ {
+ getWalker().walk(proxyNode.getLeftOperandNode());
+ IExpressionNode rightSide = proxyNode.getRightOperandNode();
+ write(".setProperty('");
+ getWalker().walk(rightSide);
+ write("', ");
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ else if (node.getNodeID() == ASTNodeID.Op_AddAssignID)
+ {
+ IExpressionNode rightSide = proxyNode.getRightOperandNode();
+ getWalker().walk(proxyNode.getLeftOperandNode());
+ write(".setProperty('");
+ getWalker().walk(rightSide);
+ write("', ");
+ getWalker().walk(proxyNode.getLeftOperandNode());
+ write(".getProperty(");
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ getWalker().walk(rightSide);
+ write(ASEmitterTokens.SINGLE_QUOTE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(" + ");
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ return;
+ }
+ }
+ else if (((JSFlexJSEmitter)getEmitter()).isDateProperty((MemberAccessExpressionNode)leftSide))
+ {
+ specialCaseDate(node, (MemberAccessExpressionNode)leftSide);
+ return;
+ }
+ }
+
+ super_emitBinaryOperator(node);
+ /*
+ IExpressionNode leftSide = node.getLeftOperandNode();
+
+ IExpressionNode property = null;
+ int leftSideChildCount = leftSide.getChildCount();
+ if (leftSideChildCount > 0)
+ {
+ IASNode childNode = leftSide.getChild(leftSideChildCount - 1);
+ if (childNode instanceof IExpressionNode)
+ property = (IExpressionNode) childNode;
+ else
+ property = leftSide;
+ }
+ else
+ property = leftSide;
+
+ IDefinition def = null;
+ if (property instanceof IIdentifierNode)
+ def = ((IIdentifierNode) property).resolve(getWalker()
+ .getProject());
+
+ boolean isSuper = false;
+ if (leftSide.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+ {
+ IASNode cnode = leftSide.getChild(0);
+ ASTNodeID cId = cnode.getNodeID();
+
+ isSuper = cId == ASTNodeID.SuperID;
+ }
+
+ String op = node.getOperator().getOperatorText();
+ boolean isAssignment = op.contains("=") && !op.contains("==") &&
+ !(op.startsWith("<") ||
+ op.startsWith(">") ||
+ op.startsWith("!"));
+
+ if (def instanceof AccessorDefinition && isAssignment)
+ {
+ // this will make the set_foo call
+ getWalker().walk(leftSide);
+ }
+ else if (isSuper)
+ {
+ emitSuperCall(node, "");
+ }
+ else
+ {
+ if (ASNodeUtils.hasParenOpen(node))
+ write(ASEmitterTokens.PAREN_OPEN);
+
+ getWalker().walk(leftSide);
+
+ if (node.getNodeID() != ASTNodeID.Op_CommaID)
+ write(ASEmitterTokens.SPACE);
+
+ writeToken(node.getOperator().getOperatorText());
+
+ getWalker().walk(node.getRightOperandNode());
+
+ if (ASNodeUtils.hasParenClose(node))
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+ */
+ }
+ }
+
+ private void super_emitBinaryOperator(IBinaryOperatorNode node)
+ {
+ if (ASNodeUtils.hasParenOpen(node))
+ write(ASEmitterTokens.PAREN_OPEN);
+
+ ASTNodeID id = node.getNodeID();
+
+ if (id == ASTNodeID.Op_IsID)
+ {
+ write(ASEmitterTokens.IS);
+ write(ASEmitterTokens.PAREN_OPEN);
+ getWalker().walk(node.getLeftOperandNode());
+ writeToken(ASEmitterTokens.COMMA);
+ getWalker().walk(node.getRightOperandNode());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+ else if (id == ASTNodeID.Op_AsID)
+ {
+ // (is(a, b) ? a : null)
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.IS);
+ write(ASEmitterTokens.PAREN_OPEN);
+ getWalker().walk(node.getLeftOperandNode());
+ writeToken(ASEmitterTokens.COMMA);
+ getWalker().walk(node.getRightOperandNode());
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ writeToken(ASEmitterTokens.TERNARY);
+ getWalker().walk(node.getLeftOperandNode());
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.COLON);
+ write(ASEmitterTokens.NULL);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+ else
+ {
+ getWalker().walk(node.getLeftOperandNode());
+
+ startMapping(node, node.getLeftOperandNode());
+
+ if (id != ASTNodeID.Op_CommaID)
+ write(ASEmitterTokens.SPACE);
+
+ // (erikdebruin) rewrite 'a &&= b' to 'a = a && b'
+ if (id == ASTNodeID.Op_LogicalAndAssignID
+ || id == ASTNodeID.Op_LogicalOrAssignID)
+ {
+ IIdentifierNode lnode = (IIdentifierNode) node
+ .getLeftOperandNode();
+
+ writeToken(ASEmitterTokens.EQUAL);
+ endMapping(node);
+ write(lnode.getName());
+
+ startMapping(node, node.getLeftOperandNode());
+ write(ASEmitterTokens.SPACE);
+ write((id == ASTNodeID.Op_LogicalAndAssignID) ? ASEmitterTokens.LOGICAL_AND
+ : ASEmitterTokens.LOGICAL_OR);
+ }
+ else
+ {
+ write(node.getOperator().getOperatorText());
+ }
+
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+
+ /*
+ IDefinition definition = node.getRightOperandNode().resolve(getProject());
+ if (definition instanceof FunctionDefinition &&
+ (!(definition instanceof AccessorDefinition)))
+ {
+ }
+ else */
+ getWalker().walk(node.getRightOperandNode());
+ if (node.getNodeID() == ASTNodeID.Op_InID &&
+ ((JSFlexJSEmitter)getEmitter()).isXML(node.getRightOperandNode()))
+ {
+ write(".elementNames()");
+ }
+ else if (node.getNodeID() == ASTNodeID.Op_InID &&
+ ((JSFlexJSEmitter)getEmitter()).isProxy(node.getRightOperandNode()))
+ {
+ write(".propertyNames()");
+ }
+ }
+
+ if (ASNodeUtils.hasParenOpen(node))
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+
+ private enum DateProperties
+ {
+ FULLYEAR("fullYear", "setFullYear"),
+ MONTH("month", "setMonth"),
+ DATE("date", "setDate"),
+ FULLYEARUTC("fullYearUTC", "setUTCFullYear"),
+ MONTHUTC("monthUTC", "setUTCMonth"),
+ DATEUTC("dateUTC", "setUTCDate"),
+ HOURS("hours", "setHours"),
+ MINUTES("minutes", "setMinutes"),
+ SECONDS("seconds", "setSeconds"),
+ MILLISECONDS("milliseconds", "setMilliseconds"),
+ HOURSUTC("hoursUTC", "setUTCHours"),
+ MINUTESUTC("minutesUTC", "setUTCMinutes"),
+ SECONDSUTC("secondsUTC", "setUTCSeconds"),
+ MILLISECONDSUTC("millisecondsUTC", "setUTCMilliseconds");
+
+ DateProperties(String value, String functionName)
+ {
+ this.value = value;
+ this.functionName = functionName;
+ }
+
+ private String value;
+ private String functionName;
+
+ public String getFunctionName()
+ {
+ return functionName;
+ }
+ }
+
+ void specialCaseDate(IBinaryOperatorNode node, MemberAccessExpressionNode leftSide)
+ {
+ MemberAccessExpressionNode dateNode = (MemberAccessExpressionNode)leftSide;
+ IIdentifierNode rightSide = (IIdentifierNode)dateNode.getRightOperandNode();
+ getWalker().walk(dateNode.getLeftOperandNode());
+ String rightName = rightSide.getName();
+ DateProperties prop = DateProperties.valueOf(rightName.toUpperCase());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(prop.getFunctionName());
+ write(ASEmitterTokens.PAREN_OPEN);
+ getWalker().walk(node.getRightOperandNode());
+ switch (prop)
+ {
+ case FULLYEAR:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getMonth()");
+ // fall through
+ case MONTH:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getDate()");
+ break;
+ case FULLYEARUTC:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getMonthUTC()");
+ // fall through
+ case MONTHUTC:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getDateUTC()");
+ break;
+ case HOURS:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getMinutes()");
+ // fall through
+ case MINUTES:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getSeconds()");
+ // fall through
+ case SECONDS:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getMilliseconds()");
+ break;
+ case HOURSUTC:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getUTCMinutes()");
+ // fall through
+ case MINUTESUTC:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getUTCSeconds()");
+ // fall through
+ case SECONDSUTC:
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ getWalker().walk(dateNode.getLeftOperandNode());
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("getUTCMilliseconds()");
+ break;
+ }
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
new file mode 100644
index 0000000..c8cbec0
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/BindableEmitter.java
@@ -0,0 +1,129 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
+
+public class BindableEmitter extends JSSubEmitter implements
+ ISubEmitter<IClassDefinition>
+{
+ public BindableEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IClassDefinition definition)
+ {
+ if (getModel().hasBindableVars())
+ {
+ write(JSGoogEmitterTokens.OBJECT);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.DEFINE_PROPERTIES);
+ write(ASEmitterTokens.PAREN_OPEN);
+ String qname = definition.getQualifiedName();
+ write(getEmitter().formatQualifiedName(qname));
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(JSEmitterTokens.PROTOTYPE);
+ write(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.SPACE);
+ write("/** @lends {" + getEmitter().formatQualifiedName(qname)
+ + ".prototype} */ ");
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+
+ boolean firstTime = true;
+ for (String varName : getModel().getBindableVars())
+ {
+ if (firstTime)
+ firstTime = false;
+ else
+ write(ASEmitterTokens.COMMA);
+
+ emitBindableVarDefineProperty(varName, definition);
+ }
+ writeNewline(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+
+ private void emitBindableVarDefineProperty(String name,
+ IClassDefinition cdef)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ // 'PropName': {
+ writeNewline("/** @export */");
+ writeNewline(name + ASEmitterTokens.COLON.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.BLOCK_OPEN.getToken());
+ indentPush();
+ writeNewline("/** @this {"
+ + fjs.formatQualifiedName(cdef.getQualifiedName()) + "} */");
+ writeNewline(ASEmitterTokens.GET.getToken()
+ + ASEmitterTokens.COLON.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.FUNCTION.getToken()
+ + ASEmitterTokens.PAREN_OPEN.getToken()
+ + ASEmitterTokens.PAREN_CLOSE.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.BLOCK_OPEN.getToken());
+ writeNewline(ASEmitterTokens.RETURN.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
+ + ASEmitterTokens.SEMICOLON.getToken());
+ indentPop();
+ writeNewline(ASEmitterTokens.BLOCK_CLOSE.getToken()
+ + ASEmitterTokens.COMMA.getToken());
+ writeNewline();
+ writeNewline("/** @this {"
+ + fjs.formatQualifiedName(cdef.getQualifiedName()) + "} */");
+ writeNewline(ASEmitterTokens.SET.getToken()
+ + ASEmitterTokens.COLON.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.FUNCTION.getToken()
+ + ASEmitterTokens.PAREN_OPEN.getToken() + "value"
+ + ASEmitterTokens.PAREN_CLOSE.getToken()
+ + ASEmitterTokens.SPACE.getToken()
+ + ASEmitterTokens.BLOCK_OPEN.getToken());
+ writeNewline("if (value != " + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_) {");
+ writeNewline(" var oldValue = " + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name + "_"
+ + ASEmitterTokens.SEMICOLON.getToken());
+ writeNewline(" " + ASEmitterTokens.THIS.getToken()
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + name
+ + "_ = value;");
+ writeNewline(" this.dispatchEvent(org.apache.flex.events.ValueChangeEvent.createUpdateEvent(");
+ writeNewline(" this, \"" + name + "\", oldValue, value));");
+ writeNewline("}");
+ write(ASEmitterTokens.BLOCK_CLOSE.getToken());
+ write(ASEmitterTokens.BLOCK_CLOSE.getToken());
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
new file mode 100644
index 0000000..fe0bc7e
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
@@ -0,0 +1,182 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.asdoc.flexjs.ASDocComment;
+import org.apache.flex.compiler.clients.MXMLJSC;
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.utils.DocEmitterUtils;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
+import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+
+public class ClassEmitter extends JSSubEmitter implements
+ ISubEmitter<IClassNode>
+{
+
+ public ClassEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IClassNode node)
+ {
+ getModel().pushClass(node.getDefinition());
+
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ getEmitter().pushSourceMapName(node);
+
+ ASDocComment asDoc = (ASDocComment) node.getASDocComment();
+ if (asDoc != null && MXMLJSC.keepASDoc)
+ DocEmitterUtils.loadImportIgnores(fjs, asDoc.commentNoEnd());
+
+ IClassDefinition definition = node.getDefinition();
+
+ IFunctionDefinition ctorDefinition = definition.getConstructor();
+
+ // Static-only (Singleton) classes may not have a constructor
+ if (ctorDefinition != null)
+ {
+ IFunctionNode ctorNode = (IFunctionNode) ctorDefinition.getNode();
+ if (ctorNode != null)
+ {
+ // constructor
+ getEmitter().emitMethod(ctorNode);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ else
+ {
+ String qname = definition.getQualifiedName();
+ if (qname != null && !qname.equals(""))
+ {
+ write(getEmitter().formatQualifiedName(qname));
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.FUNCTION);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.BLOCK_OPEN);
+ writeNewline();
+ fjs.emitComplexInitializers(node);
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+ }
+
+ IDefinitionNode[] dnodes = node.getAllMemberNodes();
+ for (IDefinitionNode dnode : dnodes)
+ {
+ if (dnode.getNodeID() == ASTNodeID.VariableID)
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ getEmitter().emitField((IVariableNode) dnode);
+ startMapping(dnode, dnode);
+ write(ASEmitterTokens.SEMICOLON);
+ endMapping(dnode);
+ }
+ else if (dnode.getNodeID() == ASTNodeID.FunctionID)
+ {
+ if (!((IFunctionNode) dnode).isConstructor())
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ getEmitter().emitMethod((IFunctionNode) dnode);
+ write(ASEmitterTokens.SEMICOLON);
+ }
+ }
+ else if (dnode.getNodeID() == ASTNodeID.GetterID
+ || dnode.getNodeID() == ASTNodeID.SetterID)
+ {
+ //writeNewline();
+ //writeNewline();
+ //writeNewline();
+ fjs.emitAccessors((IAccessorNode) dnode);
+ //this shouldn't write anything, just set up
+ //a data structure for emitASGettersAndSetters
+ //write(ASEmitterTokens.SEMICOLON);
+ }
+ else if (dnode.getNodeID() == ASTNodeID.BindableVariableID)
+ {
+ writeNewline();
+ writeNewline();
+ writeNewline();
+ getEmitter().emitField((IVariableNode) dnode);
+ startMapping(dnode, dnode);
+ write(ASEmitterTokens.SEMICOLON);
+ endMapping(dnode);
+ }
+ }
+
+ fjs.getBindableEmitter().emit(definition);
+ fjs.getAccessorEmitter().emit(definition);
+
+ fjs.getPackageFooterEmitter().emitClassInfo(node);
+
+ getEmitter().popSourceMapName();
+ getModel().popClass();
+ }
+
+ public void emitComplexInitializers(IClassNode node)
+ {
+ boolean wroteOne = false;
+ IDefinitionNode[] dnodes = node.getAllMemberNodes();
+ for (IDefinitionNode dnode : dnodes)
+ {
+ if (dnode.getNodeID() == ASTNodeID.VariableID)
+ {
+ IVariableNode varnode = ((IVariableNode)dnode);
+ IExpressionNode vnode = varnode.getAssignedValueNode();
+ if (vnode != null && (!(dnode.getDefinition().isStatic() || EmitterUtils.isScalar(vnode))))
+ {
+ writeNewline();
+ write(ASEmitterTokens.THIS);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(dnode.getName());
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ getEmitter().getWalker().walk(vnode);
+ write(ASEmitterTokens.SEMICOLON);
+ wroteOne = true;
+ }
+ }
+ }
+ if (wroteOne)
+ writeNewline();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DefinePropertyFunctionEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DefinePropertyFunctionEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DefinePropertyFunctionEmitter.java
new file mode 100644
index 0000000..f267cff
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DefinePropertyFunctionEmitter.java
@@ -0,0 +1,120 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.common.IMetaInfo;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.tree.as.SetterNode;
+import org.apache.flex.compiler.tree.as.IAccessorNode;
+import org.apache.flex.compiler.tree.as.IParameterNode;
+
+public class DefinePropertyFunctionEmitter extends JSSubEmitter implements
+ ISubEmitter<IAccessorNode>
+{
+
+ public DefinePropertyFunctionEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IAccessorNode node)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ boolean isBindableSetter = false;
+ if (node instanceof SetterNode)
+ {
+ IMetaInfo[] metaInfos = null;
+ metaInfos = node.getMetaInfos();
+ for (IMetaInfo metaInfo : metaInfos)
+ {
+ String name = metaInfo.getTagName();
+ if (name.equals("Bindable")
+ && metaInfo.getAllAttributes().length == 0)
+ {
+ isBindableSetter = true;
+ break;
+ }
+ }
+ }
+ if (isBindableSetter)
+ {
+ //write(ASEmitterTokens.FUNCTION);
+ //emitParameters(node.getParametersContainerNode());
+ write(ASEmitterTokens.SPACE);
+ writeNewline(ASEmitterTokens.BLOCK_OPEN);
+
+ write(ASEmitterTokens.VAR);
+ write(ASEmitterTokens.SPACE);
+ write("oldValue");
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.THIS);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write(node.getName());
+ //write(ASEmitterTokens.PAREN_OPEN);
+ //write(ASEmitterTokens.PAREN_CLOSE);
+ writeNewline(ASEmitterTokens.SEMICOLON);
+
+ // add change check
+ write(ASEmitterTokens.IF);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write("oldValue");
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.STRICT_EQUAL);
+ write(ASEmitterTokens.SPACE);
+ IParameterNode[] params = node.getParameterNodes();
+ write(params[0].getName());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.RETURN);
+ writeNewline(ASEmitterTokens.SEMICOLON);
+
+ write(ASEmitterTokens.THIS);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("__bindingWrappedSetter__" + node.getName());
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(params[0].getName());
+ write(ASEmitterTokens.PAREN_CLOSE);
+ writeNewline(ASEmitterTokens.SEMICOLON);
+
+ // add dispatch of change event
+ writeNewline(" this.dispatchEvent(org.apache.flex.events.ValueChangeEvent.createUpdateEvent(");
+ writeNewline(" this, \"" + node.getName()
+ + "\", oldValue, " + params[0].getName() + "));");
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ //writeNewline(ASEmitterTokens.SEMICOLON);
+ writeNewline();
+ writeNewline();
+ }
+ else
+ {
+ fjs.emitMethodScope(node.getScopedNode());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java
new file mode 100644
index 0000000..e087bcd
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DoWhileLoopEmitter.java
@@ -0,0 +1,71 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IWhileLoopNode;
+
+public class DoWhileLoopEmitter extends JSSubEmitter implements
+ ISubEmitter<IWhileLoopNode>
+{
+ public DoWhileLoopEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IWhileLoopNode node)
+ {
+ IContainerNode cnode = (IContainerNode) node.getChild(0);
+
+ startMapping(node);
+ write(ASEmitterTokens.DO);
+ if (!EmitterUtils.isImplicit(cnode))
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+
+ IASNode statementContents = node.getStatementContentsNode();
+ getWalker().walk(statementContents);
+
+ IASNode conditionalExpressionNode = node.getConditionalExpressionNode();
+ startMapping(node, statementContents);
+ if (!EmitterUtils.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);
+ endMapping(node);
+
+ getWalker().walk(conditionalExpressionNode);
+
+ startMapping(node, conditionalExpressionNode);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ write(ASEmitterTokens.SEMICOLON);
+ endMapping(node);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java
new file mode 100644
index 0000000..f02d298
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/DynamicAccessEmitter.java
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IDynamicAccessNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+
+public class DynamicAccessEmitter extends JSSubEmitter implements
+ ISubEmitter<IDynamicAccessNode>
+{
+ public DynamicAccessEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IDynamicAccessNode node)
+ {
+ IExpressionNode leftOperandNode = node.getLeftOperandNode();
+ getWalker().walk(leftOperandNode);
+
+ startMapping(node, leftOperandNode);
+ write(ASEmitterTokens.SQUARE_OPEN);
+ endMapping(node);
+
+ IExpressionNode rightOperandNode = node.getRightOperandNode();
+ getWalker().walk(rightOperandNode);
+
+ startMapping(node, rightOperandNode);
+ write(ASEmitterTokens.SQUARE_CLOSE);
+ endMapping(node);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
new file mode 100644
index 0000000..402751f
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
@@ -0,0 +1,131 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.codegen.js.goog.IJSGoogDocEmitter;
+import org.apache.flex.compiler.common.ASModifier;
+import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IVariableDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+
+public class FieldEmitter extends JSSubEmitter implements
+ ISubEmitter<IVariableNode>
+{
+ public FieldEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IVariableNode node)
+ {
+ IDefinition definition = EmitterUtils.getClassDefinition(node);
+
+ IDefinition def = null;
+ IExpressionNode enode = node.getVariableTypeNode();//getAssignedValueNode();
+ if (enode != null)
+ {
+ def = enode.resolveType(getProject());
+ }
+
+ // TODO (mschmalle)
+ if (getEmitter().getDocEmitter() instanceof IJSGoogDocEmitter)
+ {
+ ((IJSGoogDocEmitter) getEmitter().getDocEmitter()).emitFieldDoc(node, def, getProject());
+ }
+
+ IDefinition ndef = node.getDefinition();
+
+ String root = "";
+ IVariableDefinition.VariableClassification classification = node.getVariableClassification();
+ boolean isPackageOrFileMember = classification == IVariableDefinition.VariableClassification.PACKAGE_MEMBER ||
+ classification == IVariableDefinition.VariableClassification.FILE_MEMBER;
+ if (isPackageOrFileMember)
+ {
+ write(getEmitter().formatQualifiedName(node.getQualifiedName()));
+ }
+ else
+ {
+ ModifiersSet modifierSet = ndef.getModifiers();
+ if (modifierSet != null && !modifierSet.hasModifier(ASModifier.STATIC))
+ {
+ root = JSEmitterTokens.PROTOTYPE.getToken();
+ root += ASEmitterTokens.MEMBER_ACCESS.getToken();
+ }
+
+ if (definition == null)
+ definition = ndef.getContainingScope().getDefinition();
+
+ startMapping(node.getNameExpressionNode());
+ write(getEmitter().formatQualifiedName(definition.getQualifiedName())
+ + ASEmitterTokens.MEMBER_ACCESS.getToken() + root);
+ write(node.getName());
+ endMapping(node.getNameExpressionNode());
+ }
+
+ if (node.getNodeID() == ASTNodeID.BindableVariableID)
+ {
+ // add an underscore to convert this var to be the
+ // backing var for the get/set pair that will be generated later.
+ write("_");
+ }
+ IExpressionNode vnode = node.getAssignedValueNode();
+ if (vnode != null &&
+ (ndef.isStatic() || EmitterUtils.isScalar(vnode) || isPackageOrFileMember))
+ {
+ startMapping(node);
+ write(ASEmitterTokens.SPACE);
+ writeToken(ASEmitterTokens.EQUAL);
+ endMapping(node);
+ getEmitter().getWalker().walk(vnode);
+ }
+
+ if (!(node instanceof ChainedVariableNode))
+ {
+ int len = node.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ IASNode child = node.getChild(i);
+ if (child instanceof ChainedVariableNode)
+ {
+ writeNewline(ASEmitterTokens.SEMICOLON);
+ writeNewline();
+ getEmitter().emitField((IVariableNode) child);
+ }
+ }
+ }
+ if (node.getNodeID() == ASTNodeID.BindableVariableID)
+ {
+ getModel().getBindableVars().add(node.getName());
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
new file mode 100644
index 0000000..501f5ae
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForEachEmitter.java
@@ -0,0 +1,157 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.tree.as.IdentifierNode;
+import org.apache.flex.compiler.internal.tree.as.LabeledStatementNode;
+import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
+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.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IVariableExpressionNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
+
+public class ForEachEmitter extends JSSubEmitter implements
+ ISubEmitter<IForLoopNode>
+{
+
+ public ForEachEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IForLoopNode node)
+ {
+ IBinaryOperatorNode bnode = (IBinaryOperatorNode) node
+ .getConditionalsContainerNode().getChild(0);
+ IASNode childNode = bnode.getChild(0);
+
+ final String iterName = getModel().getCurrentForeachName();
+ getModel().incForeachLoopCount();
+ final String targetName = iterName + "_target";
+
+ write(ASEmitterTokens.VAR);
+ write(ASEmitterTokens.SPACE);
+ write(targetName);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.SPACE);
+ IASNode obj = bnode.getChild(1);
+ getWalker().walk(obj);
+ write(ASEmitterTokens.SEMICOLON);
+ writeNewline();
+
+ if (node.getParent().getNodeID() == ASTNodeID.BlockID &&
+ node.getParent().getParent().getNodeID() == ASTNodeID.LabledStatementID)
+ {
+ // emit label here
+ LabeledStatementNode labelNode = (LabeledStatementNode)node.getParent().getParent();
+ writeToken(labelNode.getLabel());
+ writeToken(ASEmitterTokens.COLON);
+
+ }
+ write(ASEmitterTokens.FOR);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.PAREN_OPEN);
+ write(ASEmitterTokens.VAR);
+ write(ASEmitterTokens.SPACE);
+ write(iterName);
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.IN);
+ write(ASEmitterTokens.SPACE);
+ write(targetName);
+ boolean isXML = false;
+ boolean isProxy = false;
+ if (obj.getNodeID() == ASTNodeID.IdentifierID)
+ {
+ if (((JSFlexJSEmitter)getEmitter()).isXML((IdentifierNode)obj))
+ {
+ write(".elementNames()");
+ isXML = true;
+ }
+ if (((JSFlexJSEmitter)getEmitter()).isProxy((IdentifierNode)obj))
+ {
+ write(".propertyNames()");
+ isProxy = true;
+ }
+ }
+ else if (obj.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+ {
+ if (((JSFlexJSEmitter)getEmitter()).isXMLList((MemberAccessExpressionNode)obj))
+ {
+ write(".elementNames()");
+ isXML = true;
+ }
+ if (((JSFlexJSEmitter)getEmitter()).isProxy((MemberAccessExpressionNode)obj))
+ {
+ write(".propertyNames()");
+ isXML = true;
+ }
+ }
+ writeToken(ASEmitterTokens.PAREN_CLOSE);
+ writeNewline();
+ write(ASEmitterTokens.BLOCK_OPEN);
+ writeNewline();
+ if (childNode instanceof IVariableExpressionNode)
+ {
+ write(ASEmitterTokens.VAR);
+ write(ASEmitterTokens.SPACE);
+ write(((IVariableNode) childNode.getChild(0)).getName());
+ }
+ else
+ write(((IIdentifierNode) childNode).getName());
+ write(ASEmitterTokens.SPACE);
+ write(ASEmitterTokens.EQUAL);
+ write(ASEmitterTokens.SPACE);
+ write(targetName);
+ if (isXML)
+ {
+ write(".child(");
+ write(iterName);
+ write(")");
+ }
+ else if (isProxy)
+ {
+ write(".getProperty(");
+ write(iterName);
+ write(")");
+ }
+ else
+ {
+ write(ASEmitterTokens.SQUARE_OPEN);
+ write(iterName);
+ write(ASEmitterTokens.SQUARE_CLOSE);
+ }
+ write(ASEmitterTokens.SEMICOLON);
+ writeNewline();
+ getWalker().walk(node.getStatementContentsNode());
+ write(ASEmitterTokens.BLOCK_CLOSE);
+ writeNewline();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java
new file mode 100644
index 0000000..567b029
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ForLoopEmitter.java
@@ -0,0 +1,99 @@
+package org.apache.flex.compiler.internal.codegen.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+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.IForLoopNode;
+
+public class ForLoopEmitter extends JSSubEmitter implements
+ ISubEmitter<IForLoopNode>
+{
+ public ForLoopEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IForLoopNode node)
+ {
+ IContainerNode xnode = (IContainerNode) node.getChild(1);
+
+ startMapping(node);
+ writeToken(ASEmitterTokens.FOR);
+ write(ASEmitterTokens.PAREN_OPEN);
+ endMapping(node);
+
+ IContainerNode cnode = node.getConditionalsContainerNode();
+ final IASNode node0 = cnode.getChild(0);
+ if (node0.getNodeID() == ASTNodeID.Op_InID)
+ {
+ //for(in)
+ getWalker().walk(cnode.getChild(0));
+ }
+ else //for(;;)
+ {
+ emitForStatements(cnode);
+ }
+
+ startMapping(node, cnode);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ if (!EmitterUtils.isImplicit(xnode))
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+
+ getWalker().walk(node.getStatementContentsNode());
+ }
+
+ protected void emitForStatements(IContainerNode node)
+ {
+ final IASNode node0 = node.getChild(0);
+ final IASNode node1 = node.getChild(1);
+ final IASNode node2 = node.getChild(2);
+
+ int column = node.getColumn();
+ // initializer
+ if (node0 != null)
+ {
+ getWalker().walk(node0);
+
+ if (node1.getNodeID() != ASTNodeID.NilID)
+ {
+ column += node0.getAbsoluteEnd() - node0.getAbsoluteStart();
+ }
+ startMapping(node, node.getLine(), column);
+ write(ASEmitterTokens.SEMICOLON);
+ column++;
+ if (node1.getNodeID() != ASTNodeID.NilID)
+ {
+ write(ASEmitterTokens.SPACE);
+ column++;
+ }
+ endMapping(node);
+ }
+ // condition or target
+ if (node1 != null)
+ {
+ getWalker().walk(node1);
+
+ if (node1.getNodeID() != ASTNodeID.NilID)
+ {
+ column += node1.getAbsoluteEnd() - node1.getAbsoluteStart();
+ }
+ startMapping(node, node.getLine(), column);
+ write(ASEmitterTokens.SEMICOLON);
+ if (node2.getNodeID() != ASTNodeID.NilID)
+ write(ASEmitterTokens.SPACE);
+ endMapping(node);
+ }
+ // iterator
+ if (node2 != null)
+ {
+ getWalker().walk(node2);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java
new file mode 100644
index 0000000..f875e92
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallArgumentsEmitter.java
@@ -0,0 +1,64 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+
+public class FunctionCallArgumentsEmitter extends JSSubEmitter implements
+ ISubEmitter<IContainerNode>
+{
+ public FunctionCallArgumentsEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IContainerNode node)
+ {
+ startMapping(node);
+ write(ASEmitterTokens.PAREN_OPEN);
+ endMapping(node);
+
+ int len = node.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ IExpressionNode argumentNode = (IExpressionNode) node.getChild(i);
+ getWalker().walk(argumentNode);
+ if (i < len - 1)
+ {
+ //we're mapping the comma to the container, but we use the
+ //parameter line/column in case the comma is not on the same
+ //line as the opening (
+ startMapping(node, argumentNode);
+ writeToken(ASEmitterTokens.COMMA);
+ endMapping(node);
+ }
+ }
+
+ startMapping(node, node.getLine(), node.getColumn() + node.getAbsoluteEnd() - node.getAbsoluteStart() - 1);
+ write(ASEmitterTokens.PAREN_CLOSE);
+ endMapping(node);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
new file mode 100644
index 0000000..043daa8
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/FunctionCallEmitter.java
@@ -0,0 +1,200 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.IASGlobalFunctionConstants;
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSessionModel;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.internal.definitions.AppliedVectorDefinition;
+import org.apache.flex.compiler.internal.definitions.ClassDefinition;
+import org.apache.flex.compiler.internal.definitions.InterfaceDefinition;
+import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.ContainerNode;
+import org.apache.flex.compiler.internal.tree.as.VectorLiteralNode;
+import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IContainerNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
+import org.apache.flex.compiler.tree.as.IFunctionCallNode;
+import org.apache.flex.compiler.utils.NativeUtils;
+
+public class FunctionCallEmitter extends JSSubEmitter implements ISubEmitter<IFunctionCallNode>
+{
+
+ public FunctionCallEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IFunctionCallNode node)
+ {
+ // TODO (mschmalle) will remove this cast as more things get abstracted
+ JSFlexJSEmitter fjs = (JSFlexJSEmitter) getEmitter();
+
+ IASNode cnode = node.getChild(0);
+
+ if (cnode.getNodeID() == ASTNodeID.MemberAccessExpressionID)
+ cnode = cnode.getChild(0);
+
+ ASTNodeID id = cnode.getNodeID();
+ if (id != ASTNodeID.SuperID)
+ {
+ IDefinition def = null;
+
+ boolean isClassCast = false;
+
+ if (node.isNewExpression())
+ {
+ if (!(node.getChild(1) instanceof VectorLiteralNode))
+ {
+ startMapping(node.getNewKeywordNode());
+ writeToken(ASEmitterTokens.NEW);
+ endMapping(node.getNewKeywordNode());
+ }
+ else
+ {
+ VectorLiteralNode vectorLiteralNode = (VectorLiteralNode) node.getChild(1);
+ write("[");
+ ContainerNode contentsNode = vectorLiteralNode.getContentsNode();
+ int len = contentsNode.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ getWalker().walk(contentsNode.getChild(i));
+ if (i < len - 1)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ }
+ }
+ write("]");
+ return;
+ }
+ }
+ else
+ {
+ def = node.getNameNode().resolve(getProject());
+
+ isClassCast = (def instanceof ClassDefinition || def instanceof InterfaceDefinition)
+ && !(NativeUtils.isJSNative(def.getBaseName()));
+ }
+
+ if (node.isNewExpression())
+ {
+ def = node.resolveCalledExpression(getProject());
+ IExpressionNode nameNode = node.getNameNode();
+ // all new calls to a class should be fully qualified names
+ if (def instanceof ClassDefinition)
+ {
+ startMapping(nameNode);
+ write(getEmitter().formatQualifiedName(def.getQualifiedName()));
+ endMapping(nameNode);
+ }
+ else
+ {
+ // wrap "new someFunctionCall(args)" in parens so the
+ // function call gets parsed and evaluated before new
+ // otherwise it just looks like any other "new function"
+ // in JS.
+ if (nameNode.hasParenthesis())
+ write(ASEmitterTokens.PAREN_OPEN);
+ // I think we still need this for "new someVarOfTypeClass"
+ getEmitter().getWalker().walk(nameNode);
+ if (nameNode.hasParenthesis())
+ write(ASEmitterTokens.PAREN_CLOSE);
+ }
+
+ getEmitter().emitArguments(node.getArgumentsNode());
+ }
+ else if (!isClassCast)
+ {
+ if (def != null)
+ {
+ boolean isInt = def.getBaseName().equals(IASGlobalFunctionConstants._int);
+ if (isInt || def.getBaseName().equals(IASGlobalFunctionConstants.trace)
+ || def.getBaseName().equals(IASGlobalFunctionConstants.uint))
+ {
+ ICompilerProject project = this.getProject();
+ if (project instanceof FlexJSProject)
+ ((FlexJSProject) project).needLanguage = true;
+ startMapping(node.getNameNode());
+ write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ if (isInt)
+ write(JSFlexJSEmitterTokens.UNDERSCORE);
+ endMapping(node.getNameNode());
+ }
+ else if (def != null && def.getBaseName().equals("sortOn"))
+ {
+ if (def.getParent() != null &&
+ def.getParent().getQualifiedName().equals("Array"))
+ {
+ ICompilerProject project = this.getProject();
+ if (project instanceof FlexJSProject)
+ ((FlexJSProject) project).needLanguage = true;
+ write(JSFlexJSEmitterTokens.LANGUAGE_QNAME);
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ write("sortOn");
+ IContainerNode newArgs = EmitterUtils.insertArgumentsBefore(node.getArgumentsNode(), cnode);
+ fjs.emitArguments(newArgs);
+ return;
+ }
+ }
+
+ else if (def instanceof AppliedVectorDefinition)
+ {
+ IExpressionNode[] argumentNodes = node.getArgumentNodes();
+ int len = argumentNodes.length;
+ for (int i = 0; i < len; i++)
+ {
+ IExpressionNode argumentNode = argumentNodes[i];
+ getWalker().walk(argumentNode);
+ if(i < len - 1)
+ {
+ write(", ");
+ }
+ }
+ write(".slice()");
+ return;
+ }
+ }
+ getWalker().walk(node.getNameNode());
+
+ getEmitter().emitArguments(node.getArgumentsNode());
+ }
+ else //function-style cast
+ {
+ fjs.emitIsAs(node, node.getArgumentNodes()[0], node.getNameNode(), ASTNodeID.Op_AsID, true);
+ }
+ }
+ else
+ {
+ fjs.emitSuperCall(node, JSSessionModel.SUPER_FUNCTION_CALL);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c3dce49f/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
new file mode 100644
index 0000000..0d91fcf
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java
@@ -0,0 +1,257 @@
+/*
+ *
+ * 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.js.jx;
+
+import org.apache.flex.compiler.codegen.ISubEmitter;
+import org.apache.flex.compiler.codegen.js.IJSEmitter;
+import org.apache.flex.compiler.definitions.IDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition;
+import org.apache.flex.compiler.definitions.IFunctionDefinition.FunctionClassification;
+import org.apache.flex.compiler.definitions.IVariableDefinition;
+import org.apache.flex.compiler.definitions.IVariableDefinition.VariableClassification;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
+import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
+import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
+import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
+import org.apache.flex.compiler.internal.definitions.TypeDefinitionBase;
+import org.apache.flex.compiler.internal.tree.as.NonResolvingIdentifierNode;
+import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
+import org.apache.flex.compiler.tree.as.IIdentifierNode;
+import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.flex.compiler.utils.NativeUtils;
+
+public class IdentifierEmitter extends JSSubEmitter implements
+ ISubEmitter<IIdentifierNode>
+{
+
+ public IdentifierEmitter(IJSEmitter emitter)
+ {
+ super(emitter);
+ }
+
+ @Override
+ public void emit(IIdentifierNode node)
+ {
+ if (node instanceof NonResolvingIdentifierNode)
+ {
+ startMapping(node);
+ write(node.getName());
+ endMapping(node);
+ return;
+ }
+ IDefinition nodeDef = ((IIdentifierNode) node).resolve(getProject());
+
+ IASNode parentNode = node.getParent();
+ ASTNodeID parentNodeId = parentNode.getNodeID();
+
+ boolean identifierIsAccessorFunction = nodeDef instanceof AccessorDefinition;
+ boolean identifierIsPlainFunction = nodeDef instanceof FunctionDefinition
+ && !identifierIsAccessorFunction;
+ boolean emitName = true;
+
+ if (nodeDef != null && nodeDef.isStatic())
+ {
+ String sname = nodeDef.getParent().getQualifiedName();
+ if (sname.equals("Array"))
+ {
+ String baseName = nodeDef.getBaseName();
+ if (baseName.equals("CASEINSENSITIVE"))
+ {
+ write("1");
+ return;
+ }
+ else if (baseName.equals("DESCENDING"))
+ {
+ write("2");
+ return;
+ }
+ else if (baseName.equals("UNIQUESORT"))
+ {
+ write("4");
+ return;
+ }
+ else if (baseName.equals("RETURNINDEXEDARRAY"))
+ {
+ write("8");
+ return;
+ }
+ else if (baseName.equals("NUMERIC"))
+ {
+ write("16");
+ return;
+ }
+ }
+ else if (sname.equals("int"))
+ {
+ String baseName = nodeDef.getBaseName();
+ if (baseName.equals("MAX_VALUE"))
+ {
+ write("2147483648");
+ return;
+ }
+ else if (baseName.equals("MIN_VALUE"))
+ {
+ write("-2147483648");
+ return;
+ }
+ }
+ else if (sname.equals("uint"))
+ {
+ String baseName = nodeDef.getBaseName();
+ if (baseName.equals("MAX_VALUE"))
+ {
+ write("4294967295");
+ return;
+ }
+ else if (baseName.equals("MIN_VALUE"))
+ {
+ write("0");
+ return;
+ }
+ }
+ if (sname.length() > 0)
+ {
+ write(getEmitter().formatQualifiedName(sname));
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ }
+ }
+ else if (!NativeUtils.isNative(node.getName()))
+ {
+ boolean identifierIsLocalOrInstanceFunctionAsValue = false;
+ if (identifierIsPlainFunction)
+ {
+ FunctionClassification fc = ((FunctionDefinition)nodeDef).getFunctionClassification();
+ identifierIsLocalOrInstanceFunctionAsValue =
+ (fc == FunctionClassification.LOCAL || fc == FunctionClassification.CLASS_MEMBER) &&
+ // not a value if parent is a function call or member access expression
+ (!(parentNodeId == ASTNodeID.MemberAccessExpressionID || parentNodeId == ASTNodeID.FunctionCallID));
+
+ }
+ // an instance method as a parameter or
+ // a local function
+ boolean generateClosure = (parentNodeId == ASTNodeID.ContainerID
+ && identifierIsPlainFunction && ((FunctionDefinition) nodeDef)
+ .getFunctionClassification() == FunctionClassification.CLASS_MEMBER)
+ || identifierIsLocalOrInstanceFunctionAsValue;
+
+ if (generateClosure)
+ {
+ getEmitter().emitClosureStart();
+ }
+
+ if (EmitterUtils.writeThis(getProject(), getModel(), node))
+ {
+ IFunctionObjectNode functionObjectNode = (IFunctionObjectNode) node
+ .getParent().getAncestorOfType(
+ IFunctionObjectNode.class);
+
+ if (functionObjectNode != null)
+ write(JSGoogEmitterTokens.SELF);
+ else
+ write(ASEmitterTokens.THIS);
+
+ write(ASEmitterTokens.MEMBER_ACCESS);
+ }
+
+ if (generateClosure)
+ {
+ write(node.getName());
+
+ writeToken(ASEmitterTokens.COMMA);
+ write(ASEmitterTokens.THIS);
+ getEmitter().emitClosureEnd(node);
+ emitName = false;
+ }
+ }
+
+ //IDefinition parentDef = (nodeDef != null) ? nodeDef.getParent() : null;
+ //boolean isNative = (parentDef != null)
+ // && NativeUtils.isNative(parentDef.getBaseName());
+ if (emitName)
+ {
+ if (nodeDef != null)
+ {
+ // this can be optimized but this way lets
+ // us breakpoint on the node.getName() to make
+ // sure it is ok to always use the short name in an MAE
+ String qname = nodeDef.getQualifiedName();
+ boolean isPackageOrFileMember = false;
+ if (nodeDef instanceof IVariableDefinition)
+ {
+ IVariableDefinition variable = (IVariableDefinition) nodeDef;
+ VariableClassification classification = variable.getVariableClassification();
+ if (classification == VariableClassification.PACKAGE_MEMBER ||
+ classification == VariableClassification.FILE_MEMBER)
+ {
+ isPackageOrFileMember = true;
+ }
+ }
+ else if (nodeDef instanceof IFunctionDefinition)
+ {
+ IFunctionDefinition func = (IFunctionDefinition) nodeDef;
+ FunctionClassification classification = func.getFunctionClassification();
+ if (classification == FunctionClassification.PACKAGE_MEMBER ||
+ classification == FunctionClassification.FILE_MEMBER)
+ {
+ isPackageOrFileMember = true;
+ }
+ }
+ boolean needsFormattedName = false;
+ if (isPackageOrFileMember && parentNodeId == ASTNodeID.MemberAccessExpressionID)
+ {
+ IMemberAccessExpressionNode parentMemberAccessNode = (IMemberAccessExpressionNode) parentNode;
+ //if the package or file member isn't on the left side of a
+ //member access expression, it shouldn't be fully qualified
+ needsFormattedName = parentMemberAccessNode.getLeftOperandNode() == node;
+ }
+ startMapping(node);
+ if (parentNodeId == ASTNodeID.MemberAccessExpressionID)
+ {
+ if (needsFormattedName)
+ {
+ write(getEmitter().formatQualifiedName(qname));
+ }
+ else
+ {
+ write(node.getName());
+ }
+ }
+ else if (isPackageOrFileMember)
+ write(getEmitter().formatQualifiedName(qname));
+ else if (nodeDef instanceof TypeDefinitionBase)
+ write(getEmitter().formatQualifiedName(qname));
+ else
+ write(qname);
+ endMapping(node);
+ }
+ else
+ {
+ startMapping(node);
+ write(node.getName());
+ endMapping(node);
+ }
+ }
+ }
+
+}