diff options
author | Krasimir Georgiev <krasimir@google.com> | 2018-04-23 08:50:36 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2018-04-23 08:50:36 +0000 |
commit | d6824876c2a9123dd98b5053acff9d88d7b09abe (patch) | |
tree | 5067e981b1447bc1793853e6b19731fddb3e4d98 | |
parent | 0d5c5936cbe0ff3cf7d78ade4df52053f95fd6a1 (diff) | |
download | bcm5719-llvm-d6824876c2a9123dd98b5053acff9d88d7b09abe.tar.gz bcm5719-llvm-d6824876c2a9123dd98b5053acff9d88d7b09abe.zip |
Revert "[clang-format] Improve Incomplete detection for (text) protos"
This reverts commit r330016.
The incomplete detection has too many false positives, picking up typos
for hard failures and refusing to format anything in that case.
llvm-svn: 330569
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 23 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestProto.cpp | 25 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestTextProto.cpp | 51 |
3 files changed, 9 insertions, 90 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index f76ae86b4c6..49e21520b70 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -592,8 +592,7 @@ private: return false; } } - // There are no top-level unbalanced braces in text protos. - return Style.Language != FormatStyle::LK_TextProto; + return true; } void updateParameterCount(FormatToken *Left, FormatToken *Current) { @@ -713,11 +712,6 @@ private: } else if (Contexts.back().ContextKind == tok::l_paren) { Tok->Type = TT_InlineASMColon; } - // Detects trailing pieces like key: - if ((Style.Language == FormatStyle::LK_Proto || - Style.Language == FormatStyle::LK_TextProto) && - !CurrentToken) - return false; break; case tok::pipe: case tok::amp: @@ -804,10 +798,6 @@ private: if (Previous && Previous->Type != TT_DictLiteral) Previous->Type = TT_SelectorName; } - } else if (Style.Language == FormatStyle::LK_TextProto || - Style.Language == FormatStyle::LK_Proto) { - // In TT_Proto and TT_TextProto, tok::less cannot be a binary operator. - return false; } else { Tok->Type = TT_BinaryOperator; NonTemplateLess.insert(Tok); @@ -819,16 +809,13 @@ private: case tok::r_square: return false; case tok::r_brace: - // Lines can start with '}' except in text protos. - if (Tok->Previous || Style.Language == FormatStyle::LK_TextProto) + // Lines can start with '}'. + if (Tok->Previous) return false; break; case tok::greater: - // In protos and text protos tok::greater cannot be a binary operator. - if (Style.Language == FormatStyle::LK_Proto || - Style.Language == FormatStyle::LK_TextProto) - return false; - Tok->Type = TT_BinaryOperator; + if (Style.Language != FormatStyle::LK_TextProto) + Tok->Type = TT_BinaryOperator; break; case tok::kw_operator: if (Style.Language == FormatStyle::LK_TextProto || diff --git a/clang/unittests/Format/FormatTestProto.cpp b/clang/unittests/Format/FormatTestProto.cpp index 8634a36b9d9..4b1480b074a 100644 --- a/clang/unittests/Format/FormatTestProto.cpp +++ b/clang/unittests/Format/FormatTestProto.cpp @@ -18,21 +18,13 @@ namespace clang { namespace format { class FormatTestProto : public ::testing::Test { - enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete }; - protected: static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style, - StatusCheck CheckComplete = SC_ExpectComplete) { + unsigned Length, const FormatStyle &Style) { DEBUG(llvm::errs() << "---\n"); DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); - FormattingAttemptStatus Status; - tooling::Replacements Replaces = - reformat(Style, Code, Ranges, "<stdin>", &Status); - bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete; - EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete) - << Code << "\n\n"; + tooling::Replacements Replaces = reformat(Style, Code, Ranges); auto Result = applyAllReplacements(Code, Replaces); EXPECT_TRUE(static_cast<bool>(Result)); DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); @@ -49,12 +41,6 @@ protected: EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable"; EXPECT_EQ(Code.str(), format(test::messUp(Code))); } - - static void verifyIncompleteFormat(llvm::StringRef Code) { - FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto); - EXPECT_EQ(Code.str(), - format(Code, 0, Code.size(), Style, SC_ExpectIncomplete)); - } }; TEST_F(FormatTestProto, FormatsMessages) { @@ -506,12 +492,5 @@ TEST_F(FormatTestProto, AcceptsOperatorAsKeyInOptions) { "};"); } -TEST_F(FormatTestProto, IncompleteFormat) { - verifyIncompleteFormat("option ("); - verifyIncompleteFormat("option (MyProto.options) = { bbbbbbbbb:"); - verifyIncompleteFormat("option (MyProto.options) = { bbbbbbbbb: <\n"); - verifyIncompleteFormat("option (MyProto.options) = { bbbbbbbbb: [\n"); -} - } // end namespace tooling } // end namespace clang diff --git a/clang/unittests/Format/FormatTestTextProto.cpp b/clang/unittests/Format/FormatTestTextProto.cpp index 608059c9ea8..4e4387b9d38 100644 --- a/clang/unittests/Format/FormatTestTextProto.cpp +++ b/clang/unittests/Format/FormatTestTextProto.cpp @@ -19,20 +19,12 @@ namespace format { class FormatTestTextProto : public ::testing::Test { protected: - enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete }; - static std::string format(llvm::StringRef Code, unsigned Offset, - unsigned Length, const FormatStyle &Style, - StatusCheck CheckComplete = SC_ExpectComplete) { + unsigned Length, const FormatStyle &Style) { DEBUG(llvm::errs() << "---\n"); DEBUG(llvm::errs() << Code << "\n\n"); std::vector<tooling::Range> Ranges(1, tooling::Range(Offset, Length)); - FormattingAttemptStatus Status; - tooling::Replacements Replaces = - reformat(Style, Code, Ranges, "<stdin>", &Status); - bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete; - EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete) - << Code << "\n\n"; + tooling::Replacements Replaces = reformat(Style, Code, Ranges); auto Result = applyAllReplacements(Code, Replaces); EXPECT_TRUE(static_cast<bool>(Result)); DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); @@ -53,12 +45,6 @@ protected: Style.ColumnLimit = 60; // To make writing tests easier. verifyFormat(Code, Style); } - - static void verifyIncompleteFormat(llvm::StringRef Code) { - FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto); - EXPECT_EQ(Code.str(), - format(Code, 0, Code.size(), Style, SC_ExpectIncomplete)); - } }; TEST_F(FormatTestTextProto, KeepsTopLevelEntriesFittingALine) { @@ -509,38 +495,5 @@ TEST_F(FormatTestTextProto, PutsMultipleEntriesInExtensionsOnNewlines) { "}", Style); } -TEST_F(FormatTestTextProto, IncompleteFormat) { - verifyIncompleteFormat("data {"); - verifyIncompleteFormat("data <"); - verifyIncompleteFormat("data ["); - verifyIncompleteFormat("data: {"); - verifyIncompleteFormat("data: <"); - verifyIncompleteFormat("data: ["); - verifyIncompleteFormat("key:"); - verifyIncompleteFormat("key:}"); - verifyIncompleteFormat("key: ]"); - verifyIncompleteFormat("key: >"); - verifyIncompleteFormat(": value"); - verifyIncompleteFormat(": {}"); - verifyIncompleteFormat(": <>"); - verifyIncompleteFormat(": []"); - verifyIncompleteFormat("}\n" - "key: value"); - verifyIncompleteFormat("]\n" - "key: value"); - verifyIncompleteFormat("> key: value"); - verifyIncompleteFormat("data { key: {"); - verifyIncompleteFormat("data < key: ["); - verifyIncompleteFormat("data [ key: {"); - verifyIncompleteFormat("> key: value {"); - verifyIncompleteFormat("> key: ["); - verifyIncompleteFormat("}\n" - "key: {"); - verifyIncompleteFormat("data { key: 1 id:"); - verifyIncompleteFormat("}\n" - "key {"); - verifyIncompleteFormat("> <"); -} - } // end namespace tooling } // end namespace clang |