JS: prevent IDL2K from generating delegated constructor calls

This commit is contained in:
Alexey Andreev
2016-12-20 15:02:16 +03:00
parent 1a7e8b0690
commit e4b4c19b87
3 changed files with 4 additions and 31 deletions
+2 -22
View File
@@ -133,8 +133,6 @@ 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() ?: EMPTY_CONSTRUCTOR
val declaredConstructors = iface.findConstructors()
val entityKind = resolveDefinitionKind(repository, iface, declaredConstructors)
@@ -149,23 +147,14 @@ fun generateTrait(repository: Repository, iface: InterfaceDefinition): GenerateT
val primaryConstructorWithCall = primaryConstructor?.let { constructor ->
val constructorAsFunction = generateConstructorAsFunction(repository, constructor)
val superCall = when {
superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, superClass.name, superConstructor)
else -> null
}
ConstructorWithSuperTypeCall(constructorAsFunction, constructor, superCall)
ConstructorWithSuperTypeCall(constructorAsFunction, constructor)
}
val secondaryConstructorsWithCall = secondaryConstructors.map { secondaryConstructor ->
val constructorAsFunction = generateConstructorAsFunction(repository, secondaryConstructor)
val initCall = when {
primaryConstructorWithCall != null -> superOrPrimaryConstructorCall(constructorAsFunction, "this", primaryConstructorWithCall.constructorAttribute)
superClass != null -> superOrPrimaryConstructorCall(constructorAsFunction, "super", superConstructor)
else -> null
}
ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor, initCall)
ConstructorWithSuperTypeCall(constructorAsFunction, secondaryConstructor)
}
return GenerateTraitOrClass(iface.name, iface.namespace, entityKind, (iface.superTypes + extensions.map { it.name }).distinct(),
@@ -184,15 +173,6 @@ fun generateConstructorAsFunction(repository: Repository, constructor: ExtendedA
functionName = "constructor",
nativeGetterOrSetter = NativeGetterOrSetter.NONE)
fun superOrPrimaryConstructorCall(constructorAsFunction: GenerateFunction, superClassName: String, superOrPrimaryConstructor: ExtendedAttribute): GenerateFunctionCall {
val constructorArgumentNames = constructorAsFunction.arguments.map { it.name }.toSet()
return GenerateFunctionCall(
name = superClassName,
arguments = superOrPrimaryConstructor.arguments.map { arg ->
if (arg.name in constructorArgumentNames) arg.name else "noImpl"
}
)
}
fun mapUnionType(it: UnionType) = GenerateTraitOrClass(
name = it.name,
@@ -73,7 +73,7 @@ data class GenerateFunction(
val override: Boolean
)
data class ConstructorWithSuperTypeCall(val constructor: GenerateFunction, val constructorAttribute: ExtendedAttribute, val initTypeCall: GenerateFunctionCall?)
data class ConstructorWithSuperTypeCall(val constructor: GenerateFunction, val constructorAttribute: ExtendedAttribute)
data class GenerateTraitOrClass(
val name: String,
val namespace: String,
@@ -156,10 +156,8 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
}
val superTypesExclude = inheritanceExclude[iface.name] ?: emptySet()
val superCallName = primary?.initTypeCall?.name
val superTypesWithCalls =
(primary?.initTypeCall?.let { listOf(renderCall(it)) } ?: emptyList()) +
iface.superTypes.filter { it != superCallName && it in allSuperTypesNames }.filter { it !in superTypesExclude } +
iface.superTypes.filter { it in allSuperTypesNames }.filter { it !in superTypesExclude } +
(typeNamesToUnions[iface.name] ?: emptyList())
if (superTypesWithCalls.isNotEmpty()) {
@@ -173,11 +171,6 @@ fun Appendable.render(allTypes: Map<String, GenerateTraitOrClass>, typeNamesToUn
append("constructor")
renderArgumentsDeclaration(secondary.constructor.fixRequiredArguments(iface.name).arguments.dynamicIfUnknownType(allTypes.keys), false)
if (secondary.initTypeCall != null) {
append(" : ")
append(renderCall(secondary.initTypeCall))
}
appendln()
}