From 5f0da883e4e8a54ee11b596ddea6171d0e5b4a8b Mon Sep 17 00:00:00 2001 From: Jon Meow <46229924+jonmeow@users.noreply.github.com> Date: Mon, 6 Dec 2021 14:12:35 -0800 Subject: [PATCH] Run clang-tidy over toolchain (#969) --- toolchain/common/yaml_test_helpers.h | 8 ++------ toolchain/diagnostics/diagnostic_emitter_test.cpp | 2 -- toolchain/diagnostics/mocks.h | 8 +++----- toolchain/diagnostics/null_diagnostics.h | 2 +- toolchain/driver/driver_test.cpp | 2 -- toolchain/lexer/tokenized_buffer_test.cpp | 1 - toolchain/parser/parse_tree_test.cpp | 4 +--- toolchain/parser/parser_impl.cpp | 11 ++++++----- toolchain/parser/precedence.cpp | 1 + 9 files changed, 14 insertions(+), 25 deletions(-) diff --git a/toolchain/common/yaml_test_helpers.h b/toolchain/common/yaml_test_helpers.h index eeb78d9288ff..82d162ac92e3 100644 --- a/toolchain/common/yaml_test_helpers.h +++ b/toolchain/common/yaml_test_helpers.h @@ -57,9 +57,7 @@ #include "common/ostream.h" -namespace Carbon { -namespace Testing { -namespace Yaml { +namespace Carbon::Testing::Yaml { struct EmptyComparable { friend auto operator==(EmptyComparable, EmptyComparable) -> bool { @@ -144,8 +142,6 @@ MATCHER_P(Scalar, value, return false; } -} // namespace Yaml -} // namespace Testing -} // namespace Carbon +} // namespace Carbon::Testing::Yaml #endif // TOOLCHAIN_COMMON_YAML_TEST_HELPERS_H_ diff --git a/toolchain/diagnostics/diagnostic_emitter_test.cpp b/toolchain/diagnostics/diagnostic_emitter_test.cpp index 7783d55b9ff3..6304f8d73190 100644 --- a/toolchain/diagnostics/diagnostic_emitter_test.cpp +++ b/toolchain/diagnostics/diagnostic_emitter_test.cpp @@ -18,8 +18,6 @@ using Testing::DiagnosticAt; using Testing::DiagnosticLevel; using Testing::DiagnosticMessage; using Testing::DiagnosticShortName; -using ::testing::ElementsAre; -using ::testing::Eq; struct FakeDiagnostic { static constexpr llvm::StringLiteral ShortName = "fake-diagnostic"; diff --git a/toolchain/diagnostics/mocks.h b/toolchain/diagnostics/mocks.h index abecee576ec0..7146a1052335 100644 --- a/toolchain/diagnostics/mocks.h +++ b/toolchain/diagnostics/mocks.h @@ -9,8 +9,7 @@ #include "toolchain/diagnostics/diagnostic_emitter.h" -namespace Carbon { -namespace Testing { +namespace Carbon::Testing { class MockDiagnosticConsumer : public DiagnosticConsumer { public: @@ -36,7 +35,7 @@ MATCHER_P2(DiagnosticAt, line, column, "") { return true; } -auto DiagnosticLevel(Diagnostic::Level level) -> auto { +inline auto DiagnosticLevel(Diagnostic::Level level) -> auto { return testing::Field(&Diagnostic::level, level); } @@ -52,7 +51,6 @@ auto DiagnosticShortName(Matcher&& inner_matcher) -> auto { std::forward(inner_matcher)); } -} // namespace Testing -} // namespace Carbon +} // namespace Carbon::Testing #endif // TOOLCHAIN_DIAGNOSTICS_MOCKS_H_ diff --git a/toolchain/diagnostics/null_diagnostics.h b/toolchain/diagnostics/null_diagnostics.h index ebb9410d5ccb..9fa3b55e44fc 100644 --- a/toolchain/diagnostics/null_diagnostics.h +++ b/toolchain/diagnostics/null_diagnostics.h @@ -15,7 +15,7 @@ inline auto NullDiagnosticLocationTranslator() struct Translator : DiagnosticLocationTranslator { auto GetLocation(LocationT) -> Diagnostic::Location override { return {}; } }; - static Translator* translator = new Translator; + static auto* translator = new Translator; return *translator; } diff --git a/toolchain/driver/driver_test.cpp b/toolchain/driver/driver_test.cpp index dc546e5cc724..b04405a83ede 100644 --- a/toolchain/driver/driver_test.cpp +++ b/toolchain/driver/driver_test.cpp @@ -16,9 +16,7 @@ namespace Carbon { namespace { using ::testing::ElementsAre; -using ::testing::Eq; using ::testing::HasSubstr; -using ::testing::NotNull; using ::testing::StrEq; namespace Yaml = Carbon::Testing::Yaml; diff --git a/toolchain/lexer/tokenized_buffer_test.cpp b/toolchain/lexer/tokenized_buffer_test.cpp index 2039becc1e87..d1ebdb474b03 100644 --- a/toolchain/lexer/tokenized_buffer_test.cpp +++ b/toolchain/lexer/tokenized_buffer_test.cpp @@ -31,7 +31,6 @@ using ::Carbon::Testing::HasTokens; using ::testing::ElementsAre; using ::testing::Eq; using ::testing::HasSubstr; -using ::testing::NotNull; using ::testing::StrEq; namespace Yaml = Carbon::Testing::Yaml; diff --git a/toolchain/parser/parse_tree_test.cpp b/toolchain/parser/parse_tree_test.cpp index d6562dac3de6..c051a02f6989 100644 --- a/toolchain/parser/parse_tree_test.cpp +++ b/toolchain/parser/parse_tree_test.cpp @@ -28,9 +28,7 @@ using Carbon::Testing::MatchParseTreeNodes; using namespace Carbon::Testing::NodeMatchers; using ::testing::ElementsAre; using ::testing::Eq; -using ::testing::HasSubstr; using ::testing::Ne; -using ::testing::NotNull; using ::testing::StrEq; namespace Yaml = Carbon::Testing::Yaml; @@ -1071,7 +1069,7 @@ TEST_F(ParseTreeTest, StructErrors) { DiagnosticMessage("Expected `,` or `}`.")}, }; - for (Testcase testcase : testcases) { + for (const Testcase& testcase : testcases) { TokenizedBuffer tokens = GetTokenizedBuffer(testcase.input); Testing::MockDiagnosticConsumer consumer; EXPECT_CALL(consumer, HandleDiagnostic(testcase.diag_matcher)); diff --git a/toolchain/parser/parser_impl.cpp b/toolchain/parser/parser_impl.cpp index d4f9d4a4ed2d..8e5ef3047410 100644 --- a/toolchain/parser/parser_impl.cpp +++ b/toolchain/parser/parser_impl.cpp @@ -505,7 +505,7 @@ auto ParseTree::Parser::ParseFunctionSignature() -> bool { auto params = ParseParenList( [&] { return ParseFunctionParameter(); }, ParseNodeKind::ParameterListComma(), - [&](TokenizedBuffer::Token open_paren, bool is_single_item, + [&](TokenizedBuffer::Token open_paren, bool /*is_single_item*/, TokenizedBuffer::Token close_paren, bool has_errors) { AddLeafNode(ParseNodeKind::ParameterListEnd(), close_paren); return AddNode(ParseNodeKind::ParameterList(), open_paren, start, @@ -776,7 +776,7 @@ auto ParseTree::Parser::ParseBraceExpression() -> llvm::Optional { /*has_error=*/!designator || !type_or_value); }, ParseNodeKind::StructComma(), - [&](TokenizedBuffer::Token open_brace, bool is_single_item, + [&](TokenizedBuffer::Token open_brace, bool /*is_single_item*/, TokenizedBuffer::Token close_brace, bool has_errors) { AddLeafNode(ParseNodeKind::StructEnd(), close_brace); return AddNode(kind == Type ? ParseNodeKind::StructTypeLiteral() @@ -850,7 +850,7 @@ auto ParseTree::Parser::ParseCallExpression(SubtreeStart start, bool has_errors) // ::= expression `,` expression-list return ParseParenList( [&] { return ParseExpression(); }, ParseNodeKind::CallExpressionComma(), - [&](TokenizedBuffer::Token open_paren, bool is_single_item, + [&](TokenizedBuffer::Token open_paren, bool /*is_single_item*/, TokenizedBuffer::Token close_paren, bool has_arg_errors) { AddLeafNode(ParseNodeKind::CallExpressionEnd(), close_paren); return AddNode(ParseNodeKind::CallExpression(), open_paren, start, @@ -1129,10 +1129,11 @@ auto ParseTree::Parser::ParseIfStatement() -> llvm::Optional { if (ConsumeAndAddLeafNodeIf(TokenKind::ElseKeyword(), ParseNodeKind::IfStatementElse())) { // 'else if' is permitted as a special case. - if (NextTokenIs(TokenKind::IfKeyword())) + if (NextTokenIs(TokenKind::IfKeyword())) { else_has_errors = !ParseIfStatement(); - else + } else { else_has_errors = !ParseCodeBlock(); + } } return AddNode(ParseNodeKind::IfStatement(), if_token, start, /*has_error=*/!cond || !then_case || else_has_errors); diff --git a/toolchain/parser/precedence.cpp b/toolchain/parser/precedence.cpp index 14304bfab691..cfcd9e79eef4 100644 --- a/toolchain/parser/precedence.cpp +++ b/toolchain/parser/precedence.cpp @@ -99,6 +99,7 @@ struct OperatorPriorityTable { bool changed = false; do { changed = false; + // NOLINTNEXTLINE(modernize-loop-convert) for (int8_t a = 0; a != NumPrecedenceLevels; ++a) { for (int8_t b = 0; b != NumPrecedenceLevels; ++b) { if (table[a][b] == OperatorPriority::LeftFirst) {