Return-Path: X-Original-To: apmail-flex-commits-archive@www.apache.org Delivered-To: apmail-flex-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C799419BE8 for ; Thu, 21 Apr 2016 20:35:26 +0000 (UTC) Received: (qmail 69130 invoked by uid 500); 21 Apr 2016 20:35:26 -0000 Delivered-To: apmail-flex-commits-archive@flex.apache.org Received: (qmail 69079 invoked by uid 500); 21 Apr 2016 20:35:26 -0000 Mailing-List: contact commits-help@flex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flex.apache.org Delivered-To: mailing list commits@flex.apache.org Received: (qmail 68720 invoked by uid 99); 21 Apr 2016 20:35:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Apr 2016 20:35:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3FEE4DFDE0; Thu, 21 Apr 2016 20:35:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: joshtynjala@apache.org To: commits@flex.apache.org Date: Thu, 21 Apr 2016 20:35:26 -0000 Message-Id: <8989eebc61654803ba9b6c190312a6dc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/5] git commit: [flex-falcon] [refs/heads/develop] - look for RequireExtern metadata on external classes to see if require() is needed for an external class (such as in Node.js). in the future, if different module output types are allowed, the emitter Repository: flex-falcon Updated Branches: refs/heads/develop ce38e3e39 -> b4e4fadb7 look for RequireExtern metadata on external classes to see if require() is needed for an external class (such as in Node.js). in the future, if different module output types are allowed, the emitter may decide to output it differently than in the current CommonJS format Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/53e6204e Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/53e6204e Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/53e6204e Branch: refs/heads/develop Commit: 53e6204e466a76f458cc52ee35693eb44502da6a Parents: fb2dc7a Author: Josh Tynjala Authored: Thu Apr 21 11:05:59 2016 -0700 Committer: Josh Tynjala Committed: Thu Apr 21 11:05:59 2016 -0700 ---------------------------------------------------------------------- .../codegen/js/jx/PackageHeaderEmitter.java | 119 +++++++++++++------ .../codegen/js/node/NodeEmitterTokens.java | 21 ++++ .../internal/projects/FlexJSProject.java | 50 ++++++++ 3 files changed, 155 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/53e6204e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java index d47c6dc..6ce6328 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/PackageHeaderEmitter.java @@ -38,6 +38,7 @@ 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.goog.JSGoogEmitterTokens; +import org.apache.flex.compiler.internal.codegen.js.node.NodeEmitterTokens; import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils; import org.apache.flex.compiler.internal.projects.FlexJSProject; import org.apache.flex.compiler.internal.scopes.ASProjectScope; @@ -187,10 +188,53 @@ public class PackageHeaderEmitter extends JSSubEmitter implements .getCompilationUnitForDefinition(type != null ? type : otherMainDefinition); ArrayList requiresList = flexProject.getRequires(cu); ArrayList interfacesList = flexProject.getInterfaces(cu); + ArrayList externalRequiresList = flexProject.getExternalRequires(cu); String cname = (type != null) ? type.getQualifiedName() : otherMainDefinition.getQualifiedName(); writtenRequires.add(cname); // make sure we don't add ourselves + boolean emitsRequires = emitRequires(requiresList, writtenRequires, cname); + boolean emitsInterfaces = emitInterfaces(interfacesList, writtenRequires); + + // erikdebruin: Add missing language feature support, with e.g. '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. + boolean makingSWC = flexProject.getSWFTarget() != null && + flexProject.getSWFTarget().getTargetType() == TargetType.SWC; + boolean isMainCU = flexProject.mainCU != null + && cu.getName().equals(flexProject.mainCU.getName()); + if (isMainCU || makingSWC) + { + ICompilerProject project = this.getProject(); + if (project instanceof FlexJSProject) + { + if (((FlexJSProject)project).needLanguage) + { + 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); + } + } + } + + boolean emitsExternalRequires = emitExternalRequires(externalRequiresList, writtenRequires); + + if (emitsRequires || emitsInterfaces || emitsExternalRequires || isMainCU) + { + writeNewline(); + } + + writeNewline(); + writeNewline(); + } + + private boolean emitRequires(List requiresList, List writtenRequires, String cname) + { boolean emitsRequires = false; if (requiresList != null) { @@ -208,8 +252,8 @@ public class PackageHeaderEmitter extends JSSubEmitter implements if (NativeUtils.isNative(imp)) { - if (!(imp.equals("QName") || imp.equals("Namespace") || imp.equals("XML") || imp.equals("XMLList"))) - continue; + if (!(imp.equals("QName") || imp.equals("Namespace") || imp.equals("XML") || imp.equals("XMLList"))) + continue; } if (writtenRequires.indexOf(imp) == -1) @@ -219,7 +263,7 @@ public class PackageHeaderEmitter extends JSSubEmitter implements write(JSGoogEmitterTokens.GOOG_REQUIRE); write(ASEmitterTokens.PAREN_OPEN); write(ASEmitterTokens.SINGLE_QUOTE); - write(fjs.formatQualifiedName(imp)); + write(getEmitter().formatQualifiedName(imp)); write(ASEmitterTokens.SINGLE_QUOTE); write(ASEmitterTokens.PAREN_CLOSE); writeNewline(ASEmitterTokens.SEMICOLON); @@ -230,7 +274,11 @@ public class PackageHeaderEmitter extends JSSubEmitter implements } } } - + return emitsRequires; + } + + private boolean emitInterfaces(List interfacesList, List writtenRequires) + { boolean emitsInterfaces = false; if (interfacesList != null) { @@ -242,7 +290,7 @@ public class PackageHeaderEmitter extends JSSubEmitter implements write(JSGoogEmitterTokens.GOOG_REQUIRE); write(ASEmitterTokens.PAREN_OPEN); write(ASEmitterTokens.SINGLE_QUOTE); - write(fjs.formatQualifiedName(imp)); + write(getEmitter().formatQualifiedName(imp)); write(ASEmitterTokens.SINGLE_QUOTE); write(ASEmitterTokens.PAREN_CLOSE); writeNewline(ASEmitterTokens.SEMICOLON); @@ -251,40 +299,41 @@ public class PackageHeaderEmitter extends JSSubEmitter implements } } } - - // erikdebruin: Add missing language feature support, with e.g. '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. - boolean makingSWC = flexProject.getSWFTarget() != null && - flexProject.getSWFTarget().getTargetType() == TargetType.SWC; - boolean isMainCU = flexProject.mainCU != null - && cu.getName().equals(flexProject.mainCU.getName()); - if (isMainCU || makingSWC) + return emitsInterfaces; + } + + private boolean emitExternalRequires(List externalRequiresList, List writtenRequires) + { + boolean emitsExternalRequires = false; + if (externalRequiresList != null) { - ICompilerProject project = this.getProject(); - if (project instanceof FlexJSProject) + Collections.sort(externalRequiresList); + for (String imp : externalRequiresList) { - if (((FlexJSProject)project).needLanguage) - { - 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); - } - } - } + if (writtenRequires.indexOf(imp) == -1) + { + /* var x = require('x');\n */ + write(ASEmitterTokens.VAR); + write(ASEmitterTokens.SPACE); + write(imp); + write(ASEmitterTokens.SPACE); + write(ASEmitterTokens.EQUAL); + write(ASEmitterTokens.SPACE); + write(NodeEmitterTokens.REQUIRE); + write(ASEmitterTokens.PAREN_OPEN); + write(ASEmitterTokens.SINGLE_QUOTE); + write(imp); + write(ASEmitterTokens.SINGLE_QUOTE); + write(ASEmitterTokens.PAREN_CLOSE); + writeNewline(ASEmitterTokens.SEMICOLON); - if (emitsRequires || emitsInterfaces || isMainCU) - { - writeNewline(); - } + writtenRequires.add(imp); - writeNewline(); - writeNewline(); + emitsExternalRequires = true; + } + } + } + return emitsExternalRequires; } } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/53e6204e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/node/NodeEmitterTokens.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/node/NodeEmitterTokens.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/node/NodeEmitterTokens.java new file mode 100644 index 0000000..dddcf90 --- /dev/null +++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/node/NodeEmitterTokens.java @@ -0,0 +1,21 @@ +package org.apache.flex.compiler.internal.codegen.js.node; + +import org.apache.flex.compiler.codegen.IEmitterTokens; + +public enum NodeEmitterTokens implements IEmitterTokens +{ + REQUIRE("require"), + EXPORTS("exports"); + + private String token; + + private NodeEmitterTokens(String value) + { + token = value; + } + + public String getToken() + { + return token; + } +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/53e6204e/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java ---------------------------------------------------------------------- diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java index 67869ab..5796c91 100644 --- a/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java +++ b/compiler.jx/src/org/apache/flex/compiler/internal/projects/FlexJSProject.java @@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.projects; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -60,6 +61,7 @@ public class FlexJSProject extends FlexProject private HashMap> interfaces = new HashMap>(); private HashMap> requires = new HashMap>(); + private HashMap> externalRequires = new HashMap>(); public JSGoogConfiguration config; @@ -106,6 +108,19 @@ public class FlexJSProject extends FlexProject needXML = true; reqs.put(qname, dt); } + if (externalRequires.containsKey(from)) + { + reqs = externalRequires.get(from); + } + else + { + reqs = new HashMap(); + externalRequires.put(from, reqs); + } + if (hasRequireExternMetadata(to)) + { + reqs.put(qname, dt); + } } } else @@ -146,6 +161,27 @@ public class FlexJSProject extends FlexProject // definitions that should be considered external linkage public Collection unitTestExterns; + private boolean hasRequireExternMetadata(ICompilationUnit cu) + { + try + { + Iterator iterator = cu.getFileScopeRequest().get().getExternallyVisibleDefinitions().iterator(); + while(iterator.hasNext()) + { + IDefinition def = iterator.next(); + if (def.hasMetaTagByName("RequireExtern")) + { + return true; + } + } + } + catch (Exception ex) + { + //it's safe to ignore an exception here + } + return false; + } + private boolean isExternalLinkage(ICompilationUnit cu) { if (linkageChecker == null) @@ -220,6 +256,20 @@ public class FlexJSProject extends FlexProject return null; } + public ArrayList getExternalRequires(ICompilationUnit from) + { + if (externalRequires.containsKey(from)) + { + HashMap map = externalRequires.get(from); + ArrayList arr = new ArrayList(); + Set cus = map.keySet(); + for (String s : cus) + arr.add(s); + return arr; + } + return null; + } + JSCSSCompilationSession cssSession = new JSCSSCompilationSession(); @Override