On 08/03/2012 05:11 PM, Michael Stefaniuc wrote:
> Hello!
>
> On 08/03/2012 04:50 PM, Peter Senna Tschudin wrote:
>> There is a patch that removes a semicolon after a switch:
>> http://patchwork.linuxtv.org/patch/12987/
>>
>> It can be described as:
>>
>> @@
>> @@
>> switch (...) { }
>> -;
>>
>> There are 230 hits of this on recent Kernel. But I was wondering that
>> every semicolon after curly braces may be style error. So I'm thinking
>> on a semantic patch for removing semicolon after curly braces. The
>> semantic patch:
>>
>> @@
>> statement S;
>> @@
>> S
>> -;
>>
>> works but there are many false positives for empty statements like:
>> for (...)
>> ; /* <-- I do not want to remove this */
> It's a matter of taste, you could replace it with the empty block {}.
>
>> How can I avoid empty statements ending on ';'? Any ideas?
>>
>> My first attempt, that do not work, was:
>> @@
>> @@
>> {
>> - };
>> + }
>
> @@ @@
> {...}
> - ;
>
> Legal SmPL but it seems to kill in Wine also ";" after macro calls:
> - expect_eq(r.bottom - r.top, height + 8, int, "%d");
> + expect_eq(r.bottom - r.top, height + 8, int, "%d")
This one is a bit tricky, but it takes care of the case where cocci can't
parse the statement inform of the semicolon.
@r1@
statement S;
position p;
@@
S
;@p
@script:python r2@
p << r1.p;
@@
import re
f = open(p[0].file)
lines = f.readlines()
line = lines[int(p[0].line)-1]
if not re.search('}[ \t]*;', line):
cocci.include_match(False)
@depends on r2@
position r1.p;
@@
-;@p
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)