r181996 - Comments should not prevent single-line functions.

Jordan Rose jordan_rose at apple.com
Thu May 16 09:42:19 PDT 2013


Can you add a test to make sure we don't turn this:

void longFunctionName {
} // long comment here

into this:

void longFunctionName {}
// long comment here

?


On May 16, 2013, at 3:17 , Daniel Jasper <djasper at google.com> wrote:

> Author: djasper
> Date: Thu May 16 05:17:39 2013
> New Revision: 181996
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=181996&view=rev
> Log:
> Comments should not prevent single-line functions.
> 
> Before:
> void f() {}
> void g() {
> } // comment
> 
> After:
> void f() {}
> void g() {} // comment
> 
> 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=181996&r1=181995&r2=181996&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/Format.cpp (original)
> +++ cfe/trunk/lib/Format/Format.cpp Thu May 16 05:17:39 2013
> @@ -1418,7 +1418,7 @@ private:
>       return;
> 
>     AnnotatedToken *Tok = &(I + 1)->First;
> -    if (Tok->Children.empty() && Tok->is(tok::r_brace) &&
> +    if (Tok->getNextNoneComment() == NULL && Tok->is(tok::r_brace) &&
>         !Tok->MustBreakBefore) {
>       // We merge empty blocks even if the line exceeds the column limit.
>       Tok->SpacesRequiredBefore = 0;
> @@ -1443,7 +1443,7 @@ private:
> 
>       // Last, check that the third line contains a single closing brace.
>       Tok = &(I + 2)->First;
> -      if (!Tok->Children.empty() || Tok->isNot(tok::r_brace) ||
> +      if (Tok->getNextNoneComment() != NULL || Tok->isNot(tok::r_brace) ||
>           Tok->MustBreakBefore)
>         return;
> 
> 
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=181996&r1=181995&r2=181996&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu May 16 05:17:39 2013
> @@ -3043,6 +3043,8 @@ TEST_F(FormatTest, PullTrivialFunctionDe
>                "  int a;\n"
>                "#error {\n"
>                "}");
> +  verifyFormat("void f() {} // comment");
> +  verifyFormat("void f() { int a; } // comment");
> 
>   verifyFormat("void f() { return 42; }", getLLVMStyleWithColumns(23));
>   verifyFormat("void f() {\n  return 42;\n}", getLLVMStyleWithColumns(22));
> 
> 
> _______________________________________________
> 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