Add a set of comments to process_proto_function and reorganize the logic
slightly; no functional change.
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
scripts/lib/kdoc/kdoc_parser.py | 43 ++++++++++++++++++---------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py
index 61da297df623..d5ef3ce87438 100644
--- a/scripts/lib/kdoc/kdoc_parser.py
+++ b/scripts/lib/kdoc/kdoc_parser.py
@@ -1553,39 +1553,44 @@ class KernelDoc:
"""Ancillary routine to process a function prototype"""
# strip C99-style comments to end of line
- r = KernRe(r"\/\/.*$", re.S)
- line = r.sub('', line)
-
+ line = KernRe(r"\/\/.*$", re.S).sub('', line)
+ #
+ # Soak up the line's worth of prototype text, stopping at { or ; if present.
+ #
if KernRe(r'\s*#\s*define').match(line):
self.entry.prototype = line
- elif line.startswith('#'):
- # Strip other macros like #ifdef/#ifndef/#endif/...
- pass
- else:
+ elif not line.startswith('#'): # skip other preprocessor stuff
r = KernRe(r'([^\{]*)')
if r.match(line):
self.entry.prototype += r.group(1) + " "
-
+ #
+ # If we now have the whole prototype, clean it up and declare victory.
+ #
if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line):
# strip comments and surrounding spaces
- r = KernRe(r'/\*.*\*/')
- self.entry.prototype = r.sub('', self.entry.prototype).strip()
-
+ self.entry.prototype = KernRe(r'/\*.*\*/').sub('', self.entry.prototype).strip()
+ #
# Handle self.entry.prototypes for function pointers like:
# int (*pcs_config)(struct foo)
-
+ # by turning it into
+ # int pcs_config(struct foo)
+ #
r = KernRe(r'^(\S+\s+)\(\s*\*(\S+)\)')
self.entry.prototype = r.sub(r'\1\2', self.entry.prototype)
-
+ #
+ # Handle special declaration syntaxes
+ #
if 'SYSCALL_DEFINE' in self.entry.prototype:
self.entry.prototype = self.syscall_munge(ln,
self.entry.prototype)
-
- r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT')
- if r.search(self.entry.prototype):
- self.entry.prototype = self.tracepoint_munge(ln,
- self.entry.prototype)
-
+ else:
+ r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT')
+ if r.search(self.entry.prototype):
+ self.entry.prototype = self.tracepoint_munge(ln,
+ self.entry.prototype)
+ #
+ # ... and we're done
+ #
self.dump_function(ln, self.entry.prototype)
self.reset_state(ln)
--
2.49.0
Em Tue, 1 Jul 2025 14:57:28 -0600 Jonathan Corbet <corbet@lwn.net> escreveu: > Add a set of comments to process_proto_function and reorganize the logic > slightly; no functional change. > > Signed-off-by: Jonathan Corbet <corbet@lwn.net> LGTM. Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> > --- > scripts/lib/kdoc/kdoc_parser.py | 43 ++++++++++++++++++--------------- > 1 file changed, 24 insertions(+), 19 deletions(-) > > diff --git a/scripts/lib/kdoc/kdoc_parser.py b/scripts/lib/kdoc/kdoc_parser.py > index 61da297df623..d5ef3ce87438 100644 > --- a/scripts/lib/kdoc/kdoc_parser.py > +++ b/scripts/lib/kdoc/kdoc_parser.py > @@ -1553,39 +1553,44 @@ class KernelDoc: > """Ancillary routine to process a function prototype""" > > # strip C99-style comments to end of line > - r = KernRe(r"\/\/.*$", re.S) > - line = r.sub('', line) > - > + line = KernRe(r"\/\/.*$", re.S).sub('', line) > + # > + # Soak up the line's worth of prototype text, stopping at { or ; if present. > + # > if KernRe(r'\s*#\s*define').match(line): > self.entry.prototype = line > - elif line.startswith('#'): > - # Strip other macros like #ifdef/#ifndef/#endif/... > - pass > - else: > + elif not line.startswith('#'): # skip other preprocessor stuff > r = KernRe(r'([^\{]*)') > if r.match(line): > self.entry.prototype += r.group(1) + " " > - > + # > + # If we now have the whole prototype, clean it up and declare victory. > + # > if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line): > # strip comments and surrounding spaces > - r = KernRe(r'/\*.*\*/') > - self.entry.prototype = r.sub('', self.entry.prototype).strip() > - > + self.entry.prototype = KernRe(r'/\*.*\*/').sub('', self.entry.prototype).strip() > + # > # Handle self.entry.prototypes for function pointers like: > # int (*pcs_config)(struct foo) > - > + # by turning it into > + # int pcs_config(struct foo) > + # > r = KernRe(r'^(\S+\s+)\(\s*\*(\S+)\)') > self.entry.prototype = r.sub(r'\1\2', self.entry.prototype) > - > + # > + # Handle special declaration syntaxes > + # > if 'SYSCALL_DEFINE' in self.entry.prototype: > self.entry.prototype = self.syscall_munge(ln, > self.entry.prototype) > - > - r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT') > - if r.search(self.entry.prototype): > - self.entry.prototype = self.tracepoint_munge(ln, > - self.entry.prototype) > - > + else: > + r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT') > + if r.search(self.entry.prototype): > + self.entry.prototype = self.tracepoint_munge(ln, > + self.entry.prototype) > + # > + # ... and we're done > + # > self.dump_function(ln, self.entry.prototype) > self.reset_state(ln) >
© 2016 - 2025 Red Hat, Inc.