Re: [PATCH v3 01/56] scripts: kernel-doc: fix typedef parsing

Joe Perches
2020-10-23T18:01:41Z

On Fri, 2020-10-23 at 11:22 -0600, Jonathan Corbet wrote:
> On Fri, 23 Oct 2020 18:32:48 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:
>
> > The include/linux/genalloc.h file defined this typedef:
> >
> > typedef unsigned long (*genpool_algo_t)(unsigned long *map,unsigned long size,unsigned long start,unsigned int nr,void *data, struct gen_pool *pool, unsigned long start_addr);
[]
> > diff --git a/scripts/kernel-doc b/scripts/kernel-doc
[]
> >      # Parse function prototypes
> > - if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
> > + if ($x =~ /typedef\s+(\w+\s*){1,}\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
>
> I sure wish we could find a way to make all these regexes more
> understandable and maintainable. Reviewing a change like this is ... fun.

Perhaps using some of the checkpatch regex definitions like:

$Type
$Ident
$balanced_parens

would help improve readability.

And the regex above doesn't quite work for spacing after typedef.
The regex should allow space between the open parenthesis and the *

typedef <Type> ( * <Ident> ) (args...);

And this regex does not find typedefs that use another typedef as <Ident> like:

arch/s390/include/asm/debug.h:typedef int (debug_header_proc_t) (debug_info_t *id,