All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Replacing function definition with a macro
@ 2015-08-04  8:15 Petr Malát
  2015-08-04  8:31 ` Julia Lawall
  0 siblings, 1 reply; 5+ messages in thread
From: Petr Malát @ 2015-08-04  8:15 UTC (permalink / raw)
  To: cocci

Hi All,
I'm trying to replace a function prototype in the definition with a
macro. The reason is to generate stubs to do some argument mangling.
The following is my cocci file:

@@
type T1;
identifier i1, name;
@@
- long name(T1 i1) {
+ COMPAT_SYSCALL_DEFINE1(name, T1, i1) {
  ...
  }

And the following is my testing code:

#define __SC_DECL1(t1, a1) t1 a1
#define COMPAT_SYSCALL_DEFINE1(name, ...) \
                long compat_sys_##name(__SC_DECL1(__VA_ARGS__))
long test(int first) {
        return 0;
}


And I expect spatch to replace
  long test(int first) {
with
  COMPAT_SYSCALL_DEFINE1(test, int, first) {
but when I try to run it, I get
  init_defs_builtins: /usr/local/lib/coccinelle/standard.h
  82 86
  Fatal error: exception Failure("plus: parse error:
   = File "test.cocci", line 6, column 25,  charpos = 82
      around = 'name', whole content = + COMPAT_SYSCALL_DEFINE1(name, T1, i1) {
  ")
Any idea what am I doing wrong?

Thanks,
  Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Replacing function definition with a macro
  2015-08-04  8:15 [Cocci] Replacing function definition with a macro Petr Malát
@ 2015-08-04  8:31 ` Julia Lawall
  2015-08-04 11:05   ` Petr Malát
  2015-08-04 17:09   ` SF Markus Elfring
  0 siblings, 2 replies; 5+ messages in thread
From: Julia Lawall @ 2015-08-04  8:31 UTC (permalink / raw)
  To: cocci



On Tue, 4 Aug 2015, Petr Mal?t wrote:

> Hi All,
> I'm trying to replace a function prototype in the definition with a
> macro. The reason is to generate stubs to do some argument mangling.
> The following is my cocci file:
>
> @@
> type T1;
> identifier i1, name;
> @@
> - long name(T1 i1) {
> + COMPAT_SYSCALL_DEFINE1(name, T1, i1) {
>   ...
>   }
>
> And the following is my testing code:
>
> #define __SC_DECL1(t1, a1) t1 a1
> #define COMPAT_SYSCALL_DEFINE1(name, ...) \
>                 long compat_sys_##name(__SC_DECL1(__VA_ARGS__))
> long test(int first) {
>         return 0;
> }
>
>
> And I expect spatch to replace
>   long test(int first) {
> with
>   COMPAT_SYSCALL_DEFINE1(test, int, first) {
> but when I try to run it, I get
>   init_defs_builtins: /usr/local/lib/coccinelle/standard.h
>   82 86
>   Fatal error: exception Failure("plus: parse error:
>    = File "test.cocci", line 6, column 25,  charpos = 82
>       around = 'name', whole content = + COMPAT_SYSCALL_DEFINE1(name, T1, i1) {
>   ")
> Any idea what am I doing wrong?

Coccinelle expects that each element in a parameter list will have the
form type identifier.  In the case of name, you just have an identifier.
I don't really see a solution.

julia

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Replacing function definition with a macro
  2015-08-04  8:31 ` Julia Lawall
@ 2015-08-04 11:05   ` Petr Malát
  2015-08-04 11:29     ` Julia Lawall
  2015-08-04 17:09   ` SF Markus Elfring
  1 sibling, 1 reply; 5+ messages in thread
From: Petr Malát @ 2015-08-04 11:05 UTC (permalink / raw)
  To: cocci

Hi Julia,
thanks for the answer
> Coccinelle expects that each element in a parameter list will have the
> form type identifier.  In the case of name, you just have an identifier.
> I don't really see a solution.
I though similar operations are generally possible, if all required macros
are known. Anyway, I've worked it around by using something like

@@
type T1;
identifier i1, name;
typedef DELME;
@@
- long name(T1 i1) {
+ COMPAT_SYSCALL_DEFINE1(DELME name, T1 DELME_TOO, DELME i1) {
  ...
  }

and then fixing the generated patch with sed.

Cheers,
  Petr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Replacing function definition with a macro
  2015-08-04 11:05   ` Petr Malát
@ 2015-08-04 11:29     ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2015-08-04 11:29 UTC (permalink / raw)
  To: cocci

On Tue, 4 Aug 2015, Petr Mal?t wrote:

> Hi Julia,
> thanks for the answer
> > Coccinelle expects that each element in a parameter list will have the
> > form type identifier.  In the case of name, you just have an identifier.
> > I don't really see a solution.
> I though similar operations are generally possible, if all required macros
> are known.

No.  Macros are somewhat taken into account when parsing the C code.  But
here you are talking about the SmPL (pattern) code, which is different.

> Anyway, I've worked it around by using something like
>
> @@
> type T1;
> identifier i1, name;
> typedef DELME;
> @@
> - long name(T1 i1) {
> + COMPAT_SYSCALL_DEFINE1(DELME name, T1 DELME_TOO, DELME i1) {
>   ...
>   }
>
> and then fixing the generated patch with sed.

Yeah, not ideal, but perhaps easier than making all the changes by hand.

julia

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Cocci] Replacing function definition with a macro
  2015-08-04  8:31 ` Julia Lawall
  2015-08-04 11:05   ` Petr Malát
@ 2015-08-04 17:09   ` SF Markus Elfring
  1 sibling, 0 replies; 5+ messages in thread
From: SF Markus Elfring @ 2015-08-04 17:09 UTC (permalink / raw)
  To: cocci

> Coccinelle expects that each element in a parameter list will have the
> form type identifier.

Is the Coccinelle software still limited to some degree for the handling
of function parameters?


> In the case of name, you just have an identifier.
> I don't really see a solution.

How do you think about direct support for macro parameter lists?
Does anybody dare to contribute corresponding software development efforts?

Are there any more limitations to reconsider so that further post-processing
can be avoided for generated patches?

Regards,
Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-08-04 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-04  8:15 [Cocci] Replacing function definition with a macro Petr Malát
2015-08-04  8:31 ` Julia Lawall
2015-08-04 11:05   ` Petr Malát
2015-08-04 11:29     ` Julia Lawall
2015-08-04 17:09   ` SF Markus Elfring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.