1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-07 20:06:10 +02:00

coccinelle: remove parentheses that become unnecessary

Transformations that hide multiplications can end up with an pair of
parentheses that is no longer needed.  E.g. with a rule like this:

  @@
  expression E;
  @@
  - E * 2
  + double(E)

... we might get a patch like this:

  -	x = (a + b) * 2;
  +	x = double((a + b));

Add a pair of parentheses to the preimage side of such rules.
Coccinelle will generate patches that remove them if they are present,
and it will still match expressions that lack them.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe 2017-10-01 17:12:08 +02:00 committed by Junio C Hamano
parent 4010f1d1b7
commit 9ca356fa8b

View File

@ -4,7 +4,7 @@ T *dst;
T *src;
expression n;
@@
- memcpy(dst, src, n * sizeof(*dst));
- memcpy(dst, src, (n) * sizeof(*dst));
+ COPY_ARRAY(dst, src, n);
@@
@ -13,7 +13,7 @@ T *dst;
T *src;
expression n;
@@
- memcpy(dst, src, n * sizeof(*src));
- memcpy(dst, src, (n) * sizeof(*src));
+ COPY_ARRAY(dst, src, n);
@@
@ -22,7 +22,7 @@ T *dst;
T *src;
expression n;
@@
- memcpy(dst, src, n * sizeof(T));
- memcpy(dst, src, (n) * sizeof(T));
+ COPY_ARRAY(dst, src, n);
@@
@ -47,7 +47,7 @@ type T;
T *ptr;
expression n;
@@
- ptr = xmalloc(n * sizeof(*ptr));
- ptr = xmalloc((n) * sizeof(*ptr));
+ ALLOC_ARRAY(ptr, n);
@@
@ -55,5 +55,5 @@ type T;
T *ptr;
expression n;
@@
- ptr = xmalloc(n * sizeof(T));
- ptr = xmalloc((n) * sizeof(T));
+ ALLOC_ARRAY(ptr, n);