[Cocci] Source code clean-up for parentheses?
SF Markus Elfring
elfring at users.sourceforge.net
Sun Dec 21 14:44:40 CET 2014
> Given that coccinelle understands c structure, and knows about common isomorphisms,
> is there an easy way so that I can instruct it to analyze every expression in
> my source code, and remove parentheses at every place they’re not needed?
There are various preconditions to consider.
> By not needed, I mean that the c expression meaning (taking into account operator
> precedence and the like) is the same with and without parentheses.
Software developers and source code reviewers can have strong opinions about the
placement for their parentheses.
Coding style specifications often recommend a code structure for reasonable
readability and not what compilation software can handle in principle.
> I’m working with a 200000 LOC codebase. So, if there’s no dependable way to do this
> (without false positives and the like), then I’d have to manually review every change.
Which error rate can you tolerate for your source code analysis and
eventually automatic transformations?
Do you get further ideas from the section "4.2.1 How to remove useless parentheses?"
in Coccinelle's manual?
> Feasibility of that depends on how many instances are found, which I cannot now
> in advance. If they are too many and I have to review them manually,
> then this is probably not worth the trouble.
Do efforts naturally evolve with the desire to come closer to a kind of perfection?
More information about the Cocci