summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrasimir Georgiev <krasimir@google.com>2018-06-07 09:46:24 +0000
committerKrasimir Georgiev <krasimir@google.com>2018-06-07 09:46:24 +0000
commit45dde418a9c4e075934ef124a31f5491a1082421 (patch)
tree16887a2a750ea1c65c7a8670e79330aa7e562cc8
parent4281b1d3b57375f30ab77aac45f884e93e30e952 (diff)
downloadbcm5719-llvm-45dde418a9c4e075934ef124a31f5491a1082421.tar.gz
bcm5719-llvm-45dde418a9c4e075934ef124a31f5491a1082421.zip
[clang-format] Consider tok::hashhash in python-style comments
Summary: We were missing the case when python-style comments in text protos start with `##`. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D47870 llvm-svn: 334179
-rw-r--r--clang/lib/Format/BreakableToken.cpp3
-rw-r--r--clang/lib/Format/FormatTokenLexer.cpp2
-rw-r--r--clang/unittests/Format/FormatTestTextProto.cpp22
3 files changed, 25 insertions, 2 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 933dce35403..f727f8ddf89 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -44,7 +44,8 @@ static StringRef getLineCommentIndentPrefix(StringRef Comment,
const FormatStyle &Style) {
static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", "//",
"//!"};
- static const char *const KnownTextProtoPrefixes[] = {"//", "#"};
+ static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
+ "####"};
ArrayRef<const char *> KnownPrefixes(KnownCStylePrefixes);
if (Style.Language == FormatStyle::LK_TextProto)
KnownPrefixes = KnownTextProtoPrefixes;
diff --git a/clang/lib/Format/FormatTokenLexer.cpp b/clang/lib/Format/FormatTokenLexer.cpp
index fbd26965a6e..c7f720a443d 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -334,7 +334,7 @@ void FormatTokenLexer::handleTemplateStrings() {
void FormatTokenLexer::tryParsePythonComment() {
FormatToken *HashToken = Tokens.back();
- if (HashToken->isNot(tok::hash))
+ if (!HashToken->isOneOf(tok::hash, tok::hashhash))
return;
// Turn the remainder of this line into a comment.
const char *CommentBegin =
diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp
index 050c319e4f7..fcf118eee86 100644
--- a/clang/unittests/Format/FormatTestTextProto.cpp
+++ b/clang/unittests/Format/FormatTestTextProto.cpp
@@ -347,6 +347,28 @@ TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
"cccccccccccccccccccccccc: 3849");
}
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+ Style.ColumnLimit = 60; // To make writing tests easier.
+ EXPECT_EQ("aaa: 100\n"
+ "##this is a double-hash comment.\n"
+ "bb: 100\n"
+ "## another double-hash comment.\n"
+ "### a triple-hash comment\n"
+ "cc: 200\n"
+ "#### a quadriple-hash comment\n"
+ "dd: 100\n",
+ format("aaa: 100\n"
+ "##this is a double-hash comment.\n"
+ "bb: 100\n"
+ "## another double-hash comment.\n"
+ "### a triple-hash comment\n"
+ "cc: 200\n"
+ "#### a quadriple-hash comment\n"
+ "dd: 100\n",
+ Style));
+}
+
TEST_F(FormatTestTextProto, FormatsExtensions) {
verifyFormat("[type] { key: value }");
verifyFormat("[type] {\n"
OpenPOWER on IntegriCloud