From 66425e5257c9cec2bdc428b761d59d887564daf6 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Wed, 23 Jun 2021 01:18:13 +0200 Subject: Better type handling. --- pyGHDL/dom/formatting/prettyprint.py | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'pyGHDL/dom/formatting') 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) -- cgit v1.2.3