You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by pi...@apache.org on 2019/09/16 08:07:07 UTC

[royale-compiler] branch release/0.9.6 updated (7635ee6 -> 383416e)

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

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


    from 7635ee6  fix alt params again
     new a73451c  JSWriter: externs are not post-processed like regular JS
     new 5c9bf22  compiler: warn when using this in a function closure (references #90)
     new 1d60ebf  Configuration: added -warn-this-within-closure compiler option (references #90)
     new 111f0c8  FullNameNode: fixed issue where end line and end column were never set based on the right node
     new d941f26  compiler: more end line/column improvements
     new 383416e  ConfigConditionBlockNode: fix fillInOffsets() and normalize() when disabled

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


Summary of changes:
 .../clients/problems/ProblemSettingsFilter.java    |  4 ++++
 .../royale/compiler/config/Configuration.java      | 18 +++++++++++++++
 .../royale/compiler/config/Configurator.java       |  5 +++++
 .../compiler/config/ICompilerProblemSettings.java  |  2 ++
 .../config/ICompilerSettingsConstants.java         |  1 +
 .../compiler/constants/IASWarningConstants.java    |  5 +++++
 .../internal/config/CompilerProblemSettings.java   |  3 +++
 .../internal/config/ICompilerSettings.java         |  7 ++++++
 .../problems/ThisUsedInClosureProblem.java         | 16 ++++++-------
 .../compiler/internal/codegen/js/JSWriter.java     |  8 ++++++-
 .../internal/definitions/VectorInformation.java    |  4 ++--
 .../compiler/internal/parsing/as/BaseASParser.java |  2 +-
 .../semantics/MethodBodySemanticChecker.java       | 26 ++++++++++++++++++++++
 .../compiler/internal/semantics/SemanticUtils.java | 16 +++++++++++++
 .../internal/tree/as/BinaryOperatorNodeBase.java   |  2 +-
 .../compiler/internal/tree/as/ClassNode.java       |  4 ++--
 .../internal/tree/as/ConfigConditionBlockNode.java | 20 ++++++++++++++++-
 .../compiler/internal/tree/as/FullNameNode.java    |  8 +++++++
 .../compiler/internal/tree/as/FunctionNode.java    |  4 ++--
 .../tree/as/NamespaceAccessExpressionNode.java     |  2 +-
 .../internal/tree/as/NamespaceIdentifierNode.java  |  2 +-
 .../royale/compiler/internal/tree/as/NodeBase.java | 15 +++++++++++++
 .../compiler/internal/tree/as/ParameterNode.java   |  2 +-
 .../internal/tree/as/UnaryOperatorNodeBase.java    |  2 +-
 .../internal/tree/as/UseNamespaceNode.java         |  2 +-
 .../compiler/internal/tree/mxml/MXMLNodeBase.java  |  1 +
 26 files changed, 158 insertions(+), 23 deletions(-)
 copy compiler/src/main/java/org/apache/royale/compiler/problems/InvalidSuperExpressionProblem.java => compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java (75%)


[royale-compiler] 04/06: FullNameNode: fixed issue where end line and end column were never set based on the right node

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

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

commit 111f0c8a491cc46a41db2901be922738d8151127
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Fri Sep 13 11:29:14 2019 -0700

    FullNameNode: fixed issue where end line and end column were never set based on the right node
    
    (cherry picked from commit d2bb7b4ba2c7d86f571c0eb2d9d07d79af00dc83)
---
 .../org/apache/royale/compiler/internal/tree/as/FullNameNode.java | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FullNameNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FullNameNode.java
index c23fec7..92c9709 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FullNameNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FullNameNode.java
@@ -71,7 +71,11 @@ public class FullNameNode extends MemberAccessExpressionNode implements IIdentif
         super(left, operator, right);
         
         if (right != null)
+        {
             setEnd(right.getAbsoluteEnd());
+            setEndLine(right.getEndLine());
+            setEndColumn(right.getEndColumn());
+        }
     }
 
     protected FullNameNode(MemberAccessExpressionNode node)
@@ -145,7 +149,11 @@ public class FullNameNode extends MemberAccessExpressionNode implements IIdentif
         super.setRightOperandNode(right);
         
         if (right != null)
+        {
             setEnd(right.getAbsoluteEnd());
+            setEndLine(right.getEndLine());
+            setEndColumn(right.getEndColumn());
+        }
     }
     
     //


