You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/11/20 19:43:56 UTC

[royale-compiler] branch develop updated (0c89292 -> 74c6914)

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git.


    from 0c89292  compiler-jx: JSWriter uses forward slashes for relative paths because web browser devtools prefers this formatting
     new 9fd4eef  skeleton for externs-report
     new 0d6afd2  call externs report here
     new 3c577e2  externs-report seems to work
     new bb2d94b  handle --externs options by putting them in the array
     new 74c6914  Merge branch 'externsreport' into develop

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/royale/compiler/clients/MXMLJSC.java    |   1 +
 .../royale/compiler/clients/MXMLJSCRoyale.java     | 205 ++++++++++++++++++++-
 .../driver/js/goog/JSGoogConfiguration.java        |  23 +++
 .../compiler/utils/JSClosureCompilerWrapper.java   |  19 +-
 4 files changed, 244 insertions(+), 4 deletions(-)


[royale-compiler] 01/05: skeleton for externs-report

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 9fd4eef0dc62f9f84ddc5874c2ef828d6bf58a76
Author: Alex Harui <ah...@apache.org>
AuthorDate: Fri Nov 16 13:39:58 2018 -0800

    skeleton for externs-report
---
 .../apache/royale/compiler/clients/MXMLJSC.java    |  1 +
 .../driver/js/goog/JSGoogConfiguration.java        | 23 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
index 8129274..ecf26f4 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
@@ -464,6 +464,7 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
     			  arg.startsWith("-compiler.js-library-path") ||
     			  arg.startsWith("-compiler.js-define") ||
     			  arg.startsWith("-js-output") ||
+    			  arg.startsWith("-externs-report") ||
     			  arg.startsWith("-js-load-config") ||
     			  arg.startsWith("-warn-public-vars") ||
     			  arg.startsWith("-source-map")))
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
index b6c6d7b..8a08379 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/js/goog/JSGoogConfiguration.java
@@ -446,6 +446,29 @@ public class JSGoogConfiguration extends JSConfiguration
     	warnPublicVars = value;
     }
 
+    // 'externs-report' option
+    //
+
+    private String externsReportFileName = null;
+
+    public File getExternsReport()
+    {
+        return externsReportFileName != null ? new File(externsReportFileName) : null;
+    }
+
+    /**
+     * Prints externs information to the specified output file. This file is an Google Closure Compiler externs file that contains
+     * all of the public and protected APIs in the final SWF file. The file format output
+     * by this command can be used to write a file for input to the {@code -js-compiler-options="--externs <path-to-this-file>"} option.
+     */
+    @Config(advanced = true)
+    @Mapping("externs-report")
+    @Arguments("filename")
+    public void setLinkReport(ConfigurationValue cv, String filename)
+    {
+        this.externsReportFileName = getOutputPath(cv, filename);
+    }
+
     
 
 }


[royale-compiler] 04/05: handle --externs options by putting them in the array

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit bb2d94b2332c2e8846ad7c0c9b6ae1eb6d2087a0
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Nov 20 11:25:16 2018 -0800

    handle --externs options by putting them in the array
---
 .../compiler/utils/JSClosureCompilerWrapper.java      | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java
index 2207985..69ed41e 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/utils/JSClosureCompilerWrapper.java
@@ -59,6 +59,9 @@ public class JSClosureCompilerWrapper
         Compiler.setLoggingLevel(Level.INFO);
 
         compiler_ = new Compiler();
+        jsSourceFiles_ = new ArrayList<SourceFile>();
+        jsExternsFiles_ = new ArrayList<SourceFile>();
+        
         filterOptions(args);
         
         ArrayList<String> splitArgs = new ArrayList<String>();
@@ -76,9 +79,6 @@ public class JSClosureCompilerWrapper
 		splitArgs.toArray(stringArgs);
         options_ = new CompilerOptionsParser(stringArgs).getOptions();
         
-        jsSourceFiles_ = new ArrayList<SourceFile>();
-        jsExternsFiles_ = new ArrayList<SourceFile>();
-        
         initOptions(args);
         initExterns();
 
@@ -307,11 +307,13 @@ public class JSClosureCompilerWrapper
 		final String VARIABLE_MAP = "--variable_map_output_file ";
 		final String PROPERTY_INPUT_MAP = "--property_map_input_file ";
 		final String VARIABLE_INPUT_MAP = "--variable_map_input_file ";
+		final String EXTERNS = "--externs ";
 		String propEntry = null;
 		String varEntry = null;
 		String skipEntry = null;
 		String propInputEntry = null;
 		String varInputEntry = null;
+		ArrayList<String> removeArgs = new ArrayList<String>();
 
     	for (String s : args)
     	{
@@ -344,6 +346,13 @@ public class JSClosureCompilerWrapper
     			skipEntry = s;
     			skipTypeInference = true;
     		}
+    		
+    		if (s.startsWith(EXTERNS))
+    		{
+    			String fileName = s.substring(EXTERNS.length());
+    			addJSExternsFile(fileName);
+    			removeArgs.add(s);
+    		}    			
     	}
     	if (varEntry != null)
     		args.remove(varEntry);
@@ -355,6 +364,10 @@ public class JSClosureCompilerWrapper
     		args.remove(propInputEntry);
     	if (skipEntry != null)
     		args.remove(skipEntry);
+    	for (String s : removeArgs)
+    	{
+    		args.remove(s);
+    	}
     		
     }
     


[royale-compiler] 02/05: call externs report here

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 0d6afd2f951cfba47ff3bd4d439352a3dbf5244f
Author: Alex Harui <ah...@apache.org>
AuthorDate: Mon Nov 19 09:52:58 2018 -0800

    call externs report here
---
 .../org/apache/royale/compiler/clients/MXMLJSCRoyale.java    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
index 66a2989..8d0e167 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
@@ -404,6 +404,9 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
 	                        writer.close();
 	                    }
 	                }
+	                File externsReportFile = googConfiguration.getExternsReport();
+	                if (externsReportFile != null)
+	                	generateExternsReport(externsReportFile, reachableCompilationUnits, problems);
                 }
                 
                 if (!config.getCreateTargetWithErrors())
@@ -437,7 +440,14 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
         return compilationSuccess && (errs.size() == 0);
     }
 
