From 1b0b13f3402a90ce983e81f33f830042bfa8d2f6 Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Wed, 20 Jul 2022 16:23:20 +0200 Subject: [PATCH 04/12] generate_packets.py: move all_caps union into PacketsDefinition See osdn#45169 Signed-off-by: Alina Lenk --- common/generate_packets.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index c89b05e964..4ee349d9ff 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -2357,19 +2357,19 @@ class PacketsDefinition(typing.Iterable[Packet]): last = n return last + @property + def all_caps(self) -> "set[str]": + """Set of all capabilities affecting the defined packets""" + return set().union(*(p.all_caps for p in self)) -def all_caps_union(packets: typing.Iterable[Packet]) -> "set[str]": - """Return a set of all capabilities affecting the given packets""" - return set().union(*(p.all_caps for p in packets)) # Returns a code fragment which is the implementation of the # packet_functional_capability string. -def get_packet_functional_capability(packets: typing.Iterable[Packet]) -> str: - all_caps = all_caps_union(packets) +def get_packet_functional_capability(packets: PacketsDefinition) -> str: return """\ const char *const packet_functional_capability = "%s"; -""" % " ".join(sorted(all_caps)) +""" % " ".join(sorted(packets.all_caps)) # Returns a code fragment which is the implementation of the # delta_stats_report() function. @@ -2474,13 +2474,12 @@ bool packet_has_game_info_flag(enum packet_type type) # Returns a code fragment which is the implementation of the # packet_handlers_fill_initial() function. -def get_packet_handlers_fill_initial(packets: typing.Iterable[Packet]) -> str: +def get_packet_handlers_fill_initial(packets: PacketsDefinition) -> str: intro = """\ void packet_handlers_fill_initial(struct packet_handlers *phandlers) { """ - all_caps = all_caps_union(packets) - for cap in sorted(all_caps): + for cap in sorted(packets.all_caps): intro += """\ fc_assert_msg(has_capability("{0}", our_capability), "Packets have support for unknown '{0}' capability!"); -- 2.34.1