Skip to contentSkip to conversation

Remove entire multidecl

Cocci Christoph Böhmwalder 3 participants 3 messages Aug 8, 2019 – Aug 9, 2019

lore
Share & tools
lore
#0 lore raw

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:

tmp/cocci-output-6916-8bc8e1-test.c renamed from test.c +1 -1
@@ -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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 36 lines · Christoph Böhmwalder

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:

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

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

Quoted 11 lines

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

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#2 lore raw
Quoted 5 lines
Quoted 1 line

Not exactly what I expected...

SmPL doesn't support patterns with multiple variable declarations,

How are the chances to adjust this software limitation?

Quoted 1 line

because

there is really no way to tell whether they will be on one line

Quoted 1 line

or

multiple lines.

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

Quoted 2 lines

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?

Quoted 2 lines

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci