From 4be45cbc3b4fc20eae8f817fce7bd508d6964691 Mon Sep 17 00:00:00 2001 From: Patrick Lehmann Date: Sun, 25 Dec 2022 22:27:02 +0100 Subject: Converted more symbols for packages and contexts. --- pyGHDL/dom/DesignUnit.py | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'pyGHDL/dom/DesignUnit.py') diff --git a/pyGHDL/dom/DesignUnit.py b/pyGHDL/dom/DesignUnit.py index eb7dfcb88..3e3784dde 100644 --- a/pyGHDL/dom/DesignUnit.py +++ b/pyGHDL/dom/DesignUnit.py @@ -39,7 +39,7 @@ This module contains all DOM classes for VHDL's design units (:class:`context Union[PackageMembersReferenceSymbol, AllPackageMembersReferenceSymbol]: + kind = GetIirKindOfNode(node) + prefixName = cls.GetPackageSymbol(nodes.Get_Prefix(node)) + if kind == nodes.Iir_Kind.Selected_Name: + name = GetNameOfNode(node) + return PackageMembersReferenceSymbol(node, name, prefixName) + elif kind == nodes.Iir_Kind.Selected_By_All_Name: + return AllPackageMembersReferenceSymbol(node, prefixName) + else: + raise DOMException() + + @classmethod + def GetPackageSymbol(cls, node: Iir) -> PackageReferenceSymbol: + kind = GetIirKindOfNode(node) + if kind == nodes.Iir_Kind.Selected_Name: + name = GetNameOfNode(node) + prefixName = cls.GetLibrarySymbol(nodes.Get_Prefix(node)) + return PackageReferenceSymbol(node, name, prefixName) + else: + raise DOMException() - uses = [PackageReferenceSymbol(GetNameFromNode(nodes.Get_Selected_Name(useNode)))] + @classmethod + def GetLibrarySymbol(cls, node: Iir) -> LibraryReferenceSymbol: + kind = GetIirKindOfNode(node) + if kind == nodes.Iir_Kind.Simple_Name: + name = GetNameOfNode(node) + return LibraryReferenceSymbol(node, name) + else: + raise DOMException() + + @classmethod + def parse(cls, useNode: Iir): + uses = [cls.GetPackageMemberSymbol(nodes.Get_Selected_Name(useNode))] for use in utils.chain_iter(nodes.Get_Use_Clause_Chain(useNode)): - uses.append(PackageReferenceSymbol(GetNameFromNode(nodes.Get_Selected_Name(use)))) + uses.append(cls.GetPackageMemberSymbol(nodes.Get_Selected_Name(use))) return cls(useNode, uses) -- cgit v1.2.3