aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/formatting
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/formatting
parent957566f47af6a5a10d38cc5f27551019165ea2f0 (diff)
downloadghdl-66425e5257c9cec2bdc428b761d59d887564daf6.tar.gz
ghdl-66425e5257c9cec2bdc428b761d59d887564daf6.tar.bz2
ghdl-66425e5257c9cec2bdc428b761d59d887564daf6.zip
Better type handling.
Diffstat (limited to 'pyGHDL/dom/formatting')
-rw-r--r--pyGHDL/dom/formatting/prettyprint.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py
index c4f76acaa..26a5d1916 100644
--- a/pyGHDL/dom/formatting/prettyprint.py
+++ b/pyGHDL/dom/formatting/prettyprint.py
@@ -4,13 +4,22 @@ from pydecor import export
from pyGHDL.dom.Misc import Alias
from pyGHDL.dom.Subprogram import Procedure
-from pyGHDL.dom.Type import IntegerType, SubType
+from pyGHDL.dom.Type import (
+ IntegerType,
+ SubType,
+ ArrayType,
+ RecordType,
+ AccessType,
+ EnumeratedType,
+)
from pyVHDLModel.VHDLModel import (
GenericInterfaceItem,
NamedEntity,
PortInterfaceItem,
WithDefaultExpression,
Function,
+ BaseType,
+ Type,
)
from pyGHDL import GHDLBaseException
@@ -325,15 +334,9 @@ class PrettyPrint:
else "",
)
)
- elif isinstance(item, IntegerType):
+ elif isinstance(item, Type):
buffer.append(
- "{prefix}- type {name} is range {range}".format(
- prefix=prefix,
- name=item.Name,
- range="{left!s} to {right!s}".format(
- left=item.LeftBound, right=item.RightBound
- ),
- )
+ "{prefix}- {type}".format(prefix=prefix, type=self.formatType(item))
)
elif isinstance(item, SubType):
buffer.append(
@@ -374,6 +377,27 @@ class PrettyPrint:
return buffer
+ def formatType(self, item: BaseType) -> str:
+ result = "type {name} is ".format(name=item.Name)
+ if isinstance(item, IntegerType):
+ result += "range {left!s} to {right!s}".format(
+ left=item.LeftBound, right=item.RightBound
+ )
+ elif isinstance(item, EnumeratedType):
+ result += "(........)"
+ elif isinstance(item, ArrayType):
+ result += "array(........) of ....."
+ elif isinstance(item, RecordType):
+ result += "record ..... end record"
+ elif isinstance(item, AccessType):
+ result += "access ....."
+ else:
+ raise PrettyPrintException(
+ "Unknown type '{name}'".format(name=item.__class__.__name__)
+ )
+
+ return result
+
def formatSubtypeIndication(self, subTypeIndication, entity: str, name: str) -> str:
if isinstance(subTypeIndication, SimpleSubTypeSymbol):
return "{type}".format(type=subTypeIndication.SymbolName)