r192349 - Correctly detect colon in bit fields. Fixes PR17333.
Alexander Kornienko
alexfh at google.com
Thu Oct 10 06:36:20 PDT 2013
Author: alexfh
Date: Thu Oct 10 08:36:20 2013
New Revision: 192349
URL: http://llvm.org/viewvc/llvm-project?rev=192349&view=rev
Log:
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
Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/FormatToken.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=192349&r1=192348&r2=192349&view=diff
==============================================================================
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Thu Oct 10 08:36:20 2013
@@ -26,6 +26,7 @@ namespace format {
enum TokenType {
TT_BinaryOperator,
+ TT_BitFieldColon,
TT_BlockComment,
TT_CastRParen,
TT_ConditionalExpr,
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=192349&r1=192348&r2=192349&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Oct 10 08:36:20 2013
@@ -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(con
!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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=192349&r1=192348&r2=192349&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Oct 10 08:36:20 2013
@@ -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) {
More information about the cfe-commits
mailing list