[cfe-commits] r171357 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Wed Jan 2 10:58:24 PST 2013
Well, this patch only consolidates the "int f() {}" and "int* f() {}"
cases, so it is a step into the right direction. If we implement the line
break you are suggesting, we should do so deliberately ;-).
clang-format currently formats like (assuming "bar" does not fit on the
first line):
int foo(
int bar,
int baz);
int *foo2(
int bar);
I personally would prefer that over the other solution, but it is obviously
a matter of taste (I didn't find anything in the style guide).
On Wed, Jan 2, 2013 at 7:45 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> Hm. We do this deliberately in LLVM sometimes, though, when we're pushing
> up against the 80-column limit.
>
> int
> foo(int bar,
> int baz);
>
> int *
> foo2(int bar);
>
> I grant you that this looks weird, but IMHO it's better than the
> alternative:
>
> int foo(
> int bar,
> int baz);
>
> int *foo2(
> int bar);
>
> What happens in these cases?
> Jordan
>
>
> On Jan 2, 2013, at 0:44 , Daniel Jasper <djasper at google.com> wrote:
>
> Author: djasper
> Date: Wed Jan 2 02:44:14 2013
> New Revision: 171357
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171357&view=rev
> Log:
> Don't break after pointer or reference specifier.
>
> This fixes llvm.org/PR14717.
> Buggy format:
> TypeSpecDecl *
> TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
> IdentifierInfo *II, Type *T) {
>
> Now changed to:
> TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,
> SourceLocation L, IdentifierInfo *II,
> Type *T) {
>
> 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=171357&r1=171356&r2=171357&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/Format.cpp (original)
> +++ cfe/trunk/lib/Format/Format.cpp Wed Jan 2 02:44:14 2013
> @@ -660,8 +660,7 @@
> for (int i = 1, e = Line.Tokens.size(); i != e; ++i) {
> TokenAnnotation &Annotation = Annotations[i];
>
> - Annotation.CanBreakBefore =
> - canBreakBetween(Line.Tokens[i - 1], Line.Tokens[i]);
> + Annotation.CanBreakBefore = canBreakBefore(i);
>
> if (Annotation.Type == TokenAnnotation::TT_CtorInitializerColon) {
> Annotation.MustBreakBefore = true;
> @@ -896,7 +895,13 @@
> return true;
> }
>
> - bool canBreakBetween(const FormatToken &Left, const FormatToken &Right)
> {
> + bool canBreakBefore(unsigned i) {
> + if (Annotations[i - 1].Type == TokenAnnotation::TT_PointerOrReference
> ||
> + Annotations[i].Type == TokenAnnotation::TT_ConditionalExpr) {
> + return false;
> + }
> + const FormatToken &Left = Line.Tokens[i - 1];
> + const FormatToken &Right = Line.Tokens[i];
> if (Right.Tok.is(tok::r_paren) || Right.Tok.is(tok::l_brace) ||
> Right.Tok.is(tok::comment) || Right.Tok.is(tok::greater))
> return false;
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171357&r1=171356&r2=171357&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 2 02:44:14 2013
> @@ -682,6 +682,16 @@
> verifyGoogleFormat("A<int**, int**> a;");
> }
>
> +TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {
> + verifyFormat(
> + "int *someFunction(int LoooooooooooooooongParam1,\n"
> + " int LoooooooooooooooongParam2) {\n}");
> + verifyFormat(
> + "TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext
> *DC,\n"
> + " SourceLocation L, IdentifierIn
> *II,\n"
> + " Type *T) {\n}");
> +}
> +
> TEST_F(FormatTest, LineStartsWithSpecialCharacter) {
> verifyFormat("(a)->b();");
> verifyFormat("--a;");
>
>
> _______________________________________________
> 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/20130102/56d6a471/attachment.html>
More information about the cfe-commits
mailing list