Pseudocode: Generate read instructions on call expression (instead of

callee)
This commit is contained in:
Alexey Sedunov
2014-07-25 15:22:58 +04:00
parent 9f3ebe5f3b
commit 85bb4f9b8e
6 changed files with 48 additions and 8 deletions
@@ -1499,12 +1499,12 @@ public class JetControlFlowProcessor {
if (resultingDescriptor instanceof VariableDescriptor) {
// If a callee of the call is just a variable (without 'invoke'), 'read variable' is generated.
// todo : process arguments for such a case (KT-5387)
JetExpression calleeExpression = PsiUtilPackage.getCalleeExpressionIfAny(callElement);
assert calleeExpression != null
JetExpression callExpression = callElement instanceof JetExpression ? (JetExpression) callElement : null;
assert callExpression != null
: "Variable-based call without callee expression: " + callElement.getText();
assert parameterValues.isEmpty()
: "Variable-based call with non-empty argument list: " + callElement.getText();
return builder.readVariable(calleeExpression, resolvedCall, receivers);
return builder.readVariable(callExpression, resolvedCall, receivers);
}
mark(resolvedCall.getCall().getCallElement());
return builder.call(callElement, resolvedCall, receivers, parameterValues);
@@ -0,0 +1,19 @@
== foo ==
fun foo(i: Int) {
i()
}
---------------------
L0:
1 <START>
v(i: Int)
magic[FAKE_INITIALIZER](i: Int) -> <v0>
w(i|<v0>)
2 mark({ i() })
r(i) -> <v1>
L1:
1 <END> NEXT:[<SINK>]
error:
<ERROR> PREV:[]
sink:
<SINK> PREV:[<ERROR>, <END>]
=====================
@@ -0,0 +1,3 @@
fun foo(i: Int) {
i()
}
@@ -0,0 +1,10 @@
== foo ==
fun foo(i: Int) {
i()
}
---------------------
<v0>: Int NEW: magic[FAKE_INITIALIZER](i: Int) -> <v0>
i <v1>: * NEW: r(i) -> <v1>
i() !<v2>: *
{ i() } !<v2>: * COPY
=====================
@@ -368,7 +368,7 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
public void testAssignments() throws Exception {
doTest("compiler/testData/cfg/expressions/Assignments.kt");
}
@TestMetadata("callableReferences.kt")
public void testCallableReferences() throws Exception {
doTest("compiler/testData/cfg/expressions/callableReferences.kt");
@@ -394,6 +394,11 @@ public class ControlFlowTestGenerated extends AbstractControlFlowTest {
doTest("compiler/testData/cfg/expressions/incdec.kt");
}
@TestMetadata("invalidVariableCall.kt")
public void testInvalidVariableCall() throws Exception {
doTest("compiler/testData/cfg/expressions/invalidVariableCall.kt");
}
@TestMetadata("LazyBooleans.kt")
public void testLazyBooleans() throws Exception {
doTest("compiler/testData/cfg/expressions/LazyBooleans.kt");
@@ -358,9 +358,7 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
@TestMetadata("compiler/testData/cfg/expressions")
public static class Expressions extends AbstractPseudoValueTest {
public void testAllFilesPresentInExpressions() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage",
new File("compiler/testData/cfg/expressions"), Pattern.compile("^(.+)\\.kt$"),
true);
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cfg/expressions"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("assignmentToThis.kt")
@@ -372,7 +370,7 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
public void testAssignments() throws Exception {
doTest("compiler/testData/cfg/expressions/Assignments.kt");
}
@TestMetadata("callableReferences.kt")
public void testCallableReferences() throws Exception {
doTest("compiler/testData/cfg/expressions/callableReferences.kt");
@@ -398,6 +396,11 @@ public class PseudoValueTestGenerated extends AbstractPseudoValueTest {
doTest("compiler/testData/cfg/expressions/incdec.kt");
}
@TestMetadata("invalidVariableCall.kt")
public void testInvalidVariableCall() throws Exception {
doTest("compiler/testData/cfg/expressions/invalidVariableCall.kt");
}
@TestMetadata("LazyBooleans.kt")
public void testLazyBooleans() throws Exception {
doTest("compiler/testData/cfg/expressions/LazyBooleans.kt");