History

docs: kdoc: some tweaks to process_proto_function()

Add a set of comments to process_proto_function and reorganize the logic slightly; no functional change.

Jonathan Corbet committed 1 year ago

Commit 414ccf91 parent b8ac0251 file · +24 −19Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/lib/kdoc/kdoc_parser.py+24−19
@@ -1553,39 +1553,44 @@ class KernelDoc: · 1552 unmodified lines
15531553 """Ancillary routine to process a function prototype"""
15541554
15551555 # strip C99-style comments to end of line
1556− r = KernRe(r"\/\/.*$", re.S)
1557− line = r.sub('', line)
1558−
1556+ line = KernRe(r"\/\/.*$", re.S).sub('', line)
1557+ #
1558+ # Soak up the line's worth of prototype text, stopping at { or ; if present.
1559+ #
15591560 if KernRe(r'\s*#\s*define').match(line):
15601561 self.entry.prototype = line
1561− elif line.startswith('#'):
1562− # Strip other macros like #ifdef/#ifndef/#endif/...
1563− pass
1564− else:
1562+ elif not line.startswith('#'): # skip other preprocessor stuff
15651563 r = KernRe(r'([^\{]*)')
15661564 if r.match(line):
15671565 self.entry.prototype += r.group(1) + " "
1568−
1566+ #
1567+ # If we now have the whole prototype, clean it up and declare victory.
1568+ #
15691569 if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line):
15701570 # strip comments and surrounding spaces
1571− r = KernRe(r'/\*.*\*/')
1572− self.entry.prototype = r.sub('', self.entry.prototype).strip()
1573−
1571+ self.entry.prototype = KernRe(r'/\*.*\*/').sub('', self.entry.prototype).strip()
1572+ #
15741573 # Handle self.entry.prototypes for function pointers like:
15751574 # int (*pcs_config)(struct foo)
1576−
1575+ # by turning it into
1576+ # int pcs_config(struct foo)
1577+ #
15771578 r = KernRe(r'^(\S+\s+)\(\s*\*(\S+)\)')
15781579 self.entry.prototype = r.sub(r'\1\2', self.entry.prototype)
1579−
1580+ #
1581+ # Handle special declaration syntaxes
1582+ #
15801583 if 'SYSCALL_DEFINE' in self.entry.prototype:
15811584 self.entry.prototype = self.syscall_munge(ln,
15821585 self.entry.prototype)
1583−
1584− r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT')
1585− if r.search(self.entry.prototype):
1586− self.entry.prototype = self.tracepoint_munge(ln,
1587− self.entry.prototype)
1588−
1586+ else:
1587+ r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT')
1588+ if r.search(self.entry.prototype):
1589+ self.entry.prototype = self.tracepoint_munge(ln,
1590+ self.entry.prototype)
1591+ #
1592+ # ... and we're done
1593+ #
15891594 self.dump_function(ln, self.entry.prototype)
15901595 self.reset_state(ln)
15911596