[royale-compiler] 06/06: ConfigConditionBlockNode: fix fillInOffsets() and normalize() when disabled

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

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

commit 383416e53128c9303f4feac8eea8841351de82e0
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Fri Sep 13 14:59:02 2019 -0700

    ConfigConditionBlockNode: fix fillInOffsets() and normalize() when disabled
    
    They didn't set end/endLine/endColumn before.
    
    (cherry picked from commit b81373b433fdc20477b337e9d729d16646626a17)
---
 .../internal/tree/as/ConfigConditionBlockNode.java   | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ConfigConditionBlockNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ConfigConditionBlockNode.java
index 62080ea..c0998f4 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ConfigConditionBlockNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ConfigConditionBlockNode.java
@@ -33,7 +33,7 @@ import org.apache.royale.compiler.tree.ASTNodeID;
  */
 public final class ConfigConditionBlockNode extends BlockNode
 {
-    private final boolean enabled;
+    private boolean enabled;
 
     /**
      * Create a enabled or disabled configuration config block.
@@ -58,6 +58,24 @@ public final class ConfigConditionBlockNode extends BlockNode
         else
             return 0;
     }
+
+    @Override
+    protected void fillInOffsets()
+    {
+        boolean oldEnabled = enabled;
+        enabled = true;
+        super.fillInOffsets();
+        enabled = oldEnabled;
+    }
+
+    @Override
+    public void normalize(boolean fillInOffsets)
+    {
+        boolean oldEnabled = enabled;
+        enabled = true;
+        super.normalize(fillInOffsets);
+        enabled = oldEnabled;
+    }
     
     @Override
     protected boolean buildInnerString(StringBuilder sb)


[royale-compiler] 02/06: compiler: warn when using this in a function closure (references #90)

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

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

commit 5c9bf227eaf866cb0da66f0b1b54dd951ec95a00
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Sep 11 13:18:52 2019 -0700

    compiler: warn when using this in a function closure (references #90)
    
    (cherry picked from commit 7e7b269bc922080e9084f757e3eecfa5c94697b9)
---
 .../semantics/MethodBodySemanticChecker.java       | 26 ++++++++++++++
 .../compiler/internal/semantics/SemanticUtils.java | 16 +++++++++
 .../problems/ThisUsedInClosureProblem.java         | 40 ++++++++++++++++++++++
 3 files changed, 82 insertions(+)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
index 610da6d..c455528 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/MethodBodySemanticChecker.java
@@ -789,6 +789,14 @@ public class MethodBodySemanticChecker
         {
             FunctionNode func = (FunctionNode)iNode;
 
+            if (SemanticUtils.isFunctionClosure(func))
+            {
+                for (IASNode thisNode : findThisIdentifierNodes(func))
+                {
+                    addProblem(new ThisUsedInClosureProblem(thisNode));
+                }
+            }
+
             IDefinition def = func.getDefinition();
 
             if ( project.getAllowAbstractClasses()
@@ -810,6 +818,24 @@ public class MethodBodySemanticChecker
         }
     }
 
+    private static List<IASNode> findThisIdentifierNodes(IASNode iNode)
+    {
+        List<IASNode> result = new ArrayList<IASNode>();
+        for(int i = 0, count = iNode.getChildCount(); i < count; i++)
+        {
+            IASNode child = iNode.getChild(i);
+            if(SemanticUtils.isThisKeyword(child))
+            {
+                result.add(child);
+            }
+            else if(!child.isTerminal() && !(child instanceof IFunctionNode))
+            {
+                result.addAll(findThisIdentifierNodes(child));
+            }
+        }
+        return result;
+    }
+
     public void checkNativeMethod(IASNode iNode)
     {
         if( iNode instanceof FunctionNode )
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
index 20b3747..d22d291 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
@@ -129,6 +129,7 @@ import org.apache.royale.compiler.tree.as.IMemberAccessExpressionNode;
 import org.apache.royale.compiler.tree.as.INamespaceDecorationNode;
 import org.apache.royale.compiler.tree.as.INumericLiteralNode;
 import org.apache.royale.compiler.tree.as.IParameterNode;
+import org.apache.royale.compiler.tree.as.IScopedNode;
 import org.apache.royale.compiler.tree.as.ITryNode;
 import org.apache.royale.compiler.tree.as.IVariableNode;
 import org.apache.royale.compiler.tree.mxml.IMXMLEventSpecifierNode;
@@ -1324,6 +1325,21 @@ public class SemanticUtils
     }
 
     /**
+     *  Is this function node contained within another function node?
+     *  @param iNode - the node of interest.
+     *  @return true if the function node is a closure
+     */
+    public static boolean isFunctionClosure(IFunctionNode functionNode)
+    {
+        IScopedNode containingScope = functionNode.getContainingScope();
+        if (containingScope == null)
+        {
+            return false;
+        }
+        return containingScope.getParent() instanceof IFunctionNode;
+    }
+
+    /**
      *  Is the given node in a class with a base class definition?
      *  @param iNode - the node of interest.
      *  @return true if the node is in a class with a base class.
diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java b/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
new file mode 100644
index 0000000..8a2dc28
--- /dev/null
+++ b/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
@@ -0,0 +1,40 @@
+/*
+ *
+ *  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.problems;
+
+import org.apache.royale.compiler.tree.as.IASNode;
+
+/**
+ *  Diagnostic emitted when the method body semantic checker detects
+ *  a reference to "this" in a closure
+ */
+public final class ThisUsedInClosureProblem extends SemanticWarningProblem
+{
+    public static final String DESCRIPTION =
+        "Encountered ${THIS} keyword within closure. Value of ${THIS} will not be the same as enclosing scope.";
+
+    public ThisUsedInClosureProblem(IASNode site)
+    {
+        super(site);
+    }
+
+    // Prevent these from being localized.
+    public final String THIS = "this";
+}


[royale-compiler] 03/06: Configuration: added -warn-this-within-closure compiler option (references #90)

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

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

commit 1d60ebf658c79225c8e7e2a6c3c7467a17aaebc0
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Sep 11 13:42:30 2019 -0700

    Configuration: added -warn-this-within-closure compiler option (references #90)
    
    (cherry picked from commit 9a651d8077275633240f51c94b47f0ae7e0ac34f)
---
 .../clients/problems/ProblemSettingsFilter.java        |  4 ++++
 .../apache/royale/compiler/config/Configuration.java   | 18 ++++++++++++++++++
 .../apache/royale/compiler/config/Configurator.java    |  5 +++++
 .../compiler/config/ICompilerProblemSettings.java      |  2 ++
 .../compiler/config/ICompilerSettingsConstants.java    |  1 +
 .../royale/compiler/constants/IASWarningConstants.java |  5 +++++
 .../internal/config/CompilerProblemSettings.java       |  3 +++
 .../compiler/internal/config/ICompilerSettings.java    |  7 +++++++
 .../compiler/problems/ThisUsedInClosureProblem.java    |  2 ++
 9 files changed, 47 insertions(+)

diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java b/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
index 8f857c6..2930c7f 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/clients/problems/ProblemSettingsFilter.java
@@ -41,6 +41,7 @@ import org.apache.royale.compiler.problems.OverlappingSourcePathProblem;
 import org.apache.royale.compiler.problems.ScopedToDefaultNamespaceProblem;
 import org.apache.royale.compiler.problems.SemanticWarningProblem;
 import org.apache.royale.compiler.problems.StrictSemanticsProblem;
+import org.apache.royale.compiler.problems.ThisUsedInClosureProblem;
 import org.apache.royale.compiler.problems.VariableHasNoTypeDeclarationProblem;
 
 /**
@@ -65,6 +66,7 @@ import org.apache.royale.compiler.problems.VariableHasNoTypeDeclarationProblem;
  * -warn-instanceof-changes
  * -warn-missing-namespace-decl
  * -warn-no-type-decl
+ * -warn-this-within-closure
  * 
  */
 public class ProblemSettingsFilter implements IProblemFilter
@@ -186,6 +188,8 @@ public class ProblemSettingsFilter implements IProblemFilter
                 ICompilerSettings.WARN_MISSING_NAMESPACE_DECL);
         setShowActionScriptWarning(VariableHasNoTypeDeclarationProblem.class, 
                 ICompilerSettings.WARN_NO_TYPE_DECL);
+        setShowActionScriptWarning(ThisUsedInClosureProblem.class, 
+                ICompilerSettings.WARN_THIS_WITHIN_CLOSURE);
     }
 
     /**
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
index c1d2ada..3817b3e 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configuration.java
@@ -4053,6 +4053,24 @@ public class Configuration
     }
 
     //
+    // 'compiler.warn-this-within-closure' option
+    //
+
+    private boolean warn_this_within_closure = true;
+
+    public boolean warn_this_within_closure()
+    {
+        return warn_this_within_closure;
+    }
+
+    @Config(advanced = true)
+    @Mapping({ "compiler", "warn-this-within-closure" })
+    public void setCompilerWarnThisWithinClosure(ConfigurationValue cv, boolean b)
+    {
+        warn_this_within_closure = b;
+    }
+
+    //
     // compiler.generate-abstract-syntax-tree
     //
 
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
index 065f7b1..bb90ae6 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/config/Configurator.java
@@ -2300,6 +2300,7 @@ public class Configurator implements ICompilerSettings, IConfigurator, ICompiler
      * --compiler.warn-slow-text-field-addition
      * --compiler.warn-unlikely-function-value
      * --compiler.warn-xml-class-has-changed
+     * --compiler.warn-this-within-closure
      * </pre>
      * 
      * @param warningCode warning code
@@ -2340,6 +2341,7 @@ public class Configurator implements ICompilerSettings, IConfigurator, ICompiler
      * @see #WARN_SLOW_TEXTFIELD_ADDITION
      * @see #WARN_UNLIKELY_FUNCTION_VALUE
      * @see #WARN_XML_CLASS_HAS_CHANGED
+     * @see #WARN_THIS_WITHIN_CLOSURE
      */
     @Override
     public void checkActionScriptWarning(int warningCode, boolean b)
@@ -2456,6 +2458,9 @@ public class Configurator implements ICompilerSettings, IConfigurator, ICompiler
         case WARN_XML_CLASS_HAS_CHANGED:
             key = COMPILER_WARN_XML_CLASS_HAS_CHANGED;
             break;
+        case WARN_THIS_WITHIN_CLOSURE:
+            key = COMPILER_WARN_THIS_WITHIN_CLOSURE;
+            break;
         }
         
         if (key != null)
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
index 355987e..9e0ed7c 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerProblemSettings.java
@@ -157,6 +157,7 @@ public interface ICompilerProblemSettings
       * --compiler.warn-slow-text-field-addition
       * --compiler.warn-unlikely-function-value
       * --compiler.warn-xml-class-has-changed
+      * --compiler.warn-this-within-closure
       * </pre>
       * 
       * @param warningCode warning code, one of:
@@ -198,6 +199,7 @@ public interface ICompilerProblemSettings
       * <li> WARN_SLOW_TEXTFIELD_ADDITION
       * <li> WARN_UNLIKELY_FUNCTION_VALUE
       * <li> WARN_XML_CLASS_HAS_CHANGED
+      * <li> WARN_THIS_WITHIN_CLOSURE
       * </ul>
       * </p>
       */
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
index 71a39ec..3dd99ce 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/config/ICompilerSettingsConstants.java
@@ -51,6 +51,7 @@ public interface ICompilerSettingsConstants
     static final String DEFAULT_BACKGROUND_COLOR                             = "--default-background-color";
     static final String DEBUG_PASSWORD                                       = "--debug-password";
     static final String SWF_VERSION                                          = "--swf-version";
+    static final String COMPILER_WARN_THIS_WITHIN_CLOSURE                    = "--compiler.warn-this-within-closure";
     static final String COMPILER_WARN_XML_CLASS_HAS_CHANGED                  = "--compiler.warn-xml-class-has-changed";
     static final String COMPILER_WARN_UNLIKELY_FUNCTION_VALUE                = "--compiler.warn-unlikely-function-value";
     static final String COMPILER_WARN_SLOW_TEXT_FIELD_ADDITION               = "--compiler.warn-slow-text-field-addition";
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java b/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
index 99db8ef..2b6b337 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/constants/IASWarningConstants.java
@@ -209,4 +209,9 @@ public interface IASWarningConstants
      * Possible usage of the ActionScript 2.0 <code>XML</code> class.
      */
     static final int XML_CLASS_HAS_CHANGED = 3573;
+
+    /**
+     * Keyword this within closure.
+     */
+    static final int THIS_WITHIN_CLOSURE = 20000;
 }
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
index 868293f..3bdc442 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/CompilerProblemSettings.java
@@ -213,6 +213,9 @@ public class CompilerProblemSettings implements ICompilerProblemSettings
         case ICompilerSettings.WARN_XML_CLASS_HAS_CHANGED:
             warning = configuration.warn_xml_class_has_changed();
             break;
+        case ICompilerSettings.WARN_THIS_WITHIN_CLOSURE:
+            warning = configuration.warn_this_within_closure();
+            break;
         }
         
         return warning;
diff --git a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
index 4bc7e75..054de47 100644
--- a/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/internal/config/ICompilerSettings.java
@@ -547,6 +547,11 @@ public interface ICompilerSettings extends IWriteOnlyProjectSettings
      * Possible usage of the ActionScript 2.0 <code>XML</code> class.
      */
     int WARN_XML_CLASS_HAS_CHANGED = IASWarningConstants.XML_CLASS_HAS_CHANGED;
+
+    /**
+     * Keyword this within closure.
+     */
+    int WARN_THIS_WITHIN_CLOSURE = IASWarningConstants.THIS_WITHIN_CLOSURE;
      
     /**
      * Enables checking of the following ActionScript warnings:
@@ -588,6 +593,7 @@ public interface ICompilerSettings extends IWriteOnlyProjectSettings
      * --compiler.warn-slow-text-field-addition
      * --compiler.warn-unlikely-function-value
      * --compiler.warn-xml-class-has-changed
+     * --compiler.warn-this-within-closure
      * </pre>
      * 
      * @param warningCode Warning code.
@@ -629,6 +635,7 @@ public interface ICompilerSettings extends IWriteOnlyProjectSettings
      * @see #WARN_SLOW_TEXTFIELD_ADDITION
      * @see #WARN_UNLIKELY_FUNCTION_VALUE
      * @see #WARN_XML_CLASS_HAS_CHANGED
+     * @see #WARN_THIS_WITHIN_CLOSURE
      */
     void checkActionScriptWarning(int warningCode, boolean b);
 
