Minor. Get rid of code duplication
For initialization of destructuring entries in loops use the same logic as for common local destructuring The behavior may change a little: variable start label in a table becomes less precise (now it starts a little bit earlier than it become initialized), but it can't be very important as the same logic works for common destructuring
This commit is contained in:
@@ -767,38 +767,37 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
assignToLoopParameter();
|
assignToLoopParameter();
|
||||||
v.mark(loopParameterStartLabel);
|
v.mark(loopParameterStartLabel);
|
||||||
|
|
||||||
KtDestructuringDeclaration multiParameter = forExpression.getDestructuringDeclaration();
|
KtDestructuringDeclaration destructuringDeclaration = forExpression.getDestructuringDeclaration();
|
||||||
if (multiParameter != null) {
|
if (destructuringDeclaration != null) {
|
||||||
generateMultiVariables(multiParameter.getEntries());
|
generateDestructuringDeclaration(destructuringDeclaration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateMultiVariables(List<KtDestructuringDeclarationEntry> entries) {
|
private void generateDestructuringDeclaration(@NotNull KtDestructuringDeclaration destructuringDeclaration) {
|
||||||
for (KtDestructuringDeclarationEntry variableDeclaration : entries) {
|
final Label destructuringStartLabel = new Label();
|
||||||
|
for (KtDestructuringDeclarationEntry variableDeclaration : destructuringDeclaration.getEntries()) {
|
||||||
final VariableDescriptor componentDescriptor = bindingContext.get(VARIABLE, variableDeclaration);
|
final VariableDescriptor componentDescriptor = bindingContext.get(VARIABLE, variableDeclaration);
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions") final Type componentAsmType = asmType(componentDescriptor.getReturnType());
|
@SuppressWarnings("ConstantConditions") final Type componentAsmType = asmType(componentDescriptor.getReturnType());
|
||||||
final int componentVarIndex = myFrameMap.enter(componentDescriptor, componentAsmType);
|
final int componentVarIndex = myFrameMap.enter(componentDescriptor, componentAsmType);
|
||||||
final Label variableStartLabel = new Label();
|
|
||||||
scheduleLeaveVariable(new Runnable() {
|
scheduleLeaveVariable(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
myFrameMap.leave(componentDescriptor);
|
myFrameMap.leave(componentDescriptor);
|
||||||
v.visitLocalVariable(componentDescriptor.getName().asString(),
|
v.visitLocalVariable(componentDescriptor.getName().asString(),
|
||||||
componentAsmType.getDescriptor(), null,
|
componentAsmType.getDescriptor(), null,
|
||||||
variableStartLabel, bodyEnd,
|
destructuringStartLabel, bodyEnd,
|
||||||
componentVarIndex);
|
componentVarIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration);
|
|
||||||
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
|
|
||||||
Call call = makeFakeCall(new TransientReceiver(elementType));
|
|
||||||
|
|
||||||
StackValue value = invokeFunction(call, resolvedCall, StackValue.local(loopParameterVar, asmElementType));
|
|
||||||
StackValue.local(componentVarIndex, componentAsmType).store(value, v);
|
|
||||||
v.visitLabel(variableStartLabel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v.visitLabel(destructuringStartLabel);
|
||||||
|
|
||||||
|
initializeDestructuringDeclarationVariables(
|
||||||
|
destructuringDeclaration,
|
||||||
|
new TransientReceiver(elementType),
|
||||||
|
StackValue.local(loopParameterVar, asmElementType));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void assignToLoopParameter();
|
protected abstract void assignToLoopParameter();
|
||||||
|
|||||||
Reference in New Issue
Block a user