diff options
author | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2022-12-27 12:28:40 +0100 |
---|---|---|
committer | Patrick Lehmann <Patrick.Lehmann@plc2.de> | 2022-12-27 12:28:40 +0100 |
commit | 86a96a70103d0bd34213467c957144b2d27ae77f (patch) | |
tree | d80722ccecb0dad8ed2cae254c6d94e73eadc0e6 /pyGHDL/dom | |
parent | e38cf3c90f874db468b9943073b17635a1479e2f (diff) | |
download | ghdl-86a96a70103d0bd34213467c957144b2d27ae77f.tar.gz ghdl-86a96a70103d0bd34213467c957144b2d27ae77f.tar.bz2 ghdl-86a96a70103d0bd34213467c957144b2d27ae77f.zip |
Implemented GetContextSymbol and fixed how ContextReferenceSymbols are created.
Diffstat (limited to 'pyGHDL/dom')
-rw-r--r-- | pyGHDL/dom/DesignUnit.py | 8 | ||||
-rw-r--r-- | pyGHDL/dom/_Utils.py | 11 |
2 files changed, 14 insertions, 5 deletions
diff --git a/pyGHDL/dom/DesignUnit.py b/pyGHDL/dom/DesignUnit.py index 0b74940b2..8d9c677ad 100644 --- a/pyGHDL/dom/DesignUnit.py +++ b/pyGHDL/dom/DesignUnit.py @@ -69,7 +69,7 @@ from pyGHDL.libghdl import utils from pyGHDL.libghdl._types import Iir from pyGHDL.libghdl.vhdl import nodes from pyGHDL.dom import DOMMixin, Position, DOMException -from pyGHDL.dom._Utils import GetNameOfNode, GetDocumentationOfNode, GetPackageMemberSymbol +from pyGHDL.dom._Utils import GetNameOfNode, GetDocumentationOfNode, GetPackageMemberSymbol, GetContextSymbol from pyGHDL.dom._Translate import ( GetGenericsFromChainedNodes, GetPortsFromChainedNodes, @@ -110,11 +110,9 @@ class ContextReference(VHDLModel_ContextReference, DOMMixin): @classmethod def parse(cls, contextNode: Iir): - from pyGHDL.dom._Translate import GetNameFromNode - - contexts = [ContextReferenceSymbol(GetNameFromNode(nodes.Get_Selected_Name(contextNode)))] + contexts = [GetContextSymbol(nodes.Get_Selected_Name(contextNode))] for context in utils.chain_iter(nodes.Get_Context_Reference_Chain(contextNode)): - contexts.append(ContextReferenceSymbol(GetNameFromNode(nodes.Get_Selected_Name(context)))) + contexts.append(GetContextSymbol(nodes.Get_Selected_Name(context))) return cls(contextNode, contexts) diff --git a/pyGHDL/dom/_Utils.py b/pyGHDL/dom/_Utils.py index 1b9dd06fb..3803374f3 100644 --- a/pyGHDL/dom/_Utils.py +++ b/pyGHDL/dom/_Utils.py @@ -39,6 +39,7 @@ from pyGHDL.dom.Symbol import ( PackageReferenceSymbol, PackageMembersReferenceSymbol, AllPackageMembersReferenceSymbol, + ContextReferenceSymbol, ) from pyVHDLModel.SyntaxModel import Mode @@ -166,6 +167,16 @@ def GetPackageSymbol(node: Iir) -> PackageReferenceSymbol: raise DOMException(f"{kind.name} at {Position.parse(node)}") +def GetContextSymbol(node: Iir) -> ContextReferenceSymbol: + kind = GetIirKindOfNode(node) + if kind == nodes.Iir_Kind.Selected_Name: + name = GetNameOfNode(node) + prefixName = GetLibrarySymbol(nodes.Get_Prefix(node)) + return ContextReferenceSymbol(node, name, prefixName) + else: + raise DOMException(f"{kind.name} at {Position.parse(node)}") + + def GetLibrarySymbol(node: Iir) -> LibraryReferenceSymbol: kind = GetIirKindOfNode(node) if kind == nodes.Iir_Kind.Simple_Name: |