Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.ir.backend.js.export
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.serialization.js.ModuleKind
sealed class ExportedDeclaration
data class ExportedModule(
val name: String,
val moduleKind: ModuleKind,
val declarations: List
)
class ExportedNamespace(
val name: String,
val declarations: List,
) : ExportedDeclaration()
data class ExportedFunction(
val name: String,
val returnType: ExportedType,
val parameters: List,
val typeParameters: List = emptyList(),
val isMember: Boolean = false,
val isStatic: Boolean = false,
val isAbstract: Boolean = false,
val isProtected: Boolean,
val ir: IrSimpleFunction
) : ExportedDeclaration()
data class ExportedConstructor(
val parameters: List,
val visibility: ExportedVisibility
) : ExportedDeclaration() {
val isProtected: Boolean
get() = visibility == ExportedVisibility.PROTECTED
}
data class ExportedConstructSignature(
val parameters: List,
val returnType: ExportedType,
) : ExportedDeclaration()
class ExportedProperty(
val name: String,
val type: ExportedType,
val mutable: Boolean,
val isMember: Boolean = false,
val isStatic: Boolean = false,
val isAbstract: Boolean,
val isProtected: Boolean,
val isField: Boolean,
val irGetter: IrFunction?,
val irSetter: IrFunction?,
) : ExportedDeclaration()
// TODO: Cover all cases with frontend and disable error declarations
class ErrorDeclaration(val message: String) : ExportedDeclaration()
sealed class ExportedClass : ExportedDeclaration() {
abstract val name: String
abstract val ir: IrClass
abstract val members: List
abstract val superClass: ExportedType?
abstract val superInterfaces: List
abstract val nestedClasses: List
}
data class ExportedRegularClass(
override val name: String,
val isInterface: Boolean = false,
val isAbstract: Boolean = false,
override val superClass: ExportedType? = null,
override val superInterfaces: List = emptyList(),
val typeParameters: List,
override val members: List,
override val nestedClasses: List,
override val ir: IrClass,
) : ExportedClass()
data class ExportedObject(
override val name: String,
override val superClass: ExportedType? = null,
override val superInterfaces: List = emptyList(),
override val members: List,
override val nestedClasses: List,
override val ir: IrClass,
val irGetter: IrFunction
) : ExportedClass()
class ExportedParameter(
val name: String,
val type: ExportedType,
val hasDefaultValue: Boolean = false
)
sealed class ExportedType {
sealed class Primitive(val typescript: kotlin.String) : ExportedType() {
object Boolean : Primitive("boolean")
object Number : Primitive("number")
object ByteArray : Primitive("Int8Array")
object ShortArray : Primitive("Int16Array")
object IntArray : Primitive("Int32Array")
object FloatArray : Primitive("Float32Array")
object DoubleArray : Primitive("Float64Array")
object String : Primitive("string")
object Throwable : Primitive("Error")
object Any : Primitive("any")
object Unit : Primitive("void")
object Nothing : Primitive("never")
}
sealed class LiteralType(val value: T) : ExportedType() {
class StringLiteralType(value: String) : LiteralType(value)
class NumberLiteralType(value: Number) : LiteralType(value)
}
class Array(val elementType: ExportedType) : ExportedType()
class Function(
val parameterTypes: List,
val returnType: ExportedType
) : ExportedType()
class ClassType(val name: String, val arguments: List, val ir: IrClass) : ExportedType()
class TypeParameter(val name: String, val constraint: ExportedType? = null) : ExportedType()
class Nullable(val baseType: ExportedType) : ExportedType()
class ErrorType(val comment: String) : ExportedType()
class TypeOf(val name: String) : ExportedType()
class InlineInterfaceType(
val members: List
) : ExportedType()
class UnionType(val lhs: ExportedType, val rhs: ExportedType) : ExportedType()
class IntersectionType(val lhs: ExportedType, val rhs: ExportedType) : ExportedType()
class ImplicitlyExportedType(val type: ExportedType) : ExportedType() {
override fun withNullability(nullable: Boolean) =
ImplicitlyExportedType(type.withNullability(nullable))
}
open fun withNullability(nullable: Boolean) =
if (nullable) Nullable(this) else this
fun withImplicitlyExported(implicitlyExportedType: Boolean) =
if (implicitlyExportedType) ImplicitlyExportedType(this) else this
}
enum class ExportedVisibility(val keyword: String) {
DEFAULT(""),
PRIVATE("private "),
PROTECTED("protected ")
}