Call IrSymbol.bind in declaration constructors

This commit is contained in:
Dmitry Petrov
2017-04-13 16:11:41 +03:00
parent 7995684d07
commit 57b2a4461c
13 changed files with 45 additions and 15 deletions
@@ -45,7 +45,6 @@ class SymbolTable {
inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B { inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
val symbol = getOrCreateSymbol(d, createSymbol) val symbol = getOrCreateSymbol(d, createSymbol)
val owner = createOwner(symbol) val owner = createOwner(symbol)
symbol.bind(owner)
return owner return owner
} }
@@ -128,7 +127,6 @@ class SymbolTable {
val scope = currentScope ?: throw AssertionError("No active scope") val scope = currentScope ?: throw AssertionError("No active scope")
val symbol = scope.getLocal(d) ?: createSymbol().also { scope[d] = it } val symbol = scope.getLocal(d) ?: createSymbol().also { scope[d] = it }
val owner = createOwner(symbol) val owner = createOwner(symbol)
symbol.bind(owner)
return owner return owner
} }
@@ -41,6 +41,10 @@ class IrAnonymousInitializerImpl(
this.body = body this.body = body
} }
init {
symbol.bind(this)
}
override val descriptor: ClassDescriptor get() = symbol.descriptor override val descriptor: ClassDescriptor get() = symbol.descriptor
override lateinit var body: IrBlockBody override lateinit var body: IrBlockBody
@@ -43,6 +43,10 @@ class IrClassImpl(
addAll(members) addAll(members)
} }
init {
symbol.bind(this)
}
override val descriptor: ClassDescriptor get() = symbol.descriptor override val descriptor: ClassDescriptor get() = symbol.descriptor
override var newInstanceReceiver: IrValueParameter? = null override var newInstanceReceiver: IrValueParameter? = null
@@ -42,6 +42,10 @@ class IrConstructorImpl(
this.body = body this.body = body
} }
init {
symbol.bind(this)
}
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R { override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
@@ -44,6 +44,10 @@ class IrEnumEntryImpl(
this.initializerExpression = initializerExpression this.initializerExpression = initializerExpression
} }
init {
symbol.bind(this)
}
override val descriptor: ClassDescriptor get() = symbol.descriptor override val descriptor: ClassDescriptor get() = symbol.descriptor
override var correspondingClass: IrClass? = null override var correspondingClass: IrClass? = null
override var initializerExpression: IrExpression? = null override var initializerExpression: IrExpression? = null
@@ -28,6 +28,10 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrExternalPackageFragmentImpl( class IrExternalPackageFragmentImpl(
override val symbol: IrExternalPackageFragmentSymbol override val symbol: IrExternalPackageFragmentSymbol
) : IrExternalPackageFragment, IrElementBase(UNDEFINED_OFFSET, UNDEFINED_OFFSET) { ) : IrExternalPackageFragment, IrElementBase(UNDEFINED_OFFSET, UNDEFINED_OFFSET) {
init {
symbol.bind(this)
}
override val packageFragmentDescriptor: PackageFragmentDescriptor get() = symbol.descriptor override val packageFragmentDescriptor: PackageFragmentDescriptor get() = symbol.descriptor
override val declarations: MutableList<IrDeclaration> = ArrayList() override val declarations: MutableList<IrDeclaration> = ArrayList()
@@ -42,6 +42,10 @@ class IrFieldImpl(
this.initializer = initializer this.initializer = initializer
} }
init {
symbol.bind(this)
}
override val descriptor: PropertyDescriptor = symbol.descriptor override val descriptor: PropertyDescriptor = symbol.descriptor
override var initializer: IrExpressionBody? = null override var initializer: IrExpressionBody? = null
@@ -46,6 +46,10 @@ class IrFileImpl(
this.declarations.addAll(declarations) this.declarations.addAll(declarations)
} }
init {
symbol.bind(this)
}
override val packageFragmentDescriptor: PackageFragmentDescriptor get() = symbol.descriptor override val packageFragmentDescriptor: PackageFragmentDescriptor get() = symbol.descriptor
override val fileAnnotations: MutableList<AnnotationDescriptor> = SmartList() override val fileAnnotations: MutableList<AnnotationDescriptor> = SmartList()
@@ -45,6 +45,10 @@ class IrFunctionImpl(
this.body = body this.body = body
} }
init {
symbol.bind(this)
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitSimpleFunction(this, data) visitor.visitSimpleFunction(this, data)
} }
@@ -35,6 +35,10 @@ class IrTypeParameterImpl(
constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: TypeParameterDescriptor) : constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: TypeParameterDescriptor) :
this(startOffset, endOffset, origin, IrTypeParameterSymbolImpl(descriptor)) this(startOffset, endOffset, origin, IrTypeParameterSymbolImpl(descriptor))
init {
symbol.bind(this)
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitTypeParameter(this, data) visitor.visitTypeParameter(this, data)
@@ -46,6 +46,10 @@ class IrValueParameterImpl(
this.defaultValue = defaultValue this.defaultValue = defaultValue
} }
init {
symbol.bind(this)
}
override var defaultValue: IrExpressionBody? = null override var defaultValue: IrExpressionBody? = null
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R = override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -44,6 +44,10 @@ class IrVariableImpl(
this.initializer = initializer this.initializer = initializer
} }
init {
symbol.bind(this)
}
override val descriptor: VariableDescriptor get() = symbol.descriptor override val descriptor: VariableDescriptor get() = symbol.descriptor
override var initializer: IrExpression? = null override var initializer: IrExpression? = null
@@ -66,7 +66,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
IrExternalPackageFragmentImpl( IrExternalPackageFragmentImpl(
symbolsRemapper.getDeclaredExternalPackageFragment(declaration.symbol) symbolsRemapper.getDeclaredExternalPackageFragment(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
declaration.transformDeclarationsTo(this) declaration.transformDeclarationsTo(this)
} }
@@ -75,7 +74,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
declaration.fileEntry, declaration.fileEntry,
symbolsRemapper.getDeclaredFile(declaration.symbol) symbolsRemapper.getDeclaredFile(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
fileAnnotations.addAll(declaration.fileAnnotations) fileAnnotations.addAll(declaration.fileAnnotations)
declaration.transformDeclarationsTo(this) declaration.transformDeclarationsTo(this)
} }
@@ -89,7 +87,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredClass(declaration.symbol) symbolsRemapper.getDeclaredClass(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
newInstanceReceiver = declaration.newInstanceReceiver?.transform() newInstanceReceiver = declaration.newInstanceReceiver?.transform()
declaration.typeParameters.transformTo(typeParameters) declaration.typeParameters.transformTo(typeParameters)
declaration.transformDeclarationsTo(this) declaration.transformDeclarationsTo(this)
@@ -108,7 +105,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredFunction(declaration.symbol) symbolsRemapper.getDeclaredFunction(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
transformFunctionChildren(declaration) transformFunctionChildren(declaration)
} }
@@ -118,7 +114,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredConstructor(declaration.symbol) symbolsRemapper.getDeclaredConstructor(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
transformFunctionChildren(declaration) transformFunctionChildren(declaration)
} }
@@ -148,7 +143,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredField(declaration.symbol) symbolsRemapper.getDeclaredField(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
initializer = declaration.initializer?.transform() initializer = declaration.initializer?.transform()
} }
@@ -168,7 +162,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredEnumEntry(declaration.symbol) symbolsRemapper.getDeclaredEnumEntry(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
correspondingClass = declaration.correspondingClass?.transform() correspondingClass = declaration.correspondingClass?.transform()
initializerExpression = declaration.initializerExpression?.transform() initializerExpression = declaration.initializerExpression?.transform()
} }
@@ -179,7 +172,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
IrAnonymousInitializerSymbolImpl(declaration.descriptor) IrAnonymousInitializerSymbolImpl(declaration.descriptor)
).apply { ).apply {
symbol.bind(this)
body = declaration.body.transform() body = declaration.body.transform()
} }
@@ -189,7 +181,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredVariable(declaration.symbol) symbolsRemapper.getDeclaredVariable(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
initializer = declaration.initializer?.transform() initializer = declaration.initializer?.transform()
} }
@@ -198,9 +189,7 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
declaration.startOffset, declaration.endOffset, declaration.startOffset, declaration.endOffset,
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredTypeParameter(declaration.symbol) symbolsRemapper.getDeclaredTypeParameter(declaration.symbol)
).apply { )
symbol.bind(this)
}
override fun visitValueParameter(declaration: IrValueParameter): IrValueParameter = override fun visitValueParameter(declaration: IrValueParameter): IrValueParameter =
IrValueParameterImpl( IrValueParameterImpl(
@@ -208,7 +197,6 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
mapDeclarationOrigin(declaration.origin), mapDeclarationOrigin(declaration.origin),
symbolsRemapper.getDeclaredValueParameter(declaration.symbol) symbolsRemapper.getDeclaredValueParameter(declaration.symbol)
).apply { ).apply {
symbol.bind(this)
defaultValue = declaration.defaultValue?.transform() defaultValue = declaration.defaultValue?.transform()
} }