Hi all, On Fri, Aug 24, 2012 at 9:19 AM, Julia Lawall <[email protected]> wrote: > I think it is not possible. There is something you can do on such > declaration, but I will have to check later exactly what. > > I would suggest to replace the variable name with something that is easy to > find and then fix them by hand. If you have a lot of them, it will be a > nuisance, but at the moment there may be no other solution.
I attached some cocci file for the test case provided. They use
scripting facilities
either ocaml (complete but maybe no robust for a large case
application) or python (stub).
Julia/Arie, maybe providing Ast_c manipulation functions and access
to the Pretty_print_c would help a lot in such cases.
Note that the Ocaml script need further coding to preserve
initialization of variables.
Regards.
>
> julia
>
>
> On Fri, 24 Aug 2012, ivan ivanovich wrote:
>
>> Hello,
>> Thanks a lot, developers,for creation simple to use
>> but really powerful tool - coccinelle.
>>
>> Please, help me to solve a problem with deletion of unused variable's
>> declaration, when multiple variables are declared with one statement.
>> Here is simplified original code:
>>
>> int a, person_id, b;
>> char * buf[255];
>> person_id = getCurrentPersonId();
>> PersonNameById(person_id, buf, 255);
>>
>> After transformation the code should be:
>>
>> int a, b;
>> char * buf[255];
>> CurrentPersonName(buf, 255);
>>
>> I made a semantic patch:
>>
>> @f@
>> identifier id, buffer;
>> @@
>> - id = getCurrentPersonId();
>> - PersonNameById(id, buffer, 255);
>> + CurrentPersonName(buffer, 255);
>> @v depends on f@
>> identifier f.id;
>> type T;
>> @@
>> - T id;
>>
>> But it prints fatal error message:
>> "More than one variable in the declaration, and so
>> it cannot be transformed. Check that there is no transformation
>> on the type or the ;"
>> In standard.iso there are lines:
>> //
>> ---------------------------------------------------------------------------
>> // Declaration isomorphisms
>> //
>> ---------------------------------------------------------------------------
>> // They are handled in engine (TODO)
>>
>> // int i,j,k; <=> int i; int j; int k;
>>
>> I unsuccessfully tried to mix second rule with other identifiers:
>>
>> @v depends on f@
>> identifier f.id, i1, i2;
>> type T;
>> @@
>> - T i1, id, i2;
>> + T i1, i2;
>>
>> ( doesn't match )
>> , expressions:
>>
>> @v depends on f@
>> identifier f.id;
>> expression i1, i2;
>> type T;
>> @@
>> - T i1, id, i2;
>> + T i1, i2;
>>
>> ( Fatal error: exception Failure("minus: parse error ...") )
>> , declaration:
>>
>> @v depends on f@
>> identifier f.id;
>> declaration d;
>> type T;
>> @@
>> - d;
>>
>> ( removes all declarations )
>> , dots:
>>
>> @v depends on f@
>> identifier f.id;
>> type T;
>> @@
>> T ... when != id
>> - id
>>
>> ( Fatal error: exception Failure("minus: parse error ...") )
>>
>> Please advise me how to delete variable declaration from
>> multiple variables' declaration statement.
>> _______________________________________________
>> Cocci mailing list
>> [email protected]
>> http://lists.diku.dk/mailman/listinfo/cocci
>> (Web access from inside DIKUs LAN only)
>>
> _______________________________________________
> Cocci mailing list
> [email protected]
> http://lists.diku.dk/mailman/listinfo/cocci
> (Web access from inside DIKUs LAN only)
--
Nicolas Palix
http://www.palix.info/home.html
multidecl2.cocci
Description: Binary data
multidecl2-py.cocci
Description: Binary data
_______________________________________________ Cocci mailing list [email protected] http://lists.diku.dk/mailman/listinfo/cocci (Web access from inside DIKUs LAN only)
