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 -> expressionWithValue.processPseudocodeUsages { pseudoValue, instruction ->
when (instruction) { when (instruction) {
is WriteValueInstruction -> { is WriteValueInstruction -> {
if (!processIfReceiverValue(instruction, pseudoValue, mode)) { if (!pseudoValue.processIfReceiverValue(instruction, mode)) {
instruction.target.accessedDescriptor?.originalSource?.getPsi()?.passToProcessor() instruction.target.accessedDescriptor?.originalSource?.getPsi()?.passToProcessor()
} }
} }
is ReadValueInstruction -> { is ReadValueInstruction -> {
processIfReceiverValue(instruction, pseudoValue, mode) pseudoValue.processIfReceiverValue(instruction, mode)
} }
is CallInstruction -> { is CallInstruction -> {
if (!processIfReceiverValue(instruction, pseudoValue, mode)) { if (!pseudoValue.processIfReceiverValue(instruction, mode)) {
val parameterDescriptor = instruction.arguments[pseudoValue] ?: return@processPseudocodeUsages val parameterDescriptor = instruction.arguments[pseudoValue] ?: return@processPseudocodeUsages
val parameter = parameterDescriptor.originalSource.getPsi() val parameter = parameterDescriptor.originalSource.getPsi()
if (parameter != null) { if (parameter != null) {
@@ -257,7 +257,7 @@ abstract class Slicer(
pseudocode.getUsages(receiverPseudoValue).forEach { receiverUseInstruction -> pseudocode.getUsages(receiverPseudoValue).forEach { receiverUseInstruction ->
if (receiverUseInstruction is KtElementInstruction) { if (receiverUseInstruction is KtElementInstruction) {
// TODO: make sure it processes correct receiver!! // 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( protected fun PseudoValue.processIfReceiverValue(instruction: KtElementInstruction, mode: KotlinSliceAnalysisMode): Boolean {
instruction: KtElementInstruction, val receiverValue = (instruction as? InstructionWithReceivers)?.receiverValues?.get(this) ?: return false
receiverPseudoValue: PseudoValue,
mode: KotlinSliceAnalysisMode,
): Boolean {
val receiverValue = (instruction as? InstructionWithReceivers)?.receiverValues?.get(receiverPseudoValue) ?: return false
val resolvedCall = instruction.element.resolveToCall() ?: return true val resolvedCall = instruction.element.resolveToCall() ?: return true
val descriptor = resolvedCall.resultingDescriptor val descriptor = resolvedCall.resultingDescriptor
@@ -309,7 +305,6 @@ abstract class Slicer(
} }
} }
return true return true
} }