[PATCH] D61222: [clang-format] Fix a bug in AlignConsecutiveDeclarations
This revision was automatically updated to reflect the committed changes. Closed by commit rL359711: [clang-format] Fix a bug in AlignConsecutiveDeclarations. (authored by owenpan, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D61222?vs=197566=197600#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61222/new/ https://reviews.llvm.org/D61222 Files: cfe/trunk/lib/Format/WhitespaceManager.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/WhitespaceManager.cpp === --- cfe/trunk/lib/Format/WhitespaceManager.cpp +++ cfe/trunk/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ [](Change const ) { // tok::kw_operator is necessary for aligning operator overload // definitions. -return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); +if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; +if (C.Tok->isNot(TT_StartOfName)) + return false; +// Check if there is a subsequent name that starts the same declaration. +for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) +continue; + if (!Next->Tok.getIdentifierInfo()) +break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, +tok::kw_operator)) +return false; +} +return true; }, Changes, /*StartAt=*/0); } Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -10581,6 +10581,13 @@ " unsigned c;\n" "}", Alignment); + + // See PR37175 + FormatStyle Style = getMozillaStyle(); + Style.AlignConsecutiveDeclarations = true; + EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" +"foo(int a);", +format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style)); } TEST_F(FormatTest, LinuxBraceBreaking) { Index: cfe/trunk/lib/Format/WhitespaceManager.cpp === --- cfe/trunk/lib/Format/WhitespaceManager.cpp +++ cfe/trunk/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ [](Change const ) { // tok::kw_operator is necessary for aligning operator overload // definitions. -return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); +if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; +if (C.Tok->isNot(TT_StartOfName)) + return false; +// Check if there is a subsequent name that starts the same declaration. +for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) +continue; + if (!Next->Tok.getIdentifierInfo()) +break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, +tok::kw_operator)) +return false; +} +return true; }, Changes, /*StartAt=*/0); } Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -10581,6 +10581,13 @@ " unsigned c;\n" "}", Alignment); + + // See PR37175 + FormatStyle Style = getMozillaStyle(); + Style.AlignConsecutiveDeclarations = true; + EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" +"foo(int a);", +format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style)); } TEST_F(FormatTest, LinuxBraceBreaking) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61222: [clang-format] Fix a bug in AlignConsecutiveDeclarations
owenpan updated this revision to Diff 197566. owenpan added a comment. Removed a redundant test case. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61222/new/ https://reviews.llvm.org/D61222 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10575,6 +10575,13 @@ " unsigned c;\n" "}", Alignment); + + // See PR37175 + FormatStyle Style = getMozillaStyle(); + Style.AlignConsecutiveDeclarations = true; + EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" +"foo(int a);", +format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style)); } TEST_F(FormatTest, LinuxBraceBreaking) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ [](Change const ) { // tok::kw_operator is necessary for aligning operator overload // definitions. -return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); +if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; +if (C.Tok->isNot(TT_StartOfName)) + return false; +// Check if there is a subsequent name that starts the same declaration. +for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) +continue; + if (!Next->Tok.getIdentifierInfo()) +break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, +tok::kw_operator)) +return false; +} +return true; }, Changes, /*StartAt=*/0); } Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10575,6 +10575,13 @@ " unsigned c;\n" "}", Alignment); + + // See PR37175 + FormatStyle Style = getMozillaStyle(); + Style.AlignConsecutiveDeclarations = true; + EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" +"foo(int a);", +format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ foo (int a);", Style)); } TEST_F(FormatTest, LinuxBraceBreaking) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ [](Change const ) { // tok::kw_operator is necessary for aligning operator overload // definitions. -return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); +if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; +if (C.Tok->isNot(TT_StartOfName)) + return false; +// Check if there is a subsequent name that starts the same declaration. +for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) +continue; + if (!Next->Tok.getIdentifierInfo()) +break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, +tok::kw_operator)) +return false; +} +return true; }, Changes, /*StartAt=*/0); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61222: [clang-format] Fix a bug in AlignConsecutiveDeclarations
MyDeveloperDay accepted this revision. MyDeveloperDay added a comment. This revision is now accepted and ready to land. LGTM Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61222/new/ https://reviews.llvm.org/D61222 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D61222: [clang-format] Fix a bug in AlignConsecutiveDeclarations
owenpan updated this revision to Diff 196994. owenpan retitled this revision from "[clang-format] Fix bug in determineTokenType() for TT_StartOfName" to "[clang-format] Fix a bug in AlignConsecutiveDeclarations". owenpan added a comment. This revision is now accepted and ready to land. Fix it in `WhitespaceManager::alignConsecutiveDeclarations()` instead. Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D61222/new/ https://reviews.llvm.org/D61222 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10575,6 +10575,16 @@ " unsigned c;\n" "}", Alignment); + + // See PR37175 + FormatStyle Style = getMozillaStyle(); + Style.AlignConsecutiveDeclarations = true; + EXPECT_EQ("DECOR1 /**/ DECOR2 /**/ int8_t /**/\n" +"foo(int a);", +format("DECOR1 /**/ DECOR2 /**/ int8_t /**/ foo (int a);", Style)); + EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" +"bar(int a);", +format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ bar (int a);", Style)); } TEST_F(FormatTest, LinuxBraceBreaking) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ [](Change const ) { // tok::kw_operator is necessary for aligning operator overload // definitions. -return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); +if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; +if (C.Tok->isNot(TT_StartOfName)) + return false; +// Check if there is a subsequent name that starts the same declaration. +for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) +continue; + if (!Next->Tok.getIdentifierInfo()) +break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, +tok::kw_operator)) +return false; +} +return true; }, Changes, /*StartAt=*/0); } Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10575,6 +10575,16 @@ " unsigned c;\n" "}", Alignment); + + // See PR37175 + FormatStyle Style = getMozillaStyle(); + Style.AlignConsecutiveDeclarations = true; + EXPECT_EQ("DECOR1 /**/ DECOR2 /**/ int8_t /**/\n" +"foo(int a);", +format("DECOR1 /**/ DECOR2 /**/ int8_t /**/ foo (int a);", Style)); + EXPECT_EQ("DECOR1 /**/ int8_t /**/ DECOR2 /**/\n" +"bar(int a);", +format("DECOR1 /**/ int8_t /**/ DECOR2 /**/ bar (int a);", Style)); } TEST_F(FormatTest, LinuxBraceBreaking) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ [](Change const ) { // tok::kw_operator is necessary for aligning operator overload // definitions. -return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); +if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; +if (C.Tok->isNot(TT_StartOfName)) + return false; +// Check if there is a subsequent name that starts the same declaration. +for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) +continue; + if (!Next->Tok.getIdentifierInfo()) +break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, +tok::kw_operator)) +return false; +} +return true; }, Changes, /*StartAt=*/0); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits