From 5a591be25f9f4fcce0d2445889ea5488160eddd5 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Tue, 13 Feb 2018 12:05:54 +0300 Subject: [PATCH] Convert SwitchCodegen to Kotlin, prettify and optimize codegen --- .../kotlin/codegen/when/SwitchCodegen.java | 236 ------------------ .../kotlin/codegen/when/SwitchCodegen.kt | 181 ++++++++++++++ .../when/exhaustiveWhenInitialization.kt | 6 +- .../bytecodeText/when/exhaustiveWhenReturn.kt | 4 +- .../integralWhenWithNoInlinedConstants.kt | 3 +- .../functionLiteralInTopLevel.kt | 2 +- .../whenEnumOptimization/kt14802.kt | 2 +- .../whenEnumOptimization/kt15806.kt | 2 +- 8 files changed, 190 insertions(+), 246 deletions(-) delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegen.java create mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegen.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegen.java deleted file mode 100644 index 554b914d7a6..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/when/SwitchCodegen.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright 2010-2015 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 org.jetbrains.kotlin.codegen.when; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.codegen.ExpressionCodegen; -import org.jetbrains.kotlin.codegen.FrameMap; -import org.jetbrains.kotlin.psi.KtWhenEntry; -import org.jetbrains.kotlin.psi.KtWhenExpression; -import org.jetbrains.kotlin.resolve.BindingContext; -import org.jetbrains.kotlin.resolve.constants.ConstantValue; -import org.jetbrains.kotlin.resolve.constants.NullValue; -import org.jetbrains.kotlin.types.KotlinType; -import org.jetbrains.kotlin.types.TypeUtils; -import org.jetbrains.org.objectweb.asm.Label; -import org.jetbrains.org.objectweb.asm.Type; -import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; - -import java.util.*; - -abstract public class SwitchCodegen { - protected final KtWhenExpression expression; - protected final boolean isStatement; - protected final boolean isExhaustive; - protected final ExpressionCodegen codegen; - protected final BindingContext bindingContext; - protected final Type subjectType; - protected final Type resultType; - protected final InstructionAdapter v; - - protected final NavigableMap transitionsTable = new TreeMap<>(); - protected final List