aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kernel-doc
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2016-06-03 16:21:34 -0400
committerJani Nikula <jani.nikula@intel.com>2016-06-04 04:35:31 -0400
commit0b0f5f29b282b18d26ce698e1aab0267234f77bf (patch)
tree80a3de28ac9838a59333e932d5ce04f894698483 /scripts/kernel-doc
parentb7afa92b55043b71a37a2f658553d3e260859859 (diff)
scripts/kernel-doc: Add option to inject line numbers
Opt-in since this wreaks the rst output and must be removed by consumers again. This is useful to adjust the linenumbers for included kernel-doc snippets in shinx. With that sphinx error message will be accurate when there's issues with the rst-ness of the kernel-doc comments. Especially when transitioning a new docbook .tmpl to .rst this is extremely useful, since you can just use your editors compilation quickfix list to accurately jump from error to error. v2: - Also make sure that we filter the LINENO for purpose/at declaration start so it only shows for selected blocks, not all of them (Jani). While at it make it a notch more accurate. - Avoid undefined $lineno issues. I tried filtering these out at the callsite, but Jani spotted more when linting the entire kernel. Unamed unions and similar things aren't stored consistently and end up with an undefined line number (but also no kernel-doc text, just the parameter type). Simplify things and filter undefined line numbers in print_lineno() to catch them all. v3: Fix LINENO 0 issue for kernel-doc comments without @param: lines or any other special sections that directly jump to the description after the "name - purpose" line. Only really possible for functions without parameters. Noticed by Jani. Cc: Jani Nikula <jani.nikula@intel.com> Cc: linux-doc@vger.kernel.org Cc: Jonathan Corbet <corbet@lwn.net> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Diffstat (limited to 'scripts/kernel-doc')
-rwxr-xr-xscripts/kernel-doc41
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 4da6f952d18b..5192213c5005 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -74,6 +74,8 @@ Output selection (mutually exclusive):
74 74
75Output selection modifiers: 75Output selection modifiers:
76 -no-doc-sections Do not output DOC: sections. 76 -no-doc-sections Do not output DOC: sections.
77 -enable-lineno Enable output of #define LINENO lines. Only works with
78 reStructuredText format.
77 79
78Other parameters: 80Other parameters:
79 -v Verbose output, more warnings and other information. 81 -v Verbose output, more warnings and other information.
@@ -319,6 +321,7 @@ my $verbose = 0;
319my $output_mode = "man"; 321my $output_mode = "man";
320my $output_preformatted = 0; 322my $output_preformatted = 0;
321my $no_doc_sections = 0; 323my $no_doc_sections = 0;
324my $enable_lineno = 0;
322my @highlights = @highlights_man; 325my @highlights = @highlights_man;
323my $blankline = $blankline_man; 326my $blankline = $blankline_man;
324my $modulename = "Kernel API"; 327my $modulename = "Kernel API";
@@ -351,6 +354,7 @@ my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
351# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 354# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
352# could cause "use of undefined value" or other bugs. 355# could cause "use of undefined value" or other bugs.
353my ($function, %function_table, %parametertypes, $declaration_purpose); 356my ($function, %function_table, %parametertypes, $declaration_purpose);
357my $declaration_start_line;
354my ($type, $declaration_name, $return_type); 358my ($type, $declaration_name, $return_type);
355my ($newsection, $newcontents, $prototype, $brcount, %source_map); 359my ($newsection, $newcontents, $prototype, $brcount, %source_map);
356 360
@@ -411,13 +415,16 @@ my $doc_inline_end = '^\s*\*/\s*$';
411my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 415my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
412 416
413my %parameterdescs; 417my %parameterdescs;
418my %parameterdesc_start_lines;
414my @parameterlist; 419my @parameterlist;
415my %sections; 420my %sections;
416my @sectionlist; 421my @sectionlist;
422my %section_start_lines;
417my $sectcheck; 423my $sectcheck;
418my $struct_actual; 424my $struct_actual;
419 425
420my $contents = ""; 426my $contents = "";
427my $new_start_line = 0;
421 428
422# the canonical section names. see also $doc_sect above. 429# the canonical section names. see also $doc_sect above.
423my $section_default = "Description"; # default section 430my $section_default = "Description"; # default section
@@ -486,6 +493,8 @@ while ($ARGV[0] =~ m/^-(.*)/) {
486 usage(); 493 usage();
487 } elsif ($cmd eq '-no-doc-sections') { 494 } elsif ($cmd eq '-no-doc-sections') {
488 $no_doc_sections = 1; 495 $no_doc_sections = 1;
496 } elsif ($cmd eq '-enable-lineno') {
497 $enable_lineno = 1;
489 } elsif ($cmd eq '-show-not-found') { 498 } elsif ($cmd eq '-show-not-found') {
490 $show_not_found = 1; 499 $show_not_found = 1;
491 } 500 }
@@ -503,6 +512,13 @@ sub get_kernel_version() {
503 return $version; 512 return $version;
504} 513}
505 514
515#
516sub print_lineno {
517 my $lineno = shift;
518 if ($enable_lineno && defined($lineno)) {
519 print "#define LINENO " . $lineno . "\n";
520 }
521}
506## 522##
507# dumps section contents to arrays/hashes intended for that purpose. 523# dumps section contents to arrays/hashes intended for that purpose.
508# 524#
@@ -516,11 +532,15 @@ sub dump_section {
516 $name = $1; 532 $name = $1;
517 $parameterdescs{$name} = $contents; 533 $parameterdescs{$name} = $contents;
518 $sectcheck = $sectcheck . $name . " "; 534 $sectcheck = $sectcheck . $name . " ";
535 $parameterdesc_start_lines{$name} = $new_start_line;
536 $new_start_line = 0;
519 } elsif ($name eq "@\.\.\.") { 537 } elsif ($name eq "@\.\.\.") {
520# print STDERR "parameter def '...' = '$contents'\n"; 538# print STDERR "parameter def '...' = '$contents'\n";
521 $name = "..."; 539 $name = "...";
522 $parameterdescs{$name} = $contents; 540 $parameterdescs{$name} = $contents;
523 $sectcheck = $sectcheck . $name . " "; 541 $sectcheck = $sectcheck . $name . " ";
542 $parameterdesc_start_lines{$name} = $new_start_line;
543 $new_start_line = 0;
524 } else { 544 } else {
525# print STDERR "other section '$name' = '$contents'\n"; 545# print STDERR "other section '$name' = '$contents'\n";
526 if (defined($sections{$name}) && ($sections{$name} ne "")) { 546 if (defined($sections{$name}) && ($sections{$name} ne "")) {
@@ -530,6 +550,8 @@ sub dump_section {
530 } else { 550 } else {
531 $sections{$name} = $contents; 551 $sections{$name} = $contents;
532 push @sectionlist, $name; 552 push @sectionlist, $name;
553 $section_start_lines{$name} = $new_start_line;
554 $new_start_line = 0;
533 } 555 }
534 } 556 }
535} 557}
@@ -1775,6 +1797,7 @@ sub output_blockhead_rst(%) {
1775 if ($output_selection != OUTPUT_INCLUDE) { 1797 if ($output_selection != OUTPUT_INCLUDE) {
1776 print "**$section**\n\n"; 1798 print "**$section**\n\n";
1777 } 1799 }
1800 print_lineno($section_start_lines{$section});
1778 output_highlight_rst($args{'sections'}{$section}); 1801 output_highlight_rst($args{'sections'}{$section});
1779 print "\n"; 1802 print "\n";
1780 } 1803 }
@@ -1824,6 +1847,7 @@ sub output_function_rst(%) {
1824 } 1847 }
1825 } 1848 }
1826 print ")\n\n"; 1849 print ")\n\n";
1850 print_lineno($declaration_start_line);
1827 $lineprefix = " "; 1851 $lineprefix = " ";
1828 output_highlight_rst($args{'purpose'}); 1852 output_highlight_rst($args{'purpose'});
1829 print "\n"; 1853 print "\n";
@@ -1840,6 +1864,9 @@ sub output_function_rst(%) {
1840 } else { 1864 } else {
1841 print "``$parameter``\n"; 1865 print "``$parameter``\n";
1842 } 1866 }
1867
1868 print_lineno($parameterdesc_start_lines{$parameter_name});
1869
1843 if (defined($args{'parameterdescs'}{$parameter_name}) && 1870 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1844 $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1871 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
1845 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1872 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
@@ -1861,6 +1888,7 @@ sub output_section_rst(%) {
1861 1888
1862 foreach $section (@{$args{'sectionlist'}}) { 1889 foreach $section (@{$args{'sectionlist'}}) {
1863 print "**$section**\n\n"; 1890 print "**$section**\n\n";
1891 print_lineno($section_start_lines{$section});
1864 output_highlight_rst($args{'sections'}{$section}); 1892 output_highlight_rst($args{'sections'}{$section});
1865 print "\n"; 1893 print "\n";
1866 } 1894 }
@@ -1876,6 +1904,7 @@ sub output_enum_rst(%) {
1876 my $name = "enum " . $args{'enum'}; 1904 my $name = "enum " . $args{'enum'};
1877 1905
1878 print "\n\n.. c:type:: " . $name . "\n\n"; 1906 print "\n\n.. c:type:: " . $name . "\n\n";
1907 print_lineno($declaration_start_line);
1879 $lineprefix = " "; 1908 $lineprefix = " ";
1880 output_highlight_rst($args{'purpose'}); 1909 output_highlight_rst($args{'purpose'});
1881 print "\n"; 1910 print "\n";
@@ -1903,6 +1932,7 @@ sub output_typedef_rst(%) {
1903 my $name = "typedef " . $args{'typedef'}; 1932 my $name = "typedef " . $args{'typedef'};
1904 1933
1905 print "\n\n.. c:type:: " . $name . "\n\n"; 1934 print "\n\n.. c:type:: " . $name . "\n\n";
1935 print_lineno($declaration_start_line);
1906 $lineprefix = " "; 1936 $lineprefix = " ";
1907 output_highlight_rst($args{'purpose'}); 1937 output_highlight_rst($args{'purpose'});
1908 print "\n"; 1938 print "\n";
@@ -1918,6 +1948,7 @@ sub output_struct_rst(%) {
1918 my $name = $args{'type'} . " " . $args{'struct'}; 1948 my $name = $args{'type'} . " " . $args{'struct'};
1919 1949
1920 print "\n\n.. c:type:: " . $name . "\n\n"; 1950 print "\n\n.. c:type:: " . $name . "\n\n";
1951 print_lineno($declaration_start_line);
1921 $lineprefix = " "; 1952 $lineprefix = " ";
1922 output_highlight_rst($args{'purpose'}); 1953 output_highlight_rst($args{'purpose'});
1923 print "\n"; 1954 print "\n";
@@ -1958,6 +1989,7 @@ sub output_struct_rst(%) {
1958 1989
1959 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1990 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1960 $type = $args{'parametertypes'}{$parameter}; 1991 $type = $args{'parametertypes'}{$parameter};
1992 print_lineno($parameterdesc_start_lines{$parameter_name});
1961 print "``$type $parameter``\n"; 1993 print "``$type $parameter``\n";
1962 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1994 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1963 print "\n"; 1995 print "\n";
@@ -2745,11 +2777,14 @@ sub process_file($) {
2745 if (/$doc_start/o) { 2777 if (/$doc_start/o) {
2746 $state = STATE_NAME; # next line is always the function name 2778 $state = STATE_NAME; # next line is always the function name
2747 $in_doc_sect = 0; 2779 $in_doc_sect = 0;
2780 $declaration_start_line = $. + 1;
2748 } 2781 }
2749 } elsif ($state == STATE_NAME) {# this line is the function name (always) 2782 } elsif ($state == STATE_NAME) {# this line is the function name (always)
2750 if (/$doc_block/o) { 2783 if (/$doc_block/o) {
2751 $state = STATE_DOCBLOCK; 2784 $state = STATE_DOCBLOCK;
2752 $contents = ""; 2785 $contents = "";
2786 $new_start_line = $. + 1;
2787
2753 if ( $1 eq "" ) { 2788 if ( $1 eq "" ) {
2754 $section = $section_intro; 2789 $section = $section_intro;
2755 } else { 2790 } else {
@@ -2763,8 +2798,11 @@ sub process_file($) {
2763 } 2798 }
2764 2799
2765 $state = STATE_FIELD; 2800 $state = STATE_FIELD;
2801 # if there's no @param blocks need to set up default section
2802 # here
2766 $contents = ""; 2803 $contents = "";
2767 $section = $section_default; 2804 $section = $section_default;
2805 $new_start_line = $. + 1;
2768 if (/-(.*)/) { 2806 if (/-(.*)/) {
2769 # strip leading/trailing/multiple spaces 2807 # strip leading/trailing/multiple spaces
2770 $descr= $1; 2808 $descr= $1;
@@ -2833,6 +2871,7 @@ sub process_file($) {
2833 $in_doc_sect = 1; 2871 $in_doc_sect = 1;
2834 $in_purpose = 0; 2872 $in_purpose = 0;
2835 $contents = $newcontents; 2873 $contents = $newcontents;
2874 $new_start_line = $.;
2836 while ((substr($contents, 0, 1) eq " ") || 2875 while ((substr($contents, 0, 1) eq " ") ||
2837 substr($contents, 0, 1) eq "\t") { 2876 substr($contents, 0, 1) eq "\t") {
2838 $contents = substr($contents, 1); 2877 $contents = substr($contents, 1);
@@ -2866,6 +2905,7 @@ sub process_file($) {
2866 dump_section($file, $section, xml_escape($contents)); 2905 dump_section($file, $section, xml_escape($contents));
2867 $section = $section_default; 2906 $section = $section_default;
2868 $contents = ""; 2907 $contents = "";
2908 $new_start_line = $.;
2869 } else { 2909 } else {
2870 $contents .= "\n"; 2910 $contents .= "\n";
2871 } 2911 }
@@ -2900,6 +2940,7 @@ sub process_file($) {
2900 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2940 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
2901 $section = $1; 2941 $section = $1;
2902 $contents = $2; 2942 $contents = $2;
2943 $new_start_line = $.;
2903 if ($contents ne "") { 2944 if ($contents ne "") {
2904 while ((substr($contents, 0, 1) eq " ") || 2945 while ((substr($contents, 0, 1) eq " ") ||
2905 substr($contents, 0, 1) eq "\t") { 2946 substr($contents, 0, 1) eq "\t") {