diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java index a92573192ce..1c37511288e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilder.java @@ -20,9 +20,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue; import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode; +import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.AccessTarget; import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; @@ -126,9 +126,12 @@ public interface JetControlFlowBuilder { @NotNull PseudoValue readThis(@NotNull JetExpression expression, @Nullable ReceiverParameterDescriptor parameterDescriptor); + @NotNull PseudoValue readVariable( - @NotNull JetExpression expression, @Nullable VariableDescriptor variableDescriptor, @Nullable PseudoValue receiverValue + @NotNull JetExpression expression, + @NotNull ResolvedCall resolvedCall, + @NotNull Map receiverValues ); @Nullable @@ -153,7 +156,12 @@ public interface JetControlFlowBuilder { void compilationError(@NotNull JetElement element, @NotNull String message); - void write(@NotNull JetElement assignment, @NotNull JetElement lValue, @NotNull PseudoValue rValue, @Nullable PseudoValue receiverValue); + void write( + @NotNull JetElement assignment, + @NotNull JetElement lValue, + @NotNull PseudoValue rValue, + @NotNull AccessTarget target, + @NotNull Map receiverValues); // Other void unsupported(JetElement element); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java index 6a1bc510368..acd15845357 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowBuilderAdapter.java @@ -20,9 +20,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue; import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode; +import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.AccessTarget; import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; @@ -94,9 +94,9 @@ public abstract class JetControlFlowBuilderAdapter implements JetControlFlowBuil @Override public PseudoValue readVariable( @NotNull JetExpression expression, - @Nullable VariableDescriptor variableDescriptor, - @Nullable PseudoValue receiverValue) { - return getDelegateBuilder().readVariable(expression, variableDescriptor, receiverValue); + @NotNull ResolvedCall resolvedCall, + @NotNull Map receiverValues) { + return getDelegateBuilder().readVariable(expression, resolvedCall, receiverValues); } @Nullable @@ -258,8 +258,9 @@ public abstract class JetControlFlowBuilderAdapter implements JetControlFlowBuil @NotNull JetElement assignment, @NotNull JetElement lValue, @NotNull PseudoValue rValue, - @Nullable PseudoValue receiverValue) { - getDelegateBuilder().write(assignment, lValue, rValue, receiverValue); + @NotNull AccessTarget target, + @NotNull Map receiverValues) { + getDelegateBuilder().write(assignment, lValue, rValue, target, receiverValues); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 781eb6940bc..679f9bd2487 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -32,8 +32,10 @@ import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowInstructionsGenerator import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue; import org.jetbrains.jet.lang.cfg.pseudocode.Pseudocode; import org.jetbrains.jet.lang.cfg.pseudocode.PseudocodeImpl; +import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.AccessTarget; import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingTrace; @@ -230,6 +232,30 @@ public class JetControlFlowProcessor { ); } + private void generateInitializer(@NotNull JetDeclaration declaration, @NotNull PseudoValue initValue) { + builder.write( + declaration, + declaration, + initValue, + getDeclarationAccessTarget(declaration), + Collections.emptyMap() + ); + } + + @NotNull + private AccessTarget getResolvedCallAccessTarget(JetElement element) { + ResolvedCall resolvedCall = trace.get(BindingContext.RESOLVED_CALL, element); + return resolvedCall != null ? new AccessTarget.Call(resolvedCall) : AccessTarget.BlackBox.instance$; + } + + @NotNull + private AccessTarget getDeclarationAccessTarget(JetElement element) { + DeclarationDescriptor descriptor = trace.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element); + return descriptor instanceof VariableDescriptor + ? new AccessTarget.Declaration((VariableDescriptor) descriptor) + : AccessTarget.BlackBox.instance$; + } + @Override public void visitParenthesizedExpressionVoid(@NotNull JetParenthesizedExpression expression, CFPContext context) { mark(expression); @@ -407,20 +433,22 @@ public class JetControlFlowProcessor { } PseudoValue rhsValue = rhsDeferredValue.invoke(); - PseudoValue receiverValue = null; - if (left instanceof JetSimpleNameExpression || left instanceof JetProperty) { - // Do nothing, just record write below + Map receiverValues = SmartFMap.emptyMap(); + AccessTarget accessTarget = AccessTarget.BlackBox.instance$; + if (left instanceof JetSimpleNameExpression || left instanceof JetQualifiedExpression) { + accessTarget = getResolvedCallAccessTarget(PsiUtilPackage.getQualifiedElementSelector(left)); + if (accessTarget instanceof AccessTarget.Call) { + receiverValues = getReceiverValues(((AccessTarget.Call) accessTarget).getResolvedCall(), true); + } } - else if (left instanceof JetQualifiedExpression) { - JetExpression receiverExpression = ((JetQualifiedExpression) left).getReceiverExpression(); - generateInstructions(receiverExpression, NOT_IN_CONDITION); - receiverValue = builder.getBoundValue(receiverExpression); + else if (left instanceof JetProperty) { + accessTarget = getDeclarationAccessTarget(left); } else { builder.unsupported(parentExpression); // TODO } - recordWrite(left, rhsValue, receiverValue, parentExpression); + recordWrite(left, accessTarget, rhsValue, receiverValues, parentExpression); } private void generateArrayAssignment( @@ -491,11 +519,21 @@ public class JetControlFlowProcessor { return argumentValues; } - private void recordWrite(JetExpression left, PseudoValue rightValue, PseudoValue receiverValue, JetExpression parentExpression) { + private void recordWrite( + @NotNull JetExpression left, + @NotNull AccessTarget target, + @Nullable PseudoValue rightValue, + @NotNull Map receiverValues, + @NotNull JetExpression parentExpression) { VariableDescriptor descriptor = BindingContextUtils.extractVariableDescriptorIfAny(trace.getBindingContext(), left, false); if (descriptor != null) { - builder.write(parentExpression, left, rightValue != null ? rightValue : createSyntheticValue(parentExpression), - receiverValue); + builder.write( + parentExpression, + left, + rightValue != null ? rightValue : createSyntheticValue(parentExpression), + target, + receiverValues + ); } } @@ -712,7 +750,7 @@ public class JetControlFlowProcessor { JetParameter catchParameter = catchClause.getCatchParameter(); if (catchParameter != null) { builder.declareParameter(catchParameter); - builder.write(catchParameter, catchParameter, createSyntheticValue(catchParameter), null); + generateInitializer(catchParameter, createSyntheticValue(catchParameter)); } JetExpression catchBody = catchClause.getCatchBody(); if (catchBody != null) { @@ -834,11 +872,11 @@ public class JetControlFlowProcessor { ); if (loopParameter != null) { - builder.write(loopParameter, loopParameter, value, null); + generateInitializer(loopParameter, value); } else if (multiDeclaration != null) { for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) { - builder.write(entry, entry, value, null); + generateInitializer(entry, value); } } } @@ -937,7 +975,7 @@ public class JetControlFlowProcessor { if (defaultValue != null) { generateInstructions(defaultValue, context); } - builder.write(parameter, parameter, createSyntheticValue(parameter), null); + generateInitializer(parameter, createSyntheticValue(parameter)); } @Override @@ -1079,7 +1117,7 @@ public class JetControlFlowProcessor { : builder.magic(entry, null, ContainerUtil.createMaybeSingletonList(builder.getBoundValue(initializer)), true); if (generateWriteForEntries) { - builder.write(entry, entry, writtenValue != null ? writtenValue : createSyntheticValue(entry), null); + generateInitializer(entry, writtenValue != null ? writtenValue : createSyntheticValue(entry)); } } } @@ -1341,9 +1379,9 @@ public class JetControlFlowProcessor { } if (resultingDescriptor instanceof VariableDescriptor) { - assert parameterValues.isEmpty() && receivers.size() <= 1 - : "Wrong input values for variable-based call (must be at most 1 receiver): " + resolvedCall.getCall().getCallElement().getText(); - builder.readVariable(calleeExpression, (VariableDescriptor) resultingDescriptor, KotlinPackage.firstOrNull(receivers.keySet())); + assert parameterValues.isEmpty() + : "Variable-based call with non-empty argument list: " + resolvedCall.getCall().getCallElement().getText(); + builder.readVariable(calleeExpression, resolvedCall, receivers); } else { builder.call(calleeExpression, resolvedCall, receivers, parameterValues); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java index 2d3f76d2138..ba1eee9dc8e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java @@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.jumps.*; import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.*; import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; -import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; @@ -306,8 +305,9 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd @NotNull JetElement assignment, @NotNull JetElement lValue, @NotNull PseudoValue rValue, - @Nullable PseudoValue receiverValue) { - add(new WriteValueInstruction(assignment, lValue, rValue, receiverValue, getCurrentScope())); + @NotNull AccessTarget target, + @NotNull Map receiverValues) { + add(new WriteValueInstruction(assignment, getCurrentScope(), target, receiverValues, lValue, rValue)); } @Override @@ -402,25 +402,25 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd @NotNull @Override public PseudoValue loadConstant(@NotNull JetExpression expression, @Nullable CompileTimeConstant constant) { - return read(expression, null); + return read(expression); } @NotNull @Override public PseudoValue createAnonymousObject(@NotNull JetObjectLiteralExpression expression) { - return read(expression, null); + return read(expression); } @NotNull @Override public PseudoValue createFunctionLiteral(@NotNull JetFunctionLiteralExpression expression) { - return read(expression, null); + return read(expression); } @NotNull @Override public PseudoValue loadStringTemplate(@NotNull JetStringTemplateExpression expression, @NotNull List inputValues) { - return inputValues.isEmpty() ? read(expression, null) : magic(expression, expression, inputValues, false); + return inputValues.isEmpty() ? read(expression) : magic(expression, expression, inputValues, false); } @NotNull @@ -448,17 +448,17 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd @NotNull @Override public PseudoValue readThis(@NotNull JetExpression expression, @Nullable ReceiverParameterDescriptor parameterDescriptor) { - return read(expression, null); + return read(expression); } @NotNull @Override public PseudoValue readVariable( @NotNull JetExpression expression, - @Nullable VariableDescriptor variableDescriptor, - @Nullable PseudoValue receiverValue + @NotNull ResolvedCall resolvedCall, + @NotNull Map receiverValues ) { - return read(expression, receiverValue); + return read(expression, resolvedCall, receiverValues); } @Nullable @@ -498,12 +498,21 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd } @NotNull - private PseudoValue read(@NotNull JetExpression expression, @Nullable PseudoValue receiverValue) { + private PseudoValue read( + @NotNull JetExpression expression, + @Nullable ResolvedCall resolvedCall, + @NotNull Map receiverValues) { + AccessTarget accessTarget = resolvedCall != null ? new AccessTarget.Call(resolvedCall) : AccessTarget.BlackBox.instance$; ReadValueInstruction instruction = - ReadValueInstruction.object$.create(expression, getCurrentScope(), receiverValue, valueFactory); + ReadValueInstruction.object$.create(expression, getCurrentScope(), accessTarget, receiverValues, valueFactory); add(instruction); return instruction.getOutputValue(); } + + @NotNull + private PseudoValue read(@NotNull JetExpression expression) { + return read(expression, null, Collections.emptyMap()); + } } public static class TryFinallyBlockInfo extends BlockInfo { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitor.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitor.kt index 3bc0867c2c8..42280d9810c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitor.kt @@ -22,10 +22,14 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.* import org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval.* public open class InstructionVisitor() { - public open fun visitReadValue(instruction: ReadValueInstruction) { + public open fun visitAccessInstruction(instruction: AccessValueInstruction) { visitInstructionWithNext(instruction) } + public open fun visitReadValue(instruction: ReadValueInstruction) { + visitAccessInstruction(instruction) + } + public open fun visitLocalFunctionDeclarationInstruction(instruction: LocalFunctionDeclarationInstruction) { visitInstructionWithNext(instruction) } @@ -86,7 +90,7 @@ public open class InstructionVisitor() { } public open fun visitWriteValue(instruction: WriteValueInstruction) { - visitInstructionWithNext(instruction) + visitAccessInstruction(instruction) } public open fun visitLoadUnitValue(instruction: LoadUnitValueInstruction) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitorWithResult.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitorWithResult.kt index 5ecda68c914..4e135df27f1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitorWithResult.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/InstructionVisitorWithResult.kt @@ -24,10 +24,14 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.* public abstract class InstructionVisitorWithResult() { public abstract fun visitInstruction(instruction: Instruction): R - public open fun visitReadValue(instruction: ReadValueInstruction): R { + public open fun visitAccessInstruction(instruction: AccessValueInstruction): R { return visitInstructionWithNext(instruction) } + public open fun visitReadValue(instruction: ReadValueInstruction): R { + return visitAccessInstruction(instruction) + } + public open fun visitLocalFunctionDeclarationInstruction(instruction: LocalFunctionDeclarationInstruction): R { return visitInstructionWithNext(instruction) } @@ -85,7 +89,7 @@ public abstract class InstructionVisitorWithResult() { } public open fun visitWriteValue(instruction: WriteValueInstruction): R { - return visitInstructionWithNext(instruction) + return visitAccessInstruction(instruction) } public open fun visitLoadUnitValue(instruction: LoadUnitValueInstruction): R { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/AccessValueInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/AccessValueInstruction.kt new file mode 100644 index 00000000000..4a23137e339 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/AccessValueInstruction.kt @@ -0,0 +1,40 @@ +/* + * 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.psi.JetElement +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.InstructionWithNext +import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall +import org.jetbrains.jet.lang.descriptors.VariableDescriptor +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue +import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind +import java.util.Collections + +public trait AccessTarget { + public data class Declaration(val descriptor: VariableDescriptor): AccessTarget + public data class Call(val resolvedCall: ResolvedCall<*>): AccessTarget + public object BlackBox: AccessTarget +} + +public abstract class AccessValueInstruction protected ( + element: JetElement, + lexicalScope: LexicalScope, + public val target: AccessTarget, + public override val receiverValues: Map +) : InstructionWithNext(element, lexicalScope), InstructionWithReceivers \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/InstructionWithReceivers.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/InstructionWithReceivers.kt index 2d7bec994d1..ee908d02114 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/InstructionWithReceivers.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/InstructionWithReceivers.kt @@ -18,7 +18,8 @@ package org.jetbrains.jet.lang.cfg.pseudocode.instructions.eval import org.jetbrains.jet.lang.cfg.pseudocode.PseudoValue import org.jetbrains.jet.lang.cfg.pseudocode.instructions.Instruction +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue public trait InstructionWithReceivers: Instruction { - public val receiverValues: List + public val receiverValues: Map } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt index 70eebf36e1f..248f862eea5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/ReadValueInstruction.kt @@ -23,25 +23,21 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.LexicalScope 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 -import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionWithNext -import com.intellij.util.containers.ContainerUtil import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue public class ReadValueInstruction private ( element: JetElement, lexicalScope: LexicalScope, - public val receiverValue: PseudoValue?, + target: AccessTarget, + receiverValues: Map, private var _outputValue: PseudoValue? -) : InstructionWithNext(element, lexicalScope), InstructionWithReceivers, InstructionWithValue { +) : AccessValueInstruction(element, lexicalScope, target, receiverValues), InstructionWithValue { private fun newResultValue(factory: PseudoValueFactory) { _outputValue = factory.newValue(element, this) } - override val receiverValues: List - get() = ContainerUtil.createMaybeSingletonList(receiverValue) - override val inputValues: List - get() = receiverValues + get() = receiverValues.keySet().toList() override val outputValue: PseudoValue get() = _outputValue!! @@ -55,21 +51,22 @@ public class ReadValueInstruction private ( } override fun toString(): String { - val inVal = if (receiverValue != null) "|$receiverValue" else "" + val inVal = if (receiverValues.empty) "" else "|${receiverValues.keySet().makeString()}" return "r(${render(element)}$inVal) -> $outputValue" } override fun createCopy(): InstructionImpl = - ReadValueInstruction(element, lexicalScope, receiverValue, outputValue) + ReadValueInstruction(element, lexicalScope, target, receiverValues, outputValue) class object { public fun create ( element: JetElement, lexicalScope: LexicalScope, - receiverValue: PseudoValue?, + target: AccessTarget, + receiverValues: Map, factory: PseudoValueFactory ): ReadValueInstruction { - return ReadValueInstruction(element, lexicalScope, receiverValue, null).let { instruction -> + return ReadValueInstruction(element, lexicalScope, target, receiverValues, null).let { instruction -> instruction.newResultValue(factory) instruction } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt index 286190f12b5..43beda2653a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/WriteValueInstruction.kt @@ -22,24 +22,20 @@ 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.InstructionVisitor -import java.util.Arrays import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionVisitorWithResult import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionImpl -import org.jetbrains.jet.lang.cfg.pseudocode.instructions.InstructionWithNext -import com.intellij.util.containers.ContainerUtil +import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue public class WriteValueInstruction( assignment: JetElement, + lexicalScope: LexicalScope, + target: AccessTarget, + receiverValues: Map, public val lValue: JetElement, - public val rValue: PseudoValue, - public val receiverValue: PseudoValue?, - lexicalScope: LexicalScope -) : InstructionWithNext(assignment, lexicalScope), InstructionWithReceivers { - override val receiverValues: List - get() = ContainerUtil.createMaybeSingletonList(receiverValue) - + public val rValue: PseudoValue +) : AccessValueInstruction(assignment, lexicalScope, target, receiverValues) { override val inputValues: List - get() = receiverValue?.let{ receiverValue -> Arrays.asList(receiverValue, rValue) } ?: Collections.singletonList(rValue) + get() = receiverValues.keySet() + rValue override fun accept(visitor: InstructionVisitor) { visitor.visitWriteValue(this) @@ -55,5 +51,5 @@ public class WriteValueInstruction( } override fun createCopy(): InstructionImpl = - WriteValueInstruction(element, lValue, rValue, receiverValue, lexicalScope) + WriteValueInstruction(element, lexicalScope, target, receiverValues, lValue, rValue) } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt index 339b23442cb..1696f9013c3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/instructions/eval/operationInstructions.kt @@ -61,12 +61,9 @@ public class CallInstruction private( element: JetElement, lexicalScope: LexicalScope, val resolvedCall: ResolvedCall<*>, - public val receiverValueMap: Map, + public override val receiverValues: Map, public val arguments: Map -) : OperationInstruction(element, lexicalScope, receiverValueMap.keySet() + arguments.keySet()), InstructionWithReceivers { - override val receiverValues: List - get() = receiverValueMap.keySet().toList() - +) : OperationInstruction(element, lexicalScope, receiverValues.keySet() + arguments.keySet()), InstructionWithReceivers { override fun accept(visitor: InstructionVisitor) { visitor.visitCallInstruction(this) } @@ -76,7 +73,7 @@ public class CallInstruction private( } override fun createCopy() = - CallInstruction(element, lexicalScope, resolvedCall, receiverValueMap, arguments).setResult(resultValue) + CallInstruction(element, lexicalScope, resolvedCall, receiverValues, arguments).setResult(resultValue) override fun toString() = renderInstruction("call", "${render(element)}, ${resolvedCall.getResultingDescriptor()!!.getName()}")