Re: [Cocci] Easy search for elements besides binary operators with SmPL

2017-05-12 Thread SF Markus Elfring
>> I find it just strange that extra parentheses are needed in such an use case
>> at the moment.
> 
> ... is used in a number of contexts in SmPL, and sometimes its use has to
> be restricted to avoid parsing ambiguities.

I tried to use extra parentheses for other source code search patterns.
I left them “accidentally” out with undesired consequences this time.


> I'm a bit surprised also that it is a problem in this case.

I find such a feedback interesting then if it will influence corresponding
software evolution.

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Easy search for elements besides binary operators with SmPL

2017-05-12 Thread Julia Lawall


On Fri, 12 May 2017, SF Markus Elfring wrote:

> >>> Maybe put parentheses around the second argument.  An isomorphism will
> >>> drop them and you will avoid whatever parsing issue is being encountered.
> >>
> >> I do not observe a desired improvement after such a SmPL code adjustment.
> >
> > Your change is not what I suggested either.  The second argument starts to
> > the right of one comma and ends to the left of the next one.
>
> I interpreted the “second one” as belonging to the ellipsis in the binary
> operator specification (for a moment).
>
> Now I observe that the following SmPL script variants work as desired
> in principle.
>
> @find_last_option@
> expression target;
> identifier action;
> @@
>  target = action(...,
>  ( ...
> *| __GFP_NOFAIL
>  )
> );
>
>
> @find_flag@
> expression target;
> identifier action;
> @@
>  target = action(...,
>  ( ...
> *| __GFP_NOFAIL
>  | ...
>  ),
>  ...);
>
>
> I find it just strange that extra parentheses are needed in such an use case
> at the moment.

... is used in a number of contexts in SmPL, and sometimes its use has to
be restricted to avoid parsing ambiguities.  I'm a bit surprised also that
it is a problem in this case.

julia___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Easy search for elements besides binary operators with SmPL

2017-05-12 Thread SF Markus Elfring
>>> Maybe put parentheses around the second argument.  An isomorphism will
>>> drop them and you will avoid whatever parsing issue is being encountered.
>>
>> I do not observe a desired improvement after such a SmPL code adjustment.
> 
> Your change is not what I suggested either.  The second argument starts to
> the right of one comma and ends to the left of the next one.

I interpreted the “second one” as belonging to the ellipsis in the binary
operator specification (for a moment).

Now I observe that the following SmPL script variants work as desired
in principle.

@find_last_option@
expression target;
identifier action;
@@
 target = action(...,
 ( ...
*| __GFP_NOFAIL
 )
);


@find_flag@
expression target;
identifier action;
@@
 target = action(...,
 ( ...
*| __GFP_NOFAIL
 | ...
 ),
 ...);


I find it just strange that extra parentheses are needed in such an use case
at the moment.

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] Easy search for elements besides binary operators with SmPL

2017-05-12 Thread Julia Lawall


On Fri, 12 May 2017, SF Markus Elfring wrote:

> > Maybe put parentheses around the second argument.  An isomorphism will
> > drop them and you will avoid whatever parsing issue is being encountered.
>
> I do not observe a desired improvement after such a SmPL code adjustment.

Your change is not what I suggested either.  The second argument starts to
the right of one comma and ends to the left of the next one.

julia

> @find@
> expression target;
> identifier action;
> @@
>  target = action(...,
>  ...
> *| __GFP_NOFAIL
>  | (...),
>  ...);
>
>
>
> The Coccinelle software does also not like a reduced script variant so far.
>
> @find@
> expression target;
> identifier action;
> @@
>  target = action(...,
>  ...
> *| __GFP_NOFAIL
>  );
>
>
> elfring@Sonne:~/Projekte/Linux/next-patched> spatch.opt 
> drivers/md/dm-region-hash.c 
> ~/Projekte/Coccinelle/janitor/show_use_of_nofail_as_last_option1.cocci
> …
> minus: parse error:
>   File 
> "/home/elfring/Projekte/Coccinelle/janitor/show_use_of_nofail_as_last_option1.cocci",
>  line 6, column 17, charpos = 87
>   around = '...',
>   whole content =  ...
>
>
> Do you get further ideas?
>
> Regards,
> Markus
>___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] Easy search for elements besides binary operators with SmPL

2017-05-12 Thread SF Markus Elfring
Hello,

I would like to check also the application of elements which are used together
with binary operators like the following.


@find@
expression target;
identifier action;
@@
 target = action(...,
 ...
*| __GFP_NOFAIL
 | ...,
 ...);


elfring@Sonne:~/Projekte/Linux/next-patched> spatch.opt 
drivers/md/dm-region-hash.c 
~/Projekte/Coccinelle/janitor/show_use_of_nofail1.cocci
…
minus: parse error: 
  File "/home/elfring/Projekte/Coccinelle/janitor/show_use_of_nofail1.cocci", 
line 6, column 17, charpos = 87
  around = '...',
  whole content =  ...


How should I improve my search pattern?


A metavariable can already be used for the search of a function parameter at an
undetermined position within a bigger list. Can similar functionality work also
for binary operators?

Regards,
Markus
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] howto conditional match

2017-05-12 Thread Julia Lawall


On Fri, 12 May 2017, Arend van Spriel wrote:

> On 5/12/2017 2:15 PM, Julia Lawall wrote:
> >
> >
> > On Fri, 12 May 2017, Arend van Spriel wrote:
> >
> > > I have the following rule in my cocci script. Actually, want to apply the
> > > patch conditionally, ie. when type S matches one or more structure
> > > definitions. Initially I had 'struct Foo *drvr, ...' but that did not work
> > > for
> > > me. Any hints are appreciated.
> > >
> > > Regards,
> > > Arend
> > >
> > > @@
> > > identifier func;
> > > identifier drvr;
> > > type T;
> > > expression list es;
> > > type S;
> > > @@
> > >  T func(S *drvr, ...)
> >
> > struct i *drvr, where i is an identifier metavariable?  I'm not sure what
> > you mean by one or more. Do you want to match more than the first
> > argument?
>
> Hi Julia,
>
> I mean that I want to apply the rule only if S is 'struct foo' or 'struct
> bar', but not 'struct other'. Or do I need separate rules for that?

OK, it is possible that you can put

struct \(foo\|bar\) *drvr

Or maybe \(struct foo\|struct bar\) *drvr.  Or maybe the \( \) around the
whole parameter declaration.

julia

>
> Regards,
> Arend
> > julia
> >
> >
> > >  {
> > >  <...
> > > -   brcmf_err(es);
> > > +   brcmf_derr(drvr, es);
> > >  ...>
> > >  }
> > > ___
> > > Cocci mailing list
> > > Cocci@systeme.lip6.fr
> > > https://systeme.lip6.fr/mailman/listinfo/cocci
> > >
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] howto conditional match

2017-05-12 Thread Arend van Spriel

On 5/12/2017 2:15 PM, Julia Lawall wrote:



On Fri, 12 May 2017, Arend van Spriel wrote:


I have the following rule in my cocci script. Actually, want to apply the
patch conditionally, ie. when type S matches one or more structure
definitions. Initially I had 'struct Foo *drvr, ...' but that did not work for
me. Any hints are appreciated.

Regards,
Arend

@@
identifier func;
identifier drvr;
type T;
expression list es;
type S;
@@
 T func(S *drvr, ...)


struct i *drvr, where i is an identifier metavariable?  I'm not sure what
you mean by one or more. Do you want to match more than the first
argument?


Hi Julia,

I mean that I want to apply the rule only if S is 'struct foo' or 
'struct bar', but not 'struct other'. Or do I need separate rules for that?


Regards,
Arend

julia



 {
 <...
-   brcmf_err(es);
+   brcmf_derr(drvr, es);
 ...>
 }
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


Re: [Cocci] howto conditional match

2017-05-12 Thread Julia Lawall


On Fri, 12 May 2017, Arend van Spriel wrote:

> I have the following rule in my cocci script. Actually, want to apply the
> patch conditionally, ie. when type S matches one or more structure
> definitions. Initially I had 'struct Foo *drvr, ...' but that did not work for
> me. Any hints are appreciated.
>
> Regards,
> Arend
>
> @@
> identifier func;
> identifier drvr;
> type T;
> expression list es;
> type S;
> @@
> T func(S *drvr, ...)

struct i *drvr, where i is an identifier metavariable?  I'm not sure what
you mean by one or more. Do you want to match more than the first
argument?

julia


> {
> <...
> -   brcmf_err(es);
> +   brcmf_derr(drvr, es);
> ...>
> }
> ___
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] howto conditional match

2017-05-12 Thread Arend van Spriel
I have the following rule in my cocci script. Actually, want to apply 
the patch conditionally, ie. when type S matches one or more structure 
definitions. Initially I had 'struct Foo *drvr, ...' but that did not 
work for me. Any hints are appreciated.


Regards,
Arend

@@
identifier func;
identifier drvr;
type T;
expression list es;
type S;
@@
T func(S *drvr, ...)
{
<...
-   brcmf_err(es);
+   brcmf_derr(drvr, es);
...>
}
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci