History

docs: kdoc: rework process_export() slightly

Reorganize process_export() to eliminate duplicated code, don't look for exports in states where we don't expect them, and don't bother with normal state-machine processing if an export declaration has been found.

Jonathan Corbet committed 1 year ago

Commit d06c54f1 parent 0aa36751 file · +14 −16Browse files

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

Unified · Split

scripts/lib/kdoc/kdoc_parser.py+14−16
@@ -1211,16 +1211,17 @@ class KernelDoc: · 1210 unmodified lines
12111211
12121212 if export_symbol.search(line):
12131213 symbol = export_symbol.group(2)
1214− for suffix in suffixes:
1215− symbol = symbol.removesuffix(suffix)
1216− function_set.add(symbol)
1217− return
1218−
1219− if export_symbol_ns.search(line):
1214+ elif export_symbol_ns.search(line):
12201215 symbol = export_symbol_ns.group(2)
1221− for suffix in suffixes:
1222− symbol = symbol.removesuffix(suffix)
1223− function_set.add(symbol)
1216+ else:
1217+ return False
1218+ #
1219+ # Found an export, trim out any special suffixes
1220+ #
1221+ for suffix in suffixes:
1222+ symbol = symbol.removesuffix(suffix)
1223+ function_set.add(symbol)
1224+ return True
12241225
12251226 def process_normal(self, ln, line):
12261227 """
@@ -1767,13 +1768,10 @@ class KernelDoc: · 540 unmodified lines
17671768 # it was read twice. Here, we use the already-existing
17681769 # loop to parse exported symbols as well.
17691770 #
1770− # TODO: It should be noticed that not all states are
1771− # needed here. On a future cleanup, process export only
1772− # at the states that aren't handling comment markups.
1773− self.process_export(export_table, line)
1774−
1775− # Hand this line to the appropriate state handler
1776− self.state_actions[self.state](self, ln, line)
1771+ if (self.state != state.NORMAL) or \
1772+ not self.process_export(export_table, line):
1773+ # Hand this line to the appropriate state handler
1774+ self.state_actions[self.state](self, ln, line)
17771775
17781776 except OSError:
17791777 self.config.log.error(f"Error: Cannot open file {self.fname}")