diff --git a/libraries/tools/idl2k/src/main/kotlin/gen.kt b/libraries/tools/idl2k/src/main/kotlin/gen.kt index 0237205ca97..eb0e7fb320c 100644 --- a/libraries/tools/idl2k/src/main/kotlin/gen.kt +++ b/libraries/tools/idl2k/src/main/kotlin/gen.kt @@ -66,9 +66,9 @@ fun generateFunctions(repository: Repository, function: Operation): List = iface.findConstructors()): GenerateDefinitionKind = when { + iface.dictionary -> GenerateDefinitionKind.INTERFACE iface.extendedAttributes.any { it.call == "NoInterfaceObject" } -> GenerateDefinitionKind.INTERFACE constructors.isNotEmpty() || iface.superTypes(repository).any { resolveDefinitionKind(repository, it) == GenerateDefinitionKind.CLASS } -> { GenerateDefinitionKind.CLASS @@ -88,7 +89,8 @@ private fun resolveDefinitionKind(repository: Repository, iface: InterfaceDefini 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 Constant.mapConstant(repository : Repository) = GenerateAttribute(name, mapType(repository, type), value, false, AttributeKind.VAL, false, false, true) private val EMPTY_CONSTRUCTOR = ExtendedAttribute(null, "Constructor", emptyList()) diff --git a/libraries/tools/idl2k/src/main/kotlin/idl.kt b/libraries/tools/idl2k/src/main/kotlin/idl.kt index 5a85d8e4196..af086b053cb 100644 --- a/libraries/tools/idl2k/src/main/kotlin/idl.kt +++ b/libraries/tools/idl2k/src/main/kotlin/idl.kt @@ -279,7 +279,7 @@ class DefinitionVisitor(val extendedAttributes: List, val nam 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.DICTIONARY -> InterfaceDefinition(name, namespace, extendedAttributes, operations, attributes, inherited, constants, /* dictionary = */ true, partial, callback) DefinitionKind.EXTENSION_INTERFACE -> ExtensionInterfaceDefinition(namespace, name, implements ?: "") DefinitionKind.TYPEDEF -> TypedefDefinition(typedefType ?: AnyType(true), namespace, name) DefinitionKind.ENUM -> EnumDefinition(namespace, name) diff --git a/libraries/tools/idl2k/src/main/kotlin/render.kt b/libraries/tools/idl2k/src/main/kotlin/render.kt index 93d4a9ed707..1be3358d970 100644 --- a/libraries/tools/idl2k/src/main/kotlin/render.kt +++ b/libraries/tools/idl2k/src/main/kotlin/render.kt @@ -32,9 +32,17 @@ private fun Appendable.renderAttributeDeclaration(arg: GenerateAttribute, modali append(arg.name.replaceKeywords()) append(": ") append(arg.type.render()) - if (arg.initializer != null && !omitDefaults) { + if (arg.initializer != null) { + if (omitDefaults) { + append(" /*") + } + append(" = ") append(arg.initializer.replaceWrongConstants(arg.type)) + + if (omitDefaults) { + append(" */") + } } }