Pseudocode: Introduce ValuedInstruction
This commit is contained in:
+1
-1
@@ -106,7 +106,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
private final PseudoValueFactory valueFactory = new PseudoValueFactoryImpl() {
|
||||
@NotNull
|
||||
@Override
|
||||
public PseudoValue newValue(@Nullable JetElement element, @NotNull Instruction instruction) {
|
||||
public PseudoValue newValue(@Nullable JetElement element, @NotNull InstructionWithValue instruction) {
|
||||
PseudoValue value = super.newValue(element, instruction);
|
||||
if (element != null) {
|
||||
bindValue(value, element);
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
package org.jetbrains.jet.lang.cfg.pseudocode
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.Instruction
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.InstructionWithValue
|
||||
|
||||
public trait PseudoValue {
|
||||
public val debugName: String
|
||||
public val element: JetElement?
|
||||
public val createdAt: Instruction
|
||||
public val createdAt: InstructionWithValue
|
||||
}
|
||||
|
||||
public trait PseudoValueFactory {
|
||||
public fun newValue(element: JetElement?, instruction: Instruction): PseudoValue
|
||||
public fun newValue(element: JetElement?, instruction: InstructionWithValue): PseudoValue
|
||||
}
|
||||
@@ -17,12 +17,12 @@
|
||||
package org.jetbrains.jet.lang.cfg.pseudocode
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.Instruction
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.InstructionWithValue
|
||||
|
||||
class PseudoValueImpl(
|
||||
public override val debugName: String,
|
||||
public override val element: JetElement?,
|
||||
public override val createdAt: Instruction
|
||||
public override val createdAt: InstructionWithValue
|
||||
) : PseudoValue {
|
||||
override fun toString(): String = debugName
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class PseudoValueImpl(
|
||||
open class PseudoValueFactoryImpl: PseudoValueFactory {
|
||||
private var lastIndex: Int = 0
|
||||
|
||||
override fun newValue(element: JetElement?, instruction: Instruction): PseudoValue {
|
||||
override fun newValue(element: JetElement?, instruction: InstructionWithValue): PseudoValue {
|
||||
return PseudoValueImpl("<v${lastIndex++}>", element, instruction)
|
||||
}
|
||||
}
|
||||
-1
@@ -29,7 +29,6 @@ public trait Instruction {
|
||||
public val lexicalScope: LexicalScope
|
||||
|
||||
public val inputValues: List<PseudoValue>
|
||||
public val outputValue: pseudocode.PseudoValue?
|
||||
|
||||
public fun getCopies(): Collection<Instruction>
|
||||
|
||||
|
||||
-1
@@ -69,7 +69,6 @@ public abstract class InstructionImpl(public override val lexicalScope: LexicalS
|
||||
override val previousInstructions: MutableCollection<Instruction> = LinkedHashSet()
|
||||
|
||||
override val inputValues: List<PseudoValue> = Collections.emptyList()
|
||||
override val outputValue: PseudoValue? = null
|
||||
|
||||
override fun getCopies(): Collection<Instruction> {
|
||||
return original?.let { original ->
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval
|
||||
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.JetElementInstruction
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
|
||||
|
||||
public trait InstructionWithValue : JetElementInstruction {
|
||||
public val outputValue: PseudoValue?
|
||||
}
|
||||
+1
-2
@@ -20,7 +20,6 @@ import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValueFactory
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.LexicalScope
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.InstructionWithReceiver
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitor
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitorWithResult
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionImpl
|
||||
@@ -30,7 +29,7 @@ public class ReadValueInstruction private (
|
||||
lexicalScope: LexicalScope,
|
||||
receiverValue: PseudoValue?,
|
||||
private var _outputValue: PseudoValue?
|
||||
) : InstructionWithReceiver(element, lexicalScope, receiverValue) {
|
||||
) : InstructionWithReceiver(element, lexicalScope, receiverValue), InstructionWithValue {
|
||||
private fun newResultValue(factory: PseudoValueFactory) {
|
||||
_outputValue = factory.newValue(element, this)
|
||||
}
|
||||
|
||||
-1
@@ -21,7 +21,6 @@ import org.jetbrains.jet.lang.psi.JetNamedDeclaration
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.LexicalScope
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.InstructionWithReceiver
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitor
|
||||
import java.util.Arrays
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitorWithResult
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public abstract class OperationInstruction protected(
|
||||
element: JetElement,
|
||||
lexicalScope: LexicalScope,
|
||||
public override val inputValues: List<PseudoValue>
|
||||
) : InstructionWithNext(element, lexicalScope) {
|
||||
) : InstructionWithNext(element, lexicalScope), InstructionWithValue {
|
||||
protected var resultValue: PseudoValue? = null
|
||||
|
||||
override val outputValue: PseudoValue?
|
||||
|
||||
Reference in New Issue
Block a user