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 ++++++++++++++++++++++++----------- pyGHDL/libghdl/__init__.py | 20 ++-- pyGHDL/libghdl/_decorator.py | 52 ++++++--- pyGHDL/libghdl/_types.py | 6 +- pyGHDL/libghdl/errorout_memory.py | 3 +- pyGHDL/libghdl/files_map.py | 12 ++- pyGHDL/libghdl/files_map_editor.py | 41 +++++-- pyGHDL/libghdl/flags.py | 6 +- pyGHDL/libghdl/libraries.py | 21 ++-- pyGHDL/libghdl/name_table.py | 10 +- pyGHDL/libghdl/vhdl/canon.py | 10 +- pyGHDL/libghdl/vhdl/flists.py | 5 +- pyGHDL/libghdl/vhdl/formatters.py | 8 +- pyGHDL/libghdl/vhdl/ieee.py | 14 +-- pyGHDL/libghdl/vhdl/lists.py | 12 +-- pyGHDL/libghdl/vhdl/nodes_utils.py | 2 +- pyGHDL/libghdl/vhdl/parse.py | 4 +- pyGHDL/libghdl/vhdl/scanner.py | 5 +- pyGHDL/libghdl/vhdl/sem_lib.py | 2 +- pyGHDL/libghdl/vhdl/std_package.py | 20 ++-- 31 files changed, 530 insertions(+), 296 deletions(-) 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.") diff --git a/pyGHDL/libghdl/__init__.py b/pyGHDL/libghdl/__init__.py index 1d1701aaa..1477d9361 100644 --- a/pyGHDL/libghdl/__init__.py +++ b/pyGHDL/libghdl/__init__.py @@ -42,10 +42,15 @@ from pydecor import export from pyGHDL import GHDLBaseException from pyGHDL.libghdl._types import Iir -#from pyGHDL.libghdl._decorator import BindToLibGHDL + +# from pyGHDL.libghdl._decorator import BindToLibGHDL from pyGHDL.libghdl.version import __version__ +class LibGHDLException(GHDLBaseException): + pass + + def _get_libghdl_name() -> Path: """Get the name of the libghdl library (with version and extension)""" ver = __version__.replace("-", "_").replace(".", "_") @@ -159,7 +164,7 @@ def finalize() -> None: @export -#@BindToLibGHDL("options__initialize") +# @BindToLibGHDL("options__initialize") def initialize() -> None: """Initialize or re-initialize the shared library.""" libghdl.options__initialize() @@ -179,7 +184,7 @@ def set_option(Opt: str) -> bool: @export -#@BindToLibGHDL("libghdl__analyze_init") +# @BindToLibGHDL("libghdl__analyze_init") def analyze_init() -> None: """ Initialize the analyzer. @@ -191,7 +196,7 @@ def analyze_init() -> None: @export -#@BindToLibGHDL("libghdl__analyze_init_status") +# @BindToLibGHDL("libghdl__analyze_init_status") def analyze_init_status() -> int: """ Initialize the analyzer. @@ -215,12 +220,7 @@ def analyze_file(fname: str) -> Iir: @export -#@BindToLibGHDL("ghdllocal__disp_config_prefixes") +# @BindToLibGHDL("ghdllocal__disp_config_prefixes") def disp_config() -> None: """Display the configured prefixes for libghdl.""" libghdl.ghdllocal__disp_config_prefixes() - - -@export -class LibGHDLException(GHDLBaseException): - pass diff --git a/pyGHDL/libghdl/_decorator.py b/pyGHDL/libghdl/_decorator.py index 4266d31d9..e27754121 100644 --- a/pyGHDL/libghdl/_decorator.py +++ b/pyGHDL/libghdl/_decorator.py @@ -82,24 +82,30 @@ def BindToLibGHDL(subprogramName): typeHintCount = len(typeHints) if typeHintCount == 0: - raise ValueError("Function {0} is not annotated with types.".format(func.__name__)) + raise ValueError( + "Function {0} is not annotated with types.".format(func.__name__) + ) try: - returnType = typeHints['return'] + returnType = typeHints["return"] except KeyError: - raise ValueError("Function {0} is not annotated with a return type.".format(func.__name__)) + raise ValueError( + "Function {0} is not annotated with a return type.".format( + func.__name__ + ) + ) if (typeHintCount - 1) != func.__code__.co_argcount: - raise ValueError("Number of type annotations ({0}) for function '{1}' does not match number of parameters ({2}).".format( - typeHintCount - 1, - func.__name__, - func.__code__.co_argcount) + raise ValueError( + "Number of type annotations ({0}) for function '{1}' does not match number of parameters ({2}).".format( + typeHintCount - 1, func.__name__, func.__code__.co_argcount + ) ) - # print(typeHints) + # print(typeHints) parameters = typeHints.copy() - del parameters['return'] + del parameters["return"] parameterTypes = [] for parameter in parameters.values(): @@ -117,9 +123,17 @@ def BindToLibGHDL(subprogramName): if (parameter.__bound__ is int) or (parameter.__bound__ is c_int32): parameterTypes.append(c_int32) else: - raise TypeError("Unsupported parameter type '{0!s}' in function '{1}'.".format(parameter, func.__name__)) + raise TypeError( + "Unsupported parameter type '{0!s}' in function '{1}'.".format( + parameter, func.__name__ + ) + ) else: - raise TypeError("Unsupported parameter type '{0!s}' in function '{1}'.".format(parameter, func.__name__)) + raise TypeError( + "Unsupported parameter type '{0!s}' in function '{1}'.".format( + parameter, func.__name__ + ) + ) if returnType is None: resultType = None @@ -129,19 +143,27 @@ def BindToLibGHDL(subprogramName): resultType = c_char elif returnType is c_char_p: resultType = c_char_p - elif (returnType is int): + elif returnType is int: resultType = c_int32 - elif (returnType is bool): + elif returnType is bool: resultType = c_bool elif isinstance(returnType, TypeVar): if (returnType.__bound__ is int) or (returnType.__bound__ is c_int32): resultType = c_int32 else: - raise Exception("Unsupported return type '{0!s}' in function '{1}'.".format(returnType, func.__name__)) + raise Exception( + "Unsupported return type '{0!s}' in function '{1}'.".format( + returnType, func.__name__ + ) + ) elif issubclass(returnType, Structure): resultType = returnType else: - raise Exception("Unsupported return type '{0!s}' in function '{1}'.".format(returnType, func.__name__)) + raise Exception( + "Unsupported return type '{0!s}' in function '{1}'.".format( + returnType, func.__name__ + ) + ) functionPointer = getattr(libghdl, subprogramName) functionPointer.parameterTypes = parameterTypes diff --git a/pyGHDL/libghdl/_types.py b/pyGHDL/libghdl/_types.py index 132dbfab9..21be42c64 100644 --- a/pyGHDL/libghdl/_types.py +++ b/pyGHDL/libghdl/_types.py @@ -39,7 +39,7 @@ __all__ = [ "NameId", "SourceFileEntry", "Iir", - "IirKind" + "IirKind", ] ErrorIndex = TypeVar("ErrorIndex", bound=int) @@ -56,4 +56,6 @@ Iir_Design_File = TypeVar("Iir_Design_File", bound=int) Iir_Design_Unit = TypeVar("Iir_Design_Unit", bound=int) Iir_Library_Declaration = TypeVar("Iir_Library_Declaration", bound=c_int32) Iir_Package_Declaration = TypeVar("Iir_Package_Declaration", bound=c_int32) -Iir_Enumeration_Type_Definition = TypeVar("Iir_Enumeration_Type_Definition", bound=c_int32) +Iir_Enumeration_Type_Definition = TypeVar( + "Iir_Enumeration_Type_Definition", bound=c_int32 +) diff --git a/pyGHDL/libghdl/errorout_memory.py b/pyGHDL/libghdl/errorout_memory.py index 5187d5e3c..c6577540d 100644 --- a/pyGHDL/libghdl/errorout_memory.py +++ b/pyGHDL/libghdl/errorout_memory.py @@ -107,11 +107,12 @@ def Get_Error_Record(Idx: ErrorIndex) -> Error_Message: """ -#@export +# @export @BindToLibGHDL("errorout__memory__get_error_message_addr") def _Get_Error_Message(Idx: ErrorIndex) -> c_char_p: pass + @export def Get_Error_Message(Idx: ErrorIndex) -> str: """ diff --git a/pyGHDL/libghdl/files_map.py b/pyGHDL/libghdl/files_map.py index 7e2ae0abc..ceda483c5 100644 --- a/pyGHDL/libghdl/files_map.py +++ b/pyGHDL/libghdl/files_map.py @@ -87,7 +87,9 @@ def Location_File_To_Line(Location: Location_Type, File: SourceFileEntry) -> int @export @BindToLibGHDL("files_map__location_file_line_to_offset") -def Location_File_Line_To_Offset(Location: Location_Type, File: SourceFileEntry, Line: int) -> int: +def Location_File_Line_To_Offset( + Location: Location_Type, File: SourceFileEntry, Line: int +) -> int: """ Get the offset in :obj:`Line` of :obj:`Location`. @@ -100,7 +102,9 @@ def Location_File_Line_To_Offset(Location: Location_Type, File: SourceFileEntry, @export @BindToLibGHDL("files_map__location_file_line_to_col") -def Location_File_Line_To_Col(Location: Location_Type, File: SourceFileEntry, Line: int) -> int: +def Location_File_Line_To_Col( + Location: Location_Type, File: SourceFileEntry, Line: int +) -> int: """ Get logical column (with HT expanded) from :obj:`Location`, :obj:`File` and :obj:`Line`. @@ -219,7 +223,9 @@ def Read_Source_File(Directory: NameId, Name: NameId) -> SourceFileEntry: @export @BindToLibGHDL("files_map__reserve_source_file") -def Reserve_Source_File(Directory: NameId, Name: NameId, Length: int) -> SourceFileEntry: +def Reserve_Source_File( + Directory: NameId, Name: NameId, Length: int +) -> SourceFileEntry: """ Reserve an entry, but do not read any file. diff --git a/pyGHDL/libghdl/files_map_editor.py b/pyGHDL/libghdl/files_map_editor.py index 1b1f86a01..eceb3efe2 100644 --- a/pyGHDL/libghdl/files_map_editor.py +++ b/pyGHDL/libghdl/files_map_editor.py @@ -41,9 +41,17 @@ from pyGHDL.libghdl._decorator import BindToLibGHDL from pyGHDL.libghdl._types import SourceFileEntry -#@export +# @export @BindToLibGHDL("files_map__editor__replace_text_ptr") -def _Replace_Text(File: SourceFileEntry, Start_Line: int, Start_Offset: int, End_Line: int, End_Offset: int, Text_Pointer: c_char_p, Text_Length: int) -> bool: +def _Replace_Text( + File: SourceFileEntry, + Start_Line: int, + Start_Offset: int, + End_Line: int, + End_Offset: int, + Text_Pointer: c_char_p, + Text_Length: int, +) -> bool: """Replace [START; END) by TEXT. :param File: File where to replace a text section. @@ -58,8 +66,15 @@ def _Replace_Text(File: SourceFileEntry, Start_Line: int, Start_Offset: int, End @export -def Replace_Text(File: SourceFileEntry, Start_Line: int, Start_Offset: int, End_Line: int, End_Offset: int, Text: str) -> bool: - """ Replace [START; END) by TEXT. +def Replace_Text( + File: SourceFileEntry, + Start_Line: int, + Start_Offset: int, + End_Line: int, + End_Offset: int, + Text: str, +) -> bool: + """Replace [START; END) by TEXT. :param File: File where to replace a text section. :param Start_Line: undocumented @@ -70,11 +85,19 @@ def Replace_Text(File: SourceFileEntry, Start_Line: int, Start_Offset: int, End_ :return: Return True in case of success, False in case of failure (the gap is too small). """ buffer = Text.encode("utf-8") - return _Replace_Text(File, Start_Line, Start_Offset, End_Line, End_Offset, c_char_p(buffer), len(buffer)) + return _Replace_Text( + File, + Start_Line, + Start_Offset, + End_Line, + End_Offset, + c_char_p(buffer), + len(buffer), + ) @export -#@BindToLibGHDL("files_map__editor__fill_text_ptr") +# @BindToLibGHDL("files_map__editor__fill_text_ptr") def Fill_Text(File: SourceFileEntry, Text_Pointer, Text_Length: int) -> None: """Replace the content of :obj:`File` with TEXT. @@ -88,8 +111,10 @@ def Fill_Text(File: SourceFileEntry, Text_Pointer, Text_Length: int) -> None: @export -#@BindToLibGHDL("files_map__editor__check_buffer_content") -def Check_Buffer_Content(File: SourceFileEntry, String_Pointer, String_Length: int) -> None: +# @BindToLibGHDL("files_map__editor__check_buffer_content") +def Check_Buffer_Content( + File: SourceFileEntry, String_Pointer, String_Length: int +) -> None: """ Check that content of :obj:`File` is STR[1 .. STR_LEN]. diff --git a/pyGHDL/libghdl/flags.py b/pyGHDL/libghdl/flags.py index e5f910995..fc3107e79 100644 --- a/pyGHDL/libghdl/flags.py +++ b/pyGHDL/libghdl/flags.py @@ -40,7 +40,7 @@ __all__ = [ "Flag_Elocations", "Verbose", "Flag_Elaborate_With_Outdated", - "Flag_Force_Analysis" + "Flag_Force_Analysis", ] assert sizeof(c_bool) == 1 @@ -49,6 +49,8 @@ Flag_Elocations = c_bool.in_dll(libghdl, "flags__flag_elocations") Verbose = c_bool.in_dll(libghdl, "flags__verbose") -Flag_Elaborate_With_Outdated = c_bool.in_dll(libghdl, "flags__flag_elaborate_with_outdated") +Flag_Elaborate_With_Outdated = c_bool.in_dll( + libghdl, "flags__flag_elaborate_with_outdated" +) Flag_Force_Analysis = c_bool.in_dll(libghdl, "flags__flag_force_analysis") diff --git a/pyGHDL/libghdl/libraries.py b/pyGHDL/libghdl/libraries.py index ef3d8e98d..963f390d9 100644 --- a/pyGHDL/libghdl/libraries.py +++ b/pyGHDL/libghdl/libraries.py @@ -37,13 +37,16 @@ from ctypes import c_int32 from pydecor import export from pyGHDL.libghdl import libghdl -from pyGHDL.libghdl._types import NameId, Iir_Library_Declaration, Iir_Design_Unit, Iir_Design_File, Location_Type +from pyGHDL.libghdl._types import ( + NameId, + Iir_Library_Declaration, + Iir_Design_Unit, + Iir_Design_File, + Location_Type, +) from pyGHDL.libghdl._decorator import BindToLibGHDL -__all__ = [ - "Library_Location", - "Work_Library" -] +__all__ = ["Library_Location", "Work_Library"] Library_Location: Location_Type = c_int32.in_dll(libghdl, "libraries__library_location") """ @@ -51,7 +54,9 @@ A location for library declarations (such as library WORK). Use ``.value`` to access this variable inside libghdl. """ -Work_Library:Iir_Library_Declaration = c_int32.in_dll(libghdl, "libraries__work_library") +Work_Library: Iir_Library_Declaration = c_int32.in_dll( + libghdl, "libraries__work_library" +) """ Library declaration for the work library. Note: the identifier of the work_library is ``work_library_name``, which may be different from 'WORK'. Use ``.value`` to @@ -126,7 +131,9 @@ def Get_Library_No_Create(Ident: NameId) -> Iir_Library_Declaration: @export @BindToLibGHDL("libraries__find_primary_unit") -def Find_Primary_Unit(Library: Iir_Library_Declaration, Name: NameId) -> Iir_Design_Unit: +def Find_Primary_Unit( + Library: Iir_Library_Declaration, Name: NameId +) -> Iir_Design_Unit: """ Just return the design_unit for :obj:`Name`, or ``NULL`` if not found. diff --git a/pyGHDL/libghdl/name_table.py b/pyGHDL/libghdl/name_table.py index ddb5ba491..408168797 100644 --- a/pyGHDL/libghdl/name_table.py +++ b/pyGHDL/libghdl/name_table.py @@ -39,9 +39,7 @@ from pydecor import export from pyGHDL.libghdl._types import NameId from pyGHDL.libghdl._decorator import BindToLibGHDL -__all__ = [ - "Null_Identifier" -] +__all__ = ["Null_Identifier"] Null_Identifier = 0 @@ -57,7 +55,7 @@ def Get_Name_Length(Id: NameId) -> int: """ -#@export +# @export @BindToLibGHDL("name_table__get_name_ptr") def _Get_Name_Ptr(Id: NameId) -> c_char_p: """""" @@ -76,7 +74,7 @@ def Get_Name_Ptr(Id: NameId) -> str: return _Get_Name_Ptr(Id).decode("utf-8") -#@export +# @export @BindToLibGHDL("name_table__get_character") def _Get_Character(Id: NameId) -> c_char: """""" @@ -97,7 +95,7 @@ def Get_Character(Id: NameId) -> str: return _Get_Character(Id).decode("utf-8") -#@export +# @export @BindToLibGHDL("name_table__get_identifier_with_len") def _Get_Identifier(string: c_char_p, length: int) -> NameId: """""" diff --git a/pyGHDL/libghdl/vhdl/canon.py b/pyGHDL/libghdl/vhdl/canon.py index e9bddb07c..086755c35 100644 --- a/pyGHDL/libghdl/vhdl/canon.py +++ b/pyGHDL/libghdl/vhdl/canon.py @@ -36,13 +36,11 @@ from ctypes import c_bool from pyGHDL.libghdl import libghdl -__all__ = [ - "Flag_Concurrent_Stmts", - "Flag_Configurations", - "Flag_Associations" -] +__all__ = ["Flag_Concurrent_Stmts", "Flag_Configurations", "Flag_Associations"] -Flag_Concurrent_Stmts = c_bool.in_dll(libghdl, "vhdl__canon__canon_flag_concurrent_stmts") +Flag_Concurrent_Stmts = c_bool.in_dll( + libghdl, "vhdl__canon__canon_flag_concurrent_stmts" +) Flag_Configurations = c_bool.in_dll(libghdl, "vhdl__canon__canon_flag_configurations") diff --git a/pyGHDL/libghdl/vhdl/flists.py b/pyGHDL/libghdl/vhdl/flists.py index b4217b36d..3829921f3 100644 --- a/pyGHDL/libghdl/vhdl/flists.py +++ b/pyGHDL/libghdl/vhdl/flists.py @@ -38,10 +38,7 @@ from pydecor import export from pyGHDL.libghdl._decorator import BindToLibGHDL -__all__ = [ - "Flist_Type", - "Ffirst" -] +__all__ = ["Flist_Type", "Ffirst"] Flist_Type = c_int32 #: First index of a ``FList``. diff --git a/pyGHDL/libghdl/vhdl/formatters.py b/pyGHDL/libghdl/vhdl/formatters.py index 42e8a6679..72b72010e 100644 --- a/pyGHDL/libghdl/vhdl/formatters.py +++ b/pyGHDL/libghdl/vhdl/formatters.py @@ -54,7 +54,7 @@ def Indent_String(File: int, Handle: int, FirstLine: int, LastLine: int) -> None @export -#@BindToLibGHDL("vhdl__formatters__allocate_handle") +# @BindToLibGHDL("vhdl__formatters__allocate_handle") def Allocate_Handle(): """ .. todo:: Undocumented in Ada code. @@ -65,7 +65,7 @@ def Allocate_Handle(): @export -#@BindToLibGHDL("vhdl__formatters__get_length") +# @BindToLibGHDL("vhdl__formatters__get_length") def Get_Length(Handle) -> int: """ .. todo:: Undocumented in Ada code. @@ -80,7 +80,7 @@ def Get_Length(Handle) -> int: @export -#@BindToLibGHDL("vhdl__formatters__get_c_string") +# @BindToLibGHDL("vhdl__formatters__get_c_string") def Get_C_String(Handle): """ .. todo:: Undocumented in Ada code. @@ -95,7 +95,7 @@ def Get_C_String(Handle): @export -#@BindToLibGHDL("vhdl__formatters__free_handle") +# @BindToLibGHDL("vhdl__formatters__free_handle") def Free_Handle(Handle) -> None: """ .. todo:: Undocumented in Ada code. diff --git a/pyGHDL/libghdl/vhdl/ieee.py b/pyGHDL/libghdl/vhdl/ieee.py index 66396143e..652782b55 100644 --- a/pyGHDL/libghdl/vhdl/ieee.py +++ b/pyGHDL/libghdl/vhdl/ieee.py @@ -35,19 +35,19 @@ from ctypes import c_int from pyGHDL.libghdl import libghdl -__all__ = [ - "Std_Logic_1164_Pkg", - "Std_Logic_Type", - "Std_Logic_Vector_Type" -] +__all__ = ["Std_Logic_1164_Pkg", "Std_Logic_Type", "Std_Logic_Vector_Type"] -Std_Logic_1164_Pkg = c_int.in_dll(libghdl, "vhdl__ieee__std_logic_1164__std_logic_1164_pkg") +Std_Logic_1164_Pkg = c_int.in_dll( + libghdl, "vhdl__ieee__std_logic_1164__std_logic_1164_pkg" +) # Get value Std_Logic_Type = c_int.in_dll(libghdl, "vhdl__ieee__std_logic_1164__std_logic_type") # Get value -Std_Logic_Vector_Type = c_int.in_dll(libghdl, "vhdl__ieee__std_logic_1164__std_logic_vector_type") +Std_Logic_Vector_Type = c_int.in_dll( + libghdl, "vhdl__ieee__std_logic_1164__std_logic_vector_type" +) # Get value # Rising_Edge = c_int.in_dll(libghdl, "vhdl__ieee__std_logic_1164__rising_edge") diff --git a/pyGHDL/libghdl/vhdl/lists.py b/pyGHDL/libghdl/vhdl/lists.py index 1499c4dca..d9e4fda6c 100644 --- a/pyGHDL/libghdl/vhdl/lists.py +++ b/pyGHDL/libghdl/vhdl/lists.py @@ -42,11 +42,7 @@ from pyGHDL.libghdl._decorator import BindToLibGHDL @export class Iterator(Structure): - _fields_ = [ - ("chunk", c_int32), - ("chunk_idx", c_int32), - ("remain", c_int32) - ] + _fields_ = [("chunk", c_int32), ("chunk_idx", c_int32), ("remain", c_int32)] @export @@ -71,7 +67,7 @@ def Iterate(List: int) -> Iterator: @export -#@BindToLibGHDL("vhdl__lists__is_valid") +# @BindToLibGHDL("vhdl__lists__is_valid") def Is_Valid(it: Iterator) -> bool: """ Check if iterator reached the end. @@ -87,7 +83,7 @@ def Is_Valid(it: Iterator) -> bool: @export -#@BindToLibGHDL("vhdl__lists__next") +# @BindToLibGHDL("vhdl__lists__next") def Next(it: Iterator) -> bool: """ Move iterator to the next element. @@ -103,7 +99,7 @@ def Next(it: Iterator) -> bool: @export -#@BindToLibGHDL("vhdl__lists__get_element") +# @BindToLibGHDL("vhdl__lists__get_element") def Get_Element(it: Iterator) -> int: """ Get the current element from iterator. diff --git a/pyGHDL/libghdl/vhdl/nodes_utils.py b/pyGHDL/libghdl/vhdl/nodes_utils.py index f2b9c8bba..7cecb6825 100644 --- a/pyGHDL/libghdl/vhdl/nodes_utils.py +++ b/pyGHDL/libghdl/vhdl/nodes_utils.py @@ -34,7 +34,7 @@ from pydecor import export -from pyGHDL.libghdl._types import Iir +from pyGHDL.libghdl._types import Iir from pyGHDL.libghdl._decorator import BindToLibGHDL diff --git a/pyGHDL/libghdl/vhdl/parse.py b/pyGHDL/libghdl/vhdl/parse.py index 4f7412274..c3135961f 100644 --- a/pyGHDL/libghdl/vhdl/parse.py +++ b/pyGHDL/libghdl/vhdl/parse.py @@ -41,9 +41,7 @@ from pyGHDL.libghdl._types import Iir from pyGHDL.libghdl._decorator import BindToLibGHDL -__all__ = [ - "Flag_Parse_Parenthesis" -] +__all__ = ["Flag_Parse_Parenthesis"] Flag_Parse_Parenthesis = c_bool.in_dll(libghdl, "vhdl__parse__flag_parse_parenthesis") diff --git a/pyGHDL/libghdl/vhdl/scanner.py b/pyGHDL/libghdl/vhdl/scanner.py index 2ed1d9b11..15d41e9a9 100644 --- a/pyGHDL/libghdl/vhdl/scanner.py +++ b/pyGHDL/libghdl/vhdl/scanner.py @@ -41,10 +41,7 @@ from pyGHDL.libghdl._types import SourceFileEntry, NameId from pyGHDL.libghdl._decorator import BindToLibGHDL -__all__ = [ - "Current_Token", - "Flag_Comment" -] +__all__ = ["Current_Token", "Flag_Comment"] # This is a c_int, so you want to use its .value Current_Token = c_int.in_dll(libghdl, "vhdl__scanner__current_token") diff --git a/pyGHDL/libghdl/vhdl/sem_lib.py b/pyGHDL/libghdl/vhdl/sem_lib.py index 9702302a2..c281a299c 100644 --- a/pyGHDL/libghdl/vhdl/sem_lib.py +++ b/pyGHDL/libghdl/vhdl/sem_lib.py @@ -34,7 +34,7 @@ from pydecor import export -from pyGHDL.libghdl._types import SourceFileEntry, Iir_Design_File, Iir_Design_Unit +from pyGHDL.libghdl._types import SourceFileEntry, Iir_Design_File, Iir_Design_Unit from pyGHDL.libghdl._decorator import BindToLibGHDL diff --git a/pyGHDL/libghdl/vhdl/std_package.py b/pyGHDL/libghdl/vhdl/std_package.py index 690dc78a4..600aaea83 100644 --- a/pyGHDL/libghdl/vhdl/std_package.py +++ b/pyGHDL/libghdl/vhdl/std_package.py @@ -35,21 +35,25 @@ from ctypes import c_int32 from pyGHDL.libghdl import libghdl -from pyGHDL.libghdl._types import Location_Type, Iir_Package_Declaration, Iir_Enumeration_Type_Definition +from pyGHDL.libghdl._types import ( + Location_Type, + Iir_Package_Declaration, + Iir_Enumeration_Type_Definition, +) -__all__ = [ - "Std_Location", - "Standard_Package", - "Character_Type_Definition" -] +__all__ = ["Std_Location", "Standard_Package", "Character_Type_Definition"] Std_Location: Location_Type = c_int32.in_dll(libghdl, "vhdl__std_package__std_location") """Virtual location for the ``std.standard`` package. Use ``.value`` to access this variable inside libghdl.""" -Standard_Package: Iir_Package_Declaration = c_int32.in_dll(libghdl, "vhdl__std_package__standard_package") +Standard_Package: Iir_Package_Declaration = c_int32.in_dll( + libghdl, "vhdl__std_package__standard_package" +) """Virtual package ``std.package``. Use ``.value`` to access this variable inside libghdl.""" -Character_Type_Definition: Iir_Enumeration_Type_Definition = c_int32.in_dll(libghdl, "vhdl__std_package__character_type_definition") +Character_Type_Definition: Iir_Enumeration_Type_Definition = c_int32.in_dll( + libghdl, "vhdl__std_package__character_type_definition" +) """Predefined character. Use ``.value`` to access this variable inside libghdl.""" -- cgit v1.2.3