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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
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;
|
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
|
@NotNull
|
||||||
public JsExpression apply(@NotNull CallTranslator callTranslator,
|
public JsExpression apply(@NotNull CallInfo callInfo,
|
||||||
@NotNull List<JsExpression> arguments,
|
@NotNull List<JsExpression> arguments,
|
||||||
@NotNull TranslationContext context) {
|
@NotNull TranslationContext context) {
|
||||||
return apply(callTranslator.getCallParameters().getThisOrReceiverOrNull(), arguments, context);
|
return apply(getThisOrReceiverOrNull(callInfo), arguments, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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.context.TranslationContext;
|
||||||
import org.jetbrains.k2js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
import org.jetbrains.k2js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
||||||
import org.jetbrains.k2js.translate.intrinsic.functions.patterns.NamePredicate;
|
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.AnnotationsUtils;
|
||||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||||
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
import org.jetbrains.k2js.translate.utils.JsDescriptorUtils;
|
||||||
@@ -172,9 +172,9 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JsExpression apply(@NotNull CallTranslator callTranslator, @NotNull List<JsExpression> arguments, @NotNull TranslationContext context) {
|
public JsExpression apply(@NotNull CallInfo callInfo, @NotNull List<JsExpression> arguments, @NotNull TranslationContext context) {
|
||||||
ExpressionReceiver expressionReceiver = getExpressionReceiver(callTranslator.getResolvedCall());
|
ExpressionReceiver expressionReceiver = getExpressionReceiver(callInfo.getResolvedCall());
|
||||||
JsExpression thisOrReceiver = callTranslator.getCallParameters().getThisOrReceiverOrNull();
|
JsExpression thisOrReceiver = getThisOrReceiverOrNull(callInfo);
|
||||||
assert thisOrReceiver != null;
|
assert thisOrReceiver != null;
|
||||||
if (expressionReceiver != null) {
|
if (expressionReceiver != null) {
|
||||||
JetExpression expression = expressionReceiver.getExpression();
|
JetExpression expression = expressionReceiver.getExpression();
|
||||||
@@ -212,11 +212,11 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JsExpression apply(
|
public JsExpression apply(
|
||||||
@NotNull CallTranslator callTranslator,
|
@NotNull CallInfo callInfo,
|
||||||
@NotNull List<JsExpression> arguments,
|
@NotNull List<JsExpression> arguments,
|
||||||
@NotNull TranslationContext context
|
@NotNull TranslationContext context
|
||||||
) {
|
) {
|
||||||
JetType keyType = callTranslator.getResolvedCall().getTypeArguments().values().iterator().next();
|
JetType keyType = callInfo.getResolvedCall().getTypeArguments().values().iterator().next();
|
||||||
Name keyTypeName = JsDescriptorUtils.getNameIfStandardType(keyType);
|
Name keyTypeName = JsDescriptorUtils.getNameIfStandardType(keyType);
|
||||||
String collectionClassName;
|
String collectionClassName;
|
||||||
if (keyTypeName != null &&
|
if (keyTypeName != null &&
|
||||||
@@ -229,7 +229,7 @@ public final class TopLevelFIF extends CompositeFIF {
|
|||||||
collectionClassName = isSet ? "ComplexHashSet" : "ComplexHashMap";
|
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
|
@Nullable
|
||||||
public JsExpression intrinsicInvocation() {
|
public JsExpression intrinsicInvocation() {
|
||||||
if (descriptor instanceof FunctionDescriptor) {
|
//if (descriptor instanceof FunctionDescriptor) {
|
||||||
try {
|
// try {
|
||||||
FunctionIntrinsic intrinsic = context().intrinsics().getFunctionIntrinsics().getIntrinsic((FunctionDescriptor) descriptor);
|
// FunctionIntrinsic intrinsic = context().intrinsics().getFunctionIntrinsics().getIntrinsic((FunctionDescriptor) descriptor);
|
||||||
if (intrinsic.exists()) {
|
// if (intrinsic.exists()) {
|
||||||
return intrinsic.apply(this, arguments, context());
|
// return intrinsic.apply(this, arguments, context());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
catch (RuntimeException e) {
|
// catch (RuntimeException e) {
|
||||||
throw ErrorReportingUtils.reportErrorWithLocation(e, descriptor, bindingContext());
|
// throw ErrorReportingUtils.reportErrorWithLocation(e, descriptor, bindingContext());
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
return null;
|
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 com.google.dart.compiler.backend.js.ast.JsNameRef
|
||||||
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
import org.jetbrains.k2js.translate.utils.JsAstUtils
|
||||||
import org.jetbrains.k2js.translate.context.Namer
|
import org.jetbrains.k2js.translate.context.Namer
|
||||||
|
import org.jetbrains.k2js.translate.utils.ErrorReportingUtils
|
||||||
|
|
||||||
|
|
||||||
val functionCallCases: CallCaseDispatcher<FunctionCallCase, FunctionCallInfo> = createFunctionCases()
|
val functionCallCases: CallCaseDispatcher<FunctionCallCase, FunctionCallInfo> = createFunctionCases()
|
||||||
@@ -179,9 +180,16 @@ trait DelegateIntrinsic<I : CallInfo> : CallCase<I> {
|
|||||||
fun I.getArgs(): List<JsExpression>
|
fun I.getArgs(): List<JsExpression>
|
||||||
|
|
||||||
fun I.intrinsic(): JsExpression? {
|
fun I.intrinsic(): JsExpression? {
|
||||||
val callType = if (resolvedCall.isSafeCall()) CallType.SAFE else CallType.NORMAL
|
val descriptor = getDescriptor();
|
||||||
val translator = CallTranslator(getReceiver(), null, getArgs(), resolvedCall, getDescriptor(), callType, context)
|
|
||||||
return translator.intrinsicInvocation()
|
// 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? {
|
fun intrinsic(): JsExpression? {
|
||||||
|
|||||||
Reference in New Issue
Block a user