summaryrefslogtreecommitdiff
path: root/scripts/lib/kdoc
diff options
context:
space:
mode:
authorJonathan Corbet <corbet@lwn.net>2025-09-08 16:01:15 -0600
committerJonathan Corbet <corbet@lwn.net>2025-09-18 10:19:53 -0600
commit370f430527ecd35938ad94167e45fc784f6e4d95 (patch)
tree87b29dccbd2864365da90c7e88b2e8ce595da8ec /scripts/lib/kdoc
parentff1f2af341b72bd5b6b5d432da55faf2f6d24cfe (diff)
docs: kdoc: consolidate some of the macro-processing logic
The logic to handle macros is split in dump_function(); bring it all together into a single place and add a comment saying what's going on. Remove the unneeded is_define_proto variable, and tighten up the code a bit. Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Diffstat (limited to 'scripts/lib/kdoc')
-rw-r--r--scripts/lib/kdoc/kdoc_parser.py43
1 files changed, 20 insertions, 23 deletions
diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index ec2e6e83df05..27329ce9b5e9 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -926,21 +926,31 @@ class KernelDoc:
Stores a function of function macro inside self.entries array.
"""
- func_macro = False
+ found = func_macro = False
return_type = ''
decl_type = 'function'
#
# Apply the initial transformations.
#
prototype = apply_transforms(function_xforms, prototype)
-
- # Macros are a special case, as they change the prototype format
+ #
+ # If we have a macro, remove the "#define" at the front.
+ #
new_proto = KernRe(r"^#\s*define\s+").sub("", prototype)
if new_proto != prototype:
- is_define_proto = True
prototype = new_proto
- else:
- is_define_proto = False
+ #
+ # Dispense with the simple "#define A B" case here; the key
+ # is the space after the name of the symbol being defined.
+ # NOTE that the seemingly misnamed "func_macro" indicates a
+ # macro *without* arguments.
+ #
+ r = KernRe(r'^(\w+)\s+')
+ if r.search(prototype):
+ return_type = ''
+ declaration_name = r.group(1)
+ func_macro = True
+ found = True
# Yes, this truly is vile. We are looking for:
# 1. Return type (may be nothing if we're looking at a macro)
@@ -968,19 +978,10 @@ class KernelDoc:
# parenthesis.
#
proto_args = r'\(([^\(]*|.*)\)'
-
- found = False
-
- if is_define_proto:
- r = KernRe(r'^(' + name + r')\s+')
-
- if r.search(prototype):
- return_type = ''
- declaration_name = r.group(1)
- func_macro = True
-
- found = True
-
+ #
+ # (Except for the simple macro case) attempt to split up the prototype
+ # in the various ways we understand.
+ #
if not found:
patterns = [
rf'^()({name})\s*{proto_args}',
@@ -990,16 +991,12 @@ class KernelDoc:
for p in patterns:
r = KernRe(p)
-
if r.match(prototype):
-
return_type = r.group(1)
declaration_name = r.group(2)
args = r.group(3)
-
self.create_parameter_list(ln, decl_type, args, ',',
declaration_name)
-
found = True
break
if not found: