- Compact representation for empty blocks.
- Fix some issues in IrBlockImpl.
This commit is contained in:
committed by
Dmitry Petrov
parent
09c52696a5
commit
40a60e430f
@@ -32,13 +32,33 @@ fun IrBlockImpl.addIfNotNull(statement: IrStatement?) {
|
|||||||
if (statement != null) addStatement(statement)
|
if (statement != null) addStatement(statement)
|
||||||
}
|
}
|
||||||
|
|
||||||
class IrBlockImpl(
|
class IrEmptyBlockImpl(startOffset: Int, endOffset: Int, type: KotlinType, override val operator: IrOperator? = null) :
|
||||||
startOffset: Int,
|
IrExpressionBase(startOffset, endOffset, type), IrBlock {
|
||||||
endOffset: Int,
|
override val statements: List<IrStatement> get() = emptyList()
|
||||||
type: KotlinType,
|
|
||||||
override val operator: IrOperator? = null
|
override fun getChild(slot: Int): IrElement? = null
|
||||||
) : IrExpressionBase(startOffset, endOffset, type), IrBlock {
|
|
||||||
override val statements: MutableList<IrStatement> = ArrayList()
|
override fun replaceChild(slot: Int, newChild: IrElement) {
|
||||||
|
// no children
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||||
|
return visitor.visitBlock(this, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||||
|
// no children
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class IrBlockImpl(startOffset: Int, endOffset: Int, type: KotlinType, override val operator: IrOperator? = null):
|
||||||
|
IrExpressionBase(startOffset, endOffset, type), IrBlock {
|
||||||
|
constructor(startOffset: Int, endOffset: Int, type: KotlinType, operator: IrOperator?, statements: List<IrStatement>) :
|
||||||
|
this(startOffset, endOffset, type, operator) {
|
||||||
|
addAll(statements)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val statements: MutableList<IrStatement> = ArrayList(2)
|
||||||
|
|
||||||
fun addStatement(statement: IrStatement) {
|
fun addStatement(statement: IrStatement) {
|
||||||
statement.assertDetached()
|
statement.assertDetached()
|
||||||
@@ -46,11 +66,11 @@ class IrBlockImpl(
|
|||||||
statements.add(statement)
|
statements.add(statement)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addAll(statements: List<IrStatement>) {
|
fun addAll(newStatements: List<IrStatement>) {
|
||||||
statements.forEach { it.assertDetached() }
|
newStatements.forEach { it.assertDetached() }
|
||||||
val originalSize = statements.size
|
val originalSize = this.statements.size
|
||||||
this.statements.addAll(statements)
|
this.statements.addAll(newStatements)
|
||||||
statements.forEachIndexed { i, irStatement ->
|
newStatements.forEachIndexed { i, irStatement ->
|
||||||
irStatement.setTreeLocation(this, originalSize + i)
|
irStatement.setTreeLocation(this, originalSize + i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user