From 0c726ac36be1ad1cba24eb7eff476b9a32e643fb Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Thu, 17 Jun 2021 23:12:36 +0200 Subject: Black found more files - strange. Executed black to make code unreadable. (cherry picked from commit 1b34c2368428b1ec295073ee47d201ac1def35f6) --- pyGHDL/dom/Common.py | 9 +- pyGHDL/dom/DesignUnit.py | 44 +++++--- pyGHDL/dom/Expression.py | 101 ++++++++++++------ pyGHDL/dom/InterfaceItem.py | 27 +++-- pyGHDL/dom/Literal.py | 9 +- pyGHDL/dom/Misc.py | 56 ++++++---- pyGHDL/dom/Object.py | 25 +++-- pyGHDL/dom/Range.py | 10 +- pyGHDL/dom/Symbol.py | 12 ++- pyGHDL/dom/_Translate.py | 64 +++++++---- pyGHDL/dom/_Utils.py | 15 +-- pyGHDL/dom/formatting/prettyprint.py | 201 ++++++++++++++++++++++++----------- 12 files changed, 377 insertions(+), 196 deletions(-) (limited to 'pyGHDL/dom') diff --git a/pyGHDL/dom/Common.py b/pyGHDL/dom/Common.py index 88d0cdc8c..984f06e86 100644 --- a/pyGHDL/dom/Common.py +++ b/pyGHDL/dom/Common.py @@ -37,8 +37,8 @@ """ from pydecor import export -from pyGHDL import GHDLBaseException -from pyGHDL.libghdl import LibGHDLException, errorout_memory +from pyGHDL import GHDLBaseException +from pyGHDL.libghdl import LibGHDLException, errorout_memory __all__ = [] @@ -61,5 +61,6 @@ class GHDLMixin: for i in range(errorCount): print(errorout_memory.Get_Error_Message(i + 1)) - raise DOMException("Error in libghdl.") \ - from LibGHDLException("libghdl: Internal error 2.") + raise DOMException("Error in libghdl.") from LibGHDLException( + "libghdl: Internal error 2." + ) diff --git a/pyGHDL/dom/DesignUnit.py b/pyGHDL/dom/DesignUnit.py index 9827cec24..dee86cab3 100644 --- a/pyGHDL/dom/DesignUnit.py +++ b/pyGHDL/dom/DesignUnit.py @@ -41,19 +41,24 @@ This module contains all DOM classes for VHDL's design units (:class:`context SubTypeOrSymbo subTypeIndication = nodes.Get_Subtype_Indication(node) subTypeKind = GetIirKindOfNode(subTypeIndication) - if (subTypeKind == nodes.Iir_Kind.Simple_Name): + if subTypeKind == nodes.Iir_Kind.Simple_Name: subTypeName = NodeToName(subTypeIndication) subType = SimpleSubTypeSymbol(subTypeName) - elif (subTypeKind == nodes.Iir_Kind.Array_Subtype_Definition): + elif subTypeKind == nodes.Iir_Kind.Array_Subtype_Definition: typeMark = nodes.Get_Subtype_Type_Mark(subTypeIndication) typeMarkName = NodeToName(typeMark) constraints = GetArrayConstraintsFromSubtypeIndication(subTypeIndication) subType = ConstrainedSubTypeSymbol(typeMarkName, constraints) - elif (subTypeKind == nodes.Iir_Kind.Subtype_Definition): + elif subTypeKind == nodes.Iir_Kind.Subtype_Definition: raise DOMException( "Unknown handling of subtype kind '{kind}' of subtype indication '{indication}' while parsing {entity} '{name}'.".format( - kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name) + kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name + ) ) else: raise DOMException( "Unknown subtype kind '{kind}' of subtype indication '{indication}' while parsing {entity} '{name}'.".format( - kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name) + kind=subTypeKind, indication=subTypeIndication, entity=entity, name=name + ) ) return subType + @export def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constraint]: constraints = [] @@ -58,7 +72,7 @@ def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constrai r = Range( GetExpressionFromNode(leftBound), GetExpressionFromNode(rightBound), - Direction.DownTo if direction else Direction.To + Direction.DownTo if direction else Direction.To, ) constraints.append(RangeExpression(r)) elif constraintKind == nodes.Iir_Kind.Attribute_Name: @@ -68,7 +82,10 @@ def GetArrayConstraintsFromSubtypeIndication(subTypeIndication) -> List[Constrai else: raise DOMException( "Unknown constraint kind '{kind}' for constraint '{constraint}' in subtype indication '{indication}'.".format( - kind=constraintKind, constraint=constraint, indication=subTypeIndication) + kind=constraintKind, + constraint=constraint, + indication=subTypeIndication, + ) ) return constraints @@ -117,9 +134,11 @@ def GetExpressionFromNode(node) -> Expression: else: raise DOMException( "Unknown expression kind '{kindName}'({kind}) in expression '{expr}'.".format( - kind=kind, kindName=kind.name, expr=node) + kind=kind, kindName=kind.name, expr=node + ) ) + # FIXME: rewrite to generator @export def GetGenericsFromChainedNodes(nodeChain): @@ -135,11 +154,13 @@ def GetGenericsFromChainedNodes(nodeChain): else: raise DOMException( "Unknown generic kind '{kindName}'({kind}) in generic '{generic}'.".format( - kind=kind, kindName=kind.name, generic=generic) + kind=kind, kindName=kind.name, generic=generic + ) ) return result + # FIXME: rewrite to generator @export def GetPortsFromChainedNodes(nodeChain): @@ -155,11 +176,13 @@ def GetPortsFromChainedNodes(nodeChain): else: raise DOMException( "Unknown port kind '{kindName}'({kind}) in port '{port}'.".format( - kind=kind, kindName=kind.name, port=port) + kind=kind, kindName=kind.name, port=port + ) ) return result + def GetDeclaredItemsFromChainedNodes(nodeChain, entity: str, name: str): result = [] for item in utils.chain_iter(nodeChain): @@ -168,7 +191,9 @@ def GetDeclaredItemsFromChainedNodes(nodeChain, entity: str, name: str): from pyGHDL.dom.Object import Constant constantName = NodeToName(item) - subTypeIndication = GetSubtypeIndicationFromNode(item, "constant", constantName) + subTypeIndication = GetSubtypeIndicationFromNode( + item, "constant", constantName + ) defaultExpression = GetExpressionFromNode(nodes.Get_Default_Value(item)) constant = Constant(constantName, subTypeIndication, defaultExpression) @@ -202,7 +227,8 @@ def GetDeclaredItemsFromChainedNodes(nodeChain, entity: str, name: str): else: raise DOMException( "Unknown declared item kind '{kindName}'({kind}) in {entity} '{name}'.".format( - kind=kind, kindName=kind.name, entity=entity, name=name) + kind=kind, kindName=kind.name, entity=entity, name=name + ) ) return result diff --git a/pyGHDL/dom/_Utils.py b/pyGHDL/dom/_Utils.py index f0c838517..b74bdfa96 100644 --- a/pyGHDL/dom/_Utils.py +++ b/pyGHDL/dom/_Utils.py @@ -1,21 +1,22 @@ from pydecor import export -from pyVHDLModel.VHDLModel import Mode +from pyVHDLModel.VHDLModel import Mode -from pyGHDL.libghdl import LibGHDLException, name_table +from pyGHDL.libghdl import LibGHDLException, name_table from pyGHDL.libghdl.vhdl import nodes __all__ = [] __MODE_TRANSLATION = { - nodes.Iir_Mode.In_Mode: Mode.In, - nodes.Iir_Mode.Out_Mode: Mode.Out, - nodes.Iir_Mode.Inout_Mode: Mode.InOut, - nodes.Iir_Mode.Buffer_Mode: Mode.Buffer, - nodes.Iir_Mode.Linkage_Mode: Mode.Linkage + nodes.Iir_Mode.In_Mode: Mode.In, + nodes.Iir_Mode.Out_Mode: Mode.Out, + nodes.Iir_Mode.Inout_Mode: Mode.InOut, + nodes.Iir_Mode.Buffer_Mode: Mode.Buffer, + nodes.Iir_Mode.Linkage_Mode: Mode.Linkage, } + @export def GetIirKindOfNode(node) -> nodes.Iir_Kind: kind: int = nodes.Get_Kind(node) diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index a64f2a4f5..387706cac 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -3,53 +3,83 @@ from typing import List, Union from pydecor import export from pyGHDL.dom.Object import Constant, Signal -from pyVHDLModel.VHDLModel import GenericInterfaceItem, Expression, Direction, Mode, NamedEntity, PortInterfaceItem, BinaryExpression, IdentityExpression, \ - UnaryExpression +from pyVHDLModel.VHDLModel import ( + GenericInterfaceItem, + Expression, + Direction, + Mode, + NamedEntity, + PortInterfaceItem, + BinaryExpression, + IdentityExpression, + UnaryExpression, +) from pyGHDL import GHDLBaseException from pyGHDL.dom.Misc import Document -from pyGHDL.dom.DesignUnit import Entity, Architecture, Package, PackageBody, Configuration, Context -from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem, PortSignalInterfaceItem -from pyGHDL.dom.Symbol import SimpleSubTypeSymbol, ConstrainedSubTypeSymbol, SimpleObjectSymbol +from pyGHDL.dom.DesignUnit import ( + Entity, + Architecture, + Package, + PackageBody, + Configuration, + Context, +) +from pyGHDL.dom.InterfaceItem import ( + GenericConstantInterfaceItem, + PortSignalInterfaceItem, +) +from pyGHDL.dom.Symbol import ( + SimpleSubTypeSymbol, + ConstrainedSubTypeSymbol, + SimpleObjectSymbol, +) from pyGHDL.dom.Literal import IntegerLiteral, CharacterLiteral, FloatingPointLiteral -from pyGHDL.dom.Expression import SubtractionExpression, AdditionExpression, MultiplyExpression, DivisionExpression, InverseExpression, AbsoluteExpression, \ - NegationExpression, ExponentiationExpression +from pyGHDL.dom.Expression import ( + SubtractionExpression, + AdditionExpression, + MultiplyExpression, + DivisionExpression, + InverseExpression, + AbsoluteExpression, + NegationExpression, + ExponentiationExpression, +) StringBuffer = List[str] -DirectionTranslation = { - Direction.To: "to", - Direction.DownTo: "downto" -} +DirectionTranslation = {Direction.To: "to", Direction.DownTo: "downto"} ModeTranslation = { - Mode.In: "in", - Mode.Out: "out", - Mode.InOut: "inout", - Mode.Buffer: "buffer", - Mode.Linkage: "linkage" + Mode.In: "in", + Mode.Out: "out", + Mode.InOut: "inout", + Mode.Buffer: "buffer", + Mode.Linkage: "linkage", } UnaryExpressionTranslation = { - IdentityExpression: " +", - NegationExpression: " -", - InverseExpression: "not ", - AbsoluteExpression: "abs ", + IdentityExpression: " +", + NegationExpression: " -", + InverseExpression: "not ", + AbsoluteExpression: "abs ", } BinaryExpressionTranslation = { - AdditionExpression: " + ", - SubtractionExpression: " - ", - MultiplyExpression: " * ", - DivisionExpression: " / ", - ExponentiationExpression: "**" + AdditionExpression: " + ", + SubtractionExpression: " - ", + MultiplyExpression: " * ", + DivisionExpression: " / ", + ExponentiationExpression: "**", } + @export class PrettyPrintException(GHDLBaseException): pass + @export class PrettyPrint: # _buffer: StringBuffer @@ -60,30 +90,32 @@ class PrettyPrint: def formatDocument(self, document: Document, level: int = 0) -> StringBuffer: buffer = [] prefix = " " * level - buffer.append("{prefix}Document '{doc!s}':".format(doc=document.Path, prefix=prefix)) + buffer.append( + "{prefix}Document '{doc!s}':".format(doc=document.Path, prefix=prefix) + ) buffer.append("{prefix} Entities:".format(prefix=prefix)) for entity in document.Entities: - for line in self.formatEntity(entity, level+1): + for line in self.formatEntity(entity, level + 1): buffer.append(line) buffer.append("{prefix} Architectures:".format(prefix=prefix)) for architecture in document.Architectures: - for line in self.formatArchitecture(architecture, level+1): + for line in self.formatArchitecture(architecture, level + 1): buffer.append(line) buffer.append("{prefix} Packages:".format(prefix=prefix)) for package in document.Packages: - for line in self.formatPackage(package, level+1): + for line in self.formatPackage(package, level + 1): buffer.append(line) buffer.append("{prefix} PackageBodies:".format(prefix=prefix)) for packageBodies in document.PackageBodies: - for line in self.formatPackageBody(packageBodies, level+1): + for line in self.formatPackageBody(packageBodies, level + 1): buffer.append(line) buffer.append("{prefix} Configurations:".format(prefix=prefix)) for configuration in document.Configurations: - for line in self.formatConfiguration(configuration, level+1): + for line in self.formatConfiguration(configuration, level + 1): buffer.append(line) buffer.append("{prefix} Contexts:".format(prefix=prefix)) for context in document.Contexts: - for line in self.formatContext(context, level+1): + for line in self.formatContext(context, level + 1): buffer.append(line) return buffer @@ -107,7 +139,9 @@ class PrettyPrint: return buffer - def formatArchitecture(self, architecture: Architecture, level: int = 0) -> StringBuffer: + def formatArchitecture( + self, architecture: Architecture, level: int = 0 + ) -> StringBuffer: buffer = [] prefix = " " * level buffer.append("{prefix}- {name}".format(name=architecture.Name, prefix=prefix)) @@ -129,7 +163,9 @@ class PrettyPrint: return buffer - def formatPackageBody(self, packageBody: PackageBody, level: int = 0) -> StringBuffer: + def formatPackageBody( + self, packageBody: PackageBody, level: int = 0 + ) -> StringBuffer: buffer = [] prefix = " " * level buffer.append("{prefix}- {name}".format(name=packageBody.Name, prefix=prefix)) @@ -140,7 +176,9 @@ class PrettyPrint: return buffer - def formatConfiguration(self, configuration: Configuration, level: int = 0) -> StringBuffer: + def formatConfiguration( + self, configuration: Configuration, level: int = 0 + ) -> StringBuffer: buffer = [] prefix = " " * level buffer.append("{prefix}- {name}".format(name=configuration.Name, prefix=prefix)) @@ -154,19 +192,29 @@ class PrettyPrint: return buffer - def formatGeneric(self, generic: Union[NamedEntity, GenericInterfaceItem], level: int = 0) -> StringBuffer: + def formatGeneric( + self, generic: Union[NamedEntity, GenericInterfaceItem], level: int = 0 + ) -> StringBuffer: if isinstance(generic, GenericConstantInterfaceItem): return self.formatGenericConstant(generic, level) else: - raise PrettyPrintException("Unhandled generic kind for generic '{name}'.".format(name=generic.Name)) + raise PrettyPrintException( + "Unhandled generic kind for generic '{name}'.".format(name=generic.Name) + ) - def formatPort(self, port: Union[NamedEntity, PortInterfaceItem], level: int = 0) -> StringBuffer: + def formatPort( + self, port: Union[NamedEntity, PortInterfaceItem], level: int = 0 + ) -> StringBuffer: if isinstance(port, PortSignalInterfaceItem): return self.formatPortSignal(port, level) else: - raise PrettyPrintException("Unhandled port kind for port '{name}'.".format(name=port.Name)) + raise PrettyPrintException( + "Unhandled port kind for port '{name}'.".format(name=port.Name) + ) - def formatGenericConstant(self, generic: GenericConstantInterfaceItem, level: int = 0) -> StringBuffer: + def formatGenericConstant( + self, generic: GenericConstantInterfaceItem, level: int = 0 + ) -> StringBuffer: buffer = [] prefix = " " * level subType = generic.SubType @@ -176,7 +224,7 @@ class PrettyPrint: prefix=prefix, name=generic.Name, mode=ModeTranslation[generic.Mode], - type=subType.SymbolName + type=subType.SymbolName, ) ) elif isinstance(subType, ConstrainedSubTypeSymbol): @@ -187,19 +235,31 @@ class PrettyPrint: mode=ModeTranslation[generic.Mode], type=subType.SymbolName, constraints=", ".join( - ["{left} {dir} {right}".format( - left=self.formatExpression(constraint.Range.LeftBound), - right=self.formatExpression(constraint.Range.RightBound), - dir=DirectionTranslation[constraint.Range.Direction]) - for constraint in subType.Constraints]) + [ + "{left} {dir} {right}".format( + left=self.formatExpression(constraint.Range.LeftBound), + right=self.formatExpression( + constraint.Range.RightBound + ), + dir=DirectionTranslation[constraint.Range.Direction], + ) + for constraint in subType.Constraints + ] + ), ) ) else: - raise PrettyPrintException("Unhandled constraint kind for generic '{name}'.".format(name=generic.Name)) + raise PrettyPrintException( + "Unhandled constraint kind for generic '{name}'.".format( + name=generic.Name + ) + ) return buffer - def formatPortSignal(self, port: PortSignalInterfaceItem, level: int = 0) -> StringBuffer: + def formatPortSignal( + self, port: PortSignalInterfaceItem, level: int = 0 + ) -> StringBuffer: buffer = [] prefix = " " * level @@ -208,7 +268,9 @@ class PrettyPrint: prefix=prefix, name=port.Name, mode=ModeTranslation[port.Mode], - subtypeindication=self.formatSubtypeIndication(port.SubType, "port", port.Name) + subtypeindication=self.formatSubtypeIndication( + port.SubType, "port", port.Name + ), ) ) @@ -223,8 +285,10 @@ class PrettyPrint: "{prefix}- constant {name} : {subtype} := {expr}".format( prefix=prefix, name=item.Name, - subtype=self.formatSubtypeIndication(item.SubType, "constant", item.Name), - expr=self.formatExpression(item.DefaultExpression) + subtype=self.formatSubtypeIndication( + item.SubType, "constant", item.Name + ), + expr=self.formatExpression(item.DefaultExpression), ) ) elif isinstance(item, Signal): @@ -232,10 +296,14 @@ class PrettyPrint: "{prefix}- signal {name} : {subtype}{initValue}".format( prefix=prefix, name=item.Name, - subtype=self.formatSubtypeIndication(item.SubType, "signal", item.Name), + subtype=self.formatSubtypeIndication( + item.SubType, "signal", item.Name + ), initValue=" := {expr}".format( expr=self.formatExpression(item.DefaultExpression) - ) if item.DefaultExpression is not None else "" + ) + if item.DefaultExpression is not None + else "", ) ) else: @@ -248,19 +316,25 @@ class PrettyPrint: return "{type}".format(type=subTypeIndication.SymbolName) elif isinstance(subTypeIndication, ConstrainedSubTypeSymbol): constraints = ", ".join( - ["{left} {dir} {right}".format( - left=self.formatExpression(constraint.Range.LeftBound), - right=self.formatExpression(constraint.Range.RightBound), - dir=DirectionTranslation[constraint.Range.Direction] - ) for constraint in subTypeIndication.Constraints] + [ + "{left} {dir} {right}".format( + left=self.formatExpression(constraint.Range.LeftBound), + right=self.formatExpression(constraint.Range.RightBound), + dir=DirectionTranslation[constraint.Range.Direction], + ) + for constraint in subTypeIndication.Constraints + ] ) return "{type}({constraints})".format( - type=subTypeIndication.SymbolName, - constraints=constraints + type=subTypeIndication.SymbolName, constraints=constraints ) else: - raise PrettyPrintException("Unhandled constraint kind for {entity} '{name}'.".format(entity=entity, name=name)) + raise PrettyPrintException( + "Unhandled constraint kind for {entity} '{name}'.".format( + entity=entity, name=name + ) + ) def formatExpression(self, expression: Expression) -> str: if isinstance(expression, SimpleObjectSymbol): @@ -278,8 +352,7 @@ class PrettyPrint: raise PrettyPrintException("Unhandled operator for unary expression.") return "{operator}{operand}".format( - operand=self.formatExpression(expression.Operand), - operator=operator + operand=self.formatExpression(expression.Operand), operator=operator ) elif isinstance(expression, BinaryExpression): try: @@ -290,7 +363,7 @@ class PrettyPrint: return "{left}{operator}{right}".format( left=self.formatExpression(expression.LeftOperand), right=self.formatExpression(expression.RightOperand), - operator=operator + operator=operator, ) else: raise PrettyPrintException("Unhandled expression kind.") -- cgit v1.2.3