diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/HasArguments.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/HasArguments.java index 29b12859174..2cb67b4c3fd 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/HasArguments.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/HasArguments.java @@ -9,6 +9,6 @@ import java.util.List; /** * Implemented by JavaScript objects that accept arguments. */ -public interface HasArguments extends JsExpression { +public interface HasArguments { List getArguments(); } diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java index 5d001275b54..ec9971d8bb3 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; /** * Represents a javascript expression for array access. */ -public final class JsArrayAccess extends JsExpressionImpl { +public final class JsArrayAccess extends JsExpression { private JsExpression arrayExpression; private JsExpression indexExpression; diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java index 5594d30c2aa..2aef8e1a89c 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java @@ -8,7 +8,7 @@ import com.google.dart.compiler.util.AstUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public final class JsBinaryOperation extends JsExpressionImpl { +public final class JsBinaryOperation extends JsExpression { private JsExpression arg1; private JsExpression arg2; diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java index b99b099181e..b6618c154d1 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java @@ -7,7 +7,7 @@ package com.google.dart.compiler.backend.js.ast; import com.google.dart.compiler.util.AstUtil; import org.jetbrains.annotations.NotNull; -public final class JsConditional extends JsExpressionImpl { +public final class JsConditional extends JsExpression { private JsExpression testExpression; private JsExpression elseExpression; private JsExpression thenExpression; diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java index 55cd155f41b..a5dde757efa 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; import java.util.Map; -public class JsDocComment extends JsExpressionImpl { +public class JsDocComment extends JsExpression { private final Map tags; public JsDocComment(Map tags) { diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java deleted file mode 100644 index c99964222f7..00000000000 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2010-2014 JetBrains s.r.o. - * - * Licensed 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 com.google.dart.compiler.backend.js.ast; - -import org.jetbrains.annotations.NotNull; - -public class JsEmptyExpression extends JsExpressionImpl { - - JsEmptyExpression() { - } - - @Override - @NotNull - public JsStatement makeStmt() { - return JsEmpty.INSTANCE; - } - - @Override - public void accept(JsVisitor visitor) { - throw new IllegalArgumentException("empty expression should not be here during generating Javascript code"); - } - - @Override - public void traverse(JsVisitorWithContext visitor, JsContext ctx) { - throw new IllegalArgumentException("empty expression should not be here during generating Javascript code"); - } - - @NotNull - @Override - public JsEmptyExpression deepCopy() { - return new JsEmptyExpression(); - } -} diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java index bf20bec3d4a..f3908b0ba6a 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java @@ -1,17 +1,50 @@ +// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + package com.google.dart.compiler.backend.js.ast; import org.jetbrains.annotations.NotNull; -public interface JsExpression extends JsNode { - boolean isLeaf(); +import java.util.List; + +public abstract class JsExpression extends SourceInfoAwareJsNode { + /** + * Determines whether or not this expression is a leaf, such as a + * {@link JsNameRef}, {@link JsLiteral.JsBooleanLiteral}, and so on. Leaf expressions + * never need to be parenthesized. + */ + public boolean isLeaf() { + // Conservatively say that it isn't a leaf. + // Individual subclasses can speak for themselves if they are a leaf. + return false; + } @NotNull - JsStatement makeStmt(); + public JsStatement makeStmt() { + return new JsExpressionStatement(this); + } + + protected abstract static class JsExpressionHasArguments extends JsExpression implements HasArguments { + protected final List arguments; + + public JsExpressionHasArguments(List arguments) { + this.arguments = arguments; + } + + @Override + public List getArguments() { + return arguments; + } + } @Override - JsExpression source(Object info); + public JsExpression source(Object info) { + setSource(info); + return this; + } @NotNull @Override - JsExpression deepCopy(); + public abstract JsExpression deepCopy(); } diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java deleted file mode 100644 index d26bc03f2a6..00000000000 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionImpl.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -package com.google.dart.compiler.backend.js.ast; - -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -abstract class JsExpressionImpl extends SourceInfoAwareJsNode implements JsExpression { - /** - * Determines whether or not this expression is a leaf, such as a - * {@link JsNameRef}, {@link JsLiteral.JsBooleanLiteral}, and so on. Leaf expressions - * never need to be parenthesized. - */ - @Override - public boolean isLeaf() { - // Conservatively say that it isn't a leaf. - // Individual subclasses can speak for themselves if they are a leaf. - return false; - } - - @Override - @NotNull - public JsStatement makeStmt() { - return new JsExpressionStatement(this); - } - - protected abstract static class JsExpressionHasArguments extends JsExpressionImpl implements HasArguments { - protected final List arguments; - - public JsExpressionHasArguments(List arguments) { - this.arguments = arguments; - } - - @Override - public List getArguments() { - return arguments; - } - } - - @Override - public JsExpression source(Object info) { - setSource(info); - return this; - } -} diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java index cddd0da65af..e76add545ad 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArguments { +public final class JsInvocation extends JsExpression.JsExpressionHasArguments { @NotNull private JsExpression qualifier; diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java index 13d77faf31c..078a6171b8f 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java @@ -6,7 +6,7 @@ package com.google.dart.compiler.backend.js.ast; import org.jetbrains.annotations.NotNull; -public abstract class JsLiteral extends JsExpressionImpl { +public abstract class JsLiteral extends JsExpression { public static final JsValueLiteral THIS = new JsThisRef(); public static final JsNameRef UNDEFINED = new JsNameRef("undefined"); diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java index 26febe16140..9bdb7bf498a 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java @@ -12,7 +12,7 @@ import org.jetbrains.annotations.Nullable; /** * Represents a JavaScript expression that references a name. */ -public final class JsNameRef extends JsExpressionImpl implements HasName { +public final class JsNameRef extends JsExpression implements HasName { private String ident; private JsName name; private JsExpression qualifier; diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java index aa8f3b2638d..43ac4e29ceb 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; import java.util.List; -public final class JsNew extends JsExpressionImpl.JsExpressionHasArguments { +public final class JsNew extends JsExpression.JsExpressionHasArguments { private JsExpression constructorExpression; public JsNew(JsExpression constructorExpression) { diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java index 82cd1743515..ca9df83077d 100644 --- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java +++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsUnaryOperation.java @@ -4,7 +4,7 @@ package com.google.dart.compiler.backend.js.ast; -public abstract class JsUnaryOperation extends JsExpressionImpl { +public abstract class JsUnaryOperation extends JsExpression { private JsExpression arg; diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/ExpressionDecomposer.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/ExpressionDecomposer.kt index 31108f19392..50f5987e2d7 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/ExpressionDecomposer.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/ExpressionDecomposer.kt @@ -21,7 +21,6 @@ import com.google.dart.compiler.backend.js.ast.metadata.* import com.intellij.util.SmartList import org.jetbrains.kotlin.js.inline.util.IdentitySet import org.jetbrains.kotlin.js.translate.utils.JsAstUtils -import org.jetbrains.kotlin.js.inline.util.canHaveOwnSideEffect import org.jetbrains.kotlin.js.inline.util.rewriters.ContinueReplacingVisitor import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.* import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.* @@ -296,14 +295,14 @@ internal class ExpressionDecomposer private constructor( // Qualifier might be a reference to lambda property. See KT-7674 // An exception here is `fn.call()`, which are marked as side effect free. Further recognition of such // case in inliner might be quite difficult, so never extract such call (and other calls marked this way). - if ((qualifier as? HasMetadata)?.sideEffects == SideEffectKind.PURE && - callee != null && receiver != null && receiver in containsNodeWithSideEffect + if (qualifier.sideEffects == SideEffectKind.PURE && callee != null && receiver != null && + receiver in containsNodeWithSideEffect ) { val receiverTmp = receiver.extractToTemporary() callee.qualifier = receiverTmp } else { - if (receiver != null && callee != null && applyBindIfNecessary) { + if (receiver != null && applyBindIfNecessary) { val receiverTmp = receiver.extractToTemporary() qualifier = JsAstUtils.invokeBind(receiverTmp, pureFqn(callee.ident, receiverTmp)) } diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/sideEffectUtils.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/sideEffectUtils.kt index 8bdd5b8c15f..bcd95404fe4 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/sideEffectUtils.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/inline/util/sideEffectUtils.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.js.inline.util import com.google.dart.compiler.backend.js.ast.* -import com.google.dart.compiler.backend.js.ast.metadata.HasMetadata import com.google.dart.compiler.backend.js.ast.metadata.SideEffectKind import com.google.dart.compiler.backend.js.ast.metadata.sideEffects import org.jetbrains.kotlin.js.translate.utils.jsAstUtils.any @@ -30,6 +29,5 @@ fun JsExpression.canHaveOwnSideEffect(vars: Set) = when (this) { is JsLiteral -> false is JsBinaryOperation -> operator.isAssignment is JsNameRef -> name !in vars && sideEffects != SideEffectKind.PURE - is HasMetadata -> sideEffects != SideEffectKind.PURE - else -> true + else -> sideEffects != SideEffectKind.PURE } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt index fc2fbf7848d..c53883de5b9 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/callTranslator/CallInfoExtensions.kt @@ -18,10 +18,12 @@ package org.jetbrains.kotlin.js.translate.callTranslator import com.google.dart.compiler.backend.js.ast.JsExpression import com.google.dart.compiler.backend.js.ast.JsName -import com.google.dart.compiler.backend.js.ast.metadata.HasMetadata import com.google.dart.compiler.backend.js.ast.metadata.SideEffectKind import com.google.dart.compiler.backend.js.ast.metadata.sideEffects -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor import org.jetbrains.kotlin.js.translate.context.TranslationContext import org.jetbrains.kotlin.js.translate.reference.ReferenceTranslator @@ -84,7 +86,7 @@ fun VariableAccessInfo.constructAccessExpression(ref: JsExpression): JsExpressio // This is useful when passing AST to TemporaryAssignmentElimination. It can bring // property assignment like `obj.propertyName = $tmp` to places where `$tmp` gets its value, // but only when it's sure that no side effects possible. - (ref as? HasMetadata)?.let { it.sideEffects = SideEffectKind.PURE } + ref.sideEffects = SideEffectKind.PURE JsAstUtils.assignment(ref, value!!) } } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java index 128ef0f5944..2d154c5896f 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/context/StaticContext.java @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.js.translate.context; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.dart.compiler.backend.js.ast.*; -import com.google.dart.compiler.backend.js.ast.metadata.HasMetadata; import com.google.dart.compiler.backend.js.ast.metadata.MetadataProperties; import com.google.dart.compiler.backend.js.ast.metadata.SideEffectKind; import com.intellij.openapi.util.Factory; @@ -619,13 +618,11 @@ public final class StaticContext { } private static JsExpression applySideEffects(JsExpression expression, DeclarationDescriptor descriptor) { - if (expression instanceof HasMetadata) { - if (descriptor instanceof FunctionDescriptor || - descriptor instanceof PackageFragmentDescriptor || - descriptor instanceof ClassDescriptor - ) { - MetadataProperties.setSideEffects((HasMetadata) expression, SideEffectKind.PURE); - } + if (descriptor instanceof FunctionDescriptor || + descriptor instanceof PackageFragmentDescriptor || + descriptor instanceof ClassDescriptor + ) { + MetadataProperties.setSideEffects(expression, SideEffectKind.PURE); } return expression; } diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/ReferenceTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/ReferenceTranslator.java index 08df8c33695..86dc1c42f71 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/ReferenceTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/ReferenceTranslator.java @@ -20,7 +20,6 @@ import com.google.dart.compiler.backend.js.ast.JsExpression; import com.google.dart.compiler.backend.js.ast.JsInvocation; import com.google.dart.compiler.backend.js.ast.JsName; import com.google.dart.compiler.backend.js.ast.JsNameRef; -import com.google.dart.compiler.backend.js.ast.metadata.HasMetadata; import com.google.dart.compiler.backend.js.ast.metadata.MetadataProperties; import com.google.dart.compiler.backend.js.ast.metadata.SideEffectKind; import org.jetbrains.annotations.NotNull; diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsAstUtils.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsAstUtils.java index da1d7e5959b..fa05600585e 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsAstUtils.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/utils/JsAstUtils.java @@ -28,13 +28,12 @@ import org.jetbrains.kotlin.js.translate.context.TranslationContext; import org.jetbrains.kotlin.types.expressions.OperatorConventions; import org.jetbrains.kotlin.util.OperatorNameConventions; -import java.util.Arrays; import java.util.Collections; import java.util.List; public final class JsAstUtils { private static final JsNameRef DEFINE_PROPERTY = pureFqn("defineProperty", null); - public static final JsNameRef CREATE_OBJECT = pureFqn("create", null); + private static final JsNameRef CREATE_OBJECT = pureFqn("create", null); private static final JsNameRef VALUE = new JsNameRef("value"); private static final JsPropertyInitializer WRITABLE = new JsPropertyInitializer(pureFqn("writable", null), JsLiteral.TRUE); @@ -205,11 +204,6 @@ public final class JsAstUtils { return invokeMethod(Namer.kotlinLong(), Namer.LONG_FROM_NUMBER, expression); } - @NotNull - public static JsExpression equalsForObject(@NotNull JsExpression left, @NotNull JsExpression right) { - return invokeMethod(left, Namer.EQUALS_METHOD_NAME, right); - } - @NotNull public static JsExpression compareForObject(@NotNull JsExpression left, @NotNull JsExpression right) { return invokeMethod(left, Namer.COMPARE_TO_METHOD_NAME, right); @@ -267,7 +261,7 @@ public final class JsAstUtils { return new JsBinaryOperation(JsBinaryOperator.OR, op1, op2); } - public static void setQualifier(@NotNull JsExpression selector, @Nullable JsExpression receiver) { + private static void setQualifier(@NotNull JsExpression selector, @Nullable JsExpression receiver) { assert (selector instanceof JsInvocation || selector instanceof JsNameRef); if (selector instanceof JsInvocation) { setQualifier(((JsInvocation) selector).getQualifier(), receiver); @@ -398,16 +392,6 @@ public final class JsAstUtils { return new JsVars(new JsVars.JsVar(name, expr)); } - public static void setArguments(@NotNull HasArguments invocation, @NotNull List newArgs) { - List arguments = invocation.getArguments(); - assert arguments.isEmpty() : "Arguments already set."; - arguments.addAll(newArgs); - } - - public static void setArguments(@NotNull HasArguments invocation, JsExpression... arguments) { - setArguments(invocation, Arrays.asList(arguments)); - } - public static void setParameters(@NotNull JsFunction function, @NotNull List newParams) { List parameters = function.getParameters(); assert parameters.isEmpty() : "Arguments already set.";