|
| 1 | +/* |
| 2 | + * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. |
| 3 | + */ |
| 4 | + |
| 5 | +package kotlinx.rpc.codegen |
| 6 | + |
| 7 | +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext |
| 8 | +import org.jetbrains.kotlin.backend.common.ir.createExtensionReceiver |
| 9 | +import org.jetbrains.kotlin.cli.common.messages.MessageCollector |
| 10 | +import org.jetbrains.kotlin.config.CommonConfigurationKeys |
| 11 | +import org.jetbrains.kotlin.config.CompilerConfigurationKey |
| 12 | +import org.jetbrains.kotlin.descriptors.SourceElement |
| 13 | +import org.jetbrains.kotlin.ir.builders.declarations.IrFieldBuilder |
| 14 | +import org.jetbrains.kotlin.ir.declarations.* |
| 15 | +import org.jetbrains.kotlin.ir.expressions.IrCall |
| 16 | +import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin |
| 17 | +import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl |
| 18 | +import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl |
| 19 | +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol |
| 20 | +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol |
| 21 | +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol |
| 22 | +import org.jetbrains.kotlin.ir.types.IrType |
| 23 | +import org.jetbrains.kotlin.ir.util.copyTo |
| 24 | +import org.jetbrains.kotlin.name.CallableId |
| 25 | +import org.jetbrains.kotlin.name.ClassId |
| 26 | +import org.jetbrains.kotlin.name.FqName |
| 27 | +import org.jetbrains.kotlin.name.Name |
| 28 | +import org.jetbrains.kotlin.platform.TargetPlatform |
| 29 | +import org.jetbrains.kotlin.platform.isJs |
| 30 | +import org.jetbrains.kotlin.platform.isWasm |
| 31 | + |
| 32 | +object VersionSpecificApiImpl : VersionSpecificApi { |
| 33 | + override fun isJs(platform: TargetPlatform?): Boolean { |
| 34 | + return platform.isJs() |
| 35 | + } |
| 36 | + |
| 37 | + override fun isWasm(platform: TargetPlatform?): Boolean { |
| 38 | + return platform.isWasm() |
| 39 | + } |
| 40 | + |
| 41 | + override var IrFieldBuilder.isFinalVS: Boolean |
| 42 | + get() = isFinal |
| 43 | + set(value) { |
| 44 | + isFinal = value |
| 45 | + } |
| 46 | + |
| 47 | + override var IrCall.originVS: IrStatementOrigin? |
| 48 | + get() = origin |
| 49 | + set(value) { |
| 50 | + origin = value |
| 51 | + } |
| 52 | + |
| 53 | + override var IrConstructor.isPrimaryVS: Boolean |
| 54 | + get() = isPrimary |
| 55 | + set(value) { |
| 56 | + isPrimary = value |
| 57 | + } |
| 58 | + |
| 59 | + override fun referenceClass(context: IrPluginContext, packageName: String, name: String): IrClassSymbol? { |
| 60 | + return context.referenceClass( |
| 61 | + ClassId( |
| 62 | + FqName(packageName), |
| 63 | + FqName(name), |
| 64 | + false |
| 65 | + ) |
| 66 | + ) |
| 67 | + } |
| 68 | + |
| 69 | + override fun referenceFunctions( |
| 70 | + context: IrPluginContext, |
| 71 | + packageName: String, |
| 72 | + name: String, |
| 73 | + ): Collection<IrSimpleFunctionSymbol> { |
| 74 | + return context.referenceFunctions( |
| 75 | + CallableId( |
| 76 | + FqName(packageName), |
| 77 | + Name.identifier(name), |
| 78 | + ) |
| 79 | + ) |
| 80 | + } |
| 81 | + |
| 82 | + override fun IrValueParameter.copyToVS(irFunction: IrFunction, origin: IrDeclarationOrigin): IrValueParameter { |
| 83 | + return copyTo(irFunction, origin) |
| 84 | + } |
| 85 | + |
| 86 | + override fun IrSimpleFunction.addExtensionReceiverVS(type: IrType, origin: IrDeclarationOrigin): IrValueParameter { |
| 87 | + return createExtensionReceiver(type, origin) |
| 88 | + } |
| 89 | + |
| 90 | + override val messageCollectorKey: CompilerConfigurationKey<MessageCollector> |
| 91 | + get() = CommonConfigurationKeys.MESSAGE_COLLECTOR_KEY |
| 92 | + |
| 93 | + override fun IrCallImplVS( |
| 94 | + startOffset: Int, |
| 95 | + endOffset: Int, |
| 96 | + type: IrType, |
| 97 | + symbol: IrSimpleFunctionSymbol, |
| 98 | + typeArgumentsCount: Int, |
| 99 | + valueArgumentsCount: Int, |
| 100 | + origin: IrStatementOrigin?, |
| 101 | + superQualifierSymbol: IrClassSymbol?, |
| 102 | + ): IrCallImpl { |
| 103 | + return IrCallImpl( |
| 104 | + startOffset = startOffset, |
| 105 | + endOffset = endOffset, |
| 106 | + type = type, |
| 107 | + symbol = symbol, |
| 108 | + typeArgumentsCount = typeArgumentsCount, |
| 109 | + origin = origin, |
| 110 | + superQualifierSymbol = superQualifierSymbol, |
| 111 | + ) |
| 112 | + } |
| 113 | + |
| 114 | + override fun IrConstructorCallImplVS( |
| 115 | + startOffset: Int, |
| 116 | + endOffset: Int, |
| 117 | + type: IrType, |
| 118 | + symbol: IrConstructorSymbol, |
| 119 | + typeArgumentsCount: Int, |
| 120 | + valueArgumentsCount: Int, |
| 121 | + constructorTypeArgumentsCount: Int, |
| 122 | + origin: IrStatementOrigin?, |
| 123 | + source: SourceElement, |
| 124 | + ): IrConstructorCallImpl { |
| 125 | + return IrConstructorCallImpl( |
| 126 | + startOffset = startOffset, |
| 127 | + endOffset = endOffset, |
| 128 | + type = type, |
| 129 | + symbol = symbol, |
| 130 | + typeArgumentsCount = typeArgumentsCount, |
| 131 | + constructorTypeArgumentsCount = constructorTypeArgumentsCount, |
| 132 | + origin = origin, |
| 133 | + source = source, |
| 134 | + ) |
| 135 | + } |
| 136 | +} |
0 commit comments