Hello Julia, world,
Thank you for the quick reply
On 08/05/2019 14:10, Julia Lawall wrote:
Le 08.05.2019 12:15, Nicolas Koenig a écrit :
Hi Julia,
I've recently started to learn about cocinelle, but I have a few
questions I can't for the life of me find the answers to in the
documentation, so I hope that you (as one of the persons working on
coccinelle) might be able to help.
I'm trying to write a small script that replaces each return value
with an argument of the same type. This requires special-casing
functions that don't take arguments, so I looked at the following
example I found in the official documentation
@@
expression E,f;
@@
(
if (<+... f(...) ...+>) { BUG(); }
|
- if (E) { BUG(); }
+ BUG_ON(E);
)
and tried to adapt it, so that it (for the moment) just ignores
functions without arguments
@@
type T;
identifier F;
@@
(
int F ( void ) { ... }
|
- T
+ void
F (
+ T *ret,
... ) { ... }
)
This yields a syntax error, though
init_defs_builtins: /usr/lib/coccinelle/standard.h
35 36
Fatal error: exception Failure("minus: parse error: \n = File
\"test1.cocci\", line 6, column 4, charpos = 35\n around = 'F',
whole content = int F ( void ) { ... }\n")
Any hint what I'm doing wrong would help. Also, what are in general
the rules for the '( | )' syntax?
I'm not sure whether you can make a disjunction for a function
definition.
It seems to work for forward function declarartions, just not for
declarations with implementation attached
@@
type T;
identifier fn;
@@
(
T xyzzy(...);
|
- T fn
+ void fn
(...);
)
works as expected, while
@@
type T;
identifier fn;
@@
(
T xyzzy(...) {...}
|
- T fn
+ void fn
(...) {...}
)
yields a parser error.
But I don't think that a function with just void as a
parameter list will match what you have in the other disjunct, so I
think you can just get rid of the void case.
It seem to match. Running the following little patch/script
@@
type T;
identifier fn;
@@
- T fn(
+ void fn(T *ret,
...) {...}
generates, for example, the following diff
-int foo(void) {
+void foo(int *ret, void) {
return 0;
}
Any idea what the best way to prevent this would be?
Thank you in advance!
Nicolas
P.S.: Is there a community where I can ask such questions without
bothering people personally?
Yes, there is a mailing list., You should see this in the contact link
at coccinelle.lip6.fr. You should join the mailing list so I don't have
to approve the posts.
Thank you, I've subscribed and added the list to this thread
Nicolas
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci