Hello,

I would like to use Coccinelle to turn the following piece of code :

#define N 4

int array[N];

struct dummy_struct {
        int foo[N];
};

struct dummy_struct dummy = {
        .foo = {}
};

static int
bar(void)
{
        array[0] = BAR;
        array[1] = BAZ;
        /* some more code ... */
}


into something like this :


#define N 4

int array[N];

struct dummy_struct {
        int foo[N];
};

struct dummy_struct dummy = {
        .foo = { BAR, BAZ }
};

static int
bar(void)
{
        /* some more code ... */
}



I wrote the following Coccinelle script, that almost does the job :

@r@
identifier a;
expression E;
@@
- a[...] = E;


@depends on r@
identifier d;
expression r.E;
@@
struct dummy_struct d = {
        .foo = {
++ E,
...
}
};

But I don't get the expected result :

@@ -7,12 +7,12 @@ struct dummy_struct {
 };

 struct dummy_struct dummy = {
-       .foo = {}
+       .foo = {
+               BAZ,
+               BAR, }
 };

 static int
 bar(void)
 {
-       array[0] = BAR;
-       array[1] = BAZ;
 }


The "foo" field is initialized to { BAZ, BAR, } instead of { BAR, BAZ }. How could I modify the second rule so that :
1) BAR comes before BAZ
2) No extra comma is added

?

I'm using Coccinelle 1.0.0-rc7.

Cyril.
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to