Added emission of 'org.apache.flex.utils.Language' methods and supporting code.
Supported methods are 'as', 'int', 'is', 'trace' (partial) and 'uint'. In order for 'is' to work, all classes implementing, and all interfaces extending, interfaces get a (static) constant added to their 'footer': an Array of references to the implemented/extended interfaces. Signed-off-by: Erik de Bruin <e...@ixsoftware.nl> Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/cf2db503 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/cf2db503 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/cf2db503 Branch: refs/heads/develop Commit: cf2db503453627b84979955a6ddfaa86786923a2 Parents: d3c0cd3 Author: Erik de Bruin <e...@ixsoftware.nl> Authored: Fri Nov 1 09:43:54 2013 +0100 Committer: Erik de Bruin <e...@ixsoftware.nl> Committed: Fri Nov 1 12:32:58 2013 +0100 ---------------------------------------------------------------------- .../codegen/js/flexjs/JSFlexJSEmitter.java | 100 ++++++++++++++++++- .../js/flexjs/JSFlexJSEmitterTokens.java | 43 ++++++++ 2 files changed, 141 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cf2db503/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java index b32103c..4110e79 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import org.apache.flex.compiler.codegen.IASGlobalFunctionConstants; import org.apache.flex.compiler.codegen.IDocEmitter; import org.apache.flex.compiler.codegen.js.flexjs.IJSFlexJSEmitter; import org.apache.flex.compiler.common.ASModifier; @@ -33,6 +34,7 @@ import org.apache.flex.compiler.common.ModifiersSet; import org.apache.flex.compiler.definitions.IDefinition; import org.apache.flex.compiler.definitions.IFunctionDefinition; import org.apache.flex.compiler.definitions.IFunctionDefinition.FunctionClassification; +import org.apache.flex.compiler.definitions.IInterfaceDefinition; import org.apache.flex.compiler.definitions.INamespaceDefinition; import org.apache.flex.compiler.definitions.IPackageDefinition; import org.apache.flex.compiler.definitions.ITypeDefinition; @@ -57,6 +59,7 @@ import org.apache.flex.compiler.internal.tree.as.FunctionNode; import org.apache.flex.compiler.internal.tree.as.ParameterNode; import org.apache.flex.compiler.internal.tree.as.RegExpLiteralNode; import org.apache.flex.compiler.projects.ICompilerProject; +import org.apache.flex.compiler.scopes.IASScope; import org.apache.flex.compiler.tree.ASTNodeID; import org.apache.flex.compiler.tree.as.IASNode; import org.apache.flex.compiler.tree.as.IAccessorNode; @@ -69,10 +72,12 @@ 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.IInterfaceNode; 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.ISetterNode; +import org.apache.flex.compiler.tree.as.ITypeNode; import org.apache.flex.compiler.tree.as.ITypedExpressionNode; import org.apache.flex.compiler.tree.as.IVariableExpressionNode; import org.apache.flex.compiler.tree.as.IVariableNode; @@ -278,6 +283,14 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter } else if (!isClassCast) { + if (def != null && + (def.getBaseName().equals(IASGlobalFunctionConstants._int) || + def.getBaseName().equals(IASGlobalFunctionConstants.trace) || + def.getBaseName().equals(IASGlobalFunctionConstants.uint))) + { + write(JSFlexJSEmitterTokens.LANGUAGE_QNAME); + write(ASEmitterTokens.MEMBER_ACCESS); + } getWalker().walk(node.getNameNode()); write(ASEmitterTokens.PAREN_OPEN); walkArguments(node.getArgumentNodes()); @@ -650,13 +663,26 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter public void emitBinaryOperator(IBinaryOperatorNode node) { ASTNodeID id = node.getNodeID(); - if (id == ASTNodeID.Op_IsID - || id == ASTNodeID.Op_AsID || id == ASTNodeID.Op_InID + 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) + { + write(JSFlexJSEmitterTokens.LANGUAGE_QNAME); + write(ASEmitterTokens.MEMBER_ACCESS); + if (id == ASTNodeID.Op_AsID) + write(ASEmitterTokens.AS); + else + write(ASEmitterTokens.IS); + write(ASEmitterTokens.PAREN_OPEN); + getWalker().walk(node.getLeftOperandNode()); + writeToken(ASEmitterTokens.COMMA); + getWalker().walk(node.getRightOperandNode()); + write(ASEmitterTokens.PAREN_CLOSE); + } else { IExpressionNode leftSide = node.getLeftOperandNode(); @@ -842,6 +868,76 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter writeNewline(); } } + + // erikdebruin: Add missing language feature support, like the 'is' and + // 'as' operators. We don't need to worry about requiring + // this in every project: ADVANCED_OPTIMISATIONS will NOT + // include any of the code if it is not used in the project. + if (flexProject.mainCU != null) + { + if (!(type instanceof IInterfaceDefinition) && + cu.getName().equals(flexProject.mainCU.getName())) + { + write(JSGoogEmitterTokens.GOOG_REQUIRE); + write(ASEmitterTokens.PAREN_OPEN); + write(ASEmitterTokens.SINGLE_QUOTE); + write(JSFlexJSEmitterTokens.LANGUAGE_QNAME); + write(ASEmitterTokens.SINGLE_QUOTE); + write(ASEmitterTokens.PAREN_CLOSE); + writeNewline(ASEmitterTokens.SEMICOLON); + writeNewline(); + } + } + } + + @Override + public void emitPackageFooter(IPackageDefinition definition) + { + IASScope containedScope = definition.getContainedScope(); + ITypeDefinition type = findType(containedScope.getAllLocalDefinitions()); + if (type == null) + return; + + ITypeNode tnode = findTypeNode(definition.getNode()); + if (tnode != null) + { + IExpressionNode[] enodes; + if (tnode instanceof IClassNode) + enodes = ((IClassNode) tnode).getImplementedInterfaceNodes(); + else + enodes = ((IInterfaceNode) tnode).getExtendedInterfaceNodes(); + + if (enodes.length > 0) + { + writeNewline(); + writeNewline(); + getDoc().begin(); + getDoc().emitConst(null); + getDoc().end(); + + write(type.getQualifiedName()); + write(ASEmitterTokens.MEMBER_ACCESS); + if (tnode instanceof IClassNode) + { + write(JSEmitterTokens.PROTOTYPE); + write(ASEmitterTokens.MEMBER_ACCESS); + } + write("AFJS_INTERFACES"); + write(ASEmitterTokens.SPACE); + writeToken(ASEmitterTokens.EQUAL); + write(ASEmitterTokens.SQUARE_OPEN); + int i = 0; + for (IExpressionNode enode : enodes) + { + write(enode.resolve(project).getQualifiedName()); + if (i < enodes.length - 1) + writeToken(ASEmitterTokens.COMMA); + i++; + } + write(ASEmitterTokens.SQUARE_CLOSE); + writeNewline(ASEmitterTokens.SEMICOLON); + } + } } private int foreachLoopCounter = 0; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cf2db503/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java new file mode 100644 index 0000000..85c8d7a --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitterTokens.java @@ -0,0 +1,43 @@ +/* + * + * 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.flexjs; + +import org.apache.flex.compiler.codegen.IEmitterTokens; + +/** + * @author Erik de Bruin + */ +public enum JSFlexJSEmitterTokens implements IEmitterTokens +{ + LANGUAGE_QNAME("org.apache.flex.utils.Language"), + ; + + private String token; + + private JSFlexJSEmitterTokens(String value) + { + token = value; + } + + public String getToken() + { + return token; + } +}