History

scripts: kernel-doc: reduce repeated regex expressions into variables

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.

Aditya Srivastava committed 5 years ago

Commit e86bdb21 parent 2c5ff2c1 file · +34 −37Browse files

Unified · Split

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