On 01.07.2010 11:25, Julia Lawall wrote:
> The command line argument -iso_file overwrites the default iso file. But
> if you use using "isofile.iso" at the top of the semantic patch file, then
> you should get both.
>
Like this?
# cat probe_param.cocci.7
using "array.iso"
@ rule1 @
struct flashchip chip;
identifier probe_func;
@@
chip.probe = probe_func;
@ rule2 @
identifier rule1.probe_func;
identifier flash;
typedef uint32_t;
@@
probe_func (
- struct flashchip *flash
+ struct flashchip *flash, uint32_t manufacture_id, uint32_t model_id
) {...}
The using statement is a no-op, at least for Coccinelle 0.2.2. I can
work around this by changing standard.iso. Please see the end of the
mail for details.
> On Thu, 1 Jul 2010, Carl-Daniel Hailfinger wrote:
>
>
>> 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.
>>
With a modified standard.iso (which adds my mkinit2 isomorphism), I get
the following effect: If the standard mkinit isomorphism is above
mkinit2, mkinit2 is ignored. If mkinit2 is above mkinit, mkinit is ignored.
Is there some limitation which causes the second isomorphism with the
same left-hand side to be ignored?
Next problem:
I merged the mkinit and mkinit2 isomorphism to get over the "ignore"
problem mentioned above, and changed the isomorphism to this:
E.fld = E1; => T I = { .fld = E1, }; => T I [] = { { .fld = E1, }, }; => T I []
= { { }, { .fld = E1, }, }; => T I [] = { { .fld = E1, }, { }, };
This works, but only for arrays with exactly 1 or 2 members. Any array
with 3 or more members is completely ignored. Is there a way to write an
isomorphism like the following, where ()* means zero or more occurrences
of the initializer in parentheses?
E.fld = E1; => T I = { .fld = E1, }; => T I [] = { ({ },)* { .fld = E1, }, ({
},)* };
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)