Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

docs: kdoc: move the declaration regexes out of process_name()

Move two complex regexes up with the other patterns, decluttering this
function and allowing the compilation to be done once rather than for every
kerneldoc comment.

Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20250606163438.229916-9-corbet@lwn.net

+17 -13
+17 -13
scripts/lib/kdoc/kdoc_parser.py
··· 47 47 flags=re.I, cache=False) 48 48 49 49 doc_content = doc_com_body + KernRe(r'(.*)', cache=False) 50 - doc_block = doc_com + KernRe(r'DOC:\s*(.*)?', cache=False) 51 50 doc_inline_start = KernRe(r'^\s*/\*\*\s*$', cache=False) 52 51 doc_inline_sect = KernRe(r'\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)', cache=False) 53 52 doc_inline_end = KernRe(r'^\s*\*/\s*$', cache=False) ··· 58 59 export_symbol_ns = KernRe(r'^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*"\S+"\)\s*', cache=False) 59 60 60 61 type_param = KernRe(r"\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=False) 62 + 63 + # 64 + # Tests for the beginning of a kerneldoc block in its various forms. 65 + # 66 + doc_block = doc_com + KernRe(r'DOC:\s*(.*)?', cache=False) 67 + doc_begin_data = KernRe(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)", cache = False) 68 + doc_begin_func = KernRe(str(doc_com) + # initial " * ' 69 + r"(?:\w+\s*\*\s*)?" + # type (not captured) 70 + r'(?:define\s+)?' + # possible "define" (not captured) 71 + r'(\w+)\s*(?:\(\w*\))?\s*' + # name and optional "(...)" 72 + r'(?:[-:].*)?$', # description (not captured) 73 + cache = False) 61 74 62 75 # 63 76 # A little helper to get rid of excess white space ··· 1243 1232 if doc_decl.search(line): 1244 1233 self.entry.identifier = doc_decl.group(1) 1245 1234 1246 - decl_start = str(doc_com) # comment block asterisk 1247 - fn_type = r"(?:\w+\s*\*\s*)?" # type (for non-functions) 1248 - parenthesis = r"(?:\(\w*\))?" # optional parenthesis on function 1249 - decl_end = r"(?:[-:].*)" # end of the name part 1250 - 1251 1235 # Test for data declaration 1252 - r = KernRe(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)") 1253 - r2 = KernRe(fr"^{decl_start}{fn_type}(?:define\s+)?(\w+)\s*{parenthesis}\s*{decl_end}?$") 1254 - if r.search(line): 1255 - self.entry.decl_type = r.group(1) 1256 - self.entry.identifier = r.group(2) 1236 + if doc_begin_data.search(line): 1237 + self.entry.decl_type = doc_begin_data.group(1) 1238 + self.entry.identifier = doc_begin_data.group(2) 1257 1239 # 1258 1240 # Look for a function description 1259 1241 # 1260 - elif r2.search(line): 1261 - self.entry.identifier = r2.group(1) 1242 + elif doc_begin_func.search(line): 1243 + self.entry.identifier = doc_begin_func.group(1) 1262 1244 self.entry.decl_type = "function" 1263 1245 # 1264 1246 # We struck out.