Manikishan updated this revision to Diff 203860.
Manikishan marked 4 inline comments as done.
Manikishan added a comment.
Updated unittest
Repository:
rC Clang
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63062/new/
https://reviews.llvm.org/D63062
Files:
docs/ClangFormatStyleOptions.rst
include/clang/Format/Format.h
lib/Format/ContinuationIndenter.cpp
lib/Format/Format.cpp
lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
" ddd);");
}
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+ FormatStyle Style = {};
+ Style.BitFieldDeclsOnSeparateLines = true;
+ verifyFormat(
+ "unsigned int baz : 11,
+ aaa : 2,
+ foo : 3"
+ );
+ Style.BitFieldDeclsOnSeparateLines = false;
+ verifyFormat(
+ "unsigned int baz : 11, aaa : 2, foo : 3"
+ );
+}
TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
verifyFormat(
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;
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/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,9 @@
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) && Current.Next->is(tok::colon))
+ return true;
if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
return false;
@@ -329,6 +332,9 @@
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) && Current.Next->is(tok::colon))
+ return true;
if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
return true;
if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +547,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: 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: docs/ClangFormatStyleOptions.rst
===================================================================
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -191,6 +191,18 @@
argument1, argument2);
+**BitFieldDeclsOnSeparateLines** (``bool``)
+ If ``true``, Align Bitfield Declarations on separate 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.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits