Mark descriptor/options as optional for requestDevice/Adapter

These were not marked as optional previously because it would mean that
C++ methods would look like void F(a = null, b, c) which is invalid in C++
because default arguments must be contiguous and at the end of the
signature.

This commit adds a special case when optional=true where no_default=true
still marks the argument as optional, but doesn't produce a C++ default
argument.

Fixed: dawn:1502
Change-Id: I1b648d37edb94b8412109fc0a06a91bbbd31b8c4
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97002
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez
2022-07-26 17:36:44 +00:00
committed by Dawn LUCI CQ
parent d722e619b1
commit 1260a53018
3 changed files with 6 additions and 5 deletions

View File

@@ -152,7 +152,8 @@ namespace {{metadata.namespace}} {
};
{% macro render_cpp_default_value(member, is_struct=True) -%}
{%- if member.annotation in ["*", "const*"] and member.optional or member.default_value == "nullptr" -%}
{%- if member.json_data.get("no_default", false) -%}
{%- elif member.annotation in ["*", "const*"] and member.optional or member.default_value == "nullptr" -%}
{{" "}}= nullptr
{%- elif member.type.category == "object" and member.optional and is_struct -%}
{{" "}}= nullptr