Array access expression.

This commit is contained in:
Dmitry Petrov
2016-08-25 09:44:16 +03:00
committed by Dmitry Petrov
parent 54e6bbd007
commit b3407de1e6
5 changed files with 44 additions and 5 deletions
@@ -207,7 +207,6 @@ class StatementGenerator(
}
}
is PropertyDescriptor -> {
// TODO safe calls
CallGenerator(this).generateCall(expression.startOffset, expression.endOffset, pregenerateCall(resolvedCall))
}
is VariableDescriptor ->
@@ -226,11 +225,16 @@ class StatementGenerator(
TODO("VariableAsFunctionResolvedCall = variable call + invoke call")
}
// TODO safe calls
return CallGenerator(this).generateCall(expression.startOffset, expression.endOffset, pregenerateCall(resolvedCall))
}
override fun visitArrayAccessExpression(expression: KtArrayAccessExpression, data: Nothing?): IrStatement {
val indexedGetCall = getOrFail(BindingContext.INDEXED_LVALUE_GET, expression)
return CallGenerator(this).generateCall(expression.startOffset, expression.endOffset,
pregenerateCall(indexedGetCall), IrOperator.GET_ARRAY_ELEMENT)
}
override fun visitDotQualifiedExpression(expression: KtDotQualifiedExpression, data: Nothing?): IrStatement =
expression.selectorExpression!!.accept(this, data)
@@ -297,6 +301,5 @@ class StatementGenerator(
override fun visitTryExpression(expression: KtTryExpression, data: Nothing?): IrStatement =
TryCatchExpressionGenerator(this).generateTryCatch(expression)
}
}
@@ -53,6 +53,7 @@ interface IrOperator {
object RANGE : IrOperatorImpl("RANGE")
object INVOKE : IrOperatorImpl("INVOKE")
object GET_ARRAY_ELEMENT : IrOperatorImpl("GET_ARRAY_ELEMENT")
object PREFIX_INCR : IrOperatorImpl("PREFIX_INCR")
object PREFIX_DECR : IrOperatorImpl("PREFIX_DECR")
+5
View File
@@ -0,0 +1,5 @@
val p = 0
fun foo() = 1
fun test(a: IntArray) =
a[0] + a[p] + a[foo()]
+24
View File
@@ -0,0 +1,24 @@
IrFile /arrayAccess.kt
IrProperty public val p: kotlin.Int = 0 getter=null setter=null
IrExpressionBody
CONST Int type=kotlin.Int value='0'
IrFunction public fun foo(): kotlin.Int
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
CONST Int type=kotlin.Int value='1'
IrFunction public fun test(/*0*/ a: kotlin.IntArray): kotlin.Int
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
CALL .plus type=kotlin.Int operator=PLUS
$this: CALL .plus type=kotlin.Int operator=PLUS
$this: CALL .get type=kotlin.Int operator=GET_ARRAY_ELEMENT
$this: GET_VAR a type=kotlin.IntArray operator=null
index: CONST Int type=kotlin.Int value='0'
other: CALL .get type=kotlin.Int operator=GET_ARRAY_ELEMENT
$this: GET_VAR a type=kotlin.IntArray operator=null
index: CALL .<get-p> type=kotlin.Int operator=GET_PROPERTY
other: CALL .get type=kotlin.Int operator=GET_ARRAY_ELEMENT
$this: GET_VAR a type=kotlin.IntArray operator=null
index: CALL .foo type=kotlin.Int operator=null
@@ -35,6 +35,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("arrayAccess.kt")
public void testArrayAccess() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/arrayAccess.kt");
doTest(fileName);
}
@TestMetadata("arrayAssignment.kt")
public void testArrayAssignment() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/arrayAssignment.kt");