diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-07-26 21:38:43 +0200 |
---|---|---|
committer | umarcor <unai.martinezcorral@ehu.eus> | 2021-08-23 16:35:32 +0200 |
commit | 47ec53b54ce661a806f371734754483ef906c563 (patch) | |
tree | 5a4dd61771cb85e849698d1fe09aa064697357a9 /pyGHDL/dom | |
parent | 77f969a11ea5ac38f007dbf3aab986dcf10125b0 (diff) | |
download | ghdl-47ec53b54ce661a806f371734754483ef906c563.tar.gz ghdl-47ec53b54ce661a806f371734754483ef906c563.tar.bz2 ghdl-47ec53b54ce661a806f371734754483ef906c563.zip |
Also handle multiple identifiers in record elements.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/InterfaceItem.py | 24 | ||||
-rw-r--r-- | pyGHDL/dom/Type.py | 36 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 8 |
3 files changed, 51 insertions, 17 deletions
diff --git a/pyGHDL/dom/InterfaceItem.py b/pyGHDL/dom/InterfaceItem.py index 2396ff0c8..3a9c7238f 100644 --- a/pyGHDL/dom/InterfaceItem.py +++ b/pyGHDL/dom/InterfaceItem.py @@ -83,9 +83,9 @@ class GenericConstantInterfaceItem(VHDLModel_GenericConstantInterfaceItem, DOMMi return cls( genericNode, - list( + [ name, - ), + ], mode, subtypeIndication, value, @@ -188,9 +188,9 @@ class PortSignalInterfaceItem(VHDLModel_PortSignalInterfaceItem, DOMMixin): return cls( portNode, - list( + [ name, - ), + ], mode, subtypeIndication, value, @@ -229,9 +229,9 @@ class ParameterConstantInterfaceItem( return cls( parameterNode, - list( + [ name, - ), + ], mode, subtypeIndication, value, @@ -270,9 +270,9 @@ class ParameterVariableInterfaceItem( return cls( parameterNode, - list( + [ name, - ), + ], mode, subtypeIndication, value, @@ -309,9 +309,9 @@ class ParameterSignalInterfaceItem(VHDLModel_ParameterSignalInterfaceItem, DOMMi return cls( parameterNode, - list( + [ name, - ), + ], mode, subtypeIndication, value, @@ -338,8 +338,8 @@ class ParameterFileInterfaceItem(VHDLModel_ParameterFileInterfaceItem, DOMMixin) return cls( parameterNode, - list( + [ name, - ), + ], subtypeIndication, ) diff --git a/pyGHDL/dom/Type.py b/pyGHDL/dom/Type.py index 64039c147..98b92b3f0 100644 --- a/pyGHDL/dom/Type.py +++ b/pyGHDL/dom/Type.py @@ -52,7 +52,7 @@ from pyVHDLModel.SyntaxModel import ( ) from pyGHDL.libghdl import utils from pyGHDL.libghdl._types import Iir -from pyGHDL.libghdl.vhdl import nodes +from pyGHDL.libghdl.vhdl import nodes, flists from pyGHDL.dom import DOMMixin, DOMException from pyGHDL.dom._Utils import GetNameOfNode, GetIirKindOfNode from pyGHDL.dom.Symbol import SimpleSubtypeSymbol @@ -176,8 +176,8 @@ class ArrayType(VHDLModel_ArrayType, DOMMixin): @export class RecordTypeElement(VHDLModel_RecordTypeElement, DOMMixin): - def __init__(self, node: Iir, identifier: str, subtype: SubtypeOrSymbol): - super().__init__(identifier, subtype) + def __init__(self, node: Iir, identifiers: List[str], subtype: SubtypeOrSymbol): + super().__init__(identifiers, subtype) DOMMixin.__init__(self, node) @classmethod @@ -189,7 +189,13 @@ class RecordTypeElement(VHDLModel_RecordTypeElement, DOMMixin): elementDeclarationNode, "record element", elementName ) - return cls(elementDeclarationNode, elementName, elementType) + return cls( + elementDeclarationNode, + [ + elementName, + ], + elementType, + ) @export @@ -204,8 +210,28 @@ class RecordType(VHDLModel_RecordType, DOMMixin): def parse(cls, typeName: str, typeDefinitionNode: Iir) -> "RecordType": elements = [] elementDeclarations = nodes.Get_Elements_Declaration_List(typeDefinitionNode) - for elementDeclaration in utils.flist_iter(elementDeclarations): + + elementCount = flists.Flast(elementDeclarations) + 1 + index = 0 + while index < elementCount: + elementDeclaration = flists.Get_Nth_Element(elementDeclarations, index) + element = RecordTypeElement.parse(elementDeclaration) + + # Lookahead for elements with multiple identifiers at once + if nodes.Get_Has_Identifier_List(elementDeclaration): + index += 1 + while index < elementCount: + nextNode: Iir = flists.Get_Nth_Element(elementDeclarations, index) + # Consecutive identifiers are found, if the subtype indication is Null + if nodes.Get_Subtype_Indication(nextNode) == nodes.Null_Iir: + element.Identifiers.append(GetNameOfNode(nextNode)) + else: + break + index += 1 + else: + index += 1 + elements.append(element) return cls(typeDefinitionNode, typeName, elements) diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index 740c613b6..916f0c8df 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -478,9 +478,11 @@ def GetGenericsFromChainedNodes( genericConstant = GenericConstantInterfaceItem.parse(generic) + # Lookahead for generics with multiple identifiers at once if nodes.Get_Has_Identifier_List(generic): nextNode = nodes.Get_Chain(generic) for nextGeneric in utils.chain_iter(nextNode): + # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextGeneric) == nodes.Null_Iir: genericConstant.Identifiers.append(GetNameOfNode(nextGeneric)) else: @@ -529,9 +531,11 @@ def GetPortsFromChainedNodes( portSignal = PortSignalInterfaceItem.parse(port) + # Lookahead for ports with multiple identifiers at once if nodes.Get_Has_Identifier_List(port): nextNode = nodes.Get_Chain(port) for nextPort in utils.chain_iter(nextNode): + # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextPort) == nodes.Null_Iir: portSignal.Identifiers.append(GetNameOfNode(nextPort)) else: @@ -593,9 +597,11 @@ def GetParameterFromChainedNodes( ) ) + # Lookahead for parameters with multiple identifiers at once if nodes.Get_Has_Identifier_List(parameter): nextNode = nodes.Get_Chain(parameter) for nextParameter in utils.chain_iter(nextNode): + # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextParameter) == nodes.Null_Iir: param.Identifiers.append(GetNameOfNode(nextParameter)) else: @@ -721,9 +727,11 @@ def GetDeclaredItemsFromChainedNodes( item = nodes.Get_Chain(item) continue + # Lookahead for objects with multiple identifiers at once if nodes.Get_Has_Identifier_List(item): nextNode = nodes.Get_Chain(item) for nextItem in utils.chain_iter(nextNode): + # Consecutive identifiers are found, if the subtype indication is Null if nodes.Get_Subtype_Indication(nextItem) == nodes.Null_Iir: obj.Identifiers.append(GetNameOfNode(nextItem)) else: |