Skip to content

Commit

Permalink
v0.10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels authored Jun 23, 2021
2 parents 4816241 + c8df413 commit a93ad17
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 57 deletions.
2 changes: 1 addition & 1 deletion doc/LanguageModel/TypeDefinitions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Record
# from RecordType
@property
def Members(self) -> List[RecordTypeMember]:
def Members(self) -> List[RecordTypeElement]:
.. _vhdlmodel-protectedtypes:
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _LatestTagName():

# The full version, including alpha/beta/rc tags
version = "0.9" # The short X.Y version.
release = "0.10.2" # The full version, including alpha/beta/rc tags.
release = "0.10.3" # The full version, including alpha/beta/rc tags.
try:
if _IsUnderGitControl:
latestTagName = _LatestTagName()[1:] # remove prefix "v"
Expand Down
169 changes: 117 additions & 52 deletions pyVHDLModel/VHDLModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
# load dependencies
from enum import Enum
from pathlib import Path
from typing import List, Tuple, Union
from typing import List, Tuple, Union, Dict

try:
from typing import Protocol
except ImportError:
Expand Down Expand Up @@ -325,7 +326,21 @@ def __init__(self, subTypeName: str):


@export
class ConstrainedSubTypeSymbol(SubTypeSymbol):
class ConstrainedScalarSubTypeSymbol(SubTypeSymbol):
_range: 'Range'

def __init__(self, subTypeName: str, range: 'Range' = None):
super().__init__(symbolName = subTypeName)
self._subType = None
self._range = range

@property
def Range(self) -> 'Range':
return self._range


@export
class ConstrainedCompositeSubTypeSymbol(SubTypeSymbol):
_constraints: List[Constraint]

