Skip to contentSkip to conversation

Coccinelle question

Cocci Nicolas Koenig 2 participants 2 messages May 8, 2019 – May 9, 2019 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hello Julia, world,

Thank you for the quick reply

Quoted 48 lines · Julia Lawall

Le 08.05.2019 12:15, Nicolas Koenig a écrit :

Quoted 47 lines

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")

Quoted 4 lines
Quoted 2 lines

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.

Quoted 1 line

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?

Quoted 9 lines
Quoted 7 lines

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

Quoted 2 lines

julia

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

#3 lore raw
Quoted 18 lines

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

(quoted diff) +1 -1
-int foo(void) {
+void foo(int *ret, void) {
   return 0;
 }
Quoted 1 line

Any idea what the best way to prevent this would be?

OK, sorry, I didn't notice that it was only ... in the matching part. I think you could just put a dummy parameter:

@@
type T,T1;
identifier fn,i;
@@

- T fn(
+ void fn(T *ret,

	T1 i, ...) {...}

That should match cases with only one parameter, even though the , doesn't match anything.

julia

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Thank you in advance!

  Nicolas

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

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

Quoted 2 lines

julia

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