From 01fe9f9f320dd4342664376f24eb1a0d004d03c8 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Thu, 10 Oct 2013 13:36:20 +0000 Subject: [PATCH] Correctly detect colon in bit fields. Fixes PR17333. Summary: Colon was incorrectly detected as a start of inheritance list. Fixed. Reviewers: djasper Reviewed By: djasper CC: cfe-commits, klimek Differential Revision: http://llvm-reviews.chandlerc.com/D1884 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192349 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/FormatToken.h | 1 + lib/Format/TokenAnnotator.cpp | 9 +++++---- unittests/Format/FormatTest.cpp | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Format/FormatToken.h b/lib/Format/FormatToken.h index c02ac6357a..2541c782ac 100644 --- a/lib/Format/FormatToken.h +++ b/lib/Format/FormatToken.h @@ -26,6 +26,7 @@ namespace format { enum TokenType { TT_BinaryOperator, + TT_BitFieldColon, TT_BlockComment, TT_CastRParen, TT_ConditionalExpr, diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 823235e602..87549895b1 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -328,13 +328,15 @@ private: Tok->Previous->Type = TT_ObjCSelectorName; if (Tok->Previous->ColumnWidth > Contexts.back().LongestObjCSelectorName) { - Contexts.back().LongestObjCSelectorName = - Tok->Previous->ColumnWidth; + Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth; } if (Contexts.back().FirstObjCSelectorName == NULL) Contexts.back().FirstObjCSelectorName = Tok->Previous; } else if (Contexts.back().ColonIsForRangeExpr) { Tok->Type = TT_RangeBasedForLoopColon; + } else if (CurrentToken != NULL && + CurrentToken->is(tok::numeric_constant)) { + Tok->Type = TT_BitFieldColon; } else if (Contexts.size() == 1 && Line.First->isNot(tok::kw_enum)) { Tok->Type = TT_InheritanceColon; } else if (Contexts.back().ContextKind == tok::l_paren) { @@ -1370,8 +1372,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, !Style.ConstructorInitializerAllOnOneLineOrOnePerLine) { return true; } else if (Right.Previous->BlockKind == BK_Block && - Right.Previous->isNot(tok::r_brace) && - Right.isNot(tok::r_brace)) { + Right.Previous->isNot(tok::r_brace) && Right.isNot(tok::r_brace)) { return true; } else if (Right.is(tok::l_brace) && (Right.BlockKind == BK_Block)) { return Style.BreakBeforeBraces == FormatStyle::BS_Allman; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 10d7413d42..c77616c96b 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1635,6 +1635,10 @@ TEST_F(FormatTest, FormatsBitfields) { " unsigned sClass : 8;\n" " unsigned ValueKind : 2;\n" "};"); + verifyFormat("struct A {\n" + " int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : 1,\n" + " bbbbbbbbbbbbbbbbbbbbbbbbb;\n" + "};"); } TEST_F(FormatTest, FormatsNamespaces) { -- 2.40.0