diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-23 13:29:23 +0200 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-23 13:29:23 +0200 |
commit | 11f1ebbc80250555474cfe22e1db10553e112a11 (patch) | |
tree | d50bd491e0f077a951ce81332546a6eb29e2e156 /pyGHDL/dom | |
parent | d97e2079a633736d0323e915cabff5f91cfd4ebe (diff) | |
download | ghdl-11f1ebbc80250555474cfe22e1db10553e112a11.tar.gz ghdl-11f1ebbc80250555474cfe22e1db10553e112a11.tar.bz2 ghdl-11f1ebbc80250555474cfe22e1db10553e112a11.zip |
Handle 'Subtype_Definition' in record definitions.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/Symbol.py | 16 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 30 | ||||
-rw-r--r-- | pyGHDL/dom/formatting/prettyprint.py | 4 |
3 files changed, 41 insertions, 9 deletions
diff --git a/pyGHDL/dom/Symbol.py b/pyGHDL/dom/Symbol.py index cde02ba5e..d6d348f14 100644 --- a/pyGHDL/dom/Symbol.py +++ b/pyGHDL/dom/Symbol.py @@ -33,10 +33,12 @@ from typing import List, Iterator from pydecor import export +from pyGHDL.dom.Range import Range from pyVHDLModel.VHDLModel import ( EntitySymbol as VHDLModel_EntitySymbol, SimpleSubTypeSymbol as VHDLModel_SimpleSubTypeSymbol, - ConstrainedSubTypeSymbol as VHDLModel_ConstrainedSubTypeSymbol, + ConstrainedScalarSubTypeSymbol as VHDLModel_ConstrainedScalarSubTypeSymbol, + ConstrainedCompositeSubTypeSymbol as VHDLModel_ConstrainedCompositeSubTypeSymbol, EnumerationLiteralSymbol as VHDLModel_EnumerationLiteralSymbol, SimpleObjectOrFunctionCallSymbol as VHDLModel_SimpleObjectOrFunctionCallSymbol, IndexedObjectOrFunctionCallSymbol as VHDLModel_IndexedObjectOrFunctionCallSymbol, @@ -73,7 +75,17 @@ class SimpleSubTypeSymbol(VHDLModel_SimpleSubTypeSymbol): @export -class ConstrainedSubTypeSymbol(VHDLModel_ConstrainedSubTypeSymbol): +class ConstrainedScalarSubTypeSymbol(VHDLModel_ConstrainedScalarSubTypeSymbol): + def __init__(self, subTypeName: str, range: Range = None): + super().__init__(subTypeName=subTypeName, range=range) + + @classmethod + def parse(cls, node): + pass + + +@export +class ConstrainedCompositeSubTypeSymbol(VHDLModel_ConstrainedCompositeSubTypeSymbol): def __init__(self, subTypeName: str, constraints: List[Constraint] = None): super().__init__(subTypeName=subTypeName, constraints=constraints) 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 diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 3a0a49cc1..10def8503 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -40,7 +40,7 @@ from pyGHDL.dom.InterfaceItem import ( ) from pyGHDL.dom.Symbol import ( SimpleSubTypeSymbol, - ConstrainedSubTypeSymbol, + ConstrainedCompositeSubTypeSymbol, ) @@ -401,7 +401,7 @@ class PrettyPrint: def formatSubtypeIndication(self, subTypeIndication, entity: str, name: str) -> str: if isinstance(subTypeIndication, SimpleSubTypeSymbol): return "{type}".format(type=subTypeIndication.SymbolName) - elif isinstance(subTypeIndication, ConstrainedSubTypeSymbol): + elif isinstance(subTypeIndication, ConstrainedCompositeSubTypeSymbol): ranges = [str(c.Range) for c in subTypeIndication.Constraints] constraints = ", ".join(ranges) |