r174545 - Become a little smarter with formatting long chains of pipes.
Chandler Carruth
chandlerc at google.com
Wed Feb 6 15:18:57 PST 2013
On Wed, Feb 6, 2013 at 1:04 PM, Daniel Jasper <djasper at google.com> wrote:
> Author: djasper
> Date: Wed Feb 6 15:04:05 2013
> New Revision: 174545
>
> URL: http://llvm.org/viewvc/llvm-project?rev=174545&view=rev
> Log:
> Become a little smarter with formatting long chains of pipes.
>
> Assign a high penalty to breaking before "<<" if the previous token is a
> string literal ending in ":" or "=".
>
Other places where I think the same core idea might apply (apologies if it
duplicates other discussions or bugs):
<< "Target time -> " << time
<< "this is scary (" << time << ")"
<< "array[" << x << "] = " << something // I used both!
Anyways, this is totally awesome. =D
>
> Before:
> llvm::outs()
> << "aaaaaaaaaaaaaaaaa = " << aaaaaaaaaaaaaaaaa << "bbbbbbbbbbbbbbbbb =
> "
> << bbbbbbbbbbbbbbbbb << "ccccccccccccccccc = " << ccccccccccccccccc
> << "ddddddddddddddddd = " << ddddddddddddddddd << "eeeeeeeeeeeeeeeee =
> "
> << eeeeeeeeeeeeeeeee;
>
> After:
> llvm::outs() << "aaaaaaaaaaaaaaaaa = " << aaaaaaaaaaaaaaaaa
> << "bbbbbbbbbbbbbbbbb = " << bbbbbbbbbbbbbbbbb
> << "ccccccccccccccccc = " << ccccccccccccccccc
> << "ddddddddddddddddd = " << ddddddddddddddddd
> << "eeeeeeeeeeeeeeeee = " << eeeeeeeeeeeeeeeee;
>
> Modified:
> cfe/trunk/lib/Format/TokenAnnotator.cpp
> cfe/trunk/unittests/Format/FormatTest.cpp
>
> Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=174545&r1=174544&r2=174545&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
> +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Feb 6 15:04:05 2013
> @@ -784,8 +784,16 @@ unsigned TokenAnnotator::splitPenalty(co
> Left.Type == TT_TemplateOpener)
> return 20;
>
> - if (Right.is(tok::lessless))
> + if (Right.is(tok::lessless)) {
> + if (Left.is(tok::string_literal)) {
> + char LastChar =
> + StringRef(Left.FormatTok.Tok.getLiteralData(),
> +
> Left.FormatTok.TokenLength).drop_back(1).rtrim().back();
> + if (LastChar == ':' || LastChar == '=')
> + return 100;
> + }
> return prec::Shift;
> + }
> if (Left.Type == TT_ConditionalExpr)
> return prec::Assignment;
> prec::Level Level = getPrecedence(Left);
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=174545&r1=174544&r2=174545&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb 6 15:04:05 2013
> @@ -1318,6 +1318,13 @@ TEST_F(FormatTest, AlignsPipes) {
> " << \" cccccc = \" << pkt.cccccc << \"\\n\"\n"
> " << \" ddd = [\" << pkt.ddd << \"]\\n\"\n"
> " << \"}\";");
> +
> + verifyFormat(
> + "llvm::outs() << \"aaaaaaaaaaaaaaaaa = \" << aaaaaaaaaaaaaaaaa\n"
> + " << \"bbbbbbbbbbbbbbbbb = \" << bbbbbbbbbbbbbbbbb\n"
> + " << \"ccccccccccccccccc = \" << ccccccccccccccccc\n"
> + " << \"ddddddddddddddddd = \" << ddddddddddddddddd\n"
> + " << \"eeeeeeeeeeeeeeeee = \" << eeeeeeeeeeeeeeeee;");
> }
>
> TEST_F(FormatTest, UnderstandsEquals) {
>
>
> _______________________________________________
> 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/20130206/6ee7f0e7/attachment.html>
More information about the cfe-commits
mailing list