IDL2K introduce required parameters list to avoid possible ambiguous calls

This commit is contained in:
Sergey Mashkov
2015-06-16 20:07:57 +03:00
parent 20a67c41ee
commit c4d53e1e16
4 changed files with 17 additions and 10 deletions
+2 -2
View File
@@ -4578,7 +4578,7 @@ native public open class DOMPointReadOnly(x: Double, y: Double, z: Double, w: Do
}
native public open class DOMPoint : DOMPointReadOnly {
constructor(point: DOMPointInit = noImpl) : super(noImpl, noImpl, noImpl, noImpl)
constructor(point: DOMPointInit) : super(noImpl, noImpl, noImpl, noImpl)
constructor(x: Double = 0.0, y: Double = 0.0, z: Double = 0.0, w: Double = 1.0) : super(x, y, z, w)
override var x: Double
get() = noImpl
@@ -4644,7 +4644,7 @@ native public open class DOMRectInit {
native public open class DOMQuad {
constructor(p1: DOMPointInit = noImpl, p2: DOMPointInit = noImpl, p3: DOMPointInit = noImpl, p4: DOMPointInit = noImpl)
constructor(rect: DOMRectInit = noImpl)
constructor(rect: DOMRectInit)
open val p1: DOMPoint
get() = noImpl
open val p2: DOMPoint
@@ -52,7 +52,7 @@ val relocations = mapOf(
"EventListener" to "org.w3c.dom.events"
)
val commentOutDeclarations = listOf(
val commentOutDeclarations = setOf(
"MouseEvent.screenX: Double", "MouseEvent.screenY: Double",
"MouseEvent.clientX: Double", "MouseEvent.clientY: Double",
"MouseEvent.x: Double", "MouseEvent.y: Double",
@@ -67,4 +67,9 @@ val commentOutDeclarations = listOf(
"HTMLPropertiesCollection.get",
"SVGElement.id"
).toSet()
)
val requiredArguments = setOf(
"DOMPoint.constructor.point",
"DOMQuad.constructor.rect"
)
+2 -2
View File
@@ -138,8 +138,8 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
fun generateConstructorAsFunction(repository: Repository, constructor: ExtendedAttribute) = generateFunction(
repository,
Operation("", UnitType, constructor.arguments, emptyList(), false),
functionName = "",
Operation("constructor", UnitType, constructor.arguments, emptyList(), false),
functionName = "constructor",
nativeGetterOrSetter = NativeGetterOrSetter.NONE)
fun superOrPrimaryConstructorCall(constructorAsFunction: GenerateFunction, superClassName: String, superOrPrimaryConstructor: ExtendedAttribute): GenerateFunctionCall {
@@ -98,6 +98,8 @@ private val GenerateAttribute.isVar: Boolean
private fun GenerateAttribute.isCommented(parent: String) = "$parent.$name" in commentOutDeclarations || "$parent.$name: ${type.render()}" in commentOutDeclarations
private fun GenerateFunction.isCommented(parent: String) =
"$parent.$name" in commentOutDeclarations || "$parent.$name(${arguments.size()})" in commentOutDeclarations
private fun GenerateAttribute.isRequiredFunctionArgument(owner: String, functionName: String) = "$owner.$functionName.$name" in requiredArguments
private fun GenerateFunction.fixRequiredArguments(parent: String) = copy(arguments = arguments.map { arg -> arg.copy(initializer = if (arg.isRequiredFunctionArgument(parent, name)) null else arg.initializer) })
fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUnions: Map<String, List<String>>, iface: GenerateTraitOrClass, markerAnnotation: Boolean = false) {
append("native public ")
@@ -115,7 +117,7 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
append(iface.name)
val primary = iface.primaryConstructor
if (primary != null && (primary.constructor.arguments.isNotEmpty() || iface.secondaryConstructors.isNotEmpty())) {
renderArgumentsDeclaration(primary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false)
renderArgumentsDeclaration(primary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keySet()), false)
}
val superCallName = primary?.initTypeCall?.name
@@ -133,7 +135,7 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
iface.secondaryConstructors.forEach { secondary ->
indent(false, 1)
append("constructor")
renderArgumentsDeclaration(secondary.constructor.arguments.dynamicIfUnknownType(allTypes.keySet()), false)
renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keySet()), false)
if (secondary.initTypeCall != null) {
append(" : ")
@@ -155,7 +157,7 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
renderAttributeDeclaration(arg, override = arg.signature in superSignatures, open = iface.kind == GenerateDefinitionKind.CLASS && arg.readOnly, commented = arg.isCommented(iface.name))
}
iface.memberFunctions.filter { it !in superFunctions && !it.static }.map { it.dynamicIfUnknownType(allTypes.keySet()) }.groupBy { it.signature }.reduceValues(::betterFunction).values().forEach {
renderFunctionDeclaration(it, it.signature in superSignatures, commented = it.isCommented(iface.name))
renderFunctionDeclaration(it.fixRequiredArguments(iface.name), it.signature in superSignatures, commented = it.isCommented(iface.name))
}
val staticAttributes = iface.memberAttributes.filter { it.static }
@@ -172,7 +174,7 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
renderAttributeDeclaration(it, override = false, open = false, level = 2, commented = it.isCommented(iface.name))
}
staticFunctions.forEach {
renderFunctionDeclaration(it, override = false, level = 2, commented = it.isCommented(iface.name))
renderFunctionDeclaration(it.fixRequiredArguments(iface.name), override = false, level = 2, commented = it.isCommented(iface.name))
}
indent(false, 1)
appendln("}")