diff --git a/js/js.libraries/src/generated/org.khronos.webgl.kt b/js/js.libraries/src/generated/org.khronos.webgl.kt index b5ee523a10a..34e9181f2ed 100644 --- a/js/js.libraries/src/generated/org.khronos.webgl.kt +++ b/js/js.libraries/src/generated/org.khronos.webgl.kt @@ -567,10 +567,10 @@ native public open class ArrayBuffer(length: Int) : Transferable { } native public open class Int8Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Int8Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Int8Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -595,10 +595,10 @@ native public open class Int8Array : ArrayBufferView { } native public open class Uint8Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Uint8Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Uint8Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -623,10 +623,10 @@ native public open class Uint8Array : ArrayBufferView { } native public open class Uint8ClampedArray : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Uint8ClampedArray) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Uint8ClampedArray) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -651,10 +651,10 @@ native public open class Uint8ClampedArray : ArrayBufferView { } native public open class Int16Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Int16Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Int16Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -679,10 +679,10 @@ native public open class Int16Array : ArrayBufferView { } native public open class Uint16Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Uint16Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Uint16Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -707,10 +707,10 @@ native public open class Uint16Array : ArrayBufferView { } native public open class Int32Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Int32Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Int32Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -735,10 +735,10 @@ native public open class Int32Array : ArrayBufferView { } native public open class Uint32Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Uint32Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Uint32Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -763,10 +763,10 @@ native public open class Uint32Array : ArrayBufferView { } native public open class Float32Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Float32Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Float32Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl @@ -791,10 +791,10 @@ native public open class Float32Array : ArrayBufferView { } native public open class Float64Array : ArrayBufferView { - constructor(length: Int) : super() - constructor(array: Float64Array) : super() - constructor(array: Array) : super() - constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) : super() + constructor(length: Int) + constructor(array: Float64Array) + constructor(array: Array) + constructor(buffer: ArrayBuffer, byteOffset: Int = noImpl, length: Int = noImpl) var length: Int get() = noImpl set(value) = noImpl diff --git a/js/js.libraries/src/generated/org.w3c.dom.kt b/js/js.libraries/src/generated/org.w3c.dom.kt index f0a51271888..ea69ee53799 100644 --- a/js/js.libraries/src/generated/org.w3c.dom.kt +++ b/js/js.libraries/src/generated/org.w3c.dom.kt @@ -2996,8 +2996,8 @@ native public open class HitRegionOptions { } native public open class ImageData : ImageBitmapSource { - constructor(sw: Int, sh: Int) : super() - constructor(data: Uint8ClampedArray, sw: Int, sh: Int = noImpl) : super() + constructor(sw: Int, sh: Int) + constructor(data: Uint8ClampedArray, sw: Int, sh: Int = noImpl) var width: Int get() = noImpl set(value) = noImpl @@ -5086,8 +5086,8 @@ native public open class DOMRectInit { } native public open class DOMQuad { - constructor(p1: DOMPointInit = noImpl, p2: DOMPointInit = noImpl, p3: DOMPointInit = noImpl, p4: DOMPointInit = noImpl) : super() - constructor(rect: DOMRectInit = noImpl) : super() + constructor(p1: DOMPointInit = noImpl, p2: DOMPointInit = noImpl, p3: DOMPointInit = noImpl, p4: DOMPointInit = noImpl) + constructor(rect: DOMRectInit = noImpl) var p1: DOMPoint get() = noImpl set(value) = noImpl diff --git a/libraries/tools/idl2k/src/main/kotlin/gen.kt b/libraries/tools/idl2k/src/main/kotlin/gen.kt index f773fc631d3..83836c8af86 100644 --- a/libraries/tools/idl2k/src/main/kotlin/gen.kt +++ b/libraries/tools/idl2k/src/main/kotlin/gen.kt @@ -83,7 +83,7 @@ private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefini private fun InterfaceDefinition.mapAttributes(repository: Repository) = attributes.map { generateAttribute(!dictionary, repository, it) } private fun InterfaceDefinition.mapOperations(repository: Repository) = operations.flatMap { generateFunctions(repository, it) } private fun Constant.mapConstant(repository : Repository) = GenerateAttribute(name, mapType(repository, type), value, false, true, false, false, true) -private fun emptyConstructor() = ExtendedAttribute(null, "Constructor", emptyList()) +private val EMPTY_CONSTRUCTOR = ExtendedAttribute(null, "Constructor", emptyList()) fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateTraitOrClass { val superClasses = iface.superTypes @@ -93,7 +93,7 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT assert(superClasses.size() <= 1) { "Type ${iface.name} should have one or zero super classes but found ${superClasses.map { it.name }}" } val superClass = superClasses.singleOrNull() - val superConstructor = superClass?.findConstructors()?.firstOrNull() + val superConstructor = superClass?.findConstructors()?.firstOrNull() ?: EMPTY_CONSTRUCTOR val declaredConstructors = iface.findConstructors() val entityKind = resolveDefinitionKind(repository, iface, declaredConstructors) @@ -101,26 +101,27 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT val primaryConstructor = when { declaredConstructors.size() == 1 -> declaredConstructors.single() - declaredConstructors.isEmpty() && entityKind == GenerateDefinitionKind.CLASS -> emptyConstructor() + declaredConstructors.isEmpty() && entityKind == GenerateDefinitionKind.CLASS -> EMPTY_CONSTRUCTOR else -> declaredConstructors.firstOrNull { it.arguments.isEmpty() } } val secondaryConstructors = declaredConstructors.filter { it != primaryConstructor } - val primaryConstructorWithCall = if (primaryConstructor != null) { - val constructorAsFunction = generateConstructorAsFunction(repository, primaryConstructor) + val primaryConstructorWithCall = primaryConstructor?.let { constructor -> + val constructorAsFunction = generateConstructorAsFunction(repository, constructor) val superCall = when { - superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, superClass.name, superConstructor ?: emptyConstructor()) + superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, superClass.name, superConstructor) else -> null } - ConstructorWithSuperTypeCall(constructorAsFunction, primaryConstructor, superCall) - } else null + ConstructorWithSuperTypeCall(constructorAsFunction, constructor, superCall) + } val secondaryConstructorsWithCall = secondaryConstructors.map { secondaryConstructor -> val constructorAsFunction = generateConstructorAsFunction(repository, secondaryConstructor) val initCall = when { primaryConstructorWithCall != null -> superOrPrimaryConstructorCall(constructorAsFunction, "this", primaryConstructorWithCall.constructorAttribute) - else -> superOrPrimaryConstructorCall(constructorAsFunction, "super", superConstructor ?: emptyConstructor()) + superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, "super", superConstructor) + else -> null } ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor, initCall) diff --git a/libraries/tools/idl2k/src/main/kotlin/render.kt b/libraries/tools/idl2k/src/main/kotlin/render.kt index c3015f3e1f0..e7c142480d0 100644 --- a/libraries/tools/idl2k/src/main/kotlin/render.kt +++ b/libraries/tools/idl2k/src/main/kotlin/render.kt @@ -60,7 +60,7 @@ private fun Appendable.renderArgumentsDeclaration(args: List, append(it.initializer.replaceWrongConstants(it.type)) } } - }.joinTo(this, ", ") + }.joinTo(this, ", ", "(", ")") private fun renderCall(call: GenerateFunctionCall) = "${call.name.replaceKeywords()}(${call.arguments.map { it.replaceKeywords() }.join(", ")})" @@ -80,9 +80,9 @@ private fun Appendable.renderFunctionDeclaration(f: GenerateFunction, override: if (f.name in keywords) { append("native(\"${f.name}\") ") } - append("fun ${f.name.replaceKeywords()}(") + append("fun ${f.name.replaceKeywords()}") renderArgumentsDeclaration(f.arguments, override) - appendln("): ${f.returnType.render()} = noImpl") + appendln(": ${f.returnType.render()} = noImpl") } fun Appendable.render(allTypes: Map, typeNamesToUnions: Map>, iface: GenerateTraitOrClass, markerAnnotation: Boolean = false) { @@ -100,17 +100,13 @@ fun Appendable.render(allTypes: Map, typeNamesToUn append(iface.name) val primary = iface.primaryConstructor - if (primary != null) { - if (primary.constructor.arguments.isNotEmpty() || iface.secondaryConstructors.isNotEmpty()) { - append("(") - renderArgumentsDeclaration(primary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false) - append(")") - } + if (primary != null && (primary.constructor.arguments.isNotEmpty() || iface.secondaryConstructors.isNotEmpty())) { + renderArgumentsDeclaration(primary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false) } val superCallName = primary?.initTypeCall?.name val superTypesWithCalls = - listOf(primary?.initTypeCall).filterNotNull().map { renderCall(it) } + + (primary?.initTypeCall?.let { listOf(renderCall(it)) } ?: emptyList()) + iface.superTypes.filter { it != superCallName && it in allSuperTypesNames } + (typeNamesToUnions[iface.name] ?: emptyList()) @@ -122,9 +118,8 @@ fun Appendable.render(allTypes: Map, typeNamesToUn iface.secondaryConstructors.forEach { secondary -> indent(1) - append("constructor(") + append("constructor") renderArgumentsDeclaration(secondary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false) - append(")") if (secondary.initTypeCall != null) { append(" : ")