Pseudocode: Generate magics for cast expressions
This commit is contained in:
@@ -1203,7 +1203,9 @@ public class JetControlFlowProcessor {
|
|||||||
JetExpression left = expression.getLeft();
|
JetExpression left = expression.getLeft();
|
||||||
if (operationType == JetTokens.COLON || operationType == JetTokens.AS_KEYWORD || operationType == JetTokens.AS_SAFE) {
|
if (operationType == JetTokens.COLON || operationType == JetTokens.AS_KEYWORD || operationType == JetTokens.AS_SAFE) {
|
||||||
generateInstructions(left);
|
generateInstructions(left);
|
||||||
copyValue(left, expression);
|
if (builder.getBoundValue(left) != null) {
|
||||||
|
createNonSyntheticValue(expression, MagicKind.CAST, left);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
visitJetElement(expression);
|
visitJetElement(expression);
|
||||||
|
|||||||
+1
@@ -139,6 +139,7 @@ public enum class MagicKind {
|
|||||||
NOT_NULL_ASSERTION
|
NOT_NULL_ASSERTION
|
||||||
EQUALS_IN_WHEN_CONDITION
|
EQUALS_IN_WHEN_CONDITION
|
||||||
IS
|
IS
|
||||||
|
CAST
|
||||||
CALLABLE_REFERENCE
|
CALLABLE_REFERENCE
|
||||||
// implicit operations
|
// implicit operations
|
||||||
LOOP_RANGE_ITERATION
|
LOOP_RANGE_ITERATION
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
== foo ==
|
||||||
|
fun foo(a: Any) {
|
||||||
|
a : String
|
||||||
|
a as String
|
||||||
|
a as? String
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
L0:
|
||||||
|
1 <START>
|
||||||
|
v(a: Any)
|
||||||
|
magic[FAKE_INITIALIZER](a: Any) -> <v0>
|
||||||
|
w(a|<v0>)
|
||||||
|
2 mark({ a : String a as String a as? String })
|
||||||
|
mark(a : String)
|
||||||
|
r(a) -> <v1>
|
||||||
|
magic[CAST](a : String|<v1>) -> <v2>
|
||||||
|
mark(a as String)
|
||||||
|
r(a) -> <v3>
|
||||||
|
magic[CAST](a as String|<v3>) -> <v4>
|
||||||
|
mark(a as? String)
|
||||||
|
r(a) -> <v5>
|
||||||
|
magic[CAST](a as? String|<v5>) -> <v6>
|
||||||
|
L1:
|
||||||
|
1 <END> NEXT:[<SINK>]
|
||||||
|
error:
|
||||||
|
<ERROR> PREV:[]
|
||||||
|
sink:
|
||||||
|
<SINK> PREV:[<ERROR>, <END>]
|
||||||
|
=====================
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(a: Any) {
|
||||||
|
a : String
|
||||||
|
a as String
|
||||||
|
a as? String
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
== foo ==
|
||||||
|
fun foo(a: Any) {
|
||||||
|
a : String
|
||||||
|
a as String
|
||||||
|
a as? String
|
||||||
|
}
|
||||||
|
---------------------
|
||||||
|
<v0>: {<: Any} NEW: magic[FAKE_INITIALIZER](a: Any) -> <v0>
|
||||||
|
a <v1>: * NEW: r(a) -> <v1>
|
||||||
|
a : String <v2>: * NEW: magic[CAST](a : String|<v1>) -> <v2>
|
||||||
|
a <v3>: * NEW: r(a) -> <v3>
|
||||||
|
a as String <v4>: * NEW: magic[CAST](a as String|<v3>) -> <v4>
|
||||||
|
a <v5>: * NEW: r(a) -> <v5>
|
||||||
|
a as? String <v6>: * NEW: magic[CAST](a as? String|<v5>) -> <v6>
|
||||||
|
{ a : String a as String a as? String } <v6>: * COPY
|
||||||
|
=====================
|
||||||
@@ -374,6 +374,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
|
|||||||
doTest("compiler/testData/cfg/expressions/callableReferences.kt");
|
doTest("compiler/testData/cfg/expressions/callableReferences.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("casts.kt")
|
||||||
|
public void testCasts() throws Exception {
|
||||||
|
doTest("compiler/testData/cfg/expressions/casts.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("chainedQualifiedExpression.kt")
|
@TestMetadata("chainedQualifiedExpression.kt")
|
||||||
public void testChainedQualifiedExpression() throws Exception {
|
public void testChainedQualifiedExpression() throws Exception {
|
||||||
doTest("compiler/testData/cfg/expressions/chainedQualifiedExpression.kt");
|
doTest("compiler/testData/cfg/expressions/chainedQualifiedExpression.kt");
|
||||||
|
|||||||
@@ -378,6 +378,11 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
|
|||||||
doTest("compiler/testData/cfg/expressions/callableReferences.kt");
|
doTest("compiler/testData/cfg/expressions/callableReferences.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("casts.kt")
|
||||||
|
public void testCasts() throws Exception {
|
||||||
|
doTest("compiler/testData/cfg/expressions/casts.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("chainedQualifiedExpression.kt")
|
@TestMetadata("chainedQualifiedExpression.kt")
|
||||||
public void testChainedQualifiedExpression() throws Exception {
|
public void testChainedQualifiedExpression() throws Exception {
|
||||||
doTest("compiler/testData/cfg/expressions/chainedQualifiedExpression.kt");
|
doTest("compiler/testData/cfg/expressions/chainedQualifiedExpression.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user