Support builtin properties in ConstantExpressionEvaluator
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e062e32f95
commit
0b9c9a6047
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.generators.evaluate
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.generators.util.GeneratorsFileUtil
|
||||
@@ -46,7 +47,7 @@ fun generate(): String {
|
||||
p.println("/** This file is generated by org.jetbrains.kotlin.generators.evaluate:generate(). DO NOT MODIFY MANUALLY */")
|
||||
p.println()
|
||||
|
||||
val unaryOperationsMap = arrayListOf<Pair<String, List<JetType>>>()
|
||||
val unaryOperationsMap = arrayListOf<Triple<String, List<JetType>, Boolean>>()
|
||||
val binaryOperationsMap = arrayListOf<Pair<String, List<JetType>>>()
|
||||
|
||||
val builtIns = TargetPlatform.Default.builtIns
|
||||
@@ -57,13 +58,13 @@ fun generate(): String {
|
||||
for (descriptor in allPrimitiveTypes + builtIns.getString()) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val functions = descriptor.getMemberScope(listOf()).getDescriptors()
|
||||
.filter { it is FunctionDescriptor && !EXCLUDED_FUNCTIONS.contains(it.getName().asString()) } as List<FunctionDescriptor>
|
||||
.filter { it is CallableDescriptor && !EXCLUDED_FUNCTIONS.contains(it.getName().asString()) } as List<CallableDescriptor>
|
||||
|
||||
for (function in functions) {
|
||||
val parametersTypes = function.getParametersTypes()
|
||||
|
||||
when (parametersTypes.size()) {
|
||||
1 -> unaryOperationsMap.add(function.getName().asString() to parametersTypes)
|
||||
1 -> unaryOperationsMap.add(Triple(function.getName().asString(), parametersTypes, function is FunctionDescriptor))
|
||||
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()}")
|
||||
}
|
||||
@@ -79,13 +80,14 @@ fun generate(): String {
|
||||
|
||||
val unaryOperationsMapIterator = unaryOperationsMap.iterator()
|
||||
while (unaryOperationsMapIterator.hasNext()) {
|
||||
val (funcName, parameters) = unaryOperationsMapIterator.next()
|
||||
val (funcName, parameters, isFunction) = unaryOperationsMapIterator.next()
|
||||
val parenthesesOrBlank = "()" //if (isFunction) "()" else ""
|
||||
p.println(
|
||||
"unaryOperation(",
|
||||
parameters.map { it.asString() }.joinToString(", "),
|
||||
", ",
|
||||
"\"$funcName\"",
|
||||
", { a -> a.${funcName}() }, ",
|
||||
", { a -> a.$funcName$parenthesesOrBlank }, ",
|
||||
renderCheckUnaryOperation(funcName, parameters),
|
||||
")",
|
||||
if (unaryOperationsMapIterator.hasNext()) "," else ""
|
||||
@@ -159,7 +161,7 @@ private fun JetType.isIntegerType(): Boolean {
|
||||
}
|
||||
|
||||
|
||||
private fun FunctionDescriptor.getParametersTypes(): List<JetType> {
|
||||
private fun CallableDescriptor.getParametersTypes(): List<JetType> {
|
||||
val list = arrayListOf((getContainingDeclaration() as ClassDescriptor).getDefaultType())
|
||||
getValueParameters().map { it.getType() }.forEach {
|
||||
list.add(TypeUtils.makeNotNullable(it))
|
||||
|
||||
Reference in New Issue
Block a user