Skip to content

Commit 068f910

Browse files
authored
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.
1 parent a730547 commit 068f910

11 files changed

+65
-61
lines changed

tests/concurrent/rule_003_test_input.fixed_align_left_no_align_paren_no.vhd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ begin
1212
resize(unsigned(I_FOO) +
1313
unsigned(I_BAR), q_foo'length);
1414

15-
n_bar <= a or b and c
15+
n_bar <= (a or b) and c
1616
xor z and x or
1717
w and z;
1818

1919
n_bar <=
20-
a or b and c
20+
(a or b) and c
2121
xor z and x or
2222
w and z;
2323

@@ -30,12 +30,12 @@ begin
3030
resize(unsigned(I_FOO) +
3131
unsigned(I_BAR), q_foo'length);
3232

33-
n_bar <= a or b and c
33+
n_bar <= (a or b) and c
3434
xor z and x or
3535
w and z;
3636

3737
n_bar <=
38-
a or b and c
38+
(a or b) and c
3939
xor z and x or
4040
w and z;
4141

@@ -48,12 +48,12 @@ begin
4848
resize(unsigned(I_FOO) +
4949
unsigned(I_BAR), q_foo'length);
5050

51-
n_bar <= a or b and c
51+
n_bar <= (a or b) and c
5252
xor z and x or
5353
w and z;
5454

5555
n_bar <=
56-
a or b and c
56+
(a or b) and c
5757
xor z and x or
5858
w and z;
5959

@@ -66,12 +66,12 @@ begin
6666
resize(unsigned(I_FOO) +
6767
unsigned(I_BAR), q_foo'length);
6868

69-
n_bar <= a or b and c
69+
n_bar <= (a or b) and c
7070
xor z and x or
7171
w and z;
7272

7373
n_bar <=
74-
a or b and c
74+
(a or b) and c
7575
xor z and x or
7676
w and z;
7777

tests/concurrent/rule_003_test_input.fixed_align_left_no_align_paren_yes.vhd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ begin
1212
resize(unsigned(I_FOO) +
1313
unsigned(I_BAR), q_foo'length);
1414

15-
n_bar <= a or b and c
15+
n_bar <= (a or b) and c
1616
xor z and x or
1717
w and z;
1818

1919
n_bar <=
20-
a or b and c
20+
(a or b) and c
2121
xor z and x or
2222
w and z;
2323

@@ -30,12 +30,12 @@ begin
3030
resize(unsigned(I_FOO) +
3131
unsigned(I_BAR), q_foo'length);
3232

33-
n_bar <= a or b and c
33+
n_bar <= (a or b) and c
3434
xor z and x or
3535
w and z;
3636

3737
n_bar <=
38-
a or b and c
38+
(a or b) and c
3939
xor z and x or
4040
w and z;
4141

@@ -48,12 +48,12 @@ begin
4848
resize(unsigned(I_FOO) +
4949
unsigned(I_BAR), q_foo'length);
5050

51-
n_bar <= a or b and c
51+
n_bar <= (a or b) and c
5252
xor z and x or
5353
w and z;
5454

5555
n_bar <=
56-
a or b and c
56+
(a or b) and c
5757
xor z and x or
5858
w and z;
5959

@@ -66,12 +66,12 @@ begin
6666
resize(unsigned(I_FOO) +
6767
unsigned(I_BAR), q_foo'length);
6868

69-
n_bar <= a or b and c
69+
n_bar <= (a or b) and c
7070
xor z and x or
7171
w and z;
7272

7373
n_bar <=
74-
a or b and c
74+
(a or b) and c
7575
xor z and x or
7676
w and z;
7777

tests/concurrent/rule_003_test_input.fixed_align_left_yes_align_paren_no.vhd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ begin
1212
resize(unsigned(I_FOO) +
1313
unsigned(I_BAR), q_foo'length);
1414

15-
n_bar <= a or b and c
15+
n_bar <= (a or b) and c
1616
xor z and x or
1717
w and z;
1818

1919
n_bar <=
20-
a or b and c
20+
(a or b) and c
2121
xor z and x or
2222
w and z;
2323

@@ -30,12 +30,12 @@ begin
3030
resize(unsigned(I_FOO) +
3131
unsigned(I_BAR), q_foo'length);
3232

33-
n_bar <= a or b and c
33+
n_bar <= (a or b) and c
3434
xor z and x or
3535
w and z;
3636

3737
n_bar <=
38-
a or b and c
38+
(a or b) and c
3939
xor z and x or
4040
w and z;
4141

@@ -48,12 +48,12 @@ begin
4848
resize(unsigned(I_FOO) +
4949
unsigned(I_BAR), q_foo'length);
5050

51-
n_bar <= a or b and c
51+
n_bar <= (a or b) and c
5252
xor z and x or
5353
w and z;
5454

5555
n_bar <=
56-
a or b and c
56+
(a or b) and c
5757
xor z and x or
5858
w and z;
5959

@@ -66,12 +66,12 @@ begin
6666
resize(unsigned(I_FOO) +
6767
unsigned(I_BAR), q_foo'length);
6868

69-
n_bar <= a or b and c
69+
n_bar <= (a or b) and c
7070
xor z and x or
7171
w and z;
7272

7373
n_bar <=
74-
a or b and c
74+
(a or b) and c
7575
xor z and x or
7676
w and z;
7777

tests/concurrent/rule_003_test_input.fixed_align_left_yes_align_paren_yes.vhd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ begin
1212
resize(unsigned(I_FOO) +
1313
unsigned(I_BAR), q_foo'length);
1414

15-
n_bar <= a or b and c
15+
n_bar <= (a or b) and c
1616
xor z and x or
1717
w and z;
1818

1919
n_bar <=
20-
a or b and c
20+
(a or b) and c
2121
xor z and x or
2222
w and z;
2323

@@ -30,12 +30,12 @@ begin
3030
resize(unsigned(I_FOO) +
3131
unsigned(I_BAR), q_foo'length);
3232

33-
n_bar <= a or b and c
33+
n_bar <= (a or b) and c
3434
xor z and x or
3535
w and z;
3636

3737
n_bar <=
38-
a or b and c
38+
(a or b) and c
3939
xor z and x or
4040
w and z;
4141

@@ -48,12 +48,12 @@ begin
4848
resize(unsigned(I_FOO) +
4949
unsigned(I_BAR), q_foo'length);
5050

51-
n_bar <= a or b and c
51+
n_bar <= (a or b) and c
5252
xor z and x or
5353
w and z;
5454

5555
n_bar <=
56-
a or b and c
56+
(a or b) and c
5757
xor z and x or
5858
w and z;
5959

@@ -66,12 +66,12 @@ begin
6666
resize(unsigned(I_FOO) +
6767
unsigned(I_BAR), q_foo'length);
6868

69-
n_bar <= a or b and c
69+
n_bar <= (a or b) and c
7070
xor z and x or
7171
w and z;
7272

7373
n_bar <=
74-
a or b and c
74+
(a or b) and c
7575
xor z and x or
7676
w and z;
7777

tests/concurrent/rule_003_test_input.vhd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ begin
1212
resize(unsigned(I_FOO) +
1313
unsigned(I_BAR), q_foo'length);
1414

15-
n_bar <= a or b and c
15+
n_bar <= (a or b) and c
1616
xor z and x or
1717
w and z;
1818

1919
n_bar <=
20-
a or b and c
20+
(a or b) and c
2121
xor z and x or
2222
w and z;
2323

@@ -30,12 +30,12 @@ begin
3030
resize(unsigned(I_FOO) +
3131
unsigned(I_BAR), q_foo'length);
3232

33-
n_bar <= a or b and c
33+
n_bar <= (a or b) and c
3434
xor z and x or
3535
w and z;
3636

3737
n_bar <=
38-
a or b and c
38+
(a or b) and c
3939
xor z and x or
4040
w and z;
4141

@@ -48,12 +48,12 @@ begin
4848
resize(unsigned(I_FOO) +
4949
unsigned(I_BAR), q_foo'length);
5050

51-
n_bar <= a or b and c
51+
n_bar <= (a or b) and c
5252
xor z and x or
5353
w and z;
5454

5555
n_bar <=
56-
a or b and c
56+
(a or b) and c
5757
xor z and x or
5858
w and z;
5959

@@ -66,12 +66,12 @@ begin
6666
resize(unsigned(I_FOO) +
6767
unsigned(I_BAR), q_foo'length);
6868

69-
n_bar <= a or b and c
69+
n_bar <= (a or b) and c
7070
xor z and x or
7171
w and z;
7272

7373
n_bar <=
74-
a or b and c
74+
(a or b) and c
7575
xor z and x or
7676
w and z;
7777

vsg/rules/multiline_alignment_between_tokens.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from vsg import parser, token, violation
3+
from vsg import parser, violation
44
from vsg.rule_group import alignment
55
from vsg.rules import alignment_utils, utils as rules_utils
66
from vsg.vhdlFile import utils
@@ -37,7 +37,7 @@ def __init__(self, lTokenPairs, bExcludeLastToken=False):
3737
self.iIndentAfterParen = 1
3838
self.override = False
3939
self.configuration_documentation_link = "configuring_multiline_indent_rules_link"
40-
self.check_for_array = True
40+
self.skip_array = True
4141

4242
def _get_tokens_of_interest(self, oFile):
4343
lToi = []
@@ -47,7 +47,7 @@ def _get_tokens_of_interest(self, oFile):
4747

4848
lReturn = []
4949
for oToi in lToi:
50-
if self.check_for_array and toi_is_an_array(oToi):
50+
if self.skip_array and utils.toi_is_array(oToi):
5151
continue
5252
iLine, lTokens = utils.get_toi_parameters(oToi)
5353
iFirstLine, iFirstLineIndent = alignment_utils.get_first_line_info(iLine, oFile)
@@ -102,6 +102,11 @@ def _analyze(self, lToi):
102102
iColumn += len(oToken.get_value())
103103

104104
if isinstance(oToken, parser.close_parenthesis):
105+
dLastParen = lParens[-1]
106+
if dLastParen["type"] == "open" and dLastParen["line"] == iLine:
107+
lParens.pop()
108+
continue
109+
105110
dParen = {}
106111
dParen["type"] = "close"
107112
dParen["line"] = iLine
@@ -121,6 +126,9 @@ def _analyze(self, lToi):
121126
if iFirstLine == iLastLine:
122127
continue
123128

129+
if len(lParens) == 0 or lParens[0]["line"] != iFirstLine:
130+
bStartsWithParen = False
131+
124132
iFirstTokenLength = len(lTokens[0].get_value())
125133

126134
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
528536
dReturn[iLine] = dExpectedIndent[iLine] * " "
529537

530538
return dReturn
531-
532-
533-
def toi_is_an_array(oToi):
534-
for sAssignmentToken in ["<=", ":="]:
535-
if utils.are_next_consecutive_tokens_ignoring_whitespace([sAssignmentToken, "("], 0, oToi.get_tokens()):
536-
return True
537-
return False

vsg/rules/multiline_simple_structure.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
from vsg import parser, token, violation
3+
from vsg import parser, violation
44
from vsg.rule_group import structure
55
from vsg.rules import utils as rules_utils
66
from vsg.vhdlFile import utils
@@ -54,7 +54,7 @@ def _get_tokens_of_interest(self, oFile):
5454

5555
lReturn = []
5656
for oToi in lToi:
57-
if toi_is_an_array(oToi):
57+
if utils.toi_is_array(oToi):
5858
continue
5959
lReturn.append(oToi)
6060

@@ -128,11 +128,3 @@ def _create_action_dictionary(sType, sAction):
128128
dReturn["type"] = sType
129129
dReturn["action"] = sAction
130130
return dReturn
131-
132-
133-
def toi_is_an_array(oToi):
134-
lTokens = oToi.get_tokens()
135-
for oToken in lTokens:
136-
if isinstance(oToken, token.aggregate.open_parenthesis):
137-
return True
138-
return False

vsg/rules/selected_assignment/rule_400.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ def __init__(self):
4343
self.align_left = "yes"
4444
self.align_paren = "no"
4545
self.override = True
46-
self.check_for_array = False
46+
self.skip_array = False

vsg/rules/signal/rule_400.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ def __init__(self):
3838
self.subphase = 3
3939
self.bIgnoreStartParen = True
4040
self.bConstraint = True
41+
self.skip_array = False

0 commit comments

Comments
 (0)