Niceify formatting in webgpu_cpp

Since now there's a copy (slightly hand-modified) saved into
Emscripten: https://github.com/emscripten-core/emscripten/pull/11737

Bug: None
Change-Id: I2677400f9e69a7fcd71f89bdaa04c642be357151
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/26005
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Kai Ninomiya 2020-07-30 19:02:43 +00:00 committed by Commit Bot service account
parent 0d9fce100d
commit 05863e62f3
2 changed files with 19 additions and 15 deletions

View File

@ -11,37 +11,39 @@
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and //* See the License for the specific language governing permissions and
//* limitations under the License. //* limitations under the License.
#include "dawn/webgpu_cpp.h" #include "dawn/webgpu_cpp.h"
namespace wgpu { namespace wgpu {
{% for type in by_category["enum"] %} {% for type in by_category["enum"] %}
{% set CppType = as_cppType(type.name) %} {% set CppType = as_cppType(type.name) %}
{% set CType = as_cType(type.name) %} {% set CType = as_cType(type.name) %}
// {{CppType}}
static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}"); static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}"); static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
{% for value in type.values %} {% for value in type.values %}
static_assert(static_cast<uint32_t>({{CppType}}::{{as_cppEnum(value.name)}}) == {{as_cEnum(type.name, value.name)}}, "value mismatch for {{CppType}}::{{as_cppEnum(value.name)}}"); static_assert(static_cast<uint32_t>({{CppType}}::{{as_cppEnum(value.name)}}) == {{as_cEnum(type.name, value.name)}}, "value mismatch for {{CppType}}::{{as_cppEnum(value.name)}}");
{% endfor %} {% endfor %}
{% endfor -%}
{% endfor %}
{% for type in by_category["bitmask"] %} {% for type in by_category["bitmask"] %}
{% set CppType = as_cppType(type.name) %} {% set CppType = as_cppType(type.name) %}
{% set CType = as_cType(type.name) + "Flags" %} {% set CType = as_cType(type.name) + "Flags" %}
// {{CppType}}
static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}"); static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}"); static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
{% for value in type.values %} {% for value in type.values %}
static_assert(static_cast<uint32_t>({{CppType}}::{{as_cppEnum(value.name)}}) == {{as_cEnum(type.name, value.name)}}, "value mismatch for {{CppType}}::{{as_cppEnum(value.name)}}"); static_assert(static_cast<uint32_t>({{CppType}}::{{as_cppEnum(value.name)}}) == {{as_cEnum(type.name, value.name)}}, "value mismatch for {{CppType}}::{{as_cppEnum(value.name)}}");
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
// ChainedStruct
static_assert(sizeof(ChainedStruct) == sizeof(WGPUChainedStruct), static_assert(sizeof(ChainedStruct) == sizeof(WGPUChainedStruct),
"sizeof mismatch for ChainedStruct"); "sizeof mismatch for ChainedStruct");
static_assert(alignof(ChainedStruct) == alignof(WGPUChainedStruct), static_assert(alignof(ChainedStruct) == alignof(WGPUChainedStruct),
@ -50,11 +52,12 @@ namespace wgpu {
"offsetof mismatch for ChainedStruct::nextInChain"); "offsetof mismatch for ChainedStruct::nextInChain");
static_assert(offsetof(ChainedStruct, sType) == offsetof(WGPUChainedStruct, sType), static_assert(offsetof(ChainedStruct, sType) == offsetof(WGPUChainedStruct, sType),
"offsetof mismatch for ChainedStruct::sType"); "offsetof mismatch for ChainedStruct::sType");
{% for type in by_category["structure"] %} {% for type in by_category["structure"] %}
{% set CppType = as_cppType(type.name) %} {% set CppType = as_cppType(type.name) %}
{% set CType = as_cType(type.name) %} {% set CType = as_cType(type.name) %}
// {{CppType}}
static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}"); static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}"); static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
@ -67,17 +70,18 @@ namespace wgpu {
static_assert(offsetof({{CppType}}, {{memberName}}) == offsetof({{CType}}, {{memberName}}), static_assert(offsetof({{CppType}}, {{memberName}}) == offsetof({{CType}}, {{memberName}}),
"offsetof mismatch for {{CppType}}::{{memberName}}"); "offsetof mismatch for {{CppType}}::{{memberName}}");
{% endfor %} {% endfor %}
{% endfor -%}
{% endfor %}
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
{% set CppType = as_cppType(type.name) %} {% set CppType = as_cppType(type.name) %}
{% set CType = as_cType(type.name) %} {% set CType = as_cType(type.name) %}
// {{CppType}}
static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}"); static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}"); static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
{% macro render_cpp_method_declaration(type, method) %} {% macro render_cpp_method_declaration(type, method) -%}
{% set CppType = as_cppType(type.name) %} {% set CppType = as_cppType(type.name) %}
{{as_cppType(method.return_type.name)}} {{CppType}}::{{method.name.CamelCase()}}( {{as_cppType(method.return_type.name)}} {{CppType}}::{{method.name.CamelCase()}}(
{%- for arg in method.arguments -%} {%- for arg in method.arguments -%}
@ -89,9 +93,9 @@ namespace wgpu {
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
) const ) const
{%- endmacro %} {%- endmacro -%}
{% macro render_cpp_to_c_method_call(type, method) -%} {%- macro render_cpp_to_c_method_call(type, method) -%}
{{as_cMethod(type.name, method.name)}}(Get() {{as_cMethod(type.name, method.name)}}(Get()
{%- for arg in method.arguments -%},{{" "}} {%- for arg in method.arguments -%},{{" "}}
{%- if arg.annotation == "value" -%} {%- if arg.annotation == "value" -%}
@ -109,9 +113,9 @@ namespace wgpu {
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
) )
{%- endmacro %} {%- endmacro -%}
{% for method in type.methods %} {% for method in type.methods -%}
{{render_cpp_method_declaration(type, method)}} { {{render_cpp_method_declaration(type, method)}} {
{% if method.return_type.name.concatcase() == "void" %} {% if method.return_type.name.concatcase() == "void" %}
{{render_cpp_to_c_method_call(type, method)}}; {{render_cpp_to_c_method_call(type, method)}};
@ -131,9 +135,10 @@ namespace wgpu {
{{as_cMethod(type.name, Name("release"))}}(handle); {{as_cMethod(type.name, Name("release"))}}(handle);
} }
} }
{% endfor %} {% endfor %}
// Instance
Instance CreateInstance(const InstanceDescriptor* descriptor) { Instance CreateInstance(const InstanceDescriptor* descriptor) {
const WGPUInstanceDescriptor* cDescriptor = const WGPUInstanceDescriptor* cDescriptor =
reinterpret_cast<const WGPUInstanceDescriptor*>(descriptor); reinterpret_cast<const WGPUInstanceDescriptor*>(descriptor);

View File

@ -11,7 +11,6 @@
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//* See the License for the specific language governing permissions and //* See the License for the specific language governing permissions and
//* limitations under the License. //* limitations under the License.
#ifndef WEBGPU_CPP_H_ #ifndef WEBGPU_CPP_H_
#define WEBGPU_CPP_H_ #define WEBGPU_CPP_H_