From 5c2afa1e06c43e4f445e3387b3de77231b6c42d4 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Sun, 27 Jun 2021 22:46:28 +0200 Subject: Fixed MRO problems. --- pyGHDL/dom/InterfaceItem.py | 6 +----- pyGHDL/dom/Object.py | 33 ++++++--------------------------- pyGHDL/dom/formatting/prettyprint.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index c5955c6aa..97ef0cfe8 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -199,13 +199,9 @@ class ParameterConstantInterfaceItem( subType: SubTypeOrSymbol, defaultExpression: Expression = None, ): - super().__init__(name, mode) + super().__init__(name, mode, subType, defaultExpression) DOMMixin.__init__(self, node) - # TODO: move to model - self._subType = subType - self._defaultExpression = defaultExpression - @classmethod def parse(cls, parameterNode: Iir) -> "ParameterConstantInterfaceItem": name = GetNameOfNode(parameterNode) diff --git a/pyGHDL/dom/Object.py b/pyGHDL/dom/Object.py index 3085f9f81..0358f716d 100644 --- a/pyGHDL/dom/Object.py +++ b/pyGHDL/dom/Object.py @@ -62,13 +62,9 @@ class Constant(VHDLModel_Constant, DOMMixin): subType: SubTypeOrSymbol, defaultExpression: Expression, ): - super().__init__(name) + super().__init__(name, subType, defaultExpression) DOMMixin.__init__(self, node) - self._name = name - self._subType = subType - self._defaultExpression = defaultExpression - @classmethod def parse(cls, constantNode: Iir) -> Union["Constant", "DeferredConstant"]: from pyGHDL.dom._Translate import ( @@ -90,12 +86,9 @@ class Constant(VHDLModel_Constant, DOMMixin): @export class DeferredConstant(VHDLModel_DeferredConstant, DOMMixin): def __init__(self, node: Iir, name: str, subType: SubTypeOrSymbol): - super().__init__(name) + super().__init__(name, subType) DOMMixin.__init__(self, node) - self._name = name - self._subType = subType - @classmethod def parse(cls, constantNode: Iir) -> "DeferredConstant": from pyGHDL.dom._Translate import GetSubTypeIndicationFromNode @@ -117,13 +110,9 @@ class Variable(VHDLModel_Variable, DOMMixin): subType: SubTypeOrSymbol, defaultExpression: Expression, ): - super().__init__(name) + super().__init__(name, subType, defaultExpression) DOMMixin.__init__(self, node) - self._name = name - self._subType = subType - self._defaultExpression = defaultExpression - @classmethod def parse(cls, variableNode: Iir) -> "Variable": from pyGHDL.dom._Translate import ( @@ -144,12 +133,9 @@ class Variable(VHDLModel_Variable, DOMMixin): @export class SharedVariable(VHDLModel_SharedVariable, DOMMixin): def __init__(self, node: Iir, name: str, subType: SubTypeOrSymbol): - super().__init__(name) + super().__init__(name, subType) DOMMixin.__init__(self, node) - self._name = name - self._subType = subType - @classmethod def parse(cls, variableNode: Iir) -> "SharedVariable": from pyGHDL.dom._Translate import GetSubTypeIndicationFromNode @@ -169,13 +155,9 @@ class Signal(VHDLModel_Signal, DOMMixin): subType: SubTypeOrSymbol, defaultExpression: Expression, ): - super().__init__(name) + super().__init__(name, subType, defaultExpression) DOMMixin.__init__(self, node) - self._name = name - self._subType = subType - self._defaultExpression = defaultExpression - @classmethod def parse(cls, signalNode: Iir) -> "Signal": from pyGHDL.dom._Translate import ( @@ -194,12 +176,9 @@ class Signal(VHDLModel_Signal, DOMMixin): @export class File(VHDLModel_File, DOMMixin): def __init__(self, node: Iir, name: str, subType: SubTypeOrSymbol): - super().__init__(name) + super().__init__(name, subType) DOMMixin.__init__(self, node) - self._name = name - self._subType = subType - @classmethod def parse(cls, fileNode: Iir) -> "File": from pyGHDL.dom._Translate import GetSubTypeIndicationFromNode diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index fb1fcf826..cddfec458 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -44,6 +44,7 @@ from pyGHDL.dom.Object import Constant, Signal, SharedVariable, File from pyGHDL.dom.InterfaceItem import ( GenericConstantInterfaceItem, PortSignalInterfaceItem, + GenericTypeInterfaceItem, ) from pyGHDL.dom.Symbol import ( SimpleSubTypeSymbol, @@ -262,6 +263,8 @@ class PrettyPrint: ) -> StringBuffer: if isinstance(generic, GenericConstantInterfaceItem): return self.formatGenericConstant(generic, level) + elif isinstance(generic, GenericTypeInterfaceItem): + return self.formatGenericType(generic, level) else: raise PrettyPrintException( "Unhandled generic kind for generic '{name}'.".format(name=generic.Name) @@ -297,6 +300,21 @@ class PrettyPrint: return buffer + def formatGenericType( + self, generic: GenericConstantInterfaceItem, level: int = 0 + ) -> StringBuffer: + buffer = [] + prefix = " " * level + + buffer.append( + "{prefix} - type {name}".format( + prefix=prefix, + name=generic.Name, + ) + ) + + return buffer + def formatPortSignal( self, port: PortSignalInterfaceItem, level: int = 0 ) -> StringBuffer: -- cgit v1.2.3