Previous Up

12  Tips and Tricks

12.1  How to remove useless parentheses?

If you want to rewrite any access to a pointer value by a function call, you may use the following semantic patch.

1 - a = *b 2 + a = readb(b)

However, if for some reason your code looks like bar = *(foo), you will end up with bar = readb((foo)) as the extra parentheses around foo are capture by the metavariable b.

In order to generate better output code, you can use the following semantic patch instead.

1 - a = *(b) 2 + a = readb(b)

And rely on your standard.iso isomorphism file which should contain:

1 Expression 2 @ paren @ 3 expression E; 4 @@ 5 6 (E) => E

Coccinelle will then consider bar = *(foo) as equivalent to bar = *foo (but not the other way around) and capture both. Finally, it will generate bar = readb(foo) as expected.


Previous Up