diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-18 18:16:06 +0200 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-19 15:25:07 +0200 |
commit | 4e227b02c6ff0c12ce586295a88176a9af2c3889 (patch) | |
tree | 8bcc0194551711c4adbd35e04e50fbfe3ef5e764 /pyGHDL/dom | |
parent | cb0c13d82e6d8f12029ace572b8ae4e788dcfa9a (diff) | |
download | ghdl-4e227b02c6ff0c12ce586295a88176a9af2c3889.tar.gz ghdl-4e227b02c6ff0c12ce586295a88176a9af2c3889.tar.bz2 ghdl-4e227b02c6ff0c12ce586295a88176a9af2c3889.zip |
Format aggregates.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/Expression.py | 2 | ||||
-rw-r--r-- | pyGHDL/dom/formatting/prettyprint.py | 29 |
2 files changed, 29 insertions, 2 deletions
diff --git a/pyGHDL/dom/Expression.py b/pyGHDL/dom/Expression.py index bfe2cd9dd..505006d5b 100644 --- a/pyGHDL/dom/Expression.py +++ b/pyGHDL/dom/Expression.py @@ -401,5 +401,5 @@ class Aggregate(VHDLModel_Aggregate): ) ) - return choices + return cls(choices) diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 1f71c87d5..1167d41f4 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -2,6 +2,7 @@ from typing import List, Union from pydecor import export +from pyGHDL.dom.Aggregates import SimpleAggregateElement, IndexedAggregateElement, RangedAggregateElement, NamedAggregateElement, OthersAggregateElement from pyGHDL.dom.Object import Constant, Signal from pyVHDLModel.VHDLModel import ( GenericInterfaceItem, @@ -14,6 +15,7 @@ from pyVHDLModel.VHDLModel import ( IdentityExpression, UnaryExpression, WithDefaultExpression, + AggregateElement ) from pyGHDL import GHDLBaseException @@ -376,6 +378,31 @@ class PrettyPrint: operator=operator, ) elif isinstance(expression, Aggregate): - print(Aggregate.Elements[0]) + return "({choices})".format(choices=", ".join([self.formatAggregateElement(element) for element in expression.Elements])) else: raise PrettyPrintException("Unhandled expression kind.") + + def formatAggregateElement(self, aggregateElement: AggregateElement): + if isinstance(aggregateElement, SimpleAggregateElement): + return "{value}".format( + value=self.formatExpression(aggregateElement.Expression) + ) + elif isinstance(aggregateElement, IndexedAggregateElement): + return "{index} => {value}".format( + index=self.formatExpression(aggregateElement.Index), + value=self.formatExpression(aggregateElement.Expression) + ) + elif isinstance(aggregateElement, RangedAggregateElement): + return "{range} => {value}".format( + range=self.formatRange(aggregateElement.Range), + value=self.formatExpression(aggregateElement.Expression) + ) + elif isinstance(aggregateElement, NamedAggregateElement): + return "{name} => {value}".format( + name=aggregateElement.Name, + value=self.formatExpression(aggregateElement.Expression) + ) + elif isinstance(aggregateElement, OthersAggregateElement): + return "other => {value}".format( + value=self.formatExpression(aggregateElement.Expression) + ) |