diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-23 11:52:41 +0200 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2021-06-23 11:52:41 +0200 |
commit | 700a2e85da31c53067b4b4139b1a0c2f78818c68 (patch) | |
tree | fa1e1a11f33453464fe1fedc7d1aa734f4a96d01 /pyGHDL/dom | |
parent | 95d5cb9329ee335a64e444ed0fd93bb0950edc5a (diff) | |
download | ghdl-700a2e85da31c53067b4b4139b1a0c2f78818c68.tar.gz ghdl-700a2e85da31c53067b4b4139b1a0c2f78818c68.tar.bz2 ghdl-700a2e85da31c53067b4b4139b1a0c2f78818c68.zip |
First primitive handling of selected names.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/Subprogram.py | 58 | ||||
-rw-r--r-- | pyGHDL/dom/Symbol.py | 9 | ||||
-rw-r--r-- | pyGHDL/dom/_Translate.py | 11 | ||||
-rw-r--r-- | pyGHDL/dom/_Utils.py | 17 | ||||
-rw-r--r-- | pyGHDL/dom/formatting/prettyprint.py | 4 |
5 files changed, 70 insertions, 29 deletions
diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py index b3c47bfe5..0f10ebf62 100644 --- a/pyGHDL/dom/Subprogram.py +++ b/pyGHDL/dom/Subprogram.py @@ -30,6 +30,8 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ +from typing import List + from pyGHDL.dom.Symbol import SimpleSubTypeSymbol from pyGHDL.libghdl.vhdl import nodes from pydecor import export @@ -39,14 +41,27 @@ from pyVHDLModel.VHDLModel import ( Function as VHDLModel_Function, Procedure as VHDLModel_Procedure, SubTypeOrSymbol, + GenericInterfaceItem, + ParameterInterfaceItem, ) from pyGHDL.libghdl._types import Iir @export class Function(VHDLModel_Function): - def __init__(self, functionName: str, returnType: SubTypeOrSymbol): + def __init__( + self, + functionName: str, + returnType: SubTypeOrSymbol, + genericItems: List[GenericInterfaceItem] = None, + parameterItems: List[ParameterInterfaceItem] = None, + ): super().__init__(functionName) + + self._genericItems = [] if genericItems is None else [g for g in genericItems] + self._parameterItems = ( + [] if parameterItems is None else [p for p in parameterItems] + ) self._returnType = returnType @classmethod @@ -57,27 +72,34 @@ class Function(VHDLModel_Function): ) functionName = GetNameOfNode(node) + + generics = GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)) + parameters = GetParameterFromChainedNodes( + nodes.Get_Interface_Declaration_Chain(node) + ) + returnType = nodes.Get_Return_Type_Mark(node) returnTypeName = GetNameOfNode(returnType) - returnTypeSymbol = SimpleSubTypeSymbol(returnTypeName) - function = cls(functionName, returnTypeSymbol) - - for generic in GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)): - function.GenericItems.append(generic) - for port in GetParameterFromChainedNodes( - nodes.Get_Interface_Declaration_Chain(node) - ): - function.ParameterItems.append(port) - return function + return cls(functionName, returnTypeSymbol, generics, parameters) @export class Procedure(VHDLModel_Procedure): - def __init__(self, procedureName: str): + def __init__( + self, + procedureName: str, + genericItems: List[GenericInterfaceItem] = None, + parameterItems: List[ParameterInterfaceItem] = None, + ): super().__init__(procedureName) + self._genericItems = [] if genericItems is None else [g for g in genericItems] + self._parameterItems = ( + [] if parameterItems is None else [p for p in parameterItems] + ) + @classmethod def parse(cls, node: Iir): from pyGHDL.dom._Translate import ( @@ -87,13 +109,9 @@ class Procedure(VHDLModel_Procedure): procedureName = GetNameOfNode(node) - procedure = cls(procedureName) - - for generic in GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)): - procedure.GenericItems.append(generic) - for port in GetParameterFromChainedNodes( + generics = GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)) + parameters = GetParameterFromChainedNodes( nodes.Get_Interface_Declaration_Chain(node) - ): - procedure.ParameterItems.append(port) + ) - return procedure + return cls(procedureName, generics, parameters) diff --git a/pyGHDL/dom/Symbol.py b/pyGHDL/dom/Symbol.py index 1865e4481..cde02ba5e 100644 --- a/pyGHDL/dom/Symbol.py +++ b/pyGHDL/dom/Symbol.py @@ -30,7 +30,7 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ============================================================================ -from typing import List +from typing import List, Iterator from pydecor import export from pyVHDLModel.VHDLModel import ( @@ -66,11 +66,10 @@ class EnumerationLiteralSymbol(VHDLModel_EnumerationLiteralSymbol): @export class SimpleSubTypeSymbol(VHDLModel_SimpleSubTypeSymbol): def __init__(self, subTypeName: str): - super().__init__(subTypeName=subTypeName) + if isinstance(subTypeName, (List, Iterator)): + subTypeName = ".".join(subTypeName) - @classmethod - def parse(cls, node): - pass + super().__init__(subTypeName=subTypeName) @export diff --git a/pyGHDL/dom/_Translate.py b/pyGHDL/dom/_Translate.py index beb13a11c..47d8c0b75 100644 --- a/pyGHDL/dom/_Translate.py +++ b/pyGHDL/dom/_Translate.py @@ -49,7 +49,12 @@ from pyVHDLModel.VHDLModel import ( from pyGHDL.libghdl import utils from pyGHDL.libghdl._types import Iir from pyGHDL.libghdl.vhdl import nodes -from pyGHDL.dom._Utils import GetNameOfNode, GetIirKindOfNode, GetPositionOfNode +from pyGHDL.dom._Utils import ( + GetNameOfNode, + GetIirKindOfNode, + GetPositionOfNode, + GetSelectedName, +) from pyGHDL.dom.Common import DOMException from pyGHDL.dom.Symbol import ( SimpleObjectOrFunctionCallSymbol, @@ -198,6 +203,8 @@ def GetSubTypeIndicationFromIndicationNode( kind = GetIirKindOfNode(subTypeIndicationNode) if kind == nodes.Iir_Kind.Simple_Name: return GetSimpleTypeFromNode(subTypeIndicationNode) + elif kind == nodes.Iir_Kind.Selected_Name: + return GetSimpleTypeFromNode(subTypeIndicationNode) elif kind == nodes.Iir_Kind.Array_Subtype_Definition: return GetConstrainedSubTypeFromNode(subTypeIndicationNode) else: @@ -210,7 +217,7 @@ def GetSubTypeIndicationFromIndicationNode( @export def GetSimpleTypeFromNode(subTypeIndicationNode: Iir) -> SimpleSubTypeSymbol: - subTypeName = GetNameOfNode(subTypeIndicationNode) + subTypeName = GetSelectedName(subTypeIndicationNode) return SimpleSubTypeSymbol(subTypeName) diff --git a/pyGHDL/dom/_Utils.py b/pyGHDL/dom/_Utils.py index a39638559..1c109c9dc 100644 --- a/pyGHDL/dom/_Utils.py +++ b/pyGHDL/dom/_Utils.py @@ -97,6 +97,23 @@ def GetNameOfNode(node: Iir) -> str: @export +def GetSelectedName(node: Iir): + names = [] + kind = GetIirKindOfNode(node) + if kind == nodes.Iir_Kind.Simple_Name: + return GetNameOfNode(node) + + while kind != nodes.Iir_Kind.Simple_Name: + names.append(GetNameOfNode(node)) + node = nodes.Get_Prefix(node) + kind = GetIirKindOfNode(node) + + names.append(GetNameOfNode(node)) + + return reversed(names) + + +@export def GetModeOfNode(node: Iir) -> Mode: """Return the mode of a :obj:`node`.""" diff --git a/pyGHDL/dom/formatting/prettyprint.py b/pyGHDL/dom/formatting/prettyprint.py index 26a5d1916..3a0a49cc1 100644 --- a/pyGHDL/dom/formatting/prettyprint.py +++ b/pyGHDL/dom/formatting/prettyprint.py @@ -410,8 +410,8 @@ class PrettyPrint: ) else: raise PrettyPrintException( - "Unhandled constraint kind for {entity} '{name}'.".format( - entity=entity, name=name + "Unhandled subtype kind '{type}' for {entity} '{name}'.".format( + type=subTypeIndication.__class__.__name__, entity=entity, name=name ) ) |