Skip to content

Commit 636d4d9

Browse files
author
Jonathan Corbet
committed
docs: kdoc: clean up check_sections()
entry.sectcheck is just a duplicate of our list of sections that is only passed to check_sections(); its main purpose seems to be to avoid checking the special named sections. Rework check_sections() to not use that field (which is then deleted), tocheck for the known sections directly, and tighten up the logic in general. Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent bd5628b commit 636d4d9

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@
4242
# @{section-name}:
4343
# while trying to not match literal block starts like "example::"
4444
#
45+
known_section_names = 'description|context|returns?|notes?|examples?'
46+
known_sections = KernRe(known_section_names, flags = re.I)
4547
doc_sect = doc_com + \
46-
KernRe(r'\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$',
47-
flags=re.I, cache=False)
48+
KernRe(r'\s*(\@[.\w]+|\@\.\.\.|' + known_section_names + r')\s*:([^:].*)?$',
49+
flags=re.I, cache=False)
4850

4951
doc_content = doc_com_body + KernRe(r'(.*)', cache=False)
5052
doc_inline_start = KernRe(r'^\s*/\*\*\s*$', cache=False)
@@ -115,7 +117,6 @@ def __init__(self, config, ln):
115117
self.config = config
116118

117119
self._contents = []
118-
self.sectcheck = ""
119120
self.prototype = ""
120121

121122
self.warnings = []
@@ -187,7 +188,6 @@ def dump_section(self, start_new=True):
187188
self.parameterdescs[name] = contents
188189
self.parameterdesc_start_lines[name] = self.new_start_line
189190

190-
self.sectcheck += name + " "
191191
self.new_start_line = 0
192192

193193
else:
@@ -478,29 +478,20 @@ def create_parameter_list(self, ln, decl_type, args,
478478
self.push_parameter(ln, decl_type, param, dtype,
479479
arg, declaration_name)
480480

481-
def check_sections(self, ln, decl_name, decl_type, sectcheck):
481+
def check_sections(self, ln, decl_name, decl_type):
482482
"""
483483
Check for errors inside sections, emitting warnings if not found
484484
parameters are described.
485485
"""
486-
487-
sects = sectcheck.split()
488-
489-
for sx in range(len(sects)): # pylint: disable=C0200
490-
err = True
491-
for param in self.entry.parameterlist:
492-
if param == sects[sx]:
493-
err = False
494-
break
495-
496-
if err:
486+
for section in self.entry.sections:
487+
if section not in self.entry.parameterlist and \
488+
not known_sections.search(section):
497489
if decl_type == 'function':
498490
dname = f"{decl_type} parameter"
499491
else:
500492
dname = f"{decl_type} member"
501-
502493
self.emit_msg(ln,
503-
f"Excess {dname} '{sects[sx]}' description in '{decl_name}'")
494+
f"Excess {dname} '{section}' description in '{decl_name}'")
504495

505496
def check_return_section(self, ln, declaration_name, return_type):
506497
"""
@@ -754,7 +745,7 @@ def dump_struct(self, ln, proto):
754745

755746
self.create_parameter_list(ln, decl_type, members, ';',
756747
declaration_name)
757-
self.check_sections(ln, declaration_name, decl_type, self.entry.sectcheck)
748+
self.check_sections(ln, declaration_name, decl_type)
758749

759750
# Adjust declaration for better display
760751
declaration = KernRe(r'([\{;])').sub(r'\1\n', declaration)
@@ -1018,7 +1009,7 @@ def dump_function(self, ln, prototype):
10181009
f"expecting prototype for {self.entry.identifier}(). Prototype was for {declaration_name}() instead")
10191010
return
10201011

1021-
self.check_sections(ln, declaration_name, "function", self.entry.sectcheck)
1012+
self.check_sections(ln, declaration_name, "function")
10221013

10231014
self.check_return_section(ln, declaration_name, return_type)
10241015

0 commit comments

Comments
 (0)