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
1553 """Ancillary routine to process a function prototype"""1553 """Ancillary routine to process a function prototype"""
1554 1554
1555 # strip C99-style comments to end of line1555 # strip C99-style comments to end of line
1556 r = KernRe(r"\/\/.*$", re.S)1556 line = KernRe(r"\/\/.*$", re.S).sub('', line)
1557 line = r.sub('', line)1557 #
1558 1558 # Soak up the line's worth of prototype text, stopping at { or ; if present.
1559 #
1559 if KernRe(r'\s*#\s*define').match(line):1560 if KernRe(r'\s*#\s*define').match(line):
1560 self.entry.prototype = line1561 self.entry.prototype = line
1561 elif line.startswith('#'):1562 elif not line.startswith('#'): # skip other preprocessor stuff
1562 # Strip other macros like #ifdef/#ifndef/#endif/...
1563 pass
1564 else:
1565 r = KernRe(r'([^\{]*)')1563 r = KernRe(r'([^\{]*)')
1566 if r.match(line):1564 if r.match(line):
1567 self.entry.prototype += r.group(1) + " "1565 self.entry.prototype += r.group(1) + " "
1568 1566 #
1567 # If we now have the whole prototype, clean it up and declare victory.
1568 #
1569 if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line):1569 if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line):
1570 # strip comments and surrounding spaces1570 # strip comments and surrounding spaces
1571 r = KernRe(r'/\*.*\*/')1571 self.entry.prototype = KernRe(r'/\*.*\*/').sub('', self.entry.prototype).strip()
1572 self.entry.prototype = r.sub('', self.entry.prototype).strip()1572 #
1573
1574 # Handle self.entry.prototypes for function pointers like:1573 # Handle self.entry.prototypes for function pointers like:
1575 # int (*pcs_config)(struct foo)1574 # int (*pcs_config)(struct foo)
1576 1575 # by turning it into
1576 # int pcs_config(struct foo)
1577 #
1577 r = KernRe(r'^(\S+\s+)\(\s*\*(\S+)\)')1578 r = KernRe(r'^(\S+\s+)\(\s*\*(\S+)\)')
1578 self.entry.prototype = r.sub(r'\1\2', self.entry.prototype)1579 self.entry.prototype = r.sub(r'\1\2', self.entry.prototype)
1579 1580 #
1581 # Handle special declaration syntaxes
1582 #
1580 if 'SYSCALL_DEFINE' in self.entry.prototype:1583 if 'SYSCALL_DEFINE' in self.entry.prototype:
1581 self.entry.prototype = self.syscall_munge(ln,1584 self.entry.prototype = self.syscall_munge(ln,
1582 self.entry.prototype)1585 self.entry.prototype)
1583 1586 else:
1584 r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT')1587 r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT')
1585 if r.search(self.entry.prototype):1588 if r.search(self.entry.prototype):
1586 self.entry.prototype = self.tracepoint_munge(ln,1589 self.entry.prototype = self.tracepoint_munge(ln,
1587 self.entry.prototype)1590 self.entry.prototype)
1588 1591 #
1592 # ... and we're done
1593 #
1589 self.dump_function(ln, self.entry.prototype)1594 self.dump_function(ln, self.entry.prototype)
1590 self.reset_state(ln)1595 self.reset_state(ln)
1591 1596