From 4f54d833d3beb9ae645a89971d5b327465ab2499 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 11 Jul 2014 19:30:22 +0400 Subject: [PATCH] Pseudocode: Generate instructions for callable reference expressions --- .../jet/lang/cfg/JetControlFlowProcessor.java | 6 ++++ .../eval/operationInstructions.kt | 1 + .../callableReferences.instructions | 29 +++++++++++++++++++ .../cfg/expressions/callableReferences.kt | 3 ++ .../cfg/expressions/callableReferences.values | 10 +++++++ .../jet/cfg/ControlFlowTestGenerated.java | 5 ++++ .../jet/cfg/PseudoValueTestGenerated.java | 9 +++++- 7 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/cfg/expressions/callableReferences.instructions create mode 100644 compiler/testData/cfg/expressions/callableReferences.kt create mode 100644 compiler/testData/cfg/expressions/callableReferences.values diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 535be19add1..3f18b1498f8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -1414,6 +1414,12 @@ public class JetControlFlowProcessor { } } + @Override + public void visitCallableReferenceExpression(@NotNull JetCallableReferenceExpression expression) { + mark(expression); + createNonSyntheticValue(expression, MagicKind.CALLABLE_REFERENCE); + } + @Override public void visitJetElement(@NotNull JetElement element) { builder.unsupported(element); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt index e7a7d3ed444..fd62a4e6cf1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt @@ -139,6 +139,7 @@ public enum class MagicKind { NOT_NULL_ASSERTION EQUALS_IN_WHEN_CONDITION IS + CALLABLE_REFERENCE // implicit operations LOOP_RANGE_ITERATION IMPLICIT_RECEIVER diff --git a/compiler/testData/cfg/expressions/callableReferences.instructions b/compiler/testData/cfg/expressions/callableReferences.instructions new file mode 100644 index 00000000000..b1b613a9824 --- /dev/null +++ b/compiler/testData/cfg/expressions/callableReferences.instructions @@ -0,0 +1,29 @@ +== bar == +fun bar(): Int = 1 +--------------------- +L0: + 1 + r(1) -> + ret(*|) L1 +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== +== foo == +fun foo(): Any = ::bar +--------------------- +L0: + 1 + mark(::bar) + magic[CALLABLE_REFERENCE](::bar) -> + ret(*|) L1 +L1: + NEXT:[] +error: + PREV:[] +sink: + PREV:[, ] +===================== diff --git a/compiler/testData/cfg/expressions/callableReferences.kt b/compiler/testData/cfg/expressions/callableReferences.kt new file mode 100644 index 00000000000..9c1241e55f8 --- /dev/null +++ b/compiler/testData/cfg/expressions/callableReferences.kt @@ -0,0 +1,3 @@ +fun bar(): Int = 1 + +fun foo(): Any = ::bar \ No newline at end of file diff --git a/compiler/testData/cfg/expressions/callableReferences.values b/compiler/testData/cfg/expressions/callableReferences.values new file mode 100644 index 00000000000..0d8e5c606cc --- /dev/null +++ b/compiler/testData/cfg/expressions/callableReferences.values @@ -0,0 +1,10 @@ +== bar == +fun bar(): Int = 1 +--------------------- +1 : Int NEW: r(1) -> +===================== +== foo == +fun foo(): Any = ::bar +--------------------- +::bar : {<: Any} NEW: magic[CALLABLE_REFERENCE](::bar) -> +===================== diff --git a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java index 8ec6caec2cd..61d7e5c8002 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/ControlFlowTestGenerated.java @@ -368,6 +368,11 @@ 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"); + } @TestMetadata("chainedQualifiedExpression.kt") public void testChainedQualifiedExpression() throws Exception { diff --git a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java index 3940cd4cce4..4e55d0e22fc 100644 --- a/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/cfg/PseudoValueTestGenerated.java @@ -358,7 +358,9 @@ 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") @@ -370,6 +372,11 @@ 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"); + } @TestMetadata("chainedQualifiedExpression.kt") public void testChainedQualifiedExpression() throws Exception {