Merge pull request #2627 from wsnyder/modport2
Fix modport dot member selects
diff --git a/verible/verilog/formatting/formatter_class_package_test.cc b/verible/verilog/formatting/formatter_class_package_test.cc
index ee45c51..4f65880 100644
--- a/verible/verilog/formatting/formatter_class_package_test.cc
+++ b/verible/verilog/formatting/formatter_class_package_test.cc
@@ -97,14 +97,23 @@
},
{
// Keep space before explicit modport port name
+ // Careful to still properly handle .member_selects.
"interface\tfoo ;"
"modport mp1(input .a(sig), output .b(sig));"
+ "modport mp(output .ch0_wr(ch[0].wr), input .ch0_rd(ch[0].rd), "
+ "output .ch1_wr(ch[1].wr.other), input .ch1_rd(ch[1].rd.other));"
"endinterface",
"interface foo;\n"
" modport mp1(\n"
" input .a(sig),\n"
" output .b(sig)\n"
" );\n"
+ " modport mp(\n"
+ " output .ch0_wr(ch[0].wr),\n"
+ " input .ch0_rd(ch[0].rd),\n"
+ " output .ch1_wr(ch[1].wr.other),\n"
+ " input .ch1_rd(ch[1].rd.other)\n"
+ " );\n"
"endinterface\n",
},
{
diff --git a/verible/verilog/formatting/token-annotator.cc b/verible/verilog/formatting/token-annotator.cc
index 47a8669..81e7b04 100644
--- a/verible/verilog/formatting/token-annotator.cc
+++ b/verible/verilog/formatting/token-annotator.cc
@@ -308,9 +308,11 @@
// TODO(fangism): Never insert trailing spaces before a newline.
- // Modport port name separator, e.g. "input .a("
+ // Modport port name separator, e.g. "input .a(...)". Match only the
+ // leading '.' that is a direct child of kModportSimplePort (the port
+ // name separator itself), not any '.' inside the port's expression
if (right.TokenEnum() == '.' &&
- right_context.IsInside(NodeEnum::kModportSimplePort)) {
+ right_context.DirectParentIs(NodeEnum::kModportSimplePort)) {
return {1, "Space before modport explicit port name '.'"};
}
diff --git a/verible/verilog/formatting/token-annotator_test.cc b/verible/verilog/formatting/token-annotator_test.cc
index df27619..50463f1 100644
--- a/verible/verilog/formatting/token-annotator_test.cc
+++ b/verible/verilog/formatting/token-annotator_test.cc
@@ -2771,6 +2771,19 @@
{1, SpacingOptions::kUndecided},
},
+ // A '.' nested inside a modport explicit port's parenthesized
+ // expression, e.g. the hierarchical/member select in
+ // ".a(ch[0].wr)", is not the port name separator.
+ {
+ DefaultStyle,
+ {']', "]"},
+ {'.', "."},
+ {/* any context */},
+ {NodeEnum::kModportSimplePort, NodeEnum::kParenGroup,
+ NodeEnum::kHierarchyExtension},
+ {0, SpacingOptions::kUndecided},
+ },
+
// Handle '->' as a unary prefix expression.
{
DefaultStyle,