From 111fe055b2f0f3a0225d2553cf739572d691a14d Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Sat, 26 Jun 2021 13:48:09 +0200 Subject: More DOM improvements (#1806) * First try to handle names. * Reworked names. * Reworked range expressions. * Handle AttributeNames. * Added handling of file declaration and attribute declarations. * Improved error outputs. * Handle protected types. * Make black happy with ugly code. * Handle Null literal and File parameters. * File type and physical type. * Don't fail on reported syntax errors. Catch call errors into libghdl. * Improved Sanity checks for pyGHDL.dom. * Load sourcecode via Python and process in-memory. Fixed testcases. * Added package instantiations and packages with generics. * Added UseClause, AttributeSpecification and PhysicalTypes. * Improved pretty-printing. * Fixed AttributeName in subtype indication. * Get code position of IIR nodes. * Added DOMMixin into all derived classes. * Mark as not yet implemented. * Pinned pyVHDLModel version to v0.10.4. * Removed xfail in LSP test. Bumped requirement of pyVHDLModel to v0.10.4. Fixed some Codacy issues. (cherry picked from commit f64e7ed7c3d69cbf84cd60db8e9b085e90b846cb) --- pyGHDL/dom/Subprogram.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'pyGHDL/dom/Subprogram.py') diff --git a/pyGHDL/dom/Subprogram.py b/pyGHDL/dom/Subprogram.py index 0f10ebf62..42e3c7d79 100644 --- a/pyGHDL/dom/Subprogram.py +++ b/pyGHDL/dom/Subprogram.py @@ -32,11 +32,8 @@ # ============================================================================ from typing import List -from pyGHDL.dom.Symbol import SimpleSubTypeSymbol -from pyGHDL.libghdl.vhdl import nodes from pydecor import export -from pyGHDL.dom._Utils import GetNameOfNode from pyVHDLModel.VHDLModel import ( Function as VHDLModel_Function, Procedure as VHDLModel_Procedure, @@ -45,19 +42,26 @@ from pyVHDLModel.VHDLModel import ( ParameterInterfaceItem, ) from pyGHDL.libghdl._types import Iir +from pyGHDL.libghdl.vhdl import nodes +from pyGHDL.dom import DOMMixin +from pyGHDL.dom._Utils import GetNameOfNode +from pyGHDL.dom.Symbol import SimpleSubTypeSymbol @export -class Function(VHDLModel_Function): +class Function(VHDLModel_Function, DOMMixin): def __init__( self, + node: Iir, functionName: str, returnType: SubTypeOrSymbol, genericItems: List[GenericInterfaceItem] = None, parameterItems: List[ParameterInterfaceItem] = None, ): super().__init__(functionName) + DOMMixin.__init__(self, node) + # TODO: move to model self._genericItems = [] if genericItems is None else [g for g in genericItems] self._parameterItems = ( [] if parameterItems is None else [p for p in parameterItems] @@ -65,53 +69,56 @@ class Function(VHDLModel_Function): self._returnType = returnType @classmethod - def parse(cls, node: Iir): + def parse(cls, functionNode: Iir) -> "Function": from pyGHDL.dom._Translate import ( GetGenericsFromChainedNodes, GetParameterFromChainedNodes, ) - functionName = GetNameOfNode(node) + functionName = GetNameOfNode(functionNode) - generics = GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)) + generics = GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(functionNode)) parameters = GetParameterFromChainedNodes( - nodes.Get_Interface_Declaration_Chain(node) + nodes.Get_Interface_Declaration_Chain(functionNode) ) - returnType = nodes.Get_Return_Type_Mark(node) + returnType = nodes.Get_Return_Type_Mark(functionNode) returnTypeName = GetNameOfNode(returnType) - returnTypeSymbol = SimpleSubTypeSymbol(returnTypeName) + returnTypeSymbol = SimpleSubTypeSymbol(returnType, returnTypeName) - return cls(functionName, returnTypeSymbol, generics, parameters) + return cls(functionNode, functionName, returnTypeSymbol, generics, parameters) @export -class Procedure(VHDLModel_Procedure): +class Procedure(VHDLModel_Procedure, DOMMixin): def __init__( self, + node: Iir, procedureName: str, genericItems: List[GenericInterfaceItem] = None, parameterItems: List[ParameterInterfaceItem] = None, ): super().__init__(procedureName) + DOMMixin.__init__(self, node) + # TODO: move to model 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): + def parse(cls, procedureNode: Iir) -> "Procedure": from pyGHDL.dom._Translate import ( GetGenericsFromChainedNodes, GetParameterFromChainedNodes, ) - procedureName = GetNameOfNode(node) + procedureName = GetNameOfNode(procedureNode) - generics = GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(node)) + generics = GetGenericsFromChainedNodes(nodes.Get_Generic_Chain(procedureNode)) parameters = GetParameterFromChainedNodes( - nodes.Get_Interface_Declaration_Chain(node) + nodes.Get_Interface_Declaration_Chain(procedureNode) ) - return cls(procedureName, generics, parameters) + return cls(procedureNode, procedureName, generics, parameters) -- cgit v1.2.3