Merge branch 'develop' into as2wasm
diff --git a/compiler-jx/build.xml b/compiler-jx/build.xml
index 3bfa292..320bcc4 100644
--- a/compiler-jx/build.xml
+++ b/compiler-jx/build.xml
@@ -54,6 +54,7 @@
<property name="externc.jar" value="${lib}/externc.jar" />
<property name="compc.jar" value="${lib}/compc.jar" />
<property name="jsc.jar" value="${lib}/jsc.jar" />
+ <property name="wastc.jar" value="${lib}/wastc.jar" />
<property name="asdoc.jar" value="${lib}/asdoc.jar" />
<!-- env.BUILD_NUMBER is set by Jenkins CI -->
@@ -98,6 +99,15 @@
<mkdir dir="${classes.dir}/META-INF" />
<mkdir dir="${lib}/google/closure-compiler" />
<ant antfile="${basedir}/src/main/resources/downloads.xml" dir="${basedir}/src/main/resources" inheritAll="false"/>
+ <ant dir="../compiler-test-utils">
+ <target name="clean" />
+ <target name="main" />
+ </ant>
+ <ant dir="../compiler-externc">
+ <target name="clean" />
+ <target name="main" />
+ </ant>
+ <copy file="${basedir}/../compiler-test-utils/target/classes/org/apache/royale/utils/EnvProperties.class" tofile="${classes.dir}/org/apache/royale/utils/EnvProperties.class"/>
</target>
<target name="main" depends="prebuild,compile">
@@ -107,6 +117,23 @@
<copy file="${basedir}/../LICENSE.base" tofile="${classes.dir}/META-INF/LICENSE"/>
<copy file="${basedir}/../NOTICE.base" tofile="${classes.dir}/META-INF/NOTICE"/>
+ <echo message="Building ${wastc.jar}" />
+ <copy file="${basedir}/../compiler-test-utils/target/classes/org/apache/royale/utils/EnvProperties.class" tofile="${classes.dir}/org/apache/royale/utils/EnvProperties.class"/>
+ <jar file="${wastc.jar}" basedir="${classes.dir}"
+ includes="**/*.properties,org/apache/**/*,META-INF/**/*"
+ excludes="" >
+ <include name="META-INF/LICENSE"/>
+ <include name="META-INF/NOTICE"/>
+ <manifest>
+ <attribute name="Sealed" value="${manifest.sealed}"/>
+ <attribute name="Implementation-Title" value="${manifest.Implementation-Title}"/>
+ <attribute name="Implementation-Version" value="${manifest.Implementation-Version}.${build.number}"/>
+ <attribute name="Implementation-Vendor" value="${manifest.Implementation-Vendor}"/>
+ <attribute name="Main-Class" value="org.apache.royale.compiler.clients.WASTC" />
+ <attribute name="Class-Path" value="compiler.jar" />
+ </manifest>
+ </jar>
+
<echo message="Building ${jsc.jar}" />
<jar file="${jsc.jar}" basedir="${classes.dir}"
includes="**/*.properties,org/apache/**/*,com/google/**/*,META-INF/**/*"
@@ -194,6 +221,7 @@
<include name="mxmlc.jar" />
<include name="jsc.jar" />
<include name="asdoc.jar" />
+ <include name="wastc.jar" />
</fileset>
</delete>
</target>
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java
index c4a78e9..b1795bf 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/ASDOCJSC.java
@@ -34,6 +34,7 @@
import org.apache.royale.compiler.codegen.js.royale.IJSRoyaleASDocEmitter;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -246,13 +247,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -408,7 +409,7 @@
else
return false;
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java
index 51e669e..3a79ffa 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java
@@ -42,6 +42,7 @@
import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
import org.apache.royale.compiler.codegen.as.IASWriter;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -400,13 +401,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -427,13 +428,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -612,7 +613,7 @@
else
return false;
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java
index ec69b6c..47581e7 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java
@@ -42,6 +42,7 @@
import org.apache.royale.compiler.codegen.as.IASWriter;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -265,13 +266,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -292,13 +293,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -477,7 +478,7 @@
else
return false;
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java
index 033954a..b289439 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java
@@ -42,6 +42,7 @@
import org.apache.royale.compiler.codegen.as.IASWriter;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -266,13 +267,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -293,13 +294,13 @@
IASWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = ((IJSBackend) project.getBackend()).createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = ((IJSBackend) project.getBackend()).createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
@@ -478,7 +479,7 @@
else
return false;
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
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 c09d37b..8c96d08 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
@@ -46,6 +46,7 @@
import org.apache.royale.compiler.config.Configurator;
import org.apache.royale.compiler.config.ICompilerSettingsConstants;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -509,7 +510,7 @@
return false;
}
- jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+ jsPublisher = (IJSPublisher) ((IJSBackend) project.getBackend()).createPublisher(
project, errors, config);
File outputFolder = jsPublisher.getOutputFolder();
@@ -542,12 +543,12 @@
IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = (IJSWriter) project.getBackend().createWriter(project,
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createWriter(project,
errors, unit, false);
}
else
{
- writer = (IJSWriter) project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createMXMLWriter(
project, errors, unit, false);
}
@@ -780,7 +781,7 @@
if (settings != null)
project.setTargetSettings(settings);
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
index f0f3c3a..f4fd97c 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
@@ -44,6 +44,7 @@
import org.apache.royale.compiler.config.ICompilerSettingsConstants;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -313,7 +314,7 @@
return false;
}
- jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+ jsPublisher = (IJSPublisher) ((IJSBackend) project.getBackend()).createPublisher(
project, errors, config);
File outputFolder = jsPublisher.getOutputFolder();
@@ -344,12 +345,12 @@
IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = (IJSWriter) project.getBackend().createWriter(project,
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createWriter(project,
errors, unit, false);
}
else
{
- writer = (IJSWriter) project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createMXMLWriter(
project, errors, unit, false);
}
@@ -582,7 +583,7 @@
if (settings != null)
project.setTargetSettings(settings);
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
index 463aa35..3e64fde 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
@@ -44,6 +44,7 @@
import org.apache.royale.compiler.config.ICompilerSettingsConstants;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -315,7 +316,7 @@
return false;
}
- jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+ jsPublisher = (IJSPublisher) ((IJSBackend) project.getBackend()).createPublisher(
project, errors, config);
File outputFolder = jsPublisher.getOutputFolder();
@@ -346,12 +347,12 @@
IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = (IJSWriter) project.getBackend().createWriter(project,
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createWriter(project,
errors, unit, false);
}
else
{
- writer = (IJSWriter) project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createMXMLWriter(
project, errors, unit, false);
}
@@ -584,7 +585,7 @@
if (settings != null)
project.setTargetSettings(settings);
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
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 13c8994..6dfa5a7 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
@@ -45,6 +45,7 @@
import org.apache.royale.compiler.config.ICompilerSettingsConstants;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -319,7 +320,7 @@
return false;
}
- jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+ jsPublisher = (IJSPublisher) ((IJSBackend) project.getBackend()).createPublisher(
project, errors, config);
File outputFolder = jsPublisher.getOutputFolder();
@@ -352,12 +353,12 @@
IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = (IJSWriter) project.getBackend().createWriter(project,
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createWriter(project,
errors, unit, false);
}
else
{
- writer = (IJSWriter) project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createMXMLWriter(
project, errors, unit, false);
}
@@ -590,7 +591,7 @@
if (settings != null)
project.setTargetSettings(settings);
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
index 503d75f..1d6e32a 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
@@ -44,6 +44,7 @@
import org.apache.royale.compiler.config.ICompilerSettingsConstants;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.exceptions.ConfigurationException;
import org.apache.royale.compiler.exceptions.ConfigurationException.IOError;
import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
@@ -318,7 +319,7 @@
return false;
}
- jsPublisher = (IJSPublisher) project.getBackend().createPublisher(
+ jsPublisher = (IJSPublisher) ((IJSBackend) project.getBackend()).createPublisher(
project, errors, config);
File outputFolder = jsPublisher.getOutputFolder();
@@ -349,12 +350,12 @@
IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = (IJSWriter) project.getBackend().createWriter(project,
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createWriter(project,
errors, unit, false);
}
else
{
- writer = (IJSWriter) project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) ((IJSBackend) project.getBackend()).createMXMLWriter(
project, errors, unit, false);
}
@@ -587,7 +588,7 @@
if (settings != null)
project.setTargetSettings(settings);
- target = project.getBackend().createTarget(project,
+ target = ((IJSBackend) project.getBackend()).createTarget(project,
getTargetSettings(), null);
return true;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/WASTC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/WASTC.java
new file mode 100644
index 0000000..02df03b
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/WASTC.java
@@ -0,0 +1,429 @@
+/*
+ *
+ * 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.royale.compiler.clients;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.royale.compiler.clients.problems.ProblemPrinter;
+import org.apache.royale.compiler.clients.problems.ProblemQuery;
+import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
+import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.wast.IWASTPublisher;
+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.driver.js.IJSApplication;
+import org.apache.royale.compiler.driver.wast.IWASTBackend;
+import org.apache.royale.compiler.exceptions.ConfigurationException;
+import org.apache.royale.compiler.internal.driver.wast.WASTBackend;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.compiler.internal.targets.JSTarget;
+import org.apache.royale.compiler.internal.targets.RoyaleWASTTarget;
+import org.apache.royale.compiler.internal.units.ResourceModuleCompilationUnit;
+import org.apache.royale.compiler.internal.units.SourceCompilationUnitFactory;
+import org.apache.royale.compiler.internal.workspaces.Workspace;
+import org.apache.royale.compiler.problems.ConfigurationProblem;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+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.targets.ITarget;
+import org.apache.royale.compiler.targets.ITargetSettings;
+import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+import org.apache.royale.utils.ArgumentUtil;
+import org.apache.royale.utils.FilenameNormalization;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class WASTC {
+
+ public static void main(final String[] args) {
+ long startTime = System.nanoTime();
+
+ System.out.println("WASTC");
+
+ for (String arg : args) {
+ System.out.println(arg);
+ }
+
+ WASTC wastc = new WASTC(new WASTBackend());
+
+ List<ICompilerProblem> problems = new ArrayList<ICompilerProblem>();
+
+ int exitCode = wastc.mainNoExit(args, problems);
+
+ long endTime = System.nanoTime();
+
+ System.out.println((endTime - startTime) / 1e9 + " seconds");
+
+ System.exit(exitCode);
+ }
+
+ static enum ExitCode {
+ SUCCESS(0), PRINT_HELP(1), FAILED_WITH_PROBLEMS(2), FAILED_WITH_ERRORS(3), FAILED_WITH_EXCEPTIONS(
+ 4), FAILED_WITH_CONFIG_PROBLEMS(5);
+
+ ExitCode(int code) {
+ this.code = code;
+ }
+
+ final int code;
+ }
+
+ public WASTC(IWASTBackend backend) {
+ workspace = new Workspace();
+
+ project = new RoyaleWASTProject(workspace, backend);
+
+ problems = new ProblemQuery(); // this gets replaced in configure(). Do we need it here?
+ }
+
+ private Configuration config;
+ private ICompilationUnit mainCU;
+ private ProblemQuery problems;
+ private RoyaleWASTProject project;
+ private Configurator projectConfigurator;
+ private ITarget target;
+ private Workspace workspace;
+
+ public int mainNoExit(final String[] args, List<ICompilerProblem> theProblems) {
+ int result = -1;
+
+ try {
+ ExitCode exitCode = ExitCode.SUCCESS;
+
+ try {
+ final boolean continueCompilation = configure(ArgumentUtil.fixArgs(args));
+
+ if (continueCompilation) {
+ project.setProblems(problems.getProblems());
+
+ compile();
+
+ if (problems.hasFilteredProblems()) {
+ if (problems.hasErrors())
+ exitCode = ExitCode.FAILED_WITH_ERRORS;
+ else
+ exitCode = ExitCode.FAILED_WITH_PROBLEMS;
+ }
+ } else if (problems.hasFilteredProblems()) {
+ exitCode = ExitCode.FAILED_WITH_CONFIG_PROBLEMS;
+ } else {
+ exitCode = ExitCode.PRINT_HELP;
+ }
+ } catch (Exception e) {
+ if (theProblems == null) {
+ System.err.println(e.getMessage());
+ } else {
+ final ICompilerProblem unexpectedExceptionProblem = new UnexpectedExceptionProblem(e);
+ problems.add(unexpectedExceptionProblem);
+ }
+ exitCode = ExitCode.FAILED_WITH_EXCEPTIONS;
+ } finally {
+ workspace.startIdleState();
+
+ try {
+ workspace.close();
+ } finally {
+ workspace.endIdleState(Collections.<ICompilerProject, Set<ICompilationUnit>>emptyMap());
+ }
+
+ if (theProblems != null && problems.hasFilteredProblems()) {
+ for (ICompilerProblem problem : problems.getFilteredProblems()) {
+ theProblems.add(problem);
+ }
+ }
+ }
+
+ result = exitCode.code;
+ } catch (Exception e) {
+ System.err.println(e.toString());
+ } finally {
+ if (theProblems != null && !theProblems.isEmpty()) {
+ final WorkspaceProblemFormatter formatter = new WorkspaceProblemFormatter(workspace);
+ final ProblemPrinter printer = new ProblemPrinter(formatter);
+ printer.printProblems(theProblems);
+ }
+ }
+
+ return result;
+ }
+
+ private boolean compile() {
+ boolean compilationSuccess = false;
+
+ try {
+ if (!setupTargetFile()) {
+ return false;
+ }
+
+ List<ICompilerProblem> problemsBuildingSWF = new ArrayList<ICompilerProblem>();
+
+ project.mainCU = mainCU;
+
+ IJSApplication jsTarget = null;
+
+ Collection<ICompilerProblem> fatalProblems = project.getFatalProblems();
+
+ if (!fatalProblems.isEmpty()) {
+ problemsBuildingSWF.addAll(fatalProblems);
+ } else {
+ jsTarget = ((JSTarget) target).build(mainCU, problemsBuildingSWF);
+
+ problems.addAll(problemsBuildingSWF);
+
+ if (jsTarget == null) {
+ problems.add(new UnableToBuildSWFProblem(getOutputFilePath()));
+ }
+ }
+
+ if (jsTarget != null) {
+ List<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
+ List<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>();
+
+ if (!config.getCreateTargetWithErrors()) {
+ problems.getErrorsAndWarnings(errors, warnings);
+ if (errors.size() > 0)
+ return false;
+ }
+
+ IWASTPublisher wastPublisher = project.getBackend().createPublisher(project, errors, config);
+
+ File outputFolder = wastPublisher.getOutputFolder();
+
+ ArrayList<ICompilationUnit> roots = new ArrayList<ICompilationUnit>();
+ roots.add(mainCU);
+ Set<ICompilationUnit> incs = target.getIncludesCompilationUnits();
+ roots.addAll(incs);
+ project.mixinClassNames = new TreeSet<String>();
+ project.remoteClassAliasMap = new HashMap<String, String>();
+ List<ICompilationUnit> reachableCompilationUnits = project
+ .getReachableCompilationUnitsInSWFOrder(roots);
+ ((RoyaleWASTTarget) target).collectMixinMetaData(project.mixinClassNames, reachableCompilationUnits);
+ ((RoyaleWASTTarget) target).collectRemoteClassMetaData(project.remoteClassAliasMap,
+ reachableCompilationUnits);
+ for (final ICompilationUnit cu : reachableCompilationUnits) {
+ ICompilationUnit.UnitType cuType = cu.getCompilationUnitType();
+
+ if (cuType == ICompilationUnit.UnitType.AS_UNIT || cuType == ICompilationUnit.UnitType.MXML_UNIT) {
+ final File outputClassFile = getOutputClassFile(cu.getQualifiedNames().get(0), outputFolder);
+
+ System.out.println("Compiling file: " + outputClassFile);
+
+ ICompilationUnit unit = cu;
+
+ IASWriter writer;
+ if (cuType == ICompilationUnit.UnitType.AS_UNIT) {
+ writer = (IASWriter) project.getBackend().createWriter(project, errors, unit, false);
+ } else {
+ writer = (IASWriter) project.getBackend().createMXMLWriter(project, errors, unit, false);
+ }
+
+ BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputClassFile));
+
+ writer.writeTo(out);
+ out.flush();
+ out.close();
+ writer.close();
+ }
+ }
+
+ compilationSuccess = wastPublisher.publish(problems);
+ }
+ } catch (Exception e) {
+ final ICompilerProblem problem = new InternalCompilerProblem(e);
+ problems.add(problem);
+ }
+
+ return compilationSuccess;
+ }
+
+ private String getOutputFilePath() {
+ if (config.getOutput() == null) {
+ final String extension = "." + project.getBackend().getOutputExtension();
+ return FilenameUtils.removeExtension(config.getTargetFile()).concat(extension);
+ } else
+ return config.getOutput();
+ }
+
+ private File getOutputClassFile(String qname, File outputFolder) {
+ String[] cname = qname.split("\\.");
+ String sdirPath = outputFolder + File.separator;
+ if (cname.length > 0) {
+ for (int i = 0, n = cname.length - 1; i < n; i++) {
+ sdirPath += cname[i] + File.separator;
+ }
+
+ File sdir = new File(sdirPath);
+ if (!sdir.exists())
+ sdir.mkdirs();
+
+ qname = cname[cname.length - 1];
+ }
+
+ return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension());
+ }
+
+ protected boolean setupTargetFile() throws InterruptedException {
+ final String mainFileName = config.getTargetFile();
+
+ final String normalizedMainFileName = FilenameNormalization.normalize(mainFileName);
+
+ final SourceCompilationUnitFactory compilationUnitFactory = project.getSourceCompilationUnitFactory();
+
+ File normalizedMainFile = new File(normalizedMainFileName);
+ if (compilationUnitFactory.canCreateCompilationUnit(normalizedMainFile)) {
+ project.addIncludeSourceFile(normalizedMainFile);
+
+ final List<String> sourcePath = config.getCompilerSourcePath();
+ String mainQName = null;
+ if (sourcePath != null && !sourcePath.isEmpty()) {
+ for (String path : sourcePath) {
+ final String otherPath = new File(path).getAbsolutePath();
+ if (mainFileName.startsWith(otherPath)) {
+ mainQName = mainFileName.substring(otherPath.length() + 1);
+ mainQName = mainQName.replaceAll("\\\\", "/");
+ mainQName = mainQName.replaceAll("\\/", ".");
+ if (mainQName.endsWith(".as"))
+ mainQName = mainQName.substring(0, mainQName.length() - 3);
+ break;
+ }
+ }
+ }
+
+ if (mainQName == null)
+ mainQName = FilenameUtils.getBaseName(mainFileName);
+
+ Collection<ICompilationUnit> mainFileCompilationUnits = workspace
+ .getCompilationUnits(normalizedMainFileName, project);
+
+ mainCU = Iterables.getOnlyElement(mainFileCompilationUnits);
+
+ config.setMainDefinition(mainQName);
+ }
+
+ Preconditions.checkNotNull(mainCU, "Main compilation unit can't be null");
+
+ ITargetSettings targetSettings = projectConfigurator.getTargetSettings(null);
+ if (targetSettings != null)
+ project.setTargetSettings(targetSettings);
+
+ target = project.getBackend().createTarget(project, targetSettings, null);
+
+ return true;
+ }
+
+ protected boolean configure(final String[] args) {
+ IWASTBackend backend = project.getBackend();
+
+ project.getSourceCompilationUnitFactory().addHandler(backend.getSourceFileHandlerInstance());
+
+ project.configurator = projectConfigurator = backend.createConfigurator();
+
+ try {
+ projectConfigurator.setConfiguration(args, ICompilerSettingsConstants.FILE_SPECS_VAR);
+
+ projectConfigurator.applyToProject(project);
+ project.config = (WASTConfiguration) projectConfigurator.getConfiguration();
+
+ config = projectConfigurator.getConfiguration();
+ ConfigurationBuffer configBuffer = projectConfigurator.getConfigurationBuffer();
+
+ problems = new ProblemQuery(projectConfigurator.getCompilerProblemSettings());
+ problems.addAll(projectConfigurator.getConfigurationProblems());
+
+ if (configBuffer.getVar("version") != null) //$NON-NLS-1$
+ return false;
+
+ if (problems.hasErrors())
+ return false;
+
+ validateTargetFile();
+ return true;
+ } catch (ConfigurationException e) {
+ final ICompilerProblem problem = new ConfigurationProblem(e);
+ problems.add(problem);
+ return false;
+ } catch (Exception e) {
+ final ICompilerProblem problem = new ConfigurationProblem(null, -1, -1, -1, -1, e.getMessage());
+ problems.add(problem);
+ return false;
+ } finally {
+ if (config == null) {
+ config = new Configuration();
+ }
+ }
+ }
+
+ protected void validateTargetFile() throws ConfigurationException {
+ if (mainCU instanceof ResourceModuleCompilationUnit)
+ return; // when compiling a Resource Module, no target file is defined.
+
+ final String targetFile = config.getTargetFile();
+ if (targetFile == null)
+ throw new ConfigurationException.MustSpecifyTarget(null, null, -1);
+
+ final File file = new File(targetFile);
+ if (!file.exists())
+ throw new ConfigurationException.IOError(targetFile);
+ }
+
+ public List<String> getSourceList() {
+ ArrayList<String> list = new ArrayList<String>();
+ try {
+ ArrayList<ICompilationUnit> roots = new ArrayList<ICompilationUnit>();
+ roots.add(mainCU);
+ Set<ICompilationUnit> incs = target.getIncludesCompilationUnits();
+ roots.addAll(incs);
+ project.mixinClassNames = new TreeSet<String>();
+ List<ICompilationUnit> units = project.getReachableCompilationUnitsInSWFOrder(roots);
+ for (ICompilationUnit unit : units) {
+ UnitType ut = unit.getCompilationUnitType();
+ if (ut == UnitType.AS_UNIT || ut == UnitType.MXML_UNIT) {
+ list.add(unit.getAbsoluteFilename());
+ }
+ }
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ return list;
+ }
+
+ public String getMainSource() {
+ return mainCU.getAbsoluteFilename();
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/WASTConfiguration.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/WASTConfiguration.java
new file mode 100644
index 0000000..1b1dab7
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/WASTConfiguration.java
@@ -0,0 +1,431 @@
+/*
+ *
+ * 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.royale.compiler.clients;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URLDecoder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.royale.compiler.clients.MXMLJSC.JSTargetType;
+import org.apache.royale.compiler.config.Configuration;
+import org.apache.royale.compiler.config.ConfigurationValue;
+import org.apache.royale.compiler.exceptions.ConfigurationException;
+import org.apache.royale.compiler.exceptions.ConfigurationException.CannotOpen;
+import org.apache.royale.compiler.internal.config.annotations.Arguments;
+import org.apache.royale.compiler.internal.config.annotations.Config;
+import org.apache.royale.compiler.internal.config.annotations.RoyaleOnly;
+import org.apache.royale.compiler.internal.config.annotations.InfiniteArguments;
+import org.apache.royale.compiler.internal.config.annotations.Mapping;
+import org.apache.royale.compiler.internal.mxml.MXMLNamespaceMapping;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * The {@link WASTConfiguration} class holds all compiler arguments needed for
+ * compiling ActionScript to JavaScript.
+ * <p>
+ * Specific flags are implemented here for the configuration to be loaded by the
+ * configure() method of {@link MXMLJSC}.
+ * <p>
+ * This class inherits all compiler arguments from the MXMLC compiler.
+ *
+ * @author Michael Schmalle
+ */
+public class WASTConfiguration extends JSConfiguration
+{
+ public WASTConfiguration()
+ {
+ }
+
+ //
+ // 'closure-lib'
+ //
+
+ protected String closureLib = "";
+
+ public boolean isClosureLibSet() {
+ return !closureLib.isEmpty();
+ }
+
+ public String getClosureLib()
+ {
+ try
+ {
+ if (closureLib.equals(""))
+ {
+ return getAbsolutePathFromPathRelativeToMXMLC(
+ "../../js/lib/google/closure-library");
+ }
+ }
+ catch (Exception e) { /* better to try and fail... */ }
+
+ return closureLib;
+ }
+
+ @Config
+ @Mapping("closure-lib")
+ public void setClosureLib(ConfigurationValue cv, String value)
+ throws ConfigurationException
+ {
+ if (value != null)
+ closureLib = value;
+ }
+
+ //
+ // Override 'compiler.binding-value-change-event-type'
+ //
+
+ private String bindingValueChangeEventType = "valueChange";
+
+ @Override
+ public String getBindingValueChangeEventType()
+ {
+ return bindingValueChangeEventType;
+ }
+
+ @Override
+ @Config(advanced = true)
+ public void setCompilerBindingValueChangeEventType(ConfigurationValue cv, String b)
+ {
+ bindingValueChangeEventType = b;
+ }
+
+ //
+ // Override 'compiler.mxml.children-as-data'
+ //
+
+ private Boolean childrenAsData = true;
+
+ @Override
+ public Boolean getCompilerMxmlChildrenAsData()
+ {
+ return childrenAsData;
+ }
+
+ @Override
+ @Config
+ @Mapping({"compiler", "mxml", "children-as-data"})
+ @RoyaleOnly
+ public void setCompilerMxmlChildrenAsData(ConfigurationValue cv, Boolean asData) throws ConfigurationException
+ {
+ childrenAsData = asData;
+ }
+
+ //
+ // 'marmotinni'
+ //
+
+ private String marmotinni;
+
+ public String getMarmotinni()
+ {
+ return marmotinni;
+ }
+
+ @Config
+ @Mapping("marmotinni")
+ public void setMarmotinni(ConfigurationValue cv, String value)
+ throws ConfigurationException
+ {
+ marmotinni = value;
+ }
+
+ //
+ // 'sdk-js-lib'
+ //
+
+ protected List<String> sdkJSLib = new ArrayList<String>();
+
+ public List<String> getSDKJSLib()
+ {
+ if (sdkJSLib.size() == 0)
+ {
+ try
+ {
+ String path = getAbsolutePathFromPathRelativeToMXMLC(
+ "../../frameworks/js/Royale/src");
+
+ sdkJSLib.add(path);
+ }
+ catch (Exception e) { /* better to try and fail... */ }
+ }
+
+ return sdkJSLib;
+ }
+
+ @Config(allowMultiple = true)
+ @Mapping("sdk-js-lib")
+ @Arguments(Arguments.PATH_ELEMENT)
+ @InfiniteArguments
+ public void setSDKJSLib(ConfigurationValue cv, List<String> value)
+ throws ConfigurationException
+ {
+ sdkJSLib.addAll(value);
+ }
+
+ //
+ // 'external-js-lib'
+ //
+
+ private List<String> externalJSLib = new ArrayList<String>();
+
+ public List<String> getExternalJSLib()
+ {
+ return externalJSLib;
+ }
+
+ @Config(allowMultiple = true)
+ @Mapping("external-js-lib")
+ @Arguments(Arguments.PATH_ELEMENT)
+ @InfiniteArguments
+ public void setExternalJSLib(ConfigurationValue cv, List<String> value)
+ throws ConfigurationException
+ {
+ externalJSLib.addAll(value);
+ }
+
+ //
+ // 'strict-publish'
+ //
+
+ private boolean strictPublish = true;
+
+ public boolean getStrictPublish()
+ {
+ return strictPublish;
+ }
+
+ @Config
+ @Mapping("strict-publish")
+ public void setStrictPublish(ConfigurationValue cv, boolean value)
+ throws ConfigurationException
+ {
+ strictPublish = value;
+ }
+
+ //
+ // 'keep-asdoc'
+ //
+
+ private boolean keepASDoc = true;
+
+ public boolean getKeepASDoc()
+ {
+ return keepASDoc;
+ }
+
+ @Config
+ @Mapping("keep-asdoc")
+ public void setKeepASDoc(ConfigurationValue cv, boolean value)
+ throws ConfigurationException
+ {
+ keepASDoc = value;
+ }
+
+
+
+ //
+ // 'remove-circulars'
+ //
+
+ private boolean removeCirculars = false;
+
+ public boolean getRemoveCirculars()
+ {
+ return removeCirculars;
+ }
+
+ @Config
+ @Mapping("remove-circulars")
+ public void setRemoveCirculars(ConfigurationValue cv, boolean value)
+ throws ConfigurationException
+ {
+ removeCirculars = value;
+ }
+
+
+ //
+ // 'skip-transpile'
+ //
+
+ private boolean skipTranspile = false;
+
+ public boolean getSkipTranspile()
+ {
+ return skipTranspile;
+ }
+
+ @Config
+ @Mapping("skip-transpile")
+ public void setSkipTranspile(ConfigurationValue cv, boolean value)
+ throws ConfigurationException
+ {
+ skipTranspile = value;
+ }
+
+
+
+ protected String getAbsolutePathFromPathRelativeToMXMLC(String relativePath)
+ throws IOException
+ {
+ String mxmlcURL = MXMLJSC.class.getProtectionDomain().getCodeSource()
+ .getLocation().getPath();
+
+ File mxmlc = new File(URLDecoder.decode(mxmlcURL, "utf-8"));
+
+ return new File(mxmlc.getParent() + File.separator + relativePath)
+ .getCanonicalPath();
+ }
+
+ //
+ // 'js-compiler-option'
+ //
+
+ protected List<String> jsCompilerOptions = new ArrayList<String>();
+
+ public List<String> getJSCompilerOptions()
+ {
+ return jsCompilerOptions;
+ }
+
+ @Config(allowMultiple = true)
+ @Mapping("js-compiler-option")
+ @Arguments("option")
+ @InfiniteArguments
+ public void setJSCompilerOptions(ConfigurationValue cv, List<String> value)
+ throws ConfigurationException
+ {
+ jsCompilerOptions.addAll(value);
+ }
+
+ //
+ // 'js-output-optimization'
+ //
+
+ protected List<String> jsOutputOptimizations = new ArrayList<String>();
+
+ public List<String> getJSOutputOptimizations()
+ {
+ return jsOutputOptimizations;
+ }
+
+ @Config(allowMultiple = true)
+ @Mapping("js-output-optimization")
+ @Arguments("optimization")
+ @InfiniteArguments
+ public void setJSOutputOptimizations(ConfigurationValue cv, List<String> value)
+ throws ConfigurationException
+ {
+ jsOutputOptimizations.addAll(value);
+ }
+
+ // 'html-template' option
+ //
+
+ private String htmlTemplateFileName = null;
+
+ public File getHtmlTemplate()
+ {
+ return htmlTemplateFileName != null ? new File(htmlTemplateFileName) : null;
+ }
+
+ /**
+ * Specify an HTML template with tokens to replace with application-specific values.
+ * If not specified a standard template is generated.
+ */
+ @Config(advanced = true)
+ @Mapping("html-template")
+ @Arguments("filename")
+ public void setHtmlTemplate(ConfigurationValue cv, String filename)
+ {
+ this.htmlTemplateFileName = getOutputPath(cv, filename);
+ }
+
+ // 'html-output-filename' option
+ //
+
+ private String htmlOutputFileName = "index.html";
+
+ public String getHtmlOutputFileName()
+ {
+ return htmlOutputFileName;
+ }
+
+ /**
+ * Specify the name of the HTML file that goes in the output folder. Default is index.html.
+ */
+ @Config(advanced = true)
+ @Mapping("html-output-filename")
+ @Arguments("filename")
+ public void setHtmlOutputFileName(ConfigurationValue cv, String filename)
+ {
+ this.htmlOutputFileName = filename;
+ }
+
+ //
+ // 'compiler.keep-code-with-metadata' option
+ //
+
+ private Set<String> keepCodeWithMetadata = null;
+
+ public Set<String> getCompilerKeepCodeWithMetadata()
+ {
+ return keepCodeWithMetadata == null ? Collections.<String> emptySet() : keepCodeWithMetadata;
+ }
+
+ @Config(advanced = true, allowMultiple = true)
+ @Mapping({ "compiler", "keep-code-with-metadata" })
+ @Arguments("name")
+ @InfiniteArguments
+ public void setCompilerKeepCodeWithMetadata(ConfigurationValue cv, List<String> values)
+ {
+ if (keepCodeWithMetadata == null)
+ keepCodeWithMetadata = new HashSet<String>();
+ keepCodeWithMetadata.addAll(values);
+ }
+
+ //
+ // 'export-public-symbols'
+ //
+
+ private boolean exportPublicSymbols = true;
+
+ public boolean getExportPublicSymbols()
+ {
+ return exportPublicSymbols;
+ }
+
+ @Config
+ @Mapping("export-public-symbols")
+ public void setExportPublicSymbols(ConfigurationValue cv, boolean value)
+ throws ConfigurationException
+ {
+ exportPublicSymbols = value;
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/wast/IWASTPublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/wast/IWASTPublisher.java
new file mode 100644
index 0000000..265bcd0
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/wast/IWASTPublisher.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * 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.royale.compiler.codegen.wast;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.royale.compiler.clients.problems.ProblemQuery;
+import org.apache.royale.compiler.driver.IPublisher;
+
+public interface IWASTPublisher extends IPublisher {
+
+ File getOutputFolder();
+
+ boolean publish(ProblemQuery problems) throws IOException;
+
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/driver/IBackend.java b/compiler-jx/src/main/java/org/apache/royale/compiler/driver/IBackend.java
index 8d8ee6a..d4b8ff8 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/driver/IBackend.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/driver/IBackend.java
@@ -21,27 +21,14 @@
import java.io.File;
import java.io.FilterWriter;
-import java.util.List;
import org.apache.royale.compiler.clients.MXMLJSC;
import org.apache.royale.compiler.codegen.IDocEmitter;
import org.apache.royale.compiler.codegen.as.IASEmitter;
-import org.apache.royale.compiler.codegen.as.IASWriter;
import org.apache.royale.compiler.codegen.mxml.IMXMLEmitter;
-import org.apache.royale.compiler.config.Configuration;
import org.apache.royale.compiler.config.Configurator;
-import org.apache.royale.compiler.internal.codegen.as.ASFilterWriter;
-import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
import org.apache.royale.compiler.internal.projects.ISourceFileHandler;
-import org.apache.royale.compiler.internal.targets.JSTarget;
-import org.apache.royale.compiler.problems.ICompilerProblem;
-import org.apache.royale.compiler.targets.ITarget;
-import org.apache.royale.compiler.targets.ITargetProgressMonitor;
-import org.apache.royale.compiler.targets.ITargetSettings;
import org.apache.royale.compiler.units.ICompilationUnit;
-import org.apache.royale.compiler.visitor.IBlockWalker;
-import org.apache.royale.compiler.visitor.as.IASBlockWalker;
-import org.apache.royale.compiler.visitor.mxml.IMXMLBlockWalker;
/**
* The backend strategy for the {@link MXMLJSC} javascript compiler.
@@ -69,55 +56,10 @@
*/
Configurator createConfigurator();
- /**
- * Creates a javascript target that will be used to build the compiled
- * javascript source file.
- *
- * @param project The current {@link RoyaleJSProject}.
- * @param settings The target's custom settings.
- * @param monitor The compilation monitor used during asynchronous parsing
- * of {@link ICompilationUnit}s.
- * @return A new {@link JSTarget} used during compilation.
- */
- ITarget createTarget(RoyaleJSProject project, ITargetSettings settings,
- ITargetProgressMonitor monitor);
-
IDocEmitter createDocEmitter(IASEmitter emitter);
IASEmitter createEmitter(FilterWriter writer);
IMXMLEmitter createMXMLEmitter(FilterWriter writer);
- ASFilterWriter createWriterBuffer(RoyaleJSProject project);
-
- IASWriter createWriter(RoyaleJSProject project, List<ICompilerProblem> errors,
- ICompilationUnit compilationUnit, boolean enableDebug);
-
- IASWriter createMXMLWriter(RoyaleJSProject project,
- List<ICompilerProblem> errors, ICompilationUnit compilationUnit,
- boolean enableDebug);
-
- IASBlockWalker createWalker(RoyaleJSProject project,
- List<ICompilerProblem> errors, IASEmitter emitter);
-
- IPublisher createPublisher(RoyaleJSProject project,
- List<ICompilerProblem> errors, Configuration config);
-
- /**
- * Creates an AST walker capable of traversing MXML AST and calling back to
- * the {@link IASBlockWalker} for ActionScript source code production.
- * <p>
- * Use the {@link #createWalker(RoyaleJSProject, List, ASFilterWriter)} method
- * first and pass that instance into this method's <code>walker</code>
- * parameter.
- *
- * @param project The current {@link RoyaleJSProject}.
- * @param errors The current {@link ICompilerProblem} list.
- * @param emitter The current {@link IASEmitter} that is used for it's
- * emitter and is available for callbacks to it's visit methods.
- */
- IMXMLBlockWalker createMXMLWalker(RoyaleJSProject project,
- List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter,
- IASEmitter asEmitter, IBlockWalker asBlockWalker);
-
}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/driver/js/IJSBackend.java b/compiler-jx/src/main/java/org/apache/royale/compiler/driver/js/IJSBackend.java
index 5bb93f9..5a5c42d 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/driver/js/IJSBackend.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/driver/js/IJSBackend.java
@@ -19,11 +19,75 @@
package org.apache.royale.compiler.driver.js;
+import java.util.List;
+
import org.apache.royale.compiler.codegen.ISourceMapEmitter;
+import org.apache.royale.compiler.codegen.as.IASEmitter;
+import org.apache.royale.compiler.codegen.as.IASWriter;
import org.apache.royale.compiler.codegen.js.IMappingEmitter;
+import org.apache.royale.compiler.codegen.mxml.IMXMLEmitter;
+import org.apache.royale.compiler.config.Configuration;
import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.IPublisher;
+import org.apache.royale.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
+import org.apache.royale.compiler.internal.targets.JSTarget;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.targets.ITarget;
+import org.apache.royale.compiler.targets.ITargetProgressMonitor;
+import org.apache.royale.compiler.targets.ITargetSettings;
+import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.visitor.IBlockWalker;
+import org.apache.royale.compiler.visitor.as.IASBlockWalker;
+import org.apache.royale.compiler.visitor.mxml.IMXMLBlockWalker;
public interface IJSBackend extends IBackend
{
+ /**
+ * Creates an AST walker capable of traversing MXML AST and calling back to
+ * the {@link IASBlockWalker} for ActionScript source code production.
+ * <p>
+ * Use the {@link #createWalker(RoyaleJSProject, List, ASFilterWriter)} method
+ * first and pass that instance into this method's <code>walker</code>
+ * parameter.
+ *
+ * @param project The current {@link RoyaleJSProject}.
+ * @param errors The current {@link ICompilerProblem} list.
+ * @param emitter The current {@link IASEmitter} that is used for it's
+ * emitter and is available for callbacks to it's visit methods.
+ */
+ IMXMLBlockWalker createMXMLWalker(RoyaleJSProject project,
+ List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter,
+ IASEmitter asEmitter, IBlockWalker asBlockWalker);
+
+ IASWriter createMXMLWriter(RoyaleJSProject project,
+ List<ICompilerProblem> errors, ICompilationUnit compilationUnit,
+ boolean enableDebug);
+
+ IPublisher createPublisher(RoyaleJSProject project,
+ List<ICompilerProblem> errors, Configuration config);
+
ISourceMapEmitter createSourceMapEmitter(IMappingEmitter emitter);
+
+ /**
+ * Creates a javascript target that will be used to build the compiled
+ * javascript source file.
+ *
+ * @param project The current {@link RoyaleJSProject}.
+ * @param settings The target's custom settings.
+ * @param monitor The compilation monitor used during asynchronous parsing
+ * of {@link ICompilationUnit}s.
+ * @return A new {@link JSTarget} used during compilation.
+ */
+ ITarget createTarget(RoyaleJSProject project, ITargetSettings settings,
+ ITargetProgressMonitor monitor);
+
+ IASBlockWalker createWalker(RoyaleJSProject project,
+ List<ICompilerProblem> errors, IASEmitter emitter);
+
+ IASWriter createWriter(RoyaleJSProject project, List<ICompilerProblem> errors,
+ ICompilationUnit compilationUnit, boolean enableDebug);
+
+ ASFilterWriter createWriterBuffer(RoyaleJSProject project);
+
}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/driver/wast/IWASTBackend.java b/compiler-jx/src/main/java/org/apache/royale/compiler/driver/wast/IWASTBackend.java
new file mode 100644
index 0000000..309ced8
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/driver/wast/IWASTBackend.java
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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.royale.compiler.driver.wast;
+
+import java.util.List;
+
+import org.apache.royale.compiler.codegen.as.IASEmitter;
+import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.mxml.IMXMLEmitter;
+import org.apache.royale.compiler.codegen.wast.IWASTPublisher;
+import org.apache.royale.compiler.config.Configuration;
+import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.targets.ITarget;
+import org.apache.royale.compiler.targets.ITargetProgressMonitor;
+import org.apache.royale.compiler.targets.ITargetSettings;
+import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.visitor.IBlockWalker;
+import org.apache.royale.compiler.visitor.as.IASBlockWalker;
+import org.apache.royale.compiler.visitor.mxml.IMXMLBlockWalker;
+
+public interface IWASTBackend extends IBackend {
+
+ IMXMLBlockWalker createMXMLWalker(RoyaleWASTProject project,
+ List<ICompilerProblem> errors, IMXMLEmitter mxmlEmitter,
+ IASEmitter asEmitter, IBlockWalker asBlockWalker);
+
+ IASWriter createMXMLWriter(RoyaleWASTProject project,
+ List<ICompilerProblem> errors, ICompilationUnit compilationUnit,
+ boolean enableDebug);
+
+ IWASTPublisher createPublisher(RoyaleWASTProject project,
+ List<ICompilerProblem> errors, Configuration config);
+
+ ITarget createTarget(RoyaleWASTProject project, ITargetSettings settings,
+ ITargetProgressMonitor monitor);
+
+ IASBlockWalker createWalker(RoyaleWASTProject project,
+ List<ICompilerProblem> errors, IASEmitter emitter);
+
+ IASWriter createWriter(RoyaleWASTProject project, List<ICompilerProblem> errors,
+ ICompilationUnit compilationUnit, boolean enableDebug);
+
+ ASFilterWriter createWriterBuffer(RoyaleWASTProject project);
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/as/ASWriter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/as/ASWriter.java
index 1384a9d..3ae0275 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/as/ASWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/as/ASWriter.java
@@ -27,6 +27,7 @@
import org.apache.royale.compiler.codegen.as.IASEmitter;
import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
import org.apache.royale.compiler.problems.ICompilerProblem;
import org.apache.royale.compiler.units.ICompilationUnit;
@@ -67,9 +68,9 @@
@Override
public void writeTo(OutputStream out)
{
- ASFilterWriter writer = project.getBackend().createWriterBuffer(project);
+ ASFilterWriter writer = ((IJSBackend) project.getBackend()).createWriterBuffer(project);
IASEmitter emitter = project.getBackend().createEmitter(writer);
- IASBlockWalker walker = project.getBackend().createWalker(project, problems, emitter);
+ IASBlockWalker walker = ((IJSBackend) project.getBackend()).createWalker(project, problems, emitter);
walker.visitCompilationUnit(compilationUnit);
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.java
new file mode 100644
index 0000000..46a924c
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.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.royale.compiler.internal.codegen.wast;
+
+import java.io.FilterWriter;
+
+import org.apache.royale.compiler.codegen.IEmitterTokens;
+import org.apache.royale.compiler.definitions.IFunctionDefinition;
+import org.apache.royale.compiler.definitions.IPackageDefinition;
+import org.apache.royale.compiler.internal.codegen.as.ASEmitter;
+import org.apache.royale.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.royale.compiler.internal.tree.as.FunctionNode;
+import org.apache.royale.compiler.tree.ASTNodeID;
+import org.apache.royale.compiler.tree.as.IAccessorNode;
+import org.apache.royale.compiler.tree.as.IClassNode;
+import org.apache.royale.compiler.tree.as.IFunctionNode;
+import org.apache.royale.compiler.tree.as.IGetterNode;
+import org.apache.royale.compiler.tree.as.ISetterNode;
+
+public class WASTEmitter extends ASEmitter {
+
+ public WASTEmitter(FilterWriter out)
+ {
+ super(out);
+ }
+
+ @Override
+ public void writeToken(IEmitterTokens value)
+ {
+ writeToken(value, true);
+ }
+
+ public void writeToken(IEmitterTokens value, boolean insertSpace)
+ {
+ write(value.getToken());
+ if (insertSpace) {
+ write(ASEmitterTokens.SPACE);
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ // Package
+ //--------------------------------------------------------------------------
+
+ @Override
+ public void emitPackageFooter(IPackageDefinition definition)
+ {
+ //
+ }
+
+ @Override
+ public void emitPackageHeader(IPackageDefinition definition)
+ {
+ writeToken("(module\n" +
+ " (func $add (param $lhs i32) (param $rhs i32) (result i32)\n" +
+ " get_local $lhs\n" +
+ " get_local $rhs\n" +
+ " i32.add)\n" +
+ " (export \"add\" (func $add))\n" +
+ ")");
+ }
+
+ //--------------------------------------------------------------------------
+ // Class
+ //--------------------------------------------------------------------------
+
+ @Override
+ public void emitClass(IClassNode node)
+ {
+ writeToken(ASEmitterTokens.PAREN_OPEN, false);
+ writeToken(WASTEmitterTokens.MODULE, false);
+ writeToken(ASEmitterTokens.NEW_LINE);
+ writeToken(ASEmitterTokens.NEW_LINE);
+ writeToken(ASEmitterTokens.PAREN_CLOSE, false);
+ }
+
+ //--------------------------------------------------------------------------
+ // Method
+ //--------------------------------------------------------------------------
+
+ @Override
+ public void emitMethod(IFunctionNode node)
+ {
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(getProblems());
+
+ IFunctionDefinition definition = node.getDefinition();
+
+ emitNamespaceIdentifier(node);
+ emitModifiers(definition);
+ emitMemberKeyword(node);
+
+ /*
+ // see below, this is temp, I don't want a bunch of duplicated code
+ // at them moment, subclasses can refine anyways, we are generalizing
+ if (node instanceof IGetterNode)
+ {
+ emitGetAccessorDocumentation((IGetterNode) node);
+ }
+ else if (node instanceof ISetterNode)
+ {
+ emitSetAccessorDocumentation((ISetterNode) node);
+ }
+ else
+ {
+ emitMethodDocumentation(node);
+ }
+
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(getProblems());
+
+ IFunctionDefinition definition = node.getDefinition();
+
+ emitNamespaceIdentifier(node);
+ emitModifiers(definition);
+ emitMemberKeyword(node);
+
+ // I'm cheating right here, I haven't "seen" the light
+ // on how to properly and efficiently deal with accessors since they are SO alike
+ // I don't want to lump them in with methods because implementations in the
+ // future need to know the difference without loopholes
+ if (node instanceof IAccessorNode)
+ {
+ emitAccessorKeyword(((IAccessorNode) node).getAccessorKeywordNode());
+ }
+
+ emitMemberName(node);
+ emitParameters(node.getParametersContainerNode());
+ emitType(node.getReturnTypeNode());
+ if (node.getParent().getParent().getNodeID() == ASTNodeID.ClassID)
+ {
+ emitMethodScope(node.getScopedNode());
+ }
+
+ // the client such as IASBlockWalker is responsible for the
+ // semi-colon and newline handling
+ */
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitterTokens.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitterTokens.java
new file mode 100644
index 0000000..1bb1f9c
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitterTokens.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * 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.royale.compiler.internal.codegen.wast;
+
+import org.apache.royale.compiler.codegen.IEmitterTokens;
+
+public enum WASTEmitterTokens implements IEmitterTokens
+{
+ MODULE("module");
+
+ private String token;
+
+ private WASTEmitterTokens(String value)
+ {
+ token = value;
+ }
+
+ public String getToken()
+ {
+ return token;
+ }
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTPublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTPublisher.java
new file mode 100644
index 0000000..cc77840
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTPublisher.java
@@ -0,0 +1,171 @@
+/*
+ *
+ * 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.royale.compiler.internal.codegen.wast;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.lang.ProcessBuilder.Redirect;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.royale.compiler.clients.problems.ProblemQuery;
+import org.apache.royale.compiler.codegen.wast.IWASTPublisher;
+import org.apache.royale.compiler.config.Configuration;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.utils.EnvProperties;
+
+public class WASTPublisher implements IWASTPublisher {
+
+ public WASTPublisher(RoyaleWASTProject project, Configuration config) {
+ this.configuration = config;
+ }
+
+
+
+ private Configuration configuration;
+
+ private String mainProjectFileName;
+
+ private File outputFolder;
+ private File outputParentFolder;
+
+ private EnvProperties env;
+
+
+
+ @Override
+ public File getOutputFolder() {
+ outputParentFolder = new File(configuration.getTargetFileDirectory()).getParentFile();
+
+ outputFolder = new File(outputParentFolder, "bin");
+
+ if (!outputFolder.exists()) {
+ outputFolder.mkdirs();
+ }
+
+ return outputFolder;
+ }
+
+ @Override
+ public boolean publish(ProblemQuery problems) throws IOException {
+ try {
+ String targetPath = getOutputFolder().getPath();
+
+ mainProjectFileName = configuration.getMainDefinition();
+
+ String targetWatFilePath = targetPath + "/" + mainProjectFileName + ".wat";
+
+ env = EnvProperties.initiate();
+
+ String[] cmd = { env.WAT2WASM + "/wat2wasm", targetWatFilePath, "-o", targetPath + "/" + mainProjectFileName + ".wasm" };
+
+ Process p = new ProcessBuilder(cmd).redirectError(Redirect.INHERIT)
+ .redirectOutput(Redirect.INHERIT)
+ .start();
+
+ p.waitFor();
+
+ copyGlueJS();
+
+ writeIndexHTML();
+
+ new File(targetWatFilePath).delete();
+
+ System.out.println("The project has been successfully compiled and optimized.");
+
+ return true;
+ } catch (InterruptedException e) {
+ return false;
+ }
+ }
+
+
+
+ private void copyFile(File source, File target) throws IOException
+ {
+ if (source.isDirectory()) {
+ FileUtils.copyDirectory(source, target);
+ } else {
+ FileUtils.copyFile(source, target);
+ }
+ }
+
+ private void copyGlueJS() throws IOException {
+ File flexHome = new File(WASTPublisher.class.getProtectionDomain().getCodeSource().getLocation().getPath());
+
+ String flexHomePath = flexHome.getPath();
+
+ if (!flexHomePath.substring(flexHomePath.length() - 4).equals(".jar")) {
+ flexHomePath = new File(flexHome, "../../../../royale-asjs/as2wasm/resources").getPath();
+ } else {
+ flexHomePath = new File(flexHome.getParentFile().getPath(), "../..").getPath();
+ }
+
+ System.out.println(flexHomePath);
+
+ copyFile(new File(flexHomePath, "glue.js"), new File(getOutputFolder().getPath(), "glue.js"));
+ }
+
+ private void writeFile(File target, String content) throws IOException {
+ if (!target.exists()) {
+ target.createNewFile();
+ }
+
+ FileWriter fw = new FileWriter(target, false);
+ fw.write(content);
+ fw.close();
+ }
+
+ private void writeIndexHTML() throws IOException {
+ StringBuilder htmlFile = new StringBuilder();
+
+ htmlFile.append("<!DOCTYPE html>\n");
+ htmlFile.append("\n");
+ htmlFile.append("<html>\n");
+ htmlFile.append("<head>\n");
+ htmlFile.append(" <meta charset=\"utf-8\">\n");
+ htmlFile.append(" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n");
+ htmlFile.append("\n");
+ htmlFile.append(" <title>" + mainProjectFileName + " - Royale WAST</title>\n");
+ htmlFile.append("\n");
+ htmlFile.append(" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n");
+ htmlFile.append("</head>\n");
+ htmlFile.append("<body>\n");
+ htmlFile.append("\n");
+ htmlFile.append("<div id=\"wasm-output\"></div>\n");
+ htmlFile.append("\n");
+ htmlFile.append("<script src=\"glue.js\"></script>\n");
+ htmlFile.append("\n");
+ htmlFile.append("<script>\n");
+ htmlFile.append("\n");
+ htmlFile.append(" fetchAndInstantiate('" + mainProjectFileName + ".wasm')\n");
+ htmlFile.append(" .then(function(instance) {\n");
+ htmlFile.append(" document.getElementById('wasm-output').innerHTML = 'The result from the call to the WASM method is: ' + instance.exports.add(3, 7); // 10\n");
+ htmlFile.append(" });\n");
+ htmlFile.append("\n");
+ htmlFile.append("</script>\n");
+ htmlFile.append("\n");
+ htmlFile.append("</body>\n");
+ htmlFile.append("</html>\n");
+
+ writeFile(new File(getOutputFolder().getPath(), "index.html"), htmlFile.toString());
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTWriter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTWriter.java
new file mode 100644
index 0000000..faefc1a
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTWriter.java
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.royale.compiler.internal.codegen.wast;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+import org.apache.royale.compiler.codegen.as.IASEmitter;
+import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.visitor.as.IASBlockWalker;
+
+public class WASTWriter implements IASWriter {
+
+ private RoyaleWASTProject project;
+ private List<ICompilerProblem> problems;
+ private ICompilationUnit compilationUnit;
+
+ public WASTWriter(RoyaleWASTProject project, List<ICompilerProblem> problems,
+ ICompilationUnit compilationUnit, boolean enableDebug)
+ {
+ this.project = project;
+ this.problems = problems;
+ this.compilationUnit = compilationUnit;
+ }
+
+ @Override
+ public void close() throws IOException {}
+
+ @Override
+ public void writeTo(OutputStream out) {
+ ASFilterWriter writer = project.getBackend().createWriterBuffer(project);
+ IASEmitter emitter = project.getBackend().createEmitter(writer);
+ IASBlockWalker walker = project.getBackend().createWalker(project, problems, emitter);
+
+ walker.visitCompilationUnit(compilationUnit);
+
+ System.out.println(writer.toString());
+
+ try
+ {
+ out.write(writer.toString().getBytes());
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public int writeTo(File out) throws FileNotFoundException, IOException {
+ return 0;
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/as/ASBackend.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/as/ASBackend.java
index 43c0fcd..c194f4a 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/as/ASBackend.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/as/ASBackend.java
@@ -24,13 +24,16 @@
import java.util.List;
import org.apache.royale.compiler.codegen.IDocEmitter;
+import org.apache.royale.compiler.codegen.ISourceMapEmitter;
import org.apache.royale.compiler.codegen.as.IASEmitter;
import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.js.IMappingEmitter;
import org.apache.royale.compiler.codegen.mxml.IMXMLEmitter;
import org.apache.royale.compiler.config.Configuration;
import org.apache.royale.compiler.config.Configurator;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.IPublisher;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.codegen.as.ASAfterNodeStrategy;
import org.apache.royale.compiler.internal.codegen.as.ASBeforeNodeStrategy;
import org.apache.royale.compiler.internal.codegen.as.ASBlockWalker;
@@ -58,7 +61,7 @@
*
* @author Michael Schmalle
*/
-public class ASBackend implements IBackend
+public class ASBackend implements IJSBackend
{
@Override
public String getOutputExtension()
@@ -73,6 +76,12 @@
}
@Override
+ public ISourceMapEmitter createSourceMapEmitter(IMappingEmitter emitter)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
public Configurator createConfigurator()
{
throw new UnsupportedOperationException();
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTBackend.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTBackend.java
new file mode 100644
index 0000000..1d1bc95
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTBackend.java
@@ -0,0 +1,144 @@
+/*
+ *
+ * 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.royale.compiler.internal.driver.wast;
+
+import java.io.FilterWriter;
+import java.io.StringWriter;
+import java.util.List;
+
+import org.apache.royale.compiler.clients.WASTConfiguration;
+import org.apache.royale.compiler.codegen.IDocEmitter;
+import org.apache.royale.compiler.codegen.as.IASEmitter;
+import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.mxml.IMXMLEmitter;
+import org.apache.royale.compiler.codegen.wast.IWASTPublisher;
+import org.apache.royale.compiler.config.Configuration;
+import org.apache.royale.compiler.config.Configurator;
+import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.wast.IWASTBackend;
+import org.apache.royale.compiler.internal.codegen.as.ASAfterNodeStrategy;
+import org.apache.royale.compiler.internal.codegen.as.ASBeforeNodeStrategy;
+import org.apache.royale.compiler.internal.codegen.as.ASBlockWalker;
+import org.apache.royale.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.royale.compiler.internal.codegen.wast.WASTEmitter;
+import org.apache.royale.compiler.internal.codegen.wast.WASTPublisher;
+import org.apache.royale.compiler.internal.codegen.wast.WASTWriter;
+import org.apache.royale.compiler.internal.projects.ISourceFileHandler;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.compiler.internal.targets.RoyaleWASTTarget;
+import org.apache.royale.compiler.internal.visitor.as.ASNodeSwitch;
+import org.apache.royale.compiler.internal.visitor.as.BeforeAfterStrategy;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.targets.ITarget;
+import org.apache.royale.compiler.targets.ITargetProgressMonitor;
+import org.apache.royale.compiler.targets.ITargetSettings;
+import org.apache.royale.compiler.tree.as.IFileNode;
+import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.visitor.IBlockWalker;
+import org.apache.royale.compiler.visitor.as.IASBlockWalker;
+import org.apache.royale.compiler.visitor.mxml.IMXMLBlockWalker;
+
+/**
+ * A concrete implementation of the {@link IBackend} API where the
+ * {@link ASBlockWalker} is used to traverse the {@link IFileNode} AST.
+ *
+ * @author Erik de Bruin
+ */
+public class WASTBackend implements IWASTBackend {
+
+ @Override
+ public ISourceFileHandler getSourceFileHandlerInstance() {
+ return WASTSourceFileHandler.INSTANCE;
+ }
+
+ @Override
+ public String getOutputExtension() {
+ return "wat";
+ }
+
+ @Override
+ public Configurator createConfigurator() {
+ return new Configurator(WASTConfiguration.class);
+ }
+
+ @Override
+ public ITarget createTarget(RoyaleWASTProject project, ITargetSettings settings, ITargetProgressMonitor monitor) {
+ return new RoyaleWASTTarget(project, settings, monitor);
+ }
+
+ @Override
+ public IDocEmitter createDocEmitter(IASEmitter emitter) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IASEmitter createEmitter(FilterWriter writer) {
+ return new WASTEmitter(writer);
+ }
+
+ @Override
+ public IMXMLEmitter createMXMLEmitter(FilterWriter writer) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ASFilterWriter createWriterBuffer(RoyaleWASTProject project) {
+ StringWriter out = new StringWriter();
+ ASFilterWriter writer = new ASFilterWriter(out);
+ return writer;
+ }
+
+ @Override
+ public IASWriter createWriter(RoyaleWASTProject project, List<ICompilerProblem> errors,
+ ICompilationUnit compilationUnit, boolean enableDebug) {
+ return new WASTWriter(project, errors, compilationUnit, enableDebug);
+ }
+
+ @Override
+ public IASWriter createMXMLWriter(RoyaleWASTProject project, List<ICompilerProblem> errors,
+ ICompilationUnit compilationUnit, boolean enableDebug) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IASBlockWalker createWalker(RoyaleWASTProject project, List<ICompilerProblem> errors, IASEmitter emitter) {
+ ASBlockWalker walker = new ASBlockWalker(errors, project, emitter);
+
+ BeforeAfterStrategy strategy = new BeforeAfterStrategy(
+ new ASNodeSwitch(walker), new ASBeforeNodeStrategy(emitter),
+ new ASAfterNodeStrategy(emitter));
+
+ walker.setStrategy(strategy);
+
+ return walker;
+ }
+
+ @Override
+ public IWASTPublisher createPublisher(RoyaleWASTProject project, List<ICompilerProblem> errors, Configuration config) {
+ return new WASTPublisher(project, config);
+ }
+
+ @Override
+ public IMXMLBlockWalker createMXMLWalker(RoyaleWASTProject project, List<ICompilerProblem> errors,
+ IMXMLEmitter mxmlEmitter, IASEmitter asEmitter, IBlockWalker asBlockWalker) {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTCompilationUnit.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTCompilationUnit.java
new file mode 100644
index 0000000..55422e2
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTCompilationUnit.java
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.royale.compiler.internal.driver.wast;
+
+import java.io.IOException;
+
+import org.apache.royale.compiler.common.DependencyType;
+import org.apache.royale.compiler.internal.projects.CompilerProject;
+import org.apache.royale.compiler.internal.projects.DefinitionPriority;
+import org.apache.royale.compiler.internal.units.ASCompilationUnit;
+import org.apache.royale.compiler.targets.ITarget.TargetType;
+
+public class WASTCompilationUnit extends ASCompilationUnit {
+
+ /**
+ * Create a compilation unit from an ABC file.
+ *
+ * @param project compiler project
+ * @param path ABC file path
+ * @throws IOException error
+ */
+ public WASTCompilationUnit(CompilerProject project, String path)
+ throws IOException
+ {
+ this(project, path, DefinitionPriority.BasePriority.LIBRARY_PATH);
+ }
+
+ public WASTCompilationUnit(CompilerProject project, String path,
+ DefinitionPriority.BasePriority basePriority)
+ {
+ super(project, path, basePriority);
+ }
+
+ public WASTCompilationUnit(CompilerProject project, String path,
+ DefinitionPriority.BasePriority basePriority, String qname)
+ {
+ super(project, path, basePriority, 0, qname);
+ }
+
+ public Boolean addDependency(String className, DependencyType dt)
+ {
+ return true;
+ }
+
+ @Override
+ public void startBuildAsync(TargetType targetType)
+ {
+ getSyntaxTreeRequest();
+ getFileScopeRequest();
+ getOutgoingDependenciesRequest();
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTSourceFileHandler.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTSourceFileHandler.java
new file mode 100644
index 0000000..1a1a97d
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/wast/WASTSourceFileHandler.java
@@ -0,0 +1,52 @@
+/*
+ *
+ * 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.royale.compiler.internal.driver.wast;
+
+import org.apache.royale.compiler.internal.projects.CompilerProject;
+import org.apache.royale.compiler.internal.projects.DefinitionPriority.BasePriority;
+import org.apache.royale.compiler.internal.projects.ISourceFileHandler;
+import org.apache.royale.compiler.units.ICompilationUnit;
+
+public class WASTSourceFileHandler implements ISourceFileHandler {
+
+ public static final WASTSourceFileHandler INSTANCE = new WASTSourceFileHandler();
+
+ @Override
+ public String[] getExtensions() {
+ return new String[] { "as" };
+ }
+
+ @Override
+ public boolean needCompilationUnit(CompilerProject project, String path, String qname, String locale) {
+ return true;
+ }
+
+ @Override
+ public ICompilationUnit createCompilationUnit(CompilerProject project, String path, BasePriority priority,
+ int order, String qname, String locale) {
+ return new WASTCompilationUnit(project, path, priority, qname);
+ }
+
+ @Override
+ public boolean canCreateInvisibleCompilationUnit() {
+ return false;
+ }
+
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
index fc466c9..2da8341 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
@@ -29,6 +29,7 @@
import java.util.TreeSet;
import org.apache.royale.compiler.clients.JSConfiguration;
+import org.apache.royale.compiler.clients.WASTConfiguration;
import org.apache.royale.compiler.common.DependencyType;
import org.apache.royale.compiler.config.Configuration;
import org.apache.royale.compiler.config.Configurator;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleWASTProject.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleWASTProject.java
new file mode 100644
index 0000000..93dc262
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleWASTProject.java
@@ -0,0 +1,465 @@
+/*
+ *
+ * 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.royale.compiler.internal.projects;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.royale.compiler.clients.JSConfiguration;
+import org.apache.royale.compiler.clients.WASTConfiguration;
+import org.apache.royale.compiler.common.DependencyType;
+import org.apache.royale.compiler.config.Configuration;
+import org.apache.royale.compiler.config.Configurator;
+import org.apache.royale.compiler.css.ICSSMediaQueryCondition;
+import org.apache.royale.compiler.css.ICSSRule;
+import org.apache.royale.compiler.definitions.IDefinition;
+import org.apache.royale.compiler.definitions.ITypeDefinition;
+import org.apache.royale.compiler.definitions.metadata.IMetaTag;
+import org.apache.royale.compiler.definitions.metadata.IMetaTagAttribute;
+import org.apache.royale.compiler.definitions.references.IResolvedQualifiersReference;
+import org.apache.royale.compiler.definitions.references.ReferenceFactory;
+import org.apache.royale.compiler.driver.wast.IWASTBackend;
+import org.apache.royale.compiler.internal.codegen.mxml.royale.MXMLRoyaleEmitterTokens;
+import org.apache.royale.compiler.internal.css.codegen.CSSCompilationSession;
+import org.apache.royale.compiler.internal.definitions.InterfaceDefinition;
+import org.apache.royale.compiler.internal.driver.js.royale.JSCSSCompilationSession;
+import org.apache.royale.compiler.internal.mxml.MXMLNamespaceMapping;
+import org.apache.royale.compiler.internal.scopes.ASProjectScope.DefinitionPromise;
+import org.apache.royale.compiler.internal.targets.ITargetAttributes;
+import org.apache.royale.compiler.internal.targets.LinkageChecker;
+import org.apache.royale.compiler.internal.tree.mxml.MXMLDocumentNode;
+import org.apache.royale.compiler.internal.tree.mxml.MXMLFileNode;
+import org.apache.royale.compiler.internal.units.SWCCompilationUnit;
+import org.apache.royale.compiler.internal.workspaces.Workspace;
+import org.apache.royale.compiler.targets.ITargetSettings;
+import org.apache.royale.compiler.tree.as.IASNode;
+import org.apache.royale.compiler.tree.as.IDefinitionNode;
+import org.apache.royale.compiler.units.ICompilationUnit;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * @author aharui
+ *
+ */
+public class RoyaleWASTProject extends RoyaleProject
+{
+
+ /**
+ * Constructor
+ *
+ * @param workspace The {@code Workspace} containing this project.
+ */
+ public RoyaleWASTProject(Workspace workspace, IWASTBackend backend)
+ {
+ super(workspace);
+ this.backend = backend;
+ }
+
+ private HashMap<ICompilationUnit, HashMap<String, String>> interfaces = new HashMap<ICompilationUnit, HashMap<String, String>>();
+ private HashMap<ICompilationUnit, HashMap<String, DependencyType>> requires = new HashMap<ICompilationUnit, HashMap<String, DependencyType>>();
+ private HashMap<ICompilationUnit, HashMap<String, DependencyType>> jsModules = new HashMap<ICompilationUnit, HashMap<String, DependencyType>>();
+ public TreeSet<String> mixinClassNames;
+ public HashMap<String, String> remoteClassAliasMap;
+ public WASTConfiguration config;
+ public Configurator configurator;
+
+ private IWASTBackend backend;
+
+ public ICompilationUnit mainCU;
+
+ @Override
+ public synchronized void addDependency(ICompilationUnit from, ICompilationUnit to,
+ DependencyType dt, String qname)
+ {
+ List<IDefinition> dp = to.getDefinitionPromises();
+
+ if (dp.size() == 0)
+ return;
+
+ IDefinition def = dp.get(0);
+ // IDefinition def = to.getDefinitionPromises().get(0);
+ IDefinition actualDef = ((DefinitionPromise) def).getActualDefinition();
+ boolean isInterface = (actualDef instanceof InterfaceDefinition) && (dt == DependencyType.INHERITANCE);
+ if (!isInterface)
+ {
+ if (from != to)
+ {
+ HashMap<String, DependencyType> reqs;
+ if (requires.containsKey(from))
+ reqs = requires.get(from);
+ else
+ {
+ reqs = new HashMap<String, DependencyType>();
+ requires.put(from, reqs);
+ }
+ if (reqs.containsKey(qname))
+ {
+ // inheritance is important so remember it
+ if (reqs.get(qname) != DependencyType.INHERITANCE)
+ {
+ if (!isExternalLinkage(to))
+ reqs.put(qname, dt);
+ }
+ }
+ else if (!isExternalLinkage(to) || qname.equals("Namespace"))
+ {
+ if (qname.equals("XML"))
+ needXML = true;
+ reqs.put(qname, dt);
+ }
+ if (jsModules.containsKey(from))
+ {
+ reqs = jsModules.get(from);
+ }
+ else
+ {
+ reqs = new HashMap<String, DependencyType>();
+ jsModules.put(from, reqs);
+ }
+ IMetaTag tag = getJSModuleMetadata(to);
+ if (tag != null)
+ {
+ IMetaTagAttribute nameAttribute = tag.getAttribute("name");
+ if (nameAttribute != null)
+ {
+ reqs.put(nameAttribute.getValue(), dt);
+ }
+ else
+ {
+ reqs.put(qname, dt);
+ }
+ }
+ }
+ }
+ else
+ {
+ if (from != to)
+ {
+ HashMap<String, String> interfacesArr;
+
+ if (interfaces.containsKey(from))
+ {
+ interfacesArr = interfaces.get(from);
+ }
+ else
+ {
+ interfacesArr = new HashMap<String, String>();
+ interfaces.put(from, interfacesArr);
+ }
+
+ if (!interfacesArr.containsKey(qname))
+ {
+ interfacesArr.put(qname, qname);
+ }
+ }
+ }
+
+ super.addDependency(from, to, dt, qname);
+ }
+
+ public boolean needLanguage;
+ public boolean needCSS;
+ public boolean needXML;
+
+ private LinkageChecker linkageChecker;
+ private ITargetSettings ts;
+
+ // definitions that should be considered external linkage
+ public Collection<String> unitTestExterns;
+
+ private IMetaTag getJSModuleMetadata(ICompilationUnit cu)
+ {
+ try
+ {
+ Iterator<IDefinition> iterator = cu.getFileScopeRequest().get().getExternallyVisibleDefinitions().iterator();
+ while(iterator.hasNext())
+ {
+ IDefinition def = iterator.next();
+ if (def.hasMetaTagByName("JSModule"))
+ {
+ return def.getMetaTagByName("JSModule");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ //it's safe to ignore an exception here
+ }
+ return null;
+ }
+
+ public boolean isExternalLinkage(ICompilationUnit cu)
+ {
+ if (linkageChecker == null)
+ {
+ ts = getTargetSettings();
+ linkageChecker = new LinkageChecker(this, ts);
+ }
+ // in unit tests, ts may be null and LinkageChecker NPEs
+ if (ts == null)
+ {
+ if (unitTestExterns != null)
+ {
+ try {
+ if (!(cu instanceof SWCCompilationUnit))
+ if (unitTestExterns.contains(cu.getQualifiedNames().get(0)))
+ return true;
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return false;
+ }
+
+ List<String> qnames;
+ try {
+ qnames = cu.getQualifiedNames();
+ String qname = qnames.get(0);
+ if (qname.equals("QName") || qname.equals("XML") || qname.equals("XMLList"))
+ return false;
+ } catch (InterruptedException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ try
+ {
+ return linkageChecker.isExternal(cu);
+ }
+ catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+ public ArrayList<String> getInterfaces(ICompilationUnit from)
+ {
+ if (interfaces.containsKey(from))
+ {
+ HashMap<String, String> map = interfaces.get(from);
+ ArrayList<String> arr = new ArrayList<String>();
+ Set<String> cus = map.keySet();
+ for (String s : cus)
+ arr.add(s);
+ return arr;
+ }
+ return null;
+ }
+
+ public ArrayList<String> getRequires(ICompilationUnit from)
+ {
+ if (requires.containsKey(from))
+ {
+ HashMap<String, DependencyType> map = requires.get(from);
+ ArrayList<String> arr = new ArrayList<String>();
+ Set<String> cus = map.keySet();
+ for (String s : cus)
+ arr.add(s);
+ return arr;
+ }
+ return null;
+ }
+
+ public ArrayList<String> getExternalRequires(ICompilationUnit from)
+ {
+ if (jsModules.containsKey(from))
+ {
+ HashMap<String, DependencyType> map = jsModules.get(from);
+ ArrayList<String> arr = new ArrayList<String>();
+ Set<String> cus = map.keySet();
+ for (String s : cus)
+ arr.add(s);
+ return arr;
+ }
+ return null;
+ }
+
+ JSCSSCompilationSession cssSession = new JSCSSCompilationSession();
+
+ @Override
+ public CSSCompilationSession getCSSCompilationSession()
+ {
+ // When building SWFs, each MXML document may have its own styles
+ // specified by fx:Style blocks. The CSS is separately compiled and
+ // stored in the class definition for the MXML document. That helps
+ // with deferred loading of classes. The styles and thus the
+ // classes for an MXML document are not initialized until the MXML
+ // class is initialized.
+ // For JS compilation, the CSS for non-standard CSS could be done the
+ // same way, but AFAICT, standard CSS properties are best loaded by
+ // specifying a .CSS file in the HTML. The CSS is probably less text
+ // than its codegen'd representation, and the browser can probably
+ // load a .CSS file faster than us trying to run code to update the
+ // styles.
+ // So, for Royale, all style blocks from all MXML files are gathered into
+ // one .css file and a corresponding codegen block that is output as
+ // part of the main .JS file.
+ return cssSession;
+ }
+
+ private HashMap<IASNode, String> astCache = new HashMap<IASNode, String>();
+
+ @Override
+ public void addToASTCache(IASNode ast)
+ {
+ astCache.put(ast, "");
+ }
+
+ @Override
+ public void setTargetSettings(ITargetSettings value)
+ {
+ super.setTargetSettings(value);
+ ts = value;
+ linkageChecker = new LinkageChecker(this, value);
+ try {
+ linkageChecker.initExterns();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String getGeneratedIDBase()
+ {
+ return MXMLRoyaleEmitterTokens.ID_PREFIX.getToken();
+ }
+
+ public ITargetAttributes computeTargetAttributes()
+ {
+ List<String> names;
+ try {
+ names = mainCU.getQualifiedNames();
+ IDefinition def = this.resolveQNameToDefinition(names.get(0));
+ IDefinitionNode node = def.getNode();
+ if (node instanceof MXMLDocumentNode)
+ {
+ MXMLDocumentNode mxmlDoc = (MXMLDocumentNode)node;
+ MXMLFileNode mxmlFile = (MXMLFileNode)mxmlDoc.getParent();
+ return mxmlFile.getTargetAttributes(this);
+ }
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public IWASTBackend getBackend() {
+ return backend;
+ }
+
+ @Override
+ protected void overrideDefines(Map<String, String> defines)
+ {
+ if (defines.containsKey("COMPILE::SWF"))
+ {
+ if (defines.get("COMPILE::SWF").equals("AUTO"))
+ defines.put("COMPILE::SWF", "false");
+ }
+ if (defines.containsKey("COMPILE::JS"))
+ {
+ if (defines.get("COMPILE::JS").equals("AUTO"))
+ defines.put("COMPILE::JS", "true");
+ }
+ }
+
+ /**
+ * List of external libraries so it can be overridden
+ */
+ public List<String> getCompilerExternalLibraryPath(Configuration config)
+ {
+ List<String> list = ((JSConfiguration)config).getCompilerJsExternalLibraryPath();
+ if (list != null && list.size() > 0)
+ return list;
+ return config.getCompilerExternalLibraryPath();
+ }
+
+ /**
+ * List of libraries so it can be overridden
+ */
+ public List<String> getCompilerLibraryPath(Configuration config)
+ {
+ List<String> list = ((JSConfiguration)config).getCompilerJsLibraryPath();
+ if (list != null && list.size() > 0)
+ return list;
+ return config.getCompilerLibraryPath();
+ }
+
+ /**
+ * List of libraries so it can be overridden
+ */
+ public List<MXMLNamespaceMapping> getCompilerNamespacesManifestMappings(Configuration config)
+ {
+ List<MXMLNamespaceMapping> list = ((JSConfiguration)config).getCompilerJsNamespacesManifestMappings();
+ if (list != null && list.size() > 0)
+ return list;
+ return config.getCompilerNamespacesManifestMappings();
+ }
+
+ @Override
+ public boolean isPlatformRule(ICSSRule rule) {
+ ImmutableList<ICSSMediaQueryCondition> mqlist = rule.getMediaQueryConditions();
+ int n = mqlist.size();
+ if (n > 0)
+ {
+ if (mqlist.get(0).toString().equals("-royale-swf"))
+ return false;
+ }
+ return true;
+ }
+
+ private HashSet<String> exportedNames = new HashSet<String>();
+
+ public void addExportedName(String name)
+ {
+ exportedNames.add(name);
+ }
+
+ public Set<String> getExportedNames()
+ {
+ return exportedNames;
+ }
+
+ public boolean isModule(String mainClass)
+ {
+ IResolvedQualifiersReference iModuleRef = ReferenceFactory.packageQualifiedReference(
+ getWorkspace(), "org.apache.royale.core.IModule");
+ ITypeDefinition moddef = (ITypeDefinition)iModuleRef.resolve(this);
+ IResolvedQualifiersReference mainRef = ReferenceFactory.packageQualifiedReference(
+ getWorkspace(), mainClass);
+ IDefinition maindef = mainRef.resolve(this);
+ if (maindef instanceof ITypeDefinition)
+ {
+ ITypeDefinition type = (ITypeDefinition)maindef;
+ return type.isInstanceOf(moddef, this);
+ }
+ return false;
+ }
+}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/JSTarget.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/JSTarget.java
index 1297aa1..242a7e1 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/JSTarget.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/JSTarget.java
@@ -28,7 +28,7 @@
import org.apache.royale.compiler.driver.js.IJSApplication;
import org.apache.royale.compiler.exceptions.BuildCanceledException;
import org.apache.royale.compiler.internal.driver.js.JSApplication;
-import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
+import org.apache.royale.compiler.internal.projects.RoyaleProject;
import org.apache.royale.compiler.problems.ICompilerProblem;
import org.apache.royale.compiler.targets.IJSTarget;
import org.apache.royale.compiler.targets.ITargetProgressMonitor;
@@ -49,7 +49,7 @@
*
* @param project the owner project
*/
- public JSTarget(RoyaleJSProject project, ITargetSettings targetSettings,
+ public JSTarget(RoyaleProject project, ITargetSettings targetSettings,
ITargetProgressMonitor progressMonitor)
{
super(project, targetSettings, progressMonitor);
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleJSTarget.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleJSTarget.java
index 6a18bd5..6238f62 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleJSTarget.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleJSTarget.java
@@ -56,6 +56,7 @@
ITargetProgressMonitor progressMonitor)
{
super(project, targetSettings, progressMonitor);
+
royaleProject = project;
}
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleWASTTarget.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleWASTTarget.java
new file mode 100644
index 0000000..05ce81e
--- /dev/null
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/targets/RoyaleWASTTarget.java
@@ -0,0 +1,323 @@
+/*
+ *
+ * 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.royale.compiler.internal.targets;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.royale.compiler.css.ICSSDocument;
+import org.apache.royale.compiler.css.ICSSManager;
+import org.apache.royale.compiler.definitions.IDefinition;
+import org.apache.royale.compiler.internal.css.semantics.ActivatedStyleSheets;
+import org.apache.royale.compiler.internal.driver.js.royale.JSCSSCompilationSession;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.compiler.internal.units.SWCCompilationUnit;
+import org.apache.royale.compiler.problems.FileNotFoundProblem;
+import org.apache.royale.compiler.problems.ICompilerProblem;
+import org.apache.royale.compiler.targets.IJSTarget;
+import org.apache.royale.compiler.targets.ITargetProgressMonitor;
+import org.apache.royale.compiler.targets.ITargetSettings;
+import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+
+import com.google.common.collect.ImmutableList;
+
+public class RoyaleWASTTarget extends JSTarget implements IJSTarget
+{
+ /**
+ * Initialize a JS target with the owner project and root compilation units.
+ *
+ * @param project the owner project
+ */
+ public RoyaleWASTTarget(RoyaleWASTProject project, ITargetSettings targetSettings,
+ ITargetProgressMonitor progressMonitor)
+ {
+ super(project, targetSettings, progressMonitor);
+ royaleProject = project;
+ }
+
+ private final RoyaleWASTProject royaleProject;
+
+ ///////////
+ //
+ // Copied from RoyaleAppSWFTarget.java then modified
+ //
+ ///////////
+ /**
+ * Discovers dependent compilation units from a set of root compilation
+ * units.
+ * <p>
+ * For each public visible definition in all the compilation units, if
+ * there's an applicable CSS rule, check if the CSS rule pulls in any
+ * dependencies. (i.e. embedded assets, skin classes) Add the dependencies
+ * to the list of compilation units, and check if they have any applicable
+ * CSS rules which could pull in more dependencies. Loop until we reach a
+ * stable set of compilation units.
+ * <p>
+ * CSS rules in these CSS documents can introduce class dependencies. If any
+ * candidate rule matches a class known to be linked into the target, the
+ * candidate rule's dependencies are selected for linking. Those selected
+ * dependencies will be included in the next iteration of the dependency
+ * discovery loop.
+ * <p>
+ * Once a CSS document is "activated", it stays in this collection and its
+ * rules are tested against all classes introduced in the
+ * "dependency discovery loop".
+ * <p>
+ * For example: Suppose in project P, there are "A.as" and "styles.css", and
+ * class "A" is selected for linking.<br>
+ * In "styles.css", there're two rules:
+ *
+ * <pre>
+ * A { xSkin : ClassReference("B"); }
+ * K { xSkin : ClassReference("L"); }
+ * </pre>
+ *
+ * In the 1st iteration, rule "A" is matched, which introduces dependency on
+ * "B". <br>
+ * "B" is defined in a SWC library "myskins.swc", and there's a
+ * "defaults.css" in "myskins.swc".
+ *
+ * <pre>
+ * B { ySkin : ClassReference("C"); }
+ * A { ySkin : ClassReference("D"); }
+ * K { ySkin : ClassReference("M"); }
+ * </pre>
+ *
+ * In the 2nd iteration, rule "A" and rule "B" in "defaults.css" are
+ * matched, which introduces dependencies on "C" and "D". However, "K" has
+ * not been selected so far, so "L" and "M" are not selected.
+ * <p>
+ * Now imagine, "C" is defined in "anotherSkin.swc", and there's a
+ * "defaults.css" in "anotherSkin.swc" as well.
+ *
+ * <pre>
+ * C { zSkin : ClassReference("K"); }
+ * </pre>
+ *
+ * In the 3rd iteration, rule "C" is matched because "C" was selected in the
+ * previous iteration, which makes "K" the selected dependency.
+ * <p>
+ * At the beginning of the 4th iteration, the classes selected for linking
+ * are "A", "B", "C", "D" and "K". In this iteration, these classes will be
+ * tested against all the "activated style sheets" - "styles.css" and two
+ * "defaults.css" in "myskins.swc" and "anotherSkin.swc". "K" rules in
+ * "styles.css" and "myskins.swc" are now matched, which introduces new
+ * dependencies on "L" and "M".
+ * <p>
+ * In the 5th iteration, the classes to link are "A", "B", "C", "D", "K",
+ * "L" and "M". They are tested against all the activate CSS. No more
+ * dependencies are introduced by CSS rules, making it the last iteration of
+ * the loop.
+ *
+ * @param compilationUnits Collection of compilation units known to be
+ * linked in.
+ * @param problems Collection of {@link ICompilerProblem}'s that the each
+ * found {@link ICompilationUnit} is added to.
+ * @return All compilation units which were compiled
+ * @throws InterruptedException
+ */
+ @Override
+ protected Set<ICompilationUnit> findAllCompilationUnitsToLink(final Collection<ICompilationUnit> compilationUnits,
+ final Collection<ICompilerProblem> problems)
+ throws InterruptedException
+ {
+ JSCSSCompilationSession cssCompilationSession = (JSCSSCompilationSession) royaleProject.getCSSCompilationSession();
+ cssCompilationSession.setKeepAllTypeSelectors(targetSettings.keepAllTypeSelectors());
+ cssCompilationSession.setExcludeDefaultsCSSFiles(targetSettings.getExcludeDefaultsCSSFiles());
+
+ // Performance heuristic: let's start compilation on all of the compilation
+ // units we know about up front. This is particularly useful on SWC projects where
+ // we are using "include-sources" to force a bunch of possibly unrelated classes to be
+ // compiled.
+ // Note that by putting the code here, we will start aggressive early compilation for
+ // all projects. Limited data so far shows this this is a good thing. But down the
+ // road it's possible that we might find tests cases that force us to reconsider / refine
+ // this "shotgun" approach.
+ for (ICompilationUnit cu : compilationUnits)
+ cu.startBuildAsync(getTargetType());
+
+
+ assert compilationUnits != null : "compilation units can't be null";
+ assert problems != null : "problems can't be null";
+
+ // Collection of all the compilation units that will be linked in the target.
+ final Set<ICompilationUnit> allCompilationUnitsInTarget =
+ new HashSet<ICompilationUnit>(compilationUnits);
+
+ // Collection of all the referenced CSS. Once a CSS is activated, it's always
+ // included in the dependency checking, even none of its rules are matched.
+ final ActivatedStyleSheets activatedStyleSheets = new ActivatedStyleSheets();
+
+ final ICSSManager cssManager = royaleProject.getCSSManager();
+
+ collectThemes(cssManager, activatedStyleSheets, problems);
+ collectDefaultCSS(cssManager, activatedStyleSheets, problems);
+
+ // The dependency discovery loop.
+ // It terminates when no more dependencies are introduced by CSS.
+ boolean done = false;
+ while (!done)
+ {
+ //LoggingProfiler.onStartIteration();
+
+ // Get all non-CSS dependencies.
+ final Set<ICompilationUnit> dependencies =
+ getDependentCompilationUnits(allCompilationUnitsInTarget, problems);
+ //LoggingProfiler.onCompilationUnitDependenciesChanged(allCompilationUnitsInTarget, dependencies);
+ allCompilationUnitsInTarget.addAll(dependencies);
+
+ // Get all activated defaults.css from SWCs.
+ final Map<ICSSDocument, File> activatedDefaultCSSList =
+ getAllDefaultCSS(cssManager, allCompilationUnitsInTarget);
+ for (final Map.Entry<ICSSDocument, File> entry : activatedDefaultCSSList.entrySet())
+ {
+ activatedStyleSheets.addLibraryCSS(entry.getKey(), entry.getValue().getAbsolutePath());
+ }
+ //LoggingProfiler.onDefaultsCSSCollectionChanged(activatedStyleSheets);
+
+ // Get all dependencies introduced by defaults.css from SWCs.
+ final ImmutableList<IDefinition> definitions =
+ Target.getAllExternallyVisibleDefinitions(allCompilationUnitsInTarget);
+ final Collection<ICompilationUnit> cssDependencies = new HashSet<ICompilationUnit>();
+ for (final ICSSDocument cssDocument : activatedStyleSheets.all())
+ {
+ // Side-effects of this method:
+ // 1. Resolve all type selectors in the CSS model to IClassDefinition definitions.
+ // 2. Activate CSS rules whose subject is in the definition set.
+ final Collection<ICompilationUnit> dependentCUListFromCSS =
+ cssManager.getDependentCompilationUnitsFromCSS(
+ cssCompilationSession,
+ cssDocument,
+ definitions,
+ problems);
+ cssDependencies.addAll(dependentCUListFromCSS);
+ //LoggingProfiler.onCSSDependenciesChanged(dependentCUListFromCSS);
+ }
+
+ // If there's more dependencies introduced by CSS, the loop continues.
+ done = !allCompilationUnitsInTarget.addAll(cssDependencies);
+ }
+
+ // add to front so user specified css overrides defaults
+ cssCompilationSession.cssDocuments.addAll(0, activatedStyleSheets.sort());
+
+ return super.findAllCompilationUnitsToLink(compilationUnits, problems);
+ }
+
+ /**
+ * Collect CSS from themes.
+ */
+ private void collectThemes(
+ final ICSSManager cssManager,
+ final ActivatedStyleSheets activatedStyleSheets,
+ final Collection<ICompilerProblem> problems)
+ {
+ final Collection<ICSSDocument> cssFromThemes = cssManager.getCSSFromThemes(problems);
+ for (final ICSSDocument themeCSS : cssFromThemes)
+ {
+ // Theme files are sorted by declaration order instead of filenames, so we needn't
+ // their filenames here.
+ activatedStyleSheets.addThemeCSS(themeCSS);
+ }
+ }
+
+ /**
+ * Collect CSS from 'defaults-css-files' configuration option.
+ */
+ private void collectDefaultCSS(
+ final ICSSManager cssManager,
+ final ActivatedStyleSheets activatedStyleSheets,
+ final Collection<ICompilerProblem> problems)
+ {
+ for (final String defaultsCSSPath : getTargetSettings().getDefaultsCSSFiles())
+ {
+ final ICSSDocument defaultsCSSModel = cssManager.getCSS(defaultsCSSPath);
+ if (defaultsCSSModel == null)
+ problems.add(new FileNotFoundProblem(defaultsCSSPath));
+ else
+ activatedStyleSheets.addDefaultCSS(defaultsCSSModel);
+ }
+ }
+
+ /**
+ * Find all the {@link SWCCompilationUnit}'s, and return the default CSS
+ * model in the SWCs.
+ *
+ * @param cssManager Project-level CSS manager.
+ * @param compilationUnits All the compilation units. Non-SWC compilation
+ * units are ignored.
+ * @return Model of the default CSS in the SWCs. The map keys are CSS
+ * models; the values are the enclosing SWC file.
+ */
+ private static Map<ICSSDocument, File> getAllDefaultCSS(
+ final ICSSManager cssManager,
+ final Collection<ICompilationUnit> compilationUnits)
+ {
+ assert cssManager != null : "Expected CSS manager.";
+ assert compilationUnits != null : "Expected collection of compilation units.";
+
+ final Map<ICSSDocument, File> result = new HashMap<ICSSDocument, File>();
+ for (final ICompilationUnit compilationUnit : compilationUnits)
+ {
+ if (compilationUnit.getCompilationUnitType() == UnitType.SWC_UNIT)
+ {
+ final File swcFile = new File(compilationUnit.getAbsoluteFilename());
+ final ICSSDocument defaultCSS = cssManager.getDefaultCSS(swcFile);
+ if (defaultCSS != null)
+ result.put(defaultCSS, swcFile);
+ }
+ }
+ return result;
+ }
+
+ public void collectMixinMetaData(TreeSet<String> mixinClassNames, List<ICompilationUnit> units)
+ {
+ for (ICompilationUnit unit : units)
+ {
+ try {
+ RoyaleApplicationFrame1Info.collectMixinMetaData(mixinClassNames, unit);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void collectRemoteClassMetaData(Map<String, String> remoteClassAliasMap, List<ICompilationUnit> units)
+ {
+ for (ICompilationUnit unit : units)
+ {
+ try {
+ RoyaleApplicationFrame1Info.collectRemoteClassMetaData(remoteClassAliasMap, unit);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleAccessors.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleAccessors.java
index af854af..1c45a86 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleAccessors.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleAccessors.java
@@ -36,7 +36,7 @@
public void setUp()
{
super.setUp();
- ((RoyaleJSProject)project).config = new JSGoogConfiguration();
+ ((RoyaleJSProject)royaleJSProject).config = new JSGoogConfiguration();
}
@Test
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleClass.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleClass.java
index f223030..08a8e74 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleClass.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleClass.java
@@ -37,8 +37,8 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
- ((RoyaleJSProject)project).config = new JSGoogConfiguration();
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
+ ((RoyaleJSProject)royaleJSProject).config = new JSGoogConfiguration();
super.setUp();
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleEmitter.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleEmitter.java
index e8c40a8..97ffd12 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleEmitter.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleEmitter.java
@@ -39,7 +39,7 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
super.setUp();
}
@@ -414,10 +414,10 @@
{
super.addDependencies();
workspace.setASDocDelegate(new RoyaleASDocDelegate());
- if (project.config == null)
- project.config = new JSGoogConfiguration();
+ if (royaleJSProject.config == null)
+ royaleJSProject.config = new JSGoogConfiguration();
try {
- project.config.setKeepASDoc(null, true);
+ royaleJSProject.config.setKeepASDoc(null, true);
} catch (ConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java
index 2cda9e1..3dc1817 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java
@@ -50,7 +50,7 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
workspace.setASDocDelegate(new RoyaleASDocDelegate());
JSGoogConfiguration config = new JSGoogConfiguration();
try {
@@ -59,7 +59,7 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
- ((RoyaleJSProject)project).config = config;
+ ((RoyaleJSProject)royaleJSProject).config = config;
super.setUp();
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleFile.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleFile.java
index 3dc3e48..518804a 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleFile.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleFile.java
@@ -42,7 +42,7 @@
public void setUp()
{
super.setUp();
- ((RoyaleJSProject)project).config = new JSGoogConfiguration();
+ ((RoyaleJSProject)royaleJSProject).config = new JSGoogConfiguration();
}
@Test
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
index aa516d9..1084cd2 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
@@ -45,9 +45,9 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
- project.config = new JSGoogConfiguration();
- project.setProxyBaseClass("custom.TestProxy");
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
+ royaleJSProject.config = new JSGoogConfiguration();
+ royaleJSProject.setProxyBaseClass("custom.TestProxy");
super.setUp();
}
@@ -860,47 +860,47 @@
public void testProxy()
{
IFunctionNode node = (IFunctionNode) getNode(
- "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();a.foo = 'bar'; }}",
+ "import flash.utils.Proxy; public class B {public function b() { var a:Proxy = new Proxy();a.foo = 'bar'; }}",
IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
asBlockWalker.visitFunction(node);
- assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n a.setProperty('foo', 'bar');\n}");
+ assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {flash.utils.Proxy} */ a = new flash.utils.Proxy();\n a.setProperty('foo', 'bar');\n}");
}
@Test
public void testProxyGet()
{
IFunctionNode node = (IFunctionNode) getNode(
- "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();var bar:* = a.foo; }}",
+ "import flash.utils.Proxy; public class B {public function b() { var a:Proxy = new Proxy();var bar:* = a.foo; }}",
IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
asBlockWalker.visitFunction(node);
- assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n var /** @type {*} */ bar = a.getProperty('foo');\n}");
+ assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {flash.utils.Proxy} */ a = new flash.utils.Proxy();\n var /** @type {*} */ bar = a.getProperty('foo');\n}");
}
@Test
public void testProxyConcat()
{
IFunctionNode node = (IFunctionNode) getNode(
- "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();var baz:String = a.foo + 'bar'; }}",
+ "import flash.utils.Proxy; public class B {public function b() { var a:Proxy = new Proxy();var baz:String = a.foo + 'bar'; }}",
IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
asBlockWalker.visitFunction(node);
- assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n var /** @type {string} */ baz = a.getProperty('foo') + 'bar';\n}");
+ assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {flash.utils.Proxy} */ a = new flash.utils.Proxy();\n var /** @type {string} */ baz = a.getProperty('foo') + 'bar';\n}");
}
@Test
public void testProxyAddAndAssign()
{
IFunctionNode node = (IFunctionNode) getNode(
- "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();a.foo += 'bar'; }}",
+ "import flash.utils.Proxy; public class B {public function b() { var a:Proxy = new Proxy();a.foo += 'bar'; }}",
IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
asBlockWalker.visitFunction(node);
- assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n a.setProperty('foo', a.getProperty('foo') + 'bar');\n}");
+ assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n var /** @type {flash.utils.Proxy} */ a = new flash.utils.Proxy();\n a.setProperty('foo', a.getProperty('foo') + 'bar');\n}");
}
@Test
public void testProxyForLoop()
{
IForLoopNode node = (IForLoopNode) getNode(
- "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();for (var p:* in a) delete a[p];; }}",
+ "import flash.utils.Proxy; public class B {public function b() { var a:Proxy = new Proxy();for (var p:* in a) delete a[p];; }}",
IForLoopNode.class, WRAP_LEVEL_PACKAGE, true);
asBlockWalker.visitForLoop(node);
assertOut("for (var /** @type {*} */ p in a.propertyNames())\n a.deleteProperty(p);");
@@ -910,7 +910,7 @@
public void testProxyForEachLoop()
{
IForLoopNode node = (IForLoopNode) getNode(
- "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();for each (var p:String in a) var i:int = p.length; }}",
+ "import flash.utils.Proxy; public class B {public function b() { var a:Proxy = new Proxy();for each (var p:String in a) var i:int = p.length; }}",
IForLoopNode.class, WRAP_LEVEL_PACKAGE, true);
asBlockWalker.visitForLoop(node);
assertOut("var foreachiter0_target = a;\nfor (var foreachiter0 in foreachiter0_target.propertyNames()) \n{\nvar p = foreachiter0_target.getProperty(foreachiter0);\n\n var /** @type {number} */ i = p.length;}\n");
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
index ddf5f53..4ff4b0d 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalFunctions.java
@@ -38,9 +38,9 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
- project.config = new JSGoogConfiguration();
- project.setProxyBaseClass("flash.utils.Proxy");
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
+ royaleJSProject.config = new JSGoogConfiguration();
+ royaleJSProject.setProxyBaseClass("flash.utils.Proxy");
super.setUp();
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyalePackage.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyalePackage.java
index 15a4d07..e3eb1f4 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyalePackage.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyalePackage.java
@@ -38,7 +38,7 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
JSGoogConfiguration config = new JSGoogConfiguration();
ArrayList<String> values = new ArrayList<String>();
values.add("Event");
@@ -47,7 +47,7 @@
ArrayList<String> values2 = new ArrayList<String>();
values2.add("Before");
config.setCompilerKeepCodeWithMetadata(null, values2);
- ((RoyaleJSProject)project).config = config;
+ ((RoyaleJSProject)royaleJSProject).config = config;
super.setUp();
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleProject.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleProject.java
index e70f212..b690074 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleProject.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleProject.java
@@ -59,8 +59,8 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
- project.config = new JSGoogConfiguration();
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
+ royaleJSProject.config = new JSGoogConfiguration();
super.setUp();
}
@@ -170,11 +170,11 @@
String fileName = "Test";
try {
- ((RoyaleJSProject)project).config.setCompilerAllowSubclassOverrides(null, true);
+ ((RoyaleJSProject)royaleJSProject).config.setCompilerAllowSubclassOverrides(null, true);
} catch (ConfigurationException e) {
Assert.fail(e.getMessage());
}
- project.setTargetSettings(new TargetSettings(((RoyaleJSProject)project).config, (RoyaleJSProject)project));
+ royaleJSProject.setTargetSettings(new TargetSettings(((RoyaleJSProject)royaleJSProject).config, (RoyaleJSProject)royaleJSProject));
sourcePath = new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(),
projectDirPath + "/overrides").getPath();
@@ -193,11 +193,11 @@
String fileName = "Test";
try {
- ((RoyaleJSProject)project).config.setCompilerAllowSubclassOverrides(null, true);
+ ((RoyaleJSProject)royaleJSProject).config.setCompilerAllowSubclassOverrides(null, true);
} catch (ConfigurationException e) {
Assert.fail(e.getMessage());
}
- project.setTargetSettings(new TargetSettings(((RoyaleJSProject)project).config, (RoyaleJSProject)project));
+ royaleJSProject.setTargetSettings(new TargetSettings(((RoyaleJSProject)royaleJSProject).config, (RoyaleJSProject)royaleJSProject));
sourcePath = new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(),
projectDirPath + "/bad_overrides").getPath();
@@ -350,7 +350,7 @@
protected void addSourcePaths(List<File> sourcePaths)
{
sourcePaths.add(new File(FilenameNormalization.normalize(sourcePath)));
- ((RoyaleJSProject)project).unitTestExterns = externs;
+ ((RoyaleJSProject)royaleJSProject).unitTestExterns = externs;
}
@Override
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java
index 09e7e91..624ea9d 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java
@@ -45,7 +45,7 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
super.setUp();
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/royale/TestRoyaleMXMLApplication.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/royale/TestRoyaleMXMLApplication.java
index d983ea8..f05cb5d 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/royale/TestRoyaleMXMLApplication.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/mxml/royale/TestRoyaleMXMLApplication.java
@@ -47,7 +47,7 @@
public void setUp()
{
super.setUp();
- ((RoyaleJSProject)project).config = new JSGoogConfiguration();
+ ((RoyaleJSProject)royaleJSProject).config = new JSGoogConfiguration();
}
@Test
@@ -60,7 +60,7 @@
mxmlBlockWalker.visitFile(node);
- JSCSSCompilationSession jscss = (JSCSSCompilationSession)project.getCSSCompilationSession();
+ JSCSSCompilationSession jscss = (JSCSSCompilationSession)royaleJSProject.getCSSCompilationSession();
jscss.setExcludeDefaultsCSSFiles(new ArrayList<String>());
String result = getCodeFromFile("CSSTestSource_result.css", "royale/files");
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
new file mode 100644
index 0000000..8434e19
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
@@ -0,0 +1,41 @@
+/*
+ *
+ * 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.royale.compiler.internal.codegen.wast;
+
+import org.apache.royale.compiler.internal.test.WASTTestBase;
+import org.apache.royale.compiler.tree.as.IClassNode;
+import org.junit.Test;
+
+/**
+ * This class tests the production of WebAssembly Text Format code for Classes.
+ *
+ * @author Erik de Bruin
+ */
+public class TestWASTClass extends WASTTestBase {
+
+ @Test
+ public void testClassSimple()
+ {
+ IClassNode node = (IClassNode) getNode("public class A{}", IClassNode.class, WRAP_LEVEL_PACKAGE);
+ asBlockWalker.visitClass(node);
+ assertOut("(module\n \n )");
+ }
+
+}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTMethodMember.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTMethodMember.java
new file mode 100644
index 0000000..0049821
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTMethodMember.java
@@ -0,0 +1,17 @@
+package org.apache.royale.compiler.internal.codegen.wast;
+
+import org.apache.royale.compiler.internal.test.WASTTestBase;
+import org.apache.royale.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+public class TestWASTMethodMember extends WASTTestBase {
+
+ @Test
+ public void testMethod()
+ {
+ IFunctionNode node = getMethod("function foo(){}");
+ asBlockWalker.visitFunction(node);
+ assertOut("");
+ }
+
+}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java
index 0e64896..b8a45a9 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/AMDTestBase.java
@@ -23,6 +23,7 @@
import java.util.List;
import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.driver.js.amd.AMDBackend;
import org.apache.royale.compiler.tree.as.IClassNode;
import org.apache.royale.compiler.tree.as.IDefinitionNode;
@@ -57,7 +58,7 @@
super.setUp();
asEmitter = backend.createEmitter(writer);
- asBlockWalker = backend.createWalker(project, errors, asEmitter);
+ asBlockWalker = ((IJSBackend) backend).createWalker(royaleJSProject, errors, asEmitter);
projectPath = new File(TestAdapterFactory.getTestAdapter().getUnitTestBaseDir(),
"amd/simple-project/src").getPath();
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/ASTestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/ASTestBase.java
index a0daae8..6c4328d 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/ASTestBase.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/ASTestBase.java
@@ -22,6 +22,7 @@
import java.util.List;
import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.driver.as.ASBackend;
import org.apache.royale.compiler.tree.as.IASNode;
import org.apache.royale.compiler.tree.as.IAccessorNode;
@@ -54,7 +55,10 @@
testAdapter = TestAdapterFactory.getTestAdapter();
asEmitter = backend.createEmitter(writer);
- asBlockWalker = backend.createWalker(project, errors, asEmitter);
+
+ if (backend instanceof IJSBackend) {
+ asBlockWalker = ((IJSBackend) backend).createWalker(royaleJSProject, errors, asEmitter);
+ }
}
@Override
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/MXMLTestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/MXMLTestBase.java
index 5235ffc..93be79f 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/MXMLTestBase.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/MXMLTestBase.java
@@ -22,6 +22,7 @@
import java.util.List;
import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.driver.mxml.MXMLBackend;
import org.apache.royale.compiler.internal.mxml.MXMLNamespaceMapping;
import org.apache.royale.compiler.mxml.IMXMLNamespaceMapping;
@@ -48,8 +49,8 @@
asEmitter = backend.createEmitter(writer);
mxmlEmitter = backend.createMXMLEmitter(writer);
- asBlockWalker = backend.createWalker(project, errors, asEmitter);
- mxmlBlockWalker = backend.createMXMLWalker(project, errors,
+ asBlockWalker = ((IJSBackend) backend).createWalker(royaleJSProject, errors, asEmitter);
+ mxmlBlockWalker = ((IJSBackend) backend).createMXMLWalker(royaleJSProject, errors,
mxmlEmitter, asEmitter, asBlockWalker);
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleTestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleTestBase.java
index 67ef4fb..d9fa449 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleTestBase.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/RoyaleTestBase.java
@@ -22,6 +22,7 @@
import java.util.List;
import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.driver.mxml.royale.MXMLRoyaleBackend;
import org.apache.royale.compiler.internal.mxml.MXMLNamespaceMapping;
import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
@@ -44,15 +45,15 @@
public void setUp()
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
super.setUp();
asEmitter = backend.createEmitter(writer);
mxmlEmitter = backend.createMXMLEmitter(writer);
asEmitter.setParentEmitter(mxmlEmitter);
- asBlockWalker = backend.createWalker(project, errors, asEmitter);
- mxmlBlockWalker = backend.createMXMLWalker(project, errors,
+ asBlockWalker = ((IJSBackend) backend).createWalker(royaleJSProject, errors, asEmitter);
+ mxmlBlockWalker = ((IJSBackend) backend).createMXMLWalker(royaleJSProject, errors,
mxmlEmitter, asEmitter, asBlockWalker);
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/TestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/TestBase.java
index 944b06e..aa984e8 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/TestBase.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/TestBase.java
@@ -46,9 +46,11 @@
import org.apache.royale.compiler.codegen.mxml.IMXMLEmitter;
import org.apache.royale.compiler.config.Configurator;
import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.js.IJSBackend;
import org.apache.royale.compiler.internal.codegen.as.ASFilterWriter;
import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
import org.apache.royale.compiler.internal.projects.RoyaleProjectConfigurator;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
import org.apache.royale.compiler.internal.projects.ISourceFileHandler;
import org.apache.royale.compiler.internal.targets.JSTarget;
import org.apache.royale.compiler.internal.tree.as.FunctionNode;
@@ -85,7 +87,8 @@
protected static EnvProperties env = EnvProperties.initiate();
protected static Workspace workspace = new Workspace();
- protected RoyaleJSProject project;
+ protected RoyaleJSProject royaleJSProject;
+ protected RoyaleWASTProject royaleWASTProject;
protected IBackend backend;
protected ASFilterWriter writer;
@@ -111,23 +114,25 @@
{
errors = new ArrayList<ICompilerProblem>();
- if (project == null)
+ if (royaleJSProject == null)
{
backend = createBackend();
- project = new RoyaleJSProject(workspace, backend);
- project.setProxyBaseClass("custom.TestProxy");
+ royaleJSProject = new RoyaleJSProject(workspace, backend);
+ royaleJSProject.setProxyBaseClass("custom.TestProxy");
}
- project.setProblems(errors);
- RoyaleProjectConfigurator.configure(project);
+ royaleJSProject.setProblems(errors);
+ RoyaleProjectConfigurator.configure(royaleJSProject);
try {
Configurator projectConfigurator = backend.createConfigurator();
- project.setTargetSettings(projectConfigurator.getTargetSettings(null));
+ royaleJSProject.setTargetSettings(projectConfigurator.getTargetSettings(null));
}
catch (UnsupportedOperationException e)
{
}
- writer = backend.createWriterBuffer(project);
+ if (backend instanceof IJSBackend) {
+ writer = ((IJSBackend) backend).createWriterBuffer(royaleJSProject);
+ }
try
{
@@ -325,7 +330,7 @@
.normalize(tempFile.getAbsolutePath());
Collection<ICompilationUnit> mainFileCompilationUnits = workspace
- .getCompilationUnits(normalizedMainFileName, project);
+ .getCompilationUnits(normalizedMainFileName, royaleJSProject);
ICompilationUnit cu = null;
for (ICompilationUnit cu2 : mainFileCompilationUnits)
@@ -346,7 +351,7 @@
return null;
}
fileNode = result.getAST();
- project.getDependencies(cu);
+ royaleJSProject.getDependencies(cu);
}
catch (InterruptedException e)
{
@@ -374,12 +379,12 @@
ICompilationUnit mainCU = Iterables
.getOnlyElement(workspace.getCompilationUnits(
- FilenameNormalization.normalize(mainFileName), project));
+ FilenameNormalization.normalize(mainFileName), royaleJSProject));
- project.mainCU = mainCU;
+ royaleJSProject.mainCU = mainCU;
Configurator projectConfigurator = backend.createConfigurator();
- JSTarget target = (JSTarget) backend.createTarget(project,
+ JSTarget target = (JSTarget) ((IJSBackend) backend).createTarget(royaleJSProject,
projectConfigurator.getTargetSettings(null), null);
ArrayList<ICompilerProblem> errors = new ArrayList<ICompilerProblem>();
@@ -401,7 +406,7 @@
System.out.println(sb.toString());
return compiledFileNames;
}
- List<ICompilationUnit> reachableCompilationUnits = project
+ List<ICompilationUnit> reachableCompilationUnits = royaleJSProject
.getReachableCompilationUnitsInSWFOrder(ImmutableSet.of(mainCU));
for (final ICompilationUnit cu : reachableCompilationUnits)
{
@@ -423,9 +428,9 @@
final File outputClassFile = getOutputClassFile(qname
+ "_output", outputRootDir);
- ASFilterWriter writer = backend.createWriterBuffer(project);
+ ASFilterWriter writer = ((IJSBackend) backend).createWriterBuffer(royaleJSProject);
IASEmitter emitter = backend.createEmitter(writer);
- IASBlockWalker walker = backend.createWalker(project,
+ IASBlockWalker walker = ((IJSBackend) backend).createWalker(royaleJSProject,
errors, emitter);
walker.visitCompilationUnit(cu);
@@ -687,18 +692,11 @@
{
addSourcePaths(sourcePaths);
addLibraries(libraries);
- if (libraries.size() == 0)
- {
- String jsSwcPath = FilenameNormalization.normalize("../compiler-externc/target/js.swc");
- libraries.add(new File(jsSwcPath));
- String customSwcPath = FilenameNormalization.normalize("../compiler/target/custom.swc");
- libraries.add(new File(customSwcPath));
- }
addNamespaceMappings(namespaceMappings);
- project.setSourcePath(sourcePaths);
- project.setLibraries(libraries);
- project.setNamespaceMappings(namespaceMappings);
+ royaleJSProject.setSourcePath(sourcePaths);
+ royaleJSProject.setLibraries(libraries);
+ royaleJSProject.setNamespaceMappings(namespaceMappings);
}
protected void addLibraries(List<File> libraries)
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/WASTTestBase.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/WASTTestBase.java
new file mode 100644
index 0000000..bd7c416
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/test/WASTTestBase.java
@@ -0,0 +1,72 @@
+/*
+ *
+ * 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.royale.compiler.internal.test;
+
+import java.io.File;
+import java.util.List;
+
+import org.apache.royale.compiler.driver.IBackend;
+import org.apache.royale.compiler.driver.wast.IWASTBackend;
+import org.apache.royale.compiler.internal.driver.wast.WASTBackend;
+import org.apache.royale.compiler.internal.projects.RoyaleWASTProject;
+import org.apache.royale.utils.FilenameNormalization;
+
+/**
+ * This class tests the production of WebAssembly Text Format output for for AS package.
+ *
+ * @author Erik de Bruin
+ */
+public class WASTTestBase extends ASTestBase {
+
+ @Override
+ public void setUp()
+ {
+ backend = createBackend();
+
+ royaleWASTProject = new RoyaleWASTProject(workspace, (IWASTBackend) backend);
+
+ super.setUp();
+
+ writer = ((IWASTBackend) backend).createWriterBuffer(royaleWASTProject);
+
+ asEmitter = backend.createEmitter(writer);
+ asBlockWalker = ((IWASTBackend) backend).createWalker(royaleWASTProject, errors, asEmitter);
+ }
+
+ @Override
+ protected void addSourcePaths(List<File> sourcePaths)
+ {
+ sourcePaths.add(tempDir);
+ }
+
+ @Override
+ protected void addLibraries(List<File> libraries)
+ {
+ libraries.add(new File(FilenameNormalization.normalize(env.FPSDK
+ + "/" + env.FPVER + "/playerglobal.swc")));
+ }
+
+ @Override
+ protected IBackend createBackend()
+ {
+ return new WASTBackend();
+ }
+
+}
diff --git a/compiler-test-utils/src/main/java/org/apache/royale/utils/EnvProperties.java b/compiler-test-utils/src/main/java/org/apache/royale/utils/EnvProperties.java
index 71f14d0..3646fca 100644
--- a/compiler-test-utils/src/main/java/org/apache/royale/utils/EnvProperties.java
+++ b/compiler-test-utils/src/main/java/org/apache/royale/utils/EnvProperties.java
@@ -74,6 +74,11 @@
*/
public String FPVER;
+ /**
+ * WAT2WASM_HOME
+ */
+ public String WAT2WASM;
+
private static EnvProperties env;
@@ -139,7 +144,9 @@
GOOG = p.getProperty(prefix + "GOOG_HOME", System.getenv("GOOG_HOME"));
System.out.println("environment property - GOOG_HOME = " + GOOG);
-
+
+ WAT2WASM = p.getProperty(prefix + "WAT2WASM_HOME", System.getenv("WAT2WASM_HOME"));
+ System.out.println("environment property - WAT2WASM_HOME = " + WAT2WASM);
}
}