Pseudocode: Do not store "synthetic" flag of magic instructions
This commit is contained in:
@@ -115,8 +115,7 @@ public interface JetControlFlowBuilder {
|
|||||||
@NotNull JetElement instructionElement,
|
@NotNull JetElement instructionElement,
|
||||||
@Nullable JetElement valueElement,
|
@Nullable JetElement valueElement,
|
||||||
@NotNull List<PseudoValue> inputValues,
|
@NotNull List<PseudoValue> inputValues,
|
||||||
@NotNull Map<PseudoValue, TypePredicate> expectedTypes,
|
@NotNull Map<PseudoValue, TypePredicate> expectedTypes
|
||||||
boolean synthetic
|
|
||||||
);
|
);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -71,10 +71,9 @@ public abstract class JetControlFlowBuilderAdapter implements JetControlFlowBuil
|
|||||||
@NotNull JetElement instructionElement,
|
@NotNull JetElement instructionElement,
|
||||||
@Nullable JetElement valueElement,
|
@Nullable JetElement valueElement,
|
||||||
@NotNull List<PseudoValue> inputValues,
|
@NotNull List<PseudoValue> inputValues,
|
||||||
@NotNull Map<PseudoValue, TypePredicate> expectedTypes,
|
@NotNull Map<PseudoValue, TypePredicate> expectedTypes
|
||||||
boolean synthetic
|
|
||||||
) {
|
) {
|
||||||
return getDelegateBuilder().magic(instructionElement, valueElement, inputValues, expectedTypes, synthetic);
|
return getDelegateBuilder().magic(instructionElement, valueElement, inputValues, expectedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -180,13 +180,13 @@ public class JetControlFlowProcessor {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private PseudoValue createSyntheticValue(@NotNull JetElement instructionElement, JetElement... from) {
|
private PseudoValue createSyntheticValue(@NotNull JetElement instructionElement, JetElement... from) {
|
||||||
List<PseudoValue> values = elementsToValues(from.length > 0 ? Arrays.asList(from) : Collections.<JetElement>emptyList());
|
List<PseudoValue> values = elementsToValues(from.length > 0 ? Arrays.asList(from) : Collections.<JetElement>emptyList());
|
||||||
return builder.magic(instructionElement, null, values, defaultTypeMap(values), true).getOutputValue();
|
return builder.magic(instructionElement, null, values, defaultTypeMap(values)).getOutputValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private PseudoValue createNonSyntheticValue(@NotNull JetElement to, @NotNull List<? extends JetElement> from) {
|
private PseudoValue createNonSyntheticValue(@NotNull JetElement to, @NotNull List<? extends JetElement> from) {
|
||||||
List<PseudoValue> values = elementsToValues(from);
|
List<PseudoValue> values = elementsToValues(from);
|
||||||
return builder.magic(to, to, values, defaultTypeMap(values), false).getOutputValue();
|
return builder.magic(to, to, values, defaultTypeMap(values)).getOutputValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -886,8 +886,7 @@ public class JetControlFlowProcessor {
|
|||||||
loopRange != null ? loopRange : expression,
|
loopRange != null ? loopRange : expression,
|
||||||
null,
|
null,
|
||||||
Collections.singletonList(loopRangeValue),
|
Collections.singletonList(loopRangeValue),
|
||||||
Collections.singletonMap(loopRangeValue, loopRangeTypePredicate),
|
Collections.singletonMap(loopRangeValue, loopRangeTypePredicate)
|
||||||
true
|
|
||||||
).getOutputValue();
|
).getOutputValue();
|
||||||
|
|
||||||
if (loopParameter != null) {
|
if (loopParameter != null) {
|
||||||
@@ -1387,7 +1386,7 @@ public class JetControlFlowProcessor {
|
|||||||
if (expectedTypePredicate == null) {
|
if (expectedTypePredicate == null) {
|
||||||
expectedTypePredicate = AllTypes.instance$;
|
expectedTypePredicate = AllTypes.instance$;
|
||||||
}
|
}
|
||||||
builder.magic(specifier, specifier, arguments, PseudocodePackage.expectedTypeFor(expectedTypePredicate, arguments), false);
|
builder.magic(specifier, specifier, arguments, PseudocodePackage.expectedTypeFor(expectedTypePredicate, arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+4
-5
@@ -418,7 +418,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
@Override
|
@Override
|
||||||
public InstructionWithValue loadStringTemplate(@NotNull JetStringTemplateExpression expression, @NotNull List<PseudoValue> inputValues) {
|
public InstructionWithValue loadStringTemplate(@NotNull JetStringTemplateExpression expression, @NotNull List<PseudoValue> inputValues) {
|
||||||
if (inputValues.isEmpty()) return read(expression);
|
if (inputValues.isEmpty()) return read(expression);
|
||||||
return magic(expression, expression, inputValues, PseudocodePackage.expectedTypeFor(AllTypes.instance$, inputValues), false);
|
return magic(expression, expression, inputValues, PseudocodePackage.expectedTypeFor(AllTypes.instance$, inputValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -427,11 +427,10 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
@NotNull JetElement instructionElement,
|
@NotNull JetElement instructionElement,
|
||||||
@Nullable JetElement valueElement,
|
@Nullable JetElement valueElement,
|
||||||
@NotNull List<PseudoValue> inputValues,
|
@NotNull List<PseudoValue> inputValues,
|
||||||
@NotNull Map<PseudoValue, TypePredicate> expectedTypes,
|
@NotNull Map<PseudoValue, TypePredicate> expectedTypes
|
||||||
boolean synthetic
|
|
||||||
) {
|
) {
|
||||||
MagicInstruction instruction = MagicInstruction.object$.create(
|
MagicInstruction instruction = MagicInstruction.object$.create(
|
||||||
instructionElement, valueElement, getCurrentScope(), synthetic, inputValues, expectedTypes, valueFactory
|
instructionElement, valueElement, getCurrentScope(), inputValues, expectedTypes, valueFactory
|
||||||
);
|
);
|
||||||
add(instruction);
|
add(instruction);
|
||||||
return instruction;
|
return instruction;
|
||||||
@@ -497,7 +496,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
throw new IllegalArgumentException("Invalid operation: " + operation);
|
throw new IllegalArgumentException("Invalid operation: " + operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
return magic(expression, expression, inputValues, expectedTypes, false);
|
return magic(expression, expression, inputValues, expectedTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+10
-14
@@ -97,34 +97,30 @@ public class CallInstruction private(
|
|||||||
// consume input values (so that they aren't considered unused)
|
// consume input values (so that they aren't considered unused)
|
||||||
// denote value transformation which can't be expressed by other instructions (such as call or read)
|
// denote value transformation which can't be expressed by other instructions (such as call or read)
|
||||||
// pass more than one value to instruction which formally requires only one (e.g. jump)
|
// pass more than one value to instruction which formally requires only one (e.g. jump)
|
||||||
// "Synthetic" means that the instruction does not correspond to some operation explicitly expressed by PSI element
|
|
||||||
// Examples: providing initial values for parameters, missing right-hand side in assignments
|
|
||||||
public class MagicInstruction(
|
public class MagicInstruction(
|
||||||
element: JetElement,
|
element: JetElement,
|
||||||
lexicalScope: LexicalScope,
|
lexicalScope: LexicalScope,
|
||||||
val synthetic: Boolean,
|
|
||||||
inputValues: List<PseudoValue>,
|
inputValues: List<PseudoValue>,
|
||||||
val expectedTypes: Map<PseudoValue, TypePredicate>
|
val expectedTypes: Map<PseudoValue, TypePredicate>
|
||||||
) : OperationInstruction(element, lexicalScope, inputValues), StrictlyValuedOperationInstruction {
|
) : OperationInstruction(element, lexicalScope, inputValues), StrictlyValuedOperationInstruction {
|
||||||
|
public val synthetic: Boolean get() = outputValue.element == null
|
||||||
|
|
||||||
override fun accept(visitor: InstructionVisitor) = visitor.visitMagic(this)
|
override fun accept(visitor: InstructionVisitor) = visitor.visitMagic(this)
|
||||||
|
|
||||||
override fun <R> accept(visitor: InstructionVisitorWithResult<R>): R = visitor.visitMagic(this)
|
override fun <R> accept(visitor: InstructionVisitorWithResult<R>): R = visitor.visitMagic(this)
|
||||||
|
|
||||||
override fun createCopy() = MagicInstruction(element, lexicalScope, synthetic, inputValues, expectedTypes).setResult(resultValue)
|
override fun createCopy() = MagicInstruction(element, lexicalScope, inputValues, expectedTypes).setResult(resultValue)
|
||||||
|
|
||||||
override fun toString() = renderInstruction("magic", render(element))
|
override fun toString() = renderInstruction("magic", render(element))
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
fun create(
|
fun create(element: JetElement,
|
||||||
element: JetElement,
|
valueElement: JetElement?,
|
||||||
valueElement: JetElement?,
|
lexicalScope: LexicalScope,
|
||||||
lexicalScope: LexicalScope,
|
inputValues: List<PseudoValue>,
|
||||||
synthetic: Boolean,
|
expectedTypes: Map<PseudoValue, TypePredicate>,
|
||||||
inputValues: List<PseudoValue>,
|
factory: PseudoValueFactory): MagicInstruction = MagicInstruction(
|
||||||
expectedTypes: Map<PseudoValue, TypePredicate>,
|
element, lexicalScope, inputValues, expectedTypes
|
||||||
factory: PseudoValueFactory
|
|
||||||
): MagicInstruction = MagicInstruction(
|
|
||||||
element, lexicalScope, synthetic, inputValues, expectedTypes
|
|
||||||
).setResult(factory, valueElement) as MagicInstruction
|
).setResult(factory, valueElement) as MagicInstruction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user