diff --git a/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java b/compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
similarity index 96%
rename from compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
rename to compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
index 8a2dc28..28ef5df 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
+++ b/compiler-common/src/main/java/org/apache/royale/compiler/problems/ThisUsedInClosureProblem.java
@@ -29,6 +29,8 @@ public final class ThisUsedInClosureProblem extends SemanticWarningProblem
 {
     public static final String DESCRIPTION =
         "Encountered ${THIS} keyword within closure. Value of ${THIS} will not be the same as enclosing scope.";
+    
+    public static final int warningCode = 20000;
 
     public ThisUsedInClosureProblem(IASNode site)
     {


[royale-compiler] 01/06: JSWriter: externs are not post-processed like regular JS

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

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

commit a73451c4fdce3075c89ee13bf13bd8dc2982bd27
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Wed Sep 11 10:03:48 2019 -0700

    JSWriter: externs are not post-processed like regular JS
    
    Fixes issue where goog.require() was added for XML in externs (references #95)
    
    (cherry picked from commit 53745e586bb5bf95bf6b36d6bffc5c90ab847b4c)
---
 .../org/apache/royale/compiler/internal/codegen/js/JSWriter.java  | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
index 6773d23..376bcba 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
@@ -99,7 +99,13 @@ public class JSWriter implements IJSWriter
         
         try
         {
-            jsOut.write(emitter.postProcess(writer.toString()).getBytes("utf8"));
+            String emitted = writer.toString();
+            if(!isExterns)
+            {
+                //nothing to post-process in externs
+                emitted = emitter.postProcess(emitted);
+            }
+            jsOut.write(emitted.getBytes("utf8"));
         }
         catch (IOException e)
         {


[royale-compiler] 05/06: compiler: more end line/column improvements

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

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

commit d941f263ca03890f84c3599cadc4407b966f6b0f
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Fri Sep 13 13:32:58 2019 -0700

    compiler: more end line/column improvements
    
    (cherry picked from commit f72da6033d17ae0acf9ec047882adafae186d656)
---
 .../compiler/internal/definitions/VectorInformation.java  |  4 ++--
 .../royale/compiler/internal/parsing/as/BaseASParser.java |  2 +-
 .../compiler/internal/tree/as/BinaryOperatorNodeBase.java |  2 +-
 .../royale/compiler/internal/tree/as/ClassNode.java       |  4 ++--
 .../royale/compiler/internal/tree/as/FunctionNode.java    |  4 ++--
 .../internal/tree/as/NamespaceAccessExpressionNode.java   |  2 +-
 .../internal/tree/as/NamespaceIdentifierNode.java         |  2 +-
 .../apache/royale/compiler/internal/tree/as/NodeBase.java | 15 +++++++++++++++
 .../royale/compiler/internal/tree/as/ParameterNode.java   |  2 +-
 .../compiler/internal/tree/as/UnaryOperatorNodeBase.java  |  2 +-
 .../compiler/internal/tree/as/UseNamespaceNode.java       |  2 +-
 .../royale/compiler/internal/tree/mxml/MXMLNodeBase.java  |  1 +
 12 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/VectorInformation.java b/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/VectorInformation.java
index d83b27a..1310790 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/VectorInformation.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/definitions/VectorInformation.java
@@ -198,14 +198,14 @@ class VectorInformation
         //add the fixed getter/setter pair
         GetterNode fixGetter = new GetterNode(null, null, new IdentifierNode("fixed"));
         NamespaceIdentifierNode pub = new NamespaceIdentifierNode(INamespaceConstants.public_);
-        pub.span(-1, -1, -1, -1);
+        pub.span(-1, -1, -1, -1, -1, -1);
         fixGetter.setNamespace(pub);
         fixGetter.setType(null, new IdentifierNode(IASLanguageConstants.Boolean));
         retVal[2] = fixGetter;
 
         SetterNode fixSetter = new SetterNode(null, null, new IdentifierNode("fixed"));
         pub = new NamespaceIdentifierNode(INamespaceConstants.public_);
-        pub.span(-1, -1, -1, -1);
+        pub.span(-1, -1, -1, -1, -1, -1);
         fixSetter.setNamespace(pub);
         fixSetter.setType(null, new IdentifierNode(IASLanguageConstants.void_));
         ParameterNode value = new ParameterNode(new IdentifierNode("value"));
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
index a9a5e91..62bdaee 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/parsing/as/BaseASParser.java
@@ -1573,7 +1573,7 @@ abstract class BaseASParser extends LLkParser implements IProblemReporter
         }
         else
         {
-            block.span(blockToken.getStart() + 1, blockToken.getStart() + 1, blockToken.getLine(), blockToken.getColumn());
+            block.span(blockToken.getStart() + 1, blockToken.getStart() + 1, blockToken.getLine(), blockToken.getColumn(), blockToken.getLine(), blockToken.getColumn());
         }
     }
 
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java
index d51c82d..03dae65 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/BinaryOperatorNodeBase.java
@@ -282,7 +282,7 @@ public abstract class BinaryOperatorNodeBase extends OperatorNodeBase implements
     protected void fillInOffsets()
     {
         if (rightOperandNode == null && leftOperandNode == null && operatorStart != -1)
-            span(operatorStart, operatorStart + 1, -1, -1);
+            span(operatorStart, operatorStart + 1, -1, -1, -1, -1);
         else
             super.fillInOffsets();
     }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ClassNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ClassNode.java
index bfc65ba..484f0a8 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ClassNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ClassNode.java
@@ -513,10 +513,10 @@ public class ClassNode extends MemberedNode implements IClassNode
             // so we'll create one and add it to the ClassNode
             IdentifierNode constructorNameNode = new IdentifierNode(getName());
             constructorNameNode.setReferenceValue(getDefinition());
-            constructorNameNode.span(getNameAbsoluteStart(), getNameAbsoluteEnd(), -1, -1);
+            constructorNameNode.span(getNameAbsoluteStart(), getNameAbsoluteEnd(), -1, -1, -1, -1);
             defaultConstructorNode = new FunctionNode(null, constructorNameNode);
             NamespaceIdentifierNode pub = new NamespaceIdentifierNode(INamespaceConstants.public_);
-            pub.span(-1, -1, -1, -1);
+            pub.span(-1, -1, -1, -1, -1, -1);
             defaultConstructorNode.setNamespace(pub);
             defaultConstructorNode.normalize(true);
             defaultConstructorNode.setParent(contentsNode);
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
index 64c0b2b..54c836c 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/FunctionNode.java
@@ -384,7 +384,7 @@ public class FunctionNode extends BaseTypedDefinitionNode implements IFunctionNo
                     // metadata, the constructor should be considered private
                     // and we should generate a fake namespace node
                     NamespaceIdentifierNode priv = new NamespaceIdentifierNode(INamespaceConstants.private_);
-                    priv.span(-1, -1, -1, -1);
+                    priv.span(-1, -1, -1, -1, -1, -1);
                     priv.setDecorationTarget(this);
                     return priv;
                 }
@@ -392,7 +392,7 @@ public class FunctionNode extends BaseTypedDefinitionNode implements IFunctionNo
             // if there is no namespace node, the namespace defaults to public
             // and we'll generate a fake node
             NamespaceIdentifierNode pub = new NamespaceIdentifierNode(INamespaceConstants.public_);
-            pub.span(-1, -1, -1, -1);
+            pub.span(-1, -1, -1, -1, -1, -1);
             pub.setDecorationTarget(this);
             return pub;
         }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceAccessExpressionNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceAccessExpressionNode.java
index 175f500..ae8e987 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceAccessExpressionNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceAccessExpressionNode.java
@@ -41,7 +41,7 @@ public class NamespaceAccessExpressionNode extends BinaryOperatorNodeBase implem
     {
         super(operator, left instanceof IdentifierNode ? new NamespaceIdentifierNode((IdentifierNode)left) : left, right);
         
-        leftOperandNode.span(left.getAbsoluteStart(), left.getAbsoluteEnd(), left.getLine(), left.getColumn());
+        leftOperandNode.span(left.getAbsoluteStart(), left.getAbsoluteEnd(), left.getLine(), left.getColumn(), left.getEndLine(), left.getEndColumn());
     }
 
     /**
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceIdentifierNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceIdentifierNode.java
index bd74fd2..05238a9 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceIdentifierNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NamespaceIdentifierNode.java
@@ -79,7 +79,7 @@ public class NamespaceIdentifierNode extends IdentifierNode implements INamespac
     {
         super(node.getName());
         
-        span(node.getAbsoluteStart(), node.getAbsoluteEnd(), node.getLine(), node.getColumn());
+        span(node.getAbsoluteStart(), node.getAbsoluteEnd(), node.getLine(), node.getColumn(), node.getEndLine(), node.getEndColumn());
         setSourcePath(node.getSourcePath());
     }
 
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NodeBase.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NodeBase.java
index d4d9941..eef182f 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NodeBase.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/NodeBase.java
@@ -483,13 +483,28 @@ public abstract class NodeBase extends SourceLocation implements IASNode
      * @param start start offset for the node
      * @param end end offset for the node
      * @param line line number for the node
+     * @deprecated Use span(int,int,int,int,int,int) instead so that endLine and endColumn are included
      */
     public final void span(int start, int end, int line, int column)
     {
+        span(start, end, line, column, -1, -1);
+    }
+
+    /**
+     * Set the start and end offsets of the node. Used during parsing.
+     * 
+     * @param start start offset for the node
+     * @param end end offset for the node
+     * @param line line number for the node
+     */
+    public final void span(int start, int end, int line, int column, int endLine, int endColumn)
+    {
         setStart(start);
         setEnd(end);
         setLine(line);
         setColumn(column);
+        setEndLine(endLine);
+        setEndColumn(endColumn);
     }
 
     public Collection<ICompilerProblem> runPostProcess(EnumSet<PostProcessStep> set, ASScope containingScope)
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ParameterNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ParameterNode.java
index 51b209c..93efc2f 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ParameterNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/ParameterNode.java
@@ -172,7 +172,7 @@ public final class ParameterNode extends BaseVariableNode implements IParameterN
         if (typeNode == null && isRest())
         {
             typeNode = new IdentifierNode(IASLanguageConstants.Array);
-            typeNode.span(-1, -1, -1, -1);
+            typeNode.span(-1, -1, -1, -1, -1, -1);
             return;
         }
         
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UnaryOperatorNodeBase.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UnaryOperatorNodeBase.java
index 5145924..be92a12 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UnaryOperatorNodeBase.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UnaryOperatorNodeBase.java
@@ -148,7 +148,7 @@ public abstract class UnaryOperatorNodeBase extends OperatorNodeBase implements
     {
         if (operandNode == null && operatorStart != -1)
         {
-            span(operatorStart, operatorStart + 1, -1, -1);
+            span(operatorStart, operatorStart + 1, -1, -1, -1, -1);
         }
         else
         {
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UseNamespaceNode.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UseNamespaceNode.java
index 8ce1130..51a3d29 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UseNamespaceNode.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/as/UseNamespaceNode.java
@@ -123,7 +123,7 @@ public class UseNamespaceNode extends FixedChildrenNode implements IUseNamespace
             {
                 namespaceNode = new NamespaceIdentifierNode(((IIdentifierNode)namespace).getName());
                 ((NodeBase)namespaceNode).setSourcePath(namespace.getSourcePath());
-                ((NodeBase)namespaceNode).span(namespace.getAbsoluteStart(), namespace.getAbsoluteEnd(), namespace.getLine(), namespace.getColumn());
+                ((NodeBase)namespaceNode).span(namespace.getAbsoluteStart(), namespace.getAbsoluteEnd(), namespace.getLine(), namespace.getColumn(), namespace.getEndLine(), namespace.getEndColumn());
             }
         }
     }
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLNodeBase.java b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLNodeBase.java
index 4909e2e..b511f63 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLNodeBase.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/tree/mxml/MXMLNodeBase.java
@@ -689,6 +689,7 @@ public abstract class MXMLNodeBase extends NodeBase implements IMXMLNode
      * @param end The ending offset of this node.
      * @param line The number of the line on which this node starts.
      * @param column This number of the column at which this node starts.
+     * @deprecated Use setLocation(String,int,int,int,int,int,int) instead
      */
     public void setLocation(String sourcePath, int start, int end, int line, int column)
     {