Skip to content

Commit

Permalink
Fix some non-const global variables.
Browse files Browse the repository at this point in the history
In one case, a global variable was even assigned, fixed that.
  • Loading branch information
hzeller committed Nov 23, 2024
1 parent 095cd2e commit a2dc303
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion verible/common/formatting/state-node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace verible {

static absl::string_view kNotForAlignment =
static constexpr absl::string_view kNotForAlignment =
"Aligned tokens should never use line-wrap optimization!";

static SpacingDecision FrontTokenSpacing(const FormatTokenRange range) {
Expand Down
14 changes: 7 additions & 7 deletions verible/verilog/analysis/checkers/macro-name-style-rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ static constexpr absl::string_view kUVMLowerCaseMessage =
static constexpr absl::string_view kUVMUpperCaseMessage =
"'UVM_*' named macros must follow 'UPPER_SNAKE_CASE' format.";

static absl::string_view lower_snake_case_regex = "[a-z_0-9]+";
static absl::string_view upper_snake_case_regex = "[A-Z_0-9]+";
static constexpr absl::string_view kLowerSnakeCaseRegex = "[a-z_0-9]+";
static constexpr absl::string_view kUpperSnakeCaseRegex = "[A-Z_0-9]+";

MacroNameStyleRule::MacroNameStyleRule()
: style_regex_(
std::make_unique<re2::RE2>(upper_snake_case_regex, re2::RE2::Quiet)),
std::make_unique<re2::RE2>(kUpperSnakeCaseRegex, re2::RE2::Quiet)),
style_lower_snake_case_regex_(
std::make_unique<re2::RE2>(lower_snake_case_regex, re2::RE2::Quiet)),
style_upper_snake_case_regex_(std::make_unique<re2::RE2>(
upper_snake_case_regex, re2::RE2::Quiet)) {}
std::make_unique<re2::RE2>(kLowerSnakeCaseRegex, re2::RE2::Quiet)),
style_upper_snake_case_regex_(
std::make_unique<re2::RE2>(kUpperSnakeCaseRegex, re2::RE2::Quiet)) {}

const LintRuleDescriptor &MacroNameStyleRule::GetDescriptor() {
static const LintRuleDescriptor d{
Expand All @@ -70,7 +70,7 @@ const LintRuleDescriptor &MacroNameStyleRule::GetDescriptor() {
"and \"UPPER_SNAKE_CASE\" naming conventions respectively. Refer to "
"https://github.com/chipsalliance/verible/tree/master/verilog/tools/"
"lint#readme for more detail on verible regex patterns.",
.param = {{"style_regex", std::string(upper_snake_case_regex),
.param = {{"style_regex", std::string(kUpperSnakeCaseRegex),
"A regex used to check macro names style."}},
};
return d;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ static constexpr absl::string_view kLocalParamAllowPackageMessage =
"\'localparam\' declarations should only be within modules, packages or "
"class definition bodies.";

static absl::string_view kParameterMessage = kParameterNotInPackageMessage;
static absl::string_view kLocalParamMessage = kLocalParamAllowPackageMessage;

static absl::string_view kAutoFixReplaceParameterWithLocalparam =
static constexpr absl::string_view kAutoFixReplaceParameterWithLocalparam =
"Replace 'parameter' with 'localparam'";
static absl::string_view kAutoFixReplaceLocalparamWithParameter =
static constexpr absl::string_view kAutoFixReplaceLocalparamWithParameter =
"Replace 'localparam' with 'parameter'";

const LintRuleDescriptor &ProperParameterDeclarationRule::GetDescriptor() {
Expand Down Expand Up @@ -89,6 +86,19 @@ const LintRuleDescriptor &ProperParameterDeclarationRule::GetDescriptor() {
return d;
}

ProperParameterDeclarationRule::ProperParameterDeclarationRule() {
ChooseMessagesForConfiguration();
}

void ProperParameterDeclarationRule::ChooseMessagesForConfiguration() {
// Message is slightly different depending on configuration
parameter_message_ = package_allow_parameter_ ? kParameterAllowPackageMessage
: kParameterNotInPackageMessage;
local_parameter_message_ = package_allow_localparam_
? kLocalParamAllowPackageMessage
: kLocalParamNotInPackageMessage;
}

absl::Status ProperParameterDeclarationRule::Configure(
absl::string_view configuration) {
using verible::config::SetBool;
Expand All @@ -99,12 +109,7 @@ absl::Status ProperParameterDeclarationRule::Configure(
{"package_allow_localparam", SetBool(&package_allow_localparam_)},
});

// Change the message slightly
kParameterMessage = package_allow_parameter_ ? kParameterAllowPackageMessage
: kParameterNotInPackageMessage;
kLocalParamMessage = package_allow_localparam_
? kLocalParamAllowPackageMessage
: kLocalParamNotInPackageMessage;
ChooseMessagesForConfiguration();
return status;
}

Expand All @@ -124,7 +129,7 @@ void ProperParameterDeclarationRule::AddParameterViolation(
AutoFix autofix =
AutoFix(kAutoFixReplaceParameterWithLocalparam, {*token, "localparam"});
violations_.insert(
LintViolation(*token, kParameterMessage, context, {autofix}));
LintViolation(*token, parameter_message_, context, {autofix}));
}

void ProperParameterDeclarationRule::AddLocalparamViolation(
Expand All @@ -138,7 +143,7 @@ void ProperParameterDeclarationRule::AddLocalparamViolation(
AutoFix autofix =
AutoFix(kAutoFixReplaceLocalparamWithParameter, {*token, "parameter"});
violations_.insert(
LintViolation(*token, kLocalParamMessage, context, {autofix}));
LintViolation(*token, local_parameter_message_, context, {autofix}));
}

// TODO(kathuriac): Also check the 'interface' and 'program' constructs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class ProperParameterDeclarationRule : public verible::SyntaxTreeLintRule {

static const LintRuleDescriptor &GetDescriptor();

ProperParameterDeclarationRule();

void AddParameterViolation(const verible::Symbol &symbol,
const verible::SyntaxTreeContext &context);

Expand All @@ -51,10 +53,15 @@ class ProperParameterDeclarationRule : public verible::SyntaxTreeLintRule {
absl::Status Configure(absl::string_view configuration) final;

private:
void ChooseMessagesForConfiguration();

std::set<verible::LintViolation> violations_;

bool package_allow_parameter_ = false;
bool package_allow_localparam_ = true;

absl::string_view parameter_message_;
absl::string_view local_parameter_message_;
};

} // namespace analysis
Expand Down

0 comments on commit a2dc303

Please sign in to comment.