From 56a92fb03e2690c6db2e6229a1bc8acba1298f0d Mon Sep 17 00:00:00 2001
From: Alina Lenk <alina.v.lenk@gmail.com>
Date: Wed, 20 Jul 2022 16:30:50 +0200
Subject: [PATCH 06/12] generate_packets.py: move delta_stats_report()
 generation into PacketsDefinition

See osdn#45171

Signed-off-by: Alina Lenk <alina.v.lenk@gmail.com>
---
 common/generate_packets.py | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/common/generate_packets.py b/common/generate_packets.py
index bbc1ef55c1..e6c735f96a 100755
--- a/common/generate_packets.py
+++ b/common/generate_packets.py
@@ -2370,28 +2370,28 @@ class PacketsDefinition(typing.Iterable[Packet]):
 const char *const packet_functional_capability = "%s";
 """ % " ".join(sorted(self.all_caps))
 
-
-# Returns a code fragment which is the implementation of the
-# delta_stats_report() function.
-def get_report(packets: typing.Iterable[Packet]) -> str:
-    if not generate_stats: return """\
+    @property
+    def code_delta_stats_report(self) -> str:
+        """Code fragment implementing the delta_stats_report() function"""
+        if not generate_stats: return """\
 void delta_stats_report(void) {}
 
 """
 
-    intro = """\
+        intro = """\
 void delta_stats_report(void) {
   int i;
 """
-    extro = """\
+        extro = """\
 }
 
 """
-    body = "".join(
-        prefix("  ", packet.get_report_part())
-        for packet in packets
-    )
-    return intro+body+extro
+        body = "".join(
+            prefix("  ", packet.get_report_part())
+            for packet in self
+        )
+        return intro + body + extro
+
 
 # Returns a code fragment which is the implementation of the
 # delta_stats_reset() function.
@@ -2739,7 +2739,7 @@ static int stats_total_sent;
             for p in packets:
                 output_c.write(p.get_stats())
             # write report()
-        output_c.write(get_report(packets))
+        output_c.write(packets.code_delta_stats_report)
         output_c.write(get_reset(packets))
 
         output_c.write(get_packet_name(packets))
-- 
2.34.1