Generate map for ConstantExpressionEvaluator
This commit is contained in:
+54
-21
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import java.lang.Short as JShort
|
||||
import java.lang.Byte as JByte
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument
|
||||
|
||||
[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")]
|
||||
public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor<CompileTimeConstant<*>, JetType>() {
|
||||
@@ -123,12 +124,15 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
val rightConstant = evaluate(rightExpression, booleanType)
|
||||
if (rightConstant == null) return null
|
||||
|
||||
val operationName = when(operationToken) {
|
||||
JetTokens.ANDAND -> Name.identifier("&&")
|
||||
JetTokens.OROR -> Name.identifier("||")
|
||||
val leftValue = leftConstant.getValue()
|
||||
val rightValue = rightConstant.getValue()
|
||||
|
||||
if (leftValue !is Boolean || rightValue !is Boolean) return null
|
||||
val result = when(operationToken) {
|
||||
JetTokens.ANDAND -> leftValue as Boolean && rightValue as Boolean
|
||||
JetTokens.OROR -> leftValue as Boolean || rightValue as Boolean
|
||||
else -> throw IllegalArgumentException("Unknown boolean operation token ${operationToken}")
|
||||
}
|
||||
val result = evaluateBinaryExpression(leftConstant, rightConstant, operationName)
|
||||
return createCompileTimeConstant(result, expectedType)
|
||||
}
|
||||
else {
|
||||
@@ -145,28 +149,29 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
val resolvedCall = trace.getBindingContext().get(BindingContext.RESOLVED_CALL, callExpression)
|
||||
if (resolvedCall == null) return null
|
||||
|
||||
val resultingDescriptor = resolvedCall.getResultingDescriptor()
|
||||
if (resultingDescriptor == null) return null
|
||||
val resultingDescriptorName = resolvedCall.getResultingDescriptor()?.getName()?.asString()
|
||||
if (resultingDescriptorName == null) return null
|
||||
|
||||
val receiverExpressionType = getReceiverExpressionType(resolvedCall)
|
||||
if (receiverExpressionType == null) return null
|
||||
val argumentForReceiver = createOperationArgumentForReceiver(resolvedCall, receiverExpression)
|
||||
if (argumentForReceiver == null) return null
|
||||
|
||||
val receiverValue = evaluate(receiverExpression, receiverExpressionType)
|
||||
if (receiverValue == null) return null
|
||||
val argumentsEntrySet = resolvedCall.getValueArguments().entrySet()
|
||||
if (argumentsEntrySet.isEmpty()) {
|
||||
val function = unaryOperations[UnaryOperation(argumentForReceiver.ctcType, resultingDescriptorName)]
|
||||
if (function == null) return null
|
||||
return function(argumentForReceiver.value)
|
||||
}
|
||||
else if (argumentsEntrySet.size() == 1) {
|
||||
val (parameter, argument) = argumentsEntrySet.first()
|
||||
|
||||
val arguments = resolvedCall.getValueArguments().entrySet().flatMap {
|
||||
entry ->
|
||||
val (parameter, argument) = entry
|
||||
resolveArguments(argument.getArguments(), parameter.getType())
|
||||
val argumentForParameter = createOperationArgumentForFristParameter(argument, parameter)
|
||||
if (argumentForParameter == null) return null
|
||||
|
||||
val function = binaryOperations[BinaryOperation(argumentForReceiver.ctcType, argumentForParameter.ctcType, resultingDescriptorName)]
|
||||
if (function == null) return null
|
||||
return function(argumentForReceiver.value, argumentForParameter.value)
|
||||
}
|
||||
|
||||
val resultingDescriptorName = resultingDescriptor.getName()
|
||||
if (arguments.isEmpty()) {
|
||||
return evaluateUnaryExpression(receiverValue, resultingDescriptorName)
|
||||
}
|
||||
else if (arguments.size() == 1) {
|
||||
return evaluateBinaryExpression(receiverValue, arguments.first(), resultingDescriptorName)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -277,6 +282,34 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
return evaluator.evaluate(expression, expectedType)
|
||||
}
|
||||
}
|
||||
|
||||
private class OperationArgument(val value: Any?, val ctcType: CompileTimeType<*>)
|
||||
|
||||
private fun createOperationArgumentForReceiver(resolvedCall: ResolvedCall<*>, expression: JetExpression): OperationArgument? {
|
||||
val receiverExpressionType = getReceiverExpressionType(resolvedCall)
|
||||
if (receiverExpressionType == null) return null
|
||||
|
||||
val receiverCompileTimeType = getCompileTimeType(receiverExpressionType)
|
||||
if (receiverCompileTimeType == null) return null
|
||||
|
||||
val receiverValue = evaluate(expression, receiverExpressionType)?.getValue()
|
||||
if (receiverValue == null) return null
|
||||
|
||||
return OperationArgument(receiverValue, receiverCompileTimeType)
|
||||
}
|
||||
|
||||
private fun createOperationArgumentForFristParameter(argument: ResolvedValueArgument, parameter: ValueParameterDescriptor): OperationArgument? {
|
||||
val argumentCompileTimeType = getCompileTimeType(parameter.getType())
|
||||
if (argumentCompileTimeType == null) return null
|
||||
|
||||
val argumentCompileTimeValue = resolveArguments(argument.getArguments(), parameter.getType())
|
||||
if (argumentCompileTimeValue.size != 1) return null
|
||||
|
||||
val argumentValue = argumentCompileTimeValue.first().getValue()
|
||||
if (argumentValue == null) return null
|
||||
|
||||
return OperationArgument(argumentValue, argumentCompileTimeType)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCompileTimeConstantForEquals(result: Any?, operationToken: IElementType): CompileTimeConstant<*>? {
|
||||
|
||||
@@ -0,0 +1,408 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.evaluate
|
||||
|
||||
/** This file is generated by org.jetbrains.jet.generators.evaluate:generate(). DO NOT MODIFY MANUALLY */
|
||||
|
||||
private val unaryOperations = hashMapOf<UnaryOperationKey<*>, (Any?) -> Any>(
|
||||
unaryOperationKey(BOOLEAN, "not", { a -> a.not() }),
|
||||
unaryOperationKey(BYTE, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(BYTE, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(BYTE, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(BYTE, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(BYTE, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(BYTE, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(BYTE, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(BYTE, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(BYTE, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(CHAR, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(CHAR, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(CHAR, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(CHAR, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(CHAR, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(CHAR, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(CHAR, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(CHAR, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(CHAR, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(DOUBLE, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(DOUBLE, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(DOUBLE, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(DOUBLE, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(DOUBLE, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(DOUBLE, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(DOUBLE, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(DOUBLE, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(DOUBLE, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(FLOAT, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(FLOAT, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(FLOAT, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(FLOAT, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(FLOAT, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(FLOAT, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(FLOAT, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(FLOAT, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(FLOAT, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(INT, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(INT, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(INT, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(INT, "inv", { a -> a.inv() }),
|
||||
unaryOperationKey(INT, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(INT, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(INT, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(INT, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(INT, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(INT, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(LONG, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(LONG, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(LONG, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(LONG, "inv", { a -> a.inv() }),
|
||||
unaryOperationKey(LONG, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(LONG, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(LONG, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(LONG, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(LONG, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(LONG, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(SHORT, "toInt", { a -> a.toInt() }),
|
||||
unaryOperationKey(SHORT, "minus", { a -> a.minus() }),
|
||||
unaryOperationKey(SHORT, "toChar", { a -> a.toChar() }),
|
||||
unaryOperationKey(SHORT, "toLong", { a -> a.toLong() }),
|
||||
unaryOperationKey(SHORT, "plus", { a -> a.plus() }),
|
||||
unaryOperationKey(SHORT, "toFloat", { a -> a.toFloat() }),
|
||||
unaryOperationKey(SHORT, "toDouble", { a -> a.toDouble() }),
|
||||
unaryOperationKey(SHORT, "toShort", { a -> a.toShort() }),
|
||||
unaryOperationKey(SHORT, "toByte", { a -> a.toByte() }),
|
||||
unaryOperationKey(STRING, "toString", { a -> a.toString() })
|
||||
)
|
||||
|
||||
private val binaryOperations = hashMapOf<BinaryOperationKey<*, *>, (Any?, Any?) -> Any>(
|
||||
binaryOperationKey(BOOLEAN, BOOLEAN, "xor", { a, b -> a.xor(b) }),
|
||||
binaryOperationKey(BOOLEAN, BOOLEAN, "or", { a, b -> a.or(b) }),
|
||||
binaryOperationKey(BOOLEAN, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(BOOLEAN, BOOLEAN, "and", { a, b -> a.and(b) }),
|
||||
binaryOperationKey(BYTE, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(BYTE, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(BYTE, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, CHAR, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(BYTE, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, CHAR, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(BYTE, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, CHAR, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(BYTE, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, CHAR, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(BYTE, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(CHAR, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(CHAR, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(CHAR, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(CHAR, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(CHAR, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(CHAR, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(CHAR, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(CHAR, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(CHAR, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(CHAR, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(CHAR, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(CHAR, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(CHAR, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(CHAR, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(CHAR, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(CHAR, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(CHAR, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(CHAR, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(CHAR, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(CHAR, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(CHAR, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(CHAR, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(CHAR, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(CHAR, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(CHAR, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(CHAR, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(CHAR, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(DOUBLE, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(DOUBLE, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(DOUBLE, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, CHAR, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(DOUBLE, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, CHAR, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(DOUBLE, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(DOUBLE, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(DOUBLE, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(DOUBLE, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(DOUBLE, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(DOUBLE, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(DOUBLE, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, CHAR, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(DOUBLE, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(FLOAT, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(FLOAT, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(FLOAT, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, CHAR, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(FLOAT, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, CHAR, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(FLOAT, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, CHAR, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(FLOAT, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, CHAR, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(FLOAT, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(INT, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(INT, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, CHAR, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(INT, INT, "shl", { a, b -> a.shl(b) }),
|
||||
binaryOperationKey(INT, INT, "ushr", { a, b -> a.ushr(b) }),
|
||||
binaryOperationKey(INT, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, CHAR, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(INT, INT, "shr", { a, b -> a.shr(b) }),
|
||||
binaryOperationKey(INT, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, CHAR, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(INT, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, CHAR, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(INT, INT, "or", { a, b -> a.or(b) }),
|
||||
binaryOperationKey(INT, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(INT, INT, "and", { a, b -> a.and(b) }),
|
||||
binaryOperationKey(INT, INT, "xor", { a, b -> a.xor(b) }),
|
||||
binaryOperationKey(INT, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(LONG, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(LONG, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, CHAR, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(LONG, INT, "shl", { a, b -> a.shl(b) }),
|
||||
binaryOperationKey(LONG, INT, "ushr", { a, b -> a.ushr(b) }),
|
||||
binaryOperationKey(LONG, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, CHAR, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(LONG, INT, "shr", { a, b -> a.shr(b) }),
|
||||
binaryOperationKey(LONG, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, CHAR, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(LONG, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, CHAR, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(LONG, LONG, "or", { a, b -> a.or(b) }),
|
||||
binaryOperationKey(LONG, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(LONG, LONG, "and", { a, b -> a.and(b) }),
|
||||
binaryOperationKey(LONG, LONG, "xor", { a, b -> a.xor(b) }),
|
||||
binaryOperationKey(LONG, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(SHORT, BYTE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, CHAR, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, DOUBLE, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, FLOAT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, INT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, LONG, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, SHORT, "minus", { a, b -> a.minus(b) }),
|
||||
binaryOperationKey(SHORT, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
binaryOperationKey(SHORT, BYTE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, CHAR, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, DOUBLE, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, FLOAT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, INT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, LONG, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, SHORT, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(SHORT, BYTE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, CHAR, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, DOUBLE, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, FLOAT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, INT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, LONG, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, SHORT, "div", { a, b -> a.div(b) }),
|
||||
binaryOperationKey(SHORT, BYTE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, CHAR, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, DOUBLE, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, FLOAT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, INT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, LONG, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, SHORT, "mod", { a, b -> a.mod(b) }),
|
||||
binaryOperationKey(SHORT, BYTE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, CHAR, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, DOUBLE, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, FLOAT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, INT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, LONG, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, SHORT, "times", { a, b -> a.times(b) }),
|
||||
binaryOperationKey(SHORT, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(STRING, ANY, "plus", { a, b -> a.plus(b) }),
|
||||
binaryOperationKey(STRING, INT, "get", { a, b -> a.get(b) }),
|
||||
binaryOperationKey(STRING, ANY, "equals", { a, b -> a.equals(b) }),
|
||||
binaryOperationKey(STRING, STRING, "compareTo", { a, b -> a.compareTo(b) })
|
||||
)
|
||||
-538
@@ -1,538 +0,0 @@
|
||||
package org.jetbrains.jet.lang.evaluate
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
|
||||
fun evaluateBinaryExpression(firstCompileTimeConstant: CompileTimeConstant<*>, secondCompileTimeConstant: CompileTimeConstant<*>, functionName: Name): Any? {
|
||||
val compileTimeTypeFirst = getCompileTimeType(firstCompileTimeConstant)
|
||||
val compileTimeTypeSecond = getCompileTimeType(secondCompileTimeConstant)
|
||||
if (compileTimeTypeFirst == null || compileTimeTypeSecond == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val first = firstCompileTimeConstant.getValue()
|
||||
val second = secondCompileTimeConstant.getValue()
|
||||
|
||||
val function = binaryOperations[BinaryOperation(compileTimeTypeFirst, compileTimeTypeSecond, functionName)]
|
||||
if (function != null) {
|
||||
return function(first, second)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun evaluateUnaryExpression(compileTimeConstant: CompileTimeConstant<*>, functionName: Name): Any? {
|
||||
val compileTimeType = getCompileTimeType(compileTimeConstant)
|
||||
if (compileTimeType == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
val value = compileTimeConstant.getValue()
|
||||
|
||||
val function = unaryOperations[UnaryOperation(compileTimeType, functionName)]
|
||||
if (function != null) {
|
||||
return function(value)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun getCompileTimeType(c: CompileTimeConstant<*>): CompileTimeType<out Any>? = when (c.getValue()) {
|
||||
is Int -> INT
|
||||
is Byte -> BYTE
|
||||
is Short -> SHORT
|
||||
is Long -> LONG
|
||||
is Double -> DOUBLE
|
||||
is Float -> FLOAT
|
||||
is Char -> CHAR
|
||||
is Boolean -> BOOLEAN
|
||||
is String -> STRING
|
||||
else -> null
|
||||
}
|
||||
|
||||
private class CompileTimeType<T>
|
||||
|
||||
private val BYTE = CompileTimeType<Byte>()
|
||||
private val SHORT = CompileTimeType<Short>()
|
||||
private val INT = CompileTimeType<Int>()
|
||||
private val LONG = CompileTimeType<Long>()
|
||||
private val DOUBLE = CompileTimeType<Double>()
|
||||
private val FLOAT = CompileTimeType<Float>()
|
||||
private val CHAR = CompileTimeType<Char>()
|
||||
private val BOOLEAN = CompileTimeType<Boolean>()
|
||||
private val STRING = CompileTimeType<String>()
|
||||
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
private fun <A, B> bOp(
|
||||
a: CompileTimeType<A>,
|
||||
b: CompileTimeType<B>,
|
||||
functionNameAsString: String,
|
||||
f: (A, B) -> Any
|
||||
) = BinaryOperation(a, b, Name.identifier(functionNameAsString)) to f as Function2<Any?, Any?, Any>
|
||||
|
||||
private fun <A> uOp(a: CompileTimeType<A>, functionNameAsString: String, f: (A) -> Any) = UnaryOperation(a, Name.identifier(functionNameAsString)) to f as Function1<Any?, Any>
|
||||
|
||||
private data class BinaryOperation<A, B>(val f: CompileTimeType<out A>, val s: CompileTimeType<out B>, val functionName: Name)
|
||||
private data class UnaryOperation<A>(val f: CompileTimeType<out A>, val functionName: Name)
|
||||
|
||||
private val unaryOperations = hashMapOf<UnaryOperation<*>, (Any?) -> Any>(
|
||||
uOp(DOUBLE, "minus", { -it }),
|
||||
uOp(FLOAT, "minus", { -it }),
|
||||
uOp(LONG, "minus", { -it }),
|
||||
uOp(INT, "minus", { -it }),
|
||||
uOp(SHORT, "minus", { -it }),
|
||||
uOp(BYTE, "minus", { -it }),
|
||||
uOp(CHAR, "minus", { -it }),
|
||||
uOp(DOUBLE, "plus", { a -> a.plus() }),
|
||||
uOp(FLOAT, "plus", { a -> a.plus() }),
|
||||
uOp(LONG, "plus", { a -> a.plus() }),
|
||||
uOp(INT, "plus", { a -> a.plus() }),
|
||||
uOp(SHORT, "plus", { a -> a.plus() }),
|
||||
uOp(BYTE, "plus", { a -> a.plus() }),
|
||||
uOp(CHAR, "plus", { a -> a.plus() }),
|
||||
|
||||
uOp(DOUBLE, "toDouble", { a -> a.toDouble() }),
|
||||
uOp(FLOAT, "toDouble", { a -> a.toDouble() }),
|
||||
uOp(LONG, "toDouble", { a -> a.toDouble() }),
|
||||
uOp(INT, "toDouble", { a -> a.toDouble() }),
|
||||
uOp(SHORT, "toDouble", { a -> a.toDouble() }),
|
||||
uOp(BYTE, "toDouble", { a -> a.toDouble() }),
|
||||
uOp(CHAR, "toDouble", { a -> a.toDouble() }),
|
||||
|
||||
uOp(DOUBLE, "toFloat", { a -> a.toFloat() }),
|
||||
uOp(FLOAT, "toFloat", { a -> a.toFloat() }),
|
||||
uOp(LONG, "toFloat", { a -> a.toFloat() }),
|
||||
uOp(INT, "toFloat", { a -> a.toFloat() }),
|
||||
uOp(SHORT, "toFloat", { a -> a.toFloat() }),
|
||||
uOp(BYTE, "toFloat", { a -> a.toFloat() }),
|
||||
uOp(CHAR, "toFloat", { a -> a.toFloat() }),
|
||||
|
||||
uOp(DOUBLE, "toLong", { a -> a.toLong() }),
|
||||
uOp(FLOAT, "toLong", { a -> a.toLong() }),
|
||||
uOp(LONG, "toLong", { a -> a.toLong() }),
|
||||
uOp(INT, "toLong", { a -> a.toLong() }),
|
||||
uOp(SHORT, "toLong", { a -> a.toLong() }),
|
||||
uOp(BYTE, "toLong", { a -> a.toLong() }),
|
||||
uOp(CHAR, "toLong", { a -> a.toLong() }),
|
||||
|
||||
uOp(DOUBLE, "toInt", { a -> a.toInt() }),
|
||||
uOp(FLOAT, "toInt", { a -> a.toInt() }),
|
||||
uOp(LONG, "toInt", { a -> a.toInt() }),
|
||||
uOp(INT, "toInt", { a -> a.toInt() }),
|
||||
uOp(SHORT, "toInt", { a -> a.toInt() }),
|
||||
uOp(BYTE, "toInt", { a -> a.toInt() }),
|
||||
uOp(CHAR, "toInt", { a -> a.toInt() }),
|
||||
|
||||
uOp(DOUBLE, "toChar", { a -> a.toChar() }),
|
||||
uOp(FLOAT, "toChar", { a -> a.toChar() }),
|
||||
uOp(LONG, "toChar", { a -> a.toChar() }),
|
||||
uOp(INT, "toChar", { a -> a.toChar() }),
|
||||
uOp(SHORT, "toChar", { a -> a.toChar() }),
|
||||
uOp(BYTE, "toChar", { a -> a.toChar() }),
|
||||
uOp(CHAR, "toChar", { a -> a.toChar() }),
|
||||
|
||||
uOp(DOUBLE, "toShort", { a -> a.toShort() }),
|
||||
uOp(FLOAT, "toShort", { a -> a.toShort() }),
|
||||
uOp(LONG, "toShort", { a -> a.toShort() }),
|
||||
uOp(INT, "toShort", { a -> a.toShort() }),
|
||||
uOp(SHORT, "toShort", { a -> a.toShort() }),
|
||||
uOp(BYTE, "toShort", { a -> a.toShort() }),
|
||||
uOp(CHAR, "toShort", { a -> a.toShort() }),
|
||||
|
||||
uOp(DOUBLE, "toByte", { a -> a.toByte() }),
|
||||
uOp(FLOAT, "toByte", { a -> a.toByte() }),
|
||||
uOp(LONG, "toByte", { a -> a.toByte() }),
|
||||
uOp(INT, "toByte", { a -> a.toByte() }),
|
||||
uOp(SHORT, "toByte", { a -> a.toByte() }),
|
||||
uOp(BYTE, "toByte", { a -> a.toByte() }),
|
||||
uOp(CHAR, "toByte", { a -> a.toByte() }),
|
||||
|
||||
uOp(BOOLEAN, "not", { a -> a.not() })
|
||||
)
|
||||
|
||||
private val binaryOperations = hashMapOf<BinaryOperation<*, *>, (Any?, Any?) -> Any>(
|
||||
// String
|
||||
bOp(STRING, STRING, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, INT, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(STRING, STRING, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(STRING, STRING, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Boolean
|
||||
bOp(BOOLEAN, BOOLEAN, "and", { a, b -> a and b }),
|
||||
bOp(BOOLEAN, BOOLEAN, "or", { a, b -> a or b }),
|
||||
bOp(BOOLEAN, BOOLEAN, "xor", { a, b -> a xor b }),
|
||||
bOp(BOOLEAN, BOOLEAN, "andand", { a, b -> a && b }),
|
||||
bOp(BOOLEAN, BOOLEAN, "oror", { a, b -> a || b }),
|
||||
bOp(BOOLEAN, BOOLEAN, "equals", { a, b -> a == b }),
|
||||
|
||||
// Byte
|
||||
bOp(BYTE, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, INT, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(BYTE, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, INT, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(BYTE, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, LONG, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, INT, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, CHAR, "times", { a, b -> a * b }),
|
||||
bOp(BYTE, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, LONG, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, INT, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, CHAR, "div", { a, b -> a / b }),
|
||||
bOp(BYTE, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, INT, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, CHAR, "mod", { a, b -> a % b }),
|
||||
bOp(BYTE, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(BYTE, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(BYTE, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(BYTE, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(BYTE, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(BYTE, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(BYTE, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(BYTE, CHAR, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Short
|
||||
bOp(SHORT, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, INT, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(SHORT, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, INT, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(SHORT, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, LONG, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, INT, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, CHAR, "times", { a, b -> a * b }),
|
||||
bOp(SHORT, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, LONG, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, INT, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, CHAR, "div", { a, b -> a / b }),
|
||||
bOp(SHORT, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, INT, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, CHAR, "mod", { a, b -> a % b }),
|
||||
bOp(SHORT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(SHORT, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(SHORT, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(SHORT, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(SHORT, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(SHORT, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(SHORT, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(SHORT, CHAR, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Int
|
||||
bOp(INT, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(INT, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(INT, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(INT, INT, "plus", { a, b -> a + b }),
|
||||
bOp(INT, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(INT, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(INT, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(INT, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(INT, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(INT, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(INT, INT, "minus", { a, b -> a - b }),
|
||||
bOp(INT, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(INT, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(INT, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(INT, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(INT, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(INT, LONG, "times", { a, b -> a * b }),
|
||||
bOp(INT, INT, "times", { a, b -> a * b }),
|
||||
bOp(INT, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(INT, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(INT, CHAR, "times", { a, b -> a * b }),
|
||||
bOp(INT, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(INT, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(INT, LONG, "div", { a, b -> a / b }),
|
||||
bOp(INT, INT, "div", { a, b -> a / b }),
|
||||
bOp(INT, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(INT, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(INT, CHAR, "div", { a, b -> a / b }),
|
||||
bOp(INT, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(INT, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(INT, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(INT, INT, "mod", { a, b -> a % b }),
|
||||
bOp(INT, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(INT, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(INT, CHAR, "mod", { a, b -> a % b }),
|
||||
bOp(INT, INT, "shl", { a, b -> a shl b }),
|
||||
bOp(INT, INT, "shr", { a, b -> a shr b }),
|
||||
bOp(INT, INT, "ushr",{ a, b -> a ushr b }),
|
||||
bOp(INT, INT, "and", { a, b -> a and b }),
|
||||
bOp(INT, INT, "or", { a, b -> a or b }),
|
||||
bOp(INT, INT, "xor", { a, b -> a xor b }),
|
||||
bOp(INT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(INT, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(INT, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(INT, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(INT, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(INT, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(INT, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(INT, CHAR, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Long
|
||||
bOp(LONG, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, INT, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(LONG, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, INT, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(LONG, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(LONG, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(LONG, LONG, "times", { a, b -> a * b }),
|
||||
bOp(LONG, INT, "times", { a, b -> a * b }),
|
||||
bOp(LONG, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(LONG, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(LONG, CHAR, "times", { a, b -> a * b }),
|
||||
bOp(LONG, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(LONG, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(LONG, LONG, "div", { a, b -> a / b }),
|
||||
bOp(LONG, INT, "div", { a, b -> a / b }),
|
||||
bOp(LONG, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(LONG, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(LONG, CHAR, "div", { a, b -> a / b }),
|
||||
bOp(LONG, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, INT, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, CHAR, "mod", { a, b -> a % b }),
|
||||
bOp(LONG, INT, "shl", { a, b -> a shl b }),
|
||||
bOp(LONG, INT, "shr", { a, b -> a shr b }),
|
||||
bOp(LONG, INT, "ushr",{ a, b -> a ushr b }),
|
||||
bOp(LONG, LONG, "and", { a, b -> a and b }),
|
||||
bOp(LONG, LONG, "or", { a, b -> a or b }),
|
||||
bOp(LONG, LONG, "xor", { a, b -> a xor b }),
|
||||
bOp(LONG, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(LONG, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(LONG, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(LONG, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(LONG, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(LONG, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(LONG, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(LONG, CHAR, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Double
|
||||
bOp(DOUBLE, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, INT, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(DOUBLE, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, INT, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(DOUBLE, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, LONG, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, INT, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, CHAR, "times", { a, b -> a * b }),
|
||||
bOp(DOUBLE, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, LONG, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, INT, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, CHAR, "div", { a, b -> a / b }),
|
||||
bOp(DOUBLE, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(DOUBLE, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(DOUBLE, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(DOUBLE, INT, "mod", { a, b -> a % b }),
|
||||
bOp(DOUBLE, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(DOUBLE, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(DOUBLE, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(DOUBLE, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(DOUBLE, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(DOUBLE, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(DOUBLE, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(DOUBLE, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(DOUBLE, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(DOUBLE, CHAR, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Float
|
||||
bOp(FLOAT, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, INT, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, CHAR, "plus", { a, b -> a + b }),
|
||||
bOp(FLOAT, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, INT, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(FLOAT, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, LONG, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, INT, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, CHAR, "times", { a, b -> a * b }),
|
||||
bOp(FLOAT, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, LONG, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, INT, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, CHAR, "div", { a, b -> a / b }),
|
||||
bOp(FLOAT, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, INT, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, CHAR, "mod", { a, b -> a % b }),
|
||||
bOp(FLOAT, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(FLOAT, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(FLOAT, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(FLOAT, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(FLOAT, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(FLOAT, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(FLOAT, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(FLOAT, CHAR, "equals", { a, b -> a.equals(b) }),
|
||||
|
||||
// Char
|
||||
bOp(CHAR, DOUBLE, "plus", { a, b -> a + b }),
|
||||
bOp(CHAR, FLOAT, "plus", { a, b -> a + b }),
|
||||
bOp(CHAR, LONG, "plus", { a, b -> a + b }),
|
||||
bOp(CHAR, INT, "plus", { a, b -> a + b }),
|
||||
bOp(CHAR, SHORT, "plus", { a, b -> a + b }),
|
||||
bOp(CHAR, BYTE, "plus", { a, b -> a + b }),
|
||||
bOp(CHAR, DOUBLE, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, FLOAT, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, LONG, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, INT, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, SHORT, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, BYTE, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, CHAR, "minus", { a, b -> a - b }),
|
||||
bOp(CHAR, DOUBLE, "times", { a, b -> a * b }),
|
||||
bOp(CHAR, FLOAT, "times", { a, b -> a * b }),
|
||||
bOp(CHAR, LONG, "times", { a, b -> a * b }),
|
||||
bOp(CHAR, INT, "times", { a, b -> a * b }),
|
||||
bOp(CHAR, SHORT, "times", { a, b -> a * b }),
|
||||
bOp(CHAR, BYTE, "times", { a, b -> a * b }),
|
||||
bOp(CHAR, DOUBLE, "div", { a, b -> a / b }),
|
||||
bOp(CHAR, FLOAT, "div", { a, b -> a / b }),
|
||||
bOp(CHAR, LONG, "div", { a, b -> a / b }),
|
||||
bOp(CHAR, INT, "div", { a, b -> a / b }),
|
||||
bOp(CHAR, SHORT, "div", { a, b -> a / b }),
|
||||
bOp(CHAR, BYTE, "div", { a, b -> a / b }),
|
||||
bOp(CHAR, DOUBLE, "mod", { a, b -> a % b }),
|
||||
bOp(CHAR, FLOAT, "mod", { a, b -> a % b }),
|
||||
bOp(CHAR, LONG, "mod", { a, b -> a % b }),
|
||||
bOp(CHAR, INT, "mod", { a, b -> a % b }),
|
||||
bOp(CHAR, SHORT, "mod", { a, b -> a % b }),
|
||||
bOp(CHAR, BYTE, "mod", { a, b -> a % b }),
|
||||
bOp(CHAR, DOUBLE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, FLOAT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, LONG, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, INT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, SHORT, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, BYTE, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, CHAR, "compareTo", { a, b -> a.compareTo(b) }),
|
||||
bOp(CHAR, DOUBLE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(CHAR, FLOAT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(CHAR, LONG, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(CHAR, INT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(CHAR, SHORT, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(CHAR, BYTE, "equals", { a, b -> a.equals(b) }),
|
||||
bOp(CHAR, CHAR, "equals", { a, b -> a.equals(b) })
|
||||
)
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.generators.evaluate
|
||||
|
||||
import org.jetbrains.jet.di.GeneratorsFileUtil
|
||||
import java.io.File
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.jet.utils.Printer
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.lang.types.TypeUtils
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
|
||||
val DEST_FILE: File = File("compiler/frontend/src/org/jetbrains/jet/lang/evaluate/OperationsMapGenerated.kt")
|
||||
private val EXCLUDED_FUNCTIONS = listOf("rangeTo", "hashCode", "inc", "dec")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
GeneratorsFileUtil.writeFileIfContentChanged(DEST_FILE, generate())
|
||||
}
|
||||
|
||||
fun generate(): String {
|
||||
val sb = StringBuilder()
|
||||
val p = Printer(sb)
|
||||
p.println(FileUtil.loadFile(File("injector-generator/copyright.txt")))
|
||||
p.println("package org.jetbrains.jet.lang.evaluate")
|
||||
p.println()
|
||||
p.println("/** This file is generated by org.jetbrains.jet.generators.evaluate:generate(). DO NOT MODIFY MANUALLY */")
|
||||
p.println()
|
||||
|
||||
val unaryOperationsMap = arrayListOf<Pair<String, List<String>>>()
|
||||
val binaryOperationsMap = arrayListOf<Pair<String, List<String>>>()
|
||||
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
val allPrimitiveTypes = builtIns.getBuiltInsPackage().getMemberScope().getAllDescriptors()
|
||||
.filter { it is ClassDescriptor && builtIns.isPrimitiveType(it.getDefaultType()) } as List<ClassDescriptor>
|
||||
|
||||
for (descriptor in allPrimitiveTypes + builtIns.getString()) {
|
||||
[suppress("UNCHECKED_CAST")]
|
||||
val functions = descriptor.getMemberScope(Collections.emptyList()).getAllDescriptors()
|
||||
.filter { it is FunctionDescriptor && !EXCLUDED_FUNCTIONS.contains(it.getName().asString()) } as List<FunctionDescriptor>
|
||||
|
||||
for (function in functions) {
|
||||
val parametersTypes = function.getParametersTypes()
|
||||
|
||||
when (parametersTypes.size) {
|
||||
1 -> unaryOperationsMap.add(function.getName().asString() to parametersTypes)
|
||||
2 -> binaryOperationsMap.add(function.getName().asString() to parametersTypes)
|
||||
else -> throw IllegalStateException("Couldn't add following method from builtins to operations map: ${function.getName()} in class ${descriptor.getName()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p.println("private val unaryOperations = hashMapOf<UnaryOperation<*>, (Any?) -> Any>(")
|
||||
p.pushIndent()
|
||||
|
||||
val unaryOperationsMapIterator = unaryOperationsMap.iterator()
|
||||
while (unaryOperationsMapIterator.hasNext()) {
|
||||
val (funcName, parameters) = unaryOperationsMapIterator.next()
|
||||
p.print(
|
||||
"unaryOperationKey(",
|
||||
parameters.makeString(", "),
|
||||
", ",
|
||||
"\"$funcName\"",
|
||||
", { a -> a.${funcName}() })"
|
||||
)
|
||||
if (unaryOperationsMapIterator.hasNext()) {
|
||||
p.printWithNoIndent(", ")
|
||||
}
|
||||
p.println()
|
||||
}
|
||||
p.popIndent()
|
||||
p.println(")")
|
||||
|
||||
p.println()
|
||||
|
||||
|
||||
p.println("private val binaryOperations = hashMapOf<BinaryOperation<*, *>, (Any?, Any?) -> Any>(")
|
||||
p.pushIndent()
|
||||
|
||||
val binaryOperationsMapIterator = binaryOperationsMap.iterator()
|
||||
while (binaryOperationsMapIterator.hasNext()) {
|
||||
val (funcName, parameters) = binaryOperationsMapIterator.next()
|
||||
p.print(
|
||||
"binaryOperationKey(",
|
||||
parameters.makeString(", "),
|
||||
", ",
|
||||
"\"$funcName\"",
|
||||
", { a, b -> a.${funcName}(b) })"
|
||||
)
|
||||
if (binaryOperationsMapIterator.hasNext()) {
|
||||
p.printWithNoIndent(", ")
|
||||
}
|
||||
p.println()
|
||||
}
|
||||
p.popIndent()
|
||||
p.println(")")
|
||||
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
private fun FunctionDescriptor.getParametersTypes(): List<String> {
|
||||
val list = arrayListOf(getExpectedThisObject()!!.getType().asSrting().toUpperCase())
|
||||
getValueParameters().map { it.getType() }.forEach {
|
||||
list.add(TypeUtils.makeNotNullable(it).asSrting().toUpperCase())
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
private fun JetType.asSrting(): String = getConstructor().getDeclarationDescriptor()!!.getName().asString()
|
||||
@@ -33,6 +33,7 @@ import org.jetbrains.jet.completion.*;
|
||||
import org.jetbrains.jet.completion.weighers.AbstractCompletionWeigherTest;
|
||||
import org.jetbrains.jet.descriptors.serialization.AbstractDescriptorSerializationTest;
|
||||
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
|
||||
import org.jetbrains.jet.evaluate.AbstractEvaluateExpressionTest;
|
||||
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
|
||||
import org.jetbrains.jet.formatter.AbstractJetFormatterTest;
|
||||
import org.jetbrains.jet.generators.tests.generator.SimpleTestClassModel;
|
||||
@@ -565,6 +566,13 @@ public class GenerateTests {
|
||||
AbstractAnnotationParameterTest.class,
|
||||
testModel("compiler/testData/resolveAnnotations/parameters")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"compiler/tests",
|
||||
"EvaluateExpressionTestGenerated",
|
||||
AbstractEvaluateExpressionTest.class,
|
||||
testModel("compiler/testData/evaluate")
|
||||
);
|
||||
}
|
||||
|
||||
private static SimpleTestClassModel testModel(@NotNull String rootPath) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.generators.test.evaluate
|
||||
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import org.jetbrains.jet.generators.evaluate
|
||||
|
||||
public class GenerateOperationsMapTest() : UsefulTestCase() {
|
||||
public fun testGeneratedDataIsUpToDate(): Unit {
|
||||
val text = evaluate.generate()
|
||||
JetTestUtils.assertEqualsToFile(evaluate.DEST_FILE, text)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user