diff options
| author | Jani Nikula <jani.nikula@intel.com> | 2016-05-26 07:56:05 -0400 |
|---|---|---|
| committer | Jani Nikula <jani.nikula@intel.com> | 2016-05-30 06:38:54 -0400 |
| commit | 48af606ad8912f90e1539621a26e86672976d8ae (patch) | |
| tree | 8f5c0e9d3d09a8fa2d688d30cffbe5591655d692 /scripts/kernel-doc | |
| parent | 30ca7aaf279944da930b587b05d9b325ec7f821d (diff) | |
kernel-doc: add names for states and substates
Make the state machine a bit more readable by adding constants for
parser states and inline member documentation parser substates. While at
it, rename the "split" documentation to "inline" documentation.
No functional changes.
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Diffstat (limited to 'scripts/kernel-doc')
| -rwxr-xr-x | scripts/kernel-doc | 91 |
1 files changed, 48 insertions, 43 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 3ad54abe0989..cb5fd248ac57 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
| @@ -350,24 +350,29 @@ my $section_counter = 0; | |||
| 350 | 350 | ||
| 351 | my $lineprefix=""; | 351 | my $lineprefix=""; |
| 352 | 352 | ||
| 353 | # states | 353 | # Parser states |
| 354 | # 0 - normal code | 354 | use constant { |
| 355 | # 1 - looking for function name | 355 | STATE_NORMAL => 0, # normal code |
| 356 | # 2 - scanning field start. | 356 | STATE_NAME => 1, # looking for function name |
| 357 | # 3 - scanning prototype. | 357 | STATE_FIELD => 2, # scanning field start |
| 358 | # 4 - documentation block | 358 | STATE_PROTO => 3, # scanning prototype |
| 359 | # 5 - gathering documentation outside main block | 359 | STATE_DOCBLOCK => 4, # documentation block |
| 360 | STATE_INLINE => 5, # gathering documentation outside main block | ||
| 361 | }; | ||
| 360 | my $state; | 362 | my $state; |
| 361 | my $in_doc_sect; | 363 | my $in_doc_sect; |
| 362 | 364 | ||
| 363 | # Split Doc State | 365 | # Inline documentation state |
| 364 | # 0 - Invalid (Before start or after finish) | 366 | use constant { |
| 365 | # 1 - Is started (the /** was found inside a struct) | 367 | STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) |
| 366 | # 2 - The @parameter header was found, start accepting multi paragraph text. | 368 | STATE_INLINE_NAME => 1, # looking for member name (@foo:) |
| 367 | # 3 - Finished (the */ was found) | 369 | STATE_INLINE_TEXT => 2, # looking for member documentation |
| 368 | # 4 - Error - Comment without header was found. Spit a warning as it's not | 370 | STATE_INLINE_END => 3, # done |
| 369 | # proper kernel-doc and ignore the rest. | 371 | STATE_INLINE_ERROR => 4, # error - Comment without header was found. |
| 370 | my $split_doc_state; | 372 | # Spit a warning as it's not |
| 373 | # proper kernel-doc and ignore the rest. | ||
| 374 | }; | ||
| 375 | my $inline_doc_state; | ||
| 371 | 376 | ||
| 372 | #declaration types: can be | 377 | #declaration types: can be |
| 373 | # 'function', 'struct', 'union', 'enum', 'typedef' | 378 | # 'function', 'struct', 'union', 'enum', 'typedef' |
| @@ -383,9 +388,9 @@ my $doc_decl = $doc_com . '(\w+)'; | |||
| 383 | my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; | 388 | my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; |
| 384 | my $doc_content = $doc_com_body . '(.*)'; | 389 | my $doc_content = $doc_com_body . '(.*)'; |
| 385 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; | 390 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
| 386 | my $doc_split_start = '^\s*/\*\*\s*$'; | 391 | my $doc_inline_start = '^\s*/\*\*\s*$'; |
| 387 | my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; | 392 | my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; |
| 388 | my $doc_split_end = '^\s*\*/\s*$'; | 393 | my $doc_inline_end = '^\s*\*/\s*$'; |
| 389 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; | 394 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
| 390 | 395 | ||
| 391 | my %constants; | 396 | my %constants; |
| @@ -2497,8 +2502,8 @@ sub reset_state { | |||
| 2497 | $struct_actual = ""; | 2502 | $struct_actual = ""; |
| 2498 | $prototype = ""; | 2503 | $prototype = ""; |
| 2499 | 2504 | ||
| 2500 | $state = 0; | 2505 | $state = STATE_NORMAL; |
| 2501 | $split_doc_state = 0; | 2506 | $inline_doc_state = STATE_INLINE_NA; |
| 2502 | } | 2507 | } |
| 2503 | 2508 | ||
| 2504 | sub tracepoint_munge($) { | 2509 | sub tracepoint_munge($) { |
| @@ -2707,14 +2712,14 @@ sub process_file($) { | |||
| 2707 | while (s/\\\s*$//) { | 2712 | while (s/\\\s*$//) { |
| 2708 | $_ .= <IN>; | 2713 | $_ .= <IN>; |
| 2709 | } | 2714 | } |
| 2710 | if ($state == 0) { | 2715 | if ($state == STATE_NORMAL) { |
| 2711 | if (/$doc_start/o) { | 2716 | if (/$doc_start/o) { |
| 2712 | $state = 1; # next line is always the function name | 2717 | $state = STATE_NAME; # next line is always the function name |
| 2713 | $in_doc_sect = 0; | 2718 | $in_doc_sect = 0; |
| 2714 | } | 2719 | } |
| 2715 | } elsif ($state == 1) { # this line is the function name (always) | 2720 | } elsif ($state == STATE_NAME) {# this line is the function name (always) |
| 2716 | if (/$doc_block/o) { | 2721 | if (/$doc_block/o) { |
| 2717 | $state = 4; | 2722 | $state = STATE_DOCBLOCK; |
| 2718 | $contents = ""; | 2723 | $contents = ""; |
| 2719 | if ( $1 eq "" ) { | 2724 | if ( $1 eq "" ) { |
| 2720 | $section = $section_intro; | 2725 | $section = $section_intro; |
| @@ -2728,7 +2733,7 @@ sub process_file($) { | |||
| 2728 | $identifier = $1; | 2733 | $identifier = $1; |
| 2729 | } | 2734 | } |
| 2730 | 2735 | ||
| 2731 | $state = 2; | 2736 | $state = STATE_FIELD; |
| 2732 | if (/-(.*)/) { | 2737 | if (/-(.*)/) { |
| 2733 | # strip leading/trailing/multiple spaces | 2738 | # strip leading/trailing/multiple spaces |
| 2734 | $descr= $1; | 2739 | $descr= $1; |
| @@ -2766,9 +2771,9 @@ sub process_file($) { | |||
| 2766 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", | 2771 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", |
| 2767 | " - I thought it was a doc line\n"; | 2772 | " - I thought it was a doc line\n"; |
| 2768 | ++$warnings; | 2773 | ++$warnings; |
| 2769 | $state = 0; | 2774 | $state = STATE_NORMAL; |
| 2770 | } | 2775 | } |
| 2771 | } elsif ($state == 2) { # look for head: lines, and include content | 2776 | } elsif ($state == STATE_FIELD) { # look for head: lines, and include content |
| 2772 | if (/$doc_sect/o) { | 2777 | if (/$doc_sect/o) { |
| 2773 | $newsection = $1; | 2778 | $newsection = $1; |
| 2774 | $newcontents = $2; | 2779 | $newcontents = $2; |
| @@ -2806,7 +2811,7 @@ sub process_file($) { | |||
| 2806 | } | 2811 | } |
| 2807 | 2812 | ||
| 2808 | $prototype = ""; | 2813 | $prototype = ""; |
| 2809 | $state = 3; | 2814 | $state = STATE_PROTO; |
| 2810 | $brcount = 0; | 2815 | $brcount = 0; |
| 2811 | # print STDERR "end of doc comment, looking for prototype\n"; | 2816 | # print STDERR "end of doc comment, looking for prototype\n"; |
| 2812 | } elsif (/$doc_content/) { | 2817 | } elsif (/$doc_content/) { |
| @@ -2834,9 +2839,9 @@ sub process_file($) { | |||
| 2834 | print STDERR "${file}:$.: warning: bad line: $_"; | 2839 | print STDERR "${file}:$.: warning: bad line: $_"; |
| 2835 | ++$warnings; | 2840 | ++$warnings; |
| 2836 | } | 2841 | } |
| 2837 | } elsif ($state == 5) { # scanning for split parameters | 2842 | } elsif ($state == STATE_INLINE) { # scanning for inline parameters |
| 2838 | # First line (state 1) needs to be a @parameter | 2843 | # First line (state 1) needs to be a @parameter |
| 2839 | if ($split_doc_state == 1 && /$doc_split_sect/o) { | 2844 | if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { |
| 2840 | $section = $1; | 2845 | $section = $1; |
| 2841 | $contents = $2; | 2846 | $contents = $2; |
| 2842 | if ($contents ne "") { | 2847 | if ($contents ne "") { |
| @@ -2846,37 +2851,37 @@ sub process_file($) { | |||
| 2846 | } | 2851 | } |
| 2847 | $contents .= "\n"; | 2852 | $contents .= "\n"; |
| 2848 | } | 2853 | } |
| 2849 | $split_doc_state = 2; | 2854 | $inline_doc_state = STATE_INLINE_TEXT; |
| 2850 | # Documentation block end */ | 2855 | # Documentation block end */ |
| 2851 | } elsif (/$doc_split_end/) { | 2856 | } elsif (/$doc_inline_end/) { |
| 2852 | if (($contents ne "") && ($contents ne "\n")) { | 2857 | if (($contents ne "") && ($contents ne "\n")) { |
| 2853 | dump_section($file, $section, xml_escape($contents)); | 2858 | dump_section($file, $section, xml_escape($contents)); |
| 2854 | $section = $section_default; | 2859 | $section = $section_default; |
| 2855 | $contents = ""; | 2860 | $contents = ""; |
| 2856 | } | 2861 | } |
| 2857 | $state = 3; | 2862 | $state = STATE_PROTO; |
| 2858 | $split_doc_state = 0; | 2863 | $inline_doc_state = STATE_INLINE_NA; |
| 2859 | # Regular text | 2864 | # Regular text |
| 2860 | } elsif (/$doc_content/) { | 2865 | } elsif (/$doc_content/) { |
| 2861 | if ($split_doc_state == 2) { | 2866 | if ($inline_doc_state == STATE_INLINE_TEXT) { |
| 2862 | $contents .= $1 . "\n"; | 2867 | $contents .= $1 . "\n"; |
| 2863 | } elsif ($split_doc_state == 1) { | 2868 | } elsif ($inline_doc_state == STATE_INLINE_NAME) { |
| 2864 | $split_doc_state = 4; | 2869 | $inline_doc_state = STATE_INLINE_ERROR; |
| 2865 | print STDERR "Warning(${file}:$.): "; | 2870 | print STDERR "Warning(${file}:$.): "; |
| 2866 | print STDERR "Incorrect use of kernel-doc format: $_"; | 2871 | print STDERR "Incorrect use of kernel-doc format: $_"; |
| 2867 | ++$warnings; | 2872 | ++$warnings; |
| 2868 | } | 2873 | } |
| 2869 | } | 2874 | } |
| 2870 | } elsif ($state == 3) { # scanning for function '{' (end of prototype) | 2875 | } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) |
| 2871 | if (/$doc_split_start/) { | 2876 | if (/$doc_inline_start/) { |
| 2872 | $state = 5; | 2877 | $state = STATE_INLINE; |
| 2873 | $split_doc_state = 1; | 2878 | $inline_doc_state = STATE_INLINE_NAME; |
| 2874 | } elsif ($decl_type eq 'function') { | 2879 | } elsif ($decl_type eq 'function') { |
| 2875 | process_state3_function($_, $file); | 2880 | process_state3_function($_, $file); |
| 2876 | } else { | 2881 | } else { |
| 2877 | process_state3_type($_, $file); | 2882 | process_state3_type($_, $file); |
| 2878 | } | 2883 | } |
| 2879 | } elsif ($state == 4) { | 2884 | } elsif ($state == STATE_DOCBLOCK) { |
| 2880 | # Documentation block | 2885 | # Documentation block |
| 2881 | if (/$doc_block/) { | 2886 | if (/$doc_block/) { |
| 2882 | dump_doc_section($file, $section, xml_escape($contents)); | 2887 | dump_doc_section($file, $section, xml_escape($contents)); |
| @@ -2907,7 +2912,7 @@ sub process_file($) { | |||
| 2907 | %sections = (); | 2912 | %sections = (); |
| 2908 | @sectionlist = (); | 2913 | @sectionlist = (); |
| 2909 | $prototype = ""; | 2914 | $prototype = ""; |
| 2910 | $state = 0; | 2915 | $state = STATE_NORMAL; |
| 2911 | } | 2916 | } |
| 2912 | elsif (/$doc_content/) | 2917 | elsif (/$doc_content/) |
| 2913 | { | 2918 | { |
