Revert "Generator for Kotlin structures."
This reverts commit 93124ee012aa9e3407f45d6f3dc86491ce32838a.
Reason for revert: Breaks the build
Original change's description:
> Generator for Kotlin structures.
>
> Bug: 336282625
> Change-Id: Ib0a1dc528c742963f1e354332ef03d582d9cb4d8
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/183920
> Reviewed-by: Trevor David Black <vantablack@google.com>
> Commit-Queue: Jim Blackler <jimblackler@google.com>
> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Bug: 336282625
Change-Id: I00c15f0ae483aae324715b9436f52bba7d4256fc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/187702
Reviewed-by: Trevor David Black <vantablack@google.com>
Auto-Submit: Trevor David Black <vantablack@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Trevor David Black <vantablack@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 5e5289b..5c9cbc2 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -27,7 +27,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import json, os, sys
-from collections import namedtuple, defaultdict
+from collections import namedtuple
from generator_lib import Generator, run_generator, FileRender
@@ -329,12 +329,6 @@
return any(member.requires_struct_defaulting
for member in self.members)
- @property
- # Returns True if the structure can be created with no parameters, e.g. all of its members have
- # defaults or are optional,
- def has_basic_constructor(self):
- return all((member.optional or member.default_value)
- for member in self.members)
class CallbackInfoType(StructureType):
@@ -789,36 +783,6 @@
assert False
-############################################################
-# KOTLIN STUFF
-############################################################
-
-
-def compute_kotlin_params(loaded_json):
- params_kotlin = parse_json(loaded_json, enabled_tags=['art'])
- by_category = params_kotlin['by_category']
-
- # The 'length' members are removed as Kotlin can infer that from the container.
- # 'length' members are identified when some *other* member specifies its name as the
- # length parameter.
- for structure in by_category['structure']:
- structure.members = [
- member for member in structure.members
- if member.type.name.get() not in ['void *', 'void const *'] and
- not [1 for other in structure.members if other.length == member]
- ]
-
- # A structure may need to know which other structures listed it as a chain root, e.g.
- # to know whether to mark the generated class 'open'.
- chain_children = defaultdict(list)
- for structure in by_category['structure']:
- for chain_root in structure.chain_roots:
- chain_children[chain_root.name.get()].append(structure)
- params_kotlin['chain_children'] = chain_children
- params_kotlin['unreachable_code'] = unreachable_code
- return params_kotlin
-
-
#############################################################
# Generator
#############################################################
@@ -1433,18 +1397,8 @@
lpm_params))
if 'kotlin' in targets:
- params_kotlin = compute_kotlin_params(loaded_json)
- by_category = params_kotlin['by_category']
- for structure in by_category['structure']:
- renders.append(
- FileRender(
- 'art/api_kotlin_structure.kt',
- 'java/' + metadata.kotlin_path + '/' +
- structure.name.CamelCase() + '.kt', [
- RENDER_PARAMS_BASE, params_kotlin, {
- 'structure': structure
- }
- ]))
+ params_kotlin = parse_json(loaded_json,
+ enabled_tags=['dawn', 'native'])
for enum in (params_kotlin['by_category']['bitmask'] +
params_kotlin['by_category']['enum']):
diff --git a/generator/templates/art/api_kotlin_structure.kt b/generator/templates/art/api_kotlin_structure.kt
deleted file mode 100644
index a1c36e2..0000000
--- a/generator/templates/art/api_kotlin_structure.kt
+++ /dev/null
@@ -1,40 +0,0 @@
-//* Copyright 2024 The Dawn & Tint Authors
-//*
-//* Redistribution and use in source and binary forms, with or without
-//* modification, are permitted provided that the following conditions are met:
-//*
-//* 1. Redistributions of source code must retain the above copyright notice, this
-//* list of conditions and the following disclaimer.
-//*
-//* 2. Redistributions in binary form must reproduce the above copyright notice,
-//* this list of conditions and the following disclaimer in the documentation
-//* and/or other materials provided with the distribution.
-//*
-//* 3. Neither the name of the copyright holder nor the names of its
-//* contributors may be used to endorse or promote products derived from
-//* this software without specific prior written permission.
-//*
-//* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-//* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-//* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-//* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-//* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-//* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-//* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-//* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-//* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-package {{ metadata.kotlin_package }}
-{% from 'art/api_kotlin_types.kt' import kotlin_declaration with context %}
-
-class {{ structure.name.CamelCase() }}(
- {% for member in structure.members %}
- {%- if member.type.category in ['bitmask', 'enum'] -%}
- @get:JvmName("get{{ member.name.CamelCase() }}")
- {% endif %}
- var {{ member.name.camelCase() }}: {{ kotlin_declaration(member) }},
- {% endfor %}
- {% for structure in chain_children[structure.name.get()] %}
- var {{ structure.name.camelCase() }}: {{ structure.name.CamelCase() }}? = null,
- {% endfor %}
-)
diff --git a/generator/templates/art/api_kotlin_types.kt b/generator/templates/art/api_kotlin_types.kt
deleted file mode 100644
index 222ef51..0000000
--- a/generator/templates/art/api_kotlin_types.kt
+++ /dev/null
@@ -1,122 +0,0 @@
-//* Copyright 2024 The Dawn & Tint Authors
-//*
-//* Redistribution and use in source and binary forms, with or without
-//* modification, are permitted provided that the following conditions are met:
-//*
-//* 1. Redistributions of source code must retain the above copyright notice, this
-//* list of conditions and the following disclaimer.
-//*
-//* 2. Redistributions in binary form must reproduce the above copyright notice,
-//* this list of conditions and the following disclaimer in the documentation
-//* and/or other materials provided with the distribution.
-//*
-//* 3. Neither the name of the copyright holder nor the names of its
-//* contributors may be used to endorse or promote products derived from
-//* this software without specific prior written permission.
-//*
-//* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-//* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-//* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-//* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-//* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-//* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-//* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-//* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-//* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-//* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-//* Outputs a declaration for an argument (type RecordMember), including a default defintion if
-//* required.
-{%- macro kotlin_declaration(arg) -%}
- {%- set type = arg.type %}
- {%- set optional = arg.optional %}
- {%- set default_value = arg.default_value %}
- {%- set no_default = arg.json_data is defined and arg.json_data.get('no_default', false) %}
- {%- if arg.length == 'strlen' -%}
- String{{ '?' if optional or default_value == 'nullptr' }}
- {%- if default_value or optional -%}
- = null
- {%- endif %}
- {%- elif arg.length and arg.constant_length != 1 %}
- {%- if type.category in ['function pointer', 'object', 'structure'] -%}
- Array<{{ type.name.CamelCase() }}> = arrayOf()
- {%- elif type.category in ['bitmask', 'enum'] -%}
- IntArray = intArrayOf()
- {%- elif type.name.get() == 'bool' -%}
- BooleanArray = booleanArrayOf()
- {%- elif type.name.get() == 'float' -%}
- FloatArray = floatArrayOf()
- {%- elif type.name.get() == 'double' -%}
- DoubleArray = doubleArrayOf()
- {%- elif type.name.get() in ['int8_t', 'uint8_t', 'void'] -%}
- ByteArray = byteArrayOf()
- {%- elif type.name.get() in ['int16_t', 'uint16_t'] -%}
- ShortArray = shortArrayOf()
- {%- elif type.name.get() in ['int', 'int32_t', 'uint32_t'] -%}
- IntArray = intArrayOf()
- {%- elif type.name.get() in ['int64_t', 'uint64_t', 'size_t'] -%}
- LongArray = longArrayOf()
- {%- else -%}
- {{ unreachable_code() }}
- {% endif %}
- {%- elif type.category in ['function pointer', 'object'] %}
- {{- type.name.CamelCase() }}
- {%- if optional or default_value %}? = null{% endif %}
- {%- elif type.category == 'structure' %}
- {{- type.name.CamelCase() }}{{ '?' if optional }}
- {%- if type.has_basic_constructor and not no_default -%}
- = {{ type.name.CamelCase() }}()
- {%- elif optional -%}
- = null
- {%- endif %}
- {%- elif type.category in ['bitmask', 'enum'] -%}
- Int
- {%- if default_value %}
- {%- for value in type.values if value.name.name == default_value %}
- = {{ type.name.CamelCase() }}.{{ as_ktName(value.name.CamelCase()) }}
- {%- endfor %}
- {%- endif %}
- {%- elif type.name.get() == 'bool' -%}
- Boolean{{ '?' if optional }}{% if default_value %} = {{ default_value }}{% endif %}
- {%- elif type.name.get() == 'float' -%}
- Float{{ '?' if optional }}{% if default_value %} =
- {{ 'Float.NaN' if default_value == 'NAN' else default_value or '0.0f' }}{% endif %}
- {%- elif type.name.get() == 'double' -%}
- Double{{ '?' if optional }}{% if default_value %} =
- {{ 'Double.NaN' if default_value == 'NAN' else default_value or '0.0' }}{% endif %}
- {%- elif type.name.get() in ['int8_t', 'uint8_t'] -%}
- Byte{{ '?' if optional }}{% if default_value %} = {{ default_value }}{% endif %}
- {%- elif type.name.get() in ['int16_t', 'uint16_t'] -%}
- Short{{ '?' if optional }}{% if default_value %} = {{ default_value }}{% endif %}
- {%- elif type.name.get() in ['int', 'int32_t', 'uint32_t'] -%}
- Int
- {%- if default_value -%}
- {%- if default_value is string and default_value.startswith('WGPU_') -%}
- = {{ 'Constants.' + default_value | replace('WGPU_', '') }}
- {%- elif default_value == 'nullptr' -%}
- ? = null
- {%- elif default_value == '0xFFFFFFFF' -%}
- = -0x7FFFFFFF
- {%- else -%}
- = {{ default_value }}
- {%- endif %}
- {% endif %}
- {%- elif type.name.get() in ['int64_t', 'uint64_t', 'size_t'] -%}
- Long
- {%- if default_value %}
- {%- if default_value is string and default_value.startswith('WGPU_') -%}
- = {{ 'Constants.' + default_value | replace('WGPU_', '') }}
- {%- elif default_value == 'nullptr' -%}
- ? = null
- {%- elif default_value == '0xFFFFFFFFFFFFFFFF' -%}
- = -0x7FFFFFFFFFFFFFFF
- {%- else -%}
- = {{ default_value }}
- {%- endif %}
- {% endif %}
- {%- elif type.name.get() == 'void' %}
- {{- 'Long' if arg.annotation == '*' else 'Unit' }}
- {%- else -%}
- {{ unreachable_code() }}
- {%- endif %}
-{% endmacro %}