Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: cbb4d3e6510b ("scripts/kernel-doc: handle object-like macros")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Horia Geanta <horia.geanta@freescale.com>
Tested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20241015181107.536894-1-rdunlap@infradead.org

authored by

Randy Dunlap and committed by
Jonathan Corbet
bb8fd09e 878b56e0

+30 -13
+30 -13
scripts/kernel-doc
··· 569 569 my %args = %{$_[0]}; 570 570 my ($parameter, $section); 571 571 my $count; 572 + my $func_macro = $args{'func_macro'}; 573 + my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty 572 574 573 575 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 574 576 ··· 602 600 $parenth = ""; 603 601 } 604 602 605 - print ".SH ARGUMENTS\n"; 603 + $paramcount = $#{$args{'parameterlist'}}; # -1 is empty 604 + if ($paramcount >= 0) { 605 + print ".SH ARGUMENTS\n"; 606 + } 606 607 foreach $parameter (@{$args{'parameterlist'}}) { 607 608 my $parameter_name = $parameter; 608 609 $parameter_name =~ s/\[.*//; ··· 827 822 my $oldprefix = $lineprefix; 828 823 829 824 my $signature = ""; 830 - if ($args{'functiontype'} ne "") { 831 - $signature = $args{'functiontype'} . " " . $args{'function'} . " ("; 832 - } else { 833 - $signature = $args{'function'} . " ("; 825 + my $func_macro = $args{'func_macro'}; 826 + my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty 827 + 828 + if ($func_macro) { 829 + $signature = $args{'function'}; 830 + } else { 831 + if ($args{'functiontype'}) { 832 + $signature = $args{'functiontype'} . " "; 833 + } 834 + $signature .= $args{'function'} . " ("; 834 835 } 835 836 836 837 my $count = 0; ··· 855 844 } 856 845 } 857 846 858 - $signature .= ")"; 847 + if (!$func_macro) { 848 + $signature .= ")"; 849 + } 859 850 860 851 if ($sphinx_major < 3) { 861 852 if ($args{'typedef'}) { ··· 901 888 # Put our descriptive text into a container (thus an HTML <div>) to help 902 889 # set the function prototypes apart. 903 890 # 904 - print ".. container:: kernelindent\n\n"; 905 891 $lineprefix = " "; 906 - print $lineprefix . "**Parameters**\n\n"; 892 + if ($paramcount >= 0) { 893 + print ".. container:: kernelindent\n\n"; 894 + print $lineprefix . "**Parameters**\n\n"; 895 + } 907 896 foreach $parameter (@{$args{'parameterlist'}}) { 908 897 my $parameter_name = $parameter; 909 898 $parameter_name =~ s/\[.*//; ··· 1719 1704 sub dump_function($$) { 1720 1705 my $prototype = shift; 1721 1706 my $file = shift; 1722 - my $noret = 0; 1707 + my $func_macro = 0; 1723 1708 1724 1709 print_lineno($new_start_line); 1725 1710 ··· 1784 1769 # declaration_name and opening parenthesis (notice the \s+). 1785 1770 $return_type = $1; 1786 1771 $declaration_name = $2; 1787 - $noret = 1; 1772 + $func_macro = 1; 1788 1773 } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1789 1774 $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1790 1775 $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { ··· 1811 1796 # of warnings goes sufficiently down, the check is only performed in 1812 1797 # -Wreturn mode. 1813 1798 # TODO: always perform the check. 1814 - if ($Wreturn && !$noret) { 1799 + if ($Wreturn && !$func_macro) { 1815 1800 check_return_section($file, $declaration_name, $return_type); 1816 1801 } 1817 1802 ··· 1829 1814 'parametertypes' => \%parametertypes, 1830 1815 'sectionlist' => \@sectionlist, 1831 1816 'sections' => \%sections, 1832 - 'purpose' => $declaration_purpose 1817 + 'purpose' => $declaration_purpose, 1818 + 'func_macro' => $func_macro 1833 1819 }); 1834 1820 } else { 1835 1821 output_declaration($declaration_name, ··· 1843 1827 'parametertypes' => \%parametertypes, 1844 1828 'sectionlist' => \@sectionlist, 1845 1829 'sections' => \%sections, 1846 - 'purpose' => $declaration_purpose 1830 + 'purpose' => $declaration_purpose, 1831 + 'func_macro' => $func_macro 1847 1832 }); 1848 1833 } 1849 1834 }