Hi,
I know this thread is old, but I never managed to get a solution for
this problem.
On 28.05.2009 13:20, Carl-Daniel Hailfinger wrote:
> Any ideas how to write an isomorphism which can match arrays of C99
> struct initializers?
>
I updated my testcase a bit to be more complete, and I managed to write
an isomorphism which works on a subset of arrays of C99 struct initializers.
# cat array.iso
// Match the first struct in an array of structs.
// Works if the array initializes only one member.
// Match also the second struct in an array of structs.
// Works if the array initializes two members, and the first member is default.
TopLevel
@ mkinit2 @
type T;
pure context T E;
identifier I;
identifier fld;
expression E1;
@@
E.fld = E1; => T I [] = { { .fld = E1, }, }; => T I [] = { { }, { .fld = E1, },
};
# cat c99initializer_testcase3.c
struct flashchip {
int (*probe) (struct flashchip *flash);
};
int probe_jedec1(struct flashchip *flash)
{
return 0;
}
int probe_jedec2(struct flashchip *flash)
{
return 0;
}
int probe_jedec3(struct flashchip *flash)
{
return 0;
}
int probe_jedec4(struct flashchip *flash)
{
return 0;
}
int probe_jedec5(struct flashchip *flash)
{
return 0;
}
int probe_jedec6(struct flashchip *flash)
{
return 0;
}
struct flashchip flashchip1 = {
.probe = probe_jedec1,
};
void bar()
{
struct flashchip flashchip2;
flashchip2.probe = probe_jedec2;
};
void baz()
{
struct flashchip flashchip3 = {
.probe = probe_jedec3,
};
};
struct flashchip flashchip_array1[] = {
{
.probe = probe_jedec4,
},
};
struct flashchip flashchip_array2[] = {
{
.probe = probe_jedec5,
},
{}
};
struct flashchip flashchip_array3[] = {
{},
{
.probe = probe_jedec6,
},
};
With the default isomorphism, probe_jedec1 and probe_jedec2 and
probe_jedec3 are converted.
With array.iso, probe_jedec2 and probe_jedec4 and probe_jedec6 are
converted. That happens because default.iso is not included anymore if I
tell Coccinelle to use array.iso.
Regards,
Carl-Daniel
--
http://www.hailfinger.org/
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)