JS backend: Migrate FunctionIntrinsic to CallInfo
This commit is contained in:
+12
-3
@@ -20,7 +20,7 @@ import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.reference.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.reference.CallInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,11 +45,20 @@ public abstract class FunctionIntrinsic {
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
protected static JsExpression getThisOrReceiverOrNull(@NotNull CallInfo callInfo) {
|
||||
if (callInfo.getThisObject() != null) {
|
||||
return callInfo.getThisObject();
|
||||
} else {
|
||||
return callInfo.getReceiverObject();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsExpression apply(@NotNull CallTranslator callTranslator,
|
||||
public JsExpression apply(@NotNull CallInfo callInfo,
|
||||
@NotNull List<JsExpression> arguments,
|
||||
@NotNull TranslationContext context) {
|
||||
return apply(callTranslator.getCallParameters().getThisOrReceiverOrNull(), arguments, context);
|
||||
return apply(getThisOrReceiverOrNull(callInfo), arguments, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+7
-7
@@ -34,7 +34,7 @@ import org.jetbrains.k2js.translate.context.Namer;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
||||
import org.jetbrains.k2js.translate.intrinsic.functions.patterns.NamePredicate;
|
||||
import org.jetbrains.k2js.translate.reference.CallTranslator;
|
||||
import org.jetbrains.k2js.translate.reference.CallInfo;
|
||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||
@@ -172,9 +172,9 @@ public final class TopLevelFIF extends CompositeFIF {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression apply(@NotNull CallTranslator callTranslator, @NotNull List<JsExpression> arguments, @NotNull TranslationContext context) {
|
||||
ExpressionReceiver expressionReceiver = getExpressionReceiver(callTranslator.getResolvedCall());
|
||||
JsExpression thisOrReceiver = callTranslator.getCallParameters().getThisOrReceiverOrNull();
|
||||
public JsExpression apply(@NotNull CallInfo callInfo, @NotNull List<JsExpression> arguments, @NotNull TranslationContext context) {
|
||||
ExpressionReceiver expressionReceiver = getExpressionReceiver(callInfo.getResolvedCall());
|
||||
JsExpression thisOrReceiver = getThisOrReceiverOrNull(callInfo);
|
||||
assert thisOrReceiver != null;
|
||||
if (expressionReceiver != null) {
|
||||
JetExpression expression = expressionReceiver.getExpression();
|
||||
@@ -212,11 +212,11 @@ public final class TopLevelFIF extends CompositeFIF {
|
||||
@NotNull
|
||||
@Override
|
||||
public JsExpression apply(
|
||||
@NotNull CallTranslator callTranslator,
|
||||
@NotNull CallInfo callInfo,
|
||||
@NotNull List<JsExpression> arguments,
|
||||
@NotNull TranslationContext context
|
||||
) {
|
||||
JetType keyType = callTranslator.getResolvedCall().getTypeArguments().values().iterator().next();
|
||||
JetType keyType = callInfo.getResolvedCall().getTypeArguments().values().iterator().next();
|
||||
Name keyTypeName = JsDescriptorUtils.getNameIfStandardType(keyType);
|
||||
String collectionClassName;
|
||||
if (keyTypeName != null &&
|
||||
@@ -229,7 +229,7 @@ public final class TopLevelFIF extends CompositeFIF {
|
||||
collectionClassName = isSet ? "ComplexHashSet" : "ComplexHashMap";
|
||||
}
|
||||
|
||||
return callTranslator.createConstructorCallExpression(context.namer().kotlin(collectionClassName));
|
||||
return new JsNew(context.namer().kotlin(collectionClassName), arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,17 +115,17 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
|
||||
@Nullable
|
||||
public JsExpression intrinsicInvocation() {
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
try {
|
||||
FunctionIntrinsic intrinsic = context().intrinsics().getFunctionIntrinsics().getIntrinsic((FunctionDescriptor) descriptor);
|
||||
if (intrinsic.exists()) {
|
||||
return intrinsic.apply(this, arguments, context());
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
throw ErrorReportingUtils.reportErrorWithLocation(e, descriptor, bindingContext());
|
||||
}
|
||||
}
|
||||
//if (descriptor instanceof FunctionDescriptor) {
|
||||
// try {
|
||||
// FunctionIntrinsic intrinsic = context().intrinsics().getFunctionIntrinsics().getIntrinsic((FunctionDescriptor) descriptor);
|
||||
// if (intrinsic.exists()) {
|
||||
// return intrinsic.apply(this, arguments, context());
|
||||
// }
|
||||
// }
|
||||
// catch (RuntimeException e) {
|
||||
// throw ErrorReportingUtils.reportErrorWithLocation(e, descriptor, bindingContext());
|
||||
// }
|
||||
//}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.*
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||
import org.jetbrains.k2js.translate.context.Namer
|
||||
import org.jetbrains.k2js.translate.utils.ErrorReportingUtils
|
||||
|
||||
|
||||
val functionCallCases: CallCaseDispatcher<FunctionCallCase, FunctionCallInfo> = createFunctionCases()
|
||||
@@ -179,9 +180,16 @@ trait DelegateIntrinsic<I : CallInfo> : CallCase<I> {
|
||||
fun I.getArgs(): List<JsExpression>
|
||||
|
||||
fun I.intrinsic(): JsExpression? {
|
||||
val callType = if (resolvedCall.isSafeCall()) CallType.SAFE else CallType.NORMAL
|
||||
val translator = CallTranslator(getReceiver(), null, getArgs(), resolvedCall, getDescriptor(), callType, context)
|
||||
return translator.intrinsicInvocation()
|
||||
val descriptor = getDescriptor();
|
||||
|
||||
// Now intrinsic support only FunctionDescriptor. See DelegatePropertyAccessIntrinsic.getDescriptor()
|
||||
if (descriptor is FunctionDescriptor) {
|
||||
val intrinsic = context.intrinsics().getFunctionIntrinsics().getIntrinsic(descriptor)
|
||||
if (intrinsic.exists()) {
|
||||
return intrinsic.apply(this, getArgs(), context)
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun intrinsic(): JsExpression? {
|
||||
|
||||
Reference in New Issue
Block a user