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