Issue#1451: Fixed array detection and parenthesis handling in multiline_alignment_between_tokens (#1468)

* Issue#1451: Fixed array detection in multiline_alignment_between_tokens

* Move function toi_is_array from multiline_simple_structure to the 
  utils module and use this function in 
  multiline_alignment_between_tokens, because it correctly classifies
  parenthesis of aggregates. The previous function there falsely 
  triggered array detection on parenthesis around logical operators.

* Rename "check_for_array" to "skip_array", because that is what the 
  variable is used to do.

* Extend tests for concurrent_003 with logical expressions that start 
  with a parenthesis.

* Issue#1451: Fixed parenthesis handling in multiline_alignment_between_tokens

Do not add parenthesis pairs to the list of occurring parenthesis if
they are on the same line.
This commit is contained in:
Benjamin Thiemann 2025-09-03 04:18:33 +02:00 committed by GitHub
parent a73054725f
commit 068f9102ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 65 additions and 61 deletions

View File

@ -12,12 +12,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -30,12 +30,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -48,12 +48,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -66,12 +66,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;

View File

@ -12,12 +12,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -30,12 +30,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -48,12 +48,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -66,12 +66,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;

View File

@ -12,12 +12,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -30,12 +30,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -48,12 +48,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -66,12 +66,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;

View File

@ -12,12 +12,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -30,12 +30,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -48,12 +48,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -66,12 +66,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;

View File

@ -12,12 +12,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -30,12 +30,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -48,12 +48,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;
@ -66,12 +66,12 @@ begin
resize(unsigned(I_FOO) +
unsigned(I_BAR), q_foo'length);
n_bar <= a or b and c
n_bar <= (a or b) and c
xor z and x or
w and z;
n_bar <=
a or b and c
(a or b) and c
xor z and x or
w and z;

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from vsg import parser, token, violation
from vsg import parser, violation
from vsg.rule_group import alignment
from vsg.rules import alignment_utils, utils as rules_utils
from vsg.vhdlFile import utils
@ -37,7 +37,7 @@ class multiline_alignment_between_tokens(alignment.Rule):
self.iIndentAfterParen = 1
self.override = False
self.configuration_documentation_link = "configuring_multiline_indent_rules_link"
self.check_for_array = True
self.skip_array = True
def _get_tokens_of_interest(self, oFile):
lToi = []
@ -47,7 +47,7 @@ class multiline_alignment_between_tokens(alignment.Rule):
lReturn = []
for oToi in lToi:
if self.check_for_array and toi_is_an_array(oToi):
if self.skip_array and utils.toi_is_array(oToi):
continue
iLine, lTokens = utils.get_toi_parameters(oToi)
iFirstLine, iFirstLineIndent = alignment_utils.get_first_line_info(iLine, oFile)
@ -102,6 +102,11 @@ class multiline_alignment_between_tokens(alignment.Rule):
iColumn += len(oToken.get_value())
if isinstance(oToken, parser.close_parenthesis):
dLastParen = lParens[-1]
if dLastParen["type"] == "open" and dLastParen["line"] == iLine:
lParens.pop()
continue
dParen = {}
dParen["type"] = "close"
dParen["line"] = iLine
@ -121,6 +126,9 @@ class multiline_alignment_between_tokens(alignment.Rule):
if iFirstLine == iLastLine:
continue
if len(lParens) == 0 or lParens[0]["line"] != iFirstLine:
bStartsWithParen = False
iFirstTokenLength = len(lTokens[0].get_value())
if not align_paren(self) and align_left(self):
@ -528,10 +536,3 @@ def _analyze_align_paren_no_align_left_no(iFirstLine, iLastLine, lParens, dActua
dReturn[iLine] = dExpectedIndent[iLine] * " "
return dReturn
def toi_is_an_array(oToi):
for sAssignmentToken in ["<=", ":="]:
if utils.are_next_consecutive_tokens_ignoring_whitespace([sAssignmentToken, "("], 0, oToi.get_tokens()):
return True
return False

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from vsg import parser, token, violation
from vsg import parser, violation
from vsg.rule_group import structure
from vsg.rules import utils as rules_utils
from vsg.vhdlFile import utils
@ -54,7 +54,7 @@ class multiline_simple_structure(structure.Rule):
lReturn = []
for oToi in lToi:
if toi_is_an_array(oToi):
if utils.toi_is_array(oToi):
continue
lReturn.append(oToi)
@ -128,11 +128,3 @@ def _create_action_dictionary(sType, sAction):
dReturn["type"] = sType
dReturn["action"] = sAction
return dReturn
def toi_is_an_array(oToi):
lTokens = oToi.get_tokens()
for oToken in lTokens:
if isinstance(oToken, token.aggregate.open_parenthesis):
return True
return False

View File

@ -43,4 +43,4 @@ class rule_400(Rule):
self.align_left = "yes"
self.align_paren = "no"
self.override = True
self.check_for_array = False
self.skip_array = False

View File

@ -38,3 +38,4 @@ class rule_400(Rule):
self.subphase = 3
self.bIgnoreStartParen = True
self.bConstraint = True
self.skip_array = False

View File

@ -38,3 +38,4 @@ class rule_400(Rule):
self.subphase = 3
self.bIgnoreStartParen = True
self.bConstraint = True
self.skip_array = False

View File

@ -4,6 +4,7 @@ import sys
from vsg import exceptions, parser, token
from vsg.token import (
aggregate,
choice,
direction,
element_association,
@ -751,6 +752,14 @@ def get_toi_parameters(oToi):
return oToi.get_line_number(), oToi.get_tokens()
def toi_is_array(oToi):
lTokens = oToi.get_tokens()
for oToken in lTokens:
if isinstance(oToken, aggregate.open_parenthesis):
return True
return False
def does_token_start_line(iToken, lTokens):
if isinstance(lTokens[iToken - 1], parser.whitespace) and isinstance(lTokens[iToken - 2], parser.carriage_return):
return True