IDL2K: render dictionaries as interfaces, always use nullable types
This commit is contained in:
@@ -66,9 +66,9 @@ fun generateFunctions(repository: Repository, function: Operation): List<Generat
|
|||||||
return listOf(realFunction, getterOrSetterFunction, functionWithCallbackOrNull).filterNotNull()
|
return listOf(realFunction, getterOrSetterFunction, functionWithCallbackOrNull).filterNotNull()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Attribute): GenerateAttribute =
|
fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Attribute, nullableAttributes: Boolean): GenerateAttribute =
|
||||||
GenerateAttribute(attribute.name,
|
GenerateAttribute(attribute.name,
|
||||||
type = mapType(repository, attribute.type),
|
type = mapType(repository, attribute.type).let { if (nullableAttributes) it.toNullable() else it },
|
||||||
initializer = mapLiteral(attribute.defaultValue, mapType(repository, attribute.type)),
|
initializer = mapLiteral(attribute.defaultValue, mapType(repository, attribute.type)),
|
||||||
getterSetterNoImpl = putNoImpl,
|
getterSetterNoImpl = putNoImpl,
|
||||||
kind = if (attribute.readOnly) AttributeKind.VAL else AttributeKind.VAR,
|
kind = if (attribute.readOnly) AttributeKind.VAL else AttributeKind.VAR,
|
||||||
@@ -80,6 +80,7 @@ fun generateAttribute(putNoImpl: Boolean, repository: Repository, attribute: Att
|
|||||||
private fun InterfaceDefinition.superTypes(repository: Repository) = superTypes.map { repository.interfaces[it] }.filterNotNull()
|
private fun InterfaceDefinition.superTypes(repository: Repository) = superTypes.map { repository.interfaces[it] }.filterNotNull()
|
||||||
private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefinition, constructors: List<ExtendedAttribute> = iface.findConstructors()): GenerateDefinitionKind =
|
private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefinition, constructors: List<ExtendedAttribute> = iface.findConstructors()): GenerateDefinitionKind =
|
||||||
when {
|
when {
|
||||||
|
iface.dictionary -> GenerateDefinitionKind.INTERFACE
|
||||||
iface.extendedAttributes.any { it.call == "NoInterfaceObject" } -> GenerateDefinitionKind.INTERFACE
|
iface.extendedAttributes.any { it.call == "NoInterfaceObject" } -> GenerateDefinitionKind.INTERFACE
|
||||||
constructors.isNotEmpty() || iface.superTypes(repository).any { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS } -> {
|
constructors.isNotEmpty() || iface.superTypes(repository).any { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS } -> {
|
||||||
GenerateDefinitionKind.CLASS
|
GenerateDefinitionKind.CLASS
|
||||||
@@ -88,7 +89,8 @@ private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefini
|
|||||||
else -> GenerateDefinitionKind.ABSTRACT_CLASS
|
else -> GenerateDefinitionKind.ABSTRACT_CLASS
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun InterfaceDefinition.mapAttributes(repository: Repository) = attributes.map { generateAttribute(!dictionary, repository, it) }
|
private fun InterfaceDefinition.mapAttributes(repository: Repository)
|
||||||
|
= attributes.map { generateAttribute(putNoImpl = !dictionary, repository = repository, attribute = it, nullableAttributes = dictionary) }
|
||||||
private fun InterfaceDefinition.mapOperations(repository: Repository) = operations.flatMap { generateFunctions(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, AttributeKind.VAL, false, false, true)
|
private fun Constant.mapConstant(repository : Repository) = GenerateAttribute(name, mapType(repository, type), value, false, AttributeKind.VAL, false, false, true)
|
||||||
private val EMPTY_CONSTRUCTOR = ExtendedAttribute(null, "Constructor", emptyList())
|
private val EMPTY_CONSTRUCTOR = ExtendedAttribute(null, "Constructor", emptyList())
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ class DefinitionVisitor(val extendedAttributes: List<ExtendedAttribute>, val nam
|
|||||||
|
|
||||||
override fun defaultResult(): Definition = when (kind) {
|
override fun defaultResult(): Definition = when (kind) {
|
||||||
DefinitionKind.INTERFACE -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, false, partial, callback)
|
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.DICTIONARY -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, /* dictionary = */ true, partial, callback)
|
||||||
DefinitionKind.EXTENSION_INTERFACE -> ExtensionInterfaceDefinition(namespace, name, implements ?: "")
|
DefinitionKind.EXTENSION_INTERFACE -> ExtensionInterfaceDefinition(namespace, name, implements ?: "")
|
||||||
DefinitionKind.TYPEDEF -> TypedefDefinition(typedefType ?: AnyType(true), namespace, name)
|
DefinitionKind.TYPEDEF -> TypedefDefinition(typedefType ?: AnyType(true), namespace, name)
|
||||||
DefinitionKind.ENUM -> EnumDefinition(namespace, name)
|
DefinitionKind.ENUM -> EnumDefinition(namespace, name)
|
||||||
|
|||||||
@@ -32,9 +32,17 @@ private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, modali
|
|||||||
append(arg.name.replaceKeywords())
|
append(arg.name.replaceKeywords())
|
||||||
append(": ")
|
append(": ")
|
||||||
append(arg.type.render())
|
append(arg.type.render())
|
||||||
if (arg.initializer != null && !omitDefaults) {
|
if (arg.initializer != null) {
|
||||||
|
if (omitDefaults) {
|
||||||
|
append(" /*")
|
||||||
|
}
|
||||||
|
|
||||||
append(" = ")
|
append(" = ")
|
||||||
append(arg.initializer.replaceWrongConstants(arg.type))
|
append(arg.initializer.replaceWrongConstants(arg.type))
|
||||||
|
|
||||||
|
if (omitDefaults) {
|
||||||
|
append(" */")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user