From 34e150eb5a4e5b92ad7397ccb8b5c28c0cc2aff9 Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Thu, 17 Aug 2017 18:16:38 -0500 Subject: [PATCH] Adding rule for closing parenthesis in generics. --- modules/rule_entity.py | 34 +++++++++++++++++++ .../tests/rule_entity/entity_test_input.vhd | 12 +++++++ .../tests/rule_entity/rule_entity_tests.py | 12 +++++++ 3 files changed, 58 insertions(+) diff --git a/modules/rule_entity.py b/modules/rule_entity.py index 3920d8dd..2f0a69a6 100644 --- a/modules/rule_entity.py +++ b/modules/rule_entity.py @@ -761,3 +761,37 @@ class rule_032(entity_rule): if re.match('\s*entity', sLine.lower()): fEntityFound = True self.violations = lFailureLines + + +class rule_033(entity_rule): + '''Entity rule 033 checks the indentation of closing parenthesis for generic maps.''' + + def __init__(self): + entity_rule.__init__(self) + self.identifier = '033' + self.description = 'Closing parenthesis must be on a line by itself and above the "port" keyword.' + + def analyze(self, lines): + lFailureLines = [] + fEntityFound = False + fGenericMapFound = False + fClosingParenFound = False + for iLineNumber, sLine in enumerate(lines): + if fEntityFound: + if fGenericMapFound: + if re.match('^\s*\)', sLine): + if not re.match('^\s\s\)', sLine): + lFailureLines.append(iLineNumber + 1) + else: + fClosingParenFound = True + if re.match('^\s*port\s', sLine.lower()): + fEntityFound = False + fGenericMapFound = False + if not fClosingParenFound: + lFailureLines.append(iLineNumber + 1) + fClosingParenFound = False + if re.match('^\s*generic', sLine.lower()): + fGenericMapFound = True + if re.match('\s*entity', sLine.lower()): + fEntityFound = True + self.violations = lFailureLines diff --git a/modules/tests/rule_entity/entity_test_input.vhd b/modules/tests/rule_entity/entity_test_input.vhd index 1d547104..dac02a1f 100644 --- a/modules/tests/rule_entity/entity_test_input.vhd +++ b/modules/tests/rule_entity/entity_test_input.vhd @@ -89,3 +89,15 @@ entity ENTITY1 is IO_PORT3 : inout std_logic ); end ENTITY1 + + +entity ENTITY1 is + generic ( + G_GENERIC1 : std_logic := '0'; + G_GENERIC2 : std_logic := '1'); + port ( + I_PORT1 : in std_logic; + O_PORT2 : out std_logic; + IO_PORT3 : inout std_logic + ); +end ENTITY1 diff --git a/modules/tests/rule_entity/rule_entity_tests.py b/modules/tests/rule_entity/rule_entity_tests.py index e8d33a07..aa1d4703 100644 --- a/modules/tests/rule_entity/rule_entity_tests.py +++ b/modules/tests/rule_entity/rule_entity_tests.py @@ -435,6 +435,18 @@ class testRuleEntityMethods(unittest.TestCase): oRule.analyze(lLines) self.assertEqual(oRule.violations, dExpected) + def test_rule_033_exists(self): + oRule = rule_entity.rule_033() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'entity') + self.assertEqual(oRule.identifier, '033') + + def test_rule_033(self): + oRule = rule_entity.rule_033() + + dExpected = [98] + oRule.analyze(lLines) + self.assertEqual(oRule.violations, dExpected) if __name__ == '__main__': unittest.main()