Skip to content

Commit

Permalink
Fixing blant, ClangTidy and fallthrough compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sconwayaus committed Sep 5, 2024
1 parent b7d4f02 commit aefa9e2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 26 deletions.
6 changes: 4 additions & 2 deletions verilog/analysis/checkers/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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",
],
)
Expand Down
30 changes: 25 additions & 5 deletions verilog/analysis/checkers/explicit_begin_rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@

#include "verilog/analysis/checkers/explicit_begin_rule.h"

#include <deque>
#include <set>
#include <stack>
#include <string>

#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"
Expand All @@ -33,7 +31,6 @@
namespace verilog {
namespace analysis {

using verible::AutoFix;
using verible::LintRuleStatus;
using verible::LintViolation;
using verible::TokenInfo;
Expand Down Expand Up @@ -149,6 +146,10 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) {
state_ = State::kInlineConstraint;
return false;
}
default: {
// Do nothing
break;
}
}

if (!IsTokenEnabled(token)) {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -250,6 +259,7 @@ bool ExplicitBeginRule::HandleTokenStateMachine(const TokenInfo &token) {
if (condition_expr_level_ == 0) {
state_ = State::kExpectBegin;
}
break;
}
default: {
// throw away everything else
Expand Down Expand Up @@ -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
Expand All @@ -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_)

Expand All @@ -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:
Expand Down
34 changes: 17 additions & 17 deletions verilog/analysis/checkers/explicit_begin_rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#define VERIBLE_VERILOG_ANALYSIS_CHECKERS_EXPLICIT_BEGIN_RULE_H_

#include <set>
#include <stack>
#include <string>

#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"
Expand Down Expand Up @@ -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<verible::LintViolation> violations_;
Expand Down
2 changes: 0 additions & 2 deletions verilog/analysis/checkers/explicit_begin_rule_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,7 +27,6 @@ namespace analysis {
namespace {

using verible::LintTestCase;
using verible::RunApplyFixCases;
using verible::RunConfiguredLintTestCases;
using verible::RunLintTestCases;

Expand Down

0 comments on commit aefa9e2

Please sign in to comment.