Skip to contentSkip to conversation

GNU-style function calls

cocci Arsen Arsenović 2 participants 3 messages Jul 6

lore
Share & tools
lore
#0 lore raw

Hi!

I work on GCC, meaning we use GNU-style function calls, where the call operator is preceded by a whitespace, like so:

  foo (a, b);

I've had decent luck with applying Cocci to the codebase, but if Cocci rewrites a call, it removes the whitespace preceding the call operator:

  /tmp$ cat test.cc
  void
  thing ()
  {
    foo (a, b);
  }
  /tmp$ cat test.cocci
  @@
  expression x, y;
  @@

- foo (x, y);
+ foo (y, x);
/tmp$ spatch --sp-file test.cocci --c++=14 test.cc
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: test.cc
diff =
--- test.cc
+++ /tmp/cocci-output-157607-636042-test.cc @@ -1,5 +1,5 @@
void
thing ()
{
- foo (a, b);
+ foo(b, a);
}
/tmp$

This isn't too much of a problem; I go back and modify the function calls manually, but it would be nice if Cocci handled it.

Is it possible to keep the spaces in line with the code style w/ Cocci?

Thanks in advance! Have a lovely day.

Signature · 1 line
Arsen Arsenović
#1 lore raw

There is a —simple-spacing argument where it should preserve the spacing you put in the semantic patch. Sent from my iPhone

Quoted 49 lines · Arsen Arsenović

Hi!

I work on GCC, meaning we use GNU-style function calls, where the call operator is preceded by a whitespace, like so:

foo (a, b);

I've had decent luck with applying Cocci to the codebase, but if Cocci rewrites a call, it removes the whitespace preceding the call operator:

/tmp$ cat test.cc
void
thing ()

 {
   foo (a, b);

}
/tmp$ cat test.cocci
@@
expression x, y;
@@

- foo (x, y);
+ foo (y, x);
/tmp$ spatch --sp-file test.cocci --c++=14 test.cc
init_defs_builtins: /usr/lib64/coccinelle/standard.h
HANDLING: test.cc
diff =
--- test.cc
+++ /tmp/cocci-output-157607-636042-test.cc @@ -1,5 +1,5 @@
void
thing ()
{
- foo (a, b);
+ foo(b, a);
}
/tmp$

This isn't too much of a problem; I go back and modify the function calls manually, but it would be nice if Cocci handled it.

Is it possible to keep the spaces in line with the code style w/ Cocci?

Thanks in advance! Have a lovely day.
--
Arsen Arsenović
<signature.asc>

#2 lore raw

Hi Julia!

Quoted 1 line · Julia Lawall

There is a —simple-spacing argument where it should preserve the spacing you put in the semantic patch.

Ah, yes, indeed, that works perfectly!

Thank you! Cocci is awesome :-)

Have a lovely evening.

Signature · 1 line
Arsen Arsenović