From 605da5b7b9d86ec49d619126e29848db4439d7c6 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 26 Jan 2016 18:13:42 +0300 Subject: [PATCH] ControlFlowBuilder: converted to Kotlin --- .../kotlin/cfg/ControlFlowBuilder.kt | 195 ++++++++---------- .../kotlin/cfg/ControlFlowBuilderAdapter.java | 18 +- .../ControlFlowInstructionsGenerator.java | 20 +- 3 files changed, 105 insertions(+), 128 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt index e04dd3eac8c..6cbeaf7d23d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt @@ -14,151 +14,128 @@ * limitations under the License. */ -package org.jetbrains.kotlin.cfg; +package org.jetbrains.kotlin.cfg -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue; -import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode; -import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.*; -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor; -import org.jetbrains.kotlin.psi.*; -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; -import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant; -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; +import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue +import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode +import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.* +import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant +import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import java.util.List; -import java.util.Map; - -public interface ControlFlowBuilder { +interface ControlFlowBuilder { // Subroutines - void enterSubroutine(@NotNull KtElement subroutine); + fun enterSubroutine(subroutine: KtElement) - @NotNull - Pseudocode exitSubroutine(@NotNull KtElement subroutine); + fun exitSubroutine(subroutine: KtElement): Pseudocode - @NotNull - KtElement getCurrentSubroutine(); - @Nullable - KtElement getReturnSubroutine(); + val currentSubroutine: KtElement + val returnSubroutine: KtElement? // Lexical scopes - void enterLexicalScope(@NotNull KtElement element); - void exitLexicalScope(@NotNull KtElement element); + fun enterLexicalScope(element: KtElement) + + fun exitLexicalScope(element: KtElement) // Entry/exit points - @NotNull - Label getEntryPoint(@NotNull KtElement labelElement); - @NotNull - Label getExitPoint(@NotNull KtElement labelElement); - @NotNull - Label getConditionEntryPoint(@NotNull KtElement labelElement); + fun getEntryPoint(labelElement: KtElement): Label + + fun getExitPoint(labelElement: KtElement): Label + fun getConditionEntryPoint(labelElement: KtElement): Label // Declarations - void declareParameter(@NotNull KtParameter parameter); - void declareVariable(@NotNull KtVariableDeclaration property); - void declareFunction(@NotNull KtElement subroutine, @NotNull Pseudocode pseudocode); + fun declareParameter(parameter: KtParameter) + + fun declareVariable(property: KtVariableDeclaration) + fun declareFunction(subroutine: KtElement, pseudocode: Pseudocode) // Labels - @NotNull - Label createUnboundLabel(); - @NotNull - Label createUnboundLabel(@NotNull String name); + fun createUnboundLabel(): Label - void bindLabel(@NotNull Label label); + fun createUnboundLabel(name: String): Label + + fun bindLabel(label: Label) // Jumps - void jump(@NotNull Label label, @NotNull KtElement element); - void jumpOnFalse(@NotNull Label label, @NotNull KtElement element, @Nullable PseudoValue conditionValue); - void jumpOnTrue(@NotNull Label label, @NotNull KtElement element, @Nullable PseudoValue conditionValue); - void nondeterministicJump(@NotNull Label label, @NotNull KtElement element, @Nullable PseudoValue inputValue); // Maybe, jump to label - void nondeterministicJump(@NotNull List