On Sun, 30 Aug 2020, Joe Perches wrote:

> On Sun, 2020-08-30 at 08:57 +0200, Julia Lawall wrote:
> >
> > On Sat, 29 Aug 2020, Joe Perches wrote:
> >
> > > Is it me not understanding cocci grammar again?
> >
> > The problem is the loop.  You are trying to change something in the body
> > of a loop and the body of a for loop might not be executed.  ... means
> > that the thing must be found on every execution path.
> >
> > Do you want to make the change in the function header even if there are
> > not changes in the body?  If so, <... ...> is what you are looking for.
> > If you want to be sure there is a change to make in the function body then
> > you can use <+... ...+> but it will be more expensive.
>
> Thanks.  <... works (and I thought I had tried that, oh well)
>
> Another thing I'd like to do is to change the various uses
> of a type and identifier to a specific type and identifier.
>
> In this sysfs_emit transform I've been working on, there
> are many variable names used in the assignment of the
> sysfs_emit result.
>
> $ git grep -P -oh '\w+\s*\+?=\s*sysfs_emit' | \
>   sort | uniq -c | sort -rn
>     145 ret = sysfs_emit
>      80 len = sysfs_emit
>      74 len += sysfs_emit
>      69 rc = sysfs_emit
>      50 count = sysfs_emit
>      25 count += sysfs_emit
>      19 size = sysfs_emit
>      17 n += sysfs_emit
>      15 n = sysfs_emit
>      14 status = sysfs_emit
>      12 ret += sysfs_emit
>      12 output_len += sysfs_emit
>      11 retval = sysfs_emit
>       9 res += sysfs_emit
>       7 rv = sysfs_emit
>       7 offset += sysfs_emit
>       7 l = sysfs_emit
>       6 i = sysfs_emit
>       5 size += sysfs_emit
>       5 err = sysfs_emit
>       4 written = sysfs_emit
>       4 l += sysfs_emit
>       3 written += sysfs_emit
>       2 rz = sysfs_emit
>       2 r = sysfs_emit
>       2 result = sysfs_emit
>       2 res = sysfs_emit
>       2 i += sysfs_emit
>       2 idx += sysfs_emit
>       2 error = sysfs_emit
>       2 cnt += sysfs_emit
>       2 buf_len += sysfs_emit
>       1 offset = sysfs_emit
>       1 length = sysfs_emit
>       1 cnt = sysfs_emit
>       1 bytes = sysfs_emit
>       1 bytes += sysfs_emit
>
> Most are declared int, some are ssize_t.
>
> I'd like to change them all to int len.

@r exists@
type T != int;
identifier x != len;
position p;
assignment operator aop;
@@

T x@p;
...
x aop sysfs_emit

@@
type r.T;
identifier r.x;
position r.p;
@@

- T x@p;
+ int len
  <...
- x
+ len
  ...>

This only works for the case where the type is not int and the name is not
len.  You would need other similar pairs of rules for the case where the
type is int and the variable is something else and where the type is len
and the variable is len.

Or you could get rid of the constraints and hope that replacing int by int
and len by len won't have any impact on the layout of the code.

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

Reply via email to