[cfe-commits] r172789 - in /cfe/trunk: lib/Format/Format.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp
Nico Weber
thakis at chromium.org
Fri Jan 18 10:46:43 PST 2013
On Fri, Jan 18, 2013 at 9:19 AM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Jan 17, 2013, at 9:50 PM, Nico Weber <nicolasweber at gmx.de> wrote:
>
>> Author: nico
>> Date: Thu Jan 17 23:50:57 2013
>> New Revision: 172789
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=172789&view=rev
>> Log:
>> Formatter: After case blocks, "break" goes on the same line as the "}", PR14907.
>>
>> Before:
>> switch (foo) {
>> case a: {
>> int a = g();
>> h(a);
>> }
>> break;
>> }
>>
>> Now:
>> switch (foo) {
>> case a: {
>> int a = g();
>> h(a);
>> } break;
>> }
>
> Is this a Chromium thing? I've never seen it before.
No, it's something I picked up at some other company long ago.
If people don't like this I'm happy to revert, but I figured it
doesn't affect people who put their breaks in the case block.
>
> - Doug
>
>>
>> Modified:
>> cfe/trunk/lib/Format/Format.cpp
>> cfe/trunk/lib/Format/UnwrappedLineParser.cpp
>> cfe/trunk/unittests/Format/FormatTest.cpp
>>
>> Modified: cfe/trunk/lib/Format/Format.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172789&r1=172788&r2=172789&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Format/Format.cpp (original)
>> +++ cfe/trunk/lib/Format/Format.cpp Thu Jan 17 23:50:57 2013
>> @@ -952,10 +952,10 @@
>> return false;
>> }
>> break;
>> - case tok::l_paren: {
>> + case tok::l_paren:
>> if (!parseParens())
>> return false;
>> - } break;
>> + break;
>> case tok::l_square:
>> if (!parseSquare())
>> return false;
>>
>> Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=172789&r1=172788&r2=172789&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
>> +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Jan 17 23:50:57 2013
>> @@ -487,6 +487,8 @@
>> --Line->Level;
>> if (FormatTok.Tok.is(tok::l_brace)) {
>> parseBlock();
>> + if (FormatTok.Tok.is(tok::kw_break))
>> + parseStructuralElement(); // "break;" after "}" goes on the same line.
>> }
>> addUnwrappedLine();
>> Line->Level = OldLineLevel;
>>
>> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172789&r1=172788&r2=172789&view=diff
>> ==============================================================================
>> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
>> +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 17 23:50:57 2013
>> @@ -274,6 +274,32 @@
>> " break;\n"
>> "}\n"
>> "}");
>> + verifyFormat("switch (x) {\n"
>> + "case 1: {\n"
>> + " f();\n"
>> + " {\n"
>> + " g();\n"
>> + " h();\n"
>> + " }\n"
>> + " break;\n"
>> + "}\n"
>> + "}");
>> + verifyFormat("switch (x) {\n"
>> + "case 1: {\n"
>> + " f();\n"
>> + " if (foo) {\n"
>> + " g();\n"
>> + " h();\n"
>> + " }\n"
>> + " break;\n"
>> + "}\n"
>> + "}");
>> + verifyFormat("switch (x) {\n"
>> + "case 1: {\n"
>> + " f();\n"
>> + " g();\n"
>> + "} break;\n"
>> + "}");
>> verifyFormat("switch (test)\n"
>> " ;");
>> verifyGoogleFormat("switch (x) {\n"
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list