Add mechanism for type coercion in JS

Use it for char boxing/unboxing and unit materialization.
Possible to use for other purposes, for example, to add type checks
to dynamics.

See KT-18793, KT-17915, KT-19081, KT-18216, KT-12970, KT-17014,
KT-13932, KT-13930
This commit is contained in:
Alexey Andreev
2017-07-18 16:42:30 +03:00
parent ae509d5980
commit 37fa45dc34
63 changed files with 959 additions and 264 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.js.backend.ast.*
import org.jetbrains.kotlin.resolve.inline.InlineStrategy
import org.jetbrains.kotlin.types.KotlinType
var JsName.staticRef: JsNode? by MetadataProperty(default = null)
@@ -56,12 +57,16 @@ var JsParameter.hasDefaultValue: Boolean by MetadataProperty(default = false)
var JsInvocation.typeCheck: TypeCheck? by MetadataProperty(default = null)
var JsInvocation.boxing: Boolean by MetadataProperty(default = false)
var JsInvocation.boxing: BoxingKind by MetadataProperty(default = BoxingKind.NONE)
var JsVars.exportedPackage: String? by MetadataProperty(default = null)
var JsExpressionStatement.exportedTag: String? by MetadataProperty(default = null)
var JsExpression.type: KotlinType? by MetadataProperty(default = null)
var JsExpression.isUnit: Boolean by MetadataProperty(default = false)
/**
* For function and lambda bodies indicates what declaration corresponds to.
* When absent (`null`) on body of a named function, this function is from external JS module.
@@ -142,4 +147,10 @@ enum class SpecialFunction(val suggestedName: String) {
WRAP_FUNCTION("wrapFunction"),
TO_BOXED_CHAR("toBoxedChar"),
UNBOX_CHAR("unboxChar"),
}
enum class BoxingKind {
NONE,
BOXING,
UNBOXING
}