def __init__(self, subTypeName: str, constraints: List[Constraint] = None):
Expand Down Expand Up @@ -443,17 +458,17 @@ class Design(ModelEntity):
and analysed. It's the root of this document-object-model (DOM). It contains
at least on VHDL library (see :class:`~pyVHDLModel.VHDLModel.Library`).
"""
_libraries: List['Library'] #: List of all libraries defined for a design.
_libraries: Dict[str, 'Library'] #: List of all libraries defined for a design.
_documents: List['Document'] #: List of all documents loaded for a design.

def __init__(self):
super().__init__()

self._libraries = []
self._libraries = {}
self._documents = []

@property
def Libraries(self) -> List['Library']:
def Libraries(self) -> Dict[str, 'Library']:
"""Returns a list of all libraries specified for this design."""
return self._libraries

Expand All @@ -462,6 +477,30 @@ def Documents(self) -> List['Document']:
"""Returns a list of all documents (files) loaded for this design."""
return self._documents

def GetLibrary(self, libraryName: str) -> 'Library':
if libraryName not in self._libraries:
lib = Library(libraryName)
self._libraries[libraryName] = lib
else:
lib = self._libraries[libraryName]

return lib

def AddDocument(self, document: 'Document', library: 'Library') -> None:
self._documents.append(document)

for entity in document.Entities:
library.Entities.append(entity)

for package in document.Packages:
library.Packages.append(package)

for configuration in document.Configurations:
library.Configurations.append(configuration)

for context in document.Contexts:
library.Contexts.append(context)


@export
class Library(ModelEntity, NamedEntity):
Expand Down Expand Up @@ -622,7 +661,7 @@ def ResolutionFunction(self) -> 'Function':


@export
class ScalarType(BaseType):
class ScalarType(Type):
"""
A ``ScalarType`` is a base-class for all scalar types.
"""
Expand Down Expand Up @@ -661,39 +700,55 @@ class DiscreteType:


@export
class CompositeType(BaseType):
class CompositeType(Type):
"""
A ``CompositeType`` is a base-class for all composite types.
"""


@export
class ProtectedType(BaseType):
class ProtectedType(Type):
pass


@export
class AccessType(BaseType):
pass
class AccessType(Type):
_designatedSubType: SubTypeOrSymbol

def __init__(self, name: str, designatedSubType: SubTypeOrSymbol):
super().__init__(name)
self._designatedSubType = designatedSubType

@property
def DesignatedSubtype(self):
return self._designatedSubType


@export
class FileType(BaseType):
pass
class FileType(Type):
_designatedSubType: SubTypeOrSymbol

def __init__(self, name: str, designatedSubType: SubTypeOrSymbol):
super().__init__(name)
self._designatedSubType = designatedSubType

@property
def DesignatedSubtype(self):
return self._designatedSubType


@export
class EnumeratedType(ScalarType, DiscreteType):
_elements: List['EnumerationLiteral']
_literals: List['EnumerationLiteral']

def __init__(self, name: str):
def __init__(self, name: str, literals: List['EnumerationLiteral']):
super().__init__(name)

self._elements = []
self._literals = [] if literals is None else [l for l in literals]

@property
def Elements(self) -> List['EnumerationLiteral']:
return self._elements
def Literals(self) -> List['EnumerationLiteral']:
return self._literals


@export
Expand Down Expand Up @@ -732,7 +787,7 @@ class ArrayType(CompositeType):
_dimensions: List['Range']
_elementType: SubType

def __init__(self, name: str):
def __init__(self, name: str, indices: List, elementSubType: SubTypeOrSymbol):
super().__init__(name)

self._dimensions = []
Expand All @@ -747,33 +802,37 @@ def ElementType(self) -> SubType:


@export
class RecordTypeMember(ModelEntity):
class RecordTypeElement(ModelEntity):
_name: str
_subType: SubType
_subType: SubTypeOrSymbol

def __init__(self, name: str):
def __init__(self, name: str, subType: SubTypeOrSymbol):
super().__init__()

self._name = name
self._subType = None
self._name = name
self._subType = subType

@property
def Name(self) -> str:
return self._name

@property
def SubType(self) -> SubTypeOrSymbol:
return self._subType


@export
class RecordType(CompositeType):
_members: List[RecordTypeMember]
_elements: List[RecordTypeElement]

def __init__(self, name: str):
def __init__(self, name: str, elements: List[RecordTypeElement] = None):
super().__init__(name)

self._members = []
self._elements = [] if elements is None else [i for i in elements]

@property
def Members(self) -> List[RecordTypeMember]:
return self._members
def Elements(self) -> List[RecordTypeElement]:
return self._elements


@export
Expand Down Expand Up @@ -1428,6 +1487,11 @@ class Variable(Object, WithDefaultExpression):
pass


@export
class SharedVariable(Object):
pass


@export
class Signal(Object, WithDefaultExpression):
pass
Expand Down Expand Up @@ -1769,19 +1833,19 @@ def PackageReferences(self) -> List[UseStatement]:

@export
class Entity(PrimaryUnit, MixinDesignUnitWithContext):
_genericItems: List[GenericInterfaceItem]
_portItems: List[PortInterfaceItem]
_declaredItems: List # FIXME: define list element type e.g. via Union
_bodyItems: List['ConcurrentStatement']
_genericItems: List[GenericInterfaceItem]
_portItems: List[PortInterfaceItem]
_declaredItems: List # FIXME: define list element type e.g. via Union
_bodyItems: List['ConcurrentStatement']

def __init__(self, name: str):
def __init__(self, name: str, genericItems: List[GenericInterfaceItem] = None, portItems: List[PortInterfaceItem] = None, declaredItems: List = None, bodyItems: List['ConcurrentStatement'] = None):
super().__init__(name)
MixinDesignUnitWithContext.__init__(self)

self._genericItems = []
self._portItems = []
self._declaredItems = []
self._bodyItems = []
self._genericItems = [] if genericItems is None else [g for g in genericItems]
self._portItems = [] if portItems is None else [p for p in portItems]
self._declaredItems = [] if declaredItems is None else [i for i in declaredItems]
self._bodyItems = [] if bodyItems is None else [i for i in bodyItems]

@property
def GenericItems(self) -> List[GenericInterfaceItem]:
Expand All @@ -1802,19 +1866,20 @@ def BodyItems(self) -> List['ConcurrentStatement']:

@export
class Architecture(SecondaryUnit, MixinDesignUnitWithContext):
_entity: Entity
_declaredItems: List # FIXME: define list element type e.g. via Union
_bodyItems: List['ConcurrentStatement']
_entity: EntityOrSymbol
_declaredItems: List # FIXME: define list element type e.g. via Union
_bodyItems: List['ConcurrentStatement']

def __init__(self, name: str):
def __init__(self, name: str, entity: EntityOrSymbol, declaredItems: List = None, bodyItems: List['ConcurrentStatement'] = None):
super().__init__(name)
MixinDesignUnitWithContext.__init__(self)

self._declaredItems = []
self._bodyItems = []
self._entity = entity
self._declaredItems = [] if declaredItems is None else [i for i in declaredItems]
self._bodyItems = [] if bodyItems is None else [i for i in bodyItems]

@property
def Entity(self) -> Entity:
def Entity(self) -> EntityOrSymbol:
return self._entity

@property
Expand All @@ -1831,12 +1896,12 @@ class Component(ModelEntity, NamedEntity):
_genericItems: List[GenericInterfaceItem]
_portItems: List[PortInterfaceItem]

def __init__(self, name: str):
def __init__(self, name: str, genericItems: List[GenericInterfaceItem] = None, portItems: List[PortInterfaceItem] = None):
super().__init__()
NamedEntity.__init__(self, name)

self._genericItems = []
self._portItems = []
self._genericItems = [] if genericItems is None else [g for g in genericItems]
self._portItems = [] if portItems is None else [p for p in portItems]

@property
def GenericItems(self) -> List[GenericInterfaceItem]:
Expand Down Expand Up @@ -1914,12 +1979,12 @@ class Package(PrimaryUnit, MixinDesignUnitWithContext):
_genericItems: List[GenericInterfaceItem]
_declaredItems: List

def __init__(self, name: str):
def __init__(self, name: str, genericItems: List[GenericInterfaceItem] = None, declaredItems: List = None):
super().__init__(name)
MixinDesignUnitWithContext.__init__(self)

self._genericItems = []
self._declaredItems = []
self._genericItems = [] if genericItems is None else [g for g in genericItems]
self._declaredItems = [] if declaredItems is None else [i for i in declaredItems]

@property
def GenericItems(self) -> List[GenericInterfaceItem]:
Expand All @@ -1935,11 +2000,11 @@ class PackageBody(SecondaryUnit, MixinDesignUnitWithContext):
_package: Package
_declaredItems: List

def __init__(self, name: str):
def __init__(self, name: str, declaredItems: List = None):
super().__init__(name)
MixinDesignUnitWithContext.__init__(self)

self._declaredItems = []
self._declaredItems = [] if declaredItems is None else [i for i in declaredItems]

@property
def Package(self) -> Package:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
# Assemble all package information
setuptools_setup(
name=projectName,
version="0.10.2",
version="0.10.3",

author="Patrick Lehmann",
author_email="Paebbels@gmail.com",
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/Instantiate.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def test_Entity(self):
self.assertTrue(len(entity.BodyItems) == 0)

def test_Architecture(self):
architecture = Architecture("arch_1")
entity = Entity("entity_1")
architecture = Architecture("arch_1", entity)

self.assertIsNotNone(architecture)
self.assertTrue(architecture.Name == "arch_1")
Expand Down Expand Up @@ -142,7 +143,7 @@ def test_Real(self):
self.assertTrue(real.Name == "real")

def test_Array(self):
array = ArrayType("bit_vector")
array = ArrayType("bit_vector", [], None)

self.assertIsNotNone(array)
self.assertTrue(array.Name == "bit_vector")
Expand Down

0 comments on commit a93ad17

Please sign in to comment.