From d8330c3f141868422b9ff22d7c9d66ab879a66ad Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 7 Dec 2016 13:31:08 +0300 Subject: [PATCH] Adapt JS translator to able work with deprecated 'mod' operator --- .../factories/PrimitiveBinaryOperationFIF.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java index 05c5d8ab8da..71abb412941 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/intrinsic/functions/factories/PrimitiveBinaryOperationFIF.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,7 +90,7 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory { }; @NotNull - private static final NamePredicate BINARY_OPERATIONS = new NamePredicate(OperatorConventions.BINARY_OPERATION_NAMES.values()); + private static final NamePredicate BINARY_OPERATIONS = new NamePredicate(OperatorNameConventions.BINARY_OPERATION_NAMES); private static final DescriptorPredicate PRIMITIVE_NUMBERS_BINARY_OPERATIONS = pattern(NamePredicate.PRIMITIVE_NUMBERS_MAPPED_TO_PRIMITIVE_JS, BINARY_OPERATIONS); @@ -166,12 +166,15 @@ public enum PrimitiveBinaryOperationFIF implements FunctionIntrinsicFactory { @NotNull private static JsBinaryOperator getOperator(@NotNull FunctionDescriptor descriptor) { - KtToken token = OperatorConventions.BINARY_OPERATION_NAMES.inverse().get(descriptor.getName()); + // Temporary hack to get '%' for deprecated 'mod' operator + Name descriptorName = descriptor.getName().equals(OperatorNameConventions.MOD) ? OperatorNameConventions.REM : descriptor.getName(); + + KtToken token = OperatorConventions.BINARY_OPERATION_NAMES.inverse().get(descriptorName); if (token == null) { - token = OperatorConventions.BOOLEAN_OPERATIONS.inverse().get(descriptor.getName()); + token = OperatorConventions.BOOLEAN_OPERATIONS.inverse().get(descriptorName); } if (token == null) { - assert descriptor.getName().asString().equals("xor"); + assert descriptorName.asString().equals("xor"); return JsBinaryOperator.BIT_XOR; } return OperatorTable.getBinaryOperator(token);