A partial solution to your problem is below. The problems are as follows:
1. Coccinelle has to be able to find the structure definition. This is an
intrinsic problem. You will have to use the argument --all-includes or
even --recursive-includes so that it will try to hunt around for the
needed include files. This will be slow.
2. If there is a mixture of c99 declarations and non-c99 declarations,
the rule does nothing.
3. There is a lot of duplicated code, due to some useful features not
being supported for structure initializers.
4. The rule only supports a simple structure or an array of structure.
I can fix the second and third points. But they don't really matter for
using the rule.
The rule actually works for any structure type name that you specify. You
do that using the argument
-D ty=typename
The rule could easily be generalized to work on all types, but I expect
you don't want to bother with that. So you would run spatch as follows:
spatch --cocci-file file.cocci --dir linuxpath -D ty=typename
To speed things up a bit, I would suggest adding the arguments
--cache_prefix /tmp/coccicache --cache_limit 500
This will create a cache of parsed files. You probably want to run
Coccinelle in parallel as well, eg
http://article.gmane.org/gmane.comp.version-control.coccinelle/685/match=parallel
julia
@r@
field list[n] ds;
type T;
identifier i, virtual.ty;
@@
struct ty {
ds
T i;
...
};
@rr@
type T;
identifier i, virtual.ty;
@@
struct ty {
T i;
...
};
// --------------------------------------------------------------------
@init@
position p;
identifier i,nm, virtual.ty;
initializer a;
@@
struct ty nm@p = {
...,
.i = a,
...
};
@@
initializer list[r.n] is;
initializer a;
identifier nm;
identifier r.i, virtual.ty;
position p!=init.p;
@@
struct ty nm@p = {
is,
+ .i =
a,
...
};
@init1@
position p;
identifier i,nm, virtual.ty;
initializer a;
@@
struct ty nm@p = {
...,
.i = a,
...
};
@@
initializer a;
identifier nm;
identifier rr.i, virtual.ty;
position p!=init1.p;
@@
struct ty nm@p = {
+ .i =
a,
...
};
// --------------------------------------------------------------------
@initar@
position p;
identifier i,nm, virtual.ty;
initializer a;
@@
struct ty nm@p [...] = { ..., {
...,
.i = a,
...
}, ...};
@@
initializer list[r.n] is;
initializer a;
identifier nm;
identifier r.i, virtual.ty;
position p!=initar.p;
@@
struct ty nm@p[...] = { ..., {
is,
+ .i =
a,
...
}, ...};
@initar1@
position p;
identifier i,nm, virtual.ty;
initializer a;
@@
struct ty nm@p [...] = { ..., {
...,
.i = a,
...
}, ...};
@@
initializer a;
identifier nm;
identifier rr.i, virtual.ty;
position p!=initar1.p;
@@
struct ty nm@p[...] = { ..., {
+ .i =
a,
...
}, ...};
// --------------------------------------------------------------------
@initarn@
position p;
identifier i,nm, virtual.ty;
initializer a;
@@
struct ty nm@p [] = { ..., {
...,
.i = a,
...
}, ...};
@@
initializer list[r.n] is;
initializer a;
identifier nm;
identifier r.i, virtual.ty;
position p!=initarn.p;
@@
struct ty nm@p[] = { ..., {
is,
+ .i =
a,
...
}, ...};
@initarn1@
position p;
identifier i,nm, virtual.ty;
initializer a;
@@
struct ty nm@p [] = { ..., {
...,
.i = a,
...
}, ...};
@@
initializer a;
identifier nm;
identifier rr.i, virtual.ty;
position p!=initarn1.p;
@@
struct ty nm@p[] = { ..., {
+ .i =
a,
...
}, ...};
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)