Get rid of Guava in CFA (except Multimap things)
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cfg
|
||||
|
||||
import com.google.common.collect.Lists
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
@@ -667,7 +666,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
builder.jump(afterCatches, expression)
|
||||
|
||||
builder.bindLabel(onException)
|
||||
val catchLabels = Lists.newLinkedList<Label>()
|
||||
val catchLabels = LinkedList<Label>()
|
||||
val catchClausesSize = catchClauses.size
|
||||
for (i in 0..catchClausesSize - 1 - 1) {
|
||||
catchLabels.add(builder.createUnboundLabel("catch " + i))
|
||||
@@ -903,14 +902,13 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
|
||||
private fun jumpCrossesTryCatchBoundary(jumpExpression: KtExpressionWithLabel, jumpTarget: PsiElement): Boolean {
|
||||
var current = jumpExpression.parent
|
||||
while (current != null) {
|
||||
while (true) {
|
||||
when (current) {
|
||||
jumpTarget -> return false
|
||||
is KtTryExpression -> return true
|
||||
else -> current = current.parent
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private fun jumpDoesNotCrossFunctionBoundary(jumpExpression: KtExpressionWithLabel, jumpTarget: KtLoopExpression): Boolean {
|
||||
@@ -993,7 +991,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
private fun computePseudoValueForParameter(parameter: KtParameter): PseudoValue {
|
||||
val syntheticValue = createSyntheticValue(parameter, MagicKind.FAKE_INITIALIZER)
|
||||
val defaultValue = builder.getBoundValue(parameter.defaultValue) ?: return syntheticValue
|
||||
return builder.merge(parameter, Lists.newArrayList(defaultValue, syntheticValue)).outputValue
|
||||
return builder.merge(parameter, arrayListOf(defaultValue, syntheticValue)).outputValue
|
||||
}
|
||||
|
||||
override fun visitBlockExpression(expression: KtBlockExpression) {
|
||||
@@ -1096,8 +1094,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
}
|
||||
|
||||
private fun generateAndGetReceiverIfAny(expression: KtExpression): KtExpression? {
|
||||
val parent = expression.parent
|
||||
if (parent !is KtQualifiedExpression) return null
|
||||
val parent = expression.parent as? KtQualifiedExpression ?: return null
|
||||
|
||||
if (parent.selectorExpression !== expression) return null
|
||||
|
||||
@@ -1119,7 +1116,7 @@ class ControlFlowProcessor(private val trace: BindingTrace) {
|
||||
visitAssignment(property, getDeferredValue(null), property)
|
||||
generateInstructions(delegate)
|
||||
if (property.isLocal) {
|
||||
generateInitializer(property, createSyntheticValue(property, MagicKind.FAKE_INITIALIZER));
|
||||
generateInitializer(property, createSyntheticValue(property, MagicKind.FAKE_INITIALIZER))
|
||||
}
|
||||
if (builder.getBoundValue(delegate) != null) {
|
||||
createSyntheticValue(property, MagicKind.VALUE_CONSUMER, delegate)
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cfg
|
||||
|
||||
import com.google.common.collect.Maps
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudocodeUtil
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
@@ -34,18 +33,14 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils.variableDescriptorForDec
|
||||
import java.util.*
|
||||
|
||||
class PseudocodeVariablesData(val pseudocode: Pseudocode, private val bindingContext: BindingContext) {
|
||||
private val pseudocodeVariableDataCollector: PseudocodeVariableDataCollector
|
||||
private val pseudocodeVariableDataCollector = PseudocodeVariableDataCollector(bindingContext, pseudocode)
|
||||
|
||||
private val declaredVariablesForDeclaration = Maps.newHashMap<Pseudocode, Set<VariableDescriptor>>()
|
||||
private val declaredVariablesForDeclaration = hashMapOf<Pseudocode, Set<VariableDescriptor>>()
|
||||
|
||||
val variableInitializers: Map<Instruction, Edges<InitControlFlowInfo>> by lazy {
|
||||
computeVariableInitializers()
|
||||
}
|
||||
|
||||
init {
|
||||
this.pseudocodeVariableDataCollector = PseudocodeVariableDataCollector(bindingContext, pseudocode)
|
||||
}
|
||||
|
||||
val blockScopeVariableInfo: BlockScopeVariableInfo
|
||||
get() = pseudocodeVariableDataCollector.blockScopeVariableInfo
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.cfg.pseudocode
|
||||
|
||||
import com.google.common.collect.*
|
||||
import com.google.common.collect.HashMultimap
|
||||
import com.google.common.collect.Multimap
|
||||
import com.intellij.util.containers.BidirectionalMap
|
||||
import org.jetbrains.kotlin.cfg.Label
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.*
|
||||
@@ -44,9 +45,9 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
|
||||
private val elementsToValues = BidirectionalMap<KtElement, PseudoValue>()
|
||||
|
||||
private val valueUsages = Maps.newHashMap<PseudoValue, MutableList<Instruction>>()
|
||||
private val mergedValues = Maps.newHashMap<PseudoValue, Set<PseudoValue>>()
|
||||
private val sideEffectFree = Sets.newHashSet<Instruction>()
|
||||
private val valueUsages = hashMapOf<PseudoValue, MutableList<Instruction>>()
|
||||
private val mergedValues = hashMapOf<PseudoValue, Set<PseudoValue>>()
|
||||
private val sideEffectFree = hashSetOf<Instruction>()
|
||||
|
||||
override var parent: Pseudocode? = null
|
||||
private set
|
||||
@@ -77,7 +78,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
private var postPrecessed = false
|
||||
|
||||
private fun getLocalDeclarations(pseudocode: Pseudocode): Set<LocalFunctionDeclarationInstruction> {
|
||||
val localDeclarations = Sets.newLinkedHashSet<LocalFunctionDeclarationInstruction>()
|
||||
val localDeclarations = linkedSetOf<LocalFunctionDeclarationInstruction>()
|
||||
for (instruction in (pseudocode as PseudocodeImpl).mutableInstructionList) {
|
||||
if (instruction is LocalFunctionDeclarationInstruction) {
|
||||
localDeclarations.add(instruction)
|
||||
@@ -105,18 +106,17 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
|
||||
override val reversedInstructions: List<Instruction>
|
||||
get() {
|
||||
val traversedInstructions = Sets.newLinkedHashSet<Instruction>()
|
||||
val traversedInstructions = linkedSetOf<Instruction>()
|
||||
traverseFollowingInstructions(sinkInstruction, traversedInstructions, BACKWARD, null)
|
||||
if (traversedInstructions.size < instructions.size) {
|
||||
val simplyReversedInstructions = Lists.newArrayList(instructions)
|
||||
Collections.reverse(simplyReversedInstructions)
|
||||
val simplyReversedInstructions = instructions.reversed()
|
||||
for (instruction in simplyReversedInstructions) {
|
||||
if (!traversedInstructions.contains(instruction)) {
|
||||
traverseFollowingInstructions(instruction, traversedInstructions, BACKWARD, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
return Lists.newArrayList(traversedInstructions)
|
||||
return traversedInstructions.toList()
|
||||
}
|
||||
|
||||
override val instructionsIncludingDeadCode: List<Instruction>
|
||||
@@ -181,7 +181,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
|
||||
override fun getElementValue(element: KtElement?) = elementsToValues[element]
|
||||
|
||||
override fun getValueElements(value: PseudoValue?) = elementsToValues.getKeysByValue(value) ?: emptyList()
|
||||
override fun getValueElements(value: PseudoValue?): List<KtElement> = elementsToValues.getKeysByValue(value) ?: emptyList()
|
||||
|
||||
override fun getUsages(value: PseudoValue?) = valueUsages[value] ?: mutableListOf()
|
||||
|
||||
@@ -215,7 +215,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
if (usage is MergeInstruction) return
|
||||
valueUsages.getOrPut(
|
||||
value
|
||||
) { Lists.newArrayList<Instruction>() }.add(usage)
|
||||
) { arrayListOf<Instruction>() }.add(usage)
|
||||
}
|
||||
|
||||
fun postProcess() {
|
||||
@@ -223,11 +223,9 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
postPrecessed = true
|
||||
errorInstruction.sink = sinkInstruction
|
||||
exitInstruction.sink = sinkInstruction
|
||||
var index = 0
|
||||
for (instruction in mutableInstructionList) {
|
||||
for ((index, instruction) in mutableInstructionList.withIndex()) {
|
||||
//recursively invokes 'postProcess' for local declarations
|
||||
processInstruction(instruction, index)
|
||||
index++
|
||||
instruction.processInstruction(index)
|
||||
}
|
||||
if (parent != null) return
|
||||
|
||||
@@ -249,8 +247,8 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
markDeadInstructions()
|
||||
}
|
||||
|
||||
private fun processInstruction(instruction: Instruction, currentPosition: Int) {
|
||||
instruction.accept(object : InstructionVisitor() {
|
||||
private fun Instruction.processInstruction(currentPosition: Int) {
|
||||
accept(object : InstructionVisitor() {
|
||||
override fun visitInstructionWithNext(instruction: InstructionWithNext) {
|
||||
instruction.next = getNextPosition(currentPosition)
|
||||
}
|
||||
@@ -303,7 +301,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
}
|
||||
|
||||
private fun collectReachableInstructions(): Set<Instruction> {
|
||||
val visited = Sets.newHashSet<Instruction>()
|
||||
val visited = hashSetOf<Instruction>()
|
||||
traverseFollowingInstructions(enterInstruction, visited, FORWARD
|
||||
) { instruction ->
|
||||
if (instruction is MagicInstruction && instruction.kind === MagicKind.EXHAUSTIVE_WHEN_ELSE) {
|
||||
@@ -324,7 +322,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
}
|
||||
|
||||
private fun markDeadInstructions() {
|
||||
val instructionSet = Sets.newHashSet(instructions)
|
||||
val instructionSet = instructions.toHashSet()
|
||||
for (instruction in mutableInstructionList) {
|
||||
if (!instructionSet.contains(instruction)) {
|
||||
(instruction as? InstructionImpl)?.markedAsDead = true
|
||||
@@ -372,7 +370,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
val startIndex = startLabel?.targetInstructionIndex ?: 0
|
||||
val finishIndex = finishLabel?.targetInstructionIndex ?: originalPseudocode.mutableInstructionList.size
|
||||
|
||||
val originalToCopy = Maps.newLinkedHashMap<Label, PseudocodeLabel>()
|
||||
val originalToCopy = linkedMapOf<Label, PseudocodeLabel>()
|
||||
val originalLabelsForInstruction = HashMultimap.create<Instruction, Label>()
|
||||
for (label in originalPseudocode.labels) {
|
||||
val index = label.targetInstructionIndex
|
||||
@@ -381,7 +379,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
|
||||
if (label === startLabel || label === finishLabel) continue
|
||||
|
||||
if (startIndex <= index && index <= finishIndex) {
|
||||
if (index in startIndex..finishIndex) {
|
||||
originalToCopy.put(label, label.copy(this, labelCount++))
|
||||
originalLabelsForInstruction.put(getJumpTarget(label), label)
|
||||
}
|
||||
@@ -437,7 +435,7 @@ class PseudocodeImpl(override val correspondingElement: KtElement) : Pseudocode
|
||||
}
|
||||
|
||||
private fun copyLabels(labels: Collection<Label>, originalToCopy: Map<Label, PseudocodeLabel>): MutableList<Label> {
|
||||
val newLabels = Lists.newArrayList<Label>()
|
||||
val newLabels = arrayListOf<Label>()
|
||||
for (label in labels) {
|
||||
val newLabel = originalToCopy[label]
|
||||
newLabels.add(newLabel ?: label)
|
||||
|
||||
+3
-5
@@ -19,8 +19,6 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.PseudoValue
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.cfg.Label
|
||||
import com.google.common.collect.Maps
|
||||
import com.google.common.collect.Lists
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.BlockScope
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.KtElementInstructionImpl
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
@@ -35,9 +33,9 @@ class NondeterministicJumpInstruction(
|
||||
val inputValue: PseudoValue?
|
||||
) : KtElementInstructionImpl(element, blockScope), JumpInstruction {
|
||||
private var _next: Instruction? = null
|
||||
private val _resolvedTargets: MutableMap<Label, Instruction> = Maps.newLinkedHashMap()
|
||||
private val _resolvedTargets: MutableMap<Label, Instruction> = linkedMapOf()
|
||||
|
||||
val targetLabels: List<Label> = Lists.newArrayList(targetLabels)
|
||||
val targetLabels: List<Label> = ArrayList(targetLabels)
|
||||
val resolvedTargets: Map<Label, Instruction>
|
||||
get() = _resolvedTargets
|
||||
|
||||
@@ -53,7 +51,7 @@ class NondeterministicJumpInstruction(
|
||||
|
||||
override val nextInstructions: Collection<Instruction>
|
||||
get() {
|
||||
val targetInstructions = Lists.newArrayList(resolvedTargets.values)
|
||||
val targetInstructions = ArrayList(resolvedTargets.values)
|
||||
targetInstructions.add(next)
|
||||
return targetInstructions
|
||||
}
|
||||
|
||||
+3
-4
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions.special
|
||||
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.Pseudocode
|
||||
import com.google.common.collect.Lists
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.BlockScope
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.InstructionWithNext
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.instructions.Instruction
|
||||
@@ -32,14 +31,14 @@ class LocalFunctionDeclarationInstruction(
|
||||
blockScope: BlockScope
|
||||
) : InstructionWithNext(element, blockScope) {
|
||||
var sink: SubroutineSinkInstruction? = null
|
||||
set(value: SubroutineSinkInstruction?) {
|
||||
set(value) {
|
||||
field = outgoingEdgeTo(value) as SubroutineSinkInstruction?
|
||||
}
|
||||
|
||||
override val nextInstructions: Collection<Instruction>
|
||||
get() {
|
||||
if (sink != null) {
|
||||
val instructions = Lists.newArrayList<Instruction>(sink)
|
||||
sink?.let {
|
||||
val instructions = arrayListOf<Instruction>(it)
|
||||
instructions.addAll(super.nextInstructions)
|
||||
return instructions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user