Of course I botched the rules too.
On 03/22/2012 11:59 PM, Michael Stefaniuc wrote:
> On 03/22/2012 11:29 PM, ron minnich wrote:
>> I have this code:
>> struct i2c_adapter {int i;};
>> struct intel_dp *x { struct i2c_adapter d;}
>>
>> I want to delete references to a no longer present field:
>>
>> @@
>> type T;
>> identifier f;
>> struct intel_dp *d;
>> struct i2c_adapter s;
>> expression E;
>> @@
>> T f(...)
>> {<...
>> -d->s.owner = E;
>> ...>}
>>
>> obviously I botched it :-)
>>
>> Fatal error: exception Failure("minus: parse error:
>> = File "spatches/intel_dp.c.cocci", line 318, column 4, charpos = 4023
>> around = 's', whole content = -d->s.owner = E;
>>
>> Any hints on how to do this?
> Do you need T or f? If not that can be reduced to just
> -d->s.owner = E;
>
> Which of course fails too. Because s is an "idexpression" aka a variable
> whereas in d->s s is a field name aka "identifier".
>
> The fix is to look at struct intel_dp and take the name of field ;)
>
> @@
> struct intel_dp *d;
> expression E;
> @@
> -d->adapter.owner = E;
>
> If you need a generic solution for all type of structs that embed struct
> i2c_adapter you need two rules(*), one that looks at the declaration of
> the embedding struct and reference the type and field name in the second
> rule. Something like this should do:
>
> @r@
> type T;
> identifier s;
> @@
> T {
> ...
> struct i2c_adapter s;
> ...
> }
^^^ I'm astonished it worked without the ';' and what the difference
is. Both forms match a
typedef struct _foo {
...
} foo;
And astonishing the form with the ";" actually even matches more than
the version without the ";":
typedef struct {
...
} foo;
> @@
> r.T *d;
> identifier r.s;
Forgot the expression E;
> @@
> -d->s.owner = E;
>
>
> (*) Iff you don't have deal with typedef struct. That requires quiet a
> few more rules; I still didn't find an efficient way to deal with all
> those permutations.
bye
michael
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)