All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Problems with adding code after macro definitions
@ 2017-03-22 14:28 sebald.ziegler.cocci at ikolus.de
  2017-03-22 14:46 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: sebald.ziegler.cocci at ikolus.de @ 2017-03-22 14:28 UTC (permalink / raw)
  To: cocci

Hi,

I try to use coccinelle for some kind of Macro instrumentation.
One important step is to define a wrapper for a macro after the original macro definition.
This is attempted in the rule: macro_wrapper_int_MAX_int_int
But I cannot get it to work - see the ???.
All other rules work as intended.

So the question is: What is the right way to specify the macro definition after which something should be added?
Is it at all possible to only use the name of the macro and some wildcard (as opposed to using macro name and its definition).

@script:python macros@
macro_wrapper_int_MAX_int_int_str;
@@
coccinelle.macro_wrapper_int_MAX_int_int_str = '({printf("MAX\\n"); MAX(p0, p1); })'

@macro_wrapper_int_MAX_int_int@
identifier macros.macro_wrapper_int_MAX_int_int_str;
@@
#define MAX(x,y) ???
+#define macro_wrapper_int_MAX_int_int(p0, p1) macro_wrapper_int_MAX_int_int_str

@macro_replacer_macro_wrapper_int_MAX_int_int@
int P0;
int P1;
@@
-MAX(P0, P1)
+macro_wrapper_int_MAX_int_int(P0, P1)

C program:
$ cat test.c
#define MAX(x,y) ((x>y)?x:y)
#include <stdio.h>
int main(int argc, char** argv) {
        int a=5;
        int b=7;
        int d=MAX(a,b+4);
        return d;
}

Any hints and information is greatly appreciated!

Thanks,
Sebald

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

* [Cocci] Problems with adding code after macro definitions
  2017-03-22 14:28 [Cocci] Problems with adding code after macro definitions sebald.ziegler.cocci at ikolus.de
@ 2017-03-22 14:46 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2017-03-22 14:46 UTC (permalink / raw)
  To: cocci



On Wed, 22 Mar 2017, sebald.ziegler.cocci at ikolus.de wrote:

> Hi,
>
> I try to use coccinelle for some kind of Macro instrumentation.
> One important step is to define a wrapper for a macro after the original macro definition.
> This is attempted in the rule: macro_wrapper_int_MAX_int_int
> But I cannot get it to work - see the ???.
> All other rules work as intended.
>
> So the question is: What is the right way to specify the macro definition after which something should be added?
> Is it at all possible to only use the name of the macro and some wildcard (as opposed to using macro name and its definition).
>
> @script:python macros@
> macro_wrapper_int_MAX_int_int_str;
> @@
> coccinelle.macro_wrapper_int_MAX_int_int_str = '({printf("MAX\\n"); MAX(p0, p1); })'
>
> @macro_wrapper_int_MAX_int_int@
> identifier macros.macro_wrapper_int_MAX_int_int_str;
> @@
> #define MAX(x,y) ???
> +#define macro_wrapper_int_MAX_int_int(p0, p1) macro_wrapper_int_MAX_int_int_str

It looks like the body of the macro will be an expression.  So just add
expression e; in the metavariable list, and replace ??? by e.

You can also match macros where the body is a statement.  Unfortunately
macro definitions can be any random thing in general, and I don't think
that would be supported.  At the very least, parsing the macro definition
would fail, so it would not be possible to match against it.

julia

>
> @macro_replacer_macro_wrapper_int_MAX_int_int@
> int P0;
> int P1;
> @@
> -MAX(P0, P1)
> +macro_wrapper_int_MAX_int_int(P0, P1)
>
> C program:
> $ cat test.c
> #define MAX(x,y) ((x>y)?x:y)
> #include <stdio.h>
> int main(int argc, char** argv) {
>         int a=5;
>         int b=7;
>         int d=MAX(a,b+4);
>         return d;
> }
>
> Any hints and information is greatly appreciated!
>
> Thanks,
> Sebald
>
>
> _______________________________________________
> Cocci mailing list
> Cocci at systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

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

end of thread, other threads:[~2017-03-22 14:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-22 14:28 [Cocci] Problems with adding code after macro definitions sebald.ziegler.cocci at ikolus.de
2017-03-22 14:46 ` Julia Lawall

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.