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>
This commit is contained in:
Jani Nikula 2016-05-26 14:56:05 +03:00
parent 30ca7aaf27
commit 48af606ad8
1 changed files with 48 additions and 43 deletions

View File

@ -350,24 +350,29 @@ my $section_counter = 0;
my $lineprefix=""; my $lineprefix="";
# states # Parser states
# 0 - normal code use constant {
# 1 - looking for function name STATE_NORMAL => 0, # normal code
# 2 - scanning field start. STATE_NAME => 1, # looking for function name
# 3 - scanning prototype. STATE_FIELD => 2, # scanning field start
# 4 - documentation block STATE_PROTO => 3, # scanning prototype
# 5 - gathering documentation outside main block STATE_DOCBLOCK => 4, # documentation block
STATE_INLINE => 5, # gathering documentation outside main block
};
my $state; my $state;
my $in_doc_sect; my $in_doc_sect;
# Split Doc State # Inline documentation state
# 0 - Invalid (Before start or after finish) use constant {
# 1 - Is started (the /** was found inside a struct) STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
# 2 - The @parameter header was found, start accepting multi paragraph text. STATE_INLINE_NAME => 1, # looking for member name (@foo:)
# 3 - Finished (the */ was found) STATE_INLINE_TEXT => 2, # looking for member documentation
# 4 - Error - Comment without header was found. Spit a warning as it's not STATE_INLINE_END => 3, # done
# proper kernel-doc and ignore the rest. STATE_INLINE_ERROR => 4, # error - Comment without header was found.
my $split_doc_state; # Spit a warning as it's not
# proper kernel-doc and ignore the rest.
};
my $inline_doc_state;
#declaration types: can be #declaration types: can be
# 'function', 'struct', 'union', 'enum', 'typedef' # 'function', 'struct', 'union', 'enum', 'typedef'
@ -383,9 +388,9 @@ my $doc_decl = $doc_com . '(\w+)';
my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
my $doc_content = $doc_com_body . '(.*)'; my $doc_content = $doc_com_body . '(.*)';
my $doc_block = $doc_com . 'DOC:\s*(.*)?'; my $doc_block = $doc_com . 'DOC:\s*(.*)?';
my $doc_split_start = '^\s*/\*\*\s*$'; my $doc_inline_start = '^\s*/\*\*\s*$';
my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
my $doc_split_end = '^\s*\*/\s*$'; my $doc_inline_end = '^\s*\*/\s*$';
my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
my %constants; my %constants;
@ -2497,8 +2502,8 @@ sub reset_state {
$struct_actual = ""; $struct_actual = "";
$prototype = ""; $prototype = "";
$state = 0; $state = STATE_NORMAL;
$split_doc_state = 0; $inline_doc_state = STATE_INLINE_NA;
} }
sub tracepoint_munge($) { sub tracepoint_munge($) {
@ -2707,14 +2712,14 @@ sub process_file($) {
while (s/\\\s*$//) { while (s/\\\s*$//) {
$_ .= <IN>; $_ .= <IN>;
} }
if ($state == 0) { if ($state == STATE_NORMAL) {
if (/$doc_start/o) { if (/$doc_start/o) {
$state = 1; # 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;
} }
} elsif ($state == 1) { # this line is the function name (always) } elsif ($state == STATE_NAME) {# this line is the function name (always)
if (/$doc_block/o) { if (/$doc_block/o) {
$state = 4; $state = STATE_DOCBLOCK;
$contents = ""; $contents = "";
if ( $1 eq "" ) { if ( $1 eq "" ) {
$section = $section_intro; $section = $section_intro;
@ -2728,7 +2733,7 @@ sub process_file($) {
$identifier = $1; $identifier = $1;
} }
$state = 2; $state = STATE_FIELD;
if (/-(.*)/) { if (/-(.*)/) {
# strip leading/trailing/multiple spaces # strip leading/trailing/multiple spaces
$descr= $1; $descr= $1;
@ -2766,9 +2771,9 @@ sub process_file($) {
print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
" - I thought it was a doc line\n"; " - I thought it was a doc line\n";
++$warnings; ++$warnings;
$state = 0; $state = STATE_NORMAL;
} }
} elsif ($state == 2) { # look for head: lines, and include content } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
if (/$doc_sect/o) { if (/$doc_sect/o) {
$newsection = $1; $newsection = $1;
$newcontents = $2; $newcontents = $2;
@ -2806,7 +2811,7 @@ sub process_file($) {
} }
$prototype = ""; $prototype = "";
$state = 3; $state = STATE_PROTO;
$brcount = 0; $brcount = 0;
# print STDERR "end of doc comment, looking for prototype\n"; # print STDERR "end of doc comment, looking for prototype\n";
} elsif (/$doc_content/) { } elsif (/$doc_content/) {
@ -2834,9 +2839,9 @@ sub process_file($) {
print STDERR "${file}:$.: warning: bad line: $_"; print STDERR "${file}:$.: warning: bad line: $_";
++$warnings; ++$warnings;
} }
} elsif ($state == 5) { # scanning for split parameters } elsif ($state == STATE_INLINE) { # scanning for inline parameters
# First line (state 1) needs to be a @parameter # First line (state 1) needs to be a @parameter
if ($split_doc_state == 1 && /$doc_split_sect/o) { if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
$section = $1; $section = $1;
$contents = $2; $contents = $2;
if ($contents ne "") { if ($contents ne "") {
@ -2846,37 +2851,37 @@ sub process_file($) {
} }
$contents .= "\n"; $contents .= "\n";
} }
$split_doc_state = 2; $inline_doc_state = STATE_INLINE_TEXT;
# Documentation block end */ # Documentation block end */
} elsif (/$doc_split_end/) { } elsif (/$doc_inline_end/) {
if (($contents ne "") && ($contents ne "\n")) { if (($contents ne "") && ($contents ne "\n")) {
dump_section($file, $section, xml_escape($contents)); dump_section($file, $section, xml_escape($contents));
$section = $section_default; $section = $section_default;
$contents = ""; $contents = "";
} }
$state = 3; $state = STATE_PROTO;
$split_doc_state = 0; $inline_doc_state = STATE_INLINE_NA;
# Regular text # Regular text
} elsif (/$doc_content/) { } elsif (/$doc_content/) {
if ($split_doc_state == 2) { if ($inline_doc_state == STATE_INLINE_TEXT) {
$contents .= $1 . "\n"; $contents .= $1 . "\n";
} elsif ($split_doc_state == 1) { } elsif ($inline_doc_state == STATE_INLINE_NAME) {
$split_doc_state = 4; $inline_doc_state = STATE_INLINE_ERROR;
print STDERR "Warning(${file}:$.): "; print STDERR "Warning(${file}:$.): ";
print STDERR "Incorrect use of kernel-doc format: $_"; print STDERR "Incorrect use of kernel-doc format: $_";
++$warnings; ++$warnings;
} }
} }
} elsif ($state == 3) { # scanning for function '{' (end of prototype) } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
if (/$doc_split_start/) { if (/$doc_inline_start/) {
$state = 5; $state = STATE_INLINE;
$split_doc_state = 1; $inline_doc_state = STATE_INLINE_NAME;
} elsif ($decl_type eq 'function') { } elsif ($decl_type eq 'function') {
process_state3_function($_, $file); process_state3_function($_, $file);
} else { } else {
process_state3_type($_, $file); process_state3_type($_, $file);
} }
} elsif ($state == 4) { } elsif ($state == STATE_DOCBLOCK) {
# Documentation block # Documentation block
if (/$doc_block/) { if (/$doc_block/) {
dump_doc_section($file, $section, xml_escape($contents)); dump_doc_section($file, $section, xml_escape($contents));
@ -2907,7 +2912,7 @@ sub process_file($) {
%sections = (); %sections = ();
@sectionlist = (); @sectionlist = ();
$prototype = ""; $prototype = "";
$state = 0; $state = STATE_NORMAL;
} }
elsif (/$doc_content/) elsif (/$doc_content/)
{ {