From 703110c0e24299494c12aa5fd727e6b4b77da4c8 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 11 Oct 2016 13:21:12 +0300 Subject: [PATCH] Update after rebase on master. --- .../kotlin/codegen/state/GenerationState.kt | 2 +- .../kotlin/backend/jvm/JvmIrCodegenFactory.kt | 8 +- .../generators/LoopExpressionGenerator.kt | 25 ++-- .../ir/IrBlackBoxCodegenTestGenerated.java | 117 ++++++++++++++++++ 4 files changed, 133 insertions(+), 19 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 021a8c8dfa6..335f037d698 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -19,8 +19,8 @@ package org.jetbrains.kotlin.codegen.state import com.intellij.openapi.project.Project import com.intellij.openapi.util.ModificationTracker import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.builtins.ReflectionTypes +import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.`when`.MappingsClassesForWhenByEnum import org.jetbrains.kotlin.codegen.binding.CodegenBinding diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt index 1769624f02d..671036f6886 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt @@ -27,10 +27,6 @@ import org.jetbrains.kotlin.psi.KtFile object JvmIrCodegenFactory : CodegenFactory { override fun createPackageCodegen(state: GenerationState, files: Collection, fqName: FqName, registry: PackagePartRegistry): PackageCodegen { val impl = PackageCodegenImpl(state, files, fqName, registry) -// val psi2ir = Psi2IrTranslator() -// val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext) -// val jvmBackendContext = JvmBackendFacade.createJvmBackendContext(psi2ir, state) - return object : PackageCodegen { override fun generate(errorHandler: CompilationErrorHandler) { @@ -38,7 +34,7 @@ object JvmIrCodegenFactory : CodegenFactory { } override fun generateClassOrObject(classOrObject: KtClassOrObject, packagePartContext: PackageContext) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + TODO() } override fun getPackageFragment(): PackageFragmentDescriptor { @@ -48,6 +44,6 @@ object JvmIrCodegenFactory : CodegenFactory { } override fun createMultifileClassCodegen(state: GenerationState, files: Collection, fqName: FqName, registry: PackagePartRegistry): MultifileClassCodegen { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + TODO() } } \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LoopExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LoopExpressionGenerator.kt index 12b5bfaf837..119b9fadfa1 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LoopExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LoopExpressionGenerator.kt @@ -100,8 +100,8 @@ class LoopExpressionGenerator(statementGenerator: StatementGenerator) : Statemen fun generateForLoop(ktFor: KtForExpression): IrExpression { val ktLoopParameter = ktFor.loopParameter - val ktLoopDestructuringParameter = ktFor.destructuringParameter - if (ktLoopParameter == null && ktLoopDestructuringParameter == null) { + val ktLoopDestructuringDeclaration = ktFor.destructuringDeclaration + if (ktLoopParameter == null && ktLoopDestructuringDeclaration == null) { throw AssertionError("Either loopParameter or destructuringParameter should be present:\n${ktFor.text}") } @@ -137,18 +137,19 @@ class LoopExpressionGenerator(statementGenerator: StatementGenerator) : Statemen val nextCall = statementGenerator.pregenerateCall(nextResolvedCall) nextCall.setExplicitReceiverValue(iteratorValue) val irNextCall = callGenerator.generateCall(ktLoopRange, nextCall, IrStatementOrigin.FOR_LOOP_NEXT) - val irLoopParameter = if (ktLoopParameter != null) { - val loopParameterDescriptor = getOrFail(BindingContext.VALUE_PARAMETER, ktLoopParameter) - IrVariableImpl(ktLoopParameter.startOffset, ktLoopParameter.endOffset, IrDeclarationOrigin.DEFINED, - loopParameterDescriptor, irNextCall) - } - else { - scope.createTemporaryVariable(irNextCall, "loop_parameter") - } + val irLoopParameter = + if (ktLoopParameter != null && ktLoopDestructuringDeclaration == null) { + val loopParameterDescriptor = getOrFail(BindingContext.VALUE_PARAMETER, ktLoopParameter) + IrVariableImpl(ktLoopParameter.startOffset, ktLoopParameter.endOffset, IrDeclarationOrigin.DEFINED, + loopParameterDescriptor, irNextCall) + } + else { + scope.createTemporaryVariable(irNextCall, "loop_parameter") + } irInnerBody.statements.add(irLoopParameter) - if (ktLoopDestructuringParameter != null) { - statementGenerator.declareComponentVariablesInBlock(ktLoopDestructuringParameter, irInnerBody, VariableLValue(irLoopParameter)) + if (ktLoopDestructuringDeclaration != null) { + statementGenerator.declareComponentVariablesInBlock(ktLoopDestructuringDeclaration, irInnerBody, VariableLValue(irLoopParameter)) } if (ktForBody != null) { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index b2def39a271..2cf1048e020 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -906,6 +906,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) public static class Bridges extends AbstractIrBlackBoxCodegenTest { + @TestMetadata("jsName.kt") + public void ignoredJsName() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/jsName.kt"); + doTest(fileName); + } + + @TestMetadata("jsNative.kt") + public void ignoredJsNative() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/jsNative.kt"); + doTest(fileName); + } + public void testAllFilesPresentInBridges() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/bridges"), Pattern.compile("^(.+)\\.kt$"), true); } @@ -3586,6 +3598,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("noStubsInJavaSuperClass.kt") + public void testNoStubsInJavaSuperClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collections/noStubsInJavaSuperClass.kt"); + doTest(fileName); + } + @TestMetadata("platformValueContains.kt") public void testPlatformValueContains() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collections/platformValueContains.kt"); @@ -3615,6 +3633,27 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collections/strList.kt"); doTest(fileName); } + + @TestMetadata("toArrayInJavaClass.kt") + public void testToArrayInJavaClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/collections/toArrayInJavaClass.kt"); + doTest(fileName); + } + } + + @TestMetadata("compiler/testData/codegen/box/compatibility") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Compatibility extends AbstractIrBlackBoxCodegenTest { + public void testAllFilesPresentInCompatibility() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/compatibility"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("dataClassEqualsHashCodeToString.kt") + public void testDataClassEqualsHashCodeToString() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/compatibility/dataClassEqualsHashCodeToString.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/box/constants") @@ -8446,6 +8485,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("inlinePropertyAccessors.kt") + public void testInlinePropertyAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/inlinePropertyAccessors.kt"); + doTest(fileName); + } + @TestMetadata("kt9897_static.kt") public void testKt9897_static() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/kt9897_static.kt"); @@ -8488,6 +8533,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("propertyAccessorsCompanion.kt") + public void testPropertyAccessorsCompanion() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyAccessorsCompanion.kt"); + doTest(fileName); + } + + @TestMetadata("propertyAccessorsObject.kt") + public void testPropertyAccessorsObject() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyAccessorsObject.kt"); + doTest(fileName); + } + @TestMetadata("propertyAsDefault.kt") public void testPropertyAsDefault() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/jvmStatic/propertyAsDefault.kt"); @@ -11128,6 +11185,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("inIntRange.kt") + public void testInIntRange() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/inIntRange.kt"); + doTest(fileName); + } + @TestMetadata("multiAssignmentIterationOverIntRange.kt") public void testMultiAssignmentIterationOverIntRange() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/multiAssignmentIterationOverIntRange.kt"); @@ -13594,6 +13657,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/regressions"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("arrayLengthNPE.kt") + public void testArrayLengthNPE() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/arrayLengthNPE.kt"); + doTest(fileName); + } + @TestMetadata("collections.kt") public void testCollections() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/collections.kt"); @@ -14425,6 +14494,30 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("callFromLocalSubClass.kt") + public void testCallFromLocalSubClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/callFromLocalSubClass.kt"); + doTest(fileName); + } + + @TestMetadata("callFromPrimaryWithNamedArgs.kt") + public void testCallFromPrimaryWithNamedArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/callFromPrimaryWithNamedArgs.kt"); + doTest(fileName); + } + + @TestMetadata("callFromPrimaryWithOptionalArgs.kt") + public void testCallFromPrimaryWithOptionalArgs() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/callFromPrimaryWithOptionalArgs.kt"); + doTest(fileName); + } + + @TestMetadata("callFromSubClass.kt") + public void testCallFromSubClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/callFromSubClass.kt"); + doTest(fileName); + } + @TestMetadata("clashingDefaultConstructors.kt") public void testClashingDefaultConstructors() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/clashingDefaultConstructors.kt"); @@ -15112,6 +15205,30 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt14243.kt") + public void testKt14243() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243.kt"); + doTest(fileName); + } + + @TestMetadata("kt14243_2.kt") + public void testKt14243_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_2.kt"); + doTest(fileName); + } + + @TestMetadata("kt14243_class.kt") + public void testKt14243_class() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_class.kt"); + doTest(fileName); + } + + @TestMetadata("kt14243_prop.kt") + public void testKt14243_prop() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt14243_prop.kt"); + doTest(fileName); + } + @TestMetadata("kt3492ClassFun.kt") public void testKt3492ClassFun() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/super/kt3492ClassFun.kt");