Index: docs/ClangFormatStyleOptions.rst =================================================================== --- docs/ClangFormatStyleOptions.rst +++ docs/ClangFormatStyleOptions.rst @@ -191,6 +191,18 @@ argument1, argument2); +**BitFieldDeclsOnSeparateLines** (``bool``) + If ``true``, Align Bitfield Declarations on seperate lines. + + This will align Bitfield declarations on consecutive lines. This + will result in formatting like: + + .. code-block:: c++ + + unsigned int baz : 1, + fuz : 5, + zap : 2; + **AlignConsecutiveAssignments** (``bool``) If ``true``, aligns consecutive assignments. Index: include/clang/Format/Format.h =================================================================== --- include/clang/Format/Format.h +++ include/clang/Format/Format.h @@ -101,6 +101,16 @@ /// \endcode bool AlignConsecutiveDeclarations; + /// If ``true``, Linesup Bitfield Declarations. + /// This will lineup Bitfield declarations on consecutive lines. This + /// will result in formatting like + /// \code + /// unsigned int baz : 1, /* Bitfield; line up entries if desire*/ + /// fuz : 5, + /// zap : 2; + /// \endcode + bool BitFieldDeclsOnSeparateLines; + /// Different styles for aligning escaped newlines. enum EscapedNewlineAlignmentStyle { /// Don't align escaped newlines. @@ -1950,6 +1960,7 @@ JavaScriptWrapImports == R.JavaScriptWrapImports && KeepEmptyLinesAtTheStartOfBlocks == R.KeepEmptyLinesAtTheStartOfBlocks && + BitFieldDeclsOnSeparateLines == R.BitFieldDeclsOnSeparateLines && MacroBlockBegin == R.MacroBlockBegin && MacroBlockEnd == R.MacroBlockEnd && MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep && Index: lib/Format/ContinuationIndenter.cpp =================================================================== --- lib/Format/ContinuationIndenter.cpp +++ lib/Format/ContinuationIndenter.cpp @@ -278,6 +278,10 @@ const FormatToken &Current = *State.NextToken; const FormatToken &Previous = *Current.Previous; assert(&Previous == Current.Previous); + if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){ + if(Current.Next->is(tok::colon)) + return true; + } if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace && Current.closesBlockOrBlockTypeList(Style))) return false; @@ -329,6 +333,11 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { const FormatToken &Current = *State.NextToken; const FormatToken &Previous = *Current.Previous; + if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){ + if(Current.Next->is(tok::colon)){ + return true; + } + } if (Current.MustBreakBefore || Current.is(TT_InlineASMColon)) return true; if (State.Stack.back().BreakBeforeClosingBrace && @@ -541,7 +550,7 @@ unsigned ExtraSpaces) { FormatToken &Current = *State.NextToken; const FormatToken &Previous = *State.NextToken->Previous; - if (Current.is(tok::equal) && + if (Current.isOneOf(tok::equal, tok::colon) && (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) && State.Stack.back().VariablePos == 0) { State.Stack.back().VariablePos = State.Column; Index: lib/Format/Format.cpp =================================================================== --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -451,6 +451,7 @@ IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports); IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks", Style.KeepEmptyLinesAtTheStartOfBlocks); + IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines); IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin); IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd); IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep); Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -2916,6 +2916,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right) { const FormatToken &Left = *Right.Previous; + if (Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && + Right.is(tok::identifier) && (Right.Next->is(tok::colon))) + return true; if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0) return true;