Skip to content

Commit

Permalink
Merge pull request #2109 from IEncinas10/fix-uvm-macro-semicolon-fals…
Browse files Browse the repository at this point in the history
…e-positives

lint: remove false positives from uvm-macro-semicolon
  • Loading branch information
hzeller authored Feb 16, 2024
2 parents 9442853 + 5db1408 commit 2b6a9c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 13 additions & 3 deletions verilog/analysis/checkers/uvm_macro_semicolon_rule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,21 @@ static std::string FormatReason(const verible::TokenInfo &macro_id) {

// Returns true if leaf is a macro and matches `uvm_
static bool IsUvmMacroId(const verible::SyntaxTreeLeaf &leaf) {
const absl::string_view text = leaf.get().text();
const bool starts_with_uvm = absl::StartsWithIgnoreCase(text, "`uvm_");

if (leaf.Tag().tag == verilog_tokentype::MacroCallId ||
leaf.Tag().tag == verilog_tokentype::MacroIdItem ||
leaf.Tag().tag == verilog_tokentype::MacroIdentifier) {
return absl::StartsWithIgnoreCase(leaf.get().text(), "`uvm_");
leaf.Tag().tag == verilog_tokentype::MacroIdItem) {
return starts_with_uvm;
}

const bool ends_with_end = absl::EndsWithIgnoreCase(text, "_end");
// We don't want to complain about macros like:
// `UVM_DEFAULT_TIMEOUT, UVM_MAX_STREAMBITS, ...
if (leaf.Tag().tag == verilog_tokentype::MacroIdentifier) {
return starts_with_uvm && ends_with_end;
}

return false;
}

Expand Down
9 changes: 9 additions & 0 deletions verilog/analysis/checkers/uvm_macro_semicolon_rule_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ TEST(UvmMacroSemicolonRuleTest, BaseTests) {
RunLintTestCases<VerilogAnalyzer, UvmMacroSemicolonRule>(kTestCases);
}

TEST(UvmMacroSemicolonRuleTest, NoFalsePositivesTest) {
const std::initializer_list<LintTestCase> kTestCases = {
{"module m;\nint k = `UVM_DEFAULT_TIMEOUT; endmodule\n"},
{"module m;\nbit [63:0] k = `UVM_REG_ADDR_WIDTH'(0); endmodule\n"},
};

RunLintTestCases<VerilogAnalyzer, UvmMacroSemicolonRule>(kTestCases);
}

TEST(UvmMacroSemicolonRuleTest, AcceptedUvmMacroCallTests) {
const std::initializer_list<LintTestCase> kTestCases = {
// Function/Task scope
Expand Down

0 comments on commit 2b6a9c5

Please sign in to comment.