Parameter to receiver

This commit is contained in:
Valentin Kipyatkov
2020-04-12 20:40:50 +03:00
parent 04d4f7444e
commit fdfae5260f
2 changed files with 6 additions and 11 deletions
@@ -156,17 +156,17 @@ class OutflowSlicer(
expressionWithValue.processPseudocodeUsages { pseudoValue, instruction ->
when (instruction) {
is WriteValueInstruction -> {
if (!processIfReceiverValue(instruction, pseudoValue, mode)) {
if (!pseudoValue.processIfReceiverValue(instruction, mode)) {
instruction.target.accessedDescriptor?.originalSource?.getPsi()?.passToProcessor()
}
}
is ReadValueInstruction -> {
processIfReceiverValue(instruction, pseudoValue, mode)
pseudoValue.processIfReceiverValue(instruction, mode)
}
is CallInstruction -> {
if (!processIfReceiverValue(instruction, pseudoValue, mode)) {
if (!pseudoValue.processIfReceiverValue(instruction, mode)) {
val parameterDescriptor = instruction.arguments[pseudoValue] ?: return@processPseudocodeUsages
val parameter = parameterDescriptor.originalSource.getPsi()
if (parameter != null) {
@@ -257,7 +257,7 @@ abstract class Slicer(
pseudocode.getUsages(receiverPseudoValue).forEach { receiverUseInstruction ->
if (receiverUseInstruction is KtElementInstruction) {
// TODO: make sure it processes correct receiver!!
processIfReceiverValue(receiverUseInstruction, receiverPseudoValue, mode)
receiverPseudoValue.processIfReceiverValue(receiverUseInstruction, mode)
}
}
}
@@ -265,12 +265,8 @@ abstract class Slicer(
}
}
protected fun processIfReceiverValue(
instruction: KtElementInstruction,
receiverPseudoValue: PseudoValue,
mode: KotlinSliceAnalysisMode,
): Boolean {
val receiverValue = (instruction as? InstructionWithReceivers)?.receiverValues?.get(receiverPseudoValue) ?: return false
protected fun PseudoValue.processIfReceiverValue(instruction: KtElementInstruction, mode: KotlinSliceAnalysisMode): Boolean {
val receiverValue = (instruction as? InstructionWithReceivers)?.receiverValues?.get(this) ?: return false
val resolvedCall = instruction.element.resolveToCall() ?: return true
val descriptor = resolvedCall.resultingDescriptor
@@ -309,7 +305,6 @@ abstract class Slicer(
}
}
return true
}