Pseudocode: Record resolved information in read/write instructions. Introduce AccessValueInstruction
This commit is contained in:
@@ -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<PseudoValue, ReceiverValue> 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<PseudoValue, ReceiverValue> receiverValues);
|
||||
|
||||
// Other
|
||||
void unsupported(JetElement element);
|
||||
|
||||
@@ -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<PseudoValue, ReceiverValue> 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<PseudoValue, ReceiverValue> receiverValues) {
|
||||
getDelegateBuilder().write(assignment, lValue, rValue, target, receiverValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.<PseudoValue, ReceiverValue>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<PseudoValue, ReceiverValue> 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<PseudoValue, ReceiverValue> 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);
|
||||
|
||||
+22
-13
@@ -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<PseudoValue, ReceiverValue> 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<PseudoValue> 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<PseudoValue, ReceiverValue> 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<PseudoValue, ReceiverValue> 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.<PseudoValue, ReceiverValue>emptyMap());
|
||||
}
|
||||
}
|
||||
|
||||
public static class TryFinallyBlockInfo extends BlockInfo {
|
||||
|
||||
+6
-2
@@ -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) {
|
||||
|
||||
+6
-2
@@ -24,10 +24,14 @@ import org.jetbrains.jet.lang.cfg.pseudocode.instructions.special.*
|
||||
public abstract class InstructionVisitorWithResult<R>() {
|
||||
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<R>() {
|
||||
}
|
||||
|
||||
public open fun visitWriteValue(instruction: WriteValueInstruction): R {
|
||||
return visitInstructionWithNext(instruction)
|
||||
return visitAccessInstruction(instruction)
|
||||
}
|
||||
|
||||
public open fun visitLoadUnitValue(instruction: LoadUnitValueInstruction): R {
|
||||
|
||||
+40
@@ -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<PseudoValue, ReceiverValue>
|
||||
) : InstructionWithNext(element, lexicalScope), InstructionWithReceivers
|
||||
+2
-1
@@ -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<PseudoValue>
|
||||
public val receiverValues: Map<PseudoValue, ReceiverValue>
|
||||
}
|
||||
+9
-12
@@ -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<PseudoValue, ReceiverValue>,
|
||||
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<PseudoValue>
|
||||
get() = ContainerUtil.createMaybeSingletonList(receiverValue)
|
||||
|
||||
override val inputValues: List<PseudoValue>
|
||||
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<PseudoValue, ReceiverValue>,
|
||||
factory: PseudoValueFactory
|
||||
): ReadValueInstruction {
|
||||
return ReadValueInstruction(element, lexicalScope, receiverValue, null).let { instruction ->
|
||||
return ReadValueInstruction(element, lexicalScope, target, receiverValues, null).let { instruction ->
|
||||
instruction.newResultValue(factory)
|
||||
instruction
|
||||
}
|
||||
|
||||
+8
-12
@@ -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<PseudoValue, ReceiverValue>,
|
||||
public val lValue: JetElement,
|
||||
public val rValue: PseudoValue,
|
||||
public val receiverValue: PseudoValue?,
|
||||
lexicalScope: LexicalScope
|
||||
) : InstructionWithNext(assignment, lexicalScope), InstructionWithReceivers {
|
||||
override val receiverValues: List<PseudoValue>
|
||||
get() = ContainerUtil.createMaybeSingletonList(receiverValue)
|
||||
|
||||
public val rValue: PseudoValue
|
||||
) : AccessValueInstruction(assignment, lexicalScope, target, receiverValues) {
|
||||
override val inputValues: List<PseudoValue>
|
||||
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)
|
||||
}
|
||||
|
||||
+3
-6
@@ -61,12 +61,9 @@ public class CallInstruction private(
|
||||
element: JetElement,
|
||||
lexicalScope: LexicalScope,
|
||||
val resolvedCall: ResolvedCall<*>,
|
||||
public val receiverValueMap: Map<PseudoValue, ReceiverValue>,
|
||||
public override val receiverValues: Map<PseudoValue, ReceiverValue>,
|
||||
public val arguments: Map<PseudoValue, ValueParameterDescriptor>
|
||||
) : OperationInstruction(element, lexicalScope, receiverValueMap.keySet() + arguments.keySet()), InstructionWithReceivers {
|
||||
override val receiverValues: List<PseudoValue>
|
||||
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()}")
|
||||
|
||||
Reference in New Issue
Block a user