diff --git a/verible/common/formatting/state-node.cc b/verible/common/formatting/state-node.cc index d13165f1f..7bba9322c 100644 --- a/verible/common/formatting/state-node.cc +++ b/verible/common/formatting/state-node.cc @@ -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) { diff --git a/verible/verilog/analysis/checkers/macro-name-style-rule.cc b/verible/verilog/analysis/checkers/macro-name-style-rule.cc index 36267a631..3ff7ddbce 100644 --- a/verible/verilog/analysis/checkers/macro-name-style-rule.cc +++ b/verible/verilog/analysis/checkers/macro-name-style-rule.cc @@ -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(upper_snake_case_regex, re2::RE2::Quiet)), + std::make_unique(kUpperSnakeCaseRegex, re2::RE2::Quiet)), style_lower_snake_case_regex_( - std::make_unique(lower_snake_case_regex, re2::RE2::Quiet)), - style_upper_snake_case_regex_(std::make_unique( - upper_snake_case_regex, re2::RE2::Quiet)) {} + std::make_unique(kLowerSnakeCaseRegex, re2::RE2::Quiet)), + style_upper_snake_case_regex_( + std::make_unique(kUpperSnakeCaseRegex, re2::RE2::Quiet)) {} const LintRuleDescriptor &MacroNameStyleRule::GetDescriptor() { static const LintRuleDescriptor d{ @@ -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; diff --git a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc index db2f4b54e..f58dbda3e 100644 --- a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc +++ b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.cc @@ -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() { @@ -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; @@ -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; } @@ -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( @@ -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. diff --git a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h index 810bb1830..e115a168d 100644 --- a/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h +++ b/verible/verilog/analysis/checkers/proper-parameter-declaration-rule.h @@ -37,6 +37,8 @@ class ProperParameterDeclarationRule : public verible::SyntaxTreeLintRule { static const LintRuleDescriptor &GetDescriptor(); + ProperParameterDeclarationRule(); + void AddParameterViolation(const verible::Symbol &symbol, const verible::SyntaxTreeContext &context); @@ -51,10 +53,15 @@ class ProperParameterDeclarationRule : public verible::SyntaxTreeLintRule { absl::Status Configure(absl::string_view configuration) final; private: + void ChooseMessagesForConfiguration(); + std::set violations_; bool package_allow_parameter_ = false; bool package_allow_localparam_ = true; + + absl::string_view parameter_message_; + absl::string_view local_parameter_message_; }; } // namespace analysis