Skip to content

Commit 8d9d122

Browse files
author
Jonathan Corbet
committed
docs: kdoc: drop "sectionlist"
Python dicts (as of 3.7) are guaranteed to remember the insertion order of items, so we do not need a separate list for that purpose. Drop the per-entry sectionlist variable and just rely on native dict ordering. Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 703f907 commit 8d9d122

2 files changed

Lines changed: 7 additions & 24 deletions

File tree

scripts/lib/kdoc/kdoc_output.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,10 @@ def out_section(self, args, out_docblock=False):
339339
tends to duplicate a header already in the template file.
340340
"""
341341

342-
sectionlist = args.get('sectionlist', [])
343342
sections = args.get('sections', {})
344343
section_start_lines = args.get('section_start_lines', {})
345344

346-
for section in sectionlist:
345+
for section in sections:
347346
# Skip sections that are in the nosymbol_table
348347
if section in self.nosymbol:
349348
continue
@@ -636,15 +635,14 @@ def output_highlight(self, block):
636635
self.data += line + "\n"
637636

638637
def out_doc(self, fname, name, args):
639-
sectionlist = args.get('sectionlist', [])
640638
sections = args.get('sections', {})
641639

642640
if not self.check_doc(name, args):
643641
return
644642

645643
self.data += f'.TH "{self.modulename}" 9 "{self.modulename}" "{self.man_date}" "API Manual" LINUX' + "\n"
646644

647-
for section in sectionlist:
645+
for section in sections:
648646
self.data += f'.SH "{section}"' + "\n"
649647
self.output_highlight(sections.get(section))
650648

@@ -653,7 +651,6 @@ def out_function(self, fname, name, args):
653651

654652
parameterlist = args.get('parameterlist', [])
655653
parameterdescs = args.get('parameterdescs', {})
656-
sectionlist = args.get('sectionlist', [])
657654
sections = args.get('sections', {})
658655

659656
self.data += f'.TH "{args["function"]}" 9 "{args["function"]}" "{self.man_date}" "Kernel Hacker\'s Manual" LINUX' + "\n"
@@ -695,15 +692,14 @@ def out_function(self, fname, name, args):
695692
self.data += f'.IP "{parameter}" 12' + "\n"
696693
self.output_highlight(parameterdescs.get(parameter_name, ""))
697694

698-
for section in sectionlist:
695+
for section in sections:
699696
self.data += f'.SH "{section.upper()}"' + "\n"
700697
self.output_highlight(sections[section])
701698

702699
def out_enum(self, fname, name, args):
703700

704701
name = args.get('enum', '')
705702
parameterlist = args.get('parameterlist', [])
706-
sectionlist = args.get('sectionlist', [])
707703
sections = args.get('sections', {})
708704

709705
self.data += f'.TH "{self.modulename}" 9 "enum {args["enum"]}" "{self.man_date}" "API Manual" LINUX' + "\n"
@@ -731,23 +727,22 @@ def out_enum(self, fname, name, args):
731727
self.data += f'.IP "{parameter}" 12' + "\n"
732728
self.output_highlight(args['parameterdescs'].get(parameter_name, ""))
733729

734-
for section in sectionlist:
730+
for section in sections:
735731
self.data += f'.SH "{section}"' + "\n"
736732
self.output_highlight(sections[section])
737733

738734
def out_typedef(self, fname, name, args):
739735
module = self.modulename
740736
typedef = args.get('typedef')
741737
purpose = args.get('purpose')
742-
sectionlist = args.get('sectionlist', [])
743738
sections = args.get('sections', {})
744739

745740
self.data += f'.TH "{module}" 9 "{typedef}" "{self.man_date}" "API Manual" LINUX' + "\n"
746741

747742
self.data += ".SH NAME\n"
748743
self.data += f"typedef {typedef} \\- {purpose}\n"
749744

750-
for section in sectionlist:
745+
for section in sections:
751746
self.data += f'.SH "{section}"' + "\n"
752747
self.output_highlight(sections.get(section))
753748

@@ -757,7 +752,6 @@ def out_struct(self, fname, name, args):
757752
struct_name = args.get('struct')
758753
purpose = args.get('purpose')
759754
definition = args.get('definition')
760-
sectionlist = args.get('sectionlist', [])
761755
parameterlist = args.get('parameterlist', [])
762756
sections = args.get('sections', {})
763757
parameterdescs = args.get('parameterdescs', {})
@@ -788,6 +782,6 @@ def out_struct(self, fname, name, args):
788782
self.data += f'.IP "{parameter}" 12' + "\n"
789783
self.output_highlight(parameterdescs.get(parameter_name))
790784

791-
for section in sectionlist:
785+
for section in sections:
792786
self.data += f'.SH "{section}"' + "\n"
793787
self.output_highlight(sections.get(section))

scripts/lib/kdoc/kdoc_parser.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def __init__(self, config, ln):
127127
self.parameterdesc_start_lines = {}
128128

129129
self.section_start_lines = {}
130-
self.sectionlist = []
131130
self.sections = {}
132131

133132
self.anon_struct_union = False
@@ -202,7 +201,6 @@ def dump_section(self, start_new=True):
202201
self.sections[name] += '\n' + contents
203202
else:
204203
self.sections[name] = contents
205-
self.sectionlist.append(name)
206204
self.section_start_lines[name] = self.new_start_line
207205
self.new_start_line = 0
208206

@@ -275,14 +273,12 @@ def output_declaration(self, dtype, name, **args):
275273
item.warnings = self.entry.warnings
276274

277275
sections = item.get('sections', {})
278-
sectionlist = item.get('sectionlist', [])
279276

280277
# Drop empty sections
281278
# TODO: improve empty sections logic to emit warnings
282279
for section in ["Description", "Return"]:
283-
if section in sectionlist and not sections[section].rstrip():
280+
if section in sections and not sections[section].rstrip():
284281
del sections[section]
285-
sectionlist.remove(section)
286282

287283
self.entries.append(item)
288284

@@ -828,7 +824,6 @@ def dump_struct(self, ln, proto):
828824
parameterdescs=self.entry.parameterdescs,
829825
parametertypes=self.entry.parametertypes,
830826
parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
831-
sectionlist=self.entry.sectionlist,
832827
sections=self.entry.sections,
833828
section_start_lines=self.entry.section_start_lines,
834829
purpose=self.entry.declaration_purpose)
@@ -913,7 +908,6 @@ def dump_enum(self, ln, proto):
913908
parameterlist=self.entry.parameterlist,
914909
parameterdescs=self.entry.parameterdescs,
915910
parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
916-
sectionlist=self.entry.sectionlist,
917911
sections=self.entry.sections,
918912
section_start_lines=self.entry.section_start_lines,
919913
purpose=self.entry.declaration_purpose)
@@ -1085,7 +1079,6 @@ def dump_function(self, ln, prototype):
10851079
parameterdescs=self.entry.parameterdescs,
10861080
parametertypes=self.entry.parametertypes,
10871081
parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
1088-
sectionlist=self.entry.sectionlist,
10891082
sections=self.entry.sections,
10901083
section_start_lines=self.entry.section_start_lines,
10911084
purpose=self.entry.declaration_purpose,
@@ -1099,7 +1092,6 @@ def dump_function(self, ln, prototype):
10991092
parameterdescs=self.entry.parameterdescs,
11001093
parametertypes=self.entry.parametertypes,
11011094
parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
1102-
sectionlist=self.entry.sectionlist,
11031095
sections=self.entry.sections,
11041096
section_start_lines=self.entry.section_start_lines,
11051097
purpose=self.entry.declaration_purpose,
@@ -1145,7 +1137,6 @@ def dump_typedef(self, ln, proto):
11451137
parameterdescs=self.entry.parameterdescs,
11461138
parametertypes=self.entry.parametertypes,
11471139
parameterdesc_start_lines=self.entry.parameterdesc_start_lines,
1148-
sectionlist=self.entry.sectionlist,
11491140
sections=self.entry.sections,
11501141
section_start_lines=self.entry.section_start_lines,
11511142
purpose=self.entry.declaration_purpose)
@@ -1168,7 +1159,6 @@ def dump_typedef(self, ln, proto):
11681159

11691160
self.output_declaration('typedef', declaration_name,
11701161
typedef=declaration_name,
1171-
sectionlist=self.entry.sectionlist,
11721162
sections=self.entry.sections,
11731163
section_start_lines=self.entry.section_start_lines,
11741164
purpose=self.entry.declaration_purpose)
@@ -1653,7 +1643,6 @@ def process_docblock(self, ln, line):
16531643
if doc_end.search(line):
16541644
self.dump_section()
16551645
self.output_declaration("doc", self.entry.identifier,
1656-
sectionlist=self.entry.sectionlist,
16571646
sections=self.entry.sections,
16581647
section_start_lines=self.entry.section_start_lines)
16591648
self.reset_state(ln)

0 commit comments

Comments
 (0)