diff --git a/vsg/rules/__init__.py b/vsg/rules/__init__.py index dbdae451..8343f4c1 100644 --- a/vsg/rules/__init__.py +++ b/vsg/rules/__init__.py @@ -58,6 +58,7 @@ from .split_line_at_token_if_on_same_line_as_token_if_token_pair_are_not_on_the_ from .remove_comments_from_end_of_lines_bounded_by_tokens import remove_comments_from_end_of_lines_bounded_by_tokens from .token_case_formal_part_of_association_element_in_map_between_tokens import token_case_formal_part_of_association_element_in_map_between_tokens from .token_case_first_token_after_token import token_case_first_token_after_token +from .existence_of_tokens_which_should_not_occur import existence_of_tokens_which_should_not_occur from vsg.rules import after from vsg.rules import architecture diff --git a/vsg/rules/existence_of_tokens_which_should_not_occur.py b/vsg/rules/existence_of_tokens_which_should_not_occur.py new file mode 100644 index 00000000..62c7d3b5 --- /dev/null +++ b/vsg/rules/existence_of_tokens_which_should_not_occur.py @@ -0,0 +1,48 @@ + + +from vsg import rule_item +from vsg import utils +from vsg import parser + +from vsg import violation + + +class existence_of_tokens_which_should_not_occur(rule_item.Rule): + ''' + Checks the case for words. + + Parameters + ---------- + + name : string + The group the rule belongs to. + + identifier : string + unique identifier. Usually in the form of 00N. + + lTokens : list of parser object types + object types to check the prefix + + lPrefixes : string list + acceptable prefixes + ''' + + def __init__(self, name, identifier, lTokens): + rule_item.Rule.__init__(self, name=name, identifier=identifier) + self.solution = None + self.phase = 1 + self.lTokens = lTokens + self.fixable = False + + def analyze(self, oFile): + lToi = oFile.get_tokens_matching(self.lTokens) + for oToi in lToi: + oViolation = violation.New(oToi.get_line_number(), oToi, self.solution) + self.add_violation(oViolation) + + + def fix(self, oFile): + ''' + Applies fixes for any rule violations. + ''' + return diff --git a/vsg/rules/signal/rule_007.py b/vsg/rules/signal/rule_007.py index ab628ca5..66b0f2fc 100644 --- a/vsg/rules/signal/rule_007.py +++ b/vsg/rules/signal/rule_007.py @@ -1,20 +1,17 @@ -from vsg import rule -from vsg import utils +from vsg.rules import existence_of_tokens_which_should_not_occur + +from vsg import token + +lTokens = [] +lTokens.append(token.signal_declaration.assignment_operator) -class rule_007(rule.rule): +class rule_007(existence_of_tokens_which_should_not_occur): ''' - Signal rule 007 checks for default assignments in signal declarations. + Checks for default assignments in signal declarations. ''' def __init__(self): - rule.rule.__init__(self, 'signal', '007') + existence_of_tokens_which_should_not_occur.__init__(self, 'signal', '007', lTokens) self.solution = 'Remove default assignment.' - self.phase = 1 - self.fixable = False # Allow the user to decide if these should be removed - - def _analyze(self, oFile, oLine, iLineNumber): - if oLine.isSignal and ':=' in oLine.line: - dViolation = utils.create_violation_dict(iLineNumber) - self.add_violation(dViolation) diff --git a/vsg/rules/variable/rule_007.py b/vsg/rules/variable/rule_007.py index 8216a14c..0680eef9 100644 --- a/vsg/rules/variable/rule_007.py +++ b/vsg/rules/variable/rule_007.py @@ -1,20 +1,17 @@ -from vsg import rule -from vsg import utils +from vsg.rules import existence_of_tokens_which_should_not_occur + +from vsg import token + +lTokens = [] +lTokens.append(token.variable_declaration.assignment_operator) -class rule_007(rule.rule): +class rule_007(existence_of_tokens_which_should_not_occur): ''' - Variable rule 007 checks for default assignments in variable declarations. + Checks for default assignments in variable declarations. ''' def __init__(self): - rule.rule.__init__(self, 'variable', '007') + existence_of_tokens_which_should_not_occur.__init__(self, 'variable', '007', lTokens) self.solution = 'Remove default assignment.' - self.phase = 1 - self.fixable = False # Allow the user to decide if these should be removed - - def _analyze(self, oFile, oLine, iLineNumber): - if oLine.isVariable and ':=' in oLine.line: - dViolation = utils.create_violation_dict(iLineNumber) - self.add_violation(dViolation) diff --git a/vsg/tests/signal/rule_007_test_input.vhd b/vsg/tests/signal/rule_007_test_input.vhd new file mode 100644 index 00000000..cd3cca92 --- /dev/null +++ b/vsg/tests/signal/rule_007_test_input.vhd @@ -0,0 +1,13 @@ + +architecture RTL of FIFO is + + signal sig1 : std_logic; + + -- Violations below + + signal sig1 : std_logic := '1'; + + +begin + +end architecture RTL; diff --git a/vsg/tests/signal/test_rule_007.py b/vsg/tests/signal/test_rule_007.py new file mode 100644 index 00000000..e6217602 --- /dev/null +++ b/vsg/tests/signal/test_rule_007.py @@ -0,0 +1,28 @@ + +import os +import unittest + +from vsg.rules import signal +from vsg import vhdlFile +from vsg.tests import utils + +sTestDir = os.path.dirname(__file__) + +lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_007_test_input.vhd')) + + +class test_signal_rule(unittest.TestCase): + + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + + def test_rule_007(self): + oRule = signal.rule_007() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'signal') + self.assertEqual(oRule.identifier, '007') + + lExpected = [8] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/vsg/tests/signal/test_rule_signal.py b/vsg/tests/signal/test_rule_signal.py index fced31c8..6213cfbf 100644 --- a/vsg/tests/signal/test_rule_signal.py +++ b/vsg/tests/signal/test_rule_signal.py @@ -14,14 +14,6 @@ oFile = vhdlFile.vhdlFile(lFile) class testRuleSignalMethods(unittest.TestCase): - def test_rule_007(self): - oRule = signal.rule_007() - self.assertTrue(oRule) - self.assertEqual(oRule.name, 'signal') - self.assertEqual(oRule.identifier, '007') - lExpected = utils.add_violation_list([11,16]) - oRule.analyze(oFile) - self.assertEqual(oRule.violations, lExpected) def test_rule_010(self): oRule = signal.rule_010() diff --git a/vsg/tests/variable/classification_test_input.vhd b/vsg/tests/variable/classification_test_input.vhd deleted file mode 100644 index 72208ab5..00000000 --- a/vsg/tests/variable/classification_test_input.vhd +++ /dev/null @@ -1,26 +0,0 @@ -package body fifo is - -variable INDEX: integer range 0 to 99 := 0; - -variable COUNT: POSITIVE; - -variable MEMORY: BIT_MATRIX (0 to 7, 0 to 1023); - -shared variable Counter: SharedCounter; - -shared variable addend, augend, result: ComplexNumber; - -variable bit_stack: VariableSizeBitArray := "0000"; - -shared -variable -addend -, -augend -, -result -: -ComplexNumber -; - -end package body fifo; diff --git a/vsg/tests/variable/rule_007_test_input.vhd b/vsg/tests/variable/rule_007_test_input.vhd new file mode 100644 index 00000000..1ec2174e --- /dev/null +++ b/vsg/tests/variable/rule_007_test_input.vhd @@ -0,0 +1,28 @@ + +architecture RTL of FIFO is + + shared variable shar_var1 : integer; + +begin + + process + variable var1 : integer; + begin + end process; + +end architecture RTL; + +-- Violations below + +architecture RTL of FIFO is + + shared variable shar_var1 : integer := 0; + +begin + + process + variable var1 : integer := 20; + begin + end process; + +end architecture RTL; diff --git a/vsg/tests/variable/test_fix_rule_variable.py b/vsg/tests/variable/test_fix_rule_variable.py deleted file mode 100644 index 2b4a65be..00000000 --- a/vsg/tests/variable/test_fix_rule_variable.py +++ /dev/null @@ -1,63 +0,0 @@ -import os - -import unittest -import sys -sys.path.append('vsg') - -from vsg.rules import variable -from vsg import vhdlFile -from vsg.tests import utils - - -class testFixRuleVariableMethods(unittest.TestCase): - - def setUp(self): - # Read in test file used for all tests - self.lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','variable','variable_test_input.vhd')) - self.oFile = vhdlFile.vhdlFile(self.lFile) - - def test_fix_rule_001(self): - oRule = variable.rule_001() - dExpected = [] - oRule.fix(self.oFile) - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, dExpected) - - def test_fix_rule_002(self): - oRule = variable.rule_002() - dExpected = [] - oRule.fix(self.oFile) - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, dExpected) - - def test_fix_rule_004(self): - oRule = variable.rule_004() - dExpected = [] - oRule.fix(self.oFile) - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, dExpected) - - def test_fix_rule_005(self): - oRule = variable.rule_005() - dExpected = [] - oRule.fix(self.oFile) - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, dExpected) - - def test_fix_rule_006(self): - oRule = variable.rule_006() - dExpected = [] - oRule.fix(self.oFile) - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, dExpected) - - def test_fix_rule_007(self): - oRule = variable.rule_007() - self.assertFalse(oRule.fixable) - - def test_fix_rule_010(self): - oRule = variable.rule_010() - dExpected = [] - oRule.fix(self.oFile) - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, dExpected) diff --git a/vsg/tests/variable/test_rule_007.py b/vsg/tests/variable/test_rule_007.py new file mode 100644 index 00000000..7fb38d90 --- /dev/null +++ b/vsg/tests/variable/test_rule_007.py @@ -0,0 +1,28 @@ + +import os +import unittest + +from vsg.rules import variable +from vsg import vhdlFile +from vsg.tests import utils + +sTestDir = os.path.dirname(__file__) + +lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_007_test_input.vhd')) + + +class test_variable_rule(unittest.TestCase): + + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + + def test_rule_007(self): + oRule = variable.rule_007() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'variable') + self.assertEqual(oRule.identifier, '007') + + lExpected = [19, 24] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/vsg/tests/variable/test_rule_variable.py b/vsg/tests/variable/test_rule_variable.py deleted file mode 100644 index 037f9a9b..00000000 --- a/vsg/tests/variable/test_rule_variable.py +++ /dev/null @@ -1,25 +0,0 @@ -import os - -import unittest -import sys -sys.path.append('vsg') - -from vsg.rules import variable -from vsg import vhdlFile -from vsg.tests import utils - -# Read in test file used for all tests -lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','variable','variable_test_input.vhd')) -oFile = vhdlFile.vhdlFile(lFile) - -class testRuleVariableMethods(unittest.TestCase): - - - def test_rule_007(self): - oRule = variable.rule_007() - self.assertTrue(oRule) - self.assertEqual(oRule.name, 'variable') - self.assertEqual(oRule.identifier, '007') - dExpected = utils.add_violation_list([11,16]) - oRule.analyze(oFile) - self.assertEqual(oRule.violations, dExpected) diff --git a/vsg/tests/variable/variable_test_input.vhd b/vsg/tests/variable/variable_test_input.vhd deleted file mode 100644 index c60394e7..00000000 --- a/vsg/tests/variable/variable_test_input.vhd +++ /dev/null @@ -1,79 +0,0 @@ - - -architecture ARCH of ENTITY is - - variable a_sig : std_logic_vector(31 downto 0); - variable a_SIg : std_logic_vector(31 downto 0); - Variable b_sig: std_logic_vector(31 downto 0); - variable b_sig : std_logic_vector(31 downto 0); - variable siG : std_logic_vector(31 downto 0); - variable d_sig :std_logic_vector(31 downto 0); - varIAble e_sig: std_logic_vector(31 downto 0) := "0"; - variable SIg : STD_LOGIC_VECTOR(31 downto 0); - variabLE sig : std_logic_vector(GENERIC_1 downto 0); - variable sig :std_logic_vector(31 downto 0); - variable sIg : std_logic_vector(31 downto 0); - variable sig : std_logic_vector(31 downto 0) := (others => '0'); - - variable e_sig1, d_sig2 : STD_LOGIC; - variable a_sig1, c_sig2: std_logic; - variable b_sig1, b_sig2 :std_logic; - variable c_sig1, a_sig2:std_logic; - -begin - - PROC_1 : process (A) is - - variable p1_variable_1 : std_logic; - variable p1_variable_10 : integer; - variable p1_variable_long_10 : real; - - begin - - end process PROC_1; - - PROC_2 : process(B) is - - variable p1_var_1 : std_logic; - variable p1_var_10 : integer; - variable p1_var_long_10 : real; - - begin - - end process PROC_2; - - PROC_3 : process(C) is - - variable process1_variable_1 : std_logic; - variable process1_variable_10 : integer; - variable process1_variable_long_10 : real; - - begin - - end process PROC_3; - - PROC_4 : process(C) is - - variable clk_cnt : integer range SPI_2X_CLK_DIV - 1 downto 0; - - begin - - end process PROC_4; - - PROC_5 : process(C) is - - procedure test_p (x: integer) is - variable a, b : integer; - begin - end procedure; - - function test_f (x: integer) return integer is - variable c, d : integer; - begin - end function; - - begin - - end process PROC_5; - -end architecture ARCH;