Lowering for property declarations.
This commit is contained in:
committed by
Dmitry Petrov
parent
b19bcc0587
commit
d67d8016d3
@@ -17,10 +17,12 @@
|
|||||||
package org.jetbrains.kotlin.backend.jvm
|
package org.jetbrains.kotlin.backend.jvm
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.lower.FileClassLowering
|
import org.jetbrains.kotlin.backend.jvm.lower.FileClassLowering
|
||||||
|
import org.jetbrains.kotlin.backend.jvm.lower.PropertiesLowering
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
|
||||||
class JvmLower(val context: JvmBackendContext) {
|
class JvmLower(val context: JvmBackendContext) {
|
||||||
fun lower(irFile: IrFile) {
|
fun lower(irFile: IrFile) {
|
||||||
FileClassLowering(context).lower(irFile)
|
FileClassLowering(context.jvmFileClassProvider).lower(irFile)
|
||||||
|
PropertiesLowering().lower(irFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.jvm.lower
|
package org.jetbrains.kotlin.backend.jvm.lower
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
@@ -24,7 +23,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class FileClassLowering(val context: JvmBackendContext) {
|
class FileClassLowering(val jvmFileClassProvider: JvmFileClassProvider) {
|
||||||
fun lower(irFile: IrFile) {
|
fun lower(irFile: IrFile) {
|
||||||
val classes = ArrayList<IrClass>()
|
val classes = ArrayList<IrClass>()
|
||||||
val fileClassMembers = ArrayList<IrDeclaration>()
|
val fileClassMembers = ArrayList<IrDeclaration>()
|
||||||
@@ -38,7 +37,7 @@ class FileClassLowering(val context: JvmBackendContext) {
|
|||||||
|
|
||||||
if (fileClassMembers.isEmpty()) return
|
if (fileClassMembers.isEmpty()) return
|
||||||
|
|
||||||
val fileClassDescriptor = context.jvmFileClassProvider.createFileClassDescriptor(irFile.fileEntry, irFile.packageFragmentDescriptor)
|
val fileClassDescriptor = jvmFileClassProvider.createFileClassDescriptor(irFile.fileEntry, irFile.packageFragmentDescriptor)
|
||||||
|
|
||||||
val irFileClass = IrClassImpl(0, irFile.fileEntry.maxOffset, IrDeclarationOrigin.DEFINED, fileClassDescriptor, fileClassMembers)
|
val irFileClass = IrClassImpl(0, irFile.fileEntry.maxOffset, IrDeclarationOrigin.DEFINED, fileClassDescriptor, fileClassMembers)
|
||||||
classes.add(irFileClass)
|
classes.add(irFileClass)
|
||||||
|
|||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 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.backend.jvm.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrProperty
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class PropertiesLowering : IrElementTransformerVoid {
|
||||||
|
fun lower(irFile: IrFile) {
|
||||||
|
irFile.transformChildrenVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitFile(declaration: IrFile): IrFile {
|
||||||
|
declaration.transformChildrenVoid(this)
|
||||||
|
transformDeclarations(declaration.declarations)
|
||||||
|
return declaration
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitClass(declaration: IrClass): IrStatement {
|
||||||
|
declaration.transformChildrenVoid(this)
|
||||||
|
transformDeclarations(declaration.declarations)
|
||||||
|
return declaration
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun transformDeclarations(declarations: MutableList<IrDeclaration>) {
|
||||||
|
val properties = linkedSetOf<IrProperty>()
|
||||||
|
|
||||||
|
declarations.filterIsInstanceTo(properties)
|
||||||
|
|
||||||
|
declarations.removeAll(properties)
|
||||||
|
|
||||||
|
properties.flatMapTo(declarations) { irProperty ->
|
||||||
|
val result = ArrayList<IrDeclaration>(3)
|
||||||
|
result.addIfNotNull(irProperty.backingField)
|
||||||
|
result.addIfNotNull(irProperty.getter)
|
||||||
|
result.addIfNotNull(irProperty.setter)
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user