diff options
-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: |