Skip to content

Commit f587722

Browse files
author
Jonathan Corbet
committed
Merge branch 'kdoc-item2' into docs-mw
The kerneldoc parsing phase gathers all of the information about the declarations of interest, then passes it through to the output phase as a dict that is an unstructured blob of information; this organization has its origins in the Perl version of the program. It results in an interface that is difficult to reason about, dozen-parameter function calls, and other ills. Introduce a new class (KdocItem) to carry this information between the parser and the output modules, and, step by step, modify the system to use this class in a more structured way. This could be taken further by creating a subclass of KdocItem for each declaration type (function, struct, ...), but that is probably more structure than we need. The result is (I hope) clearer code, the removal of a bunch of boilerplate, and no changes to the generated output.
2 parents 2abdc88 + 40020fe commit f587722

4 files changed

Lines changed: 145 additions & 244 deletions

File tree

scripts/lib/kdoc/kdoc_files.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ def msg(self, enable_lineno=False, export=False, internal=False,
275275
self.config.log.warning("No kernel-doc for file %s", fname)
276276
continue
277277

278-
for name, arg in self.results[fname]:
279-
m = self.out_msg(fname, name, arg)
278+
for arg in self.results[fname]:
279+
m = self.out_msg(fname, arg.name, arg)
280280

281281
if m is None:
282282
ln = arg.get("ln", 0)

scripts/lib/kdoc/kdoc_item.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
#
3+
# A class that will, eventually, encapsulate all of the parsed data that we
4+
# then pass into the output modules.
5+
#
6+
7+
class KdocItem:
8+
def __init__(self, name, type, start_line, **other_stuff):
9+
self.name = name
10+
self.type = type
11+
self.declaration_start_line = start_line
12+
self.sections = {}
13+
self.sections_start_lines = {}
14+
self.parameterlist = []
15+
self.parameterdesc_start_lines = []
16+
self.parameterdescs = {}
17+
self.parametertypes = {}
18+
#
19+
# Just save everything else into our own dict so that the output
20+
# side can grab it directly as before. As we move things into more
21+
# structured data, this will, hopefully, fade away.
22+
#
23+
self.other_stuff = other_stuff
24+
25+
def get(self, key, default = None):
26+
return self.other_stuff.get(key, default)
27+
28+
def __getitem__(self, key):
29+
return self.get(key)
30+
31+
#
32+
# Tracking of section and parameter information.
33+
#
34+
def set_sections(self, sections, start_lines):
35+
self.sections = sections
36+
self.section_start_lines = start_lines
37+
38+
def set_params(self, names, descs, types, starts):
39+
self.parameterlist = names
40+
self.parameterdescs = descs
41+
self.parametertypes = types
42+
self.parameterdesc_start_lines = starts

0 commit comments

Comments
 (0)