netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	nicolas.dichtel@6wind.com, jiri@resnulli.us,
	donald.hunter@gmail.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 5/8] tools: ynl-gen: record information about recursive nests
Date: Wed, 13 Dec 2023 15:14:29 -0800	[thread overview]
Message-ID: <20231213231432.2944749-6-kuba@kernel.org> (raw)
In-Reply-To: <20231213231432.2944749-1-kuba@kernel.org>

Track which nests are recursive. Non-recursive nesting gets
rendered in C as directly nested structs. For recursive
ones we need to put a pointer in, rather than full struct.

Track this information, no change to generated code, yet.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 tools/net/ynl/ynl-gen-c.py | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 2b7961838fb6..8a2c304cd2ad 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -105,6 +105,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
     def is_scalar(self):
         return self.type in {'u8', 'u16', 'u32', 'u64', 's32', 's64'}
 
+    def is_recursive(self):
+        return False
+
     def presence_type(self):
         return 'bit'
 
@@ -529,6 +532,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
 
 
 class TypeNest(Type):
+    def is_recursive(self):
+        return self.family.pure_nested_structs[self.nested_attrs].recursive
+
     def _complex_member_type(self, ri):
         return self.nested_struct_type
 
@@ -700,9 +706,12 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
         if self.nested and space_name in family.consts:
             self.struct_name += '_'
         self.ptr_name = self.struct_name + ' *'
+        # All attr sets this one contains, directly or multiple levels down
+        self.child_nests = set()
 
         self.request = False
         self.reply = False
+        self.recursive = False
 
         self.attr_list = []
         self.attrs = dict()
@@ -1059,14 +1068,20 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
                 pns_key_seen.add(name)
             else:
                 pns_key_list.append(name)
-        # Propagate the request / reply
+        # Propagate the request / reply / recursive
         for attr_set, struct in reversed(self.pure_nested_structs.items()):
             for _, spec in self.attr_sets[attr_set].items():
                 if 'nested-attributes' in spec:
-                    child = self.pure_nested_structs.get(spec['nested-attributes'])
+                    child_name = spec['nested-attributes']
+                    struct.child_nests.add(child_name)
+                    child = self.pure_nested_structs.get(child_name)
                     if child:
+                        if not child.recursive:
+                            struct.child_nests.update(child.child_nests)
                         child.request |= struct.request
                         child.reply |= struct.reply
+                if attr_set in struct.child_nests:
+                    struct.recursive = True
 
     def _load_attr_use(self):
         for _, struct in self.pure_nested_structs.items():
-- 
2.43.0


  parent reply	other threads:[~2023-12-13 23:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-13 23:14 [PATCH net-next 0/8] tools: ynl-gen: fill in the gaps in support of legacy families Jakub Kicinski
2023-12-13 23:14 ` [PATCH net-next 1/8] tools: ynl-gen: add missing request free helpers for dumps Jakub Kicinski
2023-12-14 10:21   ` Donald Hunter
2023-12-13 23:14 ` [PATCH net-next 2/8] tools: ynl-gen: use enum user type for members and args Jakub Kicinski
2023-12-14 10:26   ` Donald Hunter
2023-12-13 23:14 ` [PATCH net-next 3/8] tools: ynl-gen: support fixed headers in genetlink Jakub Kicinski
2023-12-14 10:57   ` Donald Hunter
2023-12-13 23:14 ` [PATCH net-next 4/8] tools: ynl-gen: fill in implementations for TypeUnused Jakub Kicinski
2023-12-14 10:58   ` Donald Hunter
2023-12-13 23:14 ` Jakub Kicinski [this message]
2023-12-14 11:02   ` [PATCH net-next 5/8] tools: ynl-gen: record information about recursive nests Donald Hunter
2023-12-13 23:14 ` [PATCH net-next 6/8] tools: ynl-gen: re-sort ignoring " Jakub Kicinski
2023-12-14 11:12   ` Donald Hunter
2023-12-13 23:14 ` [PATCH net-next 7/8] tools: ynl-gen: store recursive nests by a pointer Jakub Kicinski
2023-12-14 11:11   ` Donald Hunter
2023-12-13 23:14 ` [PATCH net-next 8/8] tools: ynl-gen: print prototypes for recursive stuff Jakub Kicinski
2023-12-14 11:11   ` Donald Hunter
2023-12-15  2:01 ` [PATCH net-next 0/8] tools: ynl-gen: fill in the gaps in support of legacy families patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231213231432.2944749-6-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@google.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.dichtel@6wind.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).