Skip to content

Commit bb8fd09

Browse files
rddunlapJonathan Corbet
authored andcommitted
kernel-doc: allow object-like macros in ReST output
output_function_rst() does not handle object-like macros. It presents a trailing "()" while output_function_man() handles these macros correctly. Update output_function_rst() to handle object-like macros. Don't show the "Parameters" heading if there are no parameters. For output_function_man(), don't show the "ARGUMENTS" heading if there are no parameters. I have tested this quite a bit with my ad hoc test files for both ReST and man format outputs. The generated output looks good. Fixes: cbb4d3e ("scripts/kernel-doc: handle object-like macros") Signed-off-by: Randy Dunlap <[email protected]> Cc: Horia Geanta <[email protected]> Tested-by: Vlastimil Babka <[email protected]> Signed-off-by: Jonathan Corbet <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 878b56e commit bb8fd09

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

scripts/kernel-doc

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ sub output_function_man(%) {
569569
my %args = %{$_[0]};
570570
my ($parameter, $section);
571571
my $count;
572+
my $func_macro = $args{'func_macro'};
573+
my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
572574

573575
print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
574576

@@ -600,7 +602,10 @@ sub output_function_man(%) {
600602
$parenth = "";
601603
}
602604

603-
print ".SH ARGUMENTS\n";
605+
$paramcount = $#{$args{'parameterlist'}}; # -1 is empty
606+
if ($paramcount >= 0) {
607+
print ".SH ARGUMENTS\n";
608+
}
604609
foreach $parameter (@{$args{'parameterlist'}}) {
605610
my $parameter_name = $parameter;
606611
$parameter_name =~ s/\[.*//;
@@ -822,10 +827,16 @@ sub output_function_rst(%) {
822827
my $oldprefix = $lineprefix;
823828

824829
my $signature = "";
825-
if ($args{'functiontype'} ne "") {
826-
$signature = $args{'functiontype'} . " " . $args{'function'} . " (";
827-
} else {
828-
$signature = $args{'function'} . " (";
830+
my $func_macro = $args{'func_macro'};
831+
my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
832+
833+
if ($func_macro) {
834+
$signature = $args{'function'};
835+
} else {
836+
if ($args{'functiontype'}) {
837+
$signature = $args{'functiontype'} . " ";
838+
}
839+
$signature .= $args{'function'} . " (";
829840
}
830841

831842
my $count = 0;
@@ -844,7 +855,9 @@ sub output_function_rst(%) {
844855
}
845856
}
846857

847-
$signature .= ")";
858+
if (!$func_macro) {
859+
$signature .= ")";
860+
}
848861

849862
if ($sphinx_major < 3) {
850863
if ($args{'typedef'}) {
@@ -888,9 +901,11 @@ sub output_function_rst(%) {
888901
# Put our descriptive text into a container (thus an HTML <div>) to help
889902
# set the function prototypes apart.
890903
#
891-
print ".. container:: kernelindent\n\n";
892904
$lineprefix = " ";
893-
print $lineprefix . "**Parameters**\n\n";
905+
if ($paramcount >= 0) {
906+
print ".. container:: kernelindent\n\n";
907+
print $lineprefix . "**Parameters**\n\n";
908+
}
894909
foreach $parameter (@{$args{'parameterlist'}}) {
895910
my $parameter_name = $parameter;
896911
$parameter_name =~ s/\[.*//;
@@ -1704,7 +1719,7 @@ sub check_return_section {
17041719
sub dump_function($$) {
17051720
my $prototype = shift;
17061721
my $file = shift;
1707-
my $noret = 0;
1722+
my $func_macro = 0;
17081723

17091724
print_lineno($new_start_line);
17101725

@@ -1769,7 +1784,7 @@ sub dump_function($$) {
17691784
# declaration_name and opening parenthesis (notice the \s+).
17701785
$return_type = $1;
17711786
$declaration_name = $2;
1772-
$noret = 1;
1787+
$func_macro = 1;
17731788
} elsif ($prototype =~ m/^()($name)\s*$prototype_end/ ||
17741789
$prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ ||
17751790
$prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) {
@@ -1796,7 +1811,7 @@ sub dump_function($$) {
17961811
# of warnings goes sufficiently down, the check is only performed in
17971812
# -Wreturn mode.
17981813
# TODO: always perform the check.
1799-
if ($Wreturn && !$noret) {
1814+
if ($Wreturn && !$func_macro) {
18001815
check_return_section($file, $declaration_name, $return_type);
18011816
}
18021817

@@ -1814,7 +1829,8 @@ sub dump_function($$) {
18141829
'parametertypes' => \%parametertypes,
18151830
'sectionlist' => \@sectionlist,
18161831
'sections' => \%sections,
1817-
'purpose' => $declaration_purpose
1832+
'purpose' => $declaration_purpose,
1833+
'func_macro' => $func_macro
18181834
});
18191835
} else {
18201836
output_declaration($declaration_name,
@@ -1827,7 +1843,8 @@ sub dump_function($$) {
18271843
'parametertypes' => \%parametertypes,
18281844
'sectionlist' => \@sectionlist,
18291845
'sections' => \%sections,
1830-
'purpose' => $declaration_purpose
1846+
'purpose' => $declaration_purpose,
1847+
'func_macro' => $func_macro
18311848
});
18321849
}
18331850
}

0 commit comments

Comments
 (0)