fix: address clang-tidy warnings (#5915)

This commit is contained in:
nerix
2025-02-07 19:22:10 +01:00
committed by GitHub
parent f37676fe1c
commit 9092f246fc
19 changed files with 333 additions and 146 deletions
+29 -1
View File
@@ -28,18 +28,46 @@ def get_type_name(type: clang.cindex.Type, namespace: tuple[str, ...]) -> str:
return type_name
def _get_template_name(type: clang.cindex.Type) -> str:
type = type.get_canonical()
if type.get_num_template_arguments() < 1:
return type.spelling
name: str = type.spelling
if type.is_const_qualified():
name.removeprefix("const ")
return name[: name.index("<")]
def _is_chrono_like_type(type: clang.cindex.Type) -> bool:
return _get_template_name(type) in ("std::chrono::time_point", "std::chrono::duration")
# clang's C API doesn't expose this, so we emulate it
def _is_trivially_copyable(type: clang.cindex.Type) -> bool:
# remove optional wrapper(s)
type = type.get_canonical()
while type.get_num_template_arguments() and _get_template_name(type) == "std::optional":
type = type.get_template_argument_type(0).get_canonical()
if type.is_pod():
return True
return _is_chrono_like_type(type)
class Member:
def __init__(
self,
name: str,
member_type: MemberType = MemberType.BASIC,
type_name: str = "?",
trivial: bool = False,
) -> None:
self.name = name
self.json_name = name
self.member_type = member_type
self.type_name = type_name
self.tag: Optional[str] = None
self.trivial = trivial
self.dont_fail_on_deserialization: bool = False
@@ -124,7 +152,7 @@ class Member:
if overwrite_member_type is not None:
member_type = overwrite_member_type
member = Member(name, member_type, type_name)
member = Member(name, member_type, type_name, _is_trivially_copyable(node.type))
if node.raw_comment is not None:
comment_commands = parse_comment_commands(node.raw_comment)
@@ -1,5 +1,5 @@
boost::json::result_for<{{enum.full_name}}, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<{{enum.full_name}}>, const boost::json::value &jvRoot)
boost::json::try_value_to_tag<{{enum.full_name}}> /* tag */, const boost::json::value &jvRoot)
{
if (!jvRoot.is_string())
{
@@ -21,7 +21,11 @@ if (jv{{field.name}} != nullptr && !jv{{field.name}}->is_null())
{
return t{{field.name}}.error();
}
{% if field.trivial -%}
{{field.name}} = t{{field.name}}.value();
{%- else -%}
{{field.name}} = std::move(t{{field.name}}.value());
{%- endif %}
{% endif %}
}
@@ -6,7 +6,7 @@ if (jv{{field.name}} == nullptr)
{
{% include 'error-missing-field.tmpl' indent content %}
}
const auto {{field.name}} = boost::json::try_value_to<std::vector<{{field.type_name}}>>(*jv{{field.name}});
auto {{field.name}} = boost::json::try_value_to<std::vector<{{field.type_name}}>>(*jv{{field.name}});
if ({{field.name}}.has_error())
{
{% include 'error-failed-to-deserialize.tmpl' indent content %}
@@ -1 +1,5 @@
{%- if field.trivial -%}
.{{field.name}} = {{field.name}}.value(),
{%- else -%}
.{{field.name}} = std::move({{field.name}}.value()),
{%- endif -%}
@@ -1 +1,5 @@
{%- if field.trivial -%}
.{{field.name}} = {{field.name}},
{%- else -%}
.{{field.name}} = std::move({{field.name}}),
{%- endif -%}
@@ -1 +1 @@
.{{field.name}} = {{field.name}}.value(),
.{{field.name}} = std::move({{field.name}}.value()),
@@ -1,5 +1,5 @@
boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invoke(
boost::json::try_value_to_tag<{{struct.full_name}}>, const boost::json::value &jvRoot)
boost::json::try_value_to_tag<{{struct.full_name}}> /* tag */, const boost::json::value &jvRoot)
{
{% if struct.inner_root %}
if (!jvRoot.is_object())
@@ -18,7 +18,7 @@ boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invo
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
}
const auto &root = jvInnerRoot->get_object();
{% else %}
{% elif struct.members|length %}
if (!jvRoot.is_object())
{
EVENTSUB_BAIL_HERE(error::Kind::ExpectedObject);
@@ -27,6 +27,9 @@ boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invo
{% endif %}
{% for field in struct.members %}
{% if field.trivial -%}
static_assert(std::is_trivially_copyable_v<std::remove_reference_t<decltype(std::declval<{{struct.full_name}}>().{{field.name}})>>);
{%- endif -%}
{% if field.member_type == MemberType.BASIC -%}
{% include 'field-basic.tmpl' indent content %}
{%- elif field.member_type == MemberType.VECTOR -%}