JVM_IR. Avoid unbound symbols and declarations without parent

This commit is contained in:
Georgy Bronnikov
2018-09-10 20:23:46 +03:00
parent 9b49c23668
commit a23aae590e
9 changed files with 99 additions and 59 deletions
@@ -16,6 +16,6 @@
package org.jetbrains.kotlin.ir.declarations
interface IrTypeParametersContainer : IrDeclaration {
interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent {
val typeParameters: MutableList<IrTypeParameter>
}
@@ -142,13 +142,13 @@ fun IrExpression.isNullConst() = this is IrConst<*> && this.kind == IrConstKind.
fun IrMemberAccessExpression.usesDefaultArguments(): Boolean =
this.descriptor.valueParameters.any { this.getValueArgument(it) == null }
fun IrFunction.createParameterDeclarations() {
fun IrFunction.createParameterDeclarations(symbolTable: SymbolTable? = null) {
fun ParameterDescriptor.irValueParameter() = IrValueParameterImpl(
innerStartOffset(this), innerEndOffset(this),
IrDeclarationOrigin.DEFINED,
this,
type.toIrType()!!,
(this as? ValueParameterDescriptor)?.varargElementType?.toIrType()
type.toIrType(symbolTable)!!,
(this as? ValueParameterDescriptor)?.varargElementType?.toIrType(symbolTable)
).also {
it.parent = this@createParameterDeclarations
}
@@ -331,6 +331,16 @@ val IrClass.isObject get() = kind == ClassKind.OBJECT
val IrDeclaration.parentAsClass get() = parent as IrClass
tailrec fun IrElement.getPackageFragment(): IrPackageFragment? {
if (this is IrPackageFragment) return this
val vParent = (this as? IrDeclaration)?.parent
return when (vParent) {
is IrPackageFragment -> vParent
is IrClass -> vParent.getPackageFragment()
else -> null
}
}
fun IrAnnotationContainer.hasAnnotation(name: FqName) =
annotations.any {
it.symbol.owner.parentAsClass.descriptor.fqNameSafe == name