r217588 - Fix bug 20892 - clang-format does not handle C-style comments
Daniel Jasper
djasper at google.com
Thu Sep 11 08:09:08 PDT 2014
Thank you!
On Thu, Sep 11, 2014 at 4:47 PM, Roman Kashitsyn <romankashicin at gmail.com>
wrote:
> Author: lifted
> Date: Thu Sep 11 09:47:20 2014
> New Revision: 217588
>
> URL: http://llvm.org/viewvc/llvm-project?rev=217588&view=rev
> Log:
> Fix bug 20892 - clang-format does not handle C-style comments
>
> Summary:
> http://llvm.org/bugs/show_bug.cgi?id=20892
>
> Add support of C-style formatting enabling/disabling directives. Now the
> following two styles are supported:
>
> // clang-format on
> /* clang-format on */
>
> The flexibility in comments (support of extra spaces and/or slashes, etc.)
> is deliberately avoided to simplify search in large code bases.
>
> Reviewers: djasper
>
> Reviewed By: djasper
>
> Subscribers: cfe-commits, curdeius, klimek
>
> Differential Revision: http://reviews.llvm.org/D5309
>
> 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=217588&r1=217587&r2=217588&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Format/Format.cpp (original)
> +++ cfe/trunk/lib/Format/Format.cpp Thu Sep 11 09:47:20 2014
> @@ -1725,11 +1725,18 @@ private:
> Tok.Tok.setKind(tok::char_constant);
> }
> }
> - if (Tok.is(tok::comment) && Tok.TokenText == "// clang-format on")
> +
> + if (Tok.is(tok::comment) && (Tok.TokenText == "// clang-format on" ||
> + Tok.TokenText == "/* clang-format on
> */")) {
> FormattingDisabled = false;
> + }
> +
> Tok.Finalized = FormattingDisabled;
> - if (Tok.is(tok::comment) && Tok.TokenText == "// clang-format off")
> +
> + if (Tok.is(tok::comment) && (Tok.TokenText == "// clang-format off" ||
> + Tok.TokenText == "/* clang-format off
> */")) {
> FormattingDisabled = true;
> + }
> }
> };
>
>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=217588&r1=217587&r2=217588&view=diff
>
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Sep 11 09:47:20 2014
> @@ -9355,6 +9355,16 @@ TEST_F(FormatTest, DisableRegions) {
> " int j;\n"
> " // clang-format on\n"
> " int k;"));
> + EXPECT_EQ("int i;\n"
> + "/* clang-format off */\n"
> + " int j;\n"
> + "/* clang-format on */\n"
> + "int k;",
> + format(" int i;\n"
> + " /* clang-format off */\n"
> + " int j;\n"
> + " /* clang-format on */\n"
> + " int k;"));
> }
>
> TEST_F(FormatTest, DoNotCrashOnInvalidInput) {
>
>
> _______________________________________________
> 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/20140911/c65e5acc/attachment.html>
More information about the cfe-commits
mailing list