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.

scripts/kernel-doc.py: Rename the kernel doc Re class to KernRe

Using just "Re" makes it harder to distinguish from the native
"re" class. So, let's rename it.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/4e095ecd5235a3e811ddcf5bad4cfb92f1da0a4a.1744106242.git.mchehab+huawei@kernel.org

authored by

Mauro Carvalho Chehab and committed by
Jonathan Corbet
04a383ce 16740c29

+159 -159
+25 -25
scripts/lib/kdoc/kdoc_output.py
··· 20 20 from datetime import datetime 21 21 22 22 from kdoc_parser import KernelDoc, type_param 23 - from kdoc_re import Re 23 + from kdoc_re import KernRe 24 24 25 25 26 - function_pointer = Re(r"([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)", cache=False) 26 + function_pointer = KernRe(r"([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)", cache=False) 27 27 28 28 # match expressions used to find embedded type information 29 - type_constant = Re(r"\b``([^\`]+)``\b", cache=False) 30 - type_constant2 = Re(r"\%([-_*\w]+)", cache=False) 31 - type_func = Re(r"(\w+)\(\)", cache=False) 32 - type_param_ref = Re(r"([\!~\*]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=False) 29 + type_constant = KernRe(r"\b``([^\`]+)``\b", cache=False) 30 + type_constant2 = KernRe(r"\%([-_*\w]+)", cache=False) 31 + type_func = KernRe(r"(\w+)\(\)", cache=False) 32 + type_param_ref = KernRe(r"([\!~\*]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=False) 33 33 34 34 # Special RST handling for func ptr params 35 - type_fp_param = Re(r"\@(\w+)\(\)", cache=False) 35 + type_fp_param = KernRe(r"\@(\w+)\(\)", cache=False) 36 36 37 37 # Special RST handling for structs with func ptr params 38 - type_fp_param2 = Re(r"\@(\w+->\S+)\(\)", cache=False) 38 + type_fp_param2 = KernRe(r"\@(\w+->\S+)\(\)", cache=False) 39 39 40 - type_env = Re(r"(\$\w+)", cache=False) 41 - type_enum = Re(r"\&(enum\s*([_\w]+))", cache=False) 42 - type_struct = Re(r"\&(struct\s*([_\w]+))", cache=False) 43 - type_typedef = Re(r"\&(typedef\s*([_\w]+))", cache=False) 44 - type_union = Re(r"\&(union\s*([_\w]+))", cache=False) 45 - type_member = Re(r"\&([_\w]+)(\.|->)([_\w]+)", cache=False) 46 - type_fallback = Re(r"\&([_\w]+)", cache=False) 47 - type_member_func = type_member + Re(r"\(\)", cache=False) 40 + type_env = KernRe(r"(\$\w+)", cache=False) 41 + type_enum = KernRe(r"\&(enum\s*([_\w]+))", cache=False) 42 + type_struct = KernRe(r"\&(struct\s*([_\w]+))", cache=False) 43 + type_typedef = KernRe(r"\&(typedef\s*([_\w]+))", cache=False) 44 + type_union = KernRe(r"\&(union\s*([_\w]+))", cache=False) 45 + type_member = KernRe(r"\&([_\w]+)(\.|->)([_\w]+)", cache=False) 46 + type_fallback = KernRe(r"\&([_\w]+)", cache=False) 47 + type_member_func = type_member + KernRe(r"\(\)", cache=False) 48 48 49 49 50 50 class OutputFormat: ··· 257 257 ] 258 258 blankline = "\n" 259 259 260 - sphinx_literal = Re(r'^[^.].*::$', cache=False) 261 - sphinx_cblock = Re(r'^\.\.\ +code-block::', cache=False) 260 + sphinx_literal = KernRe(r'^[^.].*::$', cache=False) 261 + sphinx_cblock = KernRe(r'^\.\.\ +code-block::', cache=False) 262 262 263 263 def __init__(self): 264 264 """ ··· 299 299 # If this is the first non-blank line in a literal block, 300 300 # figure out the proper indent. 301 301 if not litprefix: 302 - r = Re(r'^(\s*)') 302 + r = KernRe(r'^(\s*)') 303 303 if r.match(line): 304 304 litprefix = '^' + r.group(1) 305 305 else: 306 306 litprefix = "" 307 307 308 308 output += line + "\n" 309 - elif not Re(litprefix).match(line): 309 + elif not KernRe(litprefix).match(line): 310 310 in_literal = False 311 311 else: 312 312 output += line + "\n" ··· 429 429 self.data += f"{self.lineprefix}**Parameters**\n\n" 430 430 431 431 for parameter in parameterlist: 432 - parameter_name = Re(r'\[.*').sub('', parameter) 432 + parameter_name = KernRe(r'\[.*').sub('', parameter) 433 433 dtype = args['parametertypes'].get(parameter, "") 434 434 435 435 if dtype: ··· 626 626 contents = "\n".join(contents) 627 627 628 628 for line in contents.strip("\n").split("\n"): 629 - line = Re(r"^\s*").sub("", line) 629 + line = KernRe(r"^\s*").sub("", line) 630 630 if not line: 631 631 continue 632 632 ··· 680 680 # Pointer-to-function 681 681 self.data += f'".BI "{parenth}{function_pointer.group(1)}" " ") ({function_pointer.group(2)}){post}"' + "\n" 682 682 else: 683 - dtype = Re(r'([^\*])$').sub(r'\1 ', dtype) 683 + dtype = KernRe(r'([^\*])$').sub(r'\1 ', dtype) 684 684 685 685 self.data += f'.BI "{parenth}{dtype}" "{post}"' + "\n" 686 686 count += 1 ··· 727 727 self.data += ".SH Constants\n" 728 728 729 729 for parameter in parameterlist: 730 - parameter_name = Re(r'\[.*').sub('', parameter) 730 + parameter_name = KernRe(r'\[.*').sub('', parameter) 731 731 self.data += f'.IP "{parameter}" 12' + "\n" 732 732 self.output_highlight(args['parameterdescs'].get(parameter_name, "")) 733 733 ··· 769 769 770 770 # Replace tabs with two spaces and handle newlines 771 771 declaration = definition.replace("\t", " ") 772 - declaration = Re(r"\n").sub('"\n.br\n.BI "', declaration) 772 + declaration = KernRe(r"\n").sub('"\n.br\n.BI "', declaration) 773 773 774 774 self.data += ".SH SYNOPSIS\n" 775 775 self.data += f"{struct_type} {struct_name} " + "{" + "\n.br\n"
+132 -132
scripts/lib/kdoc/kdoc_parser.py
··· 16 16 import re 17 17 from pprint import pformat 18 18 19 - from kdoc_re import NestedMatch, Re 19 + from kdoc_re import NestedMatch, KernRe 20 20 21 21 22 22 # ··· 29 29 # 30 30 31 31 # Allow whitespace at end of comment start. 32 - doc_start = Re(r'^/\*\*\s*$', cache=False) 32 + doc_start = KernRe(r'^/\*\*\s*$', cache=False) 33 33 34 - doc_end = Re(r'\*/', cache=False) 35 - doc_com = Re(r'\s*\*\s*', cache=False) 36 - doc_com_body = Re(r'\s*\* ?', cache=False) 37 - doc_decl = doc_com + Re(r'(\w+)', cache=False) 34 + doc_end = KernRe(r'\*/', cache=False) 35 + doc_com = KernRe(r'\s*\*\s*', cache=False) 36 + doc_com_body = KernRe(r'\s*\* ?', cache=False) 37 + doc_decl = doc_com + KernRe(r'(\w+)', cache=False) 38 38 39 39 # @params and a strictly limited set of supported section names 40 40 # Specifically: ··· 44 44 # while trying to not match literal block starts like "example::" 45 45 # 46 46 doc_sect = doc_com + \ 47 - Re(r'\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$', 47 + KernRe(r'\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$', 48 48 flags=re.I, cache=False) 49 49 50 - doc_content = doc_com_body + Re(r'(.*)', cache=False) 51 - doc_block = doc_com + Re(r'DOC:\s*(.*)?', cache=False) 52 - doc_inline_start = Re(r'^\s*/\*\*\s*$', cache=False) 53 - doc_inline_sect = Re(r'\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)', cache=False) 54 - doc_inline_end = Re(r'^\s*\*/\s*$', cache=False) 55 - doc_inline_oneline = Re(r'^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$', cache=False) 56 - attribute = Re(r"__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)", 50 + doc_content = doc_com_body + KernRe(r'(.*)', cache=False) 51 + doc_block = doc_com + KernRe(r'DOC:\s*(.*)?', cache=False) 52 + doc_inline_start = KernRe(r'^\s*/\*\*\s*$', cache=False) 53 + doc_inline_sect = KernRe(r'\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)', cache=False) 54 + doc_inline_end = KernRe(r'^\s*\*/\s*$', cache=False) 55 + doc_inline_oneline = KernRe(r'^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$', cache=False) 56 + attribute = KernRe(r"__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)", 57 57 flags=re.I | re.S, cache=False) 58 58 59 - export_symbol = Re(r'^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*', cache=False) 60 - export_symbol_ns = Re(r'^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*"\S+"\)\s*', cache=False) 59 + export_symbol = KernRe(r'^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*', cache=False) 60 + export_symbol_ns = KernRe(r'^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*"\S+"\)\s*', cache=False) 61 61 62 - type_param = Re(r"\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=False) 62 + type_param = KernRe(r"\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)", cache=False) 63 63 64 64 65 65 class KernelDoc: ··· 278 278 279 279 self.entry.anon_struct_union = False 280 280 281 - param = Re(r'[\[\)].*').sub('', param, count=1) 281 + param = KernRe(r'[\[\)].*').sub('', param, count=1) 282 282 283 283 if dtype == "" and param.endswith("..."): 284 - if Re(r'\w\.\.\.$').search(param): 284 + if KernRe(r'\w\.\.\.$').search(param): 285 285 # For named variable parameters of the form `x...`, 286 286 # remove the dots 287 287 param = param[:-3] ··· 335 335 # to ignore "[blah" in a parameter string. 336 336 337 337 self.entry.parameterlist.append(param) 338 - org_arg = Re(r'\s\s+').sub(' ', org_arg) 338 + org_arg = KernRe(r'\s\s+').sub(' ', org_arg) 339 339 self.entry.parametertypes[param] = org_arg 340 340 341 341 def save_struct_actual(self, actual): ··· 344 344 one string item. 345 345 """ 346 346 347 - actual = Re(r'\s*').sub("", actual, count=1) 347 + actual = KernRe(r'\s*').sub("", actual, count=1) 348 348 349 349 self.entry.struct_actual += actual + " " 350 350 ··· 355 355 """ 356 356 357 357 # temporarily replace all commas inside function pointer definition 358 - arg_expr = Re(r'(\([^\),]+),') 358 + arg_expr = KernRe(r'(\([^\),]+),') 359 359 while arg_expr.search(args): 360 360 args = arg_expr.sub(r"\1#", args) 361 361 362 362 for arg in args.split(splitter): 363 363 # Strip comments 364 - arg = Re(r'\/\*.*\*\/').sub('', arg) 364 + arg = KernRe(r'\/\*.*\*\/').sub('', arg) 365 365 366 366 # Ignore argument attributes 367 - arg = Re(r'\sPOS0?\s').sub(' ', arg) 367 + arg = KernRe(r'\sPOS0?\s').sub(' ', arg) 368 368 369 369 # Strip leading/trailing spaces 370 370 arg = arg.strip() 371 - arg = Re(r'\s+').sub(' ', arg, count=1) 371 + arg = KernRe(r'\s+').sub(' ', arg, count=1) 372 372 373 373 if arg.startswith('#'): 374 374 # Treat preprocessor directive as a typeless variable just to fill ··· 379 379 self.push_parameter(ln, decl_type, arg, "", 380 380 "", declaration_name) 381 381 382 - elif Re(r'\(.+\)\s*\(').search(arg): 382 + elif KernRe(r'\(.+\)\s*\(').search(arg): 383 383 # Pointer-to-function 384 384 385 385 arg = arg.replace('#', ',') 386 386 387 - r = Re(r'[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)') 387 + r = KernRe(r'[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)') 388 388 if r.match(arg): 389 389 param = r.group(1) 390 390 else: 391 391 self.emit_warning(ln, f"Invalid param: {arg}") 392 392 param = arg 393 393 394 - dtype = Re(r'([^\(]+\(\*?)\s*' + re.escape(param)).sub(r'\1', arg) 394 + dtype = KernRe(r'([^\(]+\(\*?)\s*' + re.escape(param)).sub(r'\1', arg) 395 395 self.save_struct_actual(param) 396 396 self.push_parameter(ln, decl_type, param, dtype, 397 397 arg, declaration_name) 398 398 399 - elif Re(r'\(.+\)\s*\[').search(arg): 399 + elif KernRe(r'\(.+\)\s*\[').search(arg): 400 400 # Array-of-pointers 401 401 402 402 arg = arg.replace('#', ',') 403 - r = Re(r'[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)') 403 + r = KernRe(r'[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)') 404 404 if r.match(arg): 405 405 param = r.group(1) 406 406 else: 407 407 self.emit_warning(ln, f"Invalid param: {arg}") 408 408 param = arg 409 409 410 - dtype = Re(r'([^\(]+\(\*?)\s*' + re.escape(param)).sub(r'\1', arg) 410 + dtype = KernRe(r'([^\(]+\(\*?)\s*' + re.escape(param)).sub(r'\1', arg) 411 411 412 412 self.save_struct_actual(param) 413 413 self.push_parameter(ln, decl_type, param, dtype, 414 414 arg, declaration_name) 415 415 416 416 elif arg: 417 - arg = Re(r'\s*:\s*').sub(":", arg) 418 - arg = Re(r'\s*\[').sub('[', arg) 417 + arg = KernRe(r'\s*:\s*').sub(":", arg) 418 + arg = KernRe(r'\s*\[').sub('[', arg) 419 419 420 - args = Re(r'\s*,\s*').split(arg) 420 + args = KernRe(r'\s*,\s*').split(arg) 421 421 if args[0] and '*' in args[0]: 422 422 args[0] = re.sub(r'(\*+)\s*', r' \1', args[0]) 423 423 424 424 first_arg = [] 425 - r = Re(r'^(.*\s+)(.*?\[.*\].*)$') 425 + r = KernRe(r'^(.*\s+)(.*?\[.*\].*)$') 426 426 if args[0] and r.match(args[0]): 427 427 args.pop(0) 428 428 first_arg.extend(r.group(1)) 429 429 first_arg.append(r.group(2)) 430 430 else: 431 - first_arg = Re(r'\s+').split(args.pop(0)) 431 + first_arg = KernRe(r'\s+').split(args.pop(0)) 432 432 433 433 args.insert(0, first_arg.pop()) 434 434 dtype = ' '.join(first_arg) 435 435 436 436 for param in args: 437 - if Re(r'^(\*+)\s*(.*)').match(param): 438 - r = Re(r'^(\*+)\s*(.*)') 437 + if KernRe(r'^(\*+)\s*(.*)').match(param): 438 + r = KernRe(r'^(\*+)\s*(.*)') 439 439 if not r.match(param): 440 440 self.emit_warning(ln, f"Invalid param: {param}") 441 441 continue ··· 447 447 f"{dtype} {r.group(1)}", 448 448 arg, declaration_name) 449 449 450 - elif Re(r'(.*?):(\w+)').search(param): 451 - r = Re(r'(.*?):(\w+)') 450 + elif KernRe(r'(.*?):(\w+)').search(param): 451 + r = KernRe(r'(.*?):(\w+)') 452 452 if not r.match(param): 453 453 self.emit_warning(ln, f"Invalid param: {param}") 454 454 continue ··· 477 477 err = True 478 478 for px in range(len(prms)): # pylint: disable=C0200 479 479 prm_clean = prms[px] 480 - prm_clean = Re(r'\[.*\]').sub('', prm_clean) 480 + prm_clean = KernRe(r'\[.*\]').sub('', prm_clean) 481 481 prm_clean = attribute.sub('', prm_clean) 482 482 483 483 # ignore array size in a parameter string; ··· 486 486 # and this appears in @prms as "addr[6" since the 487 487 # parameter list is split at spaces; 488 488 # hence just ignore "[..." for the sections check; 489 - prm_clean = Re(r'\[.*').sub('', prm_clean) 489 + prm_clean = KernRe(r'\[.*').sub('', prm_clean) 490 490 491 491 if prm_clean == sects[sx]: 492 492 err = False ··· 512 512 513 513 # Ignore an empty return type (It's a macro) 514 514 # Ignore functions with a "void" return type (but not "void *") 515 - if not return_type or Re(r'void\s*\w*\s*$').search(return_type): 515 + if not return_type or KernRe(r'void\s*\w*\s*$').search(return_type): 516 516 return 517 517 518 518 if not self.entry.sections.get("Return", None): ··· 535 535 ] 536 536 537 537 definition_body = r'\{(.*)\}\s*' + "(?:" + '|'.join(qualifiers) + ")?" 538 - struct_members = Re(type_pattern + r'([^\{\};]+)(\{)([^\{\}]*)(\})([^\{\}\;]*)(\;)') 538 + struct_members = KernRe(type_pattern + r'([^\{\};]+)(\{)([^\{\}]*)(\})([^\{\}\;]*)(\;)') 539 539 540 540 # Extract struct/union definition 541 541 members = None 542 542 declaration_name = None 543 543 decl_type = None 544 544 545 - r = Re(type_pattern + r'\s+(\w+)\s*' + definition_body) 545 + r = KernRe(type_pattern + r'\s+(\w+)\s*' + definition_body) 546 546 if r.search(proto): 547 547 decl_type = r.group(1) 548 548 declaration_name = r.group(2) 549 549 members = r.group(3) 550 550 else: 551 - r = Re(r'typedef\s+' + type_pattern + r'\s*' + definition_body + r'\s*(\w+)\s*;') 551 + r = KernRe(r'typedef\s+' + type_pattern + r'\s*' + definition_body + r'\s*(\w+)\s*;') 552 552 553 553 if r.search(proto): 554 554 decl_type = r.group(1) ··· 567 567 args_pattern = r'([^,)]+)' 568 568 569 569 sub_prefixes = [ 570 - (Re(r'\/\*\s*private:.*?\/\*\s*public:.*?\*\/', re.S | re.I), ''), 571 - (Re(r'\/\*\s*private:.*', re.S | re.I), ''), 570 + (KernRe(r'\/\*\s*private:.*?\/\*\s*public:.*?\*\/', re.S | re.I), ''), 571 + (KernRe(r'\/\*\s*private:.*', re.S | re.I), ''), 572 572 573 573 # Strip comments 574 - (Re(r'\/\*.*?\*\/', re.S), ''), 574 + (KernRe(r'\/\*.*?\*\/', re.S), ''), 575 575 576 576 # Strip attributes 577 577 (attribute, ' '), 578 - (Re(r'\s*__aligned\s*\([^;]*\)', re.S), ' '), 579 - (Re(r'\s*__counted_by\s*\([^;]*\)', re.S), ' '), 580 - (Re(r'\s*__counted_by_(le|be)\s*\([^;]*\)', re.S), ' '), 581 - (Re(r'\s*__packed\s*', re.S), ' '), 582 - (Re(r'\s*CRYPTO_MINALIGN_ATTR', re.S), ' '), 583 - (Re(r'\s*____cacheline_aligned_in_smp', re.S), ' '), 584 - (Re(r'\s*____cacheline_aligned', re.S), ' '), 578 + (KernRe(r'\s*__aligned\s*\([^;]*\)', re.S), ' '), 579 + (KernRe(r'\s*__counted_by\s*\([^;]*\)', re.S), ' '), 580 + (KernRe(r'\s*__counted_by_(le|be)\s*\([^;]*\)', re.S), ' '), 581 + (KernRe(r'\s*__packed\s*', re.S), ' '), 582 + (KernRe(r'\s*CRYPTO_MINALIGN_ATTR', re.S), ' '), 583 + (KernRe(r'\s*____cacheline_aligned_in_smp', re.S), ' '), 584 + (KernRe(r'\s*____cacheline_aligned', re.S), ' '), 585 585 586 586 # Unwrap struct_group macros based on this definition: 587 587 # __struct_group(TAG, NAME, ATTRS, MEMBERS...) ··· 616 616 # matched. So, the implementation to drop STRUCT_GROUP() will be 617 617 # handled in separate. 618 618 619 - (Re(r'\bstruct_group\s*\(([^,]*,)', re.S), r'STRUCT_GROUP('), 620 - (Re(r'\bstruct_group_attr\s*\(([^,]*,){2}', re.S), r'STRUCT_GROUP('), 621 - (Re(r'\bstruct_group_tagged\s*\(([^,]*),([^,]*),', re.S), r'struct \1 \2; STRUCT_GROUP('), 622 - (Re(r'\b__struct_group\s*\(([^,]*,){3}', re.S), r'STRUCT_GROUP('), 619 + (KernRe(r'\bstruct_group\s*\(([^,]*,)', re.S), r'STRUCT_GROUP('), 620 + (KernRe(r'\bstruct_group_attr\s*\(([^,]*,){2}', re.S), r'STRUCT_GROUP('), 621 + (KernRe(r'\bstruct_group_tagged\s*\(([^,]*),([^,]*),', re.S), r'struct \1 \2; STRUCT_GROUP('), 622 + (KernRe(r'\b__struct_group\s*\(([^,]*,){3}', re.S), r'STRUCT_GROUP('), 623 623 624 624 # Replace macros 625 625 # ··· 628 628 # it is better to also move those to the NestedMatch logic, 629 629 # to ensure that parenthesis will be properly matched. 630 630 631 - (Re(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)', re.S), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'), 632 - (Re(r'DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)', re.S), r'DECLARE_BITMAP(\1, PHY_INTERFACE_MODE_MAX)'), 633 - (Re(r'DECLARE_BITMAP\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'unsigned long \1[BITS_TO_LONGS(\2)]'), 634 - (Re(r'DECLARE_HASHTABLE\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'unsigned long \1[1 << ((\2) - 1)]'), 635 - (Re(r'DECLARE_KFIFO\s*\(' + args_pattern + r',\s*' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'\2 *\1'), 636 - (Re(r'DECLARE_KFIFO_PTR\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'\2 *\1'), 637 - (Re(r'(?:__)?DECLARE_FLEX_ARRAY\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'\1 \2[]'), 638 - (Re(r'DEFINE_DMA_UNMAP_ADDR\s*\(' + args_pattern + r'\)', re.S), r'dma_addr_t \1'), 639 - (Re(r'DEFINE_DMA_UNMAP_LEN\s*\(' + args_pattern + r'\)', re.S), r'__u32 \1'), 631 + (KernRe(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)', re.S), r'DECLARE_BITMAP(\1, __ETHTOOL_LINK_MODE_MASK_NBITS)'), 632 + (KernRe(r'DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)', re.S), r'DECLARE_BITMAP(\1, PHY_INTERFACE_MODE_MAX)'), 633 + (KernRe(r'DECLARE_BITMAP\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'unsigned long \1[BITS_TO_LONGS(\2)]'), 634 + (KernRe(r'DECLARE_HASHTABLE\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'unsigned long \1[1 << ((\2) - 1)]'), 635 + (KernRe(r'DECLARE_KFIFO\s*\(' + args_pattern + r',\s*' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'\2 *\1'), 636 + (KernRe(r'DECLARE_KFIFO_PTR\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'\2 *\1'), 637 + (KernRe(r'(?:__)?DECLARE_FLEX_ARRAY\s*\(' + args_pattern + r',\s*' + args_pattern + r'\)', re.S), r'\1 \2[]'), 638 + (KernRe(r'DEFINE_DMA_UNMAP_ADDR\s*\(' + args_pattern + r'\)', re.S), r'dma_addr_t \1'), 639 + (KernRe(r'DEFINE_DMA_UNMAP_LEN\s*\(' + args_pattern + r'\)', re.S), r'__u32 \1'), 640 640 ] 641 641 642 642 # Regexes here are guaranteed to have the end limiter matching ··· 689 689 s_id = s_id.strip() 690 690 691 691 newmember += f"{maintype} {s_id}; " 692 - s_id = Re(r'[:\[].*').sub('', s_id) 693 - s_id = Re(r'^\s*\**(\S+)\s*').sub(r'\1', s_id) 692 + s_id = KernRe(r'[:\[].*').sub('', s_id) 693 + s_id = KernRe(r'^\s*\**(\S+)\s*').sub(r'\1', s_id) 694 694 695 695 for arg in content.split(';'): 696 696 arg = arg.strip() ··· 698 698 if not arg: 699 699 continue 700 700 701 - r = Re(r'^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)') 701 + r = KernRe(r'^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)') 702 702 if r.match(arg): 703 703 # Pointer-to-function 704 704 dtype = r.group(1) ··· 717 717 else: 718 718 arg = arg.strip() 719 719 # Handle bitmaps 720 - arg = Re(r':\s*\d+\s*').sub('', arg) 720 + arg = KernRe(r':\s*\d+\s*').sub('', arg) 721 721 722 722 # Handle arrays 723 - arg = Re(r'\[.*\]').sub('', arg) 723 + arg = KernRe(r'\[.*\]').sub('', arg) 724 724 725 725 # Handle multiple IDs 726 - arg = Re(r'\s*,\s*').sub(',', arg) 726 + arg = KernRe(r'\s*,\s*').sub(',', arg) 727 727 728 - r = Re(r'(.*)\s+([\S+,]+)') 728 + r = KernRe(r'(.*)\s+([\S+,]+)') 729 729 730 730 if r.search(arg): 731 731 dtype = r.group(1) ··· 735 735 continue 736 736 737 737 for name in names.split(','): 738 - name = Re(r'^\s*\**(\S+)\s*').sub(r'\1', name).strip() 738 + name = KernRe(r'^\s*\**(\S+)\s*').sub(r'\1', name).strip() 739 739 740 740 if not name: 741 741 continue ··· 757 757 self.entry.sectcheck, self.entry.struct_actual) 758 758 759 759 # Adjust declaration for better display 760 - declaration = Re(r'([\{;])').sub(r'\1\n', declaration) 761 - declaration = Re(r'\}\s+;').sub('};', declaration) 760 + declaration = KernRe(r'([\{;])').sub(r'\1\n', declaration) 761 + declaration = KernRe(r'\}\s+;').sub('};', declaration) 762 762 763 763 # Better handle inlined enums 764 764 while True: 765 - r = Re(r'(enum\s+\{[^\}]+),([^\n])') 765 + r = KernRe(r'(enum\s+\{[^\}]+),([^\n])') 766 766 if not r.search(declaration): 767 767 break 768 768 ··· 774 774 for clause in def_args: 775 775 776 776 clause = clause.strip() 777 - clause = Re(r'\s+').sub(' ', clause, count=1) 777 + clause = KernRe(r'\s+').sub(' ', clause, count=1) 778 778 779 779 if not clause: 780 780 continue ··· 782 782 if '}' in clause and level > 1: 783 783 level -= 1 784 784 785 - if not Re(r'^\s*#').match(clause): 785 + if not KernRe(r'^\s*#').match(clause): 786 786 declaration += "\t" * level 787 787 788 788 declaration += "\t" + clause + "\n" ··· 807 807 """ 808 808 809 809 # Ignore members marked private 810 - proto = Re(r'\/\*\s*private:.*?\/\*\s*public:.*?\*\/', flags=re.S).sub('', proto) 811 - proto = Re(r'\/\*\s*private:.*}', flags=re.S).sub('}', proto) 810 + proto = KernRe(r'\/\*\s*private:.*?\/\*\s*public:.*?\*\/', flags=re.S).sub('', proto) 811 + proto = KernRe(r'\/\*\s*private:.*}', flags=re.S).sub('}', proto) 812 812 813 813 # Strip comments 814 - proto = Re(r'\/\*.*?\*\/', flags=re.S).sub('', proto) 814 + proto = KernRe(r'\/\*.*?\*\/', flags=re.S).sub('', proto) 815 815 816 816 # Strip #define macros inside enums 817 - proto = Re(r'#\s*((define|ifdef|if)\s+|endif)[^;]*;', flags=re.S).sub('', proto) 817 + proto = KernRe(r'#\s*((define|ifdef|if)\s+|endif)[^;]*;', flags=re.S).sub('', proto) 818 818 819 819 members = None 820 820 declaration_name = None 821 821 822 - r = Re(r'typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;') 822 + r = KernRe(r'typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;') 823 823 if r.search(proto): 824 824 declaration_name = r.group(2) 825 825 members = r.group(1).rstrip() 826 826 else: 827 - r = Re(r'enum\s+(\w*)\s*\{(.*)\}') 827 + r = KernRe(r'enum\s+(\w*)\s*\{(.*)\}') 828 828 if r.match(proto): 829 829 declaration_name = r.group(1) 830 830 members = r.group(2).rstrip() ··· 847 847 848 848 member_set = set() 849 849 850 - members = Re(r'\([^;]*?[\)]').sub('', members) 850 + members = KernRe(r'\([^;]*?[\)]').sub('', members) 851 851 852 852 for arg in members.split(','): 853 853 if not arg: 854 854 continue 855 - arg = Re(r'^\s*(\w+).*').sub(r'\1', arg) 855 + arg = KernRe(r'^\s*(\w+).*').sub(r'\1', arg) 856 856 self.entry.parameterlist.append(arg) 857 857 if arg not in self.entry.parameterdescs: 858 858 self.entry.parameterdescs[arg] = self.undescribed ··· 947 947 ] 948 948 949 949 for search, sub, flags in sub_prefixes: 950 - prototype = Re(search, flags).sub(sub, prototype) 950 + prototype = KernRe(search, flags).sub(sub, prototype) 951 951 952 952 # Macros are a special case, as they change the prototype format 953 - new_proto = Re(r"^#\s*define\s+").sub("", prototype) 953 + new_proto = KernRe(r"^#\s*define\s+").sub("", prototype) 954 954 if new_proto != prototype: 955 955 is_define_proto = True 956 956 prototype = new_proto ··· 987 987 found = False 988 988 989 989 if is_define_proto: 990 - r = Re(r'^()(' + name + r')\s+') 990 + r = KernRe(r'^()(' + name + r')\s+') 991 991 992 992 if r.search(prototype): 993 993 return_type = '' ··· 1004 1004 ] 1005 1005 1006 1006 for p in patterns: 1007 - r = Re(p) 1007 + r = KernRe(p) 1008 1008 1009 1009 if r.match(prototype): 1010 1010 ··· 1071 1071 typedef_ident = r'\*?\s*(\w\S+)\s*' 1072 1072 typedef_args = r'\s*\((.*)\);' 1073 1073 1074 - typedef1 = Re(r'typedef' + typedef_type + r'\(' + typedef_ident + r'\)' + typedef_args) 1075 - typedef2 = Re(r'typedef' + typedef_type + typedef_ident + typedef_args) 1074 + typedef1 = KernRe(r'typedef' + typedef_type + r'\(' + typedef_ident + r'\)' + typedef_args) 1075 + typedef2 = KernRe(r'typedef' + typedef_type + typedef_ident + typedef_args) 1076 1076 1077 1077 # Strip comments 1078 - proto = Re(r'/\*.*?\*/', flags=re.S).sub('', proto) 1078 + proto = KernRe(r'/\*.*?\*/', flags=re.S).sub('', proto) 1079 1079 1080 1080 # Parse function typedef prototypes 1081 1081 for r in [typedef1, typedef2]: ··· 1109 1109 return 1110 1110 1111 1111 # Handle nested parentheses or brackets 1112 - r = Re(r'(\(*.\)\s*|\[*.\]\s*);$') 1112 + r = KernRe(r'(\(*.\)\s*|\[*.\]\s*);$') 1113 1113 while r.search(proto): 1114 1114 proto = r.sub('', proto) 1115 1115 1116 1116 # Parse simple typedefs 1117 - r = Re(r'typedef.*\s+(\w+)\s*;') 1117 + r = KernRe(r'typedef.*\s+(\w+)\s*;') 1118 1118 if r.match(proto): 1119 1119 declaration_name = r.group(1) 1120 1120 ··· 1195 1195 decl_end = r"(?:[-:].*)" # end of the name part 1196 1196 1197 1197 # test for pointer declaration type, foo * bar() - desc 1198 - r = Re(fr"^{decl_start}([\w\s]+?){parenthesis}?\s*{decl_end}?$") 1198 + r = KernRe(fr"^{decl_start}([\w\s]+?){parenthesis}?\s*{decl_end}?$") 1199 1199 if r.search(line): 1200 1200 self.entry.identifier = r.group(1) 1201 1201 1202 1202 # Test for data declaration 1203 - r = Re(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)") 1203 + r = KernRe(r"^\s*\*?\s*(struct|union|enum|typedef)\b\s*(\w*)") 1204 1204 if r.search(line): 1205 1205 self.entry.decl_type = r.group(1) 1206 1206 self.entry.identifier = r.group(2) ··· 1209 1209 # Look for foo() or static void foo() - description; 1210 1210 # or misspelt identifier 1211 1211 1212 - r1 = Re(fr"^{decl_start}{fn_type}(\w+)\s*{parenthesis}\s*{decl_end}?$") 1213 - r2 = Re(fr"^{decl_start}{fn_type}(\w+[^-:]*){parenthesis}\s*{decl_end}$") 1212 + r1 = KernRe(fr"^{decl_start}{fn_type}(\w+)\s*{parenthesis}\s*{decl_end}?$") 1213 + r2 = KernRe(fr"^{decl_start}{fn_type}(\w+[^-:]*){parenthesis}\s*{decl_end}$") 1214 1214 1215 1215 for r in [r1, r2]: 1216 1216 if r.search(line): 1217 1217 self.entry.identifier = r.group(1) 1218 1218 self.entry.decl_type = "function" 1219 1219 1220 - r = Re(r"define\s+") 1220 + r = KernRe(r"define\s+") 1221 1221 self.entry.identifier = r.sub("", self.entry.identifier) 1222 1222 self.entry.is_kernel_comment = True 1223 1223 break ··· 1230 1230 self.entry.section = self.section_default 1231 1231 self.entry.new_start_line = ln + 1 1232 1232 1233 - r = Re("[-:](.*)") 1233 + r = KernRe("[-:](.*)") 1234 1234 if r.search(line): 1235 1235 # strip leading/trailing/multiple spaces 1236 1236 self.entry.descr = r.group(1).strip(" ") 1237 1237 1238 - r = Re(r"\s+") 1238 + r = KernRe(r"\s+") 1239 1239 self.entry.descr = r.sub(" ", self.entry.descr) 1240 1240 self.entry.declaration_purpose = self.entry.descr 1241 1241 self.state = self.STATE_BODY_MAYBE ··· 1272 1272 """ 1273 1273 1274 1274 if self.state == self.STATE_BODY_WITH_BLANK_LINE: 1275 - r = Re(r"\s*\*\s?\S") 1275 + r = KernRe(r"\s*\*\s?\S") 1276 1276 if r.match(line): 1277 1277 self.dump_section() 1278 1278 self.entry.section = self.section_default ··· 1318 1318 self.dump_section() 1319 1319 1320 1320 # Look for doc_com + <text> + doc_end: 1321 - r = Re(r'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') 1321 + r = KernRe(r'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') 1322 1322 if r.match(line): 1323 1323 self.emit_warning(ln, f"suspicious ending line: {line}") 1324 1324 ··· 1351 1351 self.entry.declaration_purpose = self.entry.declaration_purpose.rstrip() 1352 1352 self.entry.declaration_purpose += " " + cont 1353 1353 1354 - r = Re(r"\s+") 1354 + r = KernRe(r"\s+") 1355 1355 self.entry.declaration_purpose = r.sub(' ', 1356 1356 self.entry.declaration_purpose) 1357 1357 ··· 1359 1359 if self.entry.section.startswith('@') or \ 1360 1360 self.entry.section == self.section_context: 1361 1361 if self.entry.leading_space is None: 1362 - r = Re(r'^(\s+)') 1362 + r = KernRe(r'^(\s+)') 1363 1363 if r.match(cont): 1364 1364 self.entry.leading_space = len(r.group(1)) 1365 1365 else: ··· 1436 1436 is_void = True 1437 1437 1438 1438 # Replace SYSCALL_DEFINE with correct return type & function name 1439 - proto = Re(r'SYSCALL_DEFINE.*\(').sub('long sys_', proto) 1439 + proto = KernRe(r'SYSCALL_DEFINE.*\(').sub('long sys_', proto) 1440 1440 1441 - r = Re(r'long\s+(sys_.*?),') 1441 + r = KernRe(r'long\s+(sys_.*?),') 1442 1442 if r.search(proto): 1443 - proto = Re(',').sub('(', proto, count=1) 1443 + proto = KernRe(',').sub('(', proto, count=1) 1444 1444 elif is_void: 1445 - proto = Re(r'\)').sub('(void)', proto, count=1) 1445 + proto = KernRe(r'\)').sub('(void)', proto, count=1) 1446 1446 1447 1447 # Now delete all of the odd-numbered commas in the proto 1448 1448 # so that argument types & names don't have a comma between them ··· 1469 1469 tracepointargs = None 1470 1470 1471 1471 # Match tracepoint name based on different patterns 1472 - r = Re(r'TRACE_EVENT\((.*?),') 1472 + r = KernRe(r'TRACE_EVENT\((.*?),') 1473 1473 if r.search(proto): 1474 1474 tracepointname = r.group(1) 1475 1475 1476 - r = Re(r'DEFINE_SINGLE_EVENT\((.*?),') 1476 + r = KernRe(r'DEFINE_SINGLE_EVENT\((.*?),') 1477 1477 if r.search(proto): 1478 1478 tracepointname = r.group(1) 1479 1479 1480 - r = Re(r'DEFINE_EVENT\((.*?),(.*?),') 1480 + r = KernRe(r'DEFINE_EVENT\((.*?),(.*?),') 1481 1481 if r.search(proto): 1482 1482 tracepointname = r.group(2) 1483 1483 1484 1484 if tracepointname: 1485 1485 tracepointname = tracepointname.lstrip() 1486 1486 1487 - r = Re(r'TP_PROTO\((.*?)\)') 1487 + r = KernRe(r'TP_PROTO\((.*?)\)') 1488 1488 if r.search(proto): 1489 1489 tracepointargs = r.group(1) 1490 1490 ··· 1501 1501 """Ancillary routine to process a function prototype""" 1502 1502 1503 1503 # strip C99-style comments to end of line 1504 - r = Re(r"\/\/.*$", re.S) 1504 + r = KernRe(r"\/\/.*$", re.S) 1505 1505 line = r.sub('', line) 1506 1506 1507 - if Re(r'\s*#\s*define').match(line): 1507 + if KernRe(r'\s*#\s*define').match(line): 1508 1508 self.entry.prototype = line 1509 1509 elif line.startswith('#'): 1510 1510 # Strip other macros like #ifdef/#ifndef/#endif/... 1511 1511 pass 1512 1512 else: 1513 - r = Re(r'([^\{]*)') 1513 + r = KernRe(r'([^\{]*)') 1514 1514 if r.match(line): 1515 1515 self.entry.prototype += r.group(1) + " " 1516 1516 1517 - if '{' in line or ';' in line or Re(r'\s*#\s*define').match(line): 1517 + if '{' in line or ';' in line or KernRe(r'\s*#\s*define').match(line): 1518 1518 # strip comments 1519 - r = Re(r'/\*.*?\*/') 1519 + r = KernRe(r'/\*.*?\*/') 1520 1520 self.entry.prototype = r.sub('', self.entry.prototype) 1521 1521 1522 1522 # strip newlines/cr's 1523 - r = Re(r'[\r\n]+') 1523 + r = KernRe(r'[\r\n]+') 1524 1524 self.entry.prototype = r.sub(' ', self.entry.prototype) 1525 1525 1526 1526 # strip leading spaces 1527 - r = Re(r'^\s+') 1527 + r = KernRe(r'^\s+') 1528 1528 self.entry.prototype = r.sub('', self.entry.prototype) 1529 1529 1530 1530 # Handle self.entry.prototypes for function pointers like: 1531 1531 # int (*pcs_config)(struct foo) 1532 1532 1533 - r = Re(r'^(\S+\s+)\(\s*\*(\S+)\)') 1533 + r = KernRe(r'^(\S+\s+)\(\s*\*(\S+)\)') 1534 1534 self.entry.prototype = r.sub(r'\1\2', self.entry.prototype) 1535 1535 1536 1536 if 'SYSCALL_DEFINE' in self.entry.prototype: 1537 1537 self.entry.prototype = self.syscall_munge(ln, 1538 1538 self.entry.prototype) 1539 1539 1540 - r = Re(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT') 1540 + r = KernRe(r'TRACE_EVENT|DEFINE_EVENT|DEFINE_SINGLE_EVENT') 1541 1541 if r.search(self.entry.prototype): 1542 1542 self.entry.prototype = self.tracepoint_munge(ln, 1543 1543 self.entry.prototype) ··· 1549 1549 """Ancillary routine to process a type""" 1550 1550 1551 1551 # Strip newlines/cr's. 1552 - line = Re(r'[\r\n]+', re.S).sub(' ', line) 1552 + line = KernRe(r'[\r\n]+', re.S).sub(' ', line) 1553 1553 1554 1554 # Strip leading spaces 1555 - line = Re(r'^\s+', re.S).sub('', line) 1555 + line = KernRe(r'^\s+', re.S).sub('', line) 1556 1556 1557 1557 # Strip trailing spaces 1558 - line = Re(r'\s+$', re.S).sub('', line) 1558 + line = KernRe(r'\s+$', re.S).sub('', line) 1559 1559 1560 1560 # Strip C99-style comments to the end of the line 1561 - line = Re(r"\/\/.*$", re.S).sub('', line) 1561 + line = KernRe(r"\/\/.*$", re.S).sub('', line) 1562 1562 1563 1563 # To distinguish preprocessor directive from regular declaration later. 1564 1564 if line.startswith('#'): 1565 1565 line += ";" 1566 1566 1567 - r = Re(r'([^\{\};]*)([\{\};])(.*)') 1567 + r = KernRe(r'([^\{\};]*)([\{\};])(.*)') 1568 1568 while True: 1569 1569 if r.search(line): 1570 1570 if self.entry.prototype:
+2 -2
scripts/lib/kdoc/kdoc_re.py
··· 14 14 re_cache = {} 15 15 16 16 17 - class Re: 17 + class KernRe: 18 18 """ 19 19 Helper class to simplify regex declaration and usage, 20 20 ··· 59 59 Allows adding two regular expressions into one. 60 60 """ 61 61 62 - return Re(str(self) + str(other), cache=self.cache or other.cache, 62 + return KernRe(str(self) + str(other), cache=self.cache or other.cache, 63 63 flags=self.regex.flags | other.regex.flags) 64 64 65 65 def match(self, string):