Kotlin: Remove unused code paths in type conversion. Following changes in API, type design, and tree-shaking used to remove unused converters, these code paths are no longer needed. A shorter codebase is easier to understand and work on. Bug: b/429149631 Test: ./gradlew connectedAndroidTest Change-Id: Idea5f0302f1f7938a32448b4cfdfaa177eeb2ba6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/277295 Commit-Queue: Jim Blackler <jimblackler@google.com> Reviewed-by: Ria Singhla <rsinghla@google.com>
diff --git a/generator/templates/art/api_jni_types.cpp b/generator/templates/art/api_jni_types.cpp index 6c16279..fb272a1 100644 --- a/generator/templates/art/api_jni_types.cpp +++ b/generator/templates/art/api_jni_types.cpp
@@ -77,18 +77,6 @@ {%- endif -%} {% endmacro %} -{% macro convert_array_element_to_kotlin(input, output, size, member) %} - {%- if member.type.category in ['bitmask', 'enum'] -%} - //* Kotlin value classes do not get inlined in arrays, so the creation method is different. - jclass clz = classes->{{ member.type.name.camelCase() }}; - jmethodID init = env->GetMethodID(clz, "<init>", "(I)V"); - jobject {{ output }} = env->NewObject(clz, init, static_cast<jint>({{ input }})); - {%- else -%} - //* Declares an instance of 'output' - {{ convert_to_kotlin(input, output, size, member) }} - {%- endif -%} -{% endmacro %} - {% macro convert_to_kotlin(input, output, size, member) %} {% if size is string %} {% if member.type.name.get() in ['void const *', 'void *'] %} @@ -98,7 +86,7 @@ jobjectArray {{ output }} = env->NewObjectArray( {{ size }}, classes->{{ member.type.name.camelCase() }}, 0); for (int idx = 0; idx != {{ size }}; idx++) { - {{ convert_array_element_to_kotlin(input + '[idx]', 'element', None, {'type': member.type}) | indent(4) }} + {{ convert_to_kotlin(input + '[idx]', 'element', None, {'type': member.type}) | indent(4) }} env->SetObjectArrayElement({{ output }}, idx, element); } {% elif member.type.category in ['bitmask', 'enum'] or member.type.name.get() in ['int', 'int32_t', 'uint32_t'] %} @@ -116,15 +104,10 @@ } {% elif member.type.category == 'structure' %} jobject {{ output }} = ToKotlin(env, {{ '&' if member.annotation not in ['*', 'const*'] }}{{ input }}); - {% elif member.type.name.get() == 'void *' %} - jlong {{ output }} = reinterpret_cast<jlong>({{ input }}); {% elif member.type.category in ['bitmask', 'enum', 'native'] %} //* We use Kotlin value classes for bitmask and enum, and they get inlined as lone values. {{ to_jni_type(member.type) }} {{ output }} = static_cast<{{ to_jni_type(member.type) }}>({{ input }}); - {% elif member.type.category in ['callback function', 'function pointer'] %} - jobject {{ output }} = nullptr; - dawn::WarningLog() << "while converting {{ as_cType(member.type.name) }}: Native callbacks cannot be converted to Kotlin"; {% elif member.type.category != 'kotlin type' %} - {{ unreachable_code() }} + {{ unreachable_code('Unsupported type: ' + member.type.name.get()) }} {% endif %} {% endmacro %}
diff --git a/generator/templates/art/api_kotlin_types.kt b/generator/templates/art/api_kotlin_types.kt index 1c3c9aa..07d7839 100644 --- a/generator/templates/art/api_kotlin_types.kt +++ b/generator/templates/art/api_kotlin_types.kt
@@ -29,9 +29,7 @@ {%- set type = arg.type %} {%- set optional = arg.optional and not strip_optional %} {%- set default_value = arg.default_value %} - {%- if arg == None -%} - Unit - {%- elif type.category == 'kotlin type' -%} + {%- if type.category == 'kotlin type' -%} {{ type.name.get() }} {#- The name *is* the type #} {%- elif arg.type.name.get() == 'string view' -%} String{{ '?' if optional }}