[cfe-dev] clang-format and BSD KNF
David Watson
dwatson at arbor.net
Sun Jun 8 11:29:53 PDT 2014
I’m trying to get clang-format to conform to a style which is roughly equivalent to the BSD Kernel Normal Form. In particular, I want a break after the function return type for function definitions, but not for function prototypes. For example:
int foo(int i);
int
foo(int i)
{
…
}
I’m having trouble distinguishing between function prototypes and definitions. It looks like Line.StartsDefinition is the correct key to distinguish between the two cases, however where that annotation ends up is different depending on the value of BreakBeforeBraces. When BreakBeforeBraces = Attach, the Line in question is the one starting with the return type. This works perfectly for inserting the break in TokenAnnotator::mustBreakBefore. When BreakBeforeBraces = Stroustrup, the StartsDefinition annotation gets attached to a Line starting with the first curly brace, not the line starting with the return type. In this case, I can’t find any reliable way to distinguish between a function prototype and a function definition in mustBreakBefore.
Any hints on the right way to approach this? I have to admit that I’m very confused about the high level architecture of the Format library, so it’s entirely possible I’m missing something really obvious.
Thanks in advance,
David
More information about the cfe-dev
mailing list