Re: [RFC v3] scripts: kernel-doc: fix typedef support for struct/union parsing

From
Matthew Wilcox <willy@infradead.org>
Date
2021-03-06 04:36:58
Also in
linux-kernel-mentees, lkml
Reply to
Aditya Srivastava, 2021-02-25
On Thu, Feb 25, 2021 at 08:20:33PM +0530, Aditya Srivastava wrote:
quoted hunk ↗ jump to hunk
+++ b/scripts/kernel-doc
@@ -1201,12 +1201,23 @@ sub dump_union($$) {
 sub dump_struct($$) {
     my $x = shift;
     my $file = shift;
+    my $decl_type;
+    my $members;
+    my $type = qr{struct|union};
+    # For capturing struct/union definition body, i.e. "{members*}qualifiers*"
+    my $definition_body = qr{\{(.*)\}(?:\s*(?:__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*};
-    if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
-	my $decl_type = $1;
+    if ($x =~ /($type)\s+(\w+)\s*$definition_body/) {
+	$decl_type = $1;
 	$declaration_name = $2;
-	my $members = $3;
+	$members = $3;
+    } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) {
+	$decl_type = $1;
+	$declaration_name = $3;
+	$members = $2;
+    }
In the same spirit as dump_function, would something like this work?

-    if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
+    $x =~ s/__packed +//;
+    $x =~ s/__aligned +//;
+    $x =~ s/____cacheline_aligned_in_smp +//;
+    $x =~ s/____cacheline_aligned +//;
+    $x =~ s/__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)//;
+
+    if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*)*/) {
Thread (13 messages) 13 messages, 4 authors, last reply 2021-03-07
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help