aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pyGHDL/dom/DesignUnit.py45
-rw-r--r--pyGHDL/dom/NonStandard.py8
-rw-r--r--pyGHDL/dom/Symbol.py41
3 files changed, 79 insertions, 15 deletions
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 <E
"""
-from typing import Iterable
+from typing import Iterable, Union
from pyTooling.Decorators import export
@@ -63,15 +63,13 @@ from pyVHDLModel.SyntaxModel import (
GenericInterfaceItem,
PortInterfaceItem,
ConcurrentStatement,
- PackageReferenceSymbol,
- ContextReferenceSymbol,
)
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
+from pyGHDL.dom._Utils import GetNameOfNode, GetDocumentationOfNode, GetIirKindOfNode
from pyGHDL.dom._Translate import (
GetGenericsFromChainedNodes,
GetPortsFromChainedNodes,
@@ -79,7 +77,7 @@ from pyGHDL.dom._Translate import (
GetConcurrentStatementsFromChainedNodes,
)
from pyGHDL.dom.Names import SimpleName
-from pyGHDL.dom.Symbol import EntitySymbol
+from pyGHDL.dom.Symbol import EntitySymbol, LibraryReferenceSymbol, PackageReferenceSymbol, PackageMembersReferenceSymbol, AllPackageMembersReferenceSymbol, ContextReferenceSymbol
@export
@@ -96,12 +94,41 @@ class UseClause(VHDLModel_UseClause, DOMMixin):
DOMMixin.__init__(self, useNode)
@classmethod
- def parse(cls, useNode: Iir):
- from pyGHDL.dom._Translate import GetNameFromNode
+ def GetPackageMemberSymbol(cls, node: Iir) -> 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)
diff --git a/pyGHDL/dom/NonStandard.py b/pyGHDL/dom/NonStandard.py
index 0bfc774bf..64c34b527 100644
--- a/pyGHDL/dom/NonStandard.py
+++ b/pyGHDL/dom/NonStandard.py
@@ -48,7 +48,6 @@ from pyVHDLModel.SyntaxModel import (
Design as VHDLModel_Design,
Library as VHDLModel_Library,
Document as VHDLModel_Document,
- LibraryReferenceSymbol,
)
from pyGHDL.libghdl import (
@@ -82,8 +81,8 @@ from pyGHDL.dom.DesignUnit import (
PackageInstantiation,
LibraryClause,
UseClause,
- ContextReference,
-)
+ ContextReference, )
+from pyGHDL.dom.Symbol import LibraryReferenceSymbol
from pyGHDL.dom.PSL import VerificationUnit, VerificationProperty, VerificationMode
@@ -195,7 +194,8 @@ class Document(VHDLModel_Document):
for item in utils.chain_iter(context):
itemKind = GetIirKindOfNode(item)
if itemKind is nodes.Iir_Kind.Library_Clause:
- contextNames.append(LibraryReferenceSymbol(SimpleName(item, GetNameOfNode(item))))
+ libraryIdentifier = GetNameOfNode(item)
+ contextNames.append(LibraryReferenceSymbol(item, libraryIdentifier))
if nodes.Get_Has_Identifier_List(item):
continue
diff --git a/pyGHDL/dom/Symbol.py b/pyGHDL/dom/Symbol.py
index 0dd0fefa9..ed1acb7b1 100644
--- a/pyGHDL/dom/Symbol.py
+++ b/pyGHDL/dom/Symbol.py
@@ -34,7 +34,6 @@ from typing import List, Iterator
from pyTooling.Decorators import export, InheritDocString
-from pyGHDL.dom.Names import SimpleName
from pyVHDLModel.SyntaxModel import (
EntitySymbol as VHDLModel_EntitySymbol,
ArchitectureSymbol as VHDLModel_ArchitectureSymbol,
@@ -46,13 +45,51 @@ from pyVHDLModel.SyntaxModel import (
IndexedObjectOrFunctionCallSymbol as VHDLModel_IndexedObjectOrFunctionCallSymbol,
ConstraintUnion,
Name,
+ LibraryReferenceSymbol as VHDLModel_LibraryReferenceSymbol,
+ PackageReferenceSymbol as VHDLModel_PackageReferenceSymbol,
+ PackageMembersReferenceSymbol as VHDLModel_PackageMembersReferenceSymbol,
+ AllPackageMembersReferenceSymbol as VHDLModel_AllPackageMembersReferenceSymbol,
+ ContextReferenceSymbol as VHDLModel_ContextReferenceSymbol,
)
from pyGHDL.libghdl._types import Iir
from pyGHDL.dom import DOMMixin
+from pyGHDL.dom.Names import SimpleName
from pyGHDL.dom.Range import Range
-__all__ = []
+@export
+class LibraryReferenceSymbol(VHDLModel_LibraryReferenceSymbol, DOMMixin):
+ def __init__(self, libraryNode: Iir, identifier: str):
+ super().__init__(identifier)
+ DOMMixin.__init__(self, libraryNode)
+
+
+@export
+class PackageReferenceSymbol(VHDLModel_PackageReferenceSymbol, DOMMixin):
+ def __init__(self, libraryNode: Iir, identifier: str, prefix: LibraryReferenceSymbol):
+ super().__init__(identifier, prefix)
+ DOMMixin.__init__(self, libraryNode)
+
+
+@export
+class PackageMembersReferenceSymbol(VHDLModel_PackageMembersReferenceSymbol, DOMMixin):
+ def __init__(self, libraryNode: Iir, identifier: str, prefix: PackageReferenceSymbol):
+ super().__init__(identifier, prefix)
+ DOMMixin.__init__(self, libraryNode)
+
+
+@export
+class AllPackageMembersReferenceSymbol(VHDLModel_AllPackageMembersReferenceSymbol, DOMMixin):
+ def __init__(self, libraryNode: Iir, prefix: PackageReferenceSymbol):
+ super().__init__(prefix)
+ DOMMixin.__init__(self, libraryNode)
+
+
+@export
+class ContextReferenceSymbol(VHDLModel_ContextReferenceSymbol, DOMMixin):
+ def __init__(self, libraryNode: Iir, identifier: str, prefix: LibraryReferenceSymbol):
+ super().__init__(identifier, prefix)
+ DOMMixin.__init__(self, libraryNode)
@export