Commit af404fb1 authored by Vegard Nossum's avatar Vegard Nossum Committed by Jonathan Corbet

scripts/kernel-doc: reindent

This file is using an ungodly mixture of 4 spaces, 2-wide tabs, 4-wide
tabs, _and_ 8-wide tabs, making it really hard to find good editor
settings for working with this file.

Bite the bullet and reindent it by hand. I tried using both perltidy
and vim, but neither of them were up to the task without changing too
much or getting confused about what they were supposed to be doing.

I did change a few instances of

    }
    else

into

    } else

(and same for elsif); the file is again written using both styles, and
I left functions which already seemed self-consistent alone.

You can verify that this commit only changes whitespace using e.g.:

    git diff --ignore-all-space --word-diff

or to see (only) the instances where newlines were added/removed:

    git diff --ignore-all-space

You can also see the delta from what perltidy would have wanted to
do to this file (when asked to only indent it), which isn't that much
in the end:

    perltidy -io -fnl scripts/kernel-doc
    git diff --no-index scripts/kernel-doc{,.tdy}
Signed-off-by: default avatarVegard Nossum <vegard.nossum@oracle.com>
Acked-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/r/20240208161705.888385-1-vegard.nossum@oracle.com
parent 84b4cc81
...@@ -81,49 +81,51 @@ my $type_member_func = $type_member . '\(\)'; ...@@ -81,49 +81,51 @@ my $type_member_func = $type_member . '\(\)';
# these are pretty rough # these are pretty rough
my @highlights_man = ( my @highlights_man = (
[$type_constant, "\$1"], [$type_constant, "\$1"],
[$type_constant2, "\$1"], [$type_constant2, "\$1"],
[$type_func, "\\\\fB\$1\\\\fP"], [$type_func, "\\\\fB\$1\\\\fP"],
[$type_enum, "\\\\fI\$1\\\\fP"], [$type_enum, "\\\\fI\$1\\\\fP"],
[$type_struct, "\\\\fI\$1\\\\fP"], [$type_struct, "\\\\fI\$1\\\\fP"],
[$type_typedef, "\\\\fI\$1\\\\fP"], [$type_typedef, "\\\\fI\$1\\\\fP"],
[$type_union, "\\\\fI\$1\\\\fP"], [$type_union, "\\\\fI\$1\\\\fP"],
[$type_param, "\\\\fI\$1\\\\fP"], [$type_param, "\\\\fI\$1\\\\fP"],
[$type_param_ref, "\\\\fI\$1\$2\\\\fP"], [$type_param_ref, "\\\\fI\$1\$2\\\\fP"],
[$type_member, "\\\\fI\$1\$2\$3\\\\fP"], [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
[$type_fallback, "\\\\fI\$1\\\\fP"] [$type_fallback, "\\\\fI\$1\\\\fP"]
); );
my $blankline_man = ""; my $blankline_man = "";
# rst-mode # rst-mode
my @highlights_rst = ( my @highlights_rst = (
[$type_constant, "``\$1``"], [$type_constant, "``\$1``"],
[$type_constant2, "``\$1``"], [$type_constant2, "``\$1``"],
# Note: need to escape () to avoid func matching later
[$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], # Note: need to escape () to avoid func matching later
[$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
[$type_fp_param, "**\$1\\\\(\\\\)**"], [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
[$type_fp_param2, "**\$1\\\\(\\\\)**"], [$type_fp_param, "**\$1\\\\(\\\\)**"],
[$type_func, "\$1()"], [$type_fp_param2, "**\$1\\\\(\\\\)**"],
[$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], [$type_func, "\$1()"],
[$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
[$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
[$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
# in rst this can refer to any type [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
[$type_fallback, "\\:c\\:type\\:`\$1`"],
[$type_param_ref, "**\$1\$2**"] # in rst this can refer to any type
); [$type_fallback, "\\:c\\:type\\:`\$1`"],
[$type_param_ref, "**\$1\$2**"]
);
my $blankline_rst = "\n"; my $blankline_rst = "\n";
# read arguments # read arguments
if ($#ARGV == -1) { if ($#ARGV == -1) {
pod2usage( pod2usage(
-message => "No arguments!\n", -message => "No arguments!\n",
-exitval => 1, -exitval => 1,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS', -sections => 'SYNOPSIS',
-output => \*STDERR, -output => \*STDERR,
); );
} }
my $kernelversion; my $kernelversion;
...@@ -164,9 +166,9 @@ if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && ...@@ -164,9 +166,9 @@ if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
} }
my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'July', 'August', 'September', 'October',
'November', 'December')[$build_time[4]] . 'November', 'December')[$build_time[4]] .
" " . ($build_time[5]+1900); " " . ($build_time[5]+1900);
# Essentially these are globals. # Essentially these are globals.
# They probably want to be tidied up, made more localised or something. # They probably want to be tidied up, made more localised or something.
...@@ -179,22 +181,22 @@ my ($type, $declaration_name, $return_type); ...@@ -179,22 +181,22 @@ my ($type, $declaration_name, $return_type);
my ($newsection, $newcontents, $prototype, $brcount, %source_map); my ($newsection, $newcontents, $prototype, $brcount, %source_map);
if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') {
$verbose = 1; $verbose = 1;
} }
if (defined($ENV{'KCFLAGS'})) { if (defined($ENV{'KCFLAGS'})) {
my $kcflags = "$ENV{'KCFLAGS'}"; my $kcflags = "$ENV{'KCFLAGS'}";
if ($kcflags =~ /(\s|^)-Werror(\s|$)/) { if ($kcflags =~ /(\s|^)-Werror(\s|$)/) {
$Werror = 1; $Werror = 1;
} }
} }
# reading this variable is for backwards compat just in case # reading this variable is for backwards compat just in case
# someone was calling it with the variable from outside the # someone was calling it with the variable from outside the
# kernel's build system # kernel's build system
if (defined($ENV{'KDOC_WERROR'})) { if (defined($ENV{'KDOC_WERROR'})) {
$Werror = "$ENV{'KDOC_WERROR'}"; $Werror = "$ENV{'KDOC_WERROR'}";
} }
# other environment variables are converted to command-line # other environment variables are converted to command-line
# arguments in cmd_checkdoc in the build system # arguments in cmd_checkdoc in the build system
...@@ -295,90 +297,90 @@ while ($ARGV[0] =~ m/^--?(.*)/) { ...@@ -295,90 +297,90 @@ while ($ARGV[0] =~ m/^--?(.*)/) {
my $cmd = $1; my $cmd = $1;
shift @ARGV; shift @ARGV;
if ($cmd eq "man") { if ($cmd eq "man") {
$output_mode = "man"; $output_mode = "man";
@highlights = @highlights_man; @highlights = @highlights_man;
$blankline = $blankline_man; $blankline = $blankline_man;
} elsif ($cmd eq "rst") { } elsif ($cmd eq "rst") {
$output_mode = "rst"; $output_mode = "rst";
@highlights = @highlights_rst; @highlights = @highlights_rst;
$blankline = $blankline_rst; $blankline = $blankline_rst;
} elsif ($cmd eq "none") { } elsif ($cmd eq "none") {
$output_mode = "none"; $output_mode = "none";
} elsif ($cmd eq "module") { # not needed for XML, inherits from calling document } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document
$modulename = shift @ARGV; $modulename = shift @ARGV;
} elsif ($cmd eq "function") { # to only output specific functions } elsif ($cmd eq "function") { # to only output specific functions
$output_selection = OUTPUT_INCLUDE; $output_selection = OUTPUT_INCLUDE;
$function = shift @ARGV; $function = shift @ARGV;
$function_table{$function} = 1; $function_table{$function} = 1;
} elsif ($cmd eq "nosymbol") { # Exclude specific symbols } elsif ($cmd eq "nosymbol") { # Exclude specific symbols
my $symbol = shift @ARGV; my $symbol = shift @ARGV;
$nosymbol_table{$symbol} = 1; $nosymbol_table{$symbol} = 1;
} elsif ($cmd eq "export") { # only exported symbols } elsif ($cmd eq "export") { # only exported symbols
$output_selection = OUTPUT_EXPORTED; $output_selection = OUTPUT_EXPORTED;
%function_table = (); %function_table = ();
} elsif ($cmd eq "internal") { # only non-exported symbols } elsif ($cmd eq "internal") { # only non-exported symbols
$output_selection = OUTPUT_INTERNAL; $output_selection = OUTPUT_INTERNAL;
%function_table = (); %function_table = ();
} elsif ($cmd eq "export-file") { } elsif ($cmd eq "export-file") {
my $file = shift @ARGV; my $file = shift @ARGV;
push(@export_file_list, $file); push(@export_file_list, $file);
} elsif ($cmd eq "v") { } elsif ($cmd eq "v") {
$verbose = 1; $verbose = 1;
} elsif ($cmd eq "Werror") { } elsif ($cmd eq "Werror") {
$Werror = 1; $Werror = 1;
} elsif ($cmd eq "Wreturn") { } elsif ($cmd eq "Wreturn") {
$Wreturn = 1; $Wreturn = 1;
} elsif ($cmd eq "Wshort-desc" or $cmd eq "Wshort-description") { } elsif ($cmd eq "Wshort-desc" or $cmd eq "Wshort-description") {
$Wshort_desc = 1; $Wshort_desc = 1;
} elsif ($cmd eq "Wcontents-before-sections") { } elsif ($cmd eq "Wcontents-before-sections") {
$Wcontents_before_sections = 1; $Wcontents_before_sections = 1;
} elsif ($cmd eq "Wall") { } elsif ($cmd eq "Wall") {
$Wreturn = 1; $Wreturn = 1;
$Wshort_desc = 1; $Wshort_desc = 1;
$Wcontents_before_sections = 1; $Wcontents_before_sections = 1;
} elsif (($cmd eq "h") || ($cmd eq "help")) { } elsif (($cmd eq "h") || ($cmd eq "help")) {
pod2usage(-exitval => 0, -verbose => 2); pod2usage(-exitval => 0, -verbose => 2);
} elsif ($cmd eq 'no-doc-sections') { } elsif ($cmd eq 'no-doc-sections') {
$no_doc_sections = 1; $no_doc_sections = 1;
} elsif ($cmd eq 'enable-lineno') { } elsif ($cmd eq 'enable-lineno') {
$enable_lineno = 1; $enable_lineno = 1;
} elsif ($cmd eq 'show-not-found') { } elsif ($cmd eq 'show-not-found') {
$show_not_found = 1; # A no-op but don't fail $show_not_found = 1; # A no-op but don't fail
} elsif ($cmd eq "sphinx-version") { } elsif ($cmd eq "sphinx-version") {
my $ver_string = shift @ARGV; my $ver_string = shift @ARGV;
if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) {
$sphinx_major = $1; $sphinx_major = $1;
if (defined($2)) { if (defined($2)) {
$sphinx_minor = substr($2,1); $sphinx_minor = substr($2,1);
} else { } else {
$sphinx_minor = 0; $sphinx_minor = 0;
} }
if (defined($3)) { if (defined($3)) {
$sphinx_patch = substr($3,1) $sphinx_patch = substr($3,1)
} else { } else {
$sphinx_patch = 0; $sphinx_patch = 0;
} }
} else { } else {
die "Sphinx version should either major.minor or major.minor.patch format\n"; die "Sphinx version should either major.minor or major.minor.patch format\n";
} }
} else { } else {
# Unknown argument # Unknown argument
pod2usage( pod2usage(
-message => "Argument unknown!\n", -message => "Argument unknown!\n",
-exitval => 1, -exitval => 1,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS', -sections => 'SYNOPSIS',
-output => \*STDERR, -output => \*STDERR,
); );
} }
if ($#ARGV < 0){ if ($#ARGV < 0){
pod2usage( pod2usage(
-message => "FILE argument missing\n", -message => "FILE argument missing\n",
-exitval => 1, -exitval => 1,
-verbose => 99, -verbose => 99,
-sections => 'SYNOPSIS', -sections => 'SYNOPSIS',
-output => \*STDERR, -output => \*STDERR,
); );
} }
} }
...@@ -388,45 +390,45 @@ while ($ARGV[0] =~ m/^--?(.*)/) { ...@@ -388,45 +390,45 @@ while ($ARGV[0] =~ m/^--?(.*)/) {
# version in order to produce the right tags. # version in order to produce the right tags.
sub findprog($) sub findprog($)
{ {
foreach(split(/:/, $ENV{PATH})) { foreach(split(/:/, $ENV{PATH})) {
return "$_/$_[0]" if(-x "$_/$_[0]"); return "$_/$_[0]" if(-x "$_/$_[0]");
} }
} }
sub get_sphinx_version() sub get_sphinx_version()
{ {
my $ver; my $ver;
my $cmd = "sphinx-build"; my $cmd = "sphinx-build";
if (!findprog($cmd)) { if (!findprog($cmd)) {
my $cmd = "sphinx-build3"; my $cmd = "sphinx-build3";
if (!findprog($cmd)) { if (!findprog($cmd)) {
$sphinx_major = 1; $sphinx_major = 1;
$sphinx_minor = 2; $sphinx_minor = 2;
$sphinx_patch = 0; $sphinx_patch = 0;
printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n",
$sphinx_major, $sphinx_minor, $sphinx_patch; $sphinx_major, $sphinx_minor, $sphinx_patch;
return; return;
} }
} }
open IN, "$cmd --version 2>&1 |"; open IN, "$cmd --version 2>&1 |";
while (<IN>) { while (<IN>) {
if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) {
$sphinx_major = $1; $sphinx_major = $1;
$sphinx_minor = $2; $sphinx_minor = $2;
$sphinx_patch = $3; $sphinx_patch = $3;
last; last;
} }
# Sphinx 1.2.x uses a different format # Sphinx 1.2.x uses a different format
if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) {
$sphinx_major = $1; $sphinx_major = $1;
$sphinx_minor = $2; $sphinx_minor = $2;
$sphinx_patch = $3; $sphinx_patch = $3;
last; last;
} }
} }
close IN; close IN;
} }
# get kernel version from env # get kernel version from env
...@@ -434,7 +436,7 @@ sub get_kernel_version() { ...@@ -434,7 +436,7 @@ sub get_kernel_version() {
my $version = 'unknown kernel version'; my $version = 'unknown kernel version';
if (defined($ENV{'KERNELVERSION'})) { if (defined($ENV{'KERNELVERSION'})) {
$version = $ENV{'KERNELVERSION'}; $version = $ENV{'KERNELVERSION'};
} }
return $version; return $version;
} }
...@@ -462,30 +464,30 @@ sub dump_section { ...@@ -462,30 +464,30 @@ sub dump_section {
my $contents = join "\n", @_; my $contents = join "\n", @_;
if ($name =~ m/$type_param/) { if ($name =~ m/$type_param/) {
$name = $1; $name = $1;
$parameterdescs{$name} = $contents; $parameterdescs{$name} = $contents;
$sectcheck = $sectcheck . $name . " "; $sectcheck = $sectcheck . $name . " ";
$parameterdesc_start_lines{$name} = $new_start_line; $parameterdesc_start_lines{$name} = $new_start_line;
$new_start_line = 0; $new_start_line = 0;
} elsif ($name eq "@\.\.\.") { } elsif ($name eq "@\.\.\.") {
$name = "..."; $name = "...";
$parameterdescs{$name} = $contents; $parameterdescs{$name} = $contents;
$sectcheck = $sectcheck . $name . " "; $sectcheck = $sectcheck . $name . " ";
$parameterdesc_start_lines{$name} = $new_start_line; $parameterdesc_start_lines{$name} = $new_start_line;
$new_start_line = 0; $new_start_line = 0;
} else { } else {
if (defined($sections{$name}) && ($sections{$name} ne "")) { if (defined($sections{$name}) && ($sections{$name} ne "")) {
# Only warn on user specified duplicate section names. # Only warn on user specified duplicate section names.
if ($name ne $section_default) { if ($name ne $section_default) {
emit_warning("${file}:$.", "duplicate section name '$name'\n"); emit_warning("${file}:$.", "duplicate section name '$name'\n");
} }
$sections{$name} .= $contents; $sections{$name} .= $contents;
} else { } else {
$sections{$name} = $contents; $sections{$name} = $contents;
push @sectionlist, $name; push @sectionlist, $name;
$section_start_lines{$name} = $new_start_line; $section_start_lines{$name} = $new_start_line;
$new_start_line = 0; $new_start_line = 0;
} }
} }
} }
...@@ -504,14 +506,14 @@ sub dump_doc_section { ...@@ -504,14 +506,14 @@ sub dump_doc_section {
return if (defined($nosymbol_table{$name})); return if (defined($nosymbol_table{$name}));
if (($output_selection == OUTPUT_ALL) || if (($output_selection == OUTPUT_ALL) ||
(($output_selection == OUTPUT_INCLUDE) && (($output_selection == OUTPUT_INCLUDE) &&
defined($function_table{$name}))) defined($function_table{$name})))
{ {
dump_section($file, $name, $contents); dump_section($file, $name, $contents);
output_blockhead({'sectionlist' => \@sectionlist, output_blockhead({'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'module' => $modulename, 'module' => $modulename,
'content-only' => ($output_selection != OUTPUT_ALL), }); 'content-only' => ($output_selection != OUTPUT_ALL), });
} }
} }
...@@ -542,21 +544,21 @@ sub output_highlight { ...@@ -542,21 +544,21 @@ sub output_highlight {
# print STDERR "contents af:$contents\n"; # print STDERR "contents af:$contents\n";
foreach $line (split "\n", $contents) { foreach $line (split "\n", $contents) {
if (! $output_preformatted) { if (! $output_preformatted) {
$line =~ s/^\s*//; $line =~ s/^\s*//;
} }
if ($line eq ""){ if ($line eq ""){
if (! $output_preformatted) { if (! $output_preformatted) {
print $lineprefix, $blankline; print $lineprefix, $blankline;
} }
} else { } else {
if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
print "\\&$line"; print "\\&$line";
} else { } else {
print $lineprefix, $line; print $lineprefix, $line;
} }
} }
print "\n"; print "\n";
} }
} }
...@@ -574,40 +576,40 @@ sub output_function_man(%) { ...@@ -574,40 +576,40 @@ sub output_function_man(%) {
print ".SH SYNOPSIS\n"; print ".SH SYNOPSIS\n";
if ($args{'functiontype'} ne "") { if ($args{'functiontype'} ne "") {
print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
} else { } else {
print ".B \"" . $args{'function'} . "\n"; print ".B \"" . $args{'function'} . "\n";
} }
$count = 0; $count = 0;
my $parenth = "("; my $parenth = "(";
my $post = ","; my $post = ",";
foreach my $parameter (@{$args{'parameterlist'}}) { foreach my $parameter (@{$args{'parameterlist'}}) {
if ($count == $#{$args{'parameterlist'}}) { if ($count == $#{$args{'parameterlist'}}) {
$post = ");"; $post = ");";
} }
$type = $args{'parametertypes'}{$parameter}; $type = $args{'parametertypes'}{$parameter};
if ($type =~ m/$function_pointer/) { if ($type =~ m/$function_pointer/) {
# pointer-to-function # pointer-to-function
print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n";
} else { } else {
$type =~ s/([^\*])$/$1 /; $type =~ s/([^\*])$/$1 /;
print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n";
} }
$count++; $count++;
$parenth = ""; $parenth = "";
} }
print ".SH ARGUMENTS\n"; print ".SH ARGUMENTS\n";
foreach $parameter (@{$args{'parameterlist'}}) { foreach $parameter (@{$args{'parameterlist'}}) {
my $parameter_name = $parameter; my $parameter_name = $parameter;
$parameter_name =~ s/\[.*//; $parameter_name =~ s/\[.*//;
print ".IP \"" . $parameter . "\" 12\n"; print ".IP \"" . $parameter . "\" 12\n";
output_highlight($args{'parameterdescs'}{$parameter_name}); output_highlight($args{'parameterdescs'}{$parameter_name});
} }
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
print ".SH \"", uc $section, "\"\n"; print ".SH \"", uc $section, "\"\n";
output_highlight($args{'sections'}{$section}); output_highlight($args{'sections'}{$section});
} }
} }
...@@ -627,28 +629,27 @@ sub output_enum_man(%) { ...@@ -627,28 +629,27 @@ sub output_enum_man(%) {
print "enum " . $args{'enum'} . " {\n"; print "enum " . $args{'enum'} . " {\n";
$count = 0; $count = 0;
foreach my $parameter (@{$args{'parameterlist'}}) { foreach my $parameter (@{$args{'parameterlist'}}) {
print ".br\n.BI \" $parameter\"\n"; print ".br\n.BI \" $parameter\"\n";
if ($count == $#{$args{'parameterlist'}}) { if ($count == $#{$args{'parameterlist'}}) {
print "\n};\n"; print "\n};\n";
last; last;
} } else {
else { print ", \n.br\n";
print ", \n.br\n"; }
} $count++;
$count++;
} }
print ".SH Constants\n"; print ".SH Constants\n";
foreach $parameter (@{$args{'parameterlist'}}) { foreach $parameter (@{$args{'parameterlist'}}) {
my $parameter_name = $parameter; my $parameter_name = $parameter;
$parameter_name =~ s/\[.*//; $parameter_name =~ s/\[.*//;
print ".IP \"" . $parameter . "\" 12\n"; print ".IP \"" . $parameter . "\" 12\n";
output_highlight($args{'parameterdescs'}{$parameter_name}); output_highlight($args{'parameterdescs'}{$parameter_name});
} }
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
print ".SH \"$section\"\n"; print ".SH \"$section\"\n";
output_highlight($args{'sections'}{$section}); output_highlight($args{'sections'}{$section});
} }
} }
...@@ -672,18 +673,18 @@ sub output_struct_man(%) { ...@@ -672,18 +673,18 @@ sub output_struct_man(%) {
print ".SH Members\n"; print ".SH Members\n";
foreach $parameter (@{$args{'parameterlist'}}) { foreach $parameter (@{$args{'parameterlist'}}) {
($parameter =~ /^#/) && next; ($parameter =~ /^#/) && next;
my $parameter_name = $parameter; my $parameter_name = $parameter;
$parameter_name =~ s/\[.*//; $parameter_name =~ s/\[.*//;
($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
print ".IP \"" . $parameter . "\" 12\n"; print ".IP \"" . $parameter . "\" 12\n";
output_highlight($args{'parameterdescs'}{$parameter_name}); output_highlight($args{'parameterdescs'}{$parameter_name});
} }
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
print ".SH \"$section\"\n"; print ".SH \"$section\"\n";
output_highlight($args{'sections'}{$section}); output_highlight($args{'sections'}{$section});
} }
} }
...@@ -699,8 +700,8 @@ sub output_typedef_man(%) { ...@@ -699,8 +700,8 @@ sub output_typedef_man(%) {
print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
print ".SH \"$section\"\n"; print ".SH \"$section\"\n";
output_highlight($args{'sections'}{$section}); output_highlight($args{'sections'}{$section});
} }
} }
...@@ -712,8 +713,8 @@ sub output_blockhead_man(%) { ...@@ -712,8 +713,8 @@ sub output_blockhead_man(%) {
print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
print ".SH \"$section\"\n"; print ".SH \"$section\"\n";
output_highlight($args{'sections'}{$section}); output_highlight($args{'sections'}{$section});
} }
} }
...@@ -731,15 +732,15 @@ sub output_blockhead_rst(%) { ...@@ -731,15 +732,15 @@ sub output_blockhead_rst(%) {
my ($parameter, $section); my ($parameter, $section);
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
next if (defined($nosymbol_table{$section})); next if (defined($nosymbol_table{$section}));
if ($output_selection != OUTPUT_INCLUDE) { if ($output_selection != OUTPUT_INCLUDE) {
print ".. _$section:\n\n"; print ".. _$section:\n\n";
print "**$section**\n\n"; print "**$section**\n\n";
} }
print_lineno($section_start_lines{$section}); print_lineno($section_start_lines{$section});
output_highlight_rst($args{'sections'}{$section}); output_highlight_rst($args{'sections'}{$section});
print "\n"; print "\n";
} }
} }
...@@ -769,48 +770,48 @@ sub output_highlight_rst { ...@@ -769,48 +770,48 @@ sub output_highlight_rst {
my $block = ""; my $block = "";
foreach $line (split "\n",$input) { foreach $line (split "\n",$input) {
# #
# If we're in a literal block, see if we should drop out # If we're in a literal block, see if we should drop out
# of it. Otherwise pass the line straight through unmunged. # of it. Otherwise pass the line straight through unmunged.
# #
if ($in_literal) { if ($in_literal) {
if (! ($line =~ /^\s*$/)) { if (! ($line =~ /^\s*$/)) {
# #
# If this is the first non-blank line in a literal # If this is the first non-blank line in a literal
# block we need to figure out what the proper indent is. # block we need to figure out what the proper indent is.
# #
if ($litprefix eq "") { if ($litprefix eq "") {
$line =~ /^(\s*)/; $line =~ /^(\s*)/;
$litprefix = '^' . $1; $litprefix = '^' . $1;
$output .= $line . "\n"; $output .= $line . "\n";
} elsif (! ($line =~ /$litprefix/)) { } elsif (! ($line =~ /$litprefix/)) {
$in_literal = 0; $in_literal = 0;
} else { } else {
$output .= $line . "\n"; $output .= $line . "\n";
} }
} else { } else {
$output .= $line . "\n"; $output .= $line . "\n";
} }
} }
# #
# Not in a literal block (or just dropped out) # Not in a literal block (or just dropped out)
# #
if (! $in_literal) { if (! $in_literal) {
$block .= $line . "\n"; $block .= $line . "\n";
if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) {
$in_literal = 1; $in_literal = 1;
$litprefix = ""; $litprefix = "";
$output .= highlight_block($block); $output .= highlight_block($block);
$block = "" $block = ""
} }
} }
} }
if ($block) { if ($block) {
$output .= highlight_block($block); $output .= highlight_block($block);
} }
foreach $line (split "\n", $output) { foreach $line (split "\n", $output) {
print $lineprefix . $line . "\n"; print $lineprefix . $line . "\n";
} }
} }
...@@ -822,67 +823,67 @@ sub output_function_rst(%) { ...@@ -822,67 +823,67 @@ sub output_function_rst(%) {
my $is_macro = 0; my $is_macro = 0;
if ($sphinx_major < 3) { if ($sphinx_major < 3) {
if ($args{'typedef'}) { if ($args{'typedef'}) {
print ".. c:type:: ". $args{'function'} . "\n\n"; print ".. c:type:: ". $args{'function'} . "\n\n";
print_lineno($declaration_start_line); print_lineno($declaration_start_line);
print " **Typedef**: "; print " **Typedef**: ";
$lineprefix = ""; $lineprefix = "";
output_highlight_rst($args{'purpose'}); output_highlight_rst($args{'purpose'});
$start = "\n\n**Syntax**\n\n ``"; $start = "\n\n**Syntax**\n\n ``";
$is_macro = 1; $is_macro = 1;
} else { } else {
print ".. c:function:: "; print ".. c:function:: ";
} }
} else { } else {
if ($args{'typedef'} || $args{'functiontype'} eq "") { if ($args{'typedef'} || $args{'functiontype'} eq "") {
$is_macro = 1; $is_macro = 1;
print ".. c:macro:: ". $args{'function'} . "\n\n"; print ".. c:macro:: ". $args{'function'} . "\n\n";
} else { } else {
print ".. c:function:: "; print ".. c:function:: ";
} }
if ($args{'typedef'}) { if ($args{'typedef'}) {
print_lineno($declaration_start_line); print_lineno($declaration_start_line);
print " **Typedef**: "; print " **Typedef**: ";
$lineprefix = ""; $lineprefix = "";
output_highlight_rst($args{'purpose'}); output_highlight_rst($args{'purpose'});
$start = "\n\n**Syntax**\n\n ``"; $start = "\n\n**Syntax**\n\n ``";
} else { } else {
print "``" if ($is_macro); print "``" if ($is_macro);
} }
} }
if ($args{'functiontype'} ne "") { if ($args{'functiontype'} ne "") {
$start .= $args{'functiontype'} . " " . $args{'function'} . " ("; $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
} else { } else {
$start .= $args{'function'} . " ("; $start .= $args{'function'} . " (";
} }
print $start; print $start;
my $count = 0; my $count = 0;
foreach my $parameter (@{$args{'parameterlist'}}) { foreach my $parameter (@{$args{'parameterlist'}}) {
if ($count ne 0) { if ($count ne 0) {
print ", "; print ", ";
} }
$count++; $count++;
$type = $args{'parametertypes'}{$parameter}; $type = $args{'parametertypes'}{$parameter};
if ($type =~ m/$function_pointer/) { if ($type =~ m/$function_pointer/) {
# pointer-to-function # pointer-to-function
print $1 . $parameter . ") (" . $2 . ")"; print $1 . $parameter . ") (" . $2 . ")";
} else { } else {
print $type; print $type;
} }
} }
if ($is_macro) { if ($is_macro) {
print ")``\n\n"; print ")``\n\n";
} else { } else {
print ")\n\n"; print ")\n\n";
} }
if (!$args{'typedef'}) { if (!$args{'typedef'}) {
print_lineno($declaration_start_line); print_lineno($declaration_start_line);
$lineprefix = " "; $lineprefix = " ";
output_highlight_rst($args{'purpose'}); output_highlight_rst($args{'purpose'});
print "\n"; print "\n";
} }
# #
...@@ -893,27 +894,27 @@ sub output_function_rst(%) { ...@@ -893,27 +894,27 @@ sub output_function_rst(%) {
$lineprefix = " "; $lineprefix = " ";
print $lineprefix . "**Parameters**\n\n"; print $lineprefix . "**Parameters**\n\n";
foreach $parameter (@{$args{'parameterlist'}}) { foreach $parameter (@{$args{'parameterlist'}}) {
my $parameter_name = $parameter; my $parameter_name = $parameter;
$parameter_name =~ s/\[.*//; $parameter_name =~ s/\[.*//;
$type = $args{'parametertypes'}{$parameter}; $type = $args{'parametertypes'}{$parameter};
if ($type ne "") { if ($type ne "") {
print $lineprefix . "``$type``\n"; print $lineprefix . "``$type``\n";
} else { } else {
print $lineprefix . "``$parameter``\n"; print $lineprefix . "``$parameter``\n";
} }
print_lineno($parameterdesc_start_lines{$parameter_name}); print_lineno($parameterdesc_start_lines{$parameter_name});
$lineprefix = " "; $lineprefix = " ";
if (defined($args{'parameterdescs'}{$parameter_name}) && if (defined($args{'parameterdescs'}{$parameter_name}) &&
$args{'parameterdescs'}{$parameter_name} ne $undescribed) { $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
output_highlight_rst($args{'parameterdescs'}{$parameter_name}); output_highlight_rst($args{'parameterdescs'}{$parameter_name});
} else { } else {
print $lineprefix . "*undescribed*\n"; print $lineprefix . "*undescribed*\n";
} }
$lineprefix = " "; $lineprefix = " ";
print "\n"; print "\n";
} }
output_section_rst(@_); output_section_rst(@_);
...@@ -926,10 +927,10 @@ sub output_section_rst(%) { ...@@ -926,10 +927,10 @@ sub output_section_rst(%) {
my $oldprefix = $lineprefix; my $oldprefix = $lineprefix;
foreach $section (@{$args{'sectionlist'}}) { foreach $section (@{$args{'sectionlist'}}) {
print $lineprefix . "**$section**\n\n"; print $lineprefix . "**$section**\n\n";
print_lineno($section_start_lines{$section}); print_lineno($section_start_lines{$section});
output_highlight_rst($args{'sections'}{$section}); output_highlight_rst($args{'sections'}{$section});
print "\n"; print "\n";
} }
print "\n"; print "\n";
} }
...@@ -942,11 +943,11 @@ sub output_enum_rst(%) { ...@@ -942,11 +943,11 @@ sub output_enum_rst(%) {
my $outer; my $outer;
if ($sphinx_major < 3) { if ($sphinx_major < 3) {
my $name = "enum " . $args{'enum'}; my $name = "enum " . $args{'enum'};
print "\n\n.. c:type:: " . $name . "\n\n"; print "\n\n.. c:type:: " . $name . "\n\n";
} else { } else {
my $name = $args{'enum'}; my $name = $args{'enum'};
print "\n\n.. c:enum:: " . $name . "\n\n"; print "\n\n.. c:enum:: " . $name . "\n\n";
} }
print_lineno($declaration_start_line); print_lineno($declaration_start_line);
$lineprefix = " "; $lineprefix = " ";
...@@ -958,14 +959,14 @@ sub output_enum_rst(%) { ...@@ -958,14 +959,14 @@ sub output_enum_rst(%) {
$lineprefix = $outer . " "; $lineprefix = $outer . " ";
print $outer . "**Constants**\n\n"; print $outer . "**Constants**\n\n";
foreach $parameter (@{$args{'parameterlist'}}) { foreach $parameter (@{$args{'parameterlist'}}) {
print $outer . "``$parameter``\n"; print $outer . "``$parameter``\n";
if ($args{'parameterdescs'}{$parameter} ne $undescribed) { if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
output_highlight_rst($args{'parameterdescs'}{$parameter}); output_highlight_rst($args{'parameterdescs'}{$parameter});
} else { } else {
print $lineprefix . "*undescribed*\n"; print $lineprefix . "*undescribed*\n";
} }
print "\n"; print "\n";
} }
print "\n"; print "\n";
$lineprefix = $oldprefix; $lineprefix = $oldprefix;
...@@ -979,9 +980,9 @@ sub output_typedef_rst(%) { ...@@ -979,9 +980,9 @@ sub output_typedef_rst(%) {
my $name; my $name;
if ($sphinx_major < 3) { if ($sphinx_major < 3) {
$name = "typedef " . $args{'typedef'}; $name = "typedef " . $args{'typedef'};
} else { } else {
$name = $args{'typedef'}; $name = $args{'typedef'};
} }
print "\n\n.. c:type:: " . $name . "\n\n"; print "\n\n.. c:type:: " . $name . "\n\n";
print_lineno($declaration_start_line); print_lineno($declaration_start_line);
...@@ -999,15 +1000,15 @@ sub output_struct_rst(%) { ...@@ -999,15 +1000,15 @@ sub output_struct_rst(%) {
my $oldprefix = $lineprefix; my $oldprefix = $lineprefix;
if ($sphinx_major < 3) { if ($sphinx_major < 3) {
my $name = $args{'type'} . " " . $args{'struct'}; my $name = $args{'type'} . " " . $args{'struct'};
print "\n\n.. c:type:: " . $name . "\n\n"; print "\n\n.. c:type:: " . $name . "\n\n";
} else { } else {
my $name = $args{'struct'}; my $name = $args{'struct'};
if ($args{'type'} eq 'union') { if ($args{'type'} eq 'union') {
print "\n\n.. c:union:: " . $name . "\n\n"; print "\n\n.. c:union:: " . $name . "\n\n";
} else { } else {
print "\n\n.. c:struct:: " . $name . "\n\n"; print "\n\n.. c:struct:: " . $name . "\n\n";
} }
} }
print_lineno($declaration_start_line); print_lineno($declaration_start_line);
$lineprefix = " "; $lineprefix = " ";
...@@ -1024,19 +1025,19 @@ sub output_struct_rst(%) { ...@@ -1024,19 +1025,19 @@ sub output_struct_rst(%) {
$lineprefix = " "; $lineprefix = " ";
print $lineprefix . "**Members**\n\n"; print $lineprefix . "**Members**\n\n";
foreach $parameter (@{$args{'parameterlist'}}) { foreach $parameter (@{$args{'parameterlist'}}) {
($parameter =~ /^#/) && next; ($parameter =~ /^#/) && next;
my $parameter_name = $parameter; my $parameter_name = $parameter;
$parameter_name =~ s/\[.*//; $parameter_name =~ s/\[.*//;
($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
$type = $args{'parametertypes'}{$parameter}; $type = $args{'parametertypes'}{$parameter};
print_lineno($parameterdesc_start_lines{$parameter_name}); print_lineno($parameterdesc_start_lines{$parameter_name});
print $lineprefix . "``" . $parameter . "``\n"; print $lineprefix . "``" . $parameter . "``\n";
$lineprefix = " "; $lineprefix = " ";
output_highlight_rst($args{'parameterdescs'}{$parameter_name}); output_highlight_rst($args{'parameterdescs'}{$parameter_name});
$lineprefix = " "; $lineprefix = " ";
print "\n"; print "\n";
} }
print "\n"; print "\n";
...@@ -1074,14 +1075,14 @@ sub output_declaration { ...@@ -1074,14 +1075,14 @@ sub output_declaration {
return if (defined($nosymbol_table{$name})); return if (defined($nosymbol_table{$name}));
if (($output_selection == OUTPUT_ALL) || if (($output_selection == OUTPUT_ALL) ||
(($output_selection == OUTPUT_INCLUDE || (($output_selection == OUTPUT_INCLUDE ||
$output_selection == OUTPUT_EXPORTED) && $output_selection == OUTPUT_EXPORTED) &&
defined($function_table{$name})) || defined($function_table{$name})) ||
($output_selection == OUTPUT_INTERNAL && ($output_selection == OUTPUT_INTERNAL &&
!($functype eq "function" && defined($function_table{$name})))) !($functype eq "function" && defined($function_table{$name}))))
{ {
&$func(@_); &$func(@_);
$section_counter++; $section_counter++;
} }
} }
...@@ -1120,203 +1121,202 @@ sub dump_struct($$) { ...@@ -1120,203 +1121,202 @@ sub dump_struct($$) {
my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;};
if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { if ($x =~ /($type)\s+(\w+)\s*$definition_body/) {
$decl_type = $1; $decl_type = $1;
$declaration_name = $2; $declaration_name = $2;
$members = $3; $members = $3;
} elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) {
$decl_type = $1; $decl_type = $1;
$declaration_name = $3; $declaration_name = $3;
$members = $2; $members = $2;
} }
if ($members) { if ($members) {
if ($identifier ne $declaration_name) { if ($identifier ne $declaration_name) {
emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"); emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n");
return; return;
} }
# ignore members marked private: # ignore members marked private:
$members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
$members =~ s/\/\*\s*private:.*//gosi; $members =~ s/\/\*\s*private:.*//gosi;
# strip comments: # strip comments:
$members =~ s/\/\*.*?\*\///gos; $members =~ s/\/\*.*?\*\///gos;
# strip attributes # strip attributes
$members =~ s/\s*$attribute/ /gi; $members =~ s/\s*$attribute/ /gi;
$members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos;
$members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos; $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos;
$members =~ s/\s*__packed\s*/ /gos; $members =~ s/\s*__packed\s*/ /gos;
$members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos;
$members =~ s/\s*____cacheline_aligned_in_smp/ /gos; $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;
$members =~ s/\s*____cacheline_aligned/ /gos; $members =~ s/\s*____cacheline_aligned/ /gos;
# unwrap struct_group(): # unwrap struct_group():
# - first eat non-declaration parameters and rewrite for final match # - first eat non-declaration parameters and rewrite for final match
# - then remove macro, outer parens, and trailing semicolon # - then remove macro, outer parens, and trailing semicolon
$members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos;
$members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos;
$members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos;
$members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos;
my $args = qr{([^,)]+)}; my $args = qr{([^,)]+)};
# replace DECLARE_BITMAP # replace DECLARE_BITMAP
$members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos;
$members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos;
$members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
# replace DECLARE_HASHTABLE # replace DECLARE_HASHTABLE
$members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
# replace DECLARE_KFIFO # replace DECLARE_KFIFO
$members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos;
# replace DECLARE_KFIFO_PTR # replace DECLARE_KFIFO_PTR
$members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos;
# replace DECLARE_FLEX_ARRAY # replace DECLARE_FLEX_ARRAY
$members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos;
#replace DEFINE_DMA_UNMAP_ADDR #replace DEFINE_DMA_UNMAP_ADDR
$members =~ s/DEFINE_DMA_UNMAP_ADDR\s*\($args\)/dma_addr_t $1/gos; $members =~ s/DEFINE_DMA_UNMAP_ADDR\s*\($args\)/dma_addr_t $1/gos;
#replace DEFINE_DMA_UNMAP_LEN #replace DEFINE_DMA_UNMAP_LEN
$members =~ s/DEFINE_DMA_UNMAP_LEN\s*\($args\)/__u32 $1/gos; $members =~ s/DEFINE_DMA_UNMAP_LEN\s*\($args\)/__u32 $1/gos;
my $declaration = $members; my $declaration = $members;
# Split nested struct/union elements as newer ones # Split nested struct/union elements as newer ones
while ($members =~ m/$struct_members/) { while ($members =~ m/$struct_members/) {
my $newmember; my $newmember;
my $maintype = $1; my $maintype = $1;
my $ids = $4; my $ids = $4;
my $content = $3; my $content = $3;
foreach my $id(split /,/, $ids) { foreach my $id(split /,/, $ids) {
$newmember .= "$maintype $id; "; $newmember .= "$maintype $id; ";
$id =~ s/[:\[].*//; $id =~ s/[:\[].*//;
$id =~ s/^\s*\**(\S+)\s*/$1/; $id =~ s/^\s*\**(\S+)\s*/$1/;
foreach my $arg (split /;/, $content) { foreach my $arg (split /;/, $content) {
next if ($arg =~ m/^\s*$/); next if ($arg =~ m/^\s*$/);
if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) {
# pointer-to-function # pointer-to-function
my $type = $1; my $type = $1;
my $name = $2; my $name = $2;
my $extra = $3; my $extra = $3;
next if (!$name); next if (!$name);
if ($id =~ m/^\s*$/) { if ($id =~ m/^\s*$/) {
# anonymous struct/union # anonymous struct/union
$newmember .= "$type$name$extra; "; $newmember .= "$type$name$extra; ";
} else { } else {
$newmember .= "$type$id.$name$extra; "; $newmember .= "$type$id.$name$extra; ";
} }
} else { } else {
my $type; my $type;
my $names; my $names;
$arg =~ s/^\s+//; $arg =~ s/^\s+//;
$arg =~ s/\s+$//; $arg =~ s/\s+$//;
# Handle bitmaps # Handle bitmaps
$arg =~ s/:\s*\d+\s*//g; $arg =~ s/:\s*\d+\s*//g;
# Handle arrays # Handle arrays
$arg =~ s/\[.*\]//g; $arg =~ s/\[.*\]//g;
# The type may have multiple words, # The type may have multiple words,
# and multiple IDs can be defined, like: # and multiple IDs can be defined, like:
# const struct foo, *bar, foobar # const struct foo, *bar, foobar
# So, we remove spaces when parsing the # So, we remove spaces when parsing the
# names, in order to match just names # names, in order to match just names
# and commas for the names # and commas for the names
$arg =~ s/\s*,\s*/,/g; $arg =~ s/\s*,\s*/,/g;
if ($arg =~ m/(.*)\s+([\S+,]+)/) { if ($arg =~ m/(.*)\s+([\S+,]+)/) {
$type = $1; $type = $1;
$names = $2; $names = $2;
} else { } else {
$newmember .= "$arg; "; $newmember .= "$arg; ";
next; next;
} }
foreach my $name (split /,/, $names) { foreach my $name (split /,/, $names) {
$name =~ s/^\s*\**(\S+)\s*/$1/; $name =~ s/^\s*\**(\S+)\s*/$1/;
next if (($name =~ m/^\s*$/)); next if (($name =~ m/^\s*$/));
if ($id =~ m/^\s*$/) { if ($id =~ m/^\s*$/) {
# anonymous struct/union # anonymous struct/union
$newmember .= "$type $name; "; $newmember .= "$type $name; ";
} else { } else {
$newmember .= "$type $id.$name; "; $newmember .= "$type $id.$name; ";
} }
} }
} }
} }
} }
$members =~ s/$struct_members/$newmember/; $members =~ s/$struct_members/$newmember/;
} }
# Ignore other nested elements, like enums # Ignore other nested elements, like enums
$members =~ s/(\{[^\{\}]*\})//g; $members =~ s/(\{[^\{\}]*\})//g;
create_parameterlist($members, ';', $file, $declaration_name); create_parameterlist($members, ';', $file, $declaration_name);
check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
# Adjust declaration for better display # Adjust declaration for better display
$declaration =~ s/([\{;])/$1\n/g; $declaration =~ s/([\{;])/$1\n/g;
$declaration =~ s/\}\s+;/};/g; $declaration =~ s/\}\s+;/};/g;
# Better handle inlined enums # Better handle inlined enums
do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);
my @def_args = split /\n/, $declaration; my @def_args = split /\n/, $declaration;
my $level = 1; my $level = 1;
$declaration = ""; $declaration = "";
foreach my $clause (@def_args) { foreach my $clause (@def_args) {
$clause =~ s/^\s+//; $clause =~ s/^\s+//;
$clause =~ s/\s+$//; $clause =~ s/\s+$//;
$clause =~ s/\s+/ /; $clause =~ s/\s+/ /;
next if (!$clause); next if (!$clause);
$level-- if ($clause =~ m/(\})/ && $level > 1); $level-- if ($clause =~ m/(\})/ && $level > 1);
if (!($clause =~ m/^\s*#/)) { if (!($clause =~ m/^\s*#/)) {
$declaration .= "\t" x $level; $declaration .= "\t" x $level;
} }
$declaration .= "\t" . $clause . "\n"; $declaration .= "\t" . $clause . "\n";
$level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
} }
output_declaration($declaration_name, output_declaration($declaration_name,
'struct', 'struct',
{'struct' => $declaration_name, {'struct' => $declaration_name,
'module' => $modulename, 'module' => $modulename,
'definition' => $declaration, 'definition' => $declaration,
'parameterlist' => \@parameterlist, 'parameterlist' => \@parameterlist,
'parameterdescs' => \%parameterdescs, 'parameterdescs' => \%parameterdescs,
'parametertypes' => \%parametertypes, 'parametertypes' => \%parametertypes,
'sectionlist' => \@sectionlist, 'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'purpose' => $declaration_purpose, 'purpose' => $declaration_purpose,
'type' => $decl_type 'type' => $decl_type
}); });
} } else {
else { print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; ++$errors;
++$errors;
} }
} }
sub show_warnings($$) { sub show_warnings($$) {
my $functype = shift; my $functype = shift;
my $name = shift; my $name = shift;
return 0 if (defined($nosymbol_table{$name})); return 0 if (defined($nosymbol_table{$name}));
return 1 if ($output_selection == OUTPUT_ALL); return 1 if ($output_selection == OUTPUT_ALL);
if ($output_selection == OUTPUT_EXPORTED) { if ($output_selection == OUTPUT_EXPORTED) {
if (defined($function_table{$name})) { if (defined($function_table{$name})) {
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
if ($output_selection == OUTPUT_INTERNAL) { if ($output_selection == OUTPUT_INTERNAL) {
if (!($functype eq "function" && defined($function_table{$name}))) { if (!($functype eq "function" && defined($function_table{$name}))) {
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
if ($output_selection == OUTPUT_INCLUDE) { if ($output_selection == OUTPUT_INCLUDE) {
if (defined($function_table{$name})) { if (defined($function_table{$name})) {
return 1; return 1;
} else { } else {
return 0; return 0;
} }
} }
die("Please add the new output type at show_warnings()"); die("Please add the new output type at show_warnings()");
} }
sub dump_enum($$) { sub dump_enum($$) {
...@@ -1333,62 +1333,62 @@ sub dump_enum($$) { ...@@ -1333,62 +1333,62 @@ sub dump_enum($$) {
$x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) {
$declaration_name = $2; $declaration_name = $2;
$members = $1; $members = $1;
} elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) {
$declaration_name = $1; $declaration_name = $1;
$members = $2; $members = $2;
} }
if ($members) { if ($members) {
if ($identifier ne $declaration_name) { if ($identifier ne $declaration_name) {
if ($identifier eq "") { if ($identifier eq "") {
emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n"); emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n");
} else { } else {
emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"); emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n");
} }
return; return;
} }
$declaration_name = "(anonymous)" if ($declaration_name eq ""); $declaration_name = "(anonymous)" if ($declaration_name eq "");
my %_members; my %_members;
$members =~ s/\s+$//; $members =~ s/\s+$//;
$members =~ s/\([^;]*?[\)]//g; $members =~ s/\([^;]*?[\)]//g;
foreach my $arg (split ',', $members) { foreach my $arg (split ',', $members) {
$arg =~ s/^\s*(\w+).*/$1/; $arg =~ s/^\s*(\w+).*/$1/;
push @parameterlist, $arg; push @parameterlist, $arg;
if (!$parameterdescs{$arg}) { if (!$parameterdescs{$arg}) {
$parameterdescs{$arg} = $undescribed; $parameterdescs{$arg} = $undescribed;
if (show_warnings("enum", $declaration_name)) { if (show_warnings("enum", $declaration_name)) {
emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n"); emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n");
} }
} }
$_members{$arg} = 1; $_members{$arg} = 1;
} }
while (my ($k, $v) = each %parameterdescs) { while (my ($k, $v) = each %parameterdescs) {
if (!exists($_members{$k})) { if (!exists($_members{$k})) {
if (show_warnings("enum", $declaration_name)) { if (show_warnings("enum", $declaration_name)) {
emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n"); emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n");
} }
} }
} }
output_declaration($declaration_name, output_declaration($declaration_name,
'enum', 'enum',
{'enum' => $declaration_name, {'enum' => $declaration_name,
'module' => $modulename, 'module' => $modulename,
'parameterlist' => \@parameterlist, 'parameterlist' => \@parameterlist,
'parameterdescs' => \%parameterdescs, 'parameterdescs' => \%parameterdescs,
'sectionlist' => \@sectionlist, 'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'purpose' => $declaration_purpose 'purpose' => $declaration_purpose
}); });
} else { } else {
print STDERR "${file}:$.: error: Cannot parse enum!\n"; print STDERR "${file}:$.: error: Cannot parse enum!\n";
++$errors; ++$errors;
} }
} }
...@@ -1407,59 +1407,58 @@ sub dump_typedef($$) { ...@@ -1407,59 +1407,58 @@ sub dump_typedef($$) {
# Parse function typedef prototypes # Parse function typedef prototypes
if ($x =~ $typedef1 || $x =~ $typedef2) { if ($x =~ $typedef1 || $x =~ $typedef2) {
$return_type = $1; $return_type = $1;
$declaration_name = $2; $declaration_name = $2;
my $args = $3; my $args = $3;
$return_type =~ s/^\s+//; $return_type =~ s/^\s+//;
if ($identifier ne $declaration_name) { if ($identifier ne $declaration_name) {
emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n");
return; return;
} }
create_parameterlist($args, ',', $file, $declaration_name); create_parameterlist($args, ',', $file, $declaration_name);
output_declaration($declaration_name, output_declaration($declaration_name,
'function', 'function',
{'function' => $declaration_name, {'function' => $declaration_name,
'typedef' => 1, 'typedef' => 1,
'module' => $modulename, 'module' => $modulename,
'functiontype' => $return_type, 'functiontype' => $return_type,
'parameterlist' => \@parameterlist, 'parameterlist' => \@parameterlist,
'parameterdescs' => \%parameterdescs, 'parameterdescs' => \%parameterdescs,
'parametertypes' => \%parametertypes, 'parametertypes' => \%parametertypes,
'sectionlist' => \@sectionlist, 'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'purpose' => $declaration_purpose 'purpose' => $declaration_purpose
}); });
return; return;
} }
while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
$x =~ s/\(*.\)\s*;$/;/; $x =~ s/\(*.\)\s*;$/;/;
$x =~ s/\[*.\]\s*;$/;/; $x =~ s/\[*.\]\s*;$/;/;
} }
if ($x =~ /typedef.*\s+(\w+)\s*;/) { if ($x =~ /typedef.*\s+(\w+)\s*;/) {
$declaration_name = $1; $declaration_name = $1;
if ($identifier ne $declaration_name) { if ($identifier ne $declaration_name) {
emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n");
return; return;
} }
output_declaration($declaration_name, output_declaration($declaration_name,
'typedef', 'typedef',
{'typedef' => $declaration_name, {'typedef' => $declaration_name,
'module' => $modulename, 'module' => $modulename,
'sectionlist' => \@sectionlist, 'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'purpose' => $declaration_purpose 'purpose' => $declaration_purpose
}); });
} } else {
else { print STDERR "${file}:$.: error: Cannot parse typedef!\n";
print STDERR "${file}:$.: error: Cannot parse typedef!\n"; ++$errors;
++$errors;
} }
} }
...@@ -1482,223 +1481,220 @@ sub create_parameterlist($$$$) { ...@@ -1482,223 +1481,220 @@ sub create_parameterlist($$$$) {
# temporarily replace commas inside function pointer definition # temporarily replace commas inside function pointer definition
my $arg_expr = qr{\([^\),]+}; my $arg_expr = qr{\([^\),]+};
while ($args =~ /$arg_expr,/) { while ($args =~ /$arg_expr,/) {
$args =~ s/($arg_expr),/$1#/g; $args =~ s/($arg_expr),/$1#/g;
} }
foreach my $arg (split($splitter, $args)) { foreach my $arg (split($splitter, $args)) {
# strip comments # strip comments
$arg =~ s/\/\*.*\*\///; $arg =~ s/\/\*.*\*\///;
# ignore argument attributes # ignore argument attributes
$arg =~ s/\sPOS0?\s/ /; $arg =~ s/\sPOS0?\s/ /;
# strip leading/trailing spaces # strip leading/trailing spaces
$arg =~ s/^\s*//; $arg =~ s/^\s*//;
$arg =~ s/\s*$//; $arg =~ s/\s*$//;
$arg =~ s/\s+/ /; $arg =~ s/\s+/ /;
if ($arg =~ /^#/) { if ($arg =~ /^#/) {
# Treat preprocessor directive as a typeless variable just to fill # Treat preprocessor directive as a typeless variable just to fill
# corresponding data structures "correctly". Catch it later in # corresponding data structures "correctly". Catch it later in
# output_* subs. # output_* subs.
push_parameter($arg, "", "", $file); push_parameter($arg, "", "", $file);
} elsif ($arg =~ m/\(.+\)\s*\(/) { } elsif ($arg =~ m/\(.+\)\s*\(/) {
# pointer-to-function # pointer-to-function
$arg =~ tr/#/,/; $arg =~ tr/#/,/;
$arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/;
$param = $1; $param = $1;
$type = $arg; $type = $arg;
$type =~ s/([^\(]+\(\*?)\s*$param/$1/; $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
save_struct_actual($param); save_struct_actual($param);
push_parameter($param, $type, $arg, $file, $declaration_name); push_parameter($param, $type, $arg, $file, $declaration_name);
} elsif ($arg =~ m/\(.+\)\s*\[/) { } elsif ($arg =~ m/\(.+\)\s*\[/) {
# array-of-pointers # array-of-pointers
$arg =~ tr/#/,/; $arg =~ tr/#/,/;
$arg =~ m/[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)/; $arg =~ m/[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)/;
$param = $1; $param = $1;
$type = $arg; $type = $arg;
$type =~ s/([^\(]+\(\*?)\s*$param/$1/; $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
save_struct_actual($param); save_struct_actual($param);
push_parameter($param, $type, $arg, $file, $declaration_name); push_parameter($param, $type, $arg, $file, $declaration_name);
} elsif ($arg) { } elsif ($arg) {
$arg =~ s/\s*:\s*/:/g; $arg =~ s/\s*:\s*/:/g;
$arg =~ s/\s*\[/\[/g; $arg =~ s/\s*\[/\[/g;
my @args = split('\s*,\s*', $arg); my @args = split('\s*,\s*', $arg);
if ($args[0] =~ m/\*/) { if ($args[0] =~ m/\*/) {
$args[0] =~ s/(\*+)\s*/ $1/; $args[0] =~ s/(\*+)\s*/ $1/;
} }
my @first_arg; my @first_arg;
if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
shift @args; shift @args;
push(@first_arg, split('\s+', $1)); push(@first_arg, split('\s+', $1));
push(@first_arg, $2); push(@first_arg, $2);
} else { } else {
@first_arg = split('\s+', shift @args); @first_arg = split('\s+', shift @args);
} }
unshift(@args, pop @first_arg); unshift(@args, pop @first_arg);
$type = join " ", @first_arg; $type = join " ", @first_arg;
foreach $param (@args) { foreach $param (@args) {
if ($param =~ m/^(\*+)\s*(.*)/) { if ($param =~ m/^(\*+)\s*(.*)/) {
save_struct_actual($2); save_struct_actual($2);
push_parameter($2, "$type $1", $arg, $file, $declaration_name); push_parameter($2, "$type $1", $arg, $file, $declaration_name);
} } elsif ($param =~ m/(.*?):(\d+)/) {
elsif ($param =~ m/(.*?):(\d+)/) { if ($type ne "") { # skip unnamed bit-fields
if ($type ne "") { # skip unnamed bit-fields save_struct_actual($1);
save_struct_actual($1); push_parameter($1, "$type:$2", $arg, $file, $declaration_name)
push_parameter($1, "$type:$2", $arg, $file, $declaration_name) }
} } else {
} save_struct_actual($param);
else { push_parameter($param, $type, $arg, $file, $declaration_name);
save_struct_actual($param); }
push_parameter($param, $type, $arg, $file, $declaration_name); }
} }
}
}
} }
} }
sub push_parameter($$$$$) { sub push_parameter($$$$$) {
my $param = shift; my $param = shift;
my $type = shift; my $type = shift;
my $org_arg = shift; my $org_arg = shift;
my $file = shift; my $file = shift;
my $declaration_name = shift; my $declaration_name = shift;
if (($anon_struct_union == 1) && ($type eq "") && if (($anon_struct_union == 1) && ($type eq "") &&
($param eq "}")) { ($param eq "}")) {
return; # ignore the ending }; from anon. struct/union return; # ignore the ending }; from anon. struct/union
} }
$anon_struct_union = 0; $anon_struct_union = 0;
$param =~ s/[\[\)].*//; $param =~ s/[\[\)].*//;
if ($type eq "" && $param =~ /\.\.\.$/) if ($type eq "" && $param =~ /\.\.\.$/)
{ {
if (!$param =~ /\w\.\.\.$/) { if (!$param =~ /\w\.\.\.$/) {
# handles unnamed variable parameters # handles unnamed variable parameters
$param = "..."; $param = "...";
} } elsif ($param =~ /\w\.\.\.$/) {
elsif ($param =~ /\w\.\.\.$/) { # for named variable parameters of the form `x...`, remove the dots
# for named variable parameters of the form `x...`, remove the dots $param =~ s/\.\.\.$//;
$param =~ s/\.\.\.$//; }
} if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { $parameterdescs{$param} = "variable arguments";
$parameterdescs{$param} = "variable arguments"; }
} }
} elsif ($type eq "" && ($param eq "" or $param eq "void"))
elsif ($type eq "" && ($param eq "" or $param eq "void")) {
{ $param="void";
$param="void"; $parameterdescs{void} = "no arguments";
$parameterdescs{void} = "no arguments"; }
} elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
elsif ($type eq "" && ($param eq "struct" or $param eq "union")) # handle unnamed (anonymous) union or struct:
# handle unnamed (anonymous) union or struct: {
{ $type = $param;
$type = $param; $param = "{unnamed_" . $param . "}";
$param = "{unnamed_" . $param . "}"; $parameterdescs{$param} = "anonymous\n";
$parameterdescs{$param} = "anonymous\n"; $anon_struct_union = 1;
$anon_struct_union = 1; }
} elsif ($param =~ "__cacheline_group" )
elsif ($param =~ "__cacheline_group" ) # handle cache group enforcing variables: they do not need be described in header files
# handle cache group enforcing variables: they do not need be described in header files {
{ return; # ignore __cacheline_group_begin and __cacheline_group_end
return; # ignore __cacheline_group_begin and __cacheline_group_end }
}
# warn if parameter has no description
# warn if parameter has no description # (but ignore ones starting with # as these are not parameters
# (but ignore ones starting with # as these are not parameters # but inline preprocessor statements);
# but inline preprocessor statements); # Note: It will also ignore void params and unnamed structs/unions
# Note: It will also ignore void params and unnamed structs/unions if (!defined $parameterdescs{$param} && $param !~ /^#/) {
if (!defined $parameterdescs{$param} && $param !~ /^#/) { $parameterdescs{$param} = $undescribed;
$parameterdescs{$param} = $undescribed;
if (show_warnings($type, $declaration_name) && $param !~ /\./) {
if (show_warnings($type, $declaration_name) && $param !~ /\./) { emit_warning("${file}:$.", "Function parameter or struct member '$param' not described in '$declaration_name'\n");
emit_warning("${file}:$.", "Function parameter or struct member '$param' not described in '$declaration_name'\n"); }
} }
}
# strip spaces from $param so that it is one continuous string
# strip spaces from $param so that it is one continuous string # on @parameterlist;
# on @parameterlist; # this fixes a problem where check_sections() cannot find
# this fixes a problem where check_sections() cannot find # a parameter like "addr[6 + 2]" because it actually appears
# a parameter like "addr[6 + 2]" because it actually appears # as "addr[6", "+", "2]" on the parameter list;
# as "addr[6", "+", "2]" on the parameter list; # but it's better to maintain the param string unchanged for output,
# but it's better to maintain the param string unchanged for output, # so just weaken the string compare in check_sections() to ignore
# so just weaken the string compare in check_sections() to ignore # "[blah" in a parameter string;
# "[blah" in a parameter string; ###$param =~ s/\s*//g;
###$param =~ s/\s*//g; push @parameterlist, $param;
push @parameterlist, $param; $org_arg =~ s/\s\s+/ /g;
$org_arg =~ s/\s\s+/ /g; $parametertypes{$param} = $org_arg;
$parametertypes{$param} = $org_arg;
} }
sub check_sections($$$$$) { sub check_sections($$$$$) {
my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_;
my @sects = split ' ', $sectcheck; my @sects = split ' ', $sectcheck;
my @prms = split ' ', $prmscheck; my @prms = split ' ', $prmscheck;
my $err; my $err;
my ($px, $sx); my ($px, $sx);
my $prm_clean; # strip trailing "[array size]" and/or beginning "*" my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
foreach $sx (0 .. $#sects) { foreach $sx (0 .. $#sects) {
$err = 1; $err = 1;
foreach $px (0 .. $#prms) { foreach $px (0 .. $#prms) {
$prm_clean = $prms[$px]; $prm_clean = $prms[$px];
$prm_clean =~ s/\[.*\]//; $prm_clean =~ s/\[.*\]//;
$prm_clean =~ s/$attribute//i; $prm_clean =~ s/$attribute//i;
# ignore array size in a parameter string; # ignore array size in a parameter string;
# however, the original param string may contain # however, the original param string may contain
# spaces, e.g.: addr[6 + 2] # spaces, e.g.: addr[6 + 2]
# and this appears in @prms as "addr[6" since the # and this appears in @prms as "addr[6" since the
# parameter list is split at spaces; # parameter list is split at spaces;
# hence just ignore "[..." for the sections check; # hence just ignore "[..." for the sections check;
$prm_clean =~ s/\[.*//; $prm_clean =~ s/\[.*//;
##$prm_clean =~ s/^\**//; ##$prm_clean =~ s/^\**//;
if ($prm_clean eq $sects[$sx]) { if ($prm_clean eq $sects[$sx]) {
$err = 0; $err = 0;
last; last;
} }
} }
if ($err) { if ($err) {
if ($decl_type eq "function") { if ($decl_type eq "function") {
emit_warning("${file}:$.", emit_warning("${file}:$.",
"Excess function parameter " . "Excess function parameter " .
"'$sects[$sx]' " . "'$sects[$sx]' " .
"description in '$decl_name'\n"); "description in '$decl_name'\n");
} } elsif (($decl_type eq "struct") or
elsif (($decl_type eq "struct") or ($decl_type eq "union")) {
($decl_type eq "union")) { emit_warning("${file}:$.",
emit_warning("${file}:$.", "Excess $decl_type member " .
"Excess $decl_type member " . "'$sects[$sx]' " .
"'$sects[$sx]' " . "description in '$decl_name'\n");
"description in '$decl_name'\n"); }
} }
} }
}
} }
## ##
# Checks the section describing the return value of a function. # Checks the section describing the return value of a function.
sub check_return_section { sub check_return_section {
my $file = shift; my $file = shift;
my $declaration_name = shift; my $declaration_name = shift;
my $return_type = shift; my $return_type = shift;
# Ignore an empty return type (It's a macro) # Ignore an empty return type (It's a macro)
# Ignore functions with a "void" return type. (But don't ignore "void *") # Ignore functions with a "void" return type. (But don't ignore "void *")
if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
return; return;
} }
if (!defined($sections{$section_return}) || if (!defined($sections{$section_return}) ||
$sections{$section_return} eq "") { $sections{$section_return} eq "")
emit_warning("${file}:$.", {
"No description found for return value of " . emit_warning("${file}:$.",
"'$declaration_name'\n"); "No description found for return value of " .
} "'$declaration_name'\n");
}
} }
## ##
...@@ -1773,21 +1769,21 @@ sub dump_function($$) { ...@@ -1773,21 +1769,21 @@ sub dump_function($$) {
$declaration_name = $2; $declaration_name = $2;
$noret = 1; $noret = 1;
} elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ ||
$prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ ||
$prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) {
$return_type = $1; $return_type = $1;
$declaration_name = $2; $declaration_name = $2;
my $args = $3; my $args = $3;
create_parameterlist($args, ',', $file, $declaration_name); create_parameterlist($args, ',', $file, $declaration_name);
} else { } else {
emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n"); emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n");
return; return;
} }
if ($identifier ne $declaration_name) { if ($identifier ne $declaration_name) {
emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"); emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n");
return; return;
} }
my $prms = join " ", @parameterlist; my $prms = join " ", @parameterlist;
...@@ -1799,38 +1795,38 @@ sub dump_function($$) { ...@@ -1799,38 +1795,38 @@ sub dump_function($$) {
# -Wreturn mode. # -Wreturn mode.
# TODO: always perform the check. # TODO: always perform the check.
if ($Wreturn && !$noret) { if ($Wreturn && !$noret) {
check_return_section($file, $declaration_name, $return_type); check_return_section($file, $declaration_name, $return_type);
} }
# The function parser can be called with a typedef parameter. # The function parser can be called with a typedef parameter.
# Handle it. # Handle it.
if ($return_type =~ /typedef/) { if ($return_type =~ /typedef/) {
output_declaration($declaration_name, output_declaration($declaration_name,
'function', 'function',
{'function' => $declaration_name, {'function' => $declaration_name,
'typedef' => 1, 'typedef' => 1,
'module' => $modulename, 'module' => $modulename,
'functiontype' => $return_type, 'functiontype' => $return_type,
'parameterlist' => \@parameterlist, 'parameterlist' => \@parameterlist,
'parameterdescs' => \%parameterdescs, 'parameterdescs' => \%parameterdescs,
'parametertypes' => \%parametertypes, 'parametertypes' => \%parametertypes,
'sectionlist' => \@sectionlist, 'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'purpose' => $declaration_purpose 'purpose' => $declaration_purpose
}); });
} else { } else {
output_declaration($declaration_name, output_declaration($declaration_name,
'function', 'function',
{'function' => $declaration_name, {'function' => $declaration_name,
'module' => $modulename, 'module' => $modulename,
'functiontype' => $return_type, 'functiontype' => $return_type,
'parameterlist' => \@parameterlist, 'parameterlist' => \@parameterlist,
'parameterdescs' => \%parameterdescs, 'parameterdescs' => \%parameterdescs,
'parametertypes' => \%parametertypes, 'parametertypes' => \%parametertypes,
'sectionlist' => \@sectionlist, 'sectionlist' => \@sectionlist,
'sections' => \%sections, 'sections' => \%sections,
'purpose' => $declaration_purpose 'purpose' => $declaration_purpose
}); });
} }
} }
...@@ -1850,64 +1846,64 @@ sub reset_state { ...@@ -1850,64 +1846,64 @@ sub reset_state {
} }
sub tracepoint_munge($) { sub tracepoint_munge($) {
my $file = shift; my $file = shift;
my $tracepointname = 0; my $tracepointname = 0;
my $tracepointargs = 0; my $tracepointargs = 0;
if ($prototype =~ m/TRACE_EVENT\((.*?),/) { if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
$tracepointname = $1; $tracepointname = $1;
} }
if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
$tracepointname = $1; $tracepointname = $1;
} }
if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
$tracepointname = $2; $tracepointname = $2;
} }
$tracepointname =~ s/^\s+//; #strip leading whitespace $tracepointname =~ s/^\s+//; #strip leading whitespace
if ($prototype =~ m/TP_PROTO\((.*?)\)/) { if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
$tracepointargs = $1; $tracepointargs = $1;
} }
if (($tracepointname eq 0) || ($tracepointargs eq 0)) { if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
emit_warning("${file}:$.", "Unrecognized tracepoint format: \n". emit_warning("${file}:$.", "Unrecognized tracepoint format: \n".
"$prototype\n"); "$prototype\n");
} else { } else {
$prototype = "static inline void trace_$tracepointname($tracepointargs)"; $prototype = "static inline void trace_$tracepointname($tracepointargs)";
$identifier = "trace_$identifier"; $identifier = "trace_$identifier";
} }
} }
sub syscall_munge() { sub syscall_munge() {
my $void = 0; my $void = 0;
$prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's
## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
if ($prototype =~ m/SYSCALL_DEFINE0/) { if ($prototype =~ m/SYSCALL_DEFINE0/) {
$void = 1; $void = 1;
## $prototype = "long sys_$1(void)"; ## $prototype = "long sys_$1(void)";
} }
$prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
if ($prototype =~ m/long (sys_.*?),/) { if ($prototype =~ m/long (sys_.*?),/) {
$prototype =~ s/,/\(/; $prototype =~ s/,/\(/;
} elsif ($void) { } elsif ($void) {
$prototype =~ s/\)/\(void\)/; $prototype =~ s/\)/\(void\)/;
} }
# now delete all of the odd-number commas in $prototype # now delete all of the odd-number commas in $prototype
# so that arg types & arg names don't have a comma between them # so that arg types & arg names don't have a comma between them
my $count = 0; my $count = 0;
my $len = length($prototype); my $len = length($prototype);
if ($void) { if ($void) {
$len = 0; # skip the for-loop $len = 0; # skip the for-loop
} }
for (my $ix = 0; $ix < $len; $ix++) { for (my $ix = 0; $ix < $len; $ix++) {
if (substr($prototype, $ix, 1) eq ',') { if (substr($prototype, $ix, 1) eq ',') {
$count++; $count++;
if ($count % 2 == 1) { if ($count % 2 == 1) {
substr($prototype, $ix, 1) = ' '; substr($prototype, $ix, 1) = ' ';
} }
} }
} }
} }
sub process_proto_function($$) { sub process_proto_function($$) {
...@@ -1917,31 +1913,30 @@ sub process_proto_function($$) { ...@@ -1917,31 +1913,30 @@ sub process_proto_function($$) {
$x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
if ($x =~ /^#/ && $x !~ /^#\s*define/) { if ($x =~ /^#/ && $x !~ /^#\s*define/) {
# do nothing # do nothing
} } elsif ($x =~ /([^\{]*)/) {
elsif ($x =~ /([^\{]*)/) { $prototype .= $1;
$prototype .= $1;
} }
if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
$prototype =~ s@/\*.*?\*/@@gos; # strip comments. $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
$prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
$prototype =~ s@^\s+@@gos; # strip leading spaces $prototype =~ s@^\s+@@gos; # strip leading spaces
# Handle prototypes for function pointers like: # Handle prototypes for function pointers like:
# int (*pcs_config)(struct foo) # int (*pcs_config)(struct foo)
$prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos;
if ($prototype =~ /SYSCALL_DEFINE/) { if ($prototype =~ /SYSCALL_DEFINE/) {
syscall_munge(); syscall_munge();
} }
if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
$prototype =~ /DEFINE_SINGLE_EVENT/) $prototype =~ /DEFINE_SINGLE_EVENT/)
{ {
tracepoint_munge($file); tracepoint_munge($file);
} }
dump_function($prototype, $file); dump_function($prototype, $file);
reset_state(); reset_state();
} }
} }
...@@ -1955,28 +1950,28 @@ sub process_proto_type($$) { ...@@ -1955,28 +1950,28 @@ sub process_proto_type($$) {
$x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
if ($x =~ /^#/) { if ($x =~ /^#/) {
# To distinguish preprocessor directive from regular declaration later. # To distinguish preprocessor directive from regular declaration later.
$x .= ";"; $x .= ";";
} }
while (1) { while (1) {
if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
if( length $prototype ) { if( length $prototype ) {
$prototype .= " " $prototype .= " "
} }
$prototype .= $1 . $2; $prototype .= $1 . $2;
($2 eq '{') && $brcount++; ($2 eq '{') && $brcount++;
($2 eq '}') && $brcount--; ($2 eq '}') && $brcount--;
if (($2 eq ';') && ($brcount == 0)) { if (($2 eq ';') && ($brcount == 0)) {
dump_declaration($prototype, $file); dump_declaration($prototype, $file);
reset_state(); reset_state();
last; last;
} }
$x = $3; $x = $3;
} else { } else {
$prototype .= $x; $prototype .= $x;
last; last;
} }
} }
} }
...@@ -1986,13 +1981,13 @@ sub map_filename($) { ...@@ -1986,13 +1981,13 @@ sub map_filename($) {
my ($orig_file) = @_; my ($orig_file) = @_;
if (defined($ENV{'SRCTREE'})) { if (defined($ENV{'SRCTREE'})) {
$file = "$ENV{'SRCTREE'}" . "/" . $orig_file; $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
} else { } else {
$file = $orig_file; $file = $orig_file;
} }
if (defined($source_map{$file})) { if (defined($source_map{$file})) {
$file = $source_map{$file}; $file = $source_map{$file};
} }
return $file; return $file;
...@@ -2003,20 +1998,20 @@ sub process_export_file($) { ...@@ -2003,20 +1998,20 @@ sub process_export_file($) {
my $file = map_filename($orig_file); my $file = map_filename($orig_file);
if (!open(IN,"<$file")) { if (!open(IN,"<$file")) {
print STDERR "Error: Cannot open file $file\n"; print STDERR "Error: Cannot open file $file\n";
++$errors; ++$errors;
return; return;
} }
while (<IN>) { while (<IN>) {
if (/$export_symbol/) { if (/$export_symbol/) {
next if (defined($nosymbol_table{$2})); next if (defined($nosymbol_table{$2}));
$function_table{$2} = 1; $function_table{$2} = 1;
} }
if (/$export_symbol_ns/) { if (/$export_symbol_ns/) {
next if (defined($nosymbol_table{$2})); next if (defined($nosymbol_table{$2}));
$function_table{$2} = 1; $function_table{$2} = 1;
} }
} }
close(IN); close(IN);
...@@ -2029,9 +2024,9 @@ sub process_export_file($) { ...@@ -2029,9 +2024,9 @@ sub process_export_file($) {
# #
sub process_normal() { sub process_normal() {
if (/$doc_start/o) { if (/$doc_start/o) {
$state = STATE_NAME; # next line is always the function name $state = STATE_NAME; # next line is always the function name
$in_doc_sect = 0; $in_doc_sect = 0;
$declaration_start_line = $. + 1; $declaration_start_line = $. + 1;
} }
} }
...@@ -2043,80 +2038,80 @@ sub process_name($$) { ...@@ -2043,80 +2038,80 @@ sub process_name($$) {
my $descr; my $descr;
if (/$doc_block/o) { if (/$doc_block/o) {
$state = STATE_DOCBLOCK; $state = STATE_DOCBLOCK;
$contents = ""; $contents = "";
$new_start_line = $.; $new_start_line = $.;
if ( $1 eq "" ) { if ( $1 eq "" ) {
$section = $section_intro; $section = $section_intro;
} else { } else {
$section = $1; $section = $1;
} }
} elsif (/$doc_decl/o) { } elsif (/$doc_decl/o) {
$identifier = $1; $identifier = $1;
my $is_kernel_comment = 0; my $is_kernel_comment = 0;
my $decl_start = qr{$doc_com}; my $decl_start = qr{$doc_com};
# test for pointer declaration type, foo * bar() - desc # test for pointer declaration type, foo * bar() - desc
my $fn_type = qr{\w+\s*\*\s*}; my $fn_type = qr{\w+\s*\*\s*};
my $parenthesis = qr{\(\w*\)}; my $parenthesis = qr{\(\w*\)};
my $decl_end = qr{[-:].*}; my $decl_end = qr{[-:].*};
if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) {
$identifier = $1; $identifier = $1;
} }
if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) {
$decl_type = $1; $decl_type = $1;
$identifier = $2; $identifier = $2;
$is_kernel_comment = 1; $is_kernel_comment = 1;
} }
# Look for foo() or static void foo() - description; or misspelt # Look for foo() or static void foo() - description; or misspelt
# identifier # identifier
elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||
/^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) {
$identifier = $1; $identifier = $1;
$decl_type = 'function'; $decl_type = 'function';
$identifier =~ s/^define\s+//; $identifier =~ s/^define\s+//;
$is_kernel_comment = 1; $is_kernel_comment = 1;
} }
$identifier =~ s/\s+$//; $identifier =~ s/\s+$//;
$state = STATE_BODY; $state = STATE_BODY;
# if there's no @param blocks need to set up default section # if there's no @param blocks need to set up default section
# here # here
$contents = ""; $contents = "";
$section = $section_default; $section = $section_default;
$new_start_line = $. + 1; $new_start_line = $. + 1;
if (/[-:](.*)/) { if (/[-:](.*)/) {
# strip leading/trailing/multiple spaces # strip leading/trailing/multiple spaces
$descr= $1; $descr= $1;
$descr =~ s/^\s*//; $descr =~ s/^\s*//;
$descr =~ s/\s*$//; $descr =~ s/\s*$//;
$descr =~ s/\s+/ /g; $descr =~ s/\s+/ /g;
$declaration_purpose = $descr; $declaration_purpose = $descr;
$state = STATE_BODY_MAYBE; $state = STATE_BODY_MAYBE;
} else { } else {
$declaration_purpose = ""; $declaration_purpose = "";
} }
if (!$is_kernel_comment) { if (!$is_kernel_comment) {
emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_"); emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_");
$state = STATE_NORMAL; $state = STATE_NORMAL;
} }
if (($declaration_purpose eq "") && $Wshort_desc) { if (($declaration_purpose eq "") && $Wshort_desc) {
emit_warning("${file}:$.", "missing initial short description on line:\n$_"); emit_warning("${file}:$.", "missing initial short description on line:\n$_");
} }
if ($identifier eq "" && $decl_type ne "enum") { if ($identifier eq "" && $decl_type ne "enum") {
emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_"); emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_");
$state = STATE_NORMAL; $state = STATE_NORMAL;
} }
if ($verbose) { if ($verbose) {
print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n";
} }
} else { } else {
emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n"); emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n");
$state = STATE_NORMAL; $state = STATE_NORMAL;
} }
} }
...@@ -2128,102 +2123,102 @@ sub process_body($$) { ...@@ -2128,102 +2123,102 @@ sub process_body($$) {
my $file = shift; my $file = shift;
if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) {
dump_section($file, $section, $contents); dump_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
$new_start_line = $.; $new_start_line = $.;
$contents = ""; $contents = "";
} }
if (/$doc_sect/i) { # case insensitive for supported section names if (/$doc_sect/i) { # case insensitive for supported section names
$in_doc_sect = 1; $in_doc_sect = 1;
$newsection = $1; $newsection = $1;
$newcontents = $2; $newcontents = $2;
# map the supported section names to the canonical names # map the supported section names to the canonical names
if ($newsection =~ m/^description$/i) { if ($newsection =~ m/^description$/i) {
$newsection = $section_default; $newsection = $section_default;
} elsif ($newsection =~ m/^context$/i) { } elsif ($newsection =~ m/^context$/i) {
$newsection = $section_context; $newsection = $section_context;
} elsif ($newsection =~ m/^returns?$/i) { } elsif ($newsection =~ m/^returns?$/i) {
$newsection = $section_return; $newsection = $section_return;
} elsif ($newsection =~ m/^\@return$/) { } elsif ($newsection =~ m/^\@return$/) {
# special: @return is a section, not a param description # special: @return is a section, not a param description
$newsection = $section_return; $newsection = $section_return;
} }
if (($contents ne "") && ($contents ne "\n")) { if (($contents ne "") && ($contents ne "\n")) {
if (!$in_doc_sect && $Wcontents_before_sections) { if (!$in_doc_sect && $Wcontents_before_sections) {
emit_warning("${file}:$.", "contents before sections\n"); emit_warning("${file}:$.", "contents before sections\n");
} }
dump_section($file, $section, $contents); dump_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
} }
$in_doc_sect = 1; $in_doc_sect = 1;
$state = STATE_BODY; $state = STATE_BODY;
$contents = $newcontents; $contents = $newcontents;
$new_start_line = $.; $new_start_line = $.;
while (substr($contents, 0, 1) eq " ") { while (substr($contents, 0, 1) eq " ") {
$contents = substr($contents, 1); $contents = substr($contents, 1);
} }
if ($contents ne "") { if ($contents ne "") {
$contents .= "\n"; $contents .= "\n";
} }
$section = $newsection; $section = $newsection;
$leading_space = undef; $leading_space = undef;
} elsif (/$doc_end/) { } elsif (/$doc_end/) {
if (($contents ne "") && ($contents ne "\n")) { if (($contents ne "") && ($contents ne "\n")) {
dump_section($file, $section, $contents); dump_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
} }
# look for doc_com + <text> + doc_end: # look for doc_com + <text> + doc_end:
if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
emit_warning("${file}:$.", "suspicious ending line: $_"); emit_warning("${file}:$.", "suspicious ending line: $_");
} }
$prototype = ""; $prototype = "";
$state = STATE_PROTO; $state = STATE_PROTO;
$brcount = 0; $brcount = 0;
$new_start_line = $. + 1; $new_start_line = $. + 1;
} elsif (/$doc_content/) { } elsif (/$doc_content/) {
if ($1 eq "") { if ($1 eq "") {
if ($section eq $section_context) { if ($section eq $section_context) {
dump_section($file, $section, $contents); dump_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
$new_start_line = $.; $new_start_line = $.;
$state = STATE_BODY; $state = STATE_BODY;
} else { } else {
if ($section ne $section_default) { if ($section ne $section_default) {
$state = STATE_BODY_WITH_BLANK_LINE; $state = STATE_BODY_WITH_BLANK_LINE;
} else { } else {
$state = STATE_BODY; $state = STATE_BODY;
} }
$contents .= "\n"; $contents .= "\n";
} }
} elsif ($state == STATE_BODY_MAYBE) { } elsif ($state == STATE_BODY_MAYBE) {
# Continued declaration purpose # Continued declaration purpose
chomp($declaration_purpose); chomp($declaration_purpose);
$declaration_purpose .= " " . $1; $declaration_purpose .= " " . $1;
$declaration_purpose =~ s/\s+/ /g; $declaration_purpose =~ s/\s+/ /g;
} else { } else {
my $cont = $1; my $cont = $1;
if ($section =~ m/^@/ || $section eq $section_context) { if ($section =~ m/^@/ || $section eq $section_context) {
if (!defined $leading_space) { if (!defined $leading_space) {
if ($cont =~ m/^(\s+)/) { if ($cont =~ m/^(\s+)/) {
$leading_space = $1; $leading_space = $1;
} else { } else {
$leading_space = ""; $leading_space = "";
} }
} }
$cont =~ s/^$leading_space//; $cont =~ s/^$leading_space//;
} }
$contents .= $cont . "\n"; $contents .= $cont . "\n";
} }
} else { } else {
# i dont know - bad line? ignore. # i dont know - bad line? ignore.
emit_warning("${file}:$.", "bad line: $_"); emit_warning("${file}:$.", "bad line: $_");
} }
} }
...@@ -2235,21 +2230,21 @@ sub process_proto($$) { ...@@ -2235,21 +2230,21 @@ sub process_proto($$) {
my $file = shift; my $file = shift;
if (/$doc_inline_oneline/) { if (/$doc_inline_oneline/) {
$section = $1; $section = $1;
$contents = $2; $contents = $2;
if ($contents ne "") { if ($contents ne "") {
$contents .= "\n"; $contents .= "\n";
dump_section($file, $section, $contents); dump_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
} }
} elsif (/$doc_inline_start/) { } elsif (/$doc_inline_start/) {
$state = STATE_INLINE; $state = STATE_INLINE;
$inline_doc_state = STATE_INLINE_NAME; $inline_doc_state = STATE_INLINE_NAME;
} elsif ($decl_type eq 'function') { } elsif ($decl_type eq 'function') {
process_proto_function($_, $file); process_proto_function($_, $file);
} else { } else {
process_proto_type($_, $file); process_proto_type($_, $file);
} }
} }
...@@ -2260,23 +2255,23 @@ sub process_docblock($$) { ...@@ -2260,23 +2255,23 @@ sub process_docblock($$) {
my $file = shift; my $file = shift;
if (/$doc_end/) { if (/$doc_end/) {
dump_doc_section($file, $section, $contents); dump_doc_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
$function = ""; $function = "";
%parameterdescs = (); %parameterdescs = ();
%parametertypes = (); %parametertypes = ();
@parameterlist = (); @parameterlist = ();
%sections = (); %sections = ();
@sectionlist = (); @sectionlist = ();
$prototype = ""; $prototype = "";
$state = STATE_NORMAL; $state = STATE_NORMAL;
} elsif (/$doc_content/) { } elsif (/$doc_content/) {
if ( $1 eq "" ) { if ( $1 eq "" ) {
$contents .= $blankline; $contents .= $blankline;
} else { } else {
$contents .= $1 . "\n"; $contents .= $1 . "\n";
} }
} }
} }
...@@ -2288,37 +2283,37 @@ sub process_inline($$) { ...@@ -2288,37 +2283,37 @@ sub process_inline($$) {
# First line (state 1) needs to be a @parameter # First line (state 1) needs to be a @parameter
if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
$section = $1; $section = $1;
$contents = $2; $contents = $2;
$new_start_line = $.; $new_start_line = $.;
if ($contents ne "") { if ($contents ne "") {
while (substr($contents, 0, 1) eq " ") { while (substr($contents, 0, 1) eq " ") {
$contents = substr($contents, 1); $contents = substr($contents, 1);
} }
$contents .= "\n"; $contents .= "\n";
} }
$inline_doc_state = STATE_INLINE_TEXT; $inline_doc_state = STATE_INLINE_TEXT;
# Documentation block end */ # Documentation block end */
} elsif (/$doc_inline_end/) { } elsif (/$doc_inline_end/) {
if (($contents ne "") && ($contents ne "\n")) { if (($contents ne "") && ($contents ne "\n")) {
dump_section($file, $section, $contents); dump_section($file, $section, $contents);
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
} }
$state = STATE_PROTO; $state = STATE_PROTO;
$inline_doc_state = STATE_INLINE_NA; $inline_doc_state = STATE_INLINE_NA;
# Regular text # Regular text
} elsif (/$doc_content/) { } elsif (/$doc_content/) {
if ($inline_doc_state == STATE_INLINE_TEXT) { if ($inline_doc_state == STATE_INLINE_TEXT) {
$contents .= $1 . "\n"; $contents .= $1 . "\n";
# nuke leading blank lines # nuke leading blank lines
if ($contents =~ /^\s*$/) { if ($contents =~ /^\s*$/) {
$contents = ""; $contents = "";
} }
} elsif ($inline_doc_state == STATE_INLINE_NAME) { } elsif ($inline_doc_state == STATE_INLINE_NAME) {
$inline_doc_state = STATE_INLINE_ERROR; $inline_doc_state = STATE_INLINE_ERROR;
emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_"); emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_");
} }
} }
} }
...@@ -2331,54 +2326,53 @@ sub process_file($) { ...@@ -2331,54 +2326,53 @@ sub process_file($) {
$file = map_filename($orig_file); $file = map_filename($orig_file);
if (!open(IN_FILE,"<$file")) { if (!open(IN_FILE,"<$file")) {
print STDERR "Error: Cannot open file $file\n"; print STDERR "Error: Cannot open file $file\n";
++$errors; ++$errors;
return; return;
} }
$. = 1; $. = 1;
$section_counter = 0; $section_counter = 0;
while (<IN_FILE>) { while (<IN_FILE>) {
while (!/^ \*/ && s/\\\s*$//) { while (!/^ \*/ && s/\\\s*$//) {
$_ .= <IN_FILE>; $_ .= <IN_FILE>;
} }
# Replace tabs by spaces # Replace tabs by spaces
while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
# Hand this line to the appropriate state handler # Hand this line to the appropriate state handler
if ($state == STATE_NORMAL) { if ($state == STATE_NORMAL) {
process_normal(); process_normal();
} elsif ($state == STATE_NAME) { } elsif ($state == STATE_NAME) {
process_name($file, $_); process_name($file, $_);
} elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE ||
$state == STATE_BODY_WITH_BLANK_LINE) { $state == STATE_BODY_WITH_BLANK_LINE) {
process_body($file, $_); process_body($file, $_);
} elsif ($state == STATE_INLINE) { # scanning for inline parameters } elsif ($state == STATE_INLINE) { # scanning for inline parameters
process_inline($file, $_); process_inline($file, $_);
} elsif ($state == STATE_PROTO) { } elsif ($state == STATE_PROTO) {
process_proto($file, $_); process_proto($file, $_);
} elsif ($state == STATE_DOCBLOCK) { } elsif ($state == STATE_DOCBLOCK) {
process_docblock($file, $_); process_docblock($file, $_);
} }
} }
# Make sure we got something interesting. # Make sure we got something interesting.
if ($initial_section_counter == $section_counter && $ if ($initial_section_counter == $section_counter && $
output_mode ne "none") { output_mode ne "none") {
if ($output_selection == OUTPUT_INCLUDE) { if ($output_selection == OUTPUT_INCLUDE) {
emit_warning("${file}:1", "'$_' not found\n") emit_warning("${file}:1", "'$_' not found\n")
for keys %function_table; for keys %function_table;
} } else {
else { emit_warning("${file}:1", "no structured comments found\n");
emit_warning("${file}:1", "no structured comments found\n"); }
}
} }
close IN_FILE; close IN_FILE;
} }
if ($output_mode eq "rst") { if ($output_mode eq "rst") {
get_sphinx_version() if (!$sphinx_major); get_sphinx_version() if (!$sphinx_major);
} }
$kernelversion = get_kernel_version(); $kernelversion = get_kernel_version();
...@@ -2395,14 +2389,14 @@ for (my $k = 0; $k < @highlights; $k++) { ...@@ -2395,14 +2389,14 @@ for (my $k = 0; $k < @highlights; $k++) {
# Read the file that maps relative names to absolute names for # Read the file that maps relative names to absolute names for
# separate source and object directories and for shadow trees. # separate source and object directories and for shadow trees.
if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
my ($relname, $absname); my ($relname, $absname);
while(<SOURCE_MAP>) { while(<SOURCE_MAP>) {
chop(); chop();
($relname, $absname) = (split())[0..1]; ($relname, $absname) = (split())[0..1];
$relname =~ s:^/+::; $relname =~ s:^/+::;
$source_map{$relname} = $absname; $source_map{$relname} = $absname;
} }
close(SOURCE_MAP); close(SOURCE_MAP);
} }
if ($output_selection == OUTPUT_EXPORTED || if ($output_selection == OUTPUT_EXPORTED ||
...@@ -2411,8 +2405,8 @@ if ($output_selection == OUTPUT_EXPORTED || ...@@ -2411,8 +2405,8 @@ if ($output_selection == OUTPUT_EXPORTED ||
push(@export_file_list, @ARGV); push(@export_file_list, @ARGV);
foreach (@export_file_list) { foreach (@export_file_list) {
chomp; chomp;
process_export_file($_); process_export_file($_);
} }
} }
...@@ -2421,10 +2415,10 @@ foreach (@ARGV) { ...@@ -2421,10 +2415,10 @@ foreach (@ARGV) {
process_file($_); process_file($_);
} }
if ($verbose && $errors) { if ($verbose && $errors) {
print STDERR "$errors errors\n"; print STDERR "$errors errors\n";
} }
if ($verbose && $warnings) { if ($verbose && $warnings) {
print STDERR "$warnings warnings\n"; print STDERR "$warnings warnings\n";
} }
if ($Werror && $warnings) { if ($Werror && $warnings) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment