diff options
author | Unai Martinez-Corral <38422348+umarcor@users.noreply.github.com> | 2021-06-23 16:07:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-23 16:07:10 +0100 |
commit | c6283d9a9b40c3e9afeba912fcb13aa9d56b9c52 (patch) | |
tree | e1706cb19a2439e3d94657e54c688a36c703f048 /pyGHDL/dom/Subprogram.py | |
parent | 983236ac3dfd0c455a0ac910a9a468ea2c81e5d9 (diff) | |
parent | 240b4fdd90a9f3ca04e8e168bffdc92bea2ca3f3 (diff) | |
download | ghdl-c6283d9a9b40c3e9afeba912fcb13aa9d56b9c52.tar.gz ghdl-c6283d9a9b40c3e9afeba912fcb13aa9d56b9c52.tar.bz2 ghdl-c6283d9a9b40c3e9afeba912fcb13aa9d56b9c52.zip |
DOM: Functions and types (#1804)
Diffstat (limited to 'pyGHDL/dom/Subprogram.py')
-rw-r--r-- | pyGHDL/dom/Subprogram.py | 58 |
1 files changed, 38 insertions, 20 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) |