cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] Remove entire multidecl
@ 2019-08-08 10:51 Christoph Böhmwalder
  2019-08-08 11:01 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Christoph Böhmwalder @ 2019-08-08 10:51 UTC (permalink / raw)
  To: cocci

So I've looked around in the demos/ and tests/ as well as the documentation,
but I can't seem to figure out what I'm doing wrong:

test.c
------
int x, y;


test.cocci
----------
@@
identifier x, y;
@@
- int x, y;


Should be pretty straightforward, but the rule does not match. Is there
another syntax to use here? In my real use case, I'm trying the same thing
within a function, and that doesn't match either.

Also, while playing around with it, I found this weird behaviour:

@@
identifier x, y;
@@
- int x;

Yields:

--- test.c
+++ /tmp/cocci-output-6916-8bc8e1-test.c
@@ -1 +1 @@
-int x, y;
+


Not exactly what I expected...

Thanks,
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA —  Disaster Recovery — Software defined Storage
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

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

* Re: [Cocci] Remove entire multidecl
  2019-08-08 10:51 [Cocci] Remove entire multidecl Christoph Böhmwalder
@ 2019-08-08 11:01 ` Julia Lawall
  2019-08-09  6:33   ` Markus Elfring
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2019-08-08 11:01 UTC (permalink / raw)
  To: Christoph Böhmwalder; +Cc: cocci

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



On Thu, 8 Aug 2019, Christoph Böhmwalder wrote:

> So I've looked around in the demos/ and tests/ as well as the documentation,
> but I can't seem to figure out what I'm doing wrong:
>
> test.c
> ------
> int x, y;
>
>
> test.cocci
> ----------
> @@
> identifier x, y;
> @@
> - int x, y;
>
>
> Should be pretty straightforward, but the rule does not match. Is there
> another syntax to use here? In my real use case, I'm trying the same thing
> within a function, and that doesn't match either.
>
> Also, while playing around with it, I found this weird behaviour:
>
> @@
> identifier x, y;
> @@
> - int x;
>
> Yields:
>
> --- test.c
> +++ /tmp/cocci-output-6916-8bc8e1-test.c
> @@ -1 +1 @@
> -int x, y;
> +
>
>
> Not exactly what I expected...

SmPL doesn't support patterns with multiple variable declarations, because
there is really no way to tell whether they will be on one line or
multiple lines.

I'm not sure why the latter is not what you expected.  If you only
expected to remove the int x, then x should not have been an identifier
metavariable.

Basically, it is matching the pattern multiple times on the same code,
once for each variable.  If these matches cause all of the variables to go
away, the type and the ; are removed as well.

It seems that this resulted in adding a blank line.  That is indeed not
really ideal.

julia

>
> Thanks,
> --
> Christoph Böhmwalder
> LINBIT | Keeping the Digital World Running
> DRBD HA —  Disaster Recovery — Software defined Storage
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

[-- Attachment #2: 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] 3+ messages in thread

* Re: [Cocci] Remove entire multidecl
  2019-08-08 11:01 ` Julia Lawall
@ 2019-08-09  6:33   ` Markus Elfring
  0 siblings, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2019-08-09  6:33 UTC (permalink / raw)
  To: cocci

> > Not exactly what I expected...


>
> SmPL doesn't support patterns with multiple variable declarations,

How are the chances to adjust this software limitation?


> because
 there is really no way to tell whether they will be on one line
> or
 multiple lines.


Will it become more interesting to make such a case distinction possible?


> Basically, it is matching the pattern multiple times on the same code,
> once for each variable.

Would you like to achieve that metavariables of the same type (or kind)
can refer to different source code?


> It seems that this resulted in adding a blank line.  That is indeed not
> really ideal.

Was just a blank line left over after the deletion of declarations
(which looks like an addition in the diff format)?

Would you occasionally prefer to omit it (because of pretty-printing)?

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

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

end of thread, other threads:[~2019-08-09  6:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 10:51 [Cocci] Remove entire multidecl Christoph Böhmwalder
2019-08-08 11:01 ` Julia Lawall
2019-08-09  6:33   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).