Coccinelle archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Matching more than one declaration?
@ 2019-05-02 21:04 Michael Stefaniuc
  2019-05-03  7:17 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Stefaniuc @ 2019-05-02 21:04 UTC (permalink / raw)
  To: Coccinelle

Hello,

it seems that more than one declaration cannot be matched in one rule:

@@
identifier i, f;
@@
- int i;
- int f;

That won't match

void foo(void)
{
    int i;
    float f;
}


Is there a way to do that?
In my specific case I need to replace 3 declarations with a single
declarer. I can use 3 separate rules but the first rule will produce
false positives if the other two declarations aren't there.


thanks
bye
      michael
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] Matching more than one declaration?
  2019-05-02 21:04 [Cocci] Matching more than one declaration? Michael Stefaniuc
@ 2019-05-03  7:17 ` Julia Lawall
  2019-05-03  8:03   ` Michael Stefaniuc
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2019-05-03  7:17 UTC (permalink / raw)
  To: Michael Stefaniuc; +Cc: Coccinelle



On Thu, 2 May 2019, Michael Stefaniuc wrote:

> Hello,
>
> it seems that more than one declaration cannot be matched in one rule:
>
> @@
> identifier i, f;
> @@
> - int i;
> - int f;
>
> That won't match
>
> void foo(void)
> {
>     int i;
>     float f;

The semantic patch has int int and the code has int float.  If the code
has int int, it matches fine.

julia

> }
>
>
> Is there a way to do that?
> In my specific case I need to replace 3 declarations with a single
> declarer. I can use 3 separate rules but the first rule will produce
> false positives if the other two declarations aren't there.
>
>
> thanks
> bye
>       michael
> _______________________________________________
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] Matching more than one declaration?
  2019-05-03  7:17 ` Julia Lawall
@ 2019-05-03  8:03   ` Michael Stefaniuc
  2019-05-03 20:39     ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Stefaniuc @ 2019-05-03  8:03 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

On 2019-05-03 09:17, Julia Lawall wrote:
> On Thu, 2 May 2019, Michael Stefaniuc wrote:
> 
>> Hello,
>> 
>> it seems that more than one declaration cannot be matched in one rule:
>> 
>> @@
>> identifier i, f;
>> @@
>> - int i;
>> - int f;
>> 
>> That won't match
>> 
>> void foo(void)
>> {
>>     int i;
>>     float f;
> 
> The semantic patch has int int and the code has int float.  If the code
> has int int, it matches fine.
Duh... I messed it up while simplifying my test case :/

It does work but only in function scope and not in global scope.
I've attached the fixed test case.

thanks
bye
       michael

[-- Attachment #2: declare.c --]
[-- Type: text/x-c, Size: 60 bytes --]

[-- Attachment #3: declare.cocci --]
[-- Type: text/plain, Size: 43 bytes --]

@@
identifier i, f;
@@
- int i;
- float f;

[-- Attachment #4: declare.diff --]
[-- Type: text/x-diff, Size: 133 bytes --]

[-- Attachment #5: Type: text/plain, Size: 136 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] Matching more than one declaration?
  2019-05-03  8:03   ` Michael Stefaniuc
@ 2019-05-03 20:39     ` Julia Lawall
  2019-05-03 20:44       ` Michael Stefaniuc
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2019-05-03 20:39 UTC (permalink / raw)
  To: Michael Stefaniuc; +Cc: Coccinelle



On Fri, 3 May 2019, Michael Stefaniuc wrote:

> On 2019-05-03 09:17, Julia Lawall wrote:
> > On Thu, 2 May 2019, Michael Stefaniuc wrote:
> >
> > > Hello,
> > >
> > > it seems that more than one declaration cannot be matched in one rule:
> > >
> > > @@
> > > identifier i, f;
> > > @@
> > > - int i;
> > > - int f;
> > >
> > > That won't match
> > >
> > > void foo(void)
> > > {
> > >     int i;
> > >     float f;
> >
> > The semantic patch has int int and the code has int float.  If the code
> > has int int, it matches fine.
> Duh... I messed it up while simplifying my test case :/
>
> It does work but only in function scope and not in global scope.
> I've attached the fixed test case.

No, it won't work in global scope.  You can only match one top-level thing
at a time, and each declaration is a top-level thing.  Youcan make a
series of rules that depend on the previous ones, and only make the change
if all are matched.

julia

>
> thanks
> bye
>       michael
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Cocci] Matching more than one declaration?
  2019-05-03 20:39     ` Julia Lawall
@ 2019-05-03 20:44       ` Michael Stefaniuc
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Stefaniuc @ 2019-05-03 20:44 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Coccinelle

On 5/3/19 10:39 PM, Julia Lawall wrote:
> 
> 
> On Fri, 3 May 2019, Michael Stefaniuc wrote:
> 
>> On 2019-05-03 09:17, Julia Lawall wrote:
>>> On Thu, 2 May 2019, Michael Stefaniuc wrote:
>>>
>>>> Hello,
>>>>
>>>> it seems that more than one declaration cannot be matched in one rule:
>>>>
>>>> @@
>>>> identifier i, f;
>>>> @@
>>>> - int i;
>>>> - int f;
>>>>
>>>> That won't match
>>>>
>>>> void foo(void)
>>>> {
>>>>     int i;
>>>>     float f;
>>>
>>> The semantic patch has int int and the code has int float.  If the code
>>> has int int, it matches fine.
>> Duh... I messed it up while simplifying my test case :/
>>
>> It does work but only in function scope and not in global scope.
>> I've attached the fixed test case.
> 
> No, it won't work in global scope.  You can only match one top-level thing
> at a time, and each declaration is a top-level thing.  Youcan make a
> series of rules that depend on the previous ones, and only make the change
> if all are matched.
Ok, thanks. That's what I did as a workaround.

bye
	michael

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-02 21:04 [Cocci] Matching more than one declaration? Michael Stefaniuc
2019-05-03  7:17 ` Julia Lawall
2019-05-03  8:03   ` Michael Stefaniuc
2019-05-03 20:39     ` Julia Lawall
2019-05-03 20:44       ` Michael Stefaniuc

Coccinelle archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr cocci@archiver.kernel.org
	public-inbox-index cocci


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/ public-inbox