Package com.rnett.plugin.ir

The com.rnett.plugin.ir package contains a number of utilities for working with IR. This includes basic utilities such as CompilerConfiguration.messageCollector, IrClass.addAnonymousInitializer, IrType.raiseTo, and IrClass.typeWith(List<IrTypeArgument>), all of which are available as extension functions.

Many utilities require a IrPluginContext, so in lieu of multiple receivers, they are put in HasContext which has a val context: IrPluginContext. It can be easily implemented by IrElementTransformers. Of special note are the IrBuilderWithScope.buildLambda and lambdaArgument functions.

KnowsCurrentFile is a similar interface, but requires a IrFile and provides extensions for getting message locations from IrElements using said file.

Both of these are implemented by IrTransformer, which is usable as a replacement for IrElementTransformerVoid or IrElementTransformerVoidWithContext. In addition to implementing IrElementTransformerVoidWithContext , KnowsCurrentFile, and HasContext, it modifies the file transformer so that new declarations can be added to the current file without running into ConcurrentModificationException (it does so by running transforms on a copy of the declaration list, and then on newly added declarations until no more are added).

Types

Link copied to clipboard
fun interface FunctionRemapper

Remap references to functions. Returning null will deep copy the symbol.

Link copied to clipboard
interface HasContext

A bunch of things using context that should mostly be moved to multiple receivers

Link copied to clipboard
abstract class IrTransformer(context: IrPluginContext, messageCollector: MessageCollector) : IrElementTransformerVoidWithContext, FileLoweringPass, HasContext, KnowsCurrentFile
Link copied to clipboard
class IrTryBuilder(builder: IrBuilderWithScope)
Link copied to clipboard
interface KnowsCurrentFile

Utility methods for working with a MessageCollector when the current file is available

Link copied to clipboard
interface ReferenceRemapper

A symbol remapper that only replaces references to symbols. Returning null will deep copy the symbol.

Link copied to clipboard
class ReferenceReplacements : ReferenceRemapper

A list of symbol replacements, providing a ReferenceRemapper.

Link copied to clipboard
fun interface ValueRemapper : ReferenceRemapper

Remap value symbols. If given a IrVariableSymbol, must return a IrVariableSymbol. Returning null will deep copy the symbol.

Functions

Link copied to clipboard
inline fun IrClass.addAnonymousInitializer(builder: IrAnonymousInitializer.() -> Unit): IrAnonymousInitializer
Link copied to clipboard
inline fun <T : IrElement> IrGeneratorWithScope.buildStatement(startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET, origin: IrStatementOrigin? = null, builder: IrSingleStatementBuilder.() -> T): T
Link copied to clipboard
fun IrGeneratorContext.createIrBuilder(symbol: IrSymbol, startOffset: Int = UNDEFINED_OFFSET, endOffset: Int = UNDEFINED_OFFSET): DeclarationIrBuilder
Link copied to clipboard
inline fun <T : IrElement> T.deepCopyAndRemapFunctions(initialParent: IrDeclarationParent? = null, referenceRemapper: FunctionRemapper): T

Deep copy and replace references to values.

Link copied to clipboard
inline fun <T : IrElement> T.deepCopyAndRemapReferences(initialParent: IrDeclarationParent? = null, referenceRemapper: ReferenceRemapper): T

Deep copy and replace references to symbols

inline fun <T : IrElement> T.deepCopyAndRemapReferences(initialParent: IrDeclarationParent? = null, referenceReplacements: ReferenceReplacements.Builder.() -> Unit): T

Deep copy and replace references

Link copied to clipboard
inline fun <T : IrElement> T.deepCopyAndRemapValues(initialParent: IrDeclarationParent? = null, referenceRemapper: ValueRemapper): T

Deep copy and replace references to values

Link copied to clipboard
fun IrType.hasTypeArgument(index: Int): Boolean
Link copied to clipboard
fun IrBuilderWithScope.irJsExprBody(expression: IrExpression, useExprOnJvm: Boolean = false): IrBody

