Skip to content

Commit a746fe3

Browse files
AdityaSrivastJonathan Corbet
authored andcommitted
scripts: kernel-doc: fix typedef support for struct/union parsing
Currently, there are ~1290 occurrences in 447 files in the kernel tree 'typedef struct/union' syntax for defining some struct/union. However, kernel-doc currently does not support that syntax. Of the ~1290 occurrences, there are four occurrences in ./include/linux/zstd.h with typedef struct/union syntax and a preceding kernel-doc; all other occurrences have no preceding kernel-doc. Add support for parsing struct/union following this syntax. Signed-off-by: Aditya Srivastava <yashsri421@gmail.com> Link: https://lore.kernel.org/r/20210225145033.11431-1-yashsri421@gmail.com Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 1eff491 commit a746fe3

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎scripts/kernel-doc‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,12 +1201,23 @@ sub dump_union($$) {
12011201
sub dump_struct($$) {
12021202
my $x = shift;
12031203
my $file = shift;
1204+
my $decl_type;
1205+
my $members;
1206+
my $type = qr{struct|union};
1207+
# For capturing struct/union definition body, i.e. "{members*}qualifiers*"
1208+
my $definition_body = qr{\{(.*)\}(?:\s*(?:__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*};
12041209

1205-
if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
1206-
my $decl_type = $1;
1210+
if ($x =~ /($type)\s+(\w+)\s*$definition_body/) {
1211+
$decl_type = $1;
12071212
$declaration_name = $2;
1208-
my $members = $3;
1213+
$members = $3;
1214+
} elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) {
1215+
$decl_type = $1;
1216+
$declaration_name = $3;
1217+
$members = $2;
1218+
}
12091219

1220+
if ($members) {
12101221
if ($identifier ne $declaration_name) {
12111222
print STDERR "${file}:$.: warning: expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n";
12121223
return;

0 commit comments

Comments
 (0)