All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Adding missing parameter to function if missing
@ 2016-07-06 13:54 Frédéric LEROY (ext)
  2016-07-06 16:23 ` Julia Lawall
  2016-07-06 16:50 ` [Cocci] Adding " SF Markus Elfring
  0 siblings, 2 replies; 9+ messages in thread
From: Frédéric LEROY (ext) @ 2016-07-06 13:54 UTC (permalink / raw)
  To: cocci

Hi, 

I am new to coccinelle and I have trouble to use it.
What I want to do is add a missing parameter to a function call (bar)
and add this parameter to the function prototype calling it if missing.

Example : 

f1(void *arg) {
	bar(anything);
}

f2(my_type foo, void *arg) {
	bar(anything);
}

=> 

f1(my_type foo, void *arg) {
	bar (foo, anything);
}

f2(my_type foo, void *arg) {
	bar (foo, anything);
}

I tried several ways to do it without success. If I add a negative depends on rule, it won't work.

Here is the c test file :

--------8<--------8<--------8<--------8<--------8<
static void f1(void *args) {
    bar(anything);
}

static void f2(my_type *foo, void *args) {
    bar(anything);
}

static void f3(my_type *foo, void *args) {
}

static void f4(void *args) {
}

static void f5(void *args) {
    int b;
    bar(anything);
    b = 5;
    bar(anything);
}

static void f6(my_type *foo, void *args) {
    int b;
    bar(anything);
    b = 5;
    bar(anything);
}
--------8<--------8<--------8<--------8<--------8<

And here my spatch:

--------8<--------8<--------8<--------8<--------8<
@@
expression E;
@@

- bar(E);
+ bar(foo, E);

@fn_with_user@
identifier fn, foo;
typedef my_type;
parameter list pl;
expression E; 
@@

fn(my_type *foo, pl) {
<+... 
bar(foo, E);
...+> 
}

@ test depends on !fn_with_user@
identifier fn_with_user.fn;
parameter list pl;
expression E;
@@    

fn(
+ my_type *foo,
pl) {
<+...
bar(foo, E);
...+>
}
--------8<--------8<--------8<--------8<--------8<

Could you help me ?

Sincerely,

Fr?d?ric Leroy

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

end of thread, other threads:[~2016-07-08 10:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-06 13:54 [Cocci] Adding missing parameter to function if missing Frédéric LEROY (ext)
2016-07-06 16:23 ` Julia Lawall
2016-07-07 12:18   ` Frédéric LEROY (ext)
2016-07-07 16:14     ` [Cocci] Adding " SF Markus Elfring
2016-07-08 10:46       ` Frédéric LEROY (ext)
2016-07-07 17:09     ` [Cocci] Adding missing " Julia Lawall
2016-07-06 16:50 ` [Cocci] Adding " SF Markus Elfring
2016-07-07 11:54   ` Frédéric LEROY (ext)
2016-07-07 15:43     ` SF Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.