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 8/8] tools: ynl-gen: print prototypes for recursive stuff
Date: Wed, 13 Dec 2023 15:14:32 -0800	[thread overview]
Message-ID: <20231213231432.2944749-9-kuba@kernel.org> (raw)
In-Reply-To: <20231213231432.2944749-1-kuba@kernel.org>

We avoid printing forward declarations and prototypes for most
types by sorting things topologically. But if structs nest we
do need the forward declarations, there's no other way.

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

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 7176afb4a3bd..7fc1aa788f6f 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -1521,6 +1521,10 @@ _C_KW = {
     print_prototype(ri, "request")
 
 
+def put_typol_fwd(cw, struct):
+    cw.p(f'extern struct ynl_policy_nest {struct.render_name}_nest;')
+
+
 def put_typol(cw, struct):
     type_max = struct.attr_set.max_name
     cw.block_start(line=f'struct ynl_policy_attr {struct.render_name}_policy[{type_max} + 1] =')
@@ -1594,12 +1598,17 @@ _C_KW = {
     _put_enum_to_str_helper(cw, enum.render_name, map_name, 'value', enum=enum)
 
 
-def put_req_nested(ri, struct):
+def put_req_nested_prototype(ri, struct, suffix=';'):
     func_args = ['struct nlmsghdr *nlh',
                  'unsigned int attr_type',
                  f'{struct.ptr_name}obj']
 
-    ri.cw.write_func_prot('int', f'{struct.render_name}_put', func_args)
+    ri.cw.write_func_prot('int', f'{struct.render_name}_put', func_args,
+                          suffix=suffix)
+
+
+def put_req_nested(ri, struct):
+    put_req_nested_prototype(ri, struct, suffix='')
     ri.cw.block_start()
     ri.cw.write_func_lvar('struct nlattr *nest;')
 
@@ -1726,18 +1735,23 @@ _C_KW = {
     ri.cw.nl()
 
 
-def parse_rsp_nested(ri, struct):
+def parse_rsp_nested_prototype(ri, struct, suffix=';'):
     func_args = ['struct ynl_parse_arg *yarg',
                  'const struct nlattr *nested']
     for arg in struct.inherited:
         func_args.append('__u32 ' + arg)
 
+    ri.cw.write_func_prot('int', f'{struct.render_name}_parse', func_args,
+                          suffix=suffix)
+
+
+def parse_rsp_nested(ri, struct):
+    parse_rsp_nested_prototype(ri, struct, suffix='')
+
     local_vars = ['const struct nlattr *attr;',
                   f'{struct.ptr_name}dst = yarg->data;']
     init_lines = []
 
-    ri.cw.write_func_prot('int', f'{struct.render_name}_parse', func_args)
-
     _multi_parse(ri, struct, init_lines, local_vars)
 
 
@@ -2051,6 +2065,10 @@ _C_KW = {
     ri.cw.nl()
 
 
+def free_rsp_nested_prototype(ri):
+        print_free_prototype(ri, "")
+
+
 def free_rsp_nested(ri, struct):
     _free_type(ri, "", struct)
 
@@ -2818,7 +2836,14 @@ _C_KW = {
                     put_enum_to_str(parsed, cw, const)
             cw.nl()
 
+            has_recursive_nests = False
             cw.p('/* Policies */')
+            for struct in parsed.pure_nested_structs.values():
+                if struct.recursive:
+                    put_typol_fwd(cw, struct)
+                    has_recursive_nests = True
+            if has_recursive_nests:
+                cw.nl()
             for name in parsed.pure_nested_structs:
                 struct = Struct(parsed, name)
                 put_typol(cw, struct)
@@ -2827,6 +2852,15 @@ _C_KW = {
                 put_typol(cw, struct)
 
             cw.p('/* Common nested types */')
+            if has_recursive_nests:
+                for attr_set, struct in parsed.pure_nested_structs.items():
+                    ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
+                    free_rsp_nested_prototype(ri)
+                    if struct.request:
+                        put_req_nested_prototype(ri, struct)
+                    if struct.reply:
+                        parse_rsp_nested_prototype(ri, struct)
+                cw.nl()
             for attr_set, struct in parsed.pure_nested_structs.items():
                 ri = RenderInfo(cw, parsed, args.mode, "", "", attr_set)
 
-- 
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 ` [PATCH net-next 5/8] tools: ynl-gen: record information about recursive nests Jakub Kicinski
2023-12-14 11:02   ` 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 ` Jakub Kicinski [this message]
2023-12-14 11:11   ` [PATCH net-next 8/8] tools: ynl-gen: print prototypes for recursive stuff 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-9-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).