Supported index++ pattern as non-last statement and even inside expressions
This commit is contained in:
@@ -181,8 +181,8 @@ enum class TraverseInstructionResult {
|
||||
// returns false when interrupted by handler
|
||||
fun traverseFollowingInstructions(
|
||||
rootInstruction: Instruction,
|
||||
visited: MutableSet<Instruction>,
|
||||
order: TraversalOrder,
|
||||
visited: MutableSet<Instruction> = HashSet(),
|
||||
order: TraversalOrder = FORWARD,
|
||||
// true to continue traversal
|
||||
handler: ((Instruction) -> TraverseInstructionResult)?
|
||||
): Boolean {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.cfg.pseudocode
|
||||
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDeclarationInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction
|
||||
@@ -51,4 +52,6 @@ interface Pseudocode {
|
||||
fun isSideEffectFree(instruction: Instruction): Boolean
|
||||
|
||||
fun copy(): Pseudocode
|
||||
|
||||
fun instructionForElement(element: KtElement): KtElementInstruction?
|
||||
}
|
||||
|
||||
@@ -30,17 +30,14 @@ import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.LocalFunctionDec
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineEnterInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineExitInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.special.SubroutineSinkInstruction
|
||||
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.*
|
||||
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraverseInstructionResult
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
|
||||
import java.util.*
|
||||
|
||||
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraversalOrder.BACKWARD
|
||||
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraversalOrder.FORWARD
|
||||
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.TraverseInstructionResult
|
||||
import org.jetbrains.kotlin.cfg.pseudocodeTraverser.traverseFollowingInstructions
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import java.util.*
|
||||
|
||||
class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode {
|
||||
|
||||
inner class PseudocodeLabel internal constructor(private val name: String, private val comment: String?) : Label {
|
||||
var targetInstructionIndex: Int? = null
|
||||
private set
|
||||
@@ -89,8 +86,8 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
override val localDeclarations: Set<LocalFunctionDeclarationInstruction> by lazy {
|
||||
getLocalDeclarations(this)
|
||||
}
|
||||
//todo getters
|
||||
private val representativeInstructions = HashMap<KtElement, Instruction>()
|
||||
|
||||
private val representativeInstructions = HashMap<KtElement, KtElementInstruction>()
|
||||
|
||||
private val labels = ArrayList<PseudocodeLabel>()
|
||||
|
||||
@@ -191,7 +188,9 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
instruction.owner = this
|
||||
|
||||
if (instruction is KtElementInstruction) {
|
||||
representativeInstructions.put(instruction.element, instruction)
|
||||
if (!representativeInstructions.containsKey(instruction.element)) {
|
||||
representativeInstructions.put(instruction.element, instruction)
|
||||
}
|
||||
}
|
||||
|
||||
if (instruction is MergeInstruction) {
|
||||
@@ -379,6 +378,10 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
return result
|
||||
}
|
||||
|
||||
override fun instructionForElement(element: KtElement): KtElementInstruction? {
|
||||
return representativeInstructions[element]
|
||||
}
|
||||
|
||||
private fun repeatWhole(originalPseudocode: PseudocodeImpl) {
|
||||
repeatInternal(originalPseudocode, null, null, 0)
|
||||
parent = originalPseudocode.parent
|
||||
|
||||
Reference in New Issue
Block a user