Skip to content

Commit

Permalink
Removed unnused constant parsing code. Fixes issue #59.
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Jul 16, 2015
1 parent 4f60c1e commit c8b7e60
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
6 changes: 2 additions & 4 deletions vunit/com/codec_vhdl_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class CodecVHDLPackage(VHDLPackage):
"""Class derived from VHDLPackage to provide codec generator functionality for the data types definied
in the package."""

def __init__(self, identifier, constant_declarations, # pylint: disable=too-many-arguments
def __init__(self, identifier,
enumeration_types, record_types, array_types):
super(CodecVHDLPackage, self).__init__(identifier,
constant_declarations,
enumeration_types,
record_types,
array_types)
Expand All @@ -35,12 +34,11 @@ def parse(cls, code):
"""
# Extract identifier
identifier = cls._package_start_re.match(code).group('id')
constant_declarations = cls._find_constant_declarations(code)
enumeration_types = [e for e in CodecVHDLEnumerationType.find(code)]
record_types = [r for r in CodecVHDLRecordType.find(code)]
array_types = [a for a in CodecVHDLArrayType.find(code)]

return cls(identifier, constant_declarations, enumeration_types, record_types, array_types)
return cls(identifier, enumeration_types, record_types, array_types)

@classmethod
def find_named_package(cls, code, name):
Expand Down
17 changes: 0 additions & 17 deletions vunit/test/unit/test_vhdl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,6 @@ def test_parsing_simple_package(self):
""")
self.assertEqual(package.identifier, "simple")

def test_parsing_package_with_constants(self):
package = self.parse_single_package("""\
package name is
constant foo : integer := 15 - 1 * 2;
constant bar : boolean := false or true;
end package;
""")
self.assertEqual(package.identifier, "name")
constants = package.constant_declarations
self.assertEqual(len(constants), 2)
self.assertEqual(constants[0].identifier, "foo")
self.assertEqual(constants[0].expression, "15 - 1 * 2")
self.assertEqual(constants[0].subtype_indication.type_mark, "integer")
self.assertEqual(constants[1].identifier, "bar")
self.assertEqual(constants[1].expression, "false or true")
self.assertEqual(constants[1].subtype_indication.type_mark, "boolean")

def test_parsing_context(self):
context = self.parse_single_context("""\
context foo is
Expand Down
28 changes: 2 additions & 26 deletions vunit/vhdl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,9 @@ class VHDLPackage(object):
"""
Representation of a VHDL package
"""
def __init__(self, identifier, constant_declarations, # pylint: disable=too-many-arguments
def __init__(self, identifier,
enumeration_types, record_types, array_types):
self.identifier = identifier
self.constant_declarations = constant_declarations
self.enumeration_types = enumeration_types
self.record_types = record_types
self.array_types = array_types
Expand Down Expand Up @@ -251,34 +250,11 @@ def parse(cls, code):
"""
# Extract identifier
identifier = cls._package_start_re.match(code).group('id')
constant_declarations = cls._find_constant_declarations(code)
enumeration_types = [e for e in VHDLEnumerationType.find(code)]
record_types = [r for r in VHDLRecordType.find(code)]
array_types = [a for a in VHDLArrayType.find(code)]

return cls(identifier, constant_declarations, enumeration_types, record_types, array_types)

@classmethod
def _find_constant_declarations(cls, code):
"""
Append all constant declarations found within the code to constant_declarations list
"""
re_flags = re.MULTILINE | re.IGNORECASE | re.VERBOSE
constant_start = re.compile(r"""
^ # Beginning of line
[\s]* # Potential whitespaces
constant # constant keyword
\s+ # At least one whitespace
(?P<id>[a-zA-Z][\w]*) # An identifier
[\s]* # Potential whitespaces
: # Colon
""", re_flags)

constant_declarations = []
for constant in constant_start.finditer(code):
sub_code = code[constant.start():].strip().splitlines()[0].strip()
constant_declarations.append(VHDLConstantDeclaration.parse(sub_code))
return constant_declarations
return cls(identifier, enumeration_types, record_types, array_types)


class VHDLEntity(object):
Expand Down

0 comments on commit c8b7e60

Please sign in to comment.