r178860 - Improve formatting of multi-variable DeclStmts.
Nico Weber
thakis at chromium.org
Fri Apr 5 14:04:07 PDT 2013
Thanks!
On Fri, Apr 5, 2013 at 2:38 AM, Daniel Jasper <djasper at google.com> wrote:
> Author: djasper
> Date: Fri Apr 5 04:38:50 2013
> New Revision: 178860
>
> URL: http://llvm.org/viewvc/llvm-project?rev=178860&view=rev
> Log:
> Improve formatting of multi-variable DeclStmts.
>
> This fixed llvm.org/PR15670
>
> Before:
> aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,
> c = cccccccccccccccccccc,
> d = dddddddddddddddddddd;
> aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,
> *c = ccccccccccccccccccc,
> *d = ddddddddddddddddddd;
>
> After:
> aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b = bbbbbbbbbbbbbbbbbbbb,
> c = cccccccccccccccccccc, d = dddddddddddddddddddd;
> aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,
> *c = ccccccccccccccccccc, *d = ddddddddddddddddddd;
>
> Modified:
> cfe/trunk/lib/Format/Format.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=178860&r1=178859&r2=178860&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/Format.cpp (original)
> +++ cfe/trunk/lib/Format/Format.cpp Fri Apr 5 04:38:50 2013
> @@ -798,9 +798,18 @@ private:
> }
> } else {
> if (Current.is(tok::equal) &&
> - (RootToken.is(tok::kw_for) || State.ParenLevel == 0)) {
> - State.Stack.back().VariablePos =
> - State.Column - Previous.FormatTok.TokenLength;
> + (RootToken.is(tok::kw_for) || State.ParenLevel == 0) &&
> + State.Stack.back().VariablePos == 0) {
> + State.Stack.back().VariablePos = State.Column;
> + // Move over * and & if they are bound to the variable name.
> + const AnnotatedToken *Tok = &Previous;
> + while (Tok &&
> + State.Stack.back().VariablePos >=
> Tok->FormatTok.TokenLength) {
> + State.Stack.back().VariablePos -= Tok->FormatTok.TokenLength;
> + if (Tok->SpacesRequiredBefore != 0)
> + break;
> + Tok = Tok->Parent;
> + }
> if (Previous.PartOfMultiVariableDeclStmt)
> State.Stack.back().LastSpace = State.Stack.back().VariablePos;
> }
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=178860&r1=178859&r2=178860&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Apr 5 04:38:50 2013
> @@ -1864,7 +1864,22 @@ TEST_F(FormatTest, DeclarationsOfMultipl
> "bool aaaaaaaaaaaaaaaaaaaaa =\n"
> " bbbbbbbbbbbbbbbbbbbbbbbbbbbb &&
> cccccccccccccccccccccccccccc,\n"
> " d = e && f;");
> + verifyFormat("aaaaaaaaa a = aaaaaaaaaaaaaaaaaaaa, b =
> bbbbbbbbbbbbbbbbbbbb,\n"
> + " c = cccccccccccccccccccc, d =
> dddddddddddddddddddd;");
> + verifyFormat("aaaaaaaaa *a = aaaaaaaaaaaaaaaaaaa, *b =
> bbbbbbbbbbbbbbbbbbb,\n"
> + " *c = ccccccccccccccccccc, *d =
> ddddddddddddddddddd;");
> + verifyFormat("aaaaaaaaa ***a = aaaaaaaaaaaaaaaaaaa, ***b =
> bbbbbbbbbbbbbbb,\n"
> + " ***c = ccccccccccccccccccc, ***d =
> ddddddddddddddd;");
> + // FIXME: If multiple variables are defined, the "*" needs to move to
> the new
> + // line. Also fix indent for breaking after the type, this looks bad.
> + verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *\n"
> + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaa,\n"
> + " *b = bbbbbbbbbbbbbbbbbbb;");
>
> + // Not ideal, but pointer-with-type does not allow much here.
> + verifyGoogleFormat(
> + "aaaaaaaaa* a = aaaaaaaaaaaaaaaaaaa, *b = bbbbbbbbbbbbbbbbbbb,\n"
> + " *b = bbbbbbbbbbbbbbbbbbb, *d = ddddddddddddddddddd;");
> }
>
> TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130405/586ae7b5/attachment.html>
More information about the cfe-commits
mailing list