IR: use the correct descriptor for the booleanNotSymbol creation

NOTE corresponding function now has a dispatch receiver instead of a
single argument
This commit is contained in:
Anton Bannykh
2019-03-18 18:14:38 +03:00
parent 0546548ff3
commit a382956c19
15 changed files with 28 additions and 115 deletions
@@ -195,7 +195,7 @@ fun IrBuilderWithScope.irEquals(arg1: IrExpression, arg2: IrExpression, origin:
fun IrBuilderWithScope.irNotEquals(arg1: IrExpression, arg2: IrExpression) =
primitiveOp1(
startOffset, endOffset, context.irBuiltIns.booleanNotSymbol, IrStatementOrigin.EXCLEQ,
startOffset, endOffset, context.irBuiltIns.booleanNotSymbol, context.irBuiltIns.booleanType, IrStatementOrigin.EXCLEQ,
irEquals(arg1, arg2, origin = IrStatementOrigin.EXCLEQ)
)
@@ -22,16 +22,20 @@ import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.expressions.IrWhen
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
import org.jetbrains.kotlin.ir.types.IrType
// TODO rewrite using IR Builders
fun primitiveOp1(
startOffset: Int, endOffset: Int,
primitiveOpSymbol: IrSimpleFunctionSymbol,
primitiveOpReturnType: IrType,
origin: IrStatementOrigin,
argument: IrExpression
dispatchReceiver: IrExpression
): IrExpression =
IrUnaryPrimitiveImpl(startOffset, endOffset, primitiveOpSymbol.owner.returnType, origin, primitiveOpSymbol, argument)
IrCallImpl(startOffset, endOffset, primitiveOpReturnType, primitiveOpSymbol, primitiveOpSymbol.descriptor, origin = origin).also {
it.dispatchReceiver = dispatchReceiver
}
fun primitiveOp2(
startOffset: Int, endOffset: Int,
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
@@ -195,7 +196,6 @@ class IrBuiltIns(
val throwNpeFun = defineOperator(OperatorNames.THROW_NPE, nothing, listOf())
val throwCceFun = defineOperator(OperatorNames.THROW_CCE, nothing, listOf())
val throwIseFun = defineOperator(OperatorNames.THROW_ISE, nothing, listOf())
val booleanNotFun = defineOperator(OperatorNames.NOT, bool, listOf(bool))
val noWhenBranchMatchedExceptionFun = defineOperator(OperatorNames.NO_WHEN_BRANCH_MATCHED_EXCEPTION, nothing, listOf())
val illegalArgumentExceptionFun = defineOperator(OperatorNames.ILLEGAL_ARGUMENT_EXCEPTION, nothing, listOf(string))
@@ -203,7 +203,7 @@ class IrBuiltIns(
val eqeq = eqeqFun.descriptor
val throwNpe = throwNpeFun.descriptor
val throwCce = throwCceFun.descriptor
val booleanNot = booleanNotFun.descriptor
val booleanNot = builtIns.boolean.unsubstitutedMemberScope.getContributedFunctions(Name.identifier("not"), NoLookupLocation.FROM_BACKEND).single()
val noWhenBranchMatchedException = noWhenBranchMatchedExceptionFun.descriptor
val illegalArgumentException = illegalArgumentExceptionFun.descriptor
@@ -212,7 +212,7 @@ class IrBuiltIns(
val throwNpeSymbol = throwNpeFun.symbol
val throwCceSymbol = throwCceFun.symbol
val throwIseSymbol = throwIseFun.symbol
val booleanNotSymbol = booleanNotFun.symbol
val booleanNotSymbol = symbolTable.referenceSimpleFunction(booleanNot)
val noWhenBranchMatchedExceptionSymbol = noWhenBranchMatchedExceptionFun.symbol
val illegalArgumentExceptionSymbol = illegalArgumentExceptionFun.symbol
@@ -262,7 +262,6 @@ class IrBuiltIns(
const val EQEQ = "EQEQ"
const val EQEQEQ = "EQEQEQ"
const val IEEE754_EQUALS = "ieee754equals"
const val NOT = "NOT"
const val THROW_NPE = "THROW_NPE"
const val THROW_CCE = "THROW_CCE"
const val THROW_ISE = "THROW_ISE"
@@ -107,54 +107,6 @@ class IrNullaryPrimitiveImpl(
IrNullaryPrimitiveImpl(startOffset, endOffset, type, newOrigin, newCallee)
}
class IrUnaryPrimitiveImpl(
startOffset: Int,
endOffset: Int,
type: IrType,
origin: IrStatementOrigin?,
symbol: IrFunctionSymbol
) : IrPrimitiveCallBase(startOffset, endOffset, type, origin, symbol, 1),
IrCallWithShallowCopy {
constructor(
startOffset: Int,
endOffset: Int,
type: IrType,
origin: IrStatementOrigin?,
symbol: IrFunctionSymbol,
argument: IrExpression
) : this(startOffset, endOffset, type, origin, symbol) {
this.argument = argument
}
lateinit var argument: IrExpression
override fun getValueArgument(index: Int): IrExpression? {
return when (index) {
ARGUMENT0 -> argument
else -> null
}
}
override fun putValueArgument(index: Int, valueArgument: IrExpression?) {
when (index) {
ARGUMENT0 -> argument = valueArgument ?: throw AssertionError("Primitive call $descriptor argument is null")
else -> throw AssertionError("Primitive call $descriptor: no such argument index $index")
}
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
argument.accept(visitor, data)
}
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
argument = argument.transform(transformer, data)
}
override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall =
IrUnaryPrimitiveImpl(startOffset, endOffset, type, newOrigin, newCallee)
}
class IrBinaryPrimitiveImpl(
startOffset: Int,
endOffset: Int,