From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Linux Doc Mailing List <linux-doc@vger.kernel.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH v6 2/6] kernel-doc: add support to handle DEFINE_ variables
Date: Tue, 16 Dec 2025 15:19:24 +0100 [thread overview]
Message-ID: <757a45100cfc493984574ff780aa9d90506eecb4.1765894670.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1765894670.git.mchehab+huawei@kernel.org>
Improve the parser and output plugin to work with macros,
adding support for the common pattern of using DEFINE_*
to create variables.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
tools/lib/python/kdoc/kdoc_output.py | 5 ++---
tools/lib/python/kdoc/kdoc_parser.py | 25 +++++++++++++++++++++----
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/tools/lib/python/kdoc/kdoc_output.py b/tools/lib/python/kdoc/kdoc_output.py
index 50aedbb3d6de..d2bf94275d65 100644
--- a/tools/lib/python/kdoc/kdoc_output.py
+++ b/tools/lib/python/kdoc/kdoc_output.py
@@ -486,7 +486,7 @@ class RestFormat(OutputFormat):
self.lineprefix = " "
- self.data += f"\n\n.. c:macro:: {name}\n\n{self.lineprefix}{full_proto}\n\n"
+ self.data += f"\n\n.. c:macro:: {name}\n\n{self.lineprefix}``{full_proto}``\n\n"
self.print_lineno(ln)
self.output_highlight(args.get('purpose', ''))
@@ -801,13 +801,12 @@ class ManFormat(OutputFormat):
def out_var(self, fname, name, args):
out_name = self.arg_name(args, name)
- prototype = args.other_stuff["var_type"]
full_proto = args.other_stuff["full_proto"]
self.data += f'.TH "{self.modulename}" 9 "{out_name}" "{self.man_date}" "API Manual" LINUX' + "\n"
self.data += ".SH NAME\n"
- self.data += f"{prototype} \\- {args['purpose']}\n"
+ self.data += f"{name} \\- {args['purpose']}\n"
self.data += ".SH SYNOPSIS\n"
self.data += f"{full_proto}\n"
diff --git a/tools/lib/python/kdoc/kdoc_parser.py b/tools/lib/python/kdoc/kdoc_parser.py
index 06bed1a12a45..aaa352855717 100644
--- a/tools/lib/python/kdoc/kdoc_parser.py
+++ b/tools/lib/python/kdoc/kdoc_parser.py
@@ -949,12 +949,27 @@ class KernelDoc:
# Store the full prototype before modifying it
#
full_proto = proto
+ declaration_name = None
+
+ #
+ # Handle macro definitions
+ #
+ macro_prefixes = [
+ KernRe(r"DEFINE_[\w_]+\s*\(([\w_]+)\)"),
+ ]
+
+ for r in macro_prefixes:
+ match = r.search(proto)
+ if match:
+ declaration_name = match.group(1)
+ break
#
# Drop comments and macros to have a pure C prototype
#
- for search, sub in sub_prefixes:
- proto = search.sub(sub, proto)
+ if not declaration_name:
+ for r, sub in sub_prefixes:
+ proto = r.sub(sub, proto)
proto = proto.rstrip()
@@ -968,14 +983,16 @@ class KernelDoc:
return
var_type = r.group(0)
- declaration_name = r.group(1)
+
+ if not declaration_name:
+ declaration_name = r.group(1)
+
default_val = r.group(2)
if default_val:
default_val = default_val.lstrip("=").strip()
self.output_declaration("var", declaration_name,
full_proto=full_proto,
- var_type=var_type,
default_val=default_val,
purpose=self.entry.declaration_purpose)
--
2.52.0
next prev parent reply other threads:[~2025-12-16 14:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-16 14:19 [PATCH v6 0/6] kernel-doc: add support for documenting vars Mauro Carvalho Chehab
2025-12-16 14:19 ` [PATCH v6 1/6] kernel-doc: add support for handling global variables Mauro Carvalho Chehab
2025-12-16 14:19 ` Mauro Carvalho Chehab [this message]
2025-12-16 14:19 ` [PATCH v6 3/6] docs: media: v4l2-ioctl.h: document two " Mauro Carvalho Chehab
2025-12-16 14:19 ` [PATCH v6 4/6] docs: kernel-doc.rst: don't let automarkup mangle with consts Mauro Carvalho Chehab
2025-12-16 14:19 ` [PATCH v6 5/6] docs: kernel-doc.rst: document the new "var" kernel-doc markup Mauro Carvalho Chehab
2025-12-16 14:19 ` [PATCH v6 6/6] docs: kernel-doc.rst: Parse DEFINE_ macros without prefixes Mauro Carvalho Chehab
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=757a45100cfc493984574ff780aa9d90506eecb4.1765894670.git.mchehab+huawei@kernel.org \
--to=mchehab+huawei@kernel.org \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
/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
all inboxes | Powered by JetHome®