IR: drop IrTypeAlias
This commit is contained in:
+62
-65
@@ -18,161 +18,158 @@ import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class RenderIrElementWithDescriptorsVisitor : IrElementVisitor<String, Nothing?> {
|
||||
override fun visitElement(element: IrElement, data: Nothing?): String =
|
||||
"? ${element.javaClass.simpleName}"
|
||||
"? ${element.javaClass.simpleName}"
|
||||
|
||||
override fun visitDeclaration(declaration: IrDeclaration, data: Nothing?): String =
|
||||
"? ${declaration.javaClass.simpleName} ${declaration.descriptor.ref()}"
|
||||
"? ${declaration.javaClass.simpleName} ${declaration.descriptor.ref()}"
|
||||
|
||||
override fun visitModuleFragment(declaration: IrModuleFragment, data: Nothing?): String =
|
||||
"MODULE_FRAGMENT ${declaration.descriptor}"
|
||||
"MODULE_FRAGMENT ${declaration.descriptor}"
|
||||
|
||||
override fun visitFile(declaration: IrFile, data: Nothing?): String =
|
||||
"FILE ${declaration.path}"
|
||||
"FILE ${declaration.path}"
|
||||
|
||||
override fun visitFunction(declaration: IrFunction, data: Nothing?): String =
|
||||
"FUN ${declaration.descriptor}"
|
||||
"FUN ${declaration.descriptor}"
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor, data: Nothing?): String =
|
||||
"CONSTRUCTOR ${declaration.descriptor}"
|
||||
"CONSTRUCTOR ${declaration.descriptor}"
|
||||
|
||||
override fun visitProperty(declaration: IrProperty, data: Nothing?): String =
|
||||
"PROPERTY ${declaration.descriptor}"
|
||||
"PROPERTY ${declaration.descriptor}"
|
||||
|
||||
override fun visitField(declaration: IrField, data: Nothing?): String =
|
||||
"FIELD ${declaration.descriptor}"
|
||||
"FIELD ${declaration.descriptor}"
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: Nothing?): String =
|
||||
"CLASS ${declaration.descriptor}"
|
||||
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias, data: Nothing?): String =
|
||||
"TYPEALIAS ${declaration.descriptor} type=${declaration.descriptor.underlyingType.render()}"
|
||||
"CLASS ${declaration.descriptor}"
|
||||
|
||||
override fun visitVariable(declaration: IrVariable, data: Nothing?): String =
|
||||
"VAR ${declaration.descriptor}"
|
||||
"VAR ${declaration.descriptor}"
|
||||
|
||||
override fun visitEnumEntry(declaration: IrEnumEntry, data: Nothing?): String =
|
||||
"ENUM_ENTRY ${declaration.descriptor}"
|
||||
"ENUM_ENTRY ${declaration.descriptor}"
|
||||
|
||||
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer, data: Nothing?): String =
|
||||
"ANONYMOUS_INITIALIZER ${declaration.descriptor}"
|
||||
"ANONYMOUS_INITIALIZER ${declaration.descriptor}"
|
||||
|
||||
override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty, data: Nothing?): String =
|
||||
"LOCAL_DELEGATED_PROPERTY ${declaration.descriptor}"
|
||||
"LOCAL_DELEGATED_PROPERTY ${declaration.descriptor}"
|
||||
|
||||
override fun visitExpressionBody(body: IrExpressionBody, data: Nothing?): String =
|
||||
"EXPRESSION_BODY"
|
||||
"EXPRESSION_BODY"
|
||||
|
||||
override fun visitBlockBody(body: IrBlockBody, data: Nothing?): String =
|
||||
"BLOCK_BODY"
|
||||
"BLOCK_BODY"
|
||||
|
||||
override fun visitSyntheticBody(body: IrSyntheticBody, data: Nothing?): String =
|
||||
"SYNTHETIC_BODY kind=${body.kind}"
|
||||
"SYNTHETIC_BODY kind=${body.kind}"
|
||||
|
||||
override fun visitExpression(expression: IrExpression, data: Nothing?): String =
|
||||
"? ${expression.javaClass.simpleName} type=${expression.type.render()}"
|
||||
"? ${expression.javaClass.simpleName} type=${expression.type.render()}"
|
||||
|
||||
override fun <T> visitConst(expression: IrConst<T>, data: Nothing?): String =
|
||||
"CONST ${expression.kind} type=${expression.type.render()} value='${expression.value}'"
|
||||
"CONST ${expression.kind} type=${expression.type.render()} value='${expression.value}'"
|
||||
|
||||
override fun visitVararg(expression: IrVararg, data: Nothing?): String =
|
||||
"VARARG type=${expression.type} varargElementType=${expression.varargElementType}"
|
||||
"VARARG type=${expression.type} varargElementType=${expression.varargElementType}"
|
||||
|
||||
override fun visitSpreadElement(spread: IrSpreadElement, data: Nothing?): String =
|
||||
"SPREAD_ELEMENT"
|
||||
"SPREAD_ELEMENT"
|
||||
|
||||
override fun visitBlock(expression: IrBlock, data: Nothing?): String =
|
||||
"BLOCK type=${expression.type.render()} origin=${expression.origin}"
|
||||
"BLOCK type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitComposite(expression: IrComposite, data: Nothing?): String =
|
||||
"COMPOSITE type=${expression.type.render()} origin=${expression.origin}"
|
||||
"COMPOSITE type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitReturn(expression: IrReturn, data: Nothing?): String =
|
||||
"RETURN type=${expression.type.render()} from='${expression.returnTarget}'"
|
||||
"RETURN type=${expression.type.render()} from='${expression.returnTarget}'"
|
||||
|
||||
override fun visitCall(expression: IrCall, data: Nothing?): String =
|
||||
"CALL '${expression.descriptor}' ${expression.renderSuperQualifier()}" +
|
||||
"type=${expression.type.render()} origin=${expression.origin}"
|
||||
"CALL '${expression.descriptor}' ${expression.renderSuperQualifier()}" +
|
||||
"type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
private fun IrCall.renderSuperQualifier(): String =
|
||||
superQualifier?.let { "superQualifier=${it.name} " } ?: ""
|
||||
superQualifier?.let { "superQualifier=${it.name} " } ?: ""
|
||||
|
||||
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: Nothing?): String =
|
||||
"DELEGATING_CONSTRUCTOR_CALL '${expression.descriptor}'"
|
||||
"DELEGATING_CONSTRUCTOR_CALL '${expression.descriptor}'"
|
||||
|
||||
override fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: Nothing?): String =
|
||||
"ENUM_CONSTRUCTOR_CALL '${expression.descriptor}'"
|
||||
"ENUM_CONSTRUCTOR_CALL '${expression.descriptor}'"
|
||||
|
||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall, data: Nothing?): String =
|
||||
"INSTANCE_INITIALIZER_CALL classDescriptor='${expression.classDescriptor}'"
|
||||
"INSTANCE_INITIALIZER_CALL classDescriptor='${expression.classDescriptor}'"
|
||||
|
||||
override fun visitGetValue(expression: IrGetValue, data: Nothing?): String =
|
||||
"GET_VAR '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
"GET_VAR '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitSetVariable(expression: IrSetVariable, data: Nothing?): String =
|
||||
"SET_VAR '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
"SET_VAR '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitGetField(expression: IrGetField, data: Nothing?): String =
|
||||
"GET_FIELD '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
"GET_FIELD '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitSetField(expression: IrSetField, data: Nothing?): String =
|
||||
"SET_FIELD '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
"SET_FIELD '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitGetObjectValue(expression: IrGetObjectValue, data: Nothing?): String =
|
||||
"GET_OBJECT '${expression.descriptor}' type=${expression.type.render()}"
|
||||
"GET_OBJECT '${expression.descriptor}' type=${expression.type.render()}"
|
||||
|
||||
override fun visitGetEnumValue(expression: IrGetEnumValue, data: Nothing?): String =
|
||||
"GET_ENUM '${expression.descriptor}' type=${expression.type.render()}"
|
||||
"GET_ENUM '${expression.descriptor}' type=${expression.type.render()}"
|
||||
|
||||
override fun visitStringConcatenation(expression: IrStringConcatenation, data: Nothing?): String =
|
||||
"STRING_CONCATENATION type=${expression.type.render()}"
|
||||
"STRING_CONCATENATION type=${expression.type.render()}"
|
||||
|
||||
override fun visitTypeOperator(expression: IrTypeOperatorCall, data: Nothing?): String =
|
||||
"TYPE_OP origin=${expression.operator} typeOperand=${expression.typeOperand.render()}"
|
||||
"TYPE_OP origin=${expression.operator} typeOperand=${expression.typeOperand.render()}"
|
||||
|
||||
override fun visitWhen(expression: IrWhen, data: Nothing?): String =
|
||||
"WHEN type=${expression.type.render()} origin=${expression.origin}"
|
||||
"WHEN type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitBranch(branch: IrBranch, data: Nothing?): String =
|
||||
"BRANCH"
|
||||
"BRANCH"
|
||||
|
||||
override fun visitWhileLoop(loop: IrWhileLoop, data: Nothing?): String =
|
||||
"WHILE label=${loop.label} origin=${loop.origin}"
|
||||
"WHILE label=${loop.label} origin=${loop.origin}"
|
||||
|
||||
override fun visitDoWhileLoop(loop: IrDoWhileLoop, data: Nothing?): String =
|
||||
"DO_WHILE label=${loop.label} origin=${loop.origin}"
|
||||
"DO_WHILE label=${loop.label} origin=${loop.origin}"
|
||||
|
||||
override fun visitBreak(jump: IrBreak, data: Nothing?): String =
|
||||
"BREAK label=${jump.label} loop.label=${jump.loop.label}"
|
||||
"BREAK label=${jump.label} loop.label=${jump.loop.label}"
|
||||
|
||||
override fun visitContinue(jump: IrContinue, data: Nothing?): String =
|
||||
"CONTINUE label=${jump.label} loop.label=${jump.loop.label}"
|
||||
"CONTINUE label=${jump.label} loop.label=${jump.loop.label}"
|
||||
|
||||
override fun visitThrow(expression: IrThrow, data: Nothing?): String =
|
||||
"THROW type=${expression.type.render()}"
|
||||
"THROW type=${expression.type.render()}"
|
||||
|
||||
override fun visitCallableReference(expression: IrCallableReference, data: Nothing?): String =
|
||||
"CALLABLE_REFERENCE '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
"CALLABLE_REFERENCE '${expression.descriptor}' type=${expression.type.render()} origin=${expression.origin}"
|
||||
|
||||
override fun visitClassReference(expression: IrClassReference, data: Nothing?): String =
|
||||
"CLASS_REFERENCE '${expression.descriptor}' type=${expression.type.render()}"
|
||||
"CLASS_REFERENCE '${expression.descriptor}' type=${expression.type.render()}"
|
||||
|
||||
override fun visitGetClass(expression: IrGetClass, data: Nothing?): String =
|
||||
"GET_CLASS type=${expression.type.render()}"
|
||||
"GET_CLASS type=${expression.type.render()}"
|
||||
|
||||
override fun visitTry(aTry: IrTry, data: Nothing?): String =
|
||||
"TRY type=${aTry.type.render()}"
|
||||
"TRY type=${aTry.type.render()}"
|
||||
|
||||
override fun visitCatch(aCatch: IrCatch, data: Nothing?): String =
|
||||
"CATCH parameter=${aCatch.parameter.ref()}"
|
||||
"CATCH parameter=${aCatch.parameter.ref()}"
|
||||
|
||||
override fun visitErrorDeclaration(declaration: IrErrorDeclaration, data: Nothing?): String =
|
||||
"ERROR_DECL ${declaration.descriptor.javaClass.simpleName} ${declaration.descriptor.ref()}"
|
||||
"ERROR_DECL ${declaration.descriptor.javaClass.simpleName} ${declaration.descriptor.ref()}"
|
||||
|
||||
override fun visitErrorExpression(expression: IrErrorExpression, data: Nothing?): String =
|
||||
"ERROR_EXPR '${expression.description}' type=${expression.type.render()}"
|
||||
"ERROR_EXPR '${expression.description}' type=${expression.type.render()}"
|
||||
|
||||
override fun visitErrorCallExpression(expression: IrErrorCallExpression, data: Nothing?): String =
|
||||
"ERROR_CALL '${expression.description}' type=${expression.type.render()}"
|
||||
"ERROR_CALL '${expression.description}' type=${expression.type.render()}"
|
||||
|
||||
companion object {
|
||||
val DECLARATION_RENDERER = DescriptorRenderer.withOptions {
|
||||
@@ -187,26 +184,26 @@ class RenderIrElementWithDescriptorsVisitor : IrElementVisitor<String, Nothing?>
|
||||
val REFERENCE_RENDERER = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES
|
||||
|
||||
internal fun IrDeclaration.name(): String =
|
||||
descriptor.let { it.name.toString() }
|
||||
descriptor.let { it.name.toString() }
|
||||
|
||||
internal fun IrDeclaration.renderDeclared(): String =
|
||||
DECLARATION_RENDERER.render(this.descriptor)
|
||||
DECLARATION_RENDERER.render(this.descriptor)
|
||||
|
||||
internal fun DeclarationDescriptor.ref(): String =
|
||||
if (this is ReceiverParameterDescriptor)
|
||||
"<receiver: ${containingDeclaration.ref()}>"
|
||||
else
|
||||
REFERENCE_RENDERER.render(this)
|
||||
if (this is ReceiverParameterDescriptor)
|
||||
"<receiver: ${containingDeclaration.ref()}>"
|
||||
else
|
||||
REFERENCE_RENDERER.render(this)
|
||||
|
||||
internal fun KotlinType.render(): String =
|
||||
DECLARATION_RENDERER.renderType(this)
|
||||
DECLARATION_RENDERER.renderType(this)
|
||||
|
||||
internal fun IrDeclaration.renderOrigin(): String =
|
||||
if (origin != IrDeclarationOrigin.DEFINED) origin.toString() + " " else ""
|
||||
if (origin != IrDeclarationOrigin.DEFINED) origin.toString() + " " else ""
|
||||
}
|
||||
}
|
||||
|
||||
class DumpIrTreeWithDescriptorsVisitor(out: Appendable): IrElementVisitor<Unit, String> {
|
||||
class DumpIrTreeWithDescriptorsVisitor(out: Appendable) : IrElementVisitor<Unit, String> {
|
||||
val printer = Printer(out, " ")
|
||||
val elementRenderer = RenderIrElementWithDescriptorsVisitor()
|
||||
|
||||
@@ -367,5 +364,5 @@ class DumpIrTreeWithDescriptorsVisitor(out: Appendable): IrElementVisitor<Unit,
|
||||
}
|
||||
|
||||
private fun String.withLabel(label: String) =
|
||||
if (label.isEmpty()) this else "$label: $this"
|
||||
if (label.isEmpty()) this else "$label: $this"
|
||||
}
|
||||
+21
-25
@@ -839,8 +839,6 @@ open class IrModuleSerializer(
|
||||
return proto.build()
|
||||
}
|
||||
|
||||
private fun serializeIrTypeAlias(typeAlias: IrTypeAlias) = KotlinIr.IrTypeAlias.newBuilder().build()
|
||||
|
||||
private fun serializeIrValueParameter(parameter: IrValueParameter): KotlinIr.IrValueParameter {
|
||||
val proto = KotlinIr.IrValueParameter.newBuilder()
|
||||
.setSymbol(serializeIrSymbol(parameter.symbol))
|
||||
@@ -1057,28 +1055,26 @@ open class IrModuleSerializer(
|
||||
val declarator = KotlinIr.IrDeclarator.newBuilder()
|
||||
|
||||
when (declaration) {
|
||||
is IrTypeAlias
|
||||
-> declarator.irTypeAlias = serializeIrTypeAlias(declaration)
|
||||
is IrAnonymousInitializer
|
||||
-> declarator.irAnonymousInit = serializeIrAnonymousInit(declaration)
|
||||
is IrConstructor
|
||||
-> declarator.irConstructor = serializeIrConstructor(declaration)
|
||||
is IrField
|
||||
-> declarator.irField = serializeIrField(declaration)
|
||||
is IrSimpleFunction
|
||||
-> declarator.irFunction = serializeIrFunction(declaration)
|
||||
is IrTypeParameter
|
||||
-> declarator.irTypeParameter = serializeIrTypeParameter(declaration)
|
||||
is IrVariable
|
||||
-> declarator.irVariable = serializeIrVariable(declaration)
|
||||
is IrValueParameter
|
||||
-> declarator.irValueParameter = serializeIrValueParameter(declaration)
|
||||
is IrClass
|
||||
-> declarator.irClass = serializeIrClass(declaration)
|
||||
is IrEnumEntry
|
||||
-> declarator.irEnumEntry = serializeIrEnumEntry(declaration)
|
||||
is IrProperty
|
||||
-> declarator.irProperty = serializeIrProperty(declaration)
|
||||
is IrAnonymousInitializer ->
|
||||
declarator.irAnonymousInit = serializeIrAnonymousInit(declaration)
|
||||
is IrConstructor ->
|
||||
declarator.irConstructor = serializeIrConstructor(declaration)
|
||||
is IrField ->
|
||||
declarator.irField = serializeIrField(declaration)
|
||||
is IrSimpleFunction ->
|
||||
declarator.irFunction = serializeIrFunction(declaration)
|
||||
is IrTypeParameter ->
|
||||
declarator.irTypeParameter = serializeIrTypeParameter(declaration)
|
||||
is IrVariable ->
|
||||
declarator.irVariable = serializeIrVariable(declaration)
|
||||
is IrValueParameter ->
|
||||
declarator.irValueParameter = serializeIrValueParameter(declaration)
|
||||
is IrClass ->
|
||||
declarator.irClass = serializeIrClass(declaration)
|
||||
is IrEnumEntry ->
|
||||
declarator.irEnumEntry = serializeIrEnumEntry(declaration)
|
||||
is IrProperty ->
|
||||
declarator.irProperty = serializeIrProperty(declaration)
|
||||
else
|
||||
-> TODO("Declaration serialization not supported yet: $declaration")
|
||||
}
|
||||
@@ -1114,7 +1110,7 @@ open class IrModuleSerializer(
|
||||
.setAnnotations(serializeAnnotations(file.annotations))
|
||||
|
||||
file.declarations.forEach {
|
||||
if (it is IrTypeAlias || (it.descriptor.isExpectMember && !it.descriptor.isSerializableExpectClass)) {
|
||||
if (it.descriptor.isExpectMember && !it.descriptor.isSerializableExpectClass) {
|
||||
writer.skipDeclaration()
|
||||
return@forEach
|
||||
}
|
||||
|
||||
-7
@@ -7,18 +7,11 @@ package org.jetbrains.kotlin.ir.backend.js.transformers.irToJs
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.TODO
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeAlias
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsEmpty
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNode
|
||||
|
||||
interface BaseIrElementToJsNodeTransformer<out R : JsNode, in D> : IrElementVisitor<R, D> {
|
||||
override fun visitElement(element: IrElement, data: D): R {
|
||||
TODO(element)
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias, data: D): R {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return JsEmpty as R
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,9 +200,6 @@ open class ClassCodegen protected constructor(
|
||||
is IrAnonymousInitializer -> {
|
||||
// skip
|
||||
}
|
||||
is IrTypeAlias -> {
|
||||
// skip
|
||||
}
|
||||
is IrClass -> {
|
||||
// Nested classes are generated separately
|
||||
}
|
||||
|
||||
-4
@@ -563,10 +563,6 @@ class ExpressionCodegen(
|
||||
return none()
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias, data: BlockInfo): StackValue {
|
||||
return none()
|
||||
}
|
||||
|
||||
override fun visitVararg(expression: IrVararg, data: BlockInfo): StackValue {
|
||||
expression.markLineNumber(startOffset = true)
|
||||
val outType = expression.type
|
||||
|
||||
@@ -385,7 +385,7 @@ class ClassGenerator(
|
||||
private fun generateMembersDeclaredInClassBody(irClass: IrClass, ktClassOrObject: KtPureClassOrObject) {
|
||||
// generate real body declarations
|
||||
ktClassOrObject.body?.let { ktClassBody ->
|
||||
ktClassBody.declarations.mapTo(irClass.declarations) { ktDeclaration ->
|
||||
ktClassBody.declarations.mapNotNullTo(irClass.declarations) { ktDeclaration ->
|
||||
declarationGenerator.generateClassMemberDeclaration(ktDeclaration, irClass)
|
||||
}
|
||||
}
|
||||
|
||||
+7
-14
@@ -16,11 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.psi2ir.generators
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrErrorDeclarationImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.util.withScope
|
||||
@@ -28,8 +29,6 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments
|
||||
import org.jetbrains.kotlin.psi2ir.endOffsetOrUndefined
|
||||
import org.jetbrains.kotlin.psi2ir.pureEndOffsetOrUndefined
|
||||
import org.jetbrains.kotlin.psi2ir.pureStartOffsetOrUndefined
|
||||
import org.jetbrains.kotlin.psi2ir.startOffsetOrUndefined
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
@@ -41,7 +40,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
||||
|
||||
fun KotlinType.toIrType() = typeTranslator.translateType(this)
|
||||
|
||||
fun generateMemberDeclaration(ktDeclaration: KtDeclaration): IrDeclaration =
|
||||
fun generateMemberDeclaration(ktDeclaration: KtDeclaration): IrDeclaration? =
|
||||
when (ktDeclaration) {
|
||||
is KtNamedFunction ->
|
||||
FunctionGenerator(this).generateFunctionDeclaration(ktDeclaration)
|
||||
@@ -50,7 +49,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
||||
is KtClassOrObject ->
|
||||
generateClassOrObjectDeclaration(ktDeclaration)
|
||||
is KtTypeAlias ->
|
||||
generateTypeAliasDeclaration(ktDeclaration)
|
||||
null
|
||||
else ->
|
||||
IrErrorDeclarationImpl(
|
||||
ktDeclaration.startOffsetSkippingComments, ktDeclaration.endOffset,
|
||||
@@ -62,7 +61,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
||||
return generateClassOrObjectDeclaration(syntheticDeclaration)
|
||||
}
|
||||
|
||||
fun generateClassMemberDeclaration(ktDeclaration: KtDeclaration, irClass: IrClass): IrDeclaration =
|
||||
fun generateClassMemberDeclaration(ktDeclaration: KtDeclaration, irClass: IrClass): IrDeclaration? =
|
||||
when (ktDeclaration) {
|
||||
is KtAnonymousInitializer ->
|
||||
AnonymousInitializerGenerator(this).generateAnonymousInitializerDeclaration(ktDeclaration, irClass)
|
||||
@@ -80,12 +79,6 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
||||
fun generateClassOrObjectDeclaration(ktClassOrObject: KtPureClassOrObject): IrClass =
|
||||
ClassGenerator(this).generateClass(ktClassOrObject)
|
||||
|
||||
private fun generateTypeAliasDeclaration(ktDeclaration: KtTypeAlias): IrDeclaration =
|
||||
IrTypeAliasImpl(
|
||||
ktDeclaration.startOffsetSkippingComments, ktDeclaration.endOffset, IrDeclarationOrigin.DEFINED,
|
||||
getOrFail(BindingContext.TYPE_ALIAS, ktDeclaration)
|
||||
)
|
||||
|
||||
|
||||
fun generateGlobalTypeParametersDeclarations(
|
||||
irTypeParametersOwner: IrTypeParametersContainer,
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.ir.util.IrDeserializer
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.findPackageFragmentForFile
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
||||
|
||||
@@ -66,7 +67,7 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
||||
}
|
||||
|
||||
for (ktDeclaration in ktFile.declarations) {
|
||||
irFile.declarations.add(irDeclarationGenerator.generateMemberDeclaration(ktDeclaration))
|
||||
irFile.declarations.addIfNotNull(irDeclarationGenerator.generateMemberDeclaration(ktDeclaration))
|
||||
}
|
||||
|
||||
return irFile
|
||||
|
||||
+4
-4
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.assertCast
|
||||
import org.jetbrains.kotlin.ir.builders.Scope
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
@@ -472,9 +471,10 @@ class StatementGenerator(
|
||||
LocalClassGenerator(this).generateLocalClass(classOrObject)
|
||||
|
||||
override fun visitTypeAlias(typeAlias: KtTypeAlias, data: Nothing?): IrStatement =
|
||||
IrTypeAliasImpl(
|
||||
typeAlias.startOffsetSkippingComments, typeAlias.endOffset, IrDeclarationOrigin.DEFINED,
|
||||
getOrFail(BindingContext.TYPE_ALIAS, typeAlias)
|
||||
IrBlockImpl(
|
||||
// Compile local type aliases to empty blocks
|
||||
typeAlias.startOffsetSkippingComments, typeAlias.endOffset,
|
||||
context.irBuiltIns.unitType
|
||||
)
|
||||
|
||||
override fun visitClassLiteralExpression(expression: KtClassLiteralExpression, data: Nothing?): IrStatement =
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
|
||||
interface IrTypeAlias : IrDeclaration {
|
||||
override val descriptor: TypeAliasDescriptor
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* 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.ir.declarations.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeAlias
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
|
||||
class IrTypeAliasImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
override val descriptor: TypeAliasDescriptor
|
||||
) :
|
||||
IrDeclarationBase(startOffset, endOffset, origin),
|
||||
IrTypeAlias {
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||
return visitor.visitTypeAlias(this, data)
|
||||
}
|
||||
|
||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||
// no children
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
// no children
|
||||
}
|
||||
}
|
||||
@@ -141,15 +141,6 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
declaration.transformDeclarationsTo(this)
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias): IrTypeAlias =
|
||||
IrTypeAliasImpl(
|
||||
declaration.startOffset, declaration.endOffset,
|
||||
mapDeclarationOrigin(declaration.origin),
|
||||
declaration.descriptor
|
||||
).apply {
|
||||
transformAnnotations(declaration)
|
||||
}
|
||||
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction): IrSimpleFunction =
|
||||
IrFunctionImpl(
|
||||
declaration.startOffset, declaration.endOffset,
|
||||
|
||||
@@ -226,10 +226,6 @@ class RenderIrElementVisitor(
|
||||
"inline".takeIf { isInline }
|
||||
)
|
||||
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias, data: Nothing?): String =
|
||||
"TYPEALIAS ${declaration.renderOriginIfNonTrivial()}${declaration.descriptor.ref()} " +
|
||||
"type=${DECLARATION_RENDERER.renderType(declaration.descriptor.underlyingType)}"
|
||||
|
||||
override fun visitVariable(declaration: IrVariable, data: Nothing?): String =
|
||||
"VAR ${declaration.renderOriginIfNonTrivial()}" +
|
||||
"name:${declaration.name} type:${declaration.type.render()} flags:${declaration.renderVariableFlags()}"
|
||||
|
||||
@@ -38,7 +38,6 @@ interface IrElementTransformer<in D> : IrElementVisitor<IrElement, D> {
|
||||
declaration.also { it.transformChildren(this, data) }
|
||||
|
||||
override fun visitClass(declaration: IrClass, data: D) = visitDeclaration(declaration, data)
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias, data: D) = visitDeclaration(declaration, data)
|
||||
override fun visitFunction(declaration: IrFunction, data: D) = visitDeclaration(declaration, data)
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction, data: D) = visitFunction(declaration, data)
|
||||
override fun visitConstructor(declaration: IrConstructor, data: D) = visitFunction(declaration, data)
|
||||
|
||||
@@ -49,9 +49,6 @@ abstract class IrElementTransformerVoid : IrElementTransformer<Nothing?> {
|
||||
open fun visitClass(declaration: IrClass) = visitDeclaration(declaration)
|
||||
final override fun visitClass(declaration: IrClass, data: Nothing?) = visitClass(declaration)
|
||||
|
||||
open fun visitTypeAlias(declaration: IrTypeAlias) = visitDeclaration(declaration)
|
||||
final override fun visitTypeAlias(declaration: IrTypeAlias, data: Nothing?) = visitTypeAlias(declaration)
|
||||
|
||||
open fun visitFunction(declaration: IrFunction) = visitDeclaration(declaration)
|
||||
final override fun visitFunction(declaration: IrFunction, data: Nothing?) = visitFunction(declaration)
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ interface IrElementVisitor<out R, in D> {
|
||||
|
||||
fun visitDeclaration(declaration: IrDeclaration, data: D) = visitElement(declaration, data)
|
||||
fun visitClass(declaration: IrClass, data: D) = visitDeclaration(declaration, data)
|
||||
fun visitTypeAlias(declaration: IrTypeAlias, data: D) = visitDeclaration(declaration, data)
|
||||
fun visitFunction(declaration: IrFunction, data: D) = visitDeclaration(declaration, data)
|
||||
fun visitSimpleFunction(declaration: IrSimpleFunction, data: D) = visitFunction(declaration, data)
|
||||
fun visitConstructor(declaration: IrConstructor, data: D) = visitFunction(declaration, data)
|
||||
|
||||
@@ -43,9 +43,6 @@ interface IrElementVisitorVoid : IrElementVisitor<Unit, Nothing?> {
|
||||
fun visitClass(declaration: IrClass) = visitDeclaration(declaration)
|
||||
override fun visitClass(declaration: IrClass, data: Nothing?) = visitClass(declaration)
|
||||
|
||||
fun visitTypeAlias(declaration: IrTypeAlias) = visitDeclaration(declaration)
|
||||
override fun visitTypeAlias(declaration: IrTypeAlias, data: Nothing?) = visitTypeAlias(declaration)
|
||||
|
||||
fun visitFunction(declaration: IrFunction) = visitDeclaration(declaration)
|
||||
override fun visitFunction(declaration: IrFunction, data: Nothing?) = visitFunction(declaration)
|
||||
|
||||
|
||||
-2
@@ -31,8 +31,6 @@ FILE fqName:<root> fileName:/delegatingConstructorCallToTypeAliasConstructor.kt
|
||||
overridden:
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:[]
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:[]
|
||||
TYPEALIAS typealias CT = Cell<T> type=Cell<T>
|
||||
TYPEALIAS typealias CStr = Cell<String> type=Cell<kotlin.String>
|
||||
CLASS CLASS name:C1 modality:FINAL visibility:public flags:[] superTypes:[<root>.Cell<kotlin.String>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C1 flags:[]
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.C1 flags:[primary]
|
||||
|
||||
-4
@@ -31,7 +31,3 @@ FILE fqName:<root> fileName:/typeAliasesWithAnnotations.kt
|
||||
overridden:
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:[]
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:[]
|
||||
TYPEALIAS typealias TestTypeAlias = String type=kotlin.String
|
||||
annotations:
|
||||
CALL 'CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:<root>.TestAnn flags:[primary]' type=<root>.TestAnn origin=null
|
||||
x: CONST String type=kotlin.String value="TestTypeAlias"
|
||||
|
||||
+1
-11
@@ -1,23 +1,13 @@
|
||||
FILE fqName:<root> fileName:/typeAlias.kt
|
||||
TYPEALIAS typealias Test1 = String type=kotlin.String
|
||||
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit flags:[]
|
||||
BLOCK_BODY
|
||||
TYPEALIAS typealias TestLocal = String type=kotlin.String
|
||||
annotations:
|
||||
CALL 'CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB visibility:public <> (names:kotlin.Array<out kotlin.String>) returnType:kotlin.Suppress flags:[primary]' type=kotlin.Suppress origin=null
|
||||
names: VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
|
||||
CONST String type=kotlin.String value="TOPLEVEL_TYPEALIASES_ONLY"
|
||||
BLOCK type=kotlin.Unit origin=null
|
||||
CLASS CLASS name:C modality:FINAL visibility:public flags:[] superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C flags:[]
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.C flags:[primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB visibility:public <> () returnType:kotlin.Any flags:[primary]'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public flags:[] superTypes:[kotlin.Any]'
|
||||
TYPEALIAS typealias TestNested = String type=kotlin.String
|
||||
annotations:
|
||||
CALL 'CONSTRUCTOR IR_EXTERNAL_DECLARATION_STUB visibility:public <> (names:kotlin.Array<out kotlin.String>) returnType:kotlin.Suppress flags:[primary]' type=kotlin.Suppress origin=null
|
||||
names: VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
|
||||
CONST String type=kotlin.String value="TOPLEVEL_TYPEALIASES_ONLY"
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:[]
|
||||
overridden:
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:[]
|
||||
|
||||
@@ -80,7 +80,6 @@ FILE fqName:<root> fileName:/kt16905.kt
|
||||
overridden:
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:[]
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:[]
|
||||
TYPEALIAS typealias OI = Outer.Inner type=Outer.Inner
|
||||
FUN name:test visibility:public modality:FINAL <> () returnType:<root>.Outer.Inner flags:[]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='FUN name:test visibility:public modality:FINAL <> () returnType:<root>.Outer.Inner flags:[]'
|
||||
|
||||
-1
@@ -31,7 +31,6 @@ FILE fqName:<root> fileName:/specializedTypeAliasConstructorCall.kt
|
||||
overridden:
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:[]
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:[]
|
||||
TYPEALIAS typealias IntAlias = Cell<Int> type=Cell<kotlin.Int>
|
||||
FUN name:test visibility:public modality:FINAL <> () returnType:<root>.Cell<kotlin.Int> flags:[]
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='FUN name:test visibility:public modality:FINAL <> () returnType:<root>.Cell<kotlin.Int> flags:[]'
|
||||
|
||||
@@ -40,7 +40,6 @@ FILE fqName:<root> fileName:/integerCoercionToT.kt
|
||||
overridden:
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:[]
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:[]
|
||||
TYPEALIAS typealias CInt32Var = CInt32VarX<Int> type=CInt32VarX<kotlin.Int>
|
||||
PROPERTY name:value visibility:public modality:FINAL flags:[var]
|
||||
FUN name:<get-value> visibility:public modality:FINAL <T_INT> ($receiver:<root>.CInt32VarX<<root>.<get-value>.T_INT>) returnType:<root>.<get-value>.T_INT flags:[]
|
||||
correspondingProperty: PROPERTY name:value visibility:public modality:FINAL flags:[var]
|
||||
|
||||
@@ -31,8 +31,6 @@ FILE fqName:<root> fileName:/typeAliasCtorForGenericClass.kt
|
||||
overridden:
|
||||
FUN IR_EXTERNAL_DECLARATION_STUB name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:[]
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:[]
|
||||
TYPEALIAS typealias B = A<X> type=A<X>
|
||||
TYPEALIAS typealias B2 = A<A<T>> type=A<A<T>>
|
||||
FUN name:bar visibility:public modality:FINAL <> () returnType:kotlin.Unit flags:[]
|
||||
BLOCK_BODY
|
||||
VAR name:b type:<root>.A<kotlin.Int> flags:[val]
|
||||
|
||||
Reference in New Issue
Block a user