There are some regex expressions in the kernel-doc script, which are used repeatedly in the script. Reduce such expressions into variables, which can be used everywhere. A quick manual check found that no errors and warnings were added/removed in this process.
Showing the changes to scripts/kernel-doc (1 of 1 file). Show all
Unified · Split
| @@ -406,6 +406,8 @@ my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; · 405 unmodified lines | ||
| 406 | 406 | my $doc_inline_end = '^\s*\*/\s*$'; |
| 407 | 407 | my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; |
| 408 | 408 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
| 409 | +my $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; | |
| 410 | +my $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; | |
| 409 | 411 | |
| 410 | 412 | my %parameterdescs; |
| 411 | 413 | my %parameterdesc_start_lines; |
| @@ -694,7 +696,7 @@ sub output_function_man(%) { · 282 unmodified lines | ||
| 694 | 696 | $post = ");"; |
| 695 | 697 | } |
| 696 | 698 | $type = $args{'parametertypes'}{$parameter}; |
| 697 | − if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
| 699 | + if ($type =~ m/$function_pointer/) { | |
| 698 | 700 | # pointer-to-function |
| 699 | 701 | print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; |
| 700 | 702 | } else { |
| @@ -974,7 +976,7 @@ sub output_function_rst(%) { · 273 unmodified lines | ||
| 974 | 976 | $count++; |
| 975 | 977 | $type = $args{'parametertypes'}{$parameter}; |
| 976 | 978 | |
| 977 | − if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | |
| 979 | + if ($type =~ m/$function_pointer/) { | |
| 978 | 980 | # pointer-to-function |
| 979 | 981 | print $1 . $parameter . ") (" . $2 . ")"; |
| 980 | 982 | } else { |
| @@ -1211,7 +1213,9 @@ sub dump_struct($$) { · 230 unmodified lines | ||
| 1211 | 1213 | my $members; |
| 1212 | 1214 | my $type = qr{struct|union}; |
| 1213 | 1215 | # For capturing struct/union definition body, i.e. "{members*}qualifiers*" |
| 1214 | − my $definition_body = qr{\{(.*)\}(?:\s*(?:__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*}; | |
| 1216 | + my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; | |
| 1217 | + my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; | |
| 1218 | + my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; | |
| 1215 | 1219 | |
| 1216 | 1220 | if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { |
| 1217 | 1221 | $decl_type = $1; |
| @@ -1235,27 +1239,27 @@ sub dump_struct($$) { · 17 unmodified lines | ||
| 1235 | 1239 | # strip comments: |
| 1236 | 1240 | $members =~ s/\/\*.*?\*\///gos; |
| 1237 | 1241 | # strip attributes |
| 1238 | − $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi; | |
| 1242 | + $members =~ s/\s*$attribute/ /gi; | |
| 1239 | 1243 | $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; |
| 1240 | 1244 | $members =~ s/\s*__packed\s*/ /gos; |
| 1241 | 1245 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; |
| 1242 | 1246 | $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; |
| 1243 | 1247 | $members =~ s/\s*____cacheline_aligned/ /gos; |
| 1244 | 1248 | |
| 1249 | + my $args = qr{([^,)]+)}; | |
| 1245 | 1250 | # replace DECLARE_BITMAP |
| 1246 | 1251 | $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; |
| 1247 | − $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; | |
| 1252 | + $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; | |
| 1248 | 1253 | # replace DECLARE_HASHTABLE |
| 1249 | − $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; | |
| 1254 | + $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; | |
| 1250 | 1255 | # replace DECLARE_KFIFO |
| 1251 | − $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; | |
| 1256 | + $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; | |
| 1252 | 1257 | # replace DECLARE_KFIFO_PTR |
| 1253 | − $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; | |
| 1254 | − | |
| 1258 | + $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; | |
| 1255 | 1259 | my $declaration = $members; |
| 1256 | 1260 | |
| 1257 | 1261 | # Split nested struct/union elements as newer ones |
| 1258 | − while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { | |
| 1262 | + while ($members =~ m/$struct_members/) { | |
| 1259 | 1263 | my $newmember; |
| 1260 | 1264 | my $maintype = $1; |
| 1261 | 1265 | my $ids = $4; |
| @@ -1315,7 +1319,7 @@ sub dump_struct($$) { · 53 unmodified lines | ||
| 1315 | 1319 | } |
| 1316 | 1320 | } |
| 1317 | 1321 | } |
| 1318 | − $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/; | |
| 1322 | + $members =~ s/$struct_members/$newmember/; | |
| 1319 | 1323 | } |
| 1320 | 1324 | |
| 1321 | 1325 | # Ignore other nested elements, like enums |
| @@ -1555,8 +1559,9 @@ sub create_parameterlist($$$$) { · 233 unmodified lines | ||
| 1555 | 1559 | my $param; |
| 1556 | 1560 | |
| 1557 | 1561 | # temporarily replace commas inside function pointer definition |
| 1558 | − while ($args =~ /(\([^\),]+),/) { | |
| 1559 | − $args =~ s/(\([^\),]+),/$1#/g; | |
| 1562 | + my $arg_expr = qr{\([^\),]+}; | |
| 1563 | + while ($args =~ /$arg_expr,/) { | |
| 1564 | + $args =~ s/($arg_expr),/$1#/g; | |
| 1560 | 1565 | } |
| 1561 | 1566 | |
| 1562 | 1567 | foreach my $arg (split($splitter, $args)) { |
| @@ -1707,7 +1712,7 @@ sub check_sections($$$$$) { · 144 unmodified lines | ||
| 1707 | 1712 | foreach $px (0 .. $#prms) { |
| 1708 | 1713 | $prm_clean = $prms[$px]; |
| 1709 | 1714 | $prm_clean =~ s/\[.*\]//; |
| 1710 | − $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; | |
| 1715 | + $prm_clean =~ s/$attribute//i; | |
| 1711 | 1716 | # ignore array size in a parameter string; |
| 1712 | 1717 | # however, the original param string may contain |
| 1713 | 1718 | # spaces, e.g.: addr[6 + 2] |
| @@ -1809,8 +1814,14 @@ sub dump_function($$) { · 95 unmodified lines | ||
| 1809 | 1814 | # - parport_register_device (function pointer parameters) |
| 1810 | 1815 | # - atomic_set (macro) |
| 1811 | 1816 | # - pci_match_device, __copy_to_user (long return type) |
| 1812 | − | |
| 1813 | − if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { | |
| 1817 | + my $name = qr{[a-zA-Z0-9_~:]+}; | |
| 1818 | + my $prototype_end1 = qr{[^\(]*}; | |
| 1819 | + my $prototype_end2 = qr{[^\{]*}; | |
| 1820 | + my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; | |
| 1821 | + my $type1 = qr{[\w\s]+}; | |
| 1822 | + my $type2 = qr{$type1\*+}; | |
| 1823 | + | |
| 1824 | + if ($define && $prototype =~ m/^()($name)\s+/) { | |
| 1814 | 1825 | # This is an object-like macro, it has no return type and no parameter |
| 1815 | 1826 | # list. |
| 1816 | 1827 | # Function-like macros are not allowed to have spaces between |
| @@ -1818,23 +1829,9 @@ sub dump_function($$) { · 1 unmodified line | ||
| 1818 | 1829 | $return_type = $1; |
| 1819 | 1830 | $declaration_name = $2; |
| 1820 | 1831 | $noret = 1; |
| 1821 | − } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1822 | − $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1823 | − $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1824 | − $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1825 | − $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1826 | − $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1827 | − $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | |
| 1828 | − $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1829 | − $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1830 | − $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1831 | − $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1832 | − $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1833 | − $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1834 | − $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1835 | − $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1836 | − $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | |
| 1837 | − $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { | |
| 1832 | + } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || | |
| 1833 | + $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || | |
| 1834 | + $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { | |
| 1838 | 1835 | $return_type = $1; |
| 1839 | 1836 | $declaration_name = $2; |
| 1840 | 1837 | my $args = $3; |
| @@ -2111,12 +2108,12 @@ sub process_name($$) { · 270 unmodified lines | ||
| 2111 | 2108 | } elsif (/$doc_decl/o) { |
| 2112 | 2109 | $identifier = $1; |
| 2113 | 2110 | my $is_kernel_comment = 0; |
| 2114 | − my $decl_start = qr{\s*\*}; | |
| 2111 | + my $decl_start = qr{$doc_com}; | |
| 2115 | 2112 | # test for pointer declaration type, foo * bar() - desc |
| 2116 | 2113 | my $fn_type = qr{\w+\s*\*\s*}; |
| 2117 | 2114 | my $parenthesis = qr{\(\w*\)}; |
| 2118 | 2115 | my $decl_end = qr{[-:].*}; |
| 2119 | − if (/^$decl_start\s*([\w\s]+?)$parenthesis?\s*$decl_end?$/) { | |
| 2116 | + if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { | |
| 2120 | 2117 | $identifier = $1; |
| 2121 | 2118 | } |
| 2122 | 2119 | if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { |
| @@ -2126,8 +2123,8 @@ sub process_name($$) { · 3 unmodified lines | ||
| 2126 | 2123 | } |
| 2127 | 2124 | # Look for foo() or static void foo() - description; or misspelt |
| 2128 | 2125 | # identifier |
| 2129 | − elsif (/^$decl_start\s*$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || | |
| 2130 | − /^$decl_start\s*$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { | |
| 2126 | + elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || | |
| 2127 | + /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { | |
| 2131 | 2128 | $identifier = $1; |
| 2132 | 2129 | $decl_type = 'function'; |
| 2133 | 2130 | $identifier =~ s/^define\s+//; |