<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Aditya Srivastava <<a href="mailto:yashsri421@gmail.com">yashsri421@gmail.com</a>> schrieb am Do., 22. Apr. 2021, 21:18:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">There are some regex expressions in the kernel-doc script, which are used<br>
repeatedly in the script.<br>
<br>
Reduce such expressions into variables, which can be used everywhere.<br>
<br>
A quick manual check found that no errors and warnings were added/removed<br>
in this process.<br>
<br>
Suggested-by: Jonathan Corbet <<a href="mailto:corbet@lwn.net" target="_blank" rel="noreferrer">corbet@lwn.net</a>><br>
Signed-off-by: Aditya Srivastava <<a href="mailto:yashsri421@gmail.com" target="_blank" rel="noreferrer">yashsri421@gmail.com</a>><br>
---<br>
scripts/kernel-doc | 89 ++++++++++++++++++++++++++--------------------<br>
1 file changed, 50 insertions(+), 39 deletions(-)<br>
<br>
diff --git a/scripts/kernel-doc b/scripts/kernel-doc<br>
index 2a85d34fdcd0..579c9fdd275f 100755<br>
--- a/scripts/kernel-doc<br>
+++ b/scripts/kernel-doc<br>
@@ -406,6 +406,7 @@ my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';<br>
my $doc_inline_end = '^\s*\*/\s*$';<br>
my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';<br>
my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';<br>
+my $pointer_function = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)};<br>
<br>
my %parameterdescs;<br>
my %parameterdesc_start_lines;<br>
@@ -694,7 +695,7 @@ sub output_function_man(%) {<br>
$post = ");";<br>
}<br>
$type = $args{'parametertypes'}{$parameter};<br>
- if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {<br>
+ if ($type =~ m/$pointer_function/) {<br>
# pointer-to-function<br>
print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n";<br>
} else {<br>
@@ -974,7 +975,7 @@ sub output_function_rst(%) {<br>
$count++;<br>
$type = $args{'parametertypes'}{$parameter};<br>
<br>
- if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {<br>
+ if ($type =~ m/$pointer_function/) {<br>
# pointer-to-function<br>
print $1 . $parameter . ") (" . $2 . ")";<br>
} else {<br>
@@ -1210,8 +1211,14 @@ sub dump_struct($$) {<br>
my $decl_type;<br>
my $members;<br>
my $type = qr{struct|union};<br>
+ my $packed = qr{__packed};<br>
+ my $aligned = qr{__aligned};<br>
+ my $cacheline_aligned_in_smp = qr{____cacheline_aligned_in_smp};<br>
+ my $cacheline_aligned = qr{____cacheline_aligned};<br>
+ my $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i;<br>
# For capturing struct/union definition body, i.e. "{members*}qualifiers*"<br>
- my $definition_body = qr{\{(.*)\}(?:\s*(?:__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*};<br>
+ my $definition_body = qr{\{(.*)\}(?:\s*(?:$packed|$aligned|$cacheline_aligned_in_smp|$cacheline_aligned|$attribute))*};<br>
+ my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;};<br>
<br>
if ($x =~ /($type)\s+(\w+)\s*$definition_body/) {<br>
$decl_type = $1;<br>
@@ -1235,27 +1242,27 @@ sub dump_struct($$) {<br>
# strip comments:<br>
$members =~ s/\/\*.*?\*\///gos;<br>
# strip attributes<br>
- $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi;<br>
- $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos;<br>
- $members =~ s/\s*__packed\s*/ /gos;<br>
+ $members =~ s/\s*$attribute/ /gi;<br>
+ $members =~ s/\s*$aligned\s*\([^;]*\)/ /gos;<br>
+ $members =~ s/\s*$packed\s*/ /gos;<br>
$members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos;<br>
- $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;<br>
- $members =~ s/\s*____cacheline_aligned/ /gos;<br>
+ $members =~ s/\s*$cacheline_aligned_in_smp/ /gos;<br>
+ $members =~ s/\s*$cacheline_aligned/ /gos;<br>
<br>
+ my $args = qr{([^,)]+)};<br>
# replace DECLARE_BITMAP<br>
$members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos;<br>
- $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;<br>
+ $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;<br>
# replace DECLARE_HASHTABLE<br>
- $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;<br>
+ $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos;<br>
# replace DECLARE_KFIFO<br>
- $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;<br>
+ $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos;<br>
# replace DECLARE_KFIFO_PTR<br>
- $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;<br>
-<br>
+ $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos;<br>
my $declaration = $members;<br>
<br>
# Split nested struct/union elements as newer ones<br>
- while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) {<br>
+ while ($members =~ m/$struct_members/) {<br>
my $newmember;<br>
my $maintype = $1;<br>
my $ids = $4;<br>
@@ -1315,7 +1322,7 @@ sub dump_struct($$) {<br>
}<br>
}<br>
}<br>
- $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/;<br>
+ $members =~ s/$struct_members/$newmember/;<br>
}<br>
<br>
# Ignore other nested elements, like enums<br>
@@ -1555,8 +1562,9 @@ sub create_parameterlist($$$$) {<br>
my $param;<br>
<br>
# temporarily replace commas inside function pointer definition<br>
- while ($args =~ /(\([^\),]+),/) {<br>
- $args =~ s/(\([^\),]+),/$1#/g;<br>
+ my $arg_expr = qr{\([^\),]+};<br>
+ while ($args =~ /$arg_expr,/) {<br>
+ $args =~ s/($arg_expr),/$1#/g;<br>
}<br>
<br>
foreach my $arg (split($splitter, $args)) {<br>
@@ -1808,8 +1816,11 @@ sub dump_function($$) {<br>
# - parport_register_device (function pointer parameters)<br>
# - atomic_set (macro)<br>
# - pci_match_device, __copy_to_user (long return type)<br>
+ my $name = qr{[a-zA-Z0-9_~:]+};<br>
+ my $prototype_end1 = qr{\(([^\(]*)\)};<br>
+ my $prototype_end2 = qr{\(([^\{]*)\)};<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Why do you need end1 and end2 here?</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {<br>
+ if ($define && $prototype =~ m/^()($name)\s+/) {<br>
# This is an object-like macro, it has no return type and no parameter<br>
# list.<br>
# Function-like macros are not allowed to have spaces between<br>
@@ -1817,23 +1828,23 @@ sub dump_function($$) {<br>
$return_type = $1;<br>
$declaration_name = $2;<br>
$noret = 1;<br>
- } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||<br>
- $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||<br>
- $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {<br>
+ } elsif ($prototype =~ m/^()($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^(\w+)\s+($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^(\w+\s*\*+)\s*($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+)\s+($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*($name)\s*$prototype_end1/ ||<br>
+ $prototype =~ m/^()($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+)\s+($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s*\*+)\s*($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+)\s+($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*($name)\s*$prototype_end2/ ||<br>
+ $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*($name)\s*$prototype_end2/) {<br>
$return_type = $1;<br>
$declaration_name = $2;<br>
my $args = $3;<br>
@@ -2110,12 +2121,12 @@ sub process_name($$) {<br>
} elsif (/$doc_decl/o) {<br>
$identifier = $1;<br>
my $is_kernel_comment = 0;<br>
- my $decl_start = qr{\s*\*};<br>
+ my $decl_start = qr{$doc_com};<br>
# test for pointer declaration type, foo * bar() - desc<br>
my $fn_type = qr{\w+\s*\*\s*}; <br>
my $parenthesis = qr{\(\w*\)};<br>
my $decl_end = qr{[-:].*};<br>
- if (/^$decl_start\s*([\w\s]+?)$parenthesis?\s*$decl_end?$/) {<br>
+ if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) {<br>
$identifier = $1;<br>
}<br>
if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) {<br>
@@ -2125,8 +2136,8 @@ sub process_name($$) {<br>
}<br>
# Look for foo() or static void foo() - description; or misspelt<br>
# identifier<br>
- elsif (/^$decl_start\s*$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||<br>
- /^$decl_start\s*$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) {<br>
+ elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||<br>
+ /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) {<br>
$identifier = $1;<br>
$decl_type = 'function';<br>
$identifier =~ s/^define\s+//;<br>
-- <br>
2.17.1<br>
<br>
</blockquote></div></div></div>