aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/_Translate.py
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-23 13:29:23 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-23 13:29:23 +0200
commit11f1ebbc80250555474cfe22e1db10553e112a11 (patch)
treed50bd491e0f077a951ce81332546a6eb29e2e156 /pyGHDL/dom/_Translate.py
parentd97e2079a633736d0323e915cabff5f91cfd4ebe (diff)
downloadghdl-11f1ebbc80250555474cfe22e1db10553e112a11.tar.gz
ghdl-11f1ebbc80250555474cfe22e1db10553e112a11.tar.bz2
ghdl-11f1ebbc80250555474cfe22e1db10553e112a11.zip
Handle 'Subtype_Definition' in record definitions.
Diffstat (limited to 'pyGHDL/dom/_Translate.py')
-rw-r--r--pyGHDL/dom/_Translate.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py
index 47d8c0b75..cb9448f09 100644
--- a/pyGHDL/dom/_Translate.py
+++ b/pyGHDL/dom/_Translate.py
@@ -59,8 +59,9 @@ from pyGHDL.dom.Common import DOMException
from pyGHDL.dom.Symbol import (
SimpleObjectOrFunctionCallSymbol,
SimpleSubTypeSymbol,
- ConstrainedSubTypeSymbol,
+ ConstrainedCompositeSubTypeSymbol,
IndexedObjectOrFunctionCallSymbol,
+ ConstrainedScalarSubTypeSymbol,
)
from pyGHDL.dom.Type import (
IntegerType,
@@ -133,6 +134,12 @@ def GetArrayConstraintsFromSubtypeIndication(
if constraintKind == nodes.Iir_Kind.Range_Expression:
constraints.append(RangeExpression(GetRangeFromNode(constraint)))
elif constraintKind == nodes.Iir_Kind.Attribute_Name:
+ name = GetNameOfNode(constraint)
+ prefix = nodes.Get_Prefix(constraint)
+ name2 = GetNameOfNode(prefix)
+ kind2 = GetIirKindOfNode(prefix)
+ print(name2, kind2, name)
+
raise DOMException("[NOT IMPLEMENTED] Attribute name as range.")
elif constraintKind == nodes.Iir_Kind.Simple_Name:
raise DOMException("[NOT IMPLEMENTED] Subtype as range.")
@@ -205,8 +212,10 @@ def GetSubTypeIndicationFromIndicationNode(
return GetSimpleTypeFromNode(subTypeIndicationNode)
elif kind == nodes.Iir_Kind.Selected_Name:
return GetSimpleTypeFromNode(subTypeIndicationNode)
+ elif kind == nodes.Iir_Kind.Subtype_Definition:
+ return GetScalarConstrainedSubTypeFromNode(subTypeIndicationNode)
elif kind == nodes.Iir_Kind.Array_Subtype_Definition:
- return GetConstrainedSubTypeFromNode(subTypeIndicationNode)
+ return GetCompositeConstrainedSubTypeFromNode(subTypeIndicationNode)
else:
raise DOMException(
"Unknown kind '{kind}' for an subtype indication in a {entity} of `{name}`.".format(
@@ -222,14 +231,25 @@ def GetSimpleTypeFromNode(subTypeIndicationNode: Iir) -> SimpleSubTypeSymbol:
@export
-def GetConstrainedSubTypeFromNode(
+def GetScalarConstrainedSubTypeFromNode(
+ subTypeIndicationNode: Iir,
+) -> ConstrainedScalarSubTypeSymbol:
+ typeMark = nodes.Get_Subtype_Type_Mark(subTypeIndicationNode)
+ typeMarkName = GetNameOfNode(typeMark)
+ rangeConstraint = nodes.Get_Range_Constraint(subTypeIndicationNode)
+ r = GetRangeFromNode(rangeConstraint)
+ return ConstrainedScalarSubTypeSymbol(typeMarkName, r)
+
+
+@export
+def GetCompositeConstrainedSubTypeFromNode(
subTypeIndicationNode: Iir,
-) -> ConstrainedSubTypeSymbol:
+) -> ConstrainedCompositeSubTypeSymbol:
typeMark = nodes.Get_Subtype_Type_Mark(subTypeIndicationNode)
typeMarkName = GetNameOfNode(typeMark)
constraints = GetArrayConstraintsFromSubtypeIndication(subTypeIndicationNode)
- return ConstrainedSubTypeSymbol(typeMarkName, constraints)
+ return ConstrainedCompositeSubTypeSymbol(typeMarkName, constraints)
@export