-    private void outputResourceBundle(ResourceBundleCompilationUnit cu, File outputFolder) {
+    private void generateExternsReport(File externsReportFile,
+			List<ICompilationUnit> reachableCompilationUnits,
+			ProblemQuery problems2) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	private void outputResourceBundle(ResourceBundleCompilationUnit cu, File outputFolder) {
 		// TODO Auto-generated method stub
         final ISWCManager swcManager = project.getWorkspace().getSWCManager();
         // find the SWC


[royale-compiler] 05/05: Merge branch 'externsreport' into develop

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 74c69140cf90604882853ff831833c1917eb1bff
Merge: 0c89292 bb2d94b
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Nov 20 11:25:38 2018 -0800

    Merge branch 'externsreport' into develop

 .../apache/royale/compiler/clients/MXMLJSC.java    |   1 +
 .../royale/compiler/clients/MXMLJSCRoyale.java     | 205 ++++++++++++++++++++-
 .../driver/js/goog/JSGoogConfiguration.java        |  23 +++
 .../compiler/utils/JSClosureCompilerWrapper.java   |  19 +-
 4 files changed, 244 insertions(+), 4 deletions(-)


[royale-compiler] 03/05: externs-report seems to work

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 3c577e240b65c4f7be27b7af45a340f97e737793
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Nov 20 11:24:33 2018 -0800

    externs-report seems to work
---
 .../royale/compiler/clients/MXMLJSCRoyale.java     | 199 ++++++++++++++++++++-
 1 file changed, 196 insertions(+), 3 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
index 8d0e167..2e9686d 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -49,19 +50,31 @@ import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.ConfigurationBuffer;
 import org.apache.royale.compiler.config.Configurator;
 import org.apache.royale.compiler.config.ICompilerSettingsConstants;
+import org.apache.royale.compiler.definitions.IDefinition;
 import org.apache.royale.compiler.driver.IBackend;
 import org.apache.royale.compiler.driver.js.IJSApplication;
 import org.apache.royale.compiler.exceptions.ConfigurationException;
 import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
 import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
 import org.apache.royale.compiler.exceptions.ConfigurationException.OnlyOneSource;
+import org.apache.royale.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.royale.compiler.internal.codegen.js.goog.JSGoogDocEmitter;
+import org.apache.royale.compiler.internal.codegen.js.royale.JSRoyaleEmitter;
 import org.apache.royale.compiler.internal.config.FlashBuilderConfigurator;
+import org.apache.royale.compiler.internal.definitions.AccessorDefinition;
+import org.apache.royale.compiler.internal.definitions.ClassDefinition;
+import org.apache.royale.compiler.internal.definitions.FunctionDefinition;
+import org.apache.royale.compiler.internal.definitions.InterfaceDefinition;
+import org.apache.royale.compiler.internal.definitions.ParameterDefinition;
+import org.apache.royale.compiler.internal.definitions.ScopedDefinitionBase;
 import org.apache.royale.compiler.internal.driver.js.goog.JSGoogConfiguration;
 import org.apache.royale.compiler.internal.driver.mxml.royale.MXMLRoyaleBackend;
 import org.apache.royale.compiler.internal.parsing.as.RoyaleASDocDelegate;
 import org.apache.royale.compiler.internal.projects.CompilerProject;
 import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
 import org.apache.royale.compiler.internal.projects.ISourceFileHandler;
+import org.apache.royale.compiler.internal.scopes.ASProjectScope.DefinitionPromise;
+import org.apache.royale.compiler.internal.scopes.ASScope;
 import org.apache.royale.compiler.internal.targets.RoyaleJSTarget;
 import org.apache.royale.compiler.internal.targets.JSTarget;
 import org.apache.royale.compiler.internal.units.ResourceBundleCompilationUnit;
@@ -74,6 +87,7 @@ import org.apache.royale.compiler.problems.InternalCompilerProblem;
 import org.apache.royale.compiler.problems.UnableToBuildSWFProblem;
 import org.apache.royale.compiler.problems.UnexpectedExceptionProblem;
 import org.apache.royale.compiler.projects.ICompilerProject;
+import org.apache.royale.compiler.scopes.IDefinitionSet;
 import org.apache.royale.compiler.targets.ITarget;
 import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
@@ -442,10 +456,189 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
 
     private void generateExternsReport(File externsReportFile,
 			List<ICompilationUnit> reachableCompilationUnits,
-			ProblemQuery problems2) {
-		// TODO Auto-generated method stub
-		
+			ProblemQuery problems) {
+    	
+        System.out.println("Generating externs report: " + externsReportFile.getAbsolutePath());
+        
+    	ArrayList<String> packageNames = new ArrayList<String>();
+    	
+    	StringBuilder sb = new StringBuilder();
+        sb.append("/**\n");
+        sb.append(" * Generated by Apache Royale Compiler\n");
+        sb.append(" *\n");
+        sb.append(" * @fileoverview\n");
+        sb.append(" * @externs\n");
+        sb.append(" *\n");
+        // need to suppress access controls so access to protected/private from defineProperties
+        // doesn't generate warnings.
+        sb.append(" * @suppress {checkTypes|accessControls}\n");
+        sb.append(" */\n");
+
+    	for (ICompilationUnit cu : reachableCompilationUnits)
+    	{
+    		if (project.isExternalLinkage(cu)) continue;
+    		
+            List<IDefinition> dp = cu.getDefinitionPromises();
+
+            if (dp.size() == 0)
+                return;
+
+            IDefinition def = dp.get(0);
+            IDefinition actualDef = ((DefinitionPromise) def).getActualDefinition();
+            if (actualDef instanceof ClassDefinition)
+            {
+            	sb.append("\n\n");
+            	ClassDefinition cdef = (ClassDefinition)actualDef;
+            	String pkgName = cdef.getPackageName();
+            	if (pkgName.length() > 0 && !packageNames.contains(pkgName))
+            	{
+            		packageNames.add(pkgName);
+            		String[] parts = pkgName.split("\\.");
+            		String current = "";
+            		boolean firstOne = true;
+            		for (String part : parts)
+            		{
+            			current += part;
+        				sb.append("/** @const */\n");
+            			if (firstOne)
+            			{
+            				sb.append("var ");
+            				firstOne = false;
+            			}
+            			sb.append(current);
+            			sb.append(" = {}");
+            			sb.append(ASEmitterTokens.SEMICOLON.getToken() + "\n");
+    	                current += ".";
+            		}
+            	}
+            	sb.append("\n\n");
+            	sb.append("/**\n");
+            	sb.append(" * @constructor\n");
+            	String baseString = cdef.getBaseClassAsDisplayString();
+            	if (baseString.length() > 0)
+            		sb.append(" * @extends {" + baseString + "}\n");
+            	String[] ifaces = cdef.getImplementedInterfacesAsDisplayStrings();
+            	for (String iface : ifaces)
+            		sb.append(" * @implements {" + iface + "}\n");
+            	sb.append(" */\n");
+                sb.append("function " + cdef.getQualifiedName() + "() {}\n");
+                
+            	ASScope cscope = cdef.getContainedScope();
+            	Collection<IDefinitionSet> defSets = cscope.getAllLocalDefinitionSets();
+            	IDefinitionSet[] arrayOfDefSets = new IDefinitionSet[defSets.size()];
+            	defSets.toArray(arrayOfDefSets);
+            	for (IDefinitionSet defSet : arrayOfDefSets)
+            	{
+            		int n = defSet.getSize();
+            		for (int i = 0; i < n; i++)
+            		{
+            			IDefinition api = defSet.getDefinition(i);
+            			if (!api.isOverride() && (api.isProtected() || api.isPublic()))
+            			{
+            				if (!(api instanceof FunctionDefinition) ||
+            						api instanceof AccessorDefinition)
+            				{
+                            	sb.append("\n\n");
+                            	sb.append("/**\n");
+                            	sb.append(" * @type {" + getJSType(api.getTypeAsDisplayString()) + "}\n");
+                            	sb.append(" */\n");
+                            	sb.append(cdef.getQualifiedName() + ".");
+                            	if (!api.isStatic())
+                            		sb.append("prototype.");
+                            	sb.append(api.getBaseName() + ";\n");            					
+            				}
+            				else
+            				{
+            					FunctionDefinition method = (FunctionDefinition)api;
+            					ParameterDefinition[] params = method.getParameters();
+                            	sb.append("\n\n");
+                            	sb.append("/**\n");
+                            	for (ParameterDefinition param : params)
+                            		sb.append(" * @param {" + getJSType(param.getTypeAsDisplayString()) + "} " + param.getBaseName() + "\n");
+                            	String ret = getJSType(method.getReturnTypeAsDisplayString());
+                            	if (!ret.equals("void"))
+                            		sb.append(" * @returns {" + ret + "}\n");
+                            	sb.append(" */\n");
+                            	sb.append(cdef.getQualifiedName() + ".");
+                            	if (!api.isStatic())
+                            		sb.append("prototype.");
+                            	sb.append(api.getBaseName());
+                            	sb.append(" = function(");
+                            	int m = params.length;
+                            	for (int j = 0; j < m; j++)
+                            	{
+                            		if (j > 0)
+                            			sb.append(",");
+                            		sb.append(params[j].getBaseName());
+                            	}
+                            	sb.append(") {");
+                            	if (!ret.equals("void"))
+                            	{
+                            		if (ret.equals("number"))
+                            			sb.append(" return 0; ");
+                            		else if (ret.equals("boolean"))
+                            			sb.append(" return false; ");
+                            		else
+                            			sb.append(" return null; ");
+                            	}
+                            	sb.append("};\n");
+            				}
+            			}
+            		}
+            	}            	
+            }
+            else if (actualDef instanceof InterfaceDefinition)
+            {
+            	sb.append("\n\n");
+            	InterfaceDefinition cdef = (InterfaceDefinition)actualDef;
+            	String pkgName = cdef.getPackageName();
+            	if (pkgName.length() > 0 && !packageNames.contains(pkgName))
+            	{
+            		packageNames.add(pkgName);
+            		String[] parts = pkgName.split("\\.");
+            		String current = "";
+            		boolean firstOne = true;
+            		for (String part : parts)
+            		{
+            			current += part;
+        				sb.append("/** @const */\n");
+            			if (firstOne)
+            			{
+            				sb.append("var ");
+            				firstOne = false;
+            			}
+            			sb.append(current);
+            			sb.append(" = {}");
+            			sb.append(ASEmitterTokens.SEMICOLON.getToken() + "\n");
+    	                current += ".";
+            		}
+            	}
+            	sb.append("\n\n");
+            	sb.append("/**\n");
+            	sb.append(" * @interface\n");
+            	String[] ifaces = cdef.getExtendedInterfacesAsDisplayStrings();
+            	for (String iface : ifaces)
+            		sb.append(" * @extends {" + iface + "}\n");
+            	sb.append(" */\n");
+                sb.append("function " + cdef.getQualifiedName() + "() {}\n");
+            }
+    	}
+        System.out.println("Writing externs report: " + externsReportFile.getAbsolutePath());
+        FileWriter fw;
+		try {
+			fw = new FileWriter(externsReportFile, false);
+            fw.write(sb.toString());
+            fw.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
 	}
+    
+    private String getJSType(String s)
+    {
+    	return JSGoogDocEmitter.convertASTypeToJSType(s, "");
+    }
 
 	private void outputResourceBundle(ResourceBundleCompilationUnit cu, File outputFolder) {
 		// TODO Auto-generated method stub