From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
jiri@resnulli.us, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 07/11] tools: ynl-gen: walk nested types in depth
Date: Wed, 7 Jun 2023 13:23:59 -0700 [thread overview]
Message-ID: <20230607202403.1089925-8-kuba@kernel.org> (raw)
In-Reply-To: <20230607202403.1089925-1-kuba@kernel.org>
So far we had only created structures for nested types nested
directly in messages (second level of attrs so to speak).
Walk types in depth to support deeper nesting.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/ynl-gen-c.py | 41 +++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 1a97cd517116..0cb0f74e714b 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -854,27 +854,44 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
self.root_sets[op['attribute-set']]['reply'].update(rsp_attrs)
def _load_nested_sets(self):
+ attr_set_queue = list(self.root_sets.keys())
+ attr_set_seen = set(self.root_sets.keys())
+
+ while len(attr_set_queue):
+ a_set = attr_set_queue.pop(0)
+ for attr, spec in self.attr_sets[a_set].items():
+ if 'nested-attributes' not in spec:
+ continue
+
+ nested = spec['nested-attributes']
+ if nested not in attr_set_seen:
+ attr_set_queue.append(nested)
+ attr_set_seen.add(nested)
+
+ inherit = set()
+ if nested not in self.root_sets:
+ if nested not in self.pure_nested_structs:
+ self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
+ else:
+ raise Exception(f'Using attr set as root and nested not supported - {nested}')
+
+ if 'type-value' in spec:
+ if nested in self.root_sets:
+ raise Exception("Inheriting members to a space used as root not supported")
+ inherit.update(set(spec['type-value']))
+ elif spec['type'] == 'array-nest':
+ inherit.add('idx')
+ self.pure_nested_structs[nested].set_inherited(inherit)
+
for root_set, rs_members in self.root_sets.items():
for attr, spec in self.attr_sets[root_set].items():
if 'nested-attributes' in spec:
- inherit = set()
nested = spec['nested-attributes']
- if nested not in self.root_sets:
- if nested not in self.pure_nested_structs:
- self.pure_nested_structs[nested] = Struct(self, nested, inherited=inherit)
if attr in rs_members['request']:
self.pure_nested_structs[nested].request = True
if attr in rs_members['reply']:
self.pure_nested_structs[nested].reply = True
- if 'type-value' in spec:
- if nested in self.root_sets:
- raise Exception("Inheriting members to a space used as root not supported")
- inherit.update(set(spec['type-value']))
- elif spec['type'] == 'array-nest':
- inherit.add('idx')
- self.pure_nested_structs[nested].set_inherited(inherit)
-
# Try to reorder according to dependencies
pns_key_list = list(self.pure_nested_structs.keys())
pns_key_seen = set()
--
2.40.1
next prev parent reply other threads:[~2023-06-07 20:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 20:23 [PATCH net-next 00/11] tools: ynl: generate code for the devlink family Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 01/11] netlink: specs: devlink: fill in some details important for C Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 02/11] tools: ynl-gen: use enum names in op strmap more carefully Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 03/11] tools: ynl-gen: refactor strmap helper generation Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 04/11] tools: ynl-gen: enable code gen for directional specs Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 05/11] tools: ynl-gen: try to sort the types more intelligently Jakub Kicinski
2023-06-07 20:23 ` [PATCH net-next 06/11] tools: ynl-gen: inherit struct use info Jakub Kicinski
2023-06-07 20:23 ` Jakub Kicinski [this message]
2023-06-07 20:24 ` [PATCH net-next 08/11] tools: ynl-gen: don't generate forward declarations for policies Jakub Kicinski
2023-06-07 20:24 ` [PATCH net-next 09/11] tools: ynl-gen: don't generate forward declarations for policies - regen Jakub Kicinski
2023-06-07 20:24 ` [PATCH net-next 10/11] tools: ynl: generate code for the devlink family Jakub Kicinski
2023-06-08 11:48 ` Simon Horman
2023-06-08 15:53 ` Jakub Kicinski
2023-06-09 7:46 ` Simon Horman
2023-06-07 20:24 ` [PATCH net-next 11/11] tools: ynl: add sample for devlink Jakub Kicinski
2023-06-08 21:10 ` [PATCH net-next 00/11] tools: ynl: generate code for the devlink family 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=20230607202403.1089925-8-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--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).