Use java.util.function.Predicate instead of Guava in JS modules
This commit is contained in:
@@ -16,11 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.patterns;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface DescriptorPredicate extends Predicate<FunctionDescriptor> {
|
||||
@Override
|
||||
boolean apply(@Nullable FunctionDescriptor descriptor);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.patterns;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
@@ -30,6 +28,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class NamePredicate implements Predicate<Name> {
|
||||
|
||||
@@ -75,7 +74,7 @@ public final class NamePredicate implements Predicate<Name> {
|
||||
this(Arrays.asList(validNames));
|
||||
}
|
||||
|
||||
public NamePredicate(@NotNull List<String> validNames) {
|
||||
private NamePredicate(@NotNull List<String> validNames) {
|
||||
for (String validName : validNames) {
|
||||
this.validNames.add(Name.guessByFirstCharacter(validName));
|
||||
}
|
||||
@@ -90,7 +89,7 @@ public final class NamePredicate implements Predicate<Name> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(@Nullable Name name) {
|
||||
return name != null && validNames.contains(name);
|
||||
public boolean test(Name name) {
|
||||
return validNames.contains(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public final class PatternBuilder {
|
||||
private static DescriptorPredicate pattern(@NotNull List<NamePredicate> checkers, @Nullable List<NamePredicate> arguments) {
|
||||
assert !checkers.isEmpty();
|
||||
final List<NamePredicate> checkersWithPrefixChecker = Lists.newArrayList();
|
||||
if (!checkers.get(0).apply(KOTLIN_NAME)) {
|
||||
if (!checkers.get(0).test(KOTLIN_NAME)) {
|
||||
checkersWithPrefixChecker.add(KOTLIN_NAME_PREDICATE);
|
||||
}
|
||||
|
||||
@@ -134,8 +134,7 @@ public final class PatternBuilder {
|
||||
|
||||
return new DescriptorPredicate() {
|
||||
@Override
|
||||
public boolean apply(@Nullable FunctionDescriptor descriptor) {
|
||||
assert descriptor != null : "argument for DescriptorPredicate.apply should not be null, checkers=" + checkersWithPrefixChecker;
|
||||
public boolean test(FunctionDescriptor descriptor) {
|
||||
//TODO: no need to wrap if we check beforehand
|
||||
try {
|
||||
return doApply(descriptor);
|
||||
@@ -162,7 +161,7 @@ public final class PatternBuilder {
|
||||
ValueParameterDescriptor valueParameterDescriptor = valueParameterDescriptors.get(i);
|
||||
Name name = DescriptorUtilsKt.getNameIfStandardType(valueParameterDescriptor.getType());
|
||||
NamePredicate namePredicate = argumentCheckers.get(i);
|
||||
if (!namePredicate.apply(name)) return false;
|
||||
if (!namePredicate.test(name)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -172,7 +171,7 @@ public final class PatternBuilder {
|
||||
for (int i = 0; i < nameParts.size(); ++i) {
|
||||
Name namePart = nameParts.get(i);
|
||||
NamePredicate correspondingPredicate = checkersWithPrefixChecker.get(i);
|
||||
if (!correspondingPredicate.apply(namePart)) {
|
||||
if (!correspondingPredicate.test(namePart)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -233,9 +232,7 @@ public final class PatternBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(@Nullable FunctionDescriptor functionDescriptor) {
|
||||
assert functionDescriptor != null :
|
||||
"argument for DescriptorPredicate.apply should not be null, receiverFqName=" + receiverFqName + " names=" + Arrays.asList(names);
|
||||
public boolean test(FunctionDescriptor functionDescriptor) {
|
||||
ReceiverParameterDescriptor actualReceiver = functionDescriptor.getExtensionReceiverParameter();
|
||||
if (actualReceiver != null) {
|
||||
if (receiverFqName == null) return false;
|
||||
|
||||
+4
-6
@@ -16,13 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.patterns.typePredicates
|
||||
|
||||
import com.google.common.base.Predicate
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import java.util.function.Predicate
|
||||
|
||||
public interface TypePredicate : Predicate<KotlinType> {
|
||||
override fun apply(type: KotlinType?): Boolean
|
||||
}
|
||||
interface TypePredicate : Predicate<KotlinType>
|
||||
|
||||
private val KOTLIN = TypePredicateImpl("kotlin")
|
||||
val COMPARABLE: TypePredicate = KOTLIN.inner("Comparable")
|
||||
@@ -40,8 +38,8 @@ private class TypePredicateImpl
|
||||
: TypePredicate {
|
||||
constructor(name: String) : this(listOf(name))
|
||||
|
||||
override fun apply(type: KotlinType?): Boolean {
|
||||
var descriptor: DeclarationDescriptor? = type?.constructor?.declarationDescriptor ?: return false
|
||||
override fun test(type: KotlinType): Boolean {
|
||||
var descriptor: DeclarationDescriptor? = type.constructor.declarationDescriptor ?: return false
|
||||
|
||||
for (i in nameParts.lastIndex downTo 0) {
|
||||
if (nameParts[i] != descriptor?.name?.asString()) return false
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsFunctionScope
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsProgram
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsRootScope
|
||||
import com.google.gwt.dev.js.parserExceptions.AbortParsingException
|
||||
import com.google.gwt.dev.js.rhino.CodePosition
|
||||
import com.google.gwt.dev.js.rhino.ErrorReporter
|
||||
@@ -29,6 +26,9 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsFunctionScope
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsProgram
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsRootScope
|
||||
import org.jetbrains.kotlin.js.parser.parse
|
||||
import org.jetbrains.kotlin.js.patterns.DescriptorPredicate
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder
|
||||
@@ -57,7 +57,7 @@ class JsCallChecker(
|
||||
|
||||
@JvmStatic fun <F : CallableDescriptor?> ResolvedCall<F>.isJsCall(): Boolean {
|
||||
val descriptor = resultingDescriptor
|
||||
return descriptor is SimpleFunctionDescriptor && JS_PATTERN.apply(descriptor)
|
||||
return descriptor is SimpleFunctionDescriptor && JS_PATTERN.test(descriptor)
|
||||
}
|
||||
|
||||
@JvmStatic fun extractStringValue(compileTimeConstant: CompileTimeConstant<*>?): String? {
|
||||
|
||||
+8
-9
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.js.backend.ast.JsConditional;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsInvocation;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsLiteral;
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys;
|
||||
import org.jetbrains.kotlin.js.patterns.NamePredicate;
|
||||
import org.jetbrains.kotlin.js.patterns.typePredicates.TypePredicatesKt;
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer;
|
||||
@@ -222,9 +221,9 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
|
||||
}
|
||||
|
||||
if (TypePredicatesKt.getCHAR_SEQUENCE().apply(type)) return namer().isCharSequence();
|
||||
if (TypePredicatesKt.getCHAR_SEQUENCE().test(type)) return namer().isCharSequence();
|
||||
|
||||
if (TypePredicatesKt.getCOMPARABLE().apply(type)) return namer().isComparable();
|
||||
if (TypePredicatesKt.getCOMPARABLE().test(type)) return namer().isComparable();
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -233,27 +232,27 @@ public final class PatternTranslator extends AbstractTranslator {
|
||||
private JsExpression getIsTypeCheckCallableForPrimitiveBuiltin(@NotNull KotlinType type) {
|
||||
Name typeName = getNameIfStandardType(type);
|
||||
|
||||
if (NamePredicate.STRING.apply(typeName)) {
|
||||
if (NamePredicate.STRING.test(typeName)) {
|
||||
return namer().isTypeOf(program().getStringLiteral("string"));
|
||||
}
|
||||
|
||||
if (NamePredicate.BOOLEAN.apply(typeName)) {
|
||||
if (NamePredicate.BOOLEAN.test(typeName)) {
|
||||
return namer().isTypeOf(program().getStringLiteral("boolean"));
|
||||
}
|
||||
|
||||
if (NamePredicate.LONG.apply(typeName)) {
|
||||
if (NamePredicate.LONG.test(typeName)) {
|
||||
return namer().isInstanceOf(Namer.kotlinLong());
|
||||
}
|
||||
|
||||
if (NamePredicate.NUMBER.apply(typeName)) {
|
||||
if (NamePredicate.NUMBER.test(typeName)) {
|
||||
return namer().kotlin(Namer.IS_NUMBER);
|
||||
}
|
||||
|
||||
if (NamePredicate.CHAR.apply(typeName)) {
|
||||
if (NamePredicate.CHAR.test(typeName)) {
|
||||
return namer().kotlin(Namer.IS_CHAR);
|
||||
}
|
||||
|
||||
if (NamePredicate.PRIMITIVE_NUMBERS_MAPPED_TO_PRIMITIVE_JS.apply(typeName)) {
|
||||
if (NamePredicate.PRIMITIVE_NUMBERS_MAPPED_TO_PRIMITIVE_JS.test(typeName)) {
|
||||
return namer().isTypeOf(program().getStringLiteral("number"));
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -110,10 +110,10 @@ public final class StringTemplateTranslator extends AbstractTranslator {
|
||||
Name typeName = DescriptorUtilsKt.getNameIfStandardType(type);
|
||||
if (typeName != null) {
|
||||
//TODO: this is a hacky optimization, should use some generic approach
|
||||
if (NamePredicate.STRING.apply(typeName)) {
|
||||
if (NamePredicate.STRING.test(typeName)) {
|
||||
return false;
|
||||
}
|
||||
else if (NamePredicate.PRIMITIVE_NUMBERS.apply(typeName)) {
|
||||
else if (NamePredicate.PRIMITIVE_NUMBERS.test(typeName)) {
|
||||
return resultingExpression == null;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.functions.factories;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -25,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntrinsic;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class CompositeFIF implements FunctionIntrinsicFactory {
|
||||
@NotNull
|
||||
@@ -37,7 +37,7 @@ public abstract class CompositeFIF implements FunctionIntrinsicFactory {
|
||||
@Override
|
||||
public FunctionIntrinsic getIntrinsic(@NotNull FunctionDescriptor descriptor) {
|
||||
for (Pair<Predicate<FunctionDescriptor>, FunctionIntrinsic> entry : patternsAndIntrinsics) {
|
||||
if (entry.first.apply(descriptor)) {
|
||||
if (entry.first.test(descriptor)) {
|
||||
return entry.second;
|
||||
}
|
||||
}
|
||||
@@ -47,4 +47,4 @@ public abstract class CompositeFIF implements FunctionIntrinsicFactory {
|
||||
protected void add(@NotNull Predicate<FunctionDescriptor> pattern, @NotNull FunctionIntrinsic intrinsic) {
|
||||
patternsAndIntrinsics.add(Pair.create(pattern, intrinsic));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.functions.factories
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
@@ -86,15 +86,15 @@ object LongOperationFIF : FunctionIntrinsicFactory {
|
||||
override fun getIntrinsic(descriptor: FunctionDescriptor): FunctionIntrinsic? {
|
||||
val operationName = descriptor.name.asString()
|
||||
return when {
|
||||
LONG_EQUALS_ANY.apply(descriptor) || LONG_BINARY_OPERATION_LONG.apply(descriptor) || LONG_BIT_SHIFTS.apply(descriptor) ->
|
||||
LONG_EQUALS_ANY.test(descriptor) || LONG_BINARY_OPERATION_LONG.test(descriptor) || LONG_BIT_SHIFTS.test(descriptor) ->
|
||||
longBinaryIntrinsics[operationName]
|
||||
INTEGER_BINARY_OPERATION_LONG.apply(descriptor) ->
|
||||
INTEGER_BINARY_OPERATION_LONG.test(descriptor) ->
|
||||
wrapIntrinsicIfPresent(longBinaryIntrinsics[operationName], ::longFromInt, ID())
|
||||
LONG_BINARY_OPERATION_INTEGER.apply(descriptor) ->
|
||||
LONG_BINARY_OPERATION_INTEGER.test(descriptor) ->
|
||||
wrapIntrinsicIfPresent(longBinaryIntrinsics[operationName], ID(), ::longFromInt)
|
||||
FLOATING_POINT_BINARY_OPERATION_LONG.apply(descriptor) ->
|
||||
FLOATING_POINT_BINARY_OPERATION_LONG.test(descriptor) ->
|
||||
wrapIntrinsicIfPresent(floatBinaryIntrinsics[operationName], ID(), { invokeMethod(it, Namer.LONG_TO_NUMBER) })
|
||||
LONG_BINARY_OPERATION_FLOATING_POINT.apply(descriptor) ->
|
||||
LONG_BINARY_OPERATION_FLOATING_POINT.test(descriptor) ->
|
||||
wrapIntrinsicIfPresent(floatBinaryIntrinsics[operationName], { invokeMethod(it, Namer.LONG_TO_NUMBER) }, ID())
|
||||
else ->
|
||||
null
|
||||
|
||||
+10
-8
@@ -16,22 +16,24 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.functions.factories
|
||||
|
||||
import com.google.common.base.Predicates
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.intrinsic.functions.basic.FunctionIntrinsicWithReceiverComputed
|
||||
import org.jetbrains.kotlin.js.translate.utils.JsAstUtils.*
|
||||
import org.jetbrains.kotlin.utils.identity
|
||||
import java.util.function.Predicate
|
||||
|
||||
object NumberAndCharConversionFIF : CompositeFIF() {
|
||||
val USE_AS_IS = Predicates.or(
|
||||
pattern("Int.toInt|toFloat|toDouble"), pattern("Short.toShort|toInt|toFloat|toDouble"),
|
||||
pattern("Byte.toByte|toShort|toInt|toFloat|toDouble"), pattern("Float|Double.toFloat|toDouble"),
|
||||
pattern("Long.toLong"), pattern("Char.toChar")
|
||||
)
|
||||
val USE_AS_IS: Predicate<FunctionDescriptor> = pattern("Int.toInt|toFloat|toDouble")
|
||||
.or(pattern("Short.toShort|toInt|toFloat|toDouble"))
|
||||
.or(pattern("Byte.toByte|toShort|toInt|toFloat|toDouble"))
|
||||
.or(pattern("Float|Double.toFloat|toDouble"))
|
||||
.or(pattern("Long.toLong"))
|
||||
.or(pattern("Char.toChar"))
|
||||
|
||||
private val convertOperations: Map<String, ConversionUnaryIntrinsic> =
|
||||
private val convertOperations: Map<String, ConversionUnaryIntrinsic> =
|
||||
mapOf(
|
||||
"Float|Double.toInt" to ConversionUnaryIntrinsic(::toInt32),
|
||||
"Int|Float|Double.toShort" to ConversionUnaryIntrinsic(::toShort),
|
||||
@@ -71,7 +73,7 @@ object NumberAndCharConversionFIF : CompositeFIF() {
|
||||
}
|
||||
|
||||
init {
|
||||
add(USE_AS_IS!!, ConversionUnaryIntrinsic(identity()))
|
||||
add(USE_AS_IS, ConversionUnaryIntrinsic(identity()))
|
||||
for((stringPattern, intrinsic) in convertOperations) {
|
||||
add(pattern(stringPattern), intrinsic)
|
||||
}
|
||||
|
||||
+16
-20
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.functions.factories;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -40,6 +38,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern;
|
||||
|
||||
@@ -112,10 +111,8 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
|
||||
private static final DescriptorPredicate PRIMITIVE_NUMBERS_COMPARE_TO_OPERATIONS =
|
||||
pattern(NamePredicate.PRIMITIVE_NUMBERS_MAPPED_TO_PRIMITIVE_JS, "compareTo");
|
||||
private static final Predicate<FunctionDescriptor> INT_WITH_BIT_OPERATIONS = Predicates.or(
|
||||
pattern("Int.or|and|xor|shl|shr|ushr"),
|
||||
pattern("Short|Byte.or|and|xor")
|
||||
);
|
||||
private static final Predicate<FunctionDescriptor> INT_WITH_BIT_OPERATIONS = pattern("Int.or|and|xor|shl|shr|ushr")
|
||||
.or(pattern("Short|Byte.or|and|xor"));
|
||||
private static final DescriptorPredicate BOOLEAN_OPERATIONS = pattern("Boolean.or|and|xor");
|
||||
private static final DescriptorPredicate STRING_PLUS = pattern("String.plus");
|
||||
private static final DescriptorPredicate INT_MULTIPLICATION = pattern("Int.times(Int)");
|
||||
@@ -132,18 +129,17 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
.put("ushr", JsBinaryOperator.SHRU)
|
||||
.build();
|
||||
|
||||
private static final Predicate<FunctionDescriptor> PREDICATE = Predicates.or(PRIMITIVE_NUMBERS_BINARY_OPERATIONS, BOOLEAN_OPERATIONS,
|
||||
STRING_PLUS, INT_WITH_BIT_OPERATIONS,
|
||||
PRIMITIVE_NUMBERS_COMPARE_TO_OPERATIONS);
|
||||
private static final Predicate<FunctionDescriptor> PREDICATE = PRIMITIVE_NUMBERS_BINARY_OPERATIONS
|
||||
.or(BOOLEAN_OPERATIONS).or(STRING_PLUS).or(INT_WITH_BIT_OPERATIONS).or(PRIMITIVE_NUMBERS_COMPARE_TO_OPERATIONS);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public FunctionIntrinsic getIntrinsic(@NotNull FunctionDescriptor descriptor) {
|
||||
if (CHAR_RANGE_TO.apply(descriptor)) {
|
||||
if (CHAR_RANGE_TO.test(descriptor)) {
|
||||
return new RangeToIntrinsic(descriptor);
|
||||
}
|
||||
|
||||
if (PRIMITIVE_NUMBERS_COMPARE_TO_OPERATIONS.apply(descriptor)) {
|
||||
if (PRIMITIVE_NUMBERS_COMPARE_TO_OPERATIONS.test(descriptor)) {
|
||||
return PRIMITIVE_NUMBER_COMPARE_TO_INTRINSIC;
|
||||
}
|
||||
|
||||
@@ -152,38 +148,38 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
return BUILTINS_COMPARE_TO_INTRINSIC;
|
||||
}
|
||||
|
||||
if (!PREDICATE.apply(descriptor)) {
|
||||
if (!PREDICATE.test(descriptor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (INT_MULTIPLICATION.apply(descriptor)) {
|
||||
if (INT_MULTIPLICATION.test(descriptor)) {
|
||||
return INT_MULTIPLICATION_INTRINSIC;
|
||||
}
|
||||
if (NUMBER_RANGE_TO.apply(descriptor)) {
|
||||
if (NUMBER_RANGE_TO.test(descriptor)) {
|
||||
return new RangeToIntrinsic(descriptor);
|
||||
}
|
||||
if (INT_WITH_BIT_OPERATIONS.apply(descriptor)) {
|
||||
if (INT_WITH_BIT_OPERATIONS.test(descriptor)) {
|
||||
JsBinaryOperator op = BINARY_BITWISE_OPERATIONS.get(descriptor.getName().asString());
|
||||
if (op != null) {
|
||||
return new OptimizedIntBinaryOperationInstrinsic(op);
|
||||
}
|
||||
}
|
||||
JsBinaryOperator operator = getOperator(descriptor);
|
||||
if (INT_BINARY_OPERATIONS.apply(descriptor)) {
|
||||
if (INT_BINARY_OPERATIONS.test(descriptor)) {
|
||||
return new AdditiveIntBinaryOperationInstrinsic(operator);
|
||||
}
|
||||
if (SIMPLE_INT_MULTIPLICATION.apply(descriptor) || INT_DIVISION.apply(descriptor)) {
|
||||
if (SIMPLE_INT_MULTIPLICATION.test(descriptor) || INT_DIVISION.test(descriptor)) {
|
||||
return new IntBinaryOperationFunctionIntrinsic(operator);
|
||||
}
|
||||
BinaryOperationIntrinsicBase result = new PrimitiveBinaryOperationFunctionIntrinsic(operator);
|
||||
|
||||
if (pattern("Char.plus|minus(Int)").apply(descriptor)) {
|
||||
if (pattern("Char.plus|minus(Int)").test(descriptor)) {
|
||||
return new CharAndIntBinaryOperationFunctionIntrinsic(result);
|
||||
}
|
||||
if (pattern("Char.minus(Char)").apply(descriptor)) {
|
||||
if (pattern("Char.minus(Char)").test(descriptor)) {
|
||||
return new CharAndCharBinaryOperationFunctionIntrinsic(result);
|
||||
}
|
||||
if (pattern("String.plus(Any)").apply(descriptor)) {
|
||||
if (pattern("String.plus(Any)").test(descriptor)) {
|
||||
return new StringAndCharBinaryOperationFunctionIntrinsic(result);
|
||||
}
|
||||
return result;
|
||||
|
||||
+19
-21
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.functions.factories;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
@@ -36,6 +34,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern;
|
||||
|
||||
@@ -49,17 +48,16 @@ public enum PrimitiveUnaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
pattern(NamePredicate.PRIMITIVE_NUMBERS_MAPPED_TO_PRIMITIVE_JS, UNARY_OPERATIONS);
|
||||
@NotNull
|
||||
private static final Predicate<FunctionDescriptor> PRIMITIVE_UNARY_OPERATION_NAMES =
|
||||
Predicates.or(UNARY_OPERATION_FOR_PRIMITIVE_NUMBER, pattern("Boolean.not"), pattern("Int|Short|Byte.inv"));
|
||||
UNARY_OPERATION_FOR_PRIMITIVE_NUMBER.or(pattern("Boolean.not")).or(pattern("Int|Short|Byte.inv"));
|
||||
@NotNull
|
||||
private static final DescriptorPredicate NO_PARAMETERS = new DescriptorPredicate() {
|
||||
@Override
|
||||
public boolean apply(@Nullable FunctionDescriptor descriptor) {
|
||||
assert descriptor != null : "argument for DescriptorPredicate.apply should not be null";
|
||||
public boolean test(FunctionDescriptor descriptor) {
|
||||
return !JsDescriptorUtils.hasParameters(descriptor);
|
||||
}
|
||||
};
|
||||
@NotNull
|
||||
private static final Predicate<FunctionDescriptor> PATTERN = Predicates.and(PRIMITIVE_UNARY_OPERATION_NAMES, NO_PARAMETERS);
|
||||
private static final Predicate<FunctionDescriptor> PATTERN = PRIMITIVE_UNARY_OPERATION_NAMES.and(NO_PARAMETERS);
|
||||
|
||||
private static final DescriptorPredicate INC_OPERATION_FOR_INT = pattern("Int.inc");
|
||||
private static final DescriptorPredicate DEC_OPERATION_FOR_INT = pattern("Int.dec");
|
||||
@@ -222,52 +220,52 @@ public enum PrimitiveUnaryOperationFIF implements FunctionIntrinsicFactory {
|
||||
@Nullable
|
||||
@Override
|
||||
public FunctionIntrinsic getIntrinsic(@NotNull FunctionDescriptor descriptor) {
|
||||
if (!PATTERN.apply(descriptor)) {
|
||||
if (!PATTERN.test(descriptor)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (pattern("Char.unaryPlus()").apply(descriptor)) {
|
||||
if (pattern("Char.unaryPlus()").test(descriptor)) {
|
||||
return CHAR_PLUS;
|
||||
}
|
||||
if (pattern("Char.unaryMinus()").apply(descriptor)) {
|
||||
if (pattern("Char.unaryMinus()").test(descriptor)) {
|
||||
return CHAR_MINUS;
|
||||
}
|
||||
if (pattern("Char.plus()").apply(descriptor)) {
|
||||
if (pattern("Char.plus()").test(descriptor)) {
|
||||
return CHAR_PLUS;
|
||||
}
|
||||
if (pattern("Char.minus()").apply(descriptor)) {
|
||||
if (pattern("Char.minus()").test(descriptor)) {
|
||||
return CHAR_MINUS;
|
||||
}
|
||||
if (pattern("Char.inc()").apply(descriptor)) {
|
||||
if (pattern("Char.inc()").test(descriptor)) {
|
||||
return CHAR_INC;
|
||||
}
|
||||
if (pattern("Char.dec()").apply(descriptor)) {
|
||||
if (pattern("Char.dec()").test(descriptor)) {
|
||||
return CHAR_DEC;
|
||||
}
|
||||
|
||||
if (INC_OPERATION_FOR_INT.apply(descriptor)) {
|
||||
if (INC_OPERATION_FOR_INT.test(descriptor)) {
|
||||
return new IntOverflowIntrinsic(NUMBER_INC_INTRINSIC);
|
||||
}
|
||||
if (DEC_OPERATION_FOR_INT.apply(descriptor)) {
|
||||
if (DEC_OPERATION_FOR_INT.test(descriptor)) {
|
||||
return new IntOverflowIntrinsic(NUMBER_DEC_INTRINSIC);
|
||||
}
|
||||
if (INC_OPERATION_FOR_SHORT.apply(descriptor)) {
|
||||
if (INC_OPERATION_FOR_SHORT.test(descriptor)) {
|
||||
return new ShortOverflowIntrinsic(NUMBER_INC_INTRINSIC);
|
||||
}
|
||||
if (DEC_OPERATION_FOR_SHORT.apply(descriptor)) {
|
||||
if (DEC_OPERATION_FOR_SHORT.test(descriptor)) {
|
||||
return new ShortOverflowIntrinsic(NUMBER_DEC_INTRINSIC);
|
||||
}
|
||||
if (INC_OPERATION_FOR_BYTE.apply(descriptor)) {
|
||||
if (INC_OPERATION_FOR_BYTE.test(descriptor)) {
|
||||
return new ByteOverflowIntrinsic(NUMBER_INC_INTRINSIC);
|
||||
}
|
||||
if (DEC_OPERATION_FOR_BYTE.apply(descriptor)) {
|
||||
if (DEC_OPERATION_FOR_BYTE.test(descriptor)) {
|
||||
return new ByteOverflowIntrinsic(NUMBER_DEC_INTRINSIC);
|
||||
}
|
||||
|
||||
if (INC_OPERATION_FOR_PRIMITIVE_NUMBER.apply(descriptor)) {
|
||||
if (INC_OPERATION_FOR_PRIMITIVE_NUMBER.test(descriptor)) {
|
||||
return NUMBER_INC_INTRINSIC;
|
||||
}
|
||||
if (DEC_OPERATION_FOR_PRIMITIVE_NUMBER.apply(descriptor)) {
|
||||
if (DEC_OPERATION_FOR_PRIMITIVE_NUMBER.test(descriptor)) {
|
||||
return NUMBER_DEC_INTRINSIC;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.operation
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNumberLiteral
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
import org.jetbrains.kotlin.js.translate.operation.OperatorTable
|
||||
@@ -73,11 +73,11 @@ object CompareToBOIF : BinaryOperationIntrinsicFactory {
|
||||
if (!KotlinBuiltIns.isBuiltIn(descriptor)) return null
|
||||
|
||||
return when {
|
||||
COMPARE_TO_CHAR.apply(descriptor) ->
|
||||
COMPARE_TO_CHAR.test(descriptor) ->
|
||||
CompareToCharIntrinsic
|
||||
CHAR_COMPARE_TO.apply(descriptor) ->
|
||||
CHAR_COMPARE_TO.test(descriptor) ->
|
||||
CompareCharToPrimitiveIntrinsic
|
||||
PRIMITIVE_COMPARE_TO.apply(descriptor) ->
|
||||
PRIMITIVE_COMPARE_TO.test(descriptor) ->
|
||||
CompareToIntrinsic
|
||||
else ->
|
||||
CompareToFunctionIntrinsic
|
||||
|
||||
+1
-1
@@ -129,7 +129,7 @@ object EqualsBOIF : BinaryOperationIntrinsicFactory {
|
||||
isEnumIntrinsicApplicable(descriptor, leftType, rightType) -> EnumEqualsIntrinsic
|
||||
|
||||
KotlinBuiltIns.isBuiltIn(descriptor) ||
|
||||
TopLevelFIF.EQUALS_IN_ANY.apply(descriptor) -> EqualsIntrinsic
|
||||
TopLevelFIF.EQUALS_IN_ANY.test(descriptor) -> EqualsIntrinsic
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
+9
-9
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.intrinsic.operation
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsNumberLiteral
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.js.patterns.PatternBuilder.pattern
|
||||
import org.jetbrains.kotlin.js.translate.context.Namer
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext
|
||||
@@ -75,13 +75,13 @@ object LongCompareToBOIF : BinaryOperationIntrinsicFactory {
|
||||
override fun getIntrinsic(descriptor: FunctionDescriptor, leftType: KotlinType?, rightType: KotlinType?): BinaryOperationIntrinsic? {
|
||||
if (KotlinBuiltIns.isBuiltIn(descriptor)) {
|
||||
return when {
|
||||
FLOATING_POINT_COMPARE_TO_LONG_PATTERN.apply(descriptor) -> FLOATING_POINT_COMPARE_TO_LONG
|
||||
LONG_COMPARE_TO_FLOATING_POINT_PATTERN.apply(descriptor) -> LONG_COMPARE_TO_FLOATING_POINT
|
||||
INTEGER_COMPARE_TO_LONG_PATTERN.apply(descriptor) -> INTEGER_COMPARE_TO_LONG
|
||||
CHAR_COMPARE_TO_LONG_PATTERN.apply(descriptor) -> CHAR_COMPARE_TO_LONG
|
||||
LONG_COMPARE_TO_INTEGER_PATTERN.apply(descriptor) -> LONG_COMPARE_TO_INTEGER
|
||||
LONG_COMPARE_TO_CHAR_PATTERN.apply(descriptor) -> LONG_COMPARE_TO_CHAR
|
||||
LONG_COMPARE_TO_LONG_PATTERN.apply(descriptor) -> LONG_COMPARE_TO_LONG
|
||||
FLOATING_POINT_COMPARE_TO_LONG_PATTERN.test(descriptor) -> FLOATING_POINT_COMPARE_TO_LONG
|
||||
LONG_COMPARE_TO_FLOATING_POINT_PATTERN.test(descriptor) -> LONG_COMPARE_TO_FLOATING_POINT
|
||||
INTEGER_COMPARE_TO_LONG_PATTERN.test(descriptor) -> INTEGER_COMPARE_TO_LONG
|
||||
CHAR_COMPARE_TO_LONG_PATTERN.test(descriptor) -> CHAR_COMPARE_TO_LONG
|
||||
LONG_COMPARE_TO_INTEGER_PATTERN.test(descriptor) -> LONG_COMPARE_TO_INTEGER
|
||||
LONG_COMPARE_TO_CHAR_PATTERN.test(descriptor) -> LONG_COMPARE_TO_CHAR
|
||||
LONG_COMPARE_TO_LONG_PATTERN.test(descriptor) -> LONG_COMPARE_TO_LONG
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@ public class InOperationTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
public JsExpression translate() {
|
||||
ResolvedCall<? extends FunctionDescriptor> call = CallUtilKt.getFunctionResolvedCallWithAssert(operation, bindingContext());
|
||||
if (INT_SPECIALIZATION_TEST.apply(call.getResultingDescriptor())) {
|
||||
if (INT_SPECIALIZATION_TEST.test(call.getResultingDescriptor())) {
|
||||
JsExpression candidate = translateInt();
|
||||
if (candidate != null) {
|
||||
return candidate;
|
||||
@@ -83,7 +83,7 @@ public class InOperationTranslator extends AbstractTranslator {
|
||||
return null;
|
||||
}
|
||||
FunctionDescriptor callDescriptor = (FunctionDescriptor) rightCall.getResultingDescriptor();
|
||||
if (!INT_RANGE_TEST.apply(callDescriptor)) {
|
||||
if (!INT_RANGE_TEST.test(callDescriptor)) {
|
||||
return null;
|
||||
}
|
||||
if (!(rightCall.getDispatchReceiver() instanceof ExpressionReceiver)) {
|
||||
|
||||
Reference in New Issue
Block a user