Minor. Reformat

This commit is contained in:
Mikhael Bogdanov
2018-05-07 14:32:37 +02:00
parent 9277d6a160
commit 9fad3f25f3
6 changed files with 222 additions and 194 deletions
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.util.OperatorNameConventions
// This is what Context collects about IR. // This is what Context collects about IR.
abstract class Ir<out T: CommonBackendContext>(val context: T, val irModule: IrModuleFragment) { abstract class Ir<out T : CommonBackendContext>(val context: T, val irModule: IrModuleFragment) {
abstract val symbols: Symbols<T> abstract val symbols: Symbols<T>
@@ -26,7 +26,7 @@ abstract class Ir<out T: CommonBackendContext>(val context: T, val irModule: IrM
open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false open fun shouldGenerateHandlerParameterForDefaultBodyFun() = false
} }
abstract class Symbols<out T: CommonBackendContext>(val context: T, private val symbolTable: SymbolTable) { abstract class Symbols<out T : CommonBackendContext>(val context: T, private val symbolTable: SymbolTable) {
protected val builtIns protected val builtIns
get() = context.builtIns get() = context.builtIns
@@ -58,7 +58,8 @@ abstract class Symbols<out T: CommonBackendContext>(val context: T, private val
val iterator = symbolTable.referenceClass( val iterator = symbolTable.referenceClass(
builtInsPackage("kotlin", "collections").getContributedClassifier( builtInsPackage("kotlin", "collections").getContributedClassifier(
Name.identifier("Iterator"), NoLookupLocation.FROM_BACKEND Name.identifier("Iterator"), NoLookupLocation.FROM_BACKEND
) as ClassDescriptor) ) as ClassDescriptor
)
val asserts = builtInsPackage("kotlin") val asserts = builtInsPackage("kotlin")
.getContributedFunctions(Name.identifier("assert"), NoLookupLocation.FROM_BACKEND) .getContributedFunctions(Name.identifier("assert"), NoLookupLocation.FROM_BACKEND)
@@ -121,8 +122,10 @@ abstract class Symbols<out T: CommonBackendContext>(val context: T, private val
protected fun arrayExtensionFun(type: KotlinType, name: String): IrSimpleFunctionSymbol { protected fun arrayExtensionFun(type: KotlinType, name: String): IrSimpleFunctionSymbol {
val descriptor = builtInsPackage("kotlin") val descriptor = builtInsPackage("kotlin")
.getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND) .getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BACKEND)
.singleOrNull { it.valueParameters.isEmpty() .singleOrNull {
&& (it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.defaultType == type } it.valueParameters.isEmpty()
&& (it.extensionReceiverParameter?.type?.constructor?.declarationDescriptor as? ClassDescriptor)?.defaultType == type
}
?: throw Error(type.toString()) ?: throw Error(type.toString())
return symbolTable.referenceSimpleFunction(descriptor) return symbolTable.referenceSimpleFunction(descriptor)
} }
@@ -69,9 +69,11 @@ class VariableRemapper(val mapping: Map<ValueDescriptor, IrValueParameter>) : Ab
mapping[value] mapping[value]
} }
fun BackendContext.createIrBuilder(symbol: IrSymbol, fun BackendContext.createIrBuilder(
symbol: IrSymbol,
startOffset: Int = UNDEFINED_OFFSET, startOffset: Int = UNDEFINED_OFFSET,
endOffset: Int = UNDEFINED_OFFSET) = endOffset: Int = UNDEFINED_OFFSET
) =
DeclarationIrBuilder(this, symbol, startOffset, endOffset) DeclarationIrBuilder(this, symbol, startOffset, endOffset)
@@ -80,9 +82,11 @@ fun <T : IrBuilder> T.at(element: IrElement) = this.at(element.startOffset, elem
/** /**
* Builds [IrBlock] to be used instead of given expression. * Builds [IrBlock] to be used instead of given expression.
*/ */
inline fun IrGeneratorWithScope.irBlock(expression: IrExpression, origin: IrStatementOrigin? = null, inline fun IrGeneratorWithScope.irBlock(
expression: IrExpression, origin: IrStatementOrigin? = null,
resultType: KotlinType? = expression.type, resultType: KotlinType? = expression.type,
body: IrBlockBuilder.() -> Unit) = body: IrBlockBuilder.() -> Unit
) =
this.irBlock(expression.startOffset, expression.endOffset, origin, resultType, body) this.irBlock(expression.startOffset, expression.endOffset, origin, resultType, body)
inline fun IrGeneratorWithScope.irBlockBody(irElement: IrElement, body: IrBlockBodyBuilder.() -> Unit) = inline fun IrGeneratorWithScope.irBlockBody(irElement: IrElement, body: IrBlockBodyBuilder.() -> Unit) =
@@ -107,8 +111,10 @@ fun IrBuilderWithScope.irCast(arg: IrExpression, type: KotlinType, typeOperand:
IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.CAST, typeOperand, arg) IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.CAST, typeOperand, arg)
fun IrBuilderWithScope.irImplicitCoercionToUnit(arg: IrExpression) = fun IrBuilderWithScope.irImplicitCoercionToUnit(arg: IrExpression) =
IrTypeOperatorCallImpl(startOffset, endOffset, context.builtIns.unitType, IrTypeOperatorCallImpl(
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT, context.builtIns.unitType, arg) startOffset, endOffset, context.builtIns.unitType,
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT, context.builtIns.unitType, arg
)
fun IrBuilderWithScope.irGetField(receiver: IrExpression, symbol: IrFieldSymbol) = fun IrBuilderWithScope.irGetField(receiver: IrExpression, symbol: IrFieldSymbol) =
IrGetFieldImpl(startOffset, endOffset, symbol, receiver) IrGetFieldImpl(startOffset, endOffset, symbol, receiver)
@@ -195,8 +201,10 @@ class SimpleMemberScope(val members: List<DeclarationDescriptor>) : MemberScopeI
members.filterIsInstance<SimpleFunctionDescriptor>() members.filterIsInstance<SimpleFunctionDescriptor>()
.filter { it.name == name } .filter { it.name == name }
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, override fun getContributedDescriptors(
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean
): Collection<DeclarationDescriptor> =
members.filter { kindFilter.accepts(it) && nameFilter(it.name) } members.filter { kindFilter.accepts(it) && nameFilter(it.name) }
override fun printScopeStructure(p: Printer) = TODO("not implemented") override fun printScopeStructure(p: Printer) = TODO("not implemented")
@@ -222,16 +230,17 @@ fun IrConstructor.callsSuper(): Boolean {
if (expression.descriptor.constructedClass == superClass) if (expression.descriptor.constructedClass == superClass)
callsSuper = true callsSuper = true
else if (expression.descriptor.constructedClass != constructedClass) else if (expression.descriptor.constructedClass != constructedClass)
throw AssertionError("Expected either call to another constructor of the class being constructed or" + throw AssertionError(
" call to super class constructor. But was: ${expression.descriptor.constructedClass}") "Expected either call to another constructor of the class being constructed or" +
" call to super class constructor. But was: ${expression.descriptor.constructedClass}"
)
} }
}) })
assert(numberOfCalls == 1, { "Expected exactly one delegating constructor call but none encountered: $descriptor" }) assert(numberOfCalls == 1, { "Expected exactly one delegating constructor call but none encountered: $descriptor" })
return callsSuper return callsSuper
} }
fun ParameterDescriptor.copyAsValueParameter(newOwner: CallableDescriptor, index: Int) fun ParameterDescriptor.copyAsValueParameter(newOwner: CallableDescriptor, index: Int) = when (this) {
= when (this) {
is ValueParameterDescriptor -> this.copy(newOwner, name, index) is ValueParameterDescriptor -> this.copy(newOwner, name, index)
is ReceiverParameterDescriptor -> ValueParameterDescriptorImpl( is ReceiverParameterDescriptor -> ValueParameterDescriptorImpl(
containingDeclaration = newOwner, containingDeclaration = newOwner,
@@ -25,13 +25,14 @@ import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
import org.jetbrains.kotlin.ir.builders.irCall import org.jetbrains.kotlin.ir.builders.irCall
import org.jetbrains.kotlin.ir.builders.irGet import org.jetbrains.kotlin.ir.builders.irGet
import org.jetbrains.kotlin.ir.builders.irTemporary import org.jetbrains.kotlin.ir.builders.irTemporary
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrSymbolDeclaration
import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrStringConcatenation import org.jetbrains.kotlin.ir.expressions.IrStringConcatenation
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
import org.jetbrains.kotlin.ir.util.constructors import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.functions import org.jetbrains.kotlin.ir.util.functions
import org.jetbrains.kotlin.ir.util.type
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
@@ -85,8 +86,8 @@ private class StringConcatenationTransformer(val lower: StringConcatenationLower
} }
}.toMap() }.toMap()
private fun typeToAppendFunction(type : KotlinType) : IrFunctionSymbol { private fun typeToAppendFunction(type: KotlinType): IrFunctionSymbol {
return appendFunctions[type]?:defaultAppendFunction return appendFunctions[type] ?: defaultAppendFunction
} }
override fun visitStringConcatenation(expression: IrStringConcatenation): IrExpression { override fun visitStringConcatenation(expression: IrStringConcatenation): IrExpression {
@@ -30,7 +30,15 @@ class DefaultImplsClassDescriptorImpl(
name: Name, name: Name,
override val correspondingInterface: ClassDescriptor, override val correspondingInterface: ClassDescriptor,
sourceElement: SourceElement sourceElement: SourceElement
) : DefaultImplsClassDescriptor, KnownClassDescriptor(name, correspondingInterface, sourceElement, ClassKind.CLASS, Modality.FINAL, Visibilities.PUBLIC, Annotations.EMPTY) { ) : DefaultImplsClassDescriptor, KnownClassDescriptor(
name,
correspondingInterface,
sourceElement,
ClassKind.CLASS,
Modality.FINAL,
Visibilities.PUBLIC,
Annotations.EMPTY
) {
init { init {
initialize(emptyList(), listOf(correspondingInterface.module.builtIns.anyType)) initialize(emptyList(), listOf(correspondingInterface.module.builtIns.anyType))
} }
@@ -103,7 +103,14 @@ class JvmFunctionDescriptorImpl(
containingDeclaration, original, annotations, containingDeclaration, original, annotations,
name, kind, source name, kind, source
) { ) {
override fun createSubstitutedCopy(newOwner: DeclarationDescriptor, original: FunctionDescriptor?, kind: CallableMemberDescriptor.Kind, newName: Name?, annotations: Annotations, source: SourceElement): FunctionDescriptorImpl { override fun createSubstitutedCopy(
newOwner: DeclarationDescriptor,
original: FunctionDescriptor?,
kind: CallableMemberDescriptor.Kind,
newName: Name?,
annotations: Annotations,
source: SourceElement
): FunctionDescriptorImpl {
return JvmFunctionDescriptorImpl( return JvmFunctionDescriptorImpl(
newOwner, original, annotations, name, kind, newOwner, original, annotations, name, kind,
SourceElement.NO_SOURCE, extraFlags SourceElement.NO_SOURCE, extraFlags