2018-07-25 15:03:23 +00:00
|
|
|
//* Copyright 2018 The Dawn Authors
|
|
|
|
//*
|
|
|
|
//* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
//* you may not use this file except in compliance with the License.
|
|
|
|
//* You may obtain a copy of the License at
|
|
|
|
//*
|
|
|
|
//* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//*
|
|
|
|
//* Unless required by applicable law or agreed to in writing, software
|
|
|
|
//* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
//* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//* See the License for the specific language governing permissions and
|
|
|
|
//* limitations under the License.
|
|
|
|
|
2021-12-21 03:27:34 +00:00
|
|
|
{% set impl_dir = metadata.impl_dir + "/" if metadata.impl_dir else "" %}
|
2022-01-12 09:17:35 +00:00
|
|
|
{% set namespace_name = Name(metadata.native_namespace) %}
|
|
|
|
{% set native_namespace = namespace_name.namespace_case() %}
|
|
|
|
{% set native_dir = impl_dir + namespace_name.snake_case() %}
|
2021-12-21 03:27:34 +00:00
|
|
|
{% set namespace = metadata.namespace %}
|
|
|
|
#include "{{native_dir}}/{{namespace}}_structs_autogen.h"
|
2018-07-25 15:03:23 +00:00
|
|
|
|
2021-09-28 01:04:10 +00:00
|
|
|
#include <tuple>
|
|
|
|
|
2021-09-23 17:34:53 +00:00
|
|
|
#ifdef __GNUC__
|
2021-12-21 03:27:34 +00:00
|
|
|
// error: 'offsetof' within non-standard-layout type '{{namespace}}::XXX' is conditionally-supported
|
2021-09-23 17:34:53 +00:00
|
|
|
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
|
|
|
#endif
|
|
|
|
|
2021-12-21 03:27:34 +00:00
|
|
|
namespace {{native_namespace}} {
|
2018-07-25 15:03:23 +00:00
|
|
|
|
2021-12-21 03:27:34 +00:00
|
|
|
{% set c_prefix = metadata.c_prefix %}
|
|
|
|
static_assert(sizeof(ChainedStruct) == sizeof({{c_prefix}}ChainedStruct),
|
2020-01-15 09:54:42 +00:00
|
|
|
"sizeof mismatch for ChainedStruct");
|
2021-12-21 03:27:34 +00:00
|
|
|
static_assert(alignof(ChainedStruct) == alignof({{c_prefix}}ChainedStruct),
|
2020-01-15 09:54:42 +00:00
|
|
|
"alignof mismatch for ChainedStruct");
|
2021-12-21 03:27:34 +00:00
|
|
|
static_assert(offsetof(ChainedStruct, nextInChain) == offsetof({{c_prefix}}ChainedStruct, next),
|
2020-01-15 09:54:42 +00:00
|
|
|
"offsetof mismatch for ChainedStruct::nextInChain");
|
2021-12-21 03:27:34 +00:00
|
|
|
static_assert(offsetof(ChainedStruct, sType) == offsetof({{c_prefix}}ChainedStruct, sType),
|
2020-01-15 09:54:42 +00:00
|
|
|
"offsetof mismatch for ChainedStruct::sType");
|
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
{% for type in by_category["structure"] %}
|
|
|
|
{% set CppType = as_cppType(type.name) %}
|
|
|
|
{% set CType = as_cType(type.name) %}
|
|
|
|
|
|
|
|
static_assert(sizeof({{CppType}}) == sizeof({{CType}}), "sizeof mismatch for {{CppType}}");
|
|
|
|
static_assert(alignof({{CppType}}) == alignof({{CType}}), "alignof mismatch for {{CppType}}");
|
|
|
|
|
|
|
|
{% if type.extensible %}
|
|
|
|
static_assert(offsetof({{CppType}}, nextInChain) == offsetof({{CType}}, nextInChain),
|
|
|
|
"offsetof mismatch for {{CppType}}::nextInChain");
|
|
|
|
{% endif %}
|
|
|
|
{% for member in type.members %}
|
|
|
|
{% set memberName = member.name.camelCase() %}
|
|
|
|
static_assert(offsetof({{CppType}}, {{memberName}}) == offsetof({{CType}}, {{memberName}}),
|
|
|
|
"offsetof mismatch for {{CppType}}::{{memberName}}");
|
|
|
|
{% endfor %}
|
|
|
|
|
2021-09-28 01:04:10 +00:00
|
|
|
bool {{CppType}}::operator==(const {{as_cppType(type.name)}}& rhs) const {
|
|
|
|
return {% if type.extensible or type.chained -%}
|
|
|
|
(nextInChain == rhs.nextInChain) &&
|
|
|
|
{%- endif %} std::tie(
|
|
|
|
{% for member in type.members %}
|
|
|
|
{{member.name.camelCase()-}}
|
|
|
|
{{ "," if not loop.last else "" }}
|
|
|
|
{% endfor %}
|
|
|
|
) == std::tie(
|
|
|
|
{% for member in type.members %}
|
|
|
|
rhs.{{member.name.camelCase()-}}
|
|
|
|
{{ "," if not loop.last else "" }}
|
|
|
|
{% endfor %}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-25 15:03:23 +00:00
|
|
|
{% endfor %}
|
2021-12-21 03:27:34 +00:00
|
|
|
} // namespace {{native_namespace}}
|