Commit f9bbc12c authored by Aditya Srivastava's avatar Aditya Srivastava Committed by Jonathan Corbet

scripts: kernel-doc: improve parsing for kernel-doc comments syntax

Currently kernel-doc does not identify some cases of probable kernel
doc comments, for e.g. pointer used as declaration type for identifier,
space separated identifier, etc.

Some example of these cases in files can be:
i)" *  journal_t * jbd2_journal_init_dev() - creates and initialises a journal structure"
in fs/jbd2/journal.c

ii) "*      dget, dget_dlock -      get a reference to a dentry" in
include/linux/dcache.h

iii) "  * DEFINE_SEQLOCK(sl) - Define a statically allocated seqlock_t"
in include/linux/seqlock.h

Also improve identification for non-kerneldoc comments. For e.g.,

i) " *	The following functions allow us to read data using a swap map"
in kernel/power/swap.c does follow the kernel-doc like syntax, but the
content inside does not adheres to the expected format.

Improve parsing by adding support for these probable attempts to write
kernel-doc comment.
Suggested-by: default avatarJonathan Corbet <corbet@lwn.net>
Link: https://lore.kernel.org/lkml/87mtujktl2.fsf@meer.lwn.netSigned-off-by: default avatarAditya Srivastava <yashsri421@gmail.com>
Link: https://lore.kernel.org/r/20210414192529.9080-1-yashsri421@gmail.com
[ jc: fixed some line-length issues ]
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent 9a18473c
...@@ -2110,17 +2110,28 @@ sub process_name($$) { ...@@ -2110,17 +2110,28 @@ sub process_name($$) {
} elsif (/$doc_decl/o) { } elsif (/$doc_decl/o) {
$identifier = $1; $identifier = $1;
my $is_kernel_comment = 0; my $is_kernel_comment = 0;
if (/^\s*\*\s*([\w\s]+?)(\(\))?\s*([-:].*)?$/) { my $decl_start = qr{\s*\*};
# test for pointer declaration type, foo * bar() - desc
my $fn_type = qr{\w+\s*\*\s*};
my $parenthesis = qr{\(\w*\)};
my $decl_end = qr{[-:].*};
if (/^$decl_start\s*([\w\s]+?)$parenthesis?\s*$decl_end?$/) {
$identifier = $1; $identifier = $1;
$decl_type = 'function';
$identifier =~ s/^define\s+//;
$is_kernel_comment = 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
# identifier
elsif (/^$decl_start\s*$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||
/^$decl_start\s*$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) {
$identifier = $1;
$decl_type = 'function';
$identifier =~ s/^define\s+//;
$is_kernel_comment = 1;
}
$identifier =~ s/\s+$//; $identifier =~ s/\s+$//;
$state = STATE_BODY; $state = STATE_BODY;
......
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