JS IDL2K better callbacks support + bugfixes according to review

This commit is contained in:
Sergey Mashkov
2015-05-13 15:03:11 +03:00
committed by Sergey Mashkov
parent a11e0a84b5
commit 0ce1edd417
26 changed files with 708 additions and 588 deletions
@@ -15,6 +15,7 @@ import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
@@ -77,7 +78,7 @@ native public trait WebGLShaderPrecisionFormat {
set(value) = noImpl
}
native public trait WebGLRenderingContext {
native public trait WebGLRenderingContext : RenderingContext {
var canvas: HTMLCanvasElement
get() = noImpl
set(value) = noImpl
@@ -89,7 +90,7 @@ native public trait WebGLRenderingContext {
set(value) = noImpl
fun getContextAttributes(): WebGLContextAttributes? = noImpl
fun isContextLost(): Boolean = noImpl
fun getSupportedExtensions(): Any? = noImpl
fun getSupportedExtensions(): Array<dynamic> = noImpl
fun getExtension(name: String): dynamic = noImpl
fun activeTexture(texture: Int): Unit = noImpl
fun attachShader(program: WebGLProgram?, shader: WebGLShader?): Unit = noImpl
@@ -113,8 +114,8 @@ native public trait WebGLRenderingContext {
fun clearStencil(s: Int): Unit = noImpl
fun colorMask(red: Boolean, green: Boolean, blue: Boolean, alpha: Boolean): Unit = noImpl
fun compileShader(shader: WebGLShader?): Unit = noImpl
fun compressedTexImage2D(target: Int, level: Int, internalformat: Int, width: Int, height: Int, border: Int, data: dynamic): Unit = noImpl
fun compressedTexSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, width: Int, height: Int, format: Int, data: dynamic): Unit = noImpl
fun compressedTexImage2D(target: Int, level: Int, internalformat: Int, width: Int, height: Int, border: Int, data: ArrayBufferView): Unit = noImpl
fun compressedTexSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, width: Int, height: Int, format: Int, data: ArrayBufferView): Unit = noImpl
fun copyTexImage2D(target: Int, level: Int, internalformat: Int, x: Int, y: Int, width: Int, height: Int, border: Int): Unit = noImpl
fun copyTexSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, x: Int, y: Int, width: Int, height: Int): Unit = noImpl
fun createBuffer(): WebGLBuffer? = noImpl
@@ -148,23 +149,23 @@ native public trait WebGLRenderingContext {
fun generateMipmap(target: Int): Unit = noImpl
fun getActiveAttrib(program: WebGLProgram?, index: Int): WebGLActiveInfo? = noImpl
fun getActiveUniform(program: WebGLProgram?, index: Int): WebGLActiveInfo? = noImpl
fun getAttachedShaders(program: WebGLProgram?): Any? = noImpl
fun getAttachedShaders(program: WebGLProgram?): Array<dynamic> = noImpl
fun getAttribLocation(program: WebGLProgram?, name: String): Int = noImpl
fun getBufferParameter(target: Int, pname: Int): Any? = noImpl
fun getParameter(pname: Int): Any? = noImpl
fun getBufferParameter(target: Int, pname: Int): dynamic = noImpl
fun getParameter(pname: Int): dynamic = noImpl
fun getError(): Int = noImpl
fun getFramebufferAttachmentParameter(target: Int, attachment: Int, pname: Int): Any? = noImpl
fun getProgramParameter(program: WebGLProgram?, pname: Int): Any? = noImpl
fun getFramebufferAttachmentParameter(target: Int, attachment: Int, pname: Int): dynamic = noImpl
fun getProgramParameter(program: WebGLProgram?, pname: Int): dynamic = noImpl
fun getProgramInfoLog(program: WebGLProgram?): String? = noImpl
fun getRenderbufferParameter(target: Int, pname: Int): Any? = noImpl
fun getShaderParameter(shader: WebGLShader?, pname: Int): Any? = noImpl
fun getRenderbufferParameter(target: Int, pname: Int): dynamic = noImpl
fun getShaderParameter(shader: WebGLShader?, pname: Int): dynamic = noImpl
fun getShaderPrecisionFormat(shadertype: Int, precisiontype: Int): WebGLShaderPrecisionFormat? = noImpl
fun getShaderInfoLog(shader: WebGLShader?): String? = noImpl
fun getShaderSource(shader: WebGLShader?): String? = noImpl
fun getTexParameter(target: Int, pname: Int): Any? = noImpl
fun getUniform(program: WebGLProgram?, location: WebGLUniformLocation?): Any? = noImpl
fun getTexParameter(target: Int, pname: Int): dynamic = noImpl
fun getUniform(program: WebGLProgram?, location: WebGLUniformLocation?): dynamic = noImpl
fun getUniformLocation(program: WebGLProgram?, name: String): WebGLUniformLocation? = noImpl
fun getVertexAttrib(index: Int, pname: Int): Any? = noImpl
fun getVertexAttrib(index: Int, pname: Int): dynamic = noImpl
fun getVertexAttribOffset(index: Int, pname: Int): Long = noImpl
fun hint(target: Int, mode: Int): Unit = noImpl
fun isBuffer(buffer: WebGLBuffer?): Boolean = noImpl
@@ -178,7 +179,7 @@ native public trait WebGLRenderingContext {
fun linkProgram(program: WebGLProgram?): Unit = noImpl
fun pixelStorei(pname: Int, param: Int): Unit = noImpl
fun polygonOffset(factor: Float, units: Float): Unit = noImpl
fun readPixels(x: Int, y: Int, width: Int, height: Int, format: Int, type: Int, pixels: dynamic): Unit = noImpl
fun readPixels(x: Int, y: Int, width: Int, height: Int, format: Int, type: Int, pixels: ArrayBufferView?): Unit = noImpl
fun renderbufferStorage(target: Int, internalformat: Int, width: Int, height: Int): Unit = noImpl
fun sampleCoverage(value: Float, invert: Boolean): Unit = noImpl
fun scissor(x: Int, y: Int, width: Int, height: Int): Unit = noImpl
@@ -189,56 +190,56 @@ native public trait WebGLRenderingContext {
fun stencilMaskSeparate(face: Int, mask: Int): Unit = noImpl
fun stencilOp(fail: Int, zfail: Int, zpass: Int): Unit = noImpl
fun stencilOpSeparate(face: Int, fail: Int, zfail: Int, zpass: Int): Unit = noImpl
fun texImage2D(target: Int, level: Int, internalformat: Int, width: Int, height: Int, border: Int, format: Int, type: Int, pixels: dynamic): Unit = noImpl
fun texImage2D(target: Int, level: Int, internalformat: Int, width: Int, height: Int, border: Int, format: Int, type: Int, pixels: ArrayBufferView?): Unit = noImpl
fun texImage2D(target: Int, level: Int, internalformat: Int, format: Int, type: Int, source: dynamic): Unit = noImpl
fun texParameterf(target: Int, pname: Int, param: Float): Unit = noImpl
fun texParameteri(target: Int, pname: Int, param: Int): Unit = noImpl
fun texSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, width: Int, height: Int, format: Int, type: Int, pixels: dynamic): Unit = noImpl
fun texSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, width: Int, height: Int, format: Int, type: Int, pixels: ArrayBufferView?): Unit = noImpl
fun texSubImage2D(target: Int, level: Int, xoffset: Int, yoffset: Int, format: Int, type: Int, source: dynamic): Unit = noImpl
fun uniform1f(location: WebGLUniformLocation?, x: Float): Unit = noImpl
fun uniform1fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl
fun uniform1fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform1fv(location: WebGLUniformLocation?, v: Array<Float>): Unit = noImpl
fun uniform1i(location: WebGLUniformLocation?, x: Int): Unit = noImpl
fun uniform1iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl
fun uniform1iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform1iv(location: WebGLUniformLocation?, v: Array<Int>): Unit = noImpl
fun uniform2f(location: WebGLUniformLocation?, x: Float, y: Float): Unit = noImpl
fun uniform2fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl
fun uniform2fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform2fv(location: WebGLUniformLocation?, v: Array<Float>): Unit = noImpl
fun uniform2i(location: WebGLUniformLocation?, x: Int, y: Int): Unit = noImpl
fun uniform2iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl
fun uniform2iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform2iv(location: WebGLUniformLocation?, v: Array<Int>): Unit = noImpl
fun uniform3f(location: WebGLUniformLocation?, x: Float, y: Float, z: Float): Unit = noImpl
fun uniform3fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl
fun uniform3fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform3fv(location: WebGLUniformLocation?, v: Array<Float>): Unit = noImpl
fun uniform3i(location: WebGLUniformLocation?, x: Int, y: Int, z: Int): Unit = noImpl
fun uniform3iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl
fun uniform3iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform3iv(location: WebGLUniformLocation?, v: Array<Int>): Unit = noImpl
fun uniform4f(location: WebGLUniformLocation?, x: Float, y: Float, z: Float, w: Float): Unit = noImpl
fun uniform4fv(location: WebGLUniformLocation?, v: Float32Array): Unit = noImpl
fun uniform4fv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform4fv(location: WebGLUniformLocation?, v: Array<Float>): Unit = noImpl
fun uniform4i(location: WebGLUniformLocation?, x: Int, y: Int, z: Int, w: Int): Unit = noImpl
fun uniform4iv(location: WebGLUniformLocation?, v: Int32Array): Unit = noImpl
fun uniform4iv(location: WebGLUniformLocation?, v: Any): Unit = noImpl
fun uniform4iv(location: WebGLUniformLocation?, v: Array<Int>): Unit = noImpl
fun uniformMatrix2fv(location: WebGLUniformLocation?, transpose: Boolean, value: Float32Array): Unit = noImpl
fun uniformMatrix2fv(location: WebGLUniformLocation?, transpose: Boolean, value: Any): Unit = noImpl
fun uniformMatrix2fv(location: WebGLUniformLocation?, transpose: Boolean, value: Array<Float>): Unit = noImpl
fun uniformMatrix3fv(location: WebGLUniformLocation?, transpose: Boolean, value: Float32Array): Unit = noImpl
fun uniformMatrix3fv(location: WebGLUniformLocation?, transpose: Boolean, value: Any): Unit = noImpl
fun uniformMatrix3fv(location: WebGLUniformLocation?, transpose: Boolean, value: Array<Float>): Unit = noImpl
fun uniformMatrix4fv(location: WebGLUniformLocation?, transpose: Boolean, value: Float32Array): Unit = noImpl
fun uniformMatrix4fv(location: WebGLUniformLocation?, transpose: Boolean, value: Any): Unit = noImpl
fun uniformMatrix4fv(location: WebGLUniformLocation?, transpose: Boolean, value: Array<Float>): Unit = noImpl
fun useProgram(program: WebGLProgram?): Unit = noImpl
fun validateProgram(program: WebGLProgram?): Unit = noImpl
fun vertexAttrib1f(indx: Int, x: Float): Unit = noImpl
fun vertexAttrib1fv(indx: Int, values: Float32Array): Unit = noImpl
fun vertexAttrib1fv(indx: Int, values: Any): Unit = noImpl
fun vertexAttrib1fv(indx: Int, values: Array<Float>): Unit = noImpl
fun vertexAttrib2f(indx: Int, x: Float, y: Float): Unit = noImpl
fun vertexAttrib2fv(indx: Int, values: Float32Array): Unit = noImpl
fun vertexAttrib2fv(indx: Int, values: Any): Unit = noImpl
fun vertexAttrib2fv(indx: Int, values: Array<Float>): Unit = noImpl
fun vertexAttrib3f(indx: Int, x: Float, y: Float, z: Float): Unit = noImpl
fun vertexAttrib3fv(indx: Int, values: Float32Array): Unit = noImpl
fun vertexAttrib3fv(indx: Int, values: Any): Unit = noImpl
fun vertexAttrib3fv(indx: Int, values: Array<Float>): Unit = noImpl
fun vertexAttrib4f(indx: Int, x: Float, y: Float, z: Float, w: Float): Unit = noImpl
fun vertexAttrib4fv(indx: Int, values: Float32Array): Unit = noImpl
fun vertexAttrib4fv(indx: Int, values: Any): Unit = noImpl
fun vertexAttrib4fv(indx: Int, values: Array<Float>): Unit = noImpl
fun vertexAttribPointer(indx: Int, size: Int, type: Int, normalized: Boolean, stride: Int, offset: Long): Unit = noImpl
fun viewport(x: Int, y: Int, width: Int, height: Int): Unit = noImpl
@@ -553,14 +554,14 @@ native public open class WebGLContextEventInit : EventInit() {
var statusMessage: String
}
native public open class ArrayBuffer(length: Int) {
native public open class ArrayBuffer(length: Int) : Transferable {
var byteLength: Int
get() = noImpl
set(value) = noImpl
fun slice(begin: Int, end: Int = noImpl): ArrayBuffer = noImpl
}
native public open class Int8Array(length: Int) {
native public open class Int8Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -576,7 +577,7 @@ native public open class Int8Array(length: Int) {
fun get(index: Int): Byte = noImpl
fun set(index: Int, value: Byte): Unit = noImpl
fun set(array: Int8Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Byte>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Int8Array = noImpl
companion object {
@@ -584,7 +585,7 @@ native public open class Int8Array(length: Int) {
}
}
native public open class Uint8Array(length: Int) {
native public open class Uint8Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -600,7 +601,7 @@ native public open class Uint8Array(length: Int) {
fun get(index: Int): Byte = noImpl
fun set(index: Int, value: Byte): Unit = noImpl
fun set(array: Uint8Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Byte>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Uint8Array = noImpl
companion object {
@@ -608,7 +609,7 @@ native public open class Uint8Array(length: Int) {
}
}
native public open class Uint8ClampedArray(length: Int) {
native public open class Uint8ClampedArray(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -624,7 +625,7 @@ native public open class Uint8ClampedArray(length: Int) {
fun get(index: Int): Byte = noImpl
fun set(index: Int, value: Byte): Unit = noImpl
fun set(array: Uint8ClampedArray, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Byte>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Uint8ClampedArray = noImpl
companion object {
@@ -632,7 +633,7 @@ native public open class Uint8ClampedArray(length: Int) {
}
}
native public open class Int16Array(length: Int) {
native public open class Int16Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -648,7 +649,7 @@ native public open class Int16Array(length: Int) {
fun get(index: Int): Short = noImpl
fun set(index: Int, value: Short): Unit = noImpl
fun set(array: Int16Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Short>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Int16Array = noImpl
companion object {
@@ -656,7 +657,7 @@ native public open class Int16Array(length: Int) {
}
}
native public open class Uint16Array(length: Int) {
native public open class Uint16Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -672,7 +673,7 @@ native public open class Uint16Array(length: Int) {
fun get(index: Int): Short = noImpl
fun set(index: Int, value: Short): Unit = noImpl
fun set(array: Uint16Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Short>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Uint16Array = noImpl
companion object {
@@ -680,7 +681,7 @@ native public open class Uint16Array(length: Int) {
}
}
native public open class Int32Array(length: Int) {
native public open class Int32Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -696,7 +697,7 @@ native public open class Int32Array(length: Int) {
fun get(index: Int): Int = noImpl
fun set(index: Int, value: Int): Unit = noImpl
fun set(array: Int32Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Int>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Int32Array = noImpl
companion object {
@@ -704,7 +705,7 @@ native public open class Int32Array(length: Int) {
}
}
native public open class Uint32Array(length: Int) {
native public open class Uint32Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -720,7 +721,7 @@ native public open class Uint32Array(length: Int) {
fun get(index: Int): Int = noImpl
fun set(index: Int, value: Int): Unit = noImpl
fun set(array: Uint32Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Int>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Uint32Array = noImpl
companion object {
@@ -728,7 +729,7 @@ native public open class Uint32Array(length: Int) {
}
}
native public open class Float32Array(length: Int) {
native public open class Float32Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -744,7 +745,7 @@ native public open class Float32Array(length: Int) {
fun get(index: Int): Float = noImpl
fun set(index: Int, value: Float): Unit = noImpl
fun set(array: Float32Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Float>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Float32Array = noImpl
companion object {
@@ -752,7 +753,7 @@ native public open class Float32Array(length: Int) {
}
}
native public open class Float64Array(length: Int) {
native public open class Float64Array(length: Int) : ArrayBufferView {
var length: Int
get() = noImpl
set(value) = noImpl
@@ -768,7 +769,7 @@ native public open class Float64Array(length: Int) {
fun get(index: Int): Double = noImpl
fun set(index: Int, value: Double): Unit = noImpl
fun set(array: Float64Array, offset: Int = noImpl): Unit = noImpl
fun set(array: dynamic, offset: Int = noImpl): Unit = noImpl
fun set(array: Array<Double>, offset: Int = noImpl): Unit = noImpl
fun subarray(start: Int, end: Int): Float64Array = noImpl
companion object {
@@ -776,7 +777,7 @@ native public open class Float64Array(length: Int) {
}
}
native public open class DataView(buffer: ArrayBuffer, byteOffset: Int = noImpl, byteLength: Int = noImpl) {
native public open class DataView(buffer: ArrayBuffer, byteOffset: Int = noImpl, byteLength: Int = noImpl) : ArrayBufferView {
var buffer: ArrayBuffer
get() = noImpl
set(value) = noImpl
@@ -15,6 +15,7 @@ import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
@@ -444,7 +445,7 @@ native public trait CSSStyleDeclaration {
var flexWrap: String
get() = noImpl
set(value) = noImpl
var attribute: String
var cssFloat: String
get() = noImpl
set(value) = noImpl
var font: String
@@ -852,9 +853,6 @@ native public trait CSSStyleDeclaration {
var parentRule: CSSRule?
get() = noImpl
set(value) = noImpl
var cssFloat: String
get() = noImpl
set(value) = noImpl
var _dashed_attribute: String
get() = noImpl
set(value) = noImpl
@@ -15,6 +15,7 @@ import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
File diff suppressed because it is too large Load Diff
@@ -15,6 +15,7 @@ import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
@@ -15,6 +15,7 @@ import org.w3c.dom.parsing.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
@@ -15,6 +15,7 @@ import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
@@ -22,7 +23,7 @@ native public open class Headers(init: dynamic = noImpl) {
fun append(name: String, value: String): Unit = noImpl
fun delete(name: String): Unit = noImpl
fun get(name: String): String? = noImpl
fun getAll(name: String): Any = noImpl
fun getAll(name: String): Array<String> = noImpl
fun has(name: String): Boolean = noImpl
fun set(name: String, value: String): Unit = noImpl
}
@@ -15,10 +15,11 @@ import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
native public open class Blob {
native public open class Blob : ImageBitmapSource {
var size: Long
get() = noImpl
set(value) = noImpl
@@ -36,7 +37,7 @@ native public open class BlobPropertyBag {
var type: String = ""
}
native public open class File(fileBits: Any, fileName: String, options: FilePropertyBag = noImpl) : Blob() {
native public open class File(fileBits: Array<dynamic>, fileName: String, options: FilePropertyBag = noImpl) : Blob() {
var name: String
get() = noImpl
set(value) = noImpl
@@ -68,22 +69,22 @@ native public open class FileReader : EventTarget {
var error: dynamic
get() = noImpl
set(value) = noImpl
var onloadstart: (Event) -> Unit
var onloadstart: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onprogress: (Event) -> Unit
var onprogress: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onload: (Event) -> Unit
var onload: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onabort: (Event) -> Unit
var onabort: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onerror: (Event) -> Unit
var onerror: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onloadend: (Event) -> Unit
var onloadend: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
fun readAsArrayBuffer(blob: Blob): Unit = noImpl
@@ -15,6 +15,7 @@ import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.time.*
import org.w3c.workers.*
import org.w3c.xhr.*
@@ -22,10 +23,10 @@ native public open class Notification(title: String, options: NotificationOption
var permission: String
get() = noImpl
set(value) = noImpl
var onclick: (Event) -> Unit
var onclick: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onerror: (Event) -> Unit
var onerror: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var title: String
@@ -61,7 +62,7 @@ native public open class Notification(title: String, options: NotificationOption
var sticky: Boolean
get() = noImpl
set(value) = noImpl
var data: Any?
var data: dynamic
get() = noImpl
set(value) = noImpl
fun close(): Unit = noImpl
@@ -79,10 +80,7 @@ native public open class NotificationOptions {
var silent: Boolean = false
var noscreen: Boolean = false
var sticky: Boolean = false
var data: Any? = null
}
native public trait NotificationPermissionCallback {
var data: dynamic = null
}
native public open class GetNotificationOptions {
@@ -0,0 +1,25 @@
/*
* Generated file
* DO NOT EDIT
*
* See libraries/tools/idl2k for details
*/
package org.w3c.time
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.css.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.workers.*
import org.w3c.xhr.*
native public trait Performance {
fun now(): Double = noImpl
}
@@ -16,6 +16,7 @@ import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.xhr.*
native public trait ServiceWorkerRegistration : EventTarget {
@@ -31,7 +32,7 @@ native public trait ServiceWorkerRegistration : EventTarget {
var scope: String
get() = noImpl
set(value) = noImpl
var onupdatefound: (Event) -> Unit
var onupdatefound: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var APISpace: dynamic
@@ -51,22 +52,22 @@ native public trait ServiceWorkerGlobalScope : WorkerGlobalScope {
var registration: ServiceWorkerRegistration
get() = noImpl
set(value) = noImpl
var oninstall: (Event) -> Unit
var oninstall: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onactivate: (Event) -> Unit
var onactivate: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onfetch: (Event) -> Unit
var onfetch: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onmessage: (Event) -> Unit
var onmessage: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onfunctionalevent: (Event) -> Unit
var onfunctionalevent: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onnotificationclick: (Event) -> Unit
var onnotificationclick: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
fun skipWaiting(): dynamic = noImpl
@@ -82,13 +83,13 @@ native public trait ServiceWorker : EventTarget, UnionMessagePortOrServiceWorker
var id: String
get() = noImpl
set(value) = noImpl
var onstatechange: (Event) -> Unit
var onstatechange: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onerror: (Event) -> Unit
var onerror: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
fun postMessage(message: Any?, transfer: Any = noImpl): Unit = noImpl
fun postMessage(message: dynamic, transfer: Array<Transferable> = noImpl): Unit = noImpl
}
native public trait ServiceWorkerContainer : EventTarget {
@@ -98,13 +99,13 @@ native public trait ServiceWorkerContainer : EventTarget {
var ready: dynamic
get() = noImpl
set(value) = noImpl
var oncontrollerchange: (Event) -> Unit
var oncontrollerchange: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onerror: (Event) -> Unit
var onerror: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onmessage: (Event) -> Unit
var onmessage: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
fun register(scriptURL: String, options: RegistrationOptions = noImpl): dynamic = noImpl
@@ -117,7 +118,7 @@ native public open class RegistrationOptions {
}
native public open class ServiceWorkerMessageEvent(type: String, eventInitDict: ServiceWorkerMessageEventInit = noImpl) : Event(type, eventInitDict) {
var data: Any?
var data: dynamic
get() = noImpl
set(value) = noImpl
var origin: String
@@ -129,18 +130,18 @@ native public open class ServiceWorkerMessageEvent(type: String, eventInitDict:
var source: UnionMessagePortOrServiceWorker?
get() = noImpl
set(value) = noImpl
var ports: dynamic
var ports: Array<dynamic>
get() = noImpl
set(value) = noImpl
fun initServiceWorkerMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: Any?, originArg: String, lastEventIdArg: String, sourceArg: UnionMessagePortOrServiceWorker, portsArg: Any?): Unit = noImpl
fun initServiceWorkerMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: dynamic, originArg: String, lastEventIdArg: String, sourceArg: UnionMessagePortOrServiceWorker, portsArg: Array<dynamic>): Unit = noImpl
}
native public open class ServiceWorkerMessageEventInit : EventInit() {
var data: Any?
var data: dynamic
var origin: String
var lastEventId: String
var source: UnionMessagePortOrServiceWorker?
var ports: Any
var ports: Array<MessagePort>
}
native public trait Client : UnionClientOrMessagePortOrServiceWorker {
@@ -153,7 +154,7 @@ native public trait Client : UnionClientOrMessagePortOrServiceWorker {
var id: String
get() = noImpl
set(value) = noImpl
fun postMessage(message: Any?, transfer: Any = noImpl): Unit = noImpl
fun postMessage(message: dynamic, transfer: Array<Transferable> = noImpl): Unit = noImpl
}
native public trait WindowClient : Client {
@@ -204,7 +205,7 @@ native public open class FetchEventInit : ExtendableEventInit() {
}
native public open class ExtendableMessageEvent(type: String, eventInitDict: ExtendableMessageEventInit = noImpl) : ExtendableEvent(type, eventInitDict) {
var data: Any?
var data: dynamic
get() = noImpl
set(value) = noImpl
var origin: String
@@ -216,25 +217,25 @@ native public open class ExtendableMessageEvent(type: String, eventInitDict: Ext
var source: UnionClientOrMessagePortOrServiceWorker?
get() = noImpl
set(value) = noImpl
var ports: dynamic
var ports: Array<dynamic>
get() = noImpl
set(value) = noImpl
fun initExtendableMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: Any?, originArg: String, lastEventIdArg: String, sourceArg: UnionClientOrMessagePortOrServiceWorker, portsArg: Any?): Unit = noImpl
fun initExtendableMessageEvent(typeArg: String, canBubbleArg: Boolean, cancelableArg: Boolean, dataArg: dynamic, originArg: String, lastEventIdArg: String, sourceArg: UnionClientOrMessagePortOrServiceWorker, portsArg: Array<dynamic>): Unit = noImpl
}
native public open class ExtendableMessageEventInit : ExtendableEventInit() {
var data: Any?
var data: dynamic
var origin: String
var lastEventId: String
var source: UnionClientOrMessagePortOrServiceWorker?
var ports: Any
var ports: Array<MessagePort>
}
native public trait Cache {
fun match(request: dynamic, options: CacheQueryOptions = noImpl): dynamic = noImpl
fun matchAll(request: dynamic = noImpl, options: CacheQueryOptions = noImpl): dynamic = noImpl
fun add(request: dynamic): dynamic = noImpl
fun addAll(requests: Any): dynamic = noImpl
fun addAll(requests: Array<dynamic>): dynamic = noImpl
fun put(request: dynamic, response: Response): dynamic = noImpl
fun delete(request: dynamic, options: CacheQueryOptions = noImpl): dynamic = noImpl
fun keys(request: dynamic = noImpl, options: CacheQueryOptions = noImpl): dynamic = noImpl
+11 -10
View File
@@ -16,28 +16,29 @@ import org.w3c.dom.svg.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.time.*
import org.w3c.workers.*
native public trait XMLHttpRequestEventTarget : EventTarget {
var onloadstart: (Event) -> Unit
var onloadstart: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onprogress: (Event) -> Unit
var onprogress: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onabort: (Event) -> Unit
var onabort: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onerror: (Event) -> Unit
var onerror: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onload: (Event) -> Unit
var onload: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var ontimeout: (Event) -> Unit
var ontimeout: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var onloadend: (Event) -> Unit
var onloadend: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
}
@@ -46,7 +47,7 @@ native public trait XMLHttpRequestUpload : XMLHttpRequestEventTarget {
}
native public open class XMLHttpRequest : XMLHttpRequestEventTarget {
var onreadystatechange: (Event) -> Unit
var onreadystatechange: ((Event) -> dynamic)?
get() = noImpl
set(value) = noImpl
var readyState: Short
@@ -73,7 +74,7 @@ native public open class XMLHttpRequest : XMLHttpRequestEventTarget {
var responseType: String
get() = noImpl
set(value) = noImpl
var response: Any?
var response: dynamic
get() = noImpl
set(value) = noImpl
var responseText: String
@@ -104,7 +105,7 @@ native public open class FormData(form: HTMLFormElement = noImpl) {
fun append(name: String, value: dynamic): Unit = noImpl
fun delete(name: String): Unit = noImpl
fun get(name: String): dynamic = noImpl
fun getAll(name: String): Any = noImpl
fun getAll(name: String): Array<dynamic> = noImpl
fun has(name: String): Boolean = noImpl
fun set(name: String, value: dynamic): Unit = noImpl
}
+1 -1
View File
@@ -93,7 +93,7 @@ partial interface CSSStyleDeclaration {
attribute String flexGrow;
attribute String flexShrink;
attribute String flexWrap;
attribute String float;
attribute String cssFloat;
attribute String font;
attribute String fontFamily;
attribute String fontFeatureSettings;
+6
View File
@@ -5100,4 +5100,10 @@ dictionary EditingInputEventInit : EventInit {
DOMString command;
DOMString value;
};
partial interface Window {
long requestAnimationFrame(FrameRequestCallback callback);
void cancelAnimationFrame(long handle);
};
callback FrameRequestCallback = void (DOMHighResTimeStamp time);
+8
View File
@@ -0,0 +1,8 @@
namespace org.w3c.time;
typedef double DOMHighResTimeStamp;
partial interface Performance {
DOMHighResTimeStamp now();
};
+7
View File
@@ -0,0 +1,7 @@
namespace org.w3c.webidl;
/** written by WebIDL spec */
typedef unsigned long long DOMTimeStamp;
callback Function = any (any... arguments);
callback VoidFunction = void ();
+1 -1
View File
@@ -170,7 +170,7 @@ public fun Element.addClass(vararg cssClasses: String): Boolean {
val presentClasses = classes.trim()
classes = StringBuilder {
append(presentClasses)
if (presentClasses != "") {
if (!presentClasses.isEmpty()) {
append(" ")
}
missingClasses.joinTo(this, " ")
@@ -74,7 +74,7 @@ definition
;
module
: 'module' IDENTIFIER_WEBIDL '{' definitions '}' ';'?
: 'module' IDENTIFIER_WEBIDL '{' definitions '}' ';'
;
callbackOrInterface
@@ -23,11 +23,14 @@ import java.io.File
import java.net.URL
val urls = listOf(
// "http://heycam.github.io/webidl/" to "org.w3c.webidl"
"https://raw.githubusercontent.com/whatwg/html-mirror/master/source" to "org.w3c.dom",
"https://html.spec.whatwg.org/" to "org.w3c.dom",
"https://raw.githubusercontent.com/whatwg/dom/master/dom.html" to "org.w3c.dom",
"http://www.w3.org/TR/uievents/" to "org.w3c.dom.events",
"https://dvcs.w3.org/hg/editing/raw-file/tip/editing.html" to "org.w3c.dom",
"http://www.w3.org/TR/animation-timing/" to "org.w3c.dom",
"http://www.w3.org/TR/hr-time/" to "org.w3c.time",
"https://raw.githubusercontent.com/whatwg/xhr/master/Overview.src.html" to "org.w3c.xhr",
"https://raw.githubusercontent.com/w3c/FileAPI/gh-pages/index.html" to "org.w3c.files",
"https://raw.githubusercontent.com/whatwg/notifications/master/notifications.html" to "org.w3c.notifications",
+38 -10
View File
@@ -10,21 +10,24 @@ private fun Operation.getterOrSetter() = this.attributes.map { it.call }.toSet()
}
}
fun String.isNullable() = endsWith(")?") || (endsWith("?") && !contains("->"))
fun String.ensureNullable() = when {
endsWith("?") -> this
this == "dynamic" -> this
isNullable() -> this
contains("->") -> "($this)?"
else -> "$this?"
}
fun String.dropNullable() = when {
endsWith(")?") -> this.removeSuffix("?").removeSurrounding("(", ")")
contains("->") -> this
endsWith("?") -> this.removeSuffix("?")
else -> this
}
fun String.copyNullabilityFrom(type : String) = when {
type.endsWith("?") -> ensureNullable()
type.isNullable() -> ensureNullable()
else -> this
}
@@ -32,7 +35,7 @@ fun generateFunction(repository: Repository, function: Operation, functionName:
function.attributes.map { it.call }.toSet().let { attributes ->
GenerateFunction(
name = functionName,
returnType = mapType(repository, function.returnType).let { mapped -> if (nativeGetterOrSetter != NativeGetterOrSetter.NONE) mapped.ensureNullable() else mapped },
returnType = mapType(repository, function.returnType).let { mapped -> if (nativeGetterOrSetter == NativeGetterOrSetter.GETTER) mapped.ensureNullable() else mapped },
arguments = function.parameters.map {
GenerateAttribute(
name = it.name,
@@ -59,9 +62,11 @@ fun generateFunctions(repository: Repository, function: Operation): List<Generat
val interfaceType = repository.interfaces[it.type.dropNullable()]
when {
interfaceType == null -> it
interfaceType.operations.size() != 1 -> it
interfaceType.callback -> interfaceType.operations.single().let { callbackFunction ->
it.copy(type = callbackFunction.parameters
.map { mapType(repository, it.type) }
.map { it.copy(type = mapType(repository, it.type)) }
.map { it.formatFunctionTypePart() }
.join(",", "(", ") -> ${mapType(repository, callbackFunction.returnType)}")
.copyNullabilityFrom(it.type))
}
@@ -71,7 +76,8 @@ fun generateFunctions(repository: Repository, function: Operation): List<Generat
val functionWithCallbackOrNull = when {
callbackArgumentsAsLambdas == function.parameters -> null
else -> generateFunction(repository, function.copy(parameters = callbackArgumentsAsLambdas), function.name, NativeGetterOrSetter.NONE)
realFunction != null -> generateFunction(repository, function.copy(parameters = callbackArgumentsAsLambdas), function.name, NativeGetterOrSetter.NONE)
else -> null
}
return listOf(realFunction, getterOrSetterFunction, functionWithCallbackOrNull).filterNotNull()
@@ -88,8 +94,8 @@ fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Att
)
private fun InterfaceDefinition.superTypes(repository: Repository) = superTypes.map { repository.interfaces[it] }.filterNotNull()
private fun resolveDefinitionType(repository: Repository, iface: InterfaceDefinition, constructor: ExtendedAttribute? = iface.findConstructor()): GenerateDefinitionKind =
if (iface.dictionary || constructor != null || iface.superTypes(repository).any { resolveDefinitionType(repository, it) == GenerateDefinitionKind.CLASS }) {
private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefinition, constructor: ExtendedAttribute? = iface.findConstructor()): GenerateDefinitionKind =
if (iface.dictionary || constructor != null || iface.superTypes(repository).any { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS }) {
GenerateDefinitionKind.CLASS
}
else {
@@ -108,7 +114,7 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
val constructorSuperCalls = iface.superTypes
.map { repository.interfaces[it] }
.filterNotNull()
.filter { resolveDefinitionType(repository, it) == GenerateDefinitionKind.CLASS }
.filter { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS }
.map {
val superConstructor = it.findConstructor()
GenerateFunctionCall(
@@ -123,10 +129,10 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
)
}
val entityType = resolveDefinitionType(repository, iface, constructor)
val entityKind = resolveDefinitionKind(repository, iface, constructor)
val extensions = repository.externals[iface.name]?.map { repository.interfaces[it] }?.filterNotNull() ?: emptyList()
return GenerateTraitOrClass(iface.name, iface.namespace, entityType, iface.superTypes,
return GenerateTraitOrClass(iface.name, iface.namespace, entityKind, iface.superTypes,
memberAttributes = (iface.mapAttributes(repository) + extensions.flatMap { it.mapAttributes(repository) }).distinct().toList(),
memberFunctions = (iface.mapOperations(repository) + extensions.flatMap { it.mapOperations(repository) }).distinct().toList(),
constants = (iface.constants.map {it.mapConstant(repository)} + extensions.flatMap { it.constants.map {it.mapConstant(repository)} }.distinct().toList()),
@@ -151,3 +157,25 @@ fun generateUnionTypeTraits(allUnionTypes : Iterable<UnionType>): List<GenerateT
fun mapDefinitions(repository: Repository, definitions: Iterable<InterfaceDefinition>) =
definitions.filter { "NoInterfaceObject" !in it.extendedAttributes.map { it.call } }.map { generateTrait(repository, it) }
fun generateUnions(ifaces: List<GenerateTraitOrClass>, typedefs: Iterable<TypedefDefinition>) : GenerateUnionTypes {
val declaredTypes = ifaces.toMap { it.name }
val anonymousUnionTypes = collectUnionTypes(declaredTypes)
val anonymousUnionTypeTraits = generateUnionTypeTraits(anonymousUnionTypes)
val anonymousUnionsMap = anonymousUnionTypeTraits.toMap { it.name }
val typedefsToBeGenerated = typedefs.filter { it.types.startsWith("Union<") }
.map { NamedValue(it.name, UnionType(it.namespace, splitUnionType(it.types))) }
.filter { it.value.memberTypes.all { type -> type in declaredTypes } }
val typedefsMarkersMap = typedefsToBeGenerated.groupBy { it.name }.mapValues { mapUnionType(it.value.first().value).copy(name = it.key) }
val typeNamesToUnions = anonymousUnionTypes.flatMap { unionType -> unionType.memberTypes.map { unionMember -> unionMember to unionType.name } }.toMultiMap() +
typedefsToBeGenerated.flatMap { typedef -> typedef.value.memberTypes.map { unionMember -> unionMember to typedef.name } }.toMultiMap()
return GenerateUnionTypes(
typeNamesToUnions = typeNamesToUnions,
anonymousUnionsMap = anonymousUnionsMap,
typedefsMarkersMap = typedefsMarkersMap
)
}
+45 -50
View File
@@ -29,10 +29,12 @@ import java.util.ArrayList
data class ExtendedAttribute(val name: String?, val call: String, val arguments: List<Attribute>)
data class Operation(val name: String, val returnType: String, val parameters: List<Attribute>, val attributes: List<ExtendedAttribute>)
data class Attribute(val name: String, val type: String, val readOnly: Boolean, val defaultValue: String? = null, val vararg: Boolean)
data class Attribute(val name: String, val type: String, val readOnly: Boolean = true, val defaultValue: String? = null, val vararg: Boolean)
data class Constant(val name: String, val type: String, val value: String?)
enum class DefinitionType {
fun Attribute.formatFunctionTypePart() = if (vararg) "vararg $type" else type
enum class DefinitionKind {
INTERFACE
TYPEDEF
EXTENSION_INTERFACE
@@ -75,6 +77,10 @@ class ExtendedAttributeArgumentsParser : WebIDLBaseVisitor<List<Attribute>>() {
}
}
// [Constructor]
// [Constructor(any, Int)]
// [Constructor(Int arg, String arg2 = "a")]
// [name = Constructor]
class ExtendedAttributeParser : WebIDLBaseVisitor<ExtendedAttribute>() {
private var name: String? = null
private var call: String = ""
@@ -150,7 +156,7 @@ class TypeVisitor : WebIDLBaseVisitor<String>() {
}
}
class OperationVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisitor<Operation>() {
class OperationVisitor(private val attributes: List<ExtendedAttribute>) : WebIDLBaseVisitor<Operation>() {
private var name: String = ""
private var returnType: String = ""
private val parameters = ArrayList<Attribute>()
@@ -177,7 +183,7 @@ class OperationVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisi
}
override fun visitOptionalOrRequiredArgument(ctx: WebIDLParser.OptionalOrRequiredArgumentContext): Operation {
val attributeVisitor = AttributeVisitor(false)
val attributeVisitor = AttributeVisitor()
attributeVisitor.visit(ctx)
val parameter = attributeVisitor.visitChildren(ctx)
@@ -187,11 +193,11 @@ class OperationVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisi
}
}
class AttributeVisitor(val readOnly: Boolean) : WebIDLBaseVisitor<Attribute>() {
var type: String = ""
var name: String = ""
var defaultValue: String? = null
var vararg: Boolean = false
class AttributeVisitor(private val readOnly: Boolean = false) : WebIDLBaseVisitor<Attribute>() {
private var type: String = ""
private var name: String = ""
private var defaultValue: String? = null
private var vararg: Boolean = false
override fun defaultResult(): Attribute = Attribute(name, type, readOnly, defaultValue, vararg)
@@ -208,20 +214,12 @@ class AttributeVisitor(val readOnly: Boolean) : WebIDLBaseVisitor<Attribute>() {
}
override fun visitAttributeRest(ctx: WebIDLParser.AttributeRestContext): Attribute {
try {
name = getName(ctx)
} catch (ignore: Throwable) {
name = ctx.children.filter { it is TerminalNode }.filter { it.getText() != ";" }.last().getText()
}
name = getNameOrNull(ctx) ?: ctx.children.filter { it is TerminalNode }.filter { it.getText() != ";" }.last().getText()
return defaultResult()
}
override fun visitArgumentName(ctx: WebIDLParser.ArgumentNameContext): Attribute {
try {
name = getName(ctx)
} catch (ignore: Throwable) {
name = ctx.getText()
}
name = getNameOrNull(ctx) ?: ctx.getText()
return defaultResult()
}
@@ -236,10 +234,10 @@ class AttributeVisitor(val readOnly: Boolean) : WebIDLBaseVisitor<Attribute>() {
}
}
class ConstantVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisitor<Constant>() {
var type: String = ""
var name: String = ""
var value: String? = null
class ConstantVisitor : WebIDLBaseVisitor<Constant>() {
private var type: String = ""
private var name: String = ""
private var value: String? = null
override fun defaultResult(): Constant = Constant(name, type, value)
@@ -260,8 +258,8 @@ class ConstantVisitor(val attributes: List<ExtendedAttribute>) : WebIDLBaseVisit
}
}
class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val namespace: String, val declarations : MutableList<Definition>) : WebIDLBaseVisitor<Definition>() {
private var type: DefinitionType = DefinitionType.INTERFACE
class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val namespace: String, val declarations: MutableList<Definition>) : WebIDLBaseVisitor<Definition>() {
private var kind: DefinitionKind = DefinitionKind.INTERFACE
private var name = ""
private val memberAttributes = ArrayList<ExtendedAttribute>()
private val operations = ArrayList<Operation>()
@@ -274,12 +272,12 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
private var partial = false
private var callback = false
override fun defaultResult(): Definition = when (type) {
DefinitionType.INTERFACE -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, false, partial, callback)
DefinitionType.DICTIONARY -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, true, partial, callback)
DefinitionType.EXTENSION_INTERFACE -> ExtensionInterfaceDefinition(namespace, name, implements ?: "")
DefinitionType.TYPEDEF -> TypedefDefinition(typedefType ?: "", namespace, name)
DefinitionType.ENUM -> EnumDefinition(namespace, name)
override fun defaultResult(): Definition = when (kind) {
DefinitionKind.INTERFACE -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, false, partial, callback)
DefinitionKind.DICTIONARY -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, true, partial, callback)
DefinitionKind.EXTENSION_INTERFACE -> ExtensionInterfaceDefinition(namespace, name, implements ?: "")
DefinitionKind.TYPEDEF -> TypedefDefinition(typedefType ?: "", namespace, name)
DefinitionKind.ENUM -> EnumDefinition(namespace, name)
}
override fun visitCallbackRestOrInterface(ctx: WebIDLParser.CallbackRestOrInterfaceContext): Definition {
@@ -288,10 +286,12 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
}
override fun visitCallbackRest(ctx: WebIDLParser.CallbackRestContext): Definition {
kind = DefinitionKind.TYPEDEF
name = getName(ctx)
with(OperationVisitor(memberAttributes.toList())) {
operations.add(visit(ctx))
}
val function = OperationVisitor(memberAttributes.toList()).visit(ctx)
typedefType = "(${function.parameters.map { it.formatFunctionTypePart() }.join(",")}) -> ${function.returnType}"
memberAttributes.clear()
return defaultResult()
}
@@ -324,7 +324,7 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
return defaultResult()
}
type = DefinitionType.TYPEDEF
kind = DefinitionKind.TYPEDEF
name = getName(ctx)
typedefType = ctx.accept(object : WebIDLBaseVisitor<String>() {
@@ -342,14 +342,14 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
}
override fun visitEnum_(ctx: Enum_Context): Definition {
type = DefinitionType.ENUM
kind = DefinitionKind.ENUM
name = getName(ctx)
return defaultResult()
}
override fun visitDictionary(ctx: DictionaryContext): Definition {
type = DefinitionType.DICTIONARY
kind = DefinitionKind.DICTIONARY
name = getName(ctx)
return visitChildren(ctx)
@@ -381,8 +381,8 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
override fun visitImplementsStatement(ctx: ImplementsStatementContext): Definition {
val identifiers = ctx.children.filterIdentifiers().map { it.getText() }
if (identifiers.size() >= 2) {
type = DefinitionType.EXTENSION_INTERFACE
if (identifiers.size() == 2) {
kind = DefinitionKind.EXTENSION_INTERFACE
name = identifiers[0]
implements = identifiers[1]
visitChildren(ctx)
@@ -392,16 +392,14 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
}
override fun visitOperation(ctx: OperationContext): Definition {
with(OperationVisitor(memberAttributes.toList())) {
operations.add(visit(ctx))
}
operations.add(OperationVisitor(memberAttributes.toList()).visit(ctx))
memberAttributes.clear()
return defaultResult()
}
override fun visitInheritance(ctx: WebIDLParser.InheritanceContext): Definition {
if (ctx.children != null) {
inherited.addAll(ctx.children.filterIdentifiers().map {it.getText().trim()}.filter {it != ""})
inherited.addAll(ctx.children.filterIdentifiers().map { it.getText().trim() }.filter { it != "" })
}
return defaultResult()
}
@@ -424,24 +422,20 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
}
override fun visitConst_(ctx: WebIDLParser.Const_Context): Definition {
constants.add(ConstantVisitor(memberAttributes.toList()).visit(ctx))
constants.add(ConstantVisitor().visit(ctx))
memberAttributes.clear()
return defaultResult()
}
override fun visitExtendedAttribute(ctx: ExtendedAttributeContext): Definition {
val att = with(ExtendedAttributeParser()) {
visit(ctx)
}
memberAttributes.add(att)
memberAttributes.add(ExtendedAttributeParser().visit(ctx))
return defaultResult()
}
}
class ModuleVisitor(val declarations : MutableList<Definition>, var namespace : String = "") : WebIDLBaseVisitor<Unit>() {
class ModuleVisitor(val declarations: MutableList<Definition>, var namespace: String = "") : WebIDLBaseVisitor<Unit>() {
val extendedAttributes = ArrayList<ExtendedAttribute>()
override fun visitDefinition(ctx: WebIDLParser.DefinitionContext) {
@@ -465,6 +459,7 @@ class ModuleVisitor(val declarations : MutableList<Definition>, var namespace :
private fun List<ParseTree>?.filterIdentifiers(): List<ParseTree> = this?.filter { it is TerminalNode && it.getSymbol().getType() == WebIDLLexer.IDENTIFIER_WEBIDL } ?: emptyList()
private fun getName(ctx: ParserRuleContext) = ctx.children.filterIdentifiers().first().getText()
private fun getNameOrNull(ctx: ParserRuleContext) = ctx.children.filterIdentifiers().firstOrNull()?.getText()
fun parseIDL(reader: CharStream): Repository {
val ll = WebIDLLexer(reader)
+11 -8
View File
@@ -16,7 +16,7 @@ fun main(args: Array<String>) {
outDir.deleteRecursively()
outDir.mkdirs()
val repository = srcDir.walkTopDown().filter { it.isDirectory() || it.extension == "idl" }.asSequence().filter {it.isFile()}.fold(Repository(emptyMap(), emptyMap(), emptyMap(), emptyMap())) { acc, e ->
val repository = srcDir.walkTopDown().filter { it.isDirectory() || it.extension == "idl" }.asSequence().filter { it.isFile() }.fold(Repository(emptyMap(), emptyMap(), emptyMap(), emptyMap())) { acc, e ->
val fileRepository = parseIDL(ANTLRFileStream(e.getAbsolutePath(), "UTF-8"))
Repository(
@@ -28,6 +28,7 @@ fun main(args: Array<String>) {
}
val definitions = mapDefinitions(repository, repository.interfaces.values())
val unions = generateUnions(definitions, repository.typeDefs.values())
val allPackages = definitions.map { it.namespace }.distinct().sort()
allPackages.forEach { pkg ->
@@ -43,19 +44,19 @@ fun main(args: Array<String>) {
w.appendln("package ${pkg}")
w.appendln()
allPackages.filter {it != pkg}.forEach { import ->
allPackages.filter { it != pkg }.forEach { import ->
w.appendln("import ${import}.*")
}
w.appendln()
w.render(pkg, definitions, repository.typeDefs.values())
w.render(pkg, definitions, unions)
}
}
}
private fun <K, V> Map<K, List<V>>.reduceValues(reduce : (V, V) -> V = {a, b -> b}) : Map<K, V> = mapValues { it.value.reduce(reduce) }
private fun <K, V> Map<K, List<V>>.reduceValues(reduce: (V, V) -> V = { a, b -> b }): Map<K, V> = mapValues { it.value.reduce(reduce) }
private fun <K, V> Map<K, V>.mergeReduce(other : Map<K, V>, reduce : (V, V) -> V = {a, b -> b}) : Map<K, V> {
private fun <K, V> Map<K, V>.mergeReduce(other: Map<K, V>, reduce: (V, V) -> V = { a, b -> b }): Map<K, V> {
val result = LinkedHashMap<K, V>(this.size() + other.size())
result.putAll(this)
other.forEach { e ->
@@ -63,7 +64,8 @@ private fun <K, V> Map<K, V>.mergeReduce(other : Map<K, V>, reduce : (V, V) -> V
if (existing == null) {
result[e.key] = e.value
} else {
}
else {
result[e.key] = reduce(e.value, existing)
}
}
@@ -71,7 +73,7 @@ private fun <K, V> Map<K, V>.mergeReduce(other : Map<K, V>, reduce : (V, V) -> V
return result
}
private fun <K, V> Map<K, List<V>>.merge(other : Map<K, List<V>>) : Map<K, List<V>> {
private fun <K, V> Map<K, List<V>>.merge(other: Map<K, List<V>>): Map<K, List<V>> {
val result = LinkedHashMap<K, MutableList<V>>(size() + other.size())
this.forEach {
result[it.key] = ArrayList(it.value)
@@ -80,7 +82,8 @@ private fun <K, V> Map<K, List<V>>.merge(other : Map<K, List<V>>) : Map<K, List<
val list = result[it.key]
if (list == null) {
result[it.key] = ArrayList(it.value)
} else {
}
else {
list.addAll(it.value)
}
}
@@ -35,11 +35,12 @@ val GenerateAttribute.setterNoImpl: Boolean
get() = getterSetterNoImpl && !readOnly
val String.typeSignature: String
get() = if (contains("->")) "()" else this
get() = if (contains("->")) "Function${FunctionType(this).arity}" else this
val GenerateAttribute.signature: String
get() = "$name:${type.typeSignature}"
fun GenerateAttribute.dynamicIfUnknownType(allTypes : Set<String>, standardTypes : Set<String> = standardTypes()) = this.copy(type = type.dynamicIfUnknownType(allTypes, standardTypes))
fun GenerateAttribute.dynamicIfUnknownType(allTypes : Set<String>, standardTypes : Set<String> = standardTypes()) = copy(type = type.dynamicIfUnknownType(allTypes, standardTypes))
enum class NativeGetterOrSetter {
NONE
@@ -52,7 +53,6 @@ enum class GenerateDefinitionKind {
CLASS
}
class UnionType(val namespace: String, types: Collection<String>) {
val memberTypes = HashSet(types)
val name = "Union${this.memberTypes.sort().joinToString("Or")}"
@@ -93,10 +93,15 @@ val GenerateFunction.signature: String
get() = arguments.map { it.type.typeSignature }.joinToString(", ", "$name(", ")")
fun GenerateFunction.dynamicIfUnknownType(allTypes : Set<String>) = standardTypes().let { standardTypes ->
this.copy(returnType = returnType.dynamicIfUnknownType(allTypes, standardTypes), arguments = arguments.map { it.dynamicIfUnknownType(allTypes, standardTypes) })
copy(returnType = returnType.dynamicIfUnknownType(allTypes, standardTypes), arguments = arguments.map { it.dynamicIfUnknownType(allTypes, standardTypes) })
}
fun InterfaceDefinition.findExtendedAttribute(name: String) = extendedAttributes.firstOrNull { it.call == name }
fun InterfaceDefinition?.hasExtendedAttribute(name: String) = this?.findExtendedAttribute(name) ?: null != null
fun InterfaceDefinition.findConstructor() = findExtendedAttribute("Constructor")
data class GenerateUnionTypes(
val typeNamesToUnions : Map<String, List<String>>,
val anonymousUnionsMap : Map<String, GenerateTraitOrClass>,
val typedefsMarkersMap : Map<String, GenerateTraitOrClass>
)
@@ -65,7 +65,7 @@ private fun Appendable.renderFunctionDeclaration(allTypes: Set<String>, f: Gener
when (f.nativeGetterOrSetter) {
NativeGetterOrSetter.GETTER -> append("nativeGetter ")
NativeGetterOrSetter.GETTER -> append("nativeSetter ")
NativeGetterOrSetter.SETTER -> append("nativeSetter ")
}
if (override) {
@@ -150,33 +150,19 @@ private fun Pair<String, String>.betterName() = if (((0..9).map { it.toString()
fun <K, V> List<Pair<K, V>>.toMultiMap(): Map<K, List<V>> = groupBy { it.first }.mapValues { it.value.map { it.second } }
fun Appendable.render(namespace: String, ifaces: List<GenerateTraitOrClass>, typedefs: Iterable<TypedefDefinition>) {
fun Appendable.render(namespace: String, ifaces: List<GenerateTraitOrClass>, unions : GenerateUnionTypes) {
val declaredTypes = ifaces.toMap { it.name }
val anonymousUnionTypes = collectUnionTypes(declaredTypes)
val anonymousUnionTypeTraits = generateUnionTypeTraits(anonymousUnionTypes)
val anonymousUnionsMap = anonymousUnionTypeTraits.toMap { it.name }
val typedefsToBeGenerated = typedefs.filter { it.types.startsWith("Union<") }
.filter { it.namespace == namespace }
.map { NamedValue(it.name, UnionType(namespace, splitUnionType(it.types))) }
.filter { it.value.memberTypes.all { type -> type in declaredTypes } }
val typedefsMarkerTraits = typedefsToBeGenerated.groupBy { it.name }.mapValues { mapUnionType(it.value.first().value).copy(name = it.key) }
// TODO better name, extract duplication
val typeNamesToUnions = anonymousUnionTypes.flatMap { unionType -> unionType.memberTypes.map { unionMember -> unionMember to unionType.name } }.toMultiMap()
typedefsToBeGenerated.flatMap { typedef -> typedef.value.memberTypes.map { unionMember -> unionMember to typedef.name } }.toMultiMap()
val allTypes = declaredTypes + anonymousUnionsMap + typedefsMarkerTraits
val allTypes = declaredTypes + unions.anonymousUnionsMap + unions.typedefsMarkersMap
declaredTypes.values().filter { it.namespace == namespace }.forEach {
render(allTypes, typeNamesToUnions, it)
render(allTypes, unions.typeNamesToUnions, it)
}
anonymousUnionTypeTraits.filter { it.namespace == "" || it.namespace == namespace }.forEach {
unions.anonymousUnionsMap.values().filter { it.namespace == "" || it.namespace == namespace }.forEach {
render(allTypes, emptyMap(), it, markerAnnotation = true)
}
typedefsMarkerTraits.values().filter { it.namespace == "" || it.namespace == namespace }.forEach {
unions.typedefsMarkersMap.values().filter { it.namespace == "" || it.namespace == namespace }.forEach {
render(allTypes, emptyMap(), it, markerAnnotation = true)
}
}
@@ -32,12 +32,10 @@ private val typeMapper = mapOf(
"long" to "Int",
"float" to "Float",
"double" to "Double",
"any" to "Any?",
"any" to "dynamic",
"DOMTimeStamp" to "Number",
"object" to "dynamic", // TODO map to Any?
"EventHandler" to "(Event) -> Unit",
"WindowProxy" to "Window",
"Function" to "() -> dynamic",
"USVString" to "String",
"DOMString" to "String",
"ByteString" to "String",
@@ -57,31 +55,60 @@ fun allSuperTypesImpl(roots: List<GenerateTraitOrClass>, all: Map<String, Genera
}
}
data class FunctionType(val parameterTypes : List<Attribute>, val returnType : String)
val FunctionType.arity : Int
get() = parameterTypes.size()
val FunctionType.text : String
get() = "(${parameterTypes.map { it.formatFunctionTypePart() }.join(",")}) -> ${returnType}"
fun FunctionType(text : String) : FunctionType {
val (parameters, returnType) = text.split("->".toRegex()).map {it.trim()}.filter { it != "" }
return FunctionType(
parameterTypes = parameters.removeSurrounding("(", ")").split(',')
.map { it.trim() }
.filter { !it.isEmpty() }
.map { Attribute(name = "", type = it.removePrefix("vararg "), vararg = it.startsWith("vararg ")) }
.toList(),
returnType = returnType
)
}
fun standardTypes() = typeMapper.values().map {it.dropNullable()}.toSet()
fun String.dynamicIfUnknownType(allTypes: Set<String>, standardTypes: Set<String> = standardTypes()): String = when {
startsWith("Union<") -> UnionType("", splitUnionType(this)).name.dynamicIfUnknownType(allTypes, standardTypes).copyNullabilityFrom(this)
endsWith("?") -> this.dropNullable().dynamicIfUnknownType(allTypes, standardTypes).ensureNullable()
contains("->") -> {
val (parameters, returnType) = this.split("->".toRegex()).map {it.trim()}.filter { it != "" }
"(${parameters.removeSurrounding("(", ")").split(',').map {it.dynamicIfUnknownType(allTypes, standardTypes)}.join(",")}) -> ${returnType.dynamicIfUnknownType(allTypes, standardTypes)}"
}
this in allTypes -> this
this in standardTypes -> this
startsWith("Array<") -> "Array<" + removePrefix("Array<").removeSuffix(">").dynamicIfUnknownType(allTypes, standardTypes) + ">"
startsWith("Union<") -> UnionType("", splitUnionType(this)).name.dynamicIfUnknownType(allTypes, standardTypes).copyNullabilityFrom(this)
this != dropNullable() -> dropNullable().dynamicIfUnknownType(allTypes, standardTypes).ensureNullable()
contains("->") -> {
FunctionType(this).let { function ->
function.copy(
returnType = function.returnType.dynamicIfUnknownType(allTypes, standardTypes),
parameterTypes = function.parameterTypes.map { it.copy(type = it.type.dynamicIfUnknownType(allTypes, standardTypes)) }
).text
}
}
else -> "dynamic"
}
private fun mapType(repository: Repository, type: String): String =
when {
type in typeMapper -> typeMapper[type]!!
type.endsWith("?") -> mapType(repository, type.dropNullable()).ensureNullable()
type.isNullable() -> mapType(repository, type.dropNullable()).ensureNullable()
type.endsWith("...") -> mapType(repository, type.substring(0, type.length() - 3))
type.endsWith("[]") -> "Array<${mapType(repository, type.substring(0, type.length() - 2))}>"
type.startsWith("unrestricted") -> mapType(repository, type.substring(12))
type.startsWith("sequence") -> "Any" // TODO how do we handle sequences?
type.startsWith("sequence<") -> "Array<${mapType(repository, type.removePrefix("sequence<").removeSuffix(">").trim())}>"
type.startsWith("sequence") -> "Array<dynamic>"
type in repository.typeDefs -> mapTypedef(repository, type)
type in repository.enums -> "String"
type.endsWith("Callback") -> "() -> Unit"
type.contains("->") -> FunctionType(type).let { function ->
function.copy(
returnType = mapType(repository, function.returnType),
parameterTypes = function.parameterTypes.takeWhile { !it.vararg }.map { it.copy(type = mapType(repository, it.type)) }
).text
}
type.startsWith("Promise<") -> "dynamic"
repository.interfaces[type].hasExtendedAttribute("NoInterfaceObject") -> "dynamic"
else -> type
@@ -99,7 +126,7 @@ private fun mapTypedef(repository: Repository, type: String): String {
// Union<A, Union<B>, C> -> [A, B, C]
// Union<Union<Union<A, B>>, C> -> [A, B, C]
private fun splitUnionType(unionType: String) =
unionType.replaceAll("Union<", "").replaceAll("[>]+", "").split("\\s*,\\s*".toRegex()).distinct().map {it.replaceAll("\\?$", "")}
unionType.replace("Union<".toRegex(), "").replace("[>]+".toRegex(), "").split("\\s*,\\s*".toRegex()).distinct().map {it.replace("\\?$".toRegex(), "")}
private fun GenerateFunction?.allTypes() = if (this != null) sequenceOf(returnType) + arguments.asSequence().map { it.type } else emptySequence()
@@ -0,0 +1,43 @@
package org.jetbrains.idl2k.util
import java.util.*
fun List<List<*>>.mutationsCount() = if (isEmpty()) 0 else fold(1) { acc, e -> acc * e.size() }
fun <T> List<List<T>>.mutations() : List<List<T>> {
val indices = IntArray(size())
val sizes = map { it.size() }
fun next() : Boolean {
var carry = 1
for (pos in size() - 1 downTo 0) {
var index = indices[pos]
val size = sizes[pos]
index += carry
carry = (index - size + 1).coerceAtLeast(0)
if (index >= size) {
indices[pos] = index - size
} else {
indices[pos] = index
return true
}
}
return carry == 0
}
val count = mutationsCount()
if (count == 0) {
return emptyList()
}
val result = ArrayList<List<T>>(count)
do {
result.add(indices.mapIndexed { pos, index -> this[pos][index] })
} while (next())
return result
}