Updates for issue #450:

Fixing issue with alignment if the first parenthesis is on the first line.

  1)  Updated tests
  2)  Changed phase from rule_016 to 1
  3)  Updated code to make tests pass
This commit is contained in:
Jeremiah Leary 2021-02-06 13:10:20 -06:00
parent 4dc186e8f4
commit 3d8b8f2d5b
7 changed files with 72 additions and 9 deletions

View File

@ -55,7 +55,7 @@ class rule_012(rule.Rule):
lColumn = []
lColumn.append(iStartColumn)
bCheckAlignment = False
iFirstColumn, iNextColumn = _find_first_column(oFile, oToi, self.align_left, self.indentSize)
iFirstColumn, iNextColumn, iLastColumn = _find_first_column(oFile, oToi, self.align_left, self.indentSize, self.indent_step)
iColumn = iFirstColumn
iPreviousColumn = 0
iIndent = 0
@ -76,7 +76,10 @@ class rule_012(rule.Rule):
if isinstance(lTokens[iToken + 1], parser.whitespace):
iIndent = len(lTokens[iToken + 1].get_value())
if isinstance(lTokens[iToken + 2], parser.close_parenthesis):
lColumn.pop()
if len(lColumn) > 1:
lColumn.pop()
else:
lColumn = [iLastColumn]
# print(f'Close Paren = {lColumn}')
bSkipPop = True
@ -160,13 +163,28 @@ def calculate_start_column(oFile, oToi):
return iReturn
def _find_first_column(oFile, oToi, bAlignLeft, iIndentSize):
def _find_first_column(oFile, oToi, bAlignLeft, iIndentSize, iIndentStep):
iStartIndex = oToi.get_start_index()
if bAlignLeft:
iFirstColumn = oFile.get_column_of_token_index(iStartIndex)
iIndentLevel = oFile.get_indent_of_line_at_index(iStartIndex)
iNextColumn = iIndentSize * iIndentLevel
if is_token_before_carriage_return(parser.open_parenthesis, oToi.get_tokens()):
iNextColumn = iIndentSize * iIndentLevel + iIndentStep
iLastColumn = iIndentSize * iIndentLevel
else:
iNextColumn = iIndentSize * iIndentLevel
iLastColumn = iIndentSize * iIndentLevel
else:
iFirstColumn = oFile.get_column_of_token_index(iStartIndex)
iNextColumn = iFirstColumn
return iFirstColumn, iNextColumn
iLastColumn = iFirstColumn
return iFirstColumn, iNextColumn, iLastColumn
def is_token_before_carriage_return(tToken, lTokens):
for oToken in lTokens:
if isinstance(oToken, tToken):
return True
if isinstance(oToken, parser.carriage_return):
return False
return False

View File

@ -31,8 +31,7 @@ class rule_016(rule.Rule):
def __init__(self):
rule.Rule.__init__(self, 'constant', '016')
self.solution = 'Align one space after assignment operator'
self.phase = 5
self.subphase = 4
self.phase = 1
self.lTokenPairs = lTokenPairs
self.bExcludeLastToken = False
self.first_paren_new_line = False

View File

@ -97,3 +97,14 @@ begin
end architecture rtl;
architecture rtl of fifo is
constant avmm_master_null : avmm_master_t := (
(others => '0'),
(others => '0'),
'0',
'0'
);
begin end architecture rtl;

View File

@ -8,7 +8,7 @@ architecture rtl of fifo is
constant c_stimulus : t_stimulus_array := ((name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
constant c_stimulus : t_stimulus_array := (
(name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
(name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
constant c_stimulus : t_stimulus_array :=
((name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
@ -97,3 +97,14 @@ begin
end architecture rtl;
architecture rtl of fifo is
constant avmm_master_null : avmm_master_t := (
(others => '0'),
(others => '0'),
'0',
'0'
);
begin end architecture rtl;

View File

@ -8,7 +8,7 @@ architecture rtl of fifo is
constant c_stimulus : t_stimulus_array := ((name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
constant c_stimulus : t_stimulus_array := (
(name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
(name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
constant c_stimulus : t_stimulus_array :=
((name => "Hold in reset", clk_in => "01", rst_in => "11", cnt_en_in => "00", cnt_out => "00"), (name => "Not enabled", clk_in => "01", rst_in => "00", cnt_en_in => "00", cnt_out => "00"));
@ -97,3 +97,14 @@ begin
end architecture rtl;
architecture rtl of fifo is
constant avmm_master_null : avmm_master_t := (
(others => '0'),
(others => '0'),
'0',
'0'
);
begin end architecture rtl;

View File

@ -97,3 +97,14 @@ name => "Hold in reset",
end architecture rtl;
architecture rtl of fifo is
constant avmm_master_null : avmm_master_t := (
(others => '0'),
(others => '0'),
'0',
'0'
);
begin end architecture rtl;

View File

@ -49,6 +49,7 @@ class test_constant_rule(unittest.TestCase):
lExpected.extend(range(41, 55))
lExpected.extend(range(57, 73))
lExpected.extend(range(79, 95))
lExpected.extend(range(104, 109))
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
@ -82,6 +83,7 @@ class test_constant_rule(unittest.TestCase):
lExpected.extend(range(41, 55))
lExpected.extend(range(57, 73))
lExpected.extend(range(79, 95))
lExpected.extend(range(104, 108))
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))