diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-23 01:18:13 +0200 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-23 01:18:13 +0200 |
commit | 66425e5257c9cec2bdc428b761d59d887564daf6 (patch) | |
tree | f752fd034792a7bb921c09227189b202de59b5f6 /pyGHDL/dom/formatting | |
parent | 957566f47af6a5a10d38cc5f27551019165ea2f0 (diff) | |
download | ghdl-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.py | 42 |
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) |