diff --git a/docs/codegen.md b/docs/codegen.md index d7caf379b2..75a208b2c5 100644 --- a/docs/codegen.md +++ b/docs/codegen.md @@ -38,7 +38,7 @@ Most items and sub-items can include a list of `"tags"`, which, if specified, co A **record** is a list of **record members**, each of which is a dictionary with the following schema: - `"name"` a string - `"type"` a string, the name of the base type for this member - - `"annotation"` a string, default to "value". Define the C annotation to apply to the base type. Allowed annotations are `"value"` (the default), `"*"`, `"const*"`, `"const*const*"` + - `"annotation"` a string, default to "value". Define the C annotation to apply to the base type. Allowed annotations are `"value"` (the default), `"*"`, `"const*"` - `"length"` (default to 1 if not set), a string. Defines length of the array pointed to for pointer arguments. If not set the length is implicitly 1 (so not an array), but otherwise it can be set to the name of another member in the same record that will contain the length of the array (this is heavily used in the `fooCount` `foos` pattern in the API). As a special case `"strlen"` can be used for `const char*` record members to denote that the length should be determined with `strlen`. - `"optional"` (default to false) a boolean that says whether this member is optional. Member records can be optional if they are pointers (otherwise dawn_wire will always try to dereference them), objects (otherwise dawn_wire will always try to encode their ID and crash), or if they have a `"default"` key. Optional pointers and objects will always default to `nullptr`. - `"default"` (optional) a number or string. If set the record member will use that value as default value. Depending on the member's category it can be a number, a string containing a number, or the name of an enum/bitmask value. diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index 596f65bea5..9fb39fa06f 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -594,8 +594,6 @@ def decorate(name, typ, arg): return typ + ' * ' + name elif arg.annotation == 'const*': return typ + ' const * ' + name - elif arg.annotation == 'const*const*': - return 'const ' + typ + '* const * ' + name else: assert False diff --git a/generator/templates/api_cpp.h b/generator/templates/api_cpp.h index c70e82720e..cc61a8cf51 100644 --- a/generator/templates/api_cpp.h +++ b/generator/templates/api_cpp.h @@ -140,7 +140,7 @@ namespace {{metadata.namespace}} { }; {% macro render_cpp_default_value(member, is_struct=True) -%} - {%- if member.annotation in ["*", "const*", "const*const*"] and member.optional -%} + {%- if member.annotation in ["*", "const*"] and member.optional -%} {{" "}}= nullptr {%- elif member.type.category == "object" and member.optional and is_struct -%} {{" "}}= nullptr diff --git a/generator/templates/dawn_native/wgpu_structs.h b/generator/templates/dawn_native/wgpu_structs.h index 6085793a2b..acaed3a853 100644 --- a/generator/templates/dawn_native/wgpu_structs.h +++ b/generator/templates/dawn_native/wgpu_structs.h @@ -21,7 +21,7 @@ namespace dawn_native { {% macro render_cpp_default_value(member) -%} - {%- if member.annotation in ["*", "const*", "const*const*"] and member.optional -%} + {%- if member.annotation in ["*", "const*"] and member.optional -%} {{" "}}= nullptr {%- elif member.type.category == "object" and member.optional -%} {{" "}}= nullptr diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp index b0570d0546..e6d95046f7 100644 --- a/generator/templates/dawn_wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -65,11 +65,7 @@ WIRE_TRY(provider.Get{{Optional}}Id({{in}}, &{{out}})); {% elif member.type.category == "structure"%} {%- set Provider = ", provider" if member.type.may_have_dawn_object else "" -%} - {% if member.annotation == "const*const*" %} - WIRE_TRY({{as_cType(member.type.name)}}Serialize(*{{in}}, &{{out}}, buffer{{Provider}})); - {% else %} - WIRE_TRY({{as_cType(member.type.name)}}Serialize({{in}}, &{{out}}, buffer{{Provider}})); - {% endif %} + WIRE_TRY({{as_cType(member.type.name)}}Serialize({{in}}, &{{out}}, buffer{{Provider}})); {%- else -%} {{out}} = {{in}}; {%- endif -%} @@ -178,12 +174,8 @@ //* Structures might contain more pointers so we need to add their extra size as well. {% if member.type.category == "structure" %} for (decltype(memberLength) i = 0; i < memberLength; ++i) { - {% if member.annotation == "const*const*" %} - result += {{as_cType(member.type.name)}}GetExtraRequiredSize(*record.{{as_varName(member.name)}}[i]); - {% else %} - {{assert(member.annotation == "const*")}} - result += {{as_cType(member.type.name)}}GetExtraRequiredSize(record.{{as_varName(member.name)}}[i]); - {% endif %} + {{assert(member.annotation == "const*")}} + result += {{as_cType(member.type.name)}}GetExtraRequiredSize(record.{{as_varName(member.name)}}[i]); } {% endif %} {% elif member.type.category == "structure" %} @@ -383,20 +375,7 @@ {{as_cType(member.type.name)}}* copiedMembers; WIRE_TRY(GetSpace(allocator, memberLength, &copiedMembers)); - {% if member.annotation == "const*const*" %} - {{as_cType(member.type.name)}}** pointerArray; - WIRE_TRY(GetSpace(allocator, memberLength, &pointerArray)); - - //* This loop cannot overflow because it iterates up to |memberLength|. Even if - //* memberLength were the maximum integer value, |i| would become equal to it just before - //* exiting the loop, but not increment past or wrap around. - for (decltype(memberLength) i = 0; i < memberLength; ++i) { - pointerArray[i] = &copiedMembers[i]; - } - record->{{memberName}} = pointerArray; - {% else %} - record->{{memberName}} = copiedMembers; - {% endif %} + record->{{memberName}} = copiedMembers; {% if member.type.is_wire_transparent %} //* memcpy is not allowed to copy from volatile objects. However, these arrays