public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Jonathan Corbet <corbet@lwn.net>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>,
	Kees Cook <kees@kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>,
	bpf@vger.kernel.org, intel-wired-lan@lists.osuosl.org,
	linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Stanislav Fomichev <sdf@fomichev.me>
Subject: [PATCH v3 00/30]  kernel-doc: make it parse new functions and structs
Date: Thu, 29 Jan 2026 09:07:51 +0100	[thread overview]
Message-ID: <cover.1769673038.git.mchehab+huawei@kernel.org> (raw)


Hi Jon,

And the size grew again: it is now 31 patches...

This is still based on next-20260127.

On this version, I created a new "CFunction" class, with is
just an alias for "NestedMatch" class, meant to simplify the
logic and maintainership for Linux Kernel macros that require
transforms.

With that, a transform list (for instance to cleanup structs)
become a lot simpler and easier to understand:

    #: Transforms for structs and unions
    struct_xforms = [
        (CFunction("__attribute__"), ' '),
        (CFunction('__aligned'), ' '),
        (CFunction('__counted_by'), ' '),
        (CFunction('__counted_by_(le|be)'), ' '),
        (CFunction('__guarded_by'), ' '),
        (CFunction('__pt_guarded_by'), ' '),

        (KernRe(r'\s*__packed\s*', re.S), ' '),
        (KernRe(r'\s*CRYPTO_MINALIGN_ATTR', re.S), ' '),
        (KernRe(r'\s*__private', re.S), ' '),
        (KernRe(r'\s*__rcu', re.S), ' '),
        (KernRe(r'\s*____cacheline_aligned_in_smp', re.S), ' '),
        (KernRe(r'\s*____cacheline_aligned', re.S), ' '),

        (CFunction('__cacheline_group_(begin|end)'), ''),

        (CFunction('struct_group'), r'\2'),
        (CFunction('struct_group_attr'), r'\3'),
        (CFunction('struct_group_tagged'), r'struct \1 \2; \3'),
        (CFunction('__struct_group'), r'\4'),

        (CFunction('__ETHTOOL_DECLARE_LINK_MODE_MASK'), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'),
        (CFunction('DECLARE_PHY_INTERFACE_MASK',), r'DECLARE_BITMAP(\1, PHY_INTERFACE_MODE_MAX)'),
        (CFunction('DECLARE_BITMAP'), r'unsigned long \1[BITS_TO_LONGS(\2)]'),

        (CFunction('DECLARE_HASHTABLE'), r'unsigned long \1[1 << ((\2) - 1)]'),
        (CFunction('DECLARE_KFIFO'), r'\2 *\1'),
        (CFunction('DECLARE_KFIFO_PTR'), r'\2 *\1'),
        (CFunction('(?:__)?DECLARE_FLEX_ARRAY'), r'\1 \2[]'),
        (CFunction('DEFINE_DMA_UNMAP_ADDR'), r'dma_addr_t \1'),
        (CFunction('DEFINE_DMA_UNMAP_LEN'), r'__u32 \1'),
        (CFunction('VIRTIO_DECLARE_FEATURES'), r'union { u64 \1; u64 \1_array[VIRTIO_FEATURES_U64S]; }'),
    ]

(that is the entire set of struct transforms).

I also moved the transforms to a single separate module,
placed at: tools/lib/python/kdoc/xforms_lists.py.

As KernRe, CFunction and NestedMatch have a ".sub" method, a
single transforms table can have all of them altogether.

The first 15 patches on this series were co-developed with Randy,
with came up after the original patch to support sparse annotations
used by clang thread-safety-analysis.

I ended helping identifying kernel-doc issues while help testing
and addressing its and doing some changes to make the parser more
reliable.

After those, I added other patches to cleanup macro
transforms.

Even NestedMatch being more complex than KernRe, on my machine,
parsing all files is 5% faster than before, because we're not
parsing anymore macro definitions.

Ah, due to the complexity of NestedMatch, I opted to write
some unit tests to verify that the logic there is correct.
We can use it to add other border cases.

Using it is as easy as running:

	$ tools/unittests/nested_match.py

(I opted to create a separate directory for it, as this
is not really documentation)

---

v3:
- improved the unittest helper to allow adding in the future
  a runner to create a test suite directly;
- added unittest to tools/python library documentation;
- improved comments at the new modules;
- did several cleanups at the new logic;
- added a fix for NestedMatch not remove ";" at the end,
  mimicing the behavior of KernRe;
- moved transforms to a separate module;
- replaced all regexes to parse macros with the new CFunction
  alias for NestedMatch.

v2:
- added 10 new patches adding support at NestedMatch
  to properly group and replace arguments with \1, \2, ...

Mauro Carvalho Chehab (28):
  docs: kdoc_re: add support for groups()
  docs: kdoc_re: don't go past the end of a line
  docs: kdoc_parser: move var transformers to the beginning
  docs: kdoc_parser: don't mangle with function defines
  docs: kdoc_parser: add functions support for NestedMatch
  docs: kdoc_parser: use NestedMatch to handle __attribute__ on
    functions
  docs: kdoc_parser: fix variable regexes to work with size_t
  docs: kdoc_parser: fix the default_value logic for variables
  docs: kdoc_parser: add some debug for variable parsing
  docs: kdoc_parser: don't exclude defaults from prototype
  docs: kdoc_parser: fix parser to support multi-word types
  docs: kdoc_parser: add support for LIST_HEAD
  docs: kdoc_re: properly handle strings and escape chars on it
  docs: kdoc_re: better show KernRe() at documentation
  docs: kdoc_re: don't recompile NextMatch regex every time
  docs: kdoc_re: Change NestedMath args replacement to \0
  docs: kdoc_re: make NextedMatch use KernRe
  docs: kdoc_re: add support on NestedMatch for argument replacement
  docs: python: add helpers to run unit tests
  unittests: add tests for NestedMatch class
  docs: kdoc_parser: better handle struct_group macros
  docs: kdoc_re: fix a parse bug on struct page_pool_params
  docs: kdoc_re: add a helper class to declare C function matches
  docs: kdoc_parser: use the new CFunction class
  docs: kdoc_parser: minimize differences with struct_group_tagged
  docs: kdoc_parser: move transform lists to a separate file
  docs: kdoc_re: don't remove the trailing ";" with NestedMatch
  docs: xforms_lists.py: use CFuntion to handle all function macros

Randy Dunlap (2):
  docs: kdoc_parser: ignore context analysis and lock attributes
  kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name)

 Documentation/tools/kdoc_parser.rst   |   8 +
 Documentation/tools/python.rst        |   2 +
 Documentation/tools/unittest.rst      |  24 ++
 tools/lib/python/kdoc/kdoc_files.py   |   3 +-
 tools/lib/python/kdoc/kdoc_parser.py  | 182 ++------
 tools/lib/python/kdoc/kdoc_re.py      | 215 +++++++---
 tools/lib/python/kdoc/xforms_lists.py | 105 +++++
 tools/lib/python/unittest_helper.py   | 348 +++++++++++++++
 tools/unittests/nested_match.py       | 589 ++++++++++++++++++++++++++
 9 files changed, 1277 insertions(+), 199 deletions(-)
 create mode 100644 Documentation/tools/unittest.rst
 create mode 100644 tools/lib/python/kdoc/xforms_lists.py
 create mode 100755 tools/lib/python/unittest_helper.py
 create mode 100755 tools/unittests/nested_match.py

-- 
2.52.0


             reply	other threads:[~2026-01-29  8:08 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29  8:07 Mauro Carvalho Chehab [this message]
2026-01-29  8:07 ` [PATCH v3 01/30] docs: kdoc_re: add support for groups() Mauro Carvalho Chehab
2026-01-29  8:07 ` [PATCH v3 02/30] docs: kdoc_re: don't go past the end of a line Mauro Carvalho Chehab
2026-01-29  8:07 ` [PATCH v3 03/30] docs: kdoc_parser: move var transformers to the beginning Mauro Carvalho Chehab
2026-01-29 10:26   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:07 ` [PATCH v3 04/30] docs: kdoc_parser: don't mangle with function defines Mauro Carvalho Chehab
2026-01-29 10:26   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:07 ` [PATCH v3 05/30] docs: kdoc_parser: add functions support for NestedMatch Mauro Carvalho Chehab
2026-01-29 10:27   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:07 ` [PATCH v3 06/30] docs: kdoc_parser: use NestedMatch to handle __attribute__ on functions Mauro Carvalho Chehab
2026-01-29 10:27   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:07 ` [PATCH v3 07/30] docs: kdoc_parser: fix variable regexes to work with size_t Mauro Carvalho Chehab
2026-01-29 10:27   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:07 ` [PATCH v3 08/30] docs: kdoc_parser: fix the default_value logic for variables Mauro Carvalho Chehab
2026-01-29 10:28   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 09/30] docs: kdoc_parser: add some debug for variable parsing Mauro Carvalho Chehab
2026-01-29 10:28   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 10/30] docs: kdoc_parser: don't exclude defaults from prototype Mauro Carvalho Chehab
2026-01-29 10:25   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29 10:29   ` Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 11/30] docs: kdoc_parser: fix parser to support multi-word types Mauro Carvalho Chehab
2026-01-29 10:29   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 12/30] docs: kdoc_parser: ignore context analysis and lock attributes Mauro Carvalho Chehab
2026-01-29 10:30   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 13/30] docs: kdoc_parser: add support for LIST_HEAD Mauro Carvalho Chehab
2026-01-29 10:30   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 14/30] kdoc_parser: handle struct member macro VIRTIO_DECLARE_FEATURES(name) Mauro Carvalho Chehab
2026-01-29  8:08 ` [PATCH v3 15/30] docs: kdoc_re: properly handle strings and escape chars on it Mauro Carvalho Chehab
2026-01-29 10:31   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 16/30] docs: kdoc_re: better show KernRe() at documentation Mauro Carvalho Chehab
2026-01-29 10:31   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 17/30] docs: kdoc_re: don't recompile NextMatch regex every time Mauro Carvalho Chehab
2026-01-29 10:31   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 18/30] docs: kdoc_re: Change NestedMath args replacement to \0 Mauro Carvalho Chehab
2026-01-29 10:32   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 19/30] docs: kdoc_re: make NextedMatch use KernRe Mauro Carvalho Chehab
2026-01-29 10:32   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-30 11:11   ` Kwapulinski, Piotr
2026-01-29  8:08 ` [PATCH v3 20/30] docs: kdoc_re: add support on NestedMatch for argument replacement Mauro Carvalho Chehab
2026-01-29 10:33   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 21/30] docs: python: add helpers to run unit tests Mauro Carvalho Chehab
2026-01-29  8:08 ` [PATCH v3 22/30] unittests: add tests for NestedMatch class Mauro Carvalho Chehab
2026-01-29  8:08 ` [PATCH v3 23/30] docs: kdoc_parser: better handle struct_group macros Mauro Carvalho Chehab
2026-01-29 10:33   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 24/30] docs: kdoc_re: fix a parse bug on struct page_pool_params Mauro Carvalho Chehab
2026-01-29  8:08 ` [PATCH v3 25/30] docs: kdoc_re: add a helper class to declare C function matches Mauro Carvalho Chehab
2026-01-29 10:33   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 26/30] docs: kdoc_parser: use the new CFunction class Mauro Carvalho Chehab
2026-01-29 10:34   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 27/30] docs: kdoc_parser: minimize differences with struct_group_tagged Mauro Carvalho Chehab
2026-01-29 10:34   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 28/30] docs: kdoc_parser: move transform lists to a separate file Mauro Carvalho Chehab
2026-01-29 10:34   ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 29/30] docs: kdoc_re: don't remove the trailing ";" with NestedMatch Mauro Carvalho Chehab
2026-01-29 10:34   ` [Intel-wired-lan] [PATCH v3 29/30] docs: kdoc_re: don't remove the trailing "; " " Loktionov, Aleksandr
2026-01-29  8:08 ` [PATCH v3 30/30] docs: xforms_lists.py: use CFuntion to handle all function macros 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=cover.1769673038.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=aleksander.lobakin@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=gustavoars@kernel.org \
    --cc=hawk@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=john.fastabend@gmail.com \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=skhan@linuxfoundation.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