aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/_Translate.py
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-23 01:18:13 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-23 01:18:13 +0200
commit66425e5257c9cec2bdc428b761d59d887564daf6 (patch)
treef752fd034792a7bb921c09227189b202de59b5f6 /pyGHDL/dom/_Translate.py
parent957566f47af6a5a10d38cc5f27551019165ea2f0 (diff)
downloadghdl-66425e5257c9cec2bdc428b761d59d887564daf6.tar.gz
ghdl-66425e5257c9cec2bdc428b761d59d887564daf6.tar.bz2
ghdl-66425e5257c9cec2bdc428b761d59d887564daf6.zip
Better type handling.
Diffstat (limited to 'pyGHDL/dom/_Translate.py')
-rw-r--r--pyGHDL/dom/_Translate.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py
index 3771b57f5..7239da77c 100644
--- a/pyGHDL/dom/_Translate.py
+++ b/pyGHDL/dom/_Translate.py
@@ -57,7 +57,7 @@ from pyGHDL.dom.Symbol import (
ConstrainedSubTypeSymbol,
IndexedObjectOrFunctionCallSymbol,
)
-from pyGHDL.dom.Type import IntegerType, SubType
+from pyGHDL.dom.Type import IntegerType, SubType, ArrayType, RecordType, EnumeratedType
from pyGHDL.dom.Range import Range, RangeExpression
from pyGHDL.dom.Literal import (
IntegerLiteral,
@@ -181,10 +181,37 @@ def GetArrayConstraintsFromSubtypeIndication(
@export
def GetTypeFromNode(node: Iir) -> BaseType:
typeName = GetNameOfNode(node)
- leftBound = IntegerLiteral(0)
- rightBound = IntegerLiteral(15)
+ typeDefinition = nodes.Get_Type_Definition(node)
+ kind = GetIirKindOfNode(typeDefinition)
+ if kind == nodes.Iir_Kind.Range_Expression:
+ r = GetRangeFromNode(typeDefinition)
+
+ return IntegerType(typeName, r)
+ elif kind == nodes.Iir_Kind.Enumeration_Type_Definition:
+
+ return EnumeratedType(typeName)
+ elif kind == nodes.Iir_Kind.Array_Type_Definition:
+ indexSubTypeDefinitionList = nodes.Get_Index_Subtype_Definition_List(
+ typeDefinition
+ )
+ elementSubTypeIndication = nodes.Get_Element_Subtype_Indication(typeDefinition)
+
+ return ArrayType(typeName)
+ elif kind == nodes.Iir_Kind.Record_Type_Definition:
- return IntegerType(typeName, leftBound, rightBound)
+ return RecordType(typeName)
+ else:
+ position = GetPositionOfNode(typeDefinition)
+ raise DOMException(
+ "Unknown type definition kind '{kindName}'({kind}) for type '{name}' at {file}:{line}:{column}.".format(
+ kind=kind,
+ kindName=kind.name,
+ name=typeName,
+ file=position.Filename,
+ line=position.Line,
+ column=position.Column,
+ )
+ )
@export