Matching partial expressions in macro arguments
Hi all,
In our testsuite[1] we have a macro to compare 2 integers with a given comparison operator, print them on assert failure to stderr for diagnotistics and then abort our testcase.
Usage is e.g.
igt_assert_cmpint(obj_count, ==, 0);
Now I want to add a simple igt_assert_eq(a, b) macro, so the above example should look like
igt_assert_eq(obj_count, 0);
I tried to use cocci for the refactoring, but failed. I tried
@@
expression E1, E2;
@@
-igt_assert_cmpint(E1, ==, E2);
+igt_assert_eq(E1, E2);
which failed to parse as a spatch and
@@
expression E1, E2, E;
@@
-igt_assert_cmpint(E1, E E2);
+igt_assert_eq(E1, E2);
which didn't match anything. I didn't find any examples for creative macro abuse and using iterator metavariables which helped last time around I've stumbled over macros didn't work out either.
Any ideas and suggestions highly welcome, or is this simply not possible with cocci?
Example testfile attached.
Thanks, Daniel
1: http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/ - it's for testing the intel gfx kernel driver.
Signature · 10 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch -------------- next part -------------- A non-text attachment was scrubbed... Name: prime_self_import.c Type: text/x-csrc Size: 10498 bytes Desc: not available URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20140613/e5686fe7/attachment.bin>
Quoted 31 lines · Daniel Vetter
Hi all,
In our testsuite[1] we have a macro to compare 2 integers with a given comparison operator, print them on assert failure to stderr for diagnotistics and then abort our testcase.
Usage is e.g.
igt_assert_cmpint(obj_count, ==, 0);Now I want to add a simple
igt_assert_eq(a, b)macro, so the above example should look likeigt_assert_eq(obj_count, 0);I tried to use cocci for the refactoring, but failed. I tried
@@
expression E1, E2;
@@(quoted diff) +1
-1-igt_assert_cmpint(E1, ==, E2); +igt_assert_eq(E1, E2);which failed to parse as a spatch and
@@
expression E1, E2, E;
@@(quoted diff) +1
-1-igt_assert_cmpint(E1, E E2); +igt_assert_eq(E1, E2);
Quoted 6 lines
which didn't match anything. I didn't find any examples for creative macro abuse and using iterator metavariables which helped last time around I've stumbled over macros didn't work out either.
Any ideas and suggestions highly welcome, or is this simply not possible with cocci?
I don't think it is going to be possible. == is not considered to be a valid argument by the C parser. You can make a macro definition for this, but then the C parser will just skip over the whole igt_assert_cmpint call. No matches will be possible on that part of the code.
julia
Quoted 11 lines
Example testfile attached.
Thanks, Daniel
1: http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/ - it's for testing the intel gfx kernel driver.
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 34 lines · Julia Lawall
Quoted 33 lines · Daniel Vetter
In our testsuite[1] we have a macro to compare 2 integers with a given comparison operator, print them on assert failure to stderr for diagnotistics and then abort our testcase.
Usage is e.g.
igt_assert_cmpint(obj_count, ==, 0);Now I want to add a simple
igt_assert_eq(a, b)macro, so the above example should look likeigt_assert_eq(obj_count, 0);I tried to use cocci for the refactoring, but failed. I tried
@@
expression E1, E2;
@@(quoted diff) +1
-1-igt_assert_cmpint(E1, ==, E2); +igt_assert_eq(E1, E2);which failed to parse as a spatch and
@@
expression E1, E2, E;
@@(quoted diff) +1
-1-igt_assert_cmpint(E1, E E2); +igt_assert_eq(E1, E2);which didn't match anything. I didn't find any examples for creative macro abuse and using iterator metavariables which helped last time around I've stumbled over macros didn't work out either.
Quoted 7 lines
Quoted 2 lines
Any ideas and suggestions highly welcome, or is this simply not possible with cocci?
I don't think it is going to be possible. == is not considered to be a valid argument by the C parser. You can make a macro definition for this, but then the C parser will just skip over the whole
igt_assert_cmpintcall. No matches will be possible on that part of the code.
Ah, I suspected as much. Thanks a lot for your confirmation anyway. -Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch