On Sun, 2020-08-30 at 17:46 +0200, Julia Lawall wrote:
> [...]
> 
> > Thanks, I used the slightly different from your suggestion
> > where sysfs is an identifier with function args and a
> > semicolon after the transform type, (otherwise I get cocci errors).
> > like this below:
> > 
> > But it doesn't work (no renaming) when there is an
> > initializer to the variable to be transformed.
> > 
> > ie:
> > {
> >     ssize_t count = 0;
> >     ...
> >     count += sysfs_emit_at(buf, count, ...);
> >     ...
> >     return count;
> > }
> > 
> > I tried adding =0 in various places without success.
> > 
> > Suggestions?
> > 
> > ------------------
> > 
> > // Rename the sysfs_emit assigned variables not named len and not already 
> > int
> > // and set the name to len and type to int
> > 
> > @not_int_not_len exists@
> > type T != int;
> > identifier x != len;
> > position p;
> > identifier sysfs =~ "^sysfs_emit.*$";
> > assignment operator aop;
> > @@
> > 
> > T x@p;
> > ...
> > x aop sysfs(...)
> > ...
> > 
> > @@
> > type not_int_not_len.T;
> > identifier not_int_not_len.x;
> > position not_int_not_len.p;
> > @@
> > 
> > - T x@p;
> > + int len;
> >   <...
> > - x
> > + len
> >   ...>
> > 
> > ------------------
> 
> The following:
> 
> @not_int_not_len exists@
> type T != int;
> identifier x != len;
> position p;
> identifier sysfs =~ "^sysfs_emit.*$";
> assignment operator aop;
> @@
> 
> T@p x;
> ...
> x aop sysfs(...)
> 
> @@
> type not_int_not_len.T;
> identifier not_int_not_len.x;
> position not_int_not_len.p;
> @@
> 
> (
> - T@p x;
> + int len;
> - T@p x
> + int len
>  = ...;
> )
>   <...
> - x
> + len
>   ...>
> 
> works on the following test file:
> 
> int fn1()
> {
>         ssize_t count = 0;
>         count += sysfs_emit_at(buf, count, ...);
>         return count;
> }
> 
> int fn2()
> {
>         ssize_t count;
>         count += sysfs_emit_at(buf, count, ...);
>       return count;
> }
> 
> In the first rule, T@p x; benefits from an isomorphism to get the
> initialization case.  That is not possible in the second rule, because the
> name of the declared variable is modified.
> 
> I wonder why you use a regular expression for the sysfs identifier.  I
> thought that there were only two choices?  You will get better performance
> if you make those two choices explicit in the rule, with \( \| \).

Just because I'm accustomed to regex.  I'll change it,
Thanks for all the comments and corrections.

cheers, Joe


_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to