diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-07-26 02:36:23 +0200 |
---|---|---|
committer | umarcor <unai.martinezcorral@ehu.eus> | 2021-08-23 16:35:32 +0200 |
commit | 1a67eb54fc54601dd4945d75d53da87b8e152053 (patch) | |
tree | b97674b1496b296dd107ddca14a3e95c6b21fbf5 /pyGHDL/dom | |
parent | 5fae449cbac688b5779f0ef2ec2052bb3f9bed00 (diff) | |
download | ghdl-1a67eb54fc54601dd4945d75d53da87b8e152053.tar.gz ghdl-1a67eb54fc54601dd4945d75d53da87b8e152053.tar.bz2 ghdl-1a67eb54fc54601dd4945d75d53da87b8e152053.zip |
Handle declarations with multiple identifiers.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/InterfaceItem.py | 38 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 106 |
2 files changed, 93 insertions, 51 deletions
diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index 9f4d1c5e2..fc4e6e5a9 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -30,6 +30,8 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ +from typing import List + from pydecor import export from pyVHDLModel.SyntaxModel import ( @@ -63,12 +65,12 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi def __init__( self, node: Iir, - identifier: str, + identifiers: List[str], mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: Expression, ): - super().__init__(identifier, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression) DOMMixin.__init__(self, node) @classmethod @@ -79,7 +81,7 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi default = nodes.Get_Default_Value(genericNode) value = GetExpressionFromNode(default) if default else None - return cls(genericNode, name, mode, subtypeIndication, value) + return cls(genericNode, [name, ], mode, subtypeIndication, value) @export @@ -155,12 +157,12 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): def __init__( self, node: Iir, - identifier: str, + identifiers: List[str], mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: Expression = None, ): - super().__init__(identifier, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression) DOMMixin.__init__(self, node) @classmethod @@ -176,7 +178,7 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): else None ) - return cls(portNode, name, mode, subtypeIndication, value) + return cls(portNode, [name, ], mode, subtypeIndication, value) @export @@ -186,12 +188,12 @@ class ParameterConstantInterfaceItem( def __init__( self, node: Iir, - identifier: str, + identifiers: List[str], mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: Expression = None, ): - super().__init__(identifier, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression) DOMMixin.__init__(self, node) @classmethod @@ -209,7 +211,7 @@ class ParameterConstantInterfaceItem( else None ) - return cls(parameterNode, name, mode, subtypeIndication, value) + return cls(parameterNode, [name, ], mode, subtypeIndication, value) @export @@ -219,12 +221,12 @@ class ParameterVariableInterfaceItem( def __init__( self, node: Iir, - identifier: str, + identifiers: List[str], mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: Expression = None, ): - super().__init__(identifier, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression) DOMMixin.__init__(self, node) @classmethod @@ -242,7 +244,7 @@ class ParameterVariableInterfaceItem( else None ) - return cls(parameterNode, name, mode, subtypeIndication, value) + return cls(parameterNode, [name, ], mode, subtypeIndication, value) @export @@ -250,12 +252,12 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi def __init__( self, node: Iir, - identifier: str, + identifiers: List[str], mode: Mode, subtype: SubtypeOrSymbol, defaultExpression: Expression = None, ): - super().__init__(identifier, mode, subtype, defaultExpression) + super().__init__(identifiers, mode, subtype, defaultExpression) DOMMixin.__init__(self, node) @classmethod @@ -273,7 +275,7 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi else None ) - return cls(parameterNode, name, mode, subtypeIndication, value) + return cls(parameterNode, [name, ], mode, subtypeIndication, value) @export @@ -281,10 +283,10 @@ class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin) def __init__( self, node: Iir, - identifier: str, + identifiers: List[str], subtype: SubtypeOrSymbol, ): - super().__init__(identifier, subtype) + super().__init__(identifiers, subtype) DOMMixin.__init__(self, node) @classmethod @@ -294,4 +296,4 @@ class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin) parameterNode, "parameter", name ) - return cls(parameterNode, name, subtypeIndication) + return cls(parameterNode, [name, ], subtypeIndication) diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index adff02041..3a10eba3b 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -266,7 +266,6 @@ def GetAnonymousTypeFromNode(node: Iir) -> BaseType: typeName = GetNameOfNode(node) typeDefinition = nodes.Get_Type_Definition(node) if typeDefinition is nodes.Null_Iir: - print(1, node, typeName) return IncompleteType(node, typeName) kind = GetIirKindOfNode(typeDefinition) @@ -309,12 +308,8 @@ def GetSubtypeIndicationFromIndicationNode( subtypeIndicationNode: Iir, entity: str, name: str ) -> SubtypeOrSymbol: if subtypeIndicationNode is nodes.Null_Iir: - print( - "[NOT IMPLEMENTED]: Unhandled multiple declarations for {entity} '{name}'.".format( - entity=entity, name=name - ) - ) - return None + raise ValueError("Parameter 'subtypeIndicationNode' is 'Null_Iir'.") + kind = GetIirKindOfNode(subtypeIndicationNode) if kind in ( nodes.Iir_Kind.Simple_Name, @@ -475,45 +470,75 @@ def GetGenericsFromChainedNodes( GenericFunctionInterfaceItem, ) - for generic in utils.chain_iter(nodeChain): + generic = nodeChain + while generic != nodes.Null_Iir: kind = GetIirKindOfNode(generic) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import GenericConstantInterfaceItem - yield GenericConstantInterfaceItem.parse(generic) - elif kind == nodes.Iir_Kind.Interface_Type_Declaration: - yield GenericTypeInterfaceItem.parse(generic) - elif kind == nodes.Iir_Kind.Interface_Package_Declaration: - yield GenericPackageInterfaceItem.parse(generic) - elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration: - yield GenericProcedureInterfaceItem.parse(generic) - elif kind == nodes.Iir_Kind.Interface_Function_Declaration: - yield GenericFunctionInterfaceItem.parse(generic) + genericConstant = GenericConstantInterfaceItem.parse(generic) + + if nodes.Get_Has_Identifier_List(generic): + nextNode = nodes.Get_Chain(generic) + for nextGeneric in utils.chain_iter(nextNode): + if nodes.Get_Subtype_Indication(nextGeneric) == nodes.Null_Iir: + genericConstant.Identifiers.append(GetNameOfNode(nextGeneric)) + else: + generic = nextGeneric + break + else: + generic = nodes.Get_Chain(generic) + + yield genericConstant else: - position = Position.parse(generic) - raise DOMException( - "Unknown generic kind '{kindName}'({kind}) in generic '{generic}' at {file}:{line}:{column}.".format( - kind=kind, - kindName=kind.name, - generic=generic, - file=position.Filename, - line=position.Line, - column=position.Column, + if kind == nodes.Iir_Kind.Interface_Type_Declaration: + yield GenericTypeInterfaceItem.parse(generic) + elif kind == nodes.Iir_Kind.Interface_Package_Declaration: + yield GenericPackageInterfaceItem.parse(generic) + elif kind == nodes.Iir_Kind.Interface_Procedure_Declaration: + yield GenericProcedureInterfaceItem.parse(generic) + elif kind == nodes.Iir_Kind.Interface_Function_Declaration: + yield GenericFunctionInterfaceItem.parse(generic) + else: + position = Position.parse(generic) + raise DOMException( + "Unknown generic kind '{kindName}'({kind}) in generic '{generic}' at {file}:{line}:{column}.".format( + kind=kind, + kindName=kind.name, + generic=generic, + file=position.Filename, + line=position.Line, + column=position.Column, + ) ) - ) + + generic = nodes.Get_Chain(generic) @export def GetPortsFromChainedNodes( nodeChain: Iir, ) -> Generator[PortInterfaceItem, None, None]: - for port in utils.chain_iter(nodeChain): + + port = nodeChain + while port != nodes.Null_Iir: kind = GetIirKindOfNode(port) if kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import PortSignalInterfaceItem portSignal = PortSignalInterfaceItem.parse(port) + if nodes.Get_Has_Identifier_List(port): + nextNode = nodes.Get_Chain(port) + for nextPort in utils.chain_iter(nextNode): + if nodes.Get_Subtype_Indication(nextPort) == nodes.Null_Iir: + portSignal.Identifiers.append(GetNameOfNode(nextPort)) + else: + port = nextPort + break + else: + port = nodes.Get_Chain(port) + yield portSignal else: position = Position.parse(port) @@ -533,24 +558,26 @@ def GetPortsFromChainedNodes( def GetParameterFromChainedNodes( nodeChain: Iir, ) -> Generator[ParameterInterfaceItem, None, None]: - for parameter in utils.chain_iter(nodeChain): + + parameter = nodeChain + while parameter != nodes.Null_Iir: kind = GetIirKindOfNode(parameter) if kind == nodes.Iir_Kind.Interface_Constant_Declaration: from pyGHDL.dom.InterfaceItem import ParameterConstantInterfaceItem - yield ParameterConstantInterfaceItem.parse(parameter) + param = ParameterConstantInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_Variable_Declaration: from pyGHDL.dom.InterfaceItem import ParameterVariableInterfaceItem - yield ParameterVariableInterfaceItem.parse(parameter) + param = ParameterVariableInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_Signal_Declaration: from pyGHDL.dom.InterfaceItem import ParameterSignalInterfaceItem - yield ParameterSignalInterfaceItem.parse(parameter) + param = ParameterSignalInterfaceItem.parse(parameter) elif kind == nodes.Iir_Kind.Interface_File_Declaration: from pyGHDL.dom.InterfaceItem import ParameterFileInterfaceItem - yield ParameterFileInterfaceItem.parse(parameter) + param = ParameterFileInterfaceItem.parse(parameter) else: position = Position.parse(parameter) raise DOMException( @@ -564,6 +591,19 @@ def GetParameterFromChainedNodes( ) ) + if nodes.Get_Has_Identifier_List(parameter): + nextNode = nodes.Get_Chain(parameter) + for nextParameter in utils.chain_iter(nextNode): + if nodes.Get_Subtype_Indication(nextParameter) == nodes.Null_Iir: + param.Identifiers.append(GetNameOfNode(nextParameter)) + else: + parameter = nextParameter + break + else: + parameter = nodes.Get_Chain(parameter) + + yield param + def GetDeclaredItemsFromChainedNodes( nodeChain: Iir, entity: str, name: str |