aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-29 14:40:22 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-07-01 06:39:46 +0200
commit87e356ef6c674393bba497019db13c90f2e8bd86 (patch)
tree8a245d8cd425311d547b6904bd68714bbc4d184a
parentac702e68dd4287e1639c9f2efe4421cf1f3a0910 (diff)
downloadghdl-87e356ef6c674393bba497019db13c90f2e8bd86.tar.gz
ghdl-87e356ef6c674393bba497019db13c90f2e8bd86.tar.bz2
ghdl-87e356ef6c674393bba497019db13c90f2e8bd86.zip
Reworked scalar types created from ranges.
-rw-r--r--pyGHDL/dom/Type.py21
-rw-r--r--pyGHDL/dom/_Translate.py4
-rw-r--r--pyGHDL/dom/formatting/prettyprint.py4
3 files changed, 17 insertions, 12 deletions
diff --git a/pyGHDL/dom/Type.py b/pyGHDL/dom/Type.py
index ea4765ed1..3d388956b 100644
--- a/pyGHDL/dom/Type.py
+++ b/pyGHDL/dom/Type.py
@@ -46,8 +46,9 @@ from pyVHDLModel.VHDLModel import (
FileType as VHDLModel_FileType,
ProtectedType as VHDLModel_ProtectedType,
ProtectedTypeBody as VHDLModel_ProtectedTypeBody,
- SubType as VHDLModel_SubType,
- SubTypeOrSymbol,
+ Subtype as VHDLModel_Subtype,
+ SubtypeOrSymbol,
+ Name,
)
from pyGHDL.libghdl import utils
from pyGHDL.libghdl._types import Iir
@@ -92,13 +93,10 @@ class EnumeratedType(VHDLModel_EnumeratedType, DOMMixin):
@export
class IntegerType(VHDLModel_IntegerType, DOMMixin):
- def __init__(self, node: Iir, typeName: str, range: Range):
- super().__init__(typeName)
+ def __init__(self, node: Iir, typeName: str, rng: Union[Range, "Name"]):
+ super().__init__(typeName, rng)
DOMMixin.__init__(self, node)
- self._leftBound = range.LeftBound
- self._rightBound = range.RightBound
-
@export
class PhysicalType(VHDLModel_PhysicalType, DOMMixin):
@@ -106,14 +104,19 @@ class PhysicalType(VHDLModel_PhysicalType, DOMMixin):
self,
node: Iir,
typeName: str,
+ rng: Union[Range, Name],
primaryUnit: str,
units: List[Tuple[str, PhysicalIntegerLiteral]],
):
- super().__init__(typeName, primaryUnit, units)
+ super().__init__(typeName, rng, primaryUnit, units)
DOMMixin.__init__(self, node)
@classmethod
def parse(cls, typeName: str, typeDefinitionNode: Iir) -> "PhysicalType":
+ from pyGHDL.dom._Translate import GetRangeFromNode
+
+ rng = GetRangeFromNode(nodes.Get_Range_Constraint(typeDefinitionNode))
+
primaryUnit = nodes.Get_Primary_Unit(typeDefinitionNode)
primaryUnitName = GetNameOfNode(primaryUnit)
@@ -129,7 +132,7 @@ class PhysicalType(VHDLModel_PhysicalType, DOMMixin):
units.append((secondaryUnitName, physicalLiteral))
- return cls(typeDefinitionNode, typeName, primaryUnitName, units)
+ return cls(typeDefinitionNode, typeName, rng, primaryUnitName, units)
@export
diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py
index 89f25138f..1c97d403e 100644
--- a/pyGHDL/dom/_Translate.py
+++ b/pyGHDL/dom/_Translate.py
@@ -270,6 +270,10 @@ def GetAnonymousTypeFromNode(node: Iir) -> BaseType:
r = GetRangeFromNode(typeDefinition)
return IntegerType(node, typeName, r)
+ elif kind == nodes.Iir_Kind.Parenthesis_Name:
+ n = GetNameFromNode(typeDefinition)
+
+ return IntegerType(node, typeName, n)
elif kind == nodes.Iir_Kind.Physical_Type_Definition:
return PhysicalType.parse(typeName, typeDefinition)
diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py
index 98e17a5d0..9fb412d09 100644
--- a/pyGHDL/dom/formatting/prettyprint.py
+++ b/pyGHDL/dom/formatting/prettyprint.py
@@ -486,9 +486,7 @@ class PrettyPrint:
if isinstance(item, IncompleteType):
result += ""
elif isinstance(item, IntegerType):
- result += "range {left!s} to {right!s}".format(
- left=item.LeftBound, right=item.RightBound
- )
+ result += "range {range!s}".format(range=item.Range)
elif isinstance(item, EnumeratedType):
result += "(........)"
elif isinstance(item, PhysicalType):