diff options
author | Roman Kashitsyn <romankashicin@gmail.com> | 2014-09-11 14:47:20 +0000 |
---|---|---|
committer | Roman Kashitsyn <romankashicin@gmail.com> | 2014-09-11 14:47:20 +0000 |
commit | 650ecb53ca73ab3d2f948d85ebb852f171e996e3 (patch) | |
tree | acfc1bd23be4f88db37d516a4ae75f4aeb6e7b28 /clang | |
parent | ee46b0c8bed792fb6c7f74913e1d63c760ca1f6a (diff) | |
download | bcm5719-llvm-650ecb53ca73ab3d2f948d85ebb852f171e996e3.tar.gz bcm5719-llvm-650ecb53ca73ab3d2f948d85ebb852f171e996e3.zip |
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
llvm-svn: 217588
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/Format.cpp | 11 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 10 |
2 files changed, 19 insertions, 2 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 5b2f222bfc5..36d0f62a854 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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; + } } }; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 8b8aaf1b4a6..f8e318365bf 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { |