From aefa9e29b81f658172234a4962b714a80b956917 Mon Sep 17 00:00:00 2001 From: Steven Conway Date: Wed, 4 Sep 2024 23:34:29 +1000 Subject: [PATCH] Fixing blant, ClangTidy and fallthrough compile errors --- verilog/analysis/checkers/BUILD | 6 ++-- .../analysis/checkers/explicit_begin_rule.cc | 30 +++++++++++++--- .../analysis/checkers/explicit_begin_rule.h | 34 +++++++++---------- .../checkers/explicit_begin_rule_test.cc | 2 -- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/verilog/analysis/checkers/BUILD b/verilog/analysis/checkers/BUILD index d5a59c728..760e7d538 100644 --- a/verilog/analysis/checkers/BUILD +++ b/verilog/analysis/checkers/BUILD @@ -1261,13 +1261,15 @@ cc_library( deps = [ "//common/analysis:lint-rule-status", "//common/analysis:token-stream-lint-rule", - "//common/strings:comment-utils", "//common/text:config-utils", "//common/text:token-info", "//verilog/analysis:descriptions", "//verilog/analysis:lint-rule-registry", "//verilog/parser:verilog-token-enum", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:string_view", ], alwayslink = 1, ) @@ -1279,9 +1281,9 @@ cc_test( ":explicit-begin-rule", "//common/analysis:linter-test-utils", "//common/analysis:token-stream-linter-test-utils", - "//common/text:symbol", "//verilog/analysis:verilog-analyzer", "//verilog/parser:verilog-token-enum", + "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", ], ) diff --git a/verilog/analysis/checkers/explicit_begin_rule.cc b/verilog/analysis/checkers/explicit_begin_rule.cc index 56fdf5d3a..44fee0531 100644 --- a/verilog/analysis/checkers/explicit_begin_rule.cc +++ b/verilog/analysis/checkers/explicit_begin_rule.cc @@ -14,16 +14,14 @@ #include "verilog/analysis/checkers/explicit_begin_rule.h" -#include #include -#include -#include +#include "absl/base/attributes.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "common/analysis/lint_rule_status.h" #include "common/analysis/token_stream_lint_rule.h" -#include "common/strings/comment_utils.h" #include "common/text/config_utils.h" #include "common/text/token_info.h" #include "verilog/analysis/descriptions.h" @@ -33,7 +31,6 @@ namespace verilog { namespace analysis { -using verible::AutoFix; using verible::LintRuleStatus; using verible::LintViolation; using verible::TokenInfo; @@ -149,6 +146,10 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { state_ = State::kInlineConstraint; return false; } + default: { + // Do nothing + break; + } } if (!IsTokenEnabled(token)) { @@ -158,8 +159,11 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { switch (token.token_enum()) { // After token expect "begin" case TK_always_comb: + ABSL_FALLTHROUGH_INTENDED; case TK_always_latch: + ABSL_FALLTHROUGH_INTENDED; case TK_forever: + ABSL_FALLTHROUGH_INTENDED; case TK_initial: start_token_ = token; state_ = State::kExpectBegin; @@ -168,9 +172,13 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { // be tokens prior to the condition (like in an "always_ff" statement) // and these are all ignored. case TK_if: + ABSL_FALLTHROUGH_INTENDED; case TK_always_ff: + ABSL_FALLTHROUGH_INTENDED; case TK_for: + ABSL_FALLTHROUGH_INTENDED; case TK_foreach: + ABSL_FALLTHROUGH_INTENDED; case TK_while: condition_expr_level_ = 0; start_token_ = token; @@ -200,6 +208,7 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { // "*") and maybe a condition. switch (token.token_enum()) { case '@': + break; case '*': break; case TK_begin: @@ -250,6 +259,7 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { if (condition_expr_level_ == 0) { state_ = State::kExpectBegin; } + break; } default: { // throw away everything else @@ -287,6 +297,7 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { } } } + ABSL_FALLTHROUGH_INTENDED; case State::kConstraint: { // System Verilog constraints are special and use curly braces {} // instead of begin-end. So ignore all constraints @@ -300,12 +311,18 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) { if (constraint_expr_level_ == 0) { state_ = State::kNormal; } + break; } default: { // throw away everything else break; } } + break; + } + default: { + // Do nothing + break; } } // switch (state_) @@ -325,8 +342,11 @@ void ExplicitBeginRule::HandleToken(const TokenInfo &token) { // Ignore all white space and comments and return immediately switch (token.token_enum()) { case TK_SPACE: + return; case TK_NEWLINE: + return; case TK_COMMENT_BLOCK: + return; case TK_EOL_COMMENT: return; default: diff --git a/verilog/analysis/checkers/explicit_begin_rule.h b/verilog/analysis/checkers/explicit_begin_rule.h index 5604e8e63..d3e0aa74b 100644 --- a/verilog/analysis/checkers/explicit_begin_rule.h +++ b/verilog/analysis/checkers/explicit_begin_rule.h @@ -16,9 +16,9 @@ #define VERIBLE_VERILOG_ANALYSIS_CHECKERS_EXPLICIT_BEGIN_RULE_H_ #include -#include -#include +#include "absl/status/status.h" +#include "absl/strings/string_view.h" #include "common/analysis/lint_rule_status.h" #include "common/analysis/token_stream_lint_rule.h" #include "common/text/token_info.h" @@ -62,29 +62,29 @@ class ExplicitBeginRule : public verible::TokenStreamLintRule { }; // Internal lexical analysis state. - State state_; + State state_{State::kNormal}; // Level of nested parenthesis when analysing conditional expressions - int condition_expr_level_; + int condition_expr_level_{0}; // Level inside a constraint expression - int constraint_expr_level_; + int constraint_expr_level_{0}; // Configuration - bool if_enable_ = true; - bool else_enable_ = true; - bool always_enable_ = true; - bool always_comb_enable_ = true; - bool always_latch_enable_ = true; - bool always_ff_enable_ = true; - bool for_enable_ = true; - bool forever_enable_ = true; - bool foreach_enable_ = true; - bool while_enable_ = true; - bool initial_enable_ = true; + bool if_enable_{true}; + bool else_enable_{true}; + bool always_enable_{true}; + bool always_comb_enable_{true}; + bool always_latch_enable_{true}; + bool always_ff_enable_{true}; + bool for_enable_{true}; + bool forever_enable_{true}; + bool foreach_enable_{true}; + bool while_enable_{true}; + bool initial_enable_{true}; // Token that requires blocking statement. - verible::TokenInfo start_token_ = verible::TokenInfo::EOFToken(); + verible::TokenInfo start_token_{verible::TokenInfo::EOFToken()}; // Collection of found violations. std::set violations_; diff --git a/verilog/analysis/checkers/explicit_begin_rule_test.cc b/verilog/analysis/checkers/explicit_begin_rule_test.cc index 960e833a7..50d0d6683 100644 --- a/verilog/analysis/checkers/explicit_begin_rule_test.cc +++ b/verilog/analysis/checkers/explicit_begin_rule_test.cc @@ -18,7 +18,6 @@ #include "common/analysis/linter_test_utils.h" #include "common/analysis/token_stream_linter_test_utils.h" -#include "common/text/symbol.h" #include "gtest/gtest.h" #include "verilog/analysis/verilog_analyzer.h" #include "verilog/parser/verilog_token_enum.h" @@ -28,7 +27,6 @@ namespace analysis { namespace { using verible::LintTestCase; -using verible::RunApplyFixCases; using verible::RunConfiguredLintTestCases; using verible::RunLintTestCases;