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)