Skip to contentSkip to conversation

howto conditional match

Cocci Arend van Spriel 2 participants 4 messages May 12, 2017

lore
Share & tools
lore
#0 lore raw

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);
                 ...>
         }
#1 lore raw
Quoted 8 lines · 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

Quoted 8 lines

@@
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

Quoted 11 lines
        {
                <...
(quoted diff) +1 -1
-               brcmf_err(es);
+               brcmf_derr(drvr, es);
                ...>
        }

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 21 lines · Julia Lawall
Quoted 8 lines · 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

Quoted 8 lines

@@
identifier func;
identifier drvr;
type T;
expression list es;
type S;
@@

         T func(S *drvr, ...)
Quoted 3 lines

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

Quoted 14 lines

julia

Quoted 11 lines
         {
                 <...
(quoted diff) +1 -1
-               brcmf_err(es);
+               brcmf_derr(drvr, es);
                 ...>
         }

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#3 lore raw
Quoted 23 lines · Arend van Spriel
Quoted 22 lines · Julia Lawall
Quoted 17 lines · 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, ...)
Quoted 8 lines
Quoted 3 lines

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

Quoted 18 lines

Regards,
Arend

Quoted 14 lines

julia

Quoted 11 lines
         {
                 <...
(quoted diff) +1 -1
-               brcmf_err(es);
+               brcmf_derr(drvr, es);
                 ...>
         }

_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci