Re: [PATCH RFC v2] checkpatch: extend attributes check to handle more patterns

From: Dwaipayan Ray
Date: Fri Oct 23 2020 - 16:57:36 EST


On Sat, Oct 24, 2020 at 2:12 AM Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> On Sat, 2020-10-24 at 00:44 +0530, Dwaipayan Ray wrote:
> > Hi,
>
> Hi again.
>
> > I modified the check to check the attributes from the map.
> > There are two checks - one for the normal attributes and
> > one for the ones with arguments, which needs just a bit more
> > processing.
> >
> > So attributes like __packed__ as well as those like
> > __aligned__(x) are handled.
> >
> > What do you think?
> >
> > ---
> > + $line =~ /__attribute__\s*\(\s*($balanced_parens)\s*\)/)
> > {
> > + my $attr = trim($1);
> > + $attr =~ s/\(\s*_*(.*)\)/$1/;
> > + while($attr =~ s/(.*)_$/$1/) {} # Remove trailing
> > underscores
>
> I think this could be a single test like:
>
> while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) {
> my $curr_attr = $1;
> my $parens = $2;
> $curr_attr = s/^_*(.*)_*$/$1/;
>

Thanks, I will do that.

Also I tried the pattern attr =~ s/^_*(.*)_*$/$1/
for trimming the _ earlier. I think it doesn't trim the
trailing underscores in the suffix as (.*) captures everything greedily.

Is the iterative one perhaps okay instead?
while($attr =~ s/(.*)_$/$1/) {}

> > + my %attr_list = (
> > + "alias" => "__alias",
> > + "aligned" => "__aligned",
>
> These might be better using tab alignment.
>
> And you might special case format(printf/scanf here too

Yes I think they are special cases now too. I didn't post the
entire context, so my mistake.

Thanks,
Dwaipayan.