aboutsummaryrefslogtreecommitdiffstats
path: root/pyGHDL/dom/formatting/prettyprint.py
diff options
context:
space:
mode:
authorPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-18 18:16:06 +0200
committerPatrick Lehmann <Patrick.Lehmann@plc2.de>2021-06-19 15:25:07 +0200
commit4e227b02c6ff0c12ce586295a88176a9af2c3889 (patch)
tree8bcc0194551711c4adbd35e04e50fbfe3ef5e764 /pyGHDL/dom/formatting/prettyprint.py
parentcb0c13d82e6d8f12029ace572b8ae4e788dcfa9a (diff)
downloadghdl-4e227b02c6ff0c12ce586295a88176a9af2c3889.tar.gz
ghdl-4e227b02c6ff0c12ce586295a88176a9af2c3889.tar.bz2
ghdl-4e227b02c6ff0c12ce586295a88176a9af2c3889.zip
Format aggregates.
Diffstat (limited to 'pyGHDL/dom/formatting/prettyprint.py')
-rw-r--r--pyGHDL/dom/formatting/prettyprint.py29
1 files changed, 28 insertions, 1 deletions
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)
+ )