JS backend: Use newCallTranslator for several Translators
This commit is contained in:
+2
-5
@@ -31,7 +31,7 @@ import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -78,10 +78,7 @@ public class MultiDeclarationTranslator extends AbstractTranslator {
|
||||
for (JetMultiDeclarationEntry entry : multiDeclaration.getEntries()) {
|
||||
ResolvedCall<FunctionDescriptor> entryInitCall = context().bindingContext().get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
assert entryInitCall != null : "Entry init call must be not null";
|
||||
JsExpression entryInitializer = CallBuilder.build(context())
|
||||
.receiver(multiObjNameRef)
|
||||
.resolvedCall(entryInitCall)
|
||||
.translate();
|
||||
JsExpression entryInitializer = ReferencePackage.buildCall(context(), entryInitCall, multiObjNameRef);
|
||||
|
||||
VariableDescriptor descriptor = BindingContextUtils.getNotNull( context().bindingContext(), BindingContext.VARIABLE, entry);
|
||||
JsName name = context().getNameForDescriptor(descriptor);
|
||||
|
||||
+2
-5
@@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.psi.JetForExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getLoopRange;
|
||||
@@ -73,9 +73,6 @@ public final class IteratorForTranslator extends ForTranslator {
|
||||
@NotNull
|
||||
private JsExpression translateMethodInvocation(@Nullable JsExpression receiver,
|
||||
@NotNull ResolvedCall<FunctionDescriptor> resolvedCall) {
|
||||
return CallBuilder.build(context())
|
||||
.resolvedCall(resolvedCall)
|
||||
.receiver(receiver)
|
||||
.translate();
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, receiver);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-16
@@ -30,14 +30,13 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.general.AbstractTranslator;
|
||||
import org.jetbrains.k2js.translate.intrinsic.operation.BinaryOperationIntrinsic;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.CallType;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.operation.AssignmentTranslator.isAssignmentOperator;
|
||||
import static org.jetbrains.k2js.translate.operation.CompareToTranslator.isCompareToCall;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionDescriptorForOperationExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCall;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionResolvedCall;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.not;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.translateLeftExpression;
|
||||
@@ -128,24 +127,17 @@ public final class BinaryOperationTranslator extends AbstractTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression translateAsOverloadedBinaryOperation() {
|
||||
CallBuilder callBuilder = setReceiverAndArguments();
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(bindingContext(), expression.getOperationReference());
|
||||
JsExpression result = callBuilder.resolvedCall(resolvedCall).type(CallType.NORMAL).translate();
|
||||
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCall(bindingContext(), expression.getOperationReference());
|
||||
JsExpression result = ReferencePackage.buildCall(context(), resolvedCall, getReceiver());
|
||||
return mayBeWrapWithNegation(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private CallBuilder setReceiverAndArguments() {
|
||||
CallBuilder callBuilder = CallBuilder.build(context());
|
||||
|
||||
JsExpression leftExpression = translateLeftExpression(context(), expression);
|
||||
JsExpression rightExpression = translateRightExpression(context(), expression);
|
||||
|
||||
private JsExpression getReceiver() {
|
||||
if (isInOrNotInOperation(expression)) {
|
||||
return callBuilder.receiver(rightExpression).args(leftExpression);
|
||||
}
|
||||
else {
|
||||
return callBuilder.receiver(leftExpression).args(rightExpression);
|
||||
return translateRightExpression(context(), expression);
|
||||
} else {
|
||||
return translateLeftExpression(context(), expression);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-11
@@ -20,8 +20,9 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
|
||||
public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
@@ -33,15 +34,12 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final FunctionDescriptor operationDescriptor;
|
||||
private final ResolvedCall<? extends FunctionDescriptor> resolvedCall;
|
||||
|
||||
private OverloadedAssignmentTranslator(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(expression, context);
|
||||
FunctionDescriptor functionDescriptor =
|
||||
BindingUtils.getFunctionDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
assert functionDescriptor != null : "";
|
||||
this.operationDescriptor = functionDescriptor;
|
||||
resolvedCall = BindingUtils.getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -59,10 +57,6 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
private JsExpression overloadedMethodInvocation() {
|
||||
return CallBuilder.build(context())
|
||||
.descriptor(operationDescriptor)
|
||||
.receiver(accessTranslator.translateAsGet())
|
||||
.args(right)
|
||||
.translate();
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, accessTranslator.translateAsGet());
|
||||
}
|
||||
}
|
||||
|
||||
+6
-11
@@ -20,32 +20,27 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionDescriptorForOperationExpression;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
|
||||
public final class OverloadedIncrementTranslator extends IncrementTranslator {
|
||||
|
||||
@NotNull
|
||||
private final FunctionDescriptor operationDescriptor;
|
||||
private final ResolvedCall<? extends FunctionDescriptor> resolvedCall;
|
||||
|
||||
/*package*/ OverloadedIncrementTranslator(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
super(expression, context);
|
||||
FunctionDescriptor functionDescriptor = getFunctionDescriptorForOperationExpression(context.bindingContext(), expression);
|
||||
assert functionDescriptor != null : "Descriptor should not be null for overloaded increment expression.";
|
||||
this.operationDescriptor = functionDescriptor;
|
||||
this.resolvedCall = BindingUtils.getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected JsExpression operationExpression(@NotNull JsExpression receiver) {
|
||||
return CallBuilder.build(context())
|
||||
.receiver(receiver)
|
||||
.descriptor(operationDescriptor)
|
||||
.translate();
|
||||
return ReferencePackage.buildCall(context(), resolvedCall, receiver);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-9
@@ -20,19 +20,19 @@ import com.google.dart.compiler.backend.js.ast.JsBinaryOperation;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetUnaryExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallBuilder;
|
||||
import org.jetbrains.k2js.translate.reference.ReferencePackage;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.general.Translation.translateAsExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCall;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionResolvedCall;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getBaseExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getOperationToken;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.isEqualLikeOperator;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.sure;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.translateExclForBinaryEqualLikeExpr;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.*;
|
||||
|
||||
public final class UnaryOperationTranslator {
|
||||
private UnaryOperationTranslator() {
|
||||
@@ -56,10 +56,8 @@ public final class UnaryOperationTranslator {
|
||||
return translateExclForBinaryEqualLikeExpr((JsBinaryOperation) baseExpression);
|
||||
}
|
||||
|
||||
return CallBuilder.build(context)
|
||||
.receiver(TranslationUtils.translateBaseExpression(context, expression))
|
||||
.resolvedCall(getResolvedCall(context.bindingContext(), expression.getOperationReference()))
|
||||
.translate();
|
||||
ResolvedCall<? extends FunctionDescriptor> resolvedCall = getFunctionResolvedCall(context.bindingContext(), expression.getOperationReference());
|
||||
return ReferencePackage.buildCall(context, resolvedCall, baseExpression);
|
||||
}
|
||||
|
||||
private static boolean isExclForBinaryEqualLikeExpr(@NotNull JetUnaryExpression expression, @NotNull JsExpression baseExpression) {
|
||||
|
||||
@@ -159,7 +159,13 @@ public final class BindingUtils {
|
||||
public static ResolvedCall<? extends FunctionDescriptor> getResolvedCallForCallExpression(@NotNull BindingContext context,
|
||||
@NotNull JetCallExpression expression) {
|
||||
JetExpression calleeExpression = PsiUtils.getCallee(expression);
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(context, calleeExpression);
|
||||
return getFunctionResolvedCall(context, calleeExpression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolvedCall<? extends FunctionDescriptor> getFunctionResolvedCall(@NotNull BindingContext context,
|
||||
@NotNull JetExpression expression) {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(context, expression);
|
||||
assert resolvedCall.getResultingDescriptor() instanceof FunctionDescriptor
|
||||
: message(expression, "ResolvedCall for this expression must be ResolvedCall<? extends FunctionDescriptor>");
|
||||
return (ResolvedCall<? extends FunctionDescriptor>) resolvedCall;
|
||||
|
||||
Reference in New Issue
Block a user