IrExprBody on JS causes issues: (https://youtrack.jetbrains.com/issue/KT-49561).

Link copied to clipboard
fun IrBuilderWithScope.irTry(result: IrExpression, type: IrType = result.type): IrTry
inline fun IrBuilderWithScope.irTry(result: IrExpression, type: IrType = result.type, catches: IrTryBuilder.() -> Unit): IrTry
fun IrBuilderWithScope.irTry(result: IrExpression, type: IrType, catches: List<IrCatch>, finally: IrExpression? = null): IrTry
Link copied to clipboard
inline fun <T> HasContext.irTypeOf(): IrType
inline fun <T> IrPluginContext.irTypeOf(): IrType
Link copied to clipboard
fun IrBuilderWithScope.irVararg(elementType: IrType, elements: Iterable<IrExpression>): IrVararg
Link copied to clipboard
fun IrMemberAccessExpression<*>.putTypeArguments(vararg namedArgs: Pair<String, IrType?>, substitute: Boolean = this is IrCall)
fun IrMemberAccessExpression<*>.putTypeArguments(vararg args: IrType?, substitute: Boolean = this is IrCall)

Set the type arguments of the call. If substitute is true and this is an IrCall, calls substituteTypeParams.

Link copied to clipboard
fun IrMemberAccessExpression<*>.putValueArguments(vararg namedArgs: Pair<String, IrExpression?>, substitute: Boolean = this is IrCall)
fun IrMemberAccessExpression<*>.putValueArguments(vararg args: IrExpression?, substitute: Boolean = this is IrCall)
Link copied to clipboard
inline fun IrType.raiseTo(predicate: (IrType) -> Boolean): IrType

Gets the lowest superclass or this that matches the predicate. Helpful for discovering the type parameters of supertypes.

fun IrType.raiseTo(classifier: IrClassifierSymbol): IrType

Gets the lowest superclass or this that has the given classifier. Helpful for discovering the type parameters of supertypes.

Link copied to clipboard
inline fun IrType.raiseToOrNull(predicate: (IrType) -> Boolean): IrType?
fun IrType.raiseToOrNull(classifier: IrClassifierSymbol): IrType?

Gets the lowest superclass or this that matches the predicate, or null if none do. Helpful for discovering the type parameters of supertypes.

Link copied to clipboard
inline fun ReferenceReplacements(builder: ReferenceReplacements.Builder.() -> Unit): ReferenceReplacements

Build a list of symbol replacements

Link copied to clipboard
fun IrCall.substituteTypeParams(): IrCall

Substitute the set type parameters into the return type.

Link copied to clipboard
fun IrType.supertypesWithSubstitution(): List<IrType>

Get the supertypes of a type, substituting type parameters for their values where known and not *.

Link copied to clipboard
fun IrType.typeArgument(index: Int): IrType
Link copied to clipboard
fun IrClass.typeWith(arguments: List<IrTypeArgument>): IrSimpleType
fun IrClassifierSymbol.typeWith(arguments: List<IrTypeArgument>): IrSimpleType
Link copied to clipboard
fun IrCall.valueArgumentsByName(): Map<String, IrExpression?>

Get the arguments of an IrCall by their parameter names

Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withDispatchReceiver(receiver: IrExpression?, substitute: Boolean = this is IrCall): T
Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withExtensionReceiver(receiver: IrExpression?, substitute: Boolean = this is IrCall): T
Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withTypeArguments(vararg namedArgs: Pair<String, IrType?>, substitute: Boolean = this is IrCall): T
fun <T : IrMemberAccessExpression<*>> T.withTypeArguments(vararg args: IrType?, substitute: Boolean = this is IrCall): T

Set the type arguments of the call. If substitute is true and this is an IrCall, calls substituteTypeParams.

Link copied to clipboard
fun <T : IrMemberAccessExpression<*>> T.withValueArguments(vararg namedArgs: Pair<String, IrExpression?>, substitute: Boolean = this is IrCall): T
fun <T : IrMemberAccessExpression<*>> T.withValueArguments(vararg args: IrExpression?, substitute: Boolean = this is IrCall): T

Properties

Link copied to clipboard
val CompilerConfiguration.messageCollector: MessageCollector
Link copied to clipboard
val IrGeneratorContextInterface.typeSystem: IrTypeSystemContext