code cleanup for JS modules
This commit is contained in:
@@ -30,6 +30,6 @@ public enum class PredefinedAnnotation(fqName: String) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// TODO: replace with straight assignment when KT-5761 will be fixed
|
// TODO: replace with straight assignment when KT-5761 will be fixed
|
||||||
val WITH_CUSTOM_NAME by Delegates.lazy { setOf(LIBRARY, NATIVE) }
|
val WITH_CUSTOM_NAME by lazy { setOf(LIBRARY, NATIVE) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.diagnostics.rendering.DiagnosticFactoryToRendererMap
|
|||||||
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
import org.jetbrains.kotlin.diagnostics.rendering.Renderers
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
private val DIAGNOSTIC_FACTORY_TO_RENDERER by Delegates.lazy {
|
private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||||
with(DiagnosticFactoryToRendererMap()) {
|
with(DiagnosticFactoryToRendererMap()) {
|
||||||
|
|
||||||
put(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN,
|
put(ErrorsJs.NATIVE_ANNOTATIONS_ALLOWED_ONLY_ON_MEMBER_OR_EXTENSION_FUN,
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ class ExpressionDecomposer private constructor(
|
|||||||
private inner class Temporary(val value: JsExpression? = null) {
|
private inner class Temporary(val value: JsExpression? = null) {
|
||||||
val name: JsName = scope.declareTemporary()
|
val name: JsName = scope.declareTemporary()
|
||||||
|
|
||||||
val variable: JsVars by Delegates.lazy {
|
val variable: JsVars by lazy {
|
||||||
newVar(name, value)
|
newVar(name, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ private constructor(
|
|||||||
var thisReplacement = getThisReplacement(call)
|
var thisReplacement = getThisReplacement(call)
|
||||||
if (thisReplacement == null || thisReplacement is JsLiteral.JsThisRef) return
|
if (thisReplacement == null || thisReplacement is JsLiteral.JsThisRef) return
|
||||||
|
|
||||||
if (thisReplacement!!.needToAlias()) {
|
if (thisReplacement.needToAlias()) {
|
||||||
val thisName = namingContext.getFreshName(getThisAlias())
|
val thisName = namingContext.getFreshName(getThisAlias())
|
||||||
namingContext.newVar(thisName, thisReplacement)
|
namingContext.newVar(thisName, thisReplacement)
|
||||||
thisReplacement = thisName.makeRef()
|
thisReplacement = thisName.makeRef()
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceThisReference(body, thisReplacement!!)
|
replaceThisReference(body, thisReplacement)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun removeStatementsAfterTopReturn() {
|
private fun removeStatementsAfterTopReturn() {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ private fun isNameInitialized(
|
|||||||
val expr = (lastThenStmt as? JsExpressionStatement)?.getExpression()
|
val expr = (lastThenStmt as? JsExpressionStatement)?.getExpression()
|
||||||
if (expr !is JsBinaryOperation) return false
|
if (expr !is JsBinaryOperation) return false
|
||||||
|
|
||||||
val op = expr.getOperator()!!
|
val op = expr.getOperator()
|
||||||
if (!op.isAssignment()) return false
|
if (!op.isAssignment()) return false
|
||||||
|
|
||||||
val arg1 = expr.getArg1()
|
val arg1 = expr.getArg1()
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ abstract class FunctionContext(
|
|||||||
|
|
||||||
/** in case 4, 5 get ref (reduce 4, 5 to 2, 3 accordingly) */
|
/** in case 4, 5 get ref (reduce 4, 5 to 2, 3 accordingly) */
|
||||||
if (callQualifier is JsNameRef) {
|
if (callQualifier is JsNameRef) {
|
||||||
val staticRef = (callQualifier as JsNameRef).getName()?.staticRef
|
val staticRef = callQualifier.getName()?.staticRef
|
||||||
|
|
||||||
callQualifier = when (staticRef) {
|
callQualifier = when (staticRef) {
|
||||||
is JsNameRef -> staticRef
|
is JsNameRef -> staticRef
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.js.inline.context
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsContext
|
import com.google.dart.compiler.backend.js.ast.JsContext
|
||||||
import com.google.dart.compiler.backend.js.ast.JsStatement
|
import com.google.dart.compiler.backend.js.ast.JsStatement
|
||||||
|
|
||||||
trait InliningContext {
|
interface InliningContext {
|
||||||
public val statementContext: JsContext<JsStatement>
|
public val statementContext: JsContext<JsStatement>
|
||||||
public val functionContext: FunctionContext
|
public val functionContext: FunctionContext
|
||||||
|
|
||||||
|
|||||||
@@ -47,14 +47,14 @@ public fun getSimpleIdent(call: JsInvocation): String? {
|
|||||||
qualifiers@ while (qualifier != null) {
|
qualifiers@ while (qualifier != null) {
|
||||||
when (qualifier) {
|
when (qualifier) {
|
||||||
is JsInvocation -> {
|
is JsInvocation -> {
|
||||||
val callableQualifier = qualifier as JsInvocation
|
val callableQualifier = qualifier
|
||||||
qualifier = callableQualifier.getQualifier()
|
qualifier = callableQualifier.getQualifier()
|
||||||
|
|
||||||
if (isCallInvocation(callableQualifier)) {
|
if (isCallInvocation(callableQualifier)) {
|
||||||
qualifier = (qualifier as? JsNameRef)?.getQualifier()
|
qualifier = (qualifier as? JsNameRef)?.getQualifier()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is HasName -> return (qualifier as HasName).getName()?.getIdent()
|
is HasName -> return qualifier.getName()?.getIdent()
|
||||||
else -> break@qualifiers
|
else -> break@qualifiers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.kotlin.serialization.DescriptorSerializer
|
|||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
|
|
||||||
public object ClassSerializationUtil {
|
public object ClassSerializationUtil {
|
||||||
public trait Sink {
|
public interface Sink {
|
||||||
fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class)
|
fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import com.google.dart.compiler.backend.js.ast.JsLiteral
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsConditional
|
import com.google.dart.compiler.backend.js.ast.JsConditional
|
||||||
import com.google.dart.compiler.backend.js.ast.JsBlock
|
import com.google.dart.compiler.backend.js.ast.JsBlock
|
||||||
|
|
||||||
trait CallInfo {
|
interface CallInfo {
|
||||||
val context: TranslationContext
|
val context: TranslationContext
|
||||||
val resolvedCall: ResolvedCall<out CallableDescriptor>
|
val resolvedCall: ResolvedCall<out CallableDescriptor>
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ fun TranslationContext.getCallInfo(resolvedCall: ResolvedCall<out FunctionDescri
|
|||||||
var receiverRef = explicitReceivers.extensionReceiver
|
var receiverRef = explicitReceivers.extensionReceiver
|
||||||
if (receiverRef != null) {
|
if (receiverRef != null) {
|
||||||
receiverRef = this.declareTemporary(null).reference()
|
receiverRef = this.declareTemporary(null).reference()
|
||||||
this.addStatementToCurrentBlock(JsAstUtils.assignment(receiverRef!!, explicitReceivers.extensionReceiver!!).makeStmt())
|
this.addStatementToCurrentBlock(JsAstUtils.assignment(receiverRef, explicitReceivers.extensionReceiver!!).makeStmt())
|
||||||
}
|
}
|
||||||
ExplicitReceivers(receiverOrThisRef, receiverRef)
|
ExplicitReceivers(receiverOrThisRef, receiverRef)
|
||||||
}
|
}
|
||||||
@@ -138,11 +138,11 @@ private fun TranslationContext.createCallInfo(resolvedCall: ResolvedCall<out Cal
|
|||||||
when (resolvedCall.getExplicitReceiverKind()) {
|
when (resolvedCall.getExplicitReceiverKind()) {
|
||||||
BOTH_RECEIVERS, EXTENSION_RECEIVER -> {
|
BOTH_RECEIVERS, EXTENSION_RECEIVER -> {
|
||||||
notNullConditional = TranslationUtils.notNullConditional(extensionReceiver!!, JsLiteral.NULL, this)
|
notNullConditional = TranslationUtils.notNullConditional(extensionReceiver!!, JsLiteral.NULL, this)
|
||||||
extensionReceiver = notNullConditional!!.getThenExpression()
|
extensionReceiver = notNullConditional.getThenExpression()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
notNullConditional = TranslationUtils.notNullConditional(dispatchReceiver!!, JsLiteral.NULL, this)
|
notNullConditional = TranslationUtils.notNullConditional(dispatchReceiver!!, JsLiteral.NULL, this)
|
||||||
dispatchReceiver = notNullConditional!!.getThenExpression()
|
dispatchReceiver = notNullConditional.getThenExpression()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ fun VariableAccessInfo.getAccessFunctionName(): String {
|
|||||||
return context.getNameForDescriptor(propertyAccessorDescriptor!!).getIdent()
|
return context.getNameForDescriptor(propertyAccessorDescriptor!!).getIdent()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return Namer.getNameForAccessor(variableName.getIdent()!!, isGetAccess(), false)
|
return Namer.getNameForAccessor(variableName.getIdent(), isGetAccess(), false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -154,7 +154,7 @@ fun computeExplicitReceiversForInvoke(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait CallCase<I : CallInfo> {
|
interface CallCase<I : CallInfo> {
|
||||||
|
|
||||||
protected fun I.unsupported(message: String = "") : Nothing = throw IllegalStateException("this case unsupported. $this")
|
protected fun I.unsupported(message: String = "") : Nothing = throw IllegalStateException("this case unsupported. $this")
|
||||||
|
|
||||||
@@ -183,11 +183,11 @@ trait CallCase<I : CallInfo> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait FunctionCallCase : CallCase<FunctionCallInfo>
|
interface FunctionCallCase : CallCase<FunctionCallInfo>
|
||||||
|
|
||||||
trait VariableAccessCase : CallCase<VariableAccessInfo>
|
interface VariableAccessCase : CallCase<VariableAccessInfo>
|
||||||
|
|
||||||
trait DelegateIntrinsic<I : CallInfo> {
|
interface DelegateIntrinsic<I : CallInfo> {
|
||||||
fun I.canBeApply(): Boolean = true
|
fun I.canBeApply(): Boolean = true
|
||||||
fun I.getDescriptor(): CallableDescriptor
|
fun I.getDescriptor(): CallableDescriptor
|
||||||
fun I.getArgs(): List<JsExpression>
|
fun I.getArgs(): List<JsExpression>
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ class FileDeclarationVisitor(
|
|||||||
|
|
||||||
private val initializer = JsAstUtils.createFunctionWithEmptyBody(context.scope())
|
private val initializer = JsAstUtils.createFunctionWithEmptyBody(context.scope())
|
||||||
private val initializerContext = context.contextWithScope(initializer)
|
private val initializerContext = context.contextWithScope(initializer)
|
||||||
private val initializerStatements = initializer.getBody()!!.getStatements()!!
|
private val initializerStatements = initializer.getBody().getStatements()
|
||||||
private val initializerVisitor = InitializerVisitor(initializerStatements)
|
private val initializerVisitor = InitializerVisitor(initializerStatements)
|
||||||
|
|
||||||
fun computeInitializer(): JsFunction? {
|
fun computeInitializer(): JsFunction? {
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
|
|||||||
for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
|
for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
|
||||||
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||||
assert entryInitCall != null : "Entry init call must be not null";
|
assert entryInitCall != null : "Entry init call must be not null";
|
||||||
JsExpression entryInitializer = CallTranslator.INSTANCE$.translate(context(), entryInitCall, multiObjNameRef);
|
JsExpression entryInitializer = CallTranslator.translate(context(), entryInitCall, multiObjNameRef);
|
||||||
FunctionDescriptor candidateDescriptor = entryInitCall.getCandidateDescriptor();
|
FunctionDescriptor candidateDescriptor = entryInitCall.getCandidateDescriptor();
|
||||||
if (CallExpressionTranslator.shouldBeInlined(candidateDescriptor)) {
|
if (CallExpressionTranslator.shouldBeInlined(candidateDescriptor)) {
|
||||||
setInlineCallMetadata(entryInitializer, entry, entryInitCall, context());
|
setInlineCallMetadata(entryInitializer, entry, entryInitCall, context());
|
||||||
|
|||||||
+1
-1
@@ -46,7 +46,7 @@ public class ObjectIntrinsics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public trait ObjectIntrinsic {
|
public interface ObjectIntrinsic {
|
||||||
fun apply(context: TranslationContext): JsExpression
|
fun apply(context: TranslationContext): JsExpression
|
||||||
fun exists(): Boolean = true
|
fun exists(): Boolean = true
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -26,7 +26,7 @@ import gnu.trove.THashMap
|
|||||||
import com.google.dart.compiler.backend.js.ast.JsExpression
|
import com.google.dart.compiler.backend.js.ast.JsExpression
|
||||||
import com.google.common.collect.ImmutableSet
|
import com.google.common.collect.ImmutableSet
|
||||||
|
|
||||||
public trait BinaryOperationIntrinsic {
|
public interface BinaryOperationIntrinsic {
|
||||||
|
|
||||||
fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
|
fun apply(expression: JetBinaryExpression, left: JsExpression, right: JsExpression, context: TranslationContext): JsExpression
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ public class BinaryOperationIntrinsics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait BinaryOperationIntrinsicFactory {
|
interface BinaryOperationIntrinsicFactory {
|
||||||
|
|
||||||
public fun getSupportTokens(): ImmutableSet<out JetToken>
|
public fun getSupportTokens(): ImmutableSet<out JetToken>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -57,6 +57,6 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression overloadedMethodInvocation() {
|
private JsExpression overloadedMethodInvocation() {
|
||||||
return CallTranslator.INSTANCE$.translate(context(), resolvedCall, accessTranslator.translateAsGet());
|
return CallTranslator.translate(context(), resolvedCall, accessTranslator.translateAsGet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ public final class OverloadedIncrementTranslator extends IncrementTranslator {
|
|||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
protected JsExpression operationExpression(@NotNull JsExpression receiver) {
|
protected JsExpression operationExpression(@NotNull JsExpression receiver) {
|
||||||
return CallTranslator.INSTANCE$.translate(context(), resolvedCall, receiver);
|
return CallTranslator.translate(context(), resolvedCall, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ public final class UnaryOperationTranslator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCallWithAssert(expression, context.bindingContext());
|
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCallWithAssert(expression, context.bindingContext());
|
||||||
return CallTranslator.INSTANCE$.translate(context, resolvedCall, baseExpression);
|
return CallTranslator.translate(context, resolvedCall, baseExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isExclForBinaryEqualLikeExpr(@NotNull JetUnaryExpression expression, @NotNull JsExpression baseExpression) {
|
private static boolean isExclForBinaryEqualLikeExpr(@NotNull JetUnaryExpression expression, @NotNull JsExpression baseExpression) {
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ public class ArrayAccessTranslator extends AbstractTranslator implements AccessT
|
|||||||
if (!isGetter) {
|
if (!isGetter) {
|
||||||
context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
|
context = contextWithValueParameterAliasInArrayGetAccess(toSetTo);
|
||||||
}
|
}
|
||||||
return CallTranslator.INSTANCE$.translate(context, resolvedCall, arrayExpression);
|
return CallTranslator.translate(context, resolvedCall, arrayExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+3
-3
@@ -150,14 +150,14 @@ public class CallArgumentTranslator private constructor(
|
|||||||
concatArguments!!.addAll(result)
|
concatArguments!!.addAll(result)
|
||||||
|
|
||||||
if (!argsBeforeVararg!!.isEmpty()) {
|
if (!argsBeforeVararg!!.isEmpty()) {
|
||||||
concatArguments!!.add(0, JsArrayLiteral(argsBeforeVararg))
|
concatArguments.add(0, JsArrayLiteral(argsBeforeVararg))
|
||||||
}
|
}
|
||||||
|
|
||||||
result = SmartList(concatArgumentsIfNeeded(concatArguments!!))
|
result = SmartList(concatArgumentsIfNeeded(concatArguments))
|
||||||
|
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
cachedReceiver = context().getOrDeclareTemporaryConstVariable(receiver)
|
cachedReceiver = context().getOrDeclareTemporaryConstVariable(receiver)
|
||||||
result.add(0, cachedReceiver!!.reference())
|
result.add(0, cachedReceiver.reference())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result.add(0, JsLiteral.NULL)
|
result.add(0, JsLiteral.NULL)
|
||||||
|
|||||||
+1
-1
@@ -97,7 +97,7 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression translate() {
|
private JsExpression translate() {
|
||||||
return CallTranslator.INSTANCE$.translate(context(), resolvedCall, receiver);
|
return CallTranslator.translate(context(), resolvedCall, receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public final class PsiUtils {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public static List<JetParameter> getPrimaryConstructorParameters(@NotNull JetClassOrObject classDeclaration) {
|
public static List<JetParameter> getPrimaryConstructorParameters(@NotNull JetClassOrObject classDeclaration) {
|
||||||
if (classDeclaration instanceof JetClass) {
|
if (classDeclaration instanceof JetClass) {
|
||||||
return ((JetClass) classDeclaration).getPrimaryConstructorParameters();
|
return classDeclaration.getPrimaryConstructorParameters();
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user