Regions
Summary
- Package:
- Doc-string:
documented
File |
Expected |
Covered |
Uncovered |
Coverage |
|---|---|---|---|---|
Regions.py |
130 |
130 |
0 |
100.0% |
Source
pyVHDLModel/Regions.pydocumentedundocumentedignoredexcludednot counted
32"""
33This module contains parts of an abstract document language model for VHDL.
34
35tbd.
36"""
...
61
67@export
68class WithGenericsMixin(
69 metaclass=ExtendedType,
70 mixin=True,
71 expects=("_AddToNamespace", "_RemoveFromNamespace", "_ClashingDeclarations")
72):
73 """
74 A mixin-class for language constructs with a generic clause.
75
76 The host class provides ``_AddToNamespace(element)`` and ``_RemoveFromNamespace(element)``, called when a generic is
77 inserted or removed: :class:`~pyVHDLModel.Regions.DeclarationRegionMixin` updates its namespace, a language construct
78 without a namespace implements both as no-operations.
79
80 The host class also provides ``_ClashingDeclarations(item)``, called before a generic is inserted: it returns the
81 declarations sharing an identifier with the new item.
82
83 Indexing the generics (``_IndexGenericItems()``) needs the host's namespace ``_namespace``; a host without one, e.g.
84 a component, can't index them.
85
86 .. seealso::
87
88 * :class:`Package <pyVHDLModel.DesignUnit.Package>`
89 * :class:`Entity <pyVHDLModel.DesignUnit.Entity>`
90 * :class:`Component <pyVHDLModel.DesignUnit.Component>`
91 * :class:`Subprogram <pyVHDLModel.Subprogram.Subprogram>`
92 * :class:`Generic group <pyVHDLModel.Interface.GenericGroup>`
93 """
94 _genericItems: list[GenericInterfaceItemMixin] #: List of all generics, in declaration order.
95
96 def __init__(
97 self,
98 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None,
99 ) -> None:
100 """
101 Initializes a language construct with a generic clause.
102
103 :param genericItems: List of all generics, in declaration order.
104 """
...
110
111 @readonly
112 def GenericItems(self) -> list[GenericInterfaceItemMixin]:
113 """
114 Read-only property to access the generic items (:attr:`_genericItems`).
115
116 :returns: List of generic items.
117 """
...
119
120 @readonly
121 def GenericCount(self) -> int:
122 """
123 Read-only property to return the number of generics in :attr:`_genericItems`.
124
125 :returns: The generic count.
126 """
...
128
129 def IterateSingleGenericDeclarations(
130 self,
131 predicate: Nullable[Callable[[SingleGenericDeclarationMixin | GenericInterfaceItemMixin], bool]] = None
132 ) -> Generator[SingleGenericDeclarationMixin | GenericInterfaceItemMixin, None, None]:
133 """
134 Iterate all generics per declared identifier, in declaration order.
135
136 A generic constant yields one single declaration per identifier: ``generic (A, B : positive)`` yields two. A
137 generic type, subprogram or package declares exactly one identifier and is yielded itself.
138
139 :param predicate: Optional, filter function to select the yielded generics. Default: all.
140 :returns: A generator to iterate all (selected) generics.
141 """
...
156
157 def AddGenericItem(self, genericItem: GenericInterfaceItemMixin) -> None:
158 """
159 Add a generic at the end of the generic clause.
160
161 The generic's parent is set to this language construct, and its identifiers are added to the language construct's
162 namespace, if it has one.
163
164 :param genericItem: The generic to add.
165 :raises ValueError: If parameter 'genericItem' is ``None``.
166 :raises TypeError: If parameter 'genericItem' is not of type
167 :class:`~pyVHDLModel.Interface.GenericInterfaceItemMixin`.
168 :raises AlreadyInDesignError: If parameter 'genericItem' already has a parent.
169 :raises DuplicateGenericError: If an existing declaration of the language construct shares an identifier
170 with the generic.
171
172 .. seealso::
173
174 :meth:`InsertGenericItem`
175 |rarr| Insert a generic at a position of the generic clause.
176 :meth:`RemoveGenericItem`
177 |rarr| Remove a generic from the generic clause.
178 """
...
180
181 def InsertGenericItem(self, index: int, genericItem: GenericInterfaceItemMixin) -> None:
182 """
183 Insert a generic at a position of the generic clause.
184
185 The generic's parent is set to this language construct, and its identifiers are added to the language construct's
186 namespace, if it has one.
187
188 :param index: Position, from ``0`` (first) to :data:`GenericCount` (append).
189 A negative index counts from the end, as for :meth:`list.insert`: ``-1`` inserts
190 before the last generic.
191 :param genericItem: The generic to insert.
192 :raises ValueError: If parameter 'index' is ``None``.
193 :raises TypeError: If parameter 'index' is not of type :class:`int`.
194 :raises ValueError: If parameter 'index' is out of range.
195 :raises ValueError: If parameter 'genericItem' is ``None``.
196 :raises TypeError: If parameter 'genericItem' is not of type
197 :class:`~pyVHDLModel.Interface.GenericInterfaceItemMixin`.
198 :raises AlreadyInDesignError: If parameter 'genericItem' already has a parent.
199 :raises DuplicateGenericError: If an existing declaration of the language construct shares an identifier
200 with the generic.
201
202 .. seealso::
203
204 :meth:`AddGenericItem`
205 |rarr| Add a generic at the end of the generic clause.
206 :meth:`RemoveGenericItem`
207 |rarr| Remove a generic from the generic clause.
208 :meth:`MoveGenericItem`
209 |rarr| Move a generic to a position of the generic clause.
210 """
...
257
258 def RemoveGenericItem(self, genericItem: GenericInterfaceItemMixin) -> None:
259 """
260 Remove a generic from the generic clause.
261
262 The generic is detached: its parent is cleared and its identifiers are removed from the language construct's
263 namespace, if it has one. The generic itself is unchanged and can be added to another language construct, or
264 inserted at another position.
265
266 :param genericItem: The generic to remove.
267 :raises ValueError: If parameter 'genericItem' is ``None``.
268 :raises TypeError: If parameter 'genericItem' is not of type
269 :class:`~pyVHDLModel.Interface.GenericInterfaceItemMixin`.
270 :raises NotAChildError: If parameter 'genericItem' is not a generic of this language construct.
271 :raises NotInNamespaceError: If the namespace is indexed, and an identifier of the generic isn't declared in it.
272 :raises NotInNamespaceError: If the namespace is indexed, and an identifier of the generic refers to another
273 element, e.g. a duplicate declaration.
274
275 .. seealso::
276
277 :meth:`AddGenericItem`
278 |rarr| Add a generic at the end of the generic clause.
279 :meth:`InsertGenericItem`
280 |rarr| Insert a generic at a position of the generic clause.
281 :meth:`MoveGenericItem`
282 |rarr| Move a generic to a position of the generic clause.
283 """
...
307
308 def MoveGenericItem(self, genericItem: GenericInterfaceItemMixin, index: int) -> None:
309 """
310 Move a generic to a position of the generic clause.
311
312 The generic stays a generic of this language construct: only the order of the generic clause changes. A generic
313 subprogram is an overload: if the language construct's namespace is indexed, it refers to the overload declared
314 last afterwards.
315
316 :param genericItem: The generic to move.
317 :param index: Position of the generic after the move, from ``0`` (first) to :data:`GenericCount`
318 minus one (last). A negative index counts from the end, as for a :class:`list`
319 index: ``-1`` moves the generic to the end.
320 :raises ValueError: If parameter 'genericItem' is ``None``.
321 :raises TypeError: If parameter 'genericItem' is not of type
322 :class:`~pyVHDLModel.Interface.GenericInterfaceItemMixin`.
323 :raises NotAChildError: If parameter 'genericItem' is not a generic of this language construct.
324 :raises ValueError: If parameter 'index' is ``None``.
325 :raises TypeError: If parameter 'index' is not of type :class:`int`.
326 :raises ValueError: If parameter 'index' is out of range.
327 :raises NotInNamespaceError: If the namespace is indexed, and the identifier of a generic subprogram refers to an
328 element, which is no overload, e.g. a duplicate declaration.
329
330 .. seealso::
331
332 :meth:`InsertGenericItem`
333 |rarr| Insert a generic at a position of the generic clause.
334 :meth:`RemoveGenericItem`
335 |rarr| Remove a generic from the generic clause.
336 """
...
382
383 @expects("_namespace")
384 def _IndexGenericItems(self) -> None:
385 """Add the generics to the host's namespace; a generic subprogram is an overload."""
...
392
393 def _VisitGenericClause(self, visitor: Visitor) -> None:
394 """
395 Walk the generic clause, if there are generics, with a visitor.
396
397 The generics are separated by semicolons.
398
399 :param visitor: The visitor receiving the events.
400 """
...
412
414@export
415class WithPortsMixin(
416 metaclass=ExtendedType,
417 mixin=True,
418 expects=("_AddToNamespace", "_RemoveFromNamespace", "_ClashingDeclarations")
419):
420 """
421 A mixin-class for language constructs with a port clause.
422
423 The host class provides ``_AddToNamespace(element)`` and ``_RemoveFromNamespace(element)``, called when a port is
424 inserted or removed: :class:`~pyVHDLModel.Regions.DeclarationRegionMixin` updates its namespace, a language construct
425 without a namespace implements both as no-operations.
426
427 The host class also provides ``_ClashingDeclarations(item)``, called before a port is inserted: it returns the
428 declarations sharing an identifier with the new item.
429
430 Indexing the ports (``_IndexPortItems()``) needs the host's namespace ``_namespace``; a host without one, e.g.
431 a component, can't index them.
432
433 .. seealso::
434
435 * :class:`Concurrent block statement <pyVHDLModel.Concurrent.ConcurrentBlockStatement>`
436 * :class:`Entity <pyVHDLModel.DesignUnit.Entity>`
437 * :class:`Component <pyVHDLModel.DesignUnit.Component>`
438 * :class:`Port group <pyVHDLModel.Interface.PortGroup>`
439 """
440 _portItems: list[PortInterfaceItemMixin] #: List of all ports, in declaration order.
441
442 def __init__(
443 self,
444 portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None,
445 ) -> None:
446 """
447 Initializes a language construct with a port clause.
448
449 :param portItems: List of all ports, in declaration order.
450 """
...
456
457 @readonly
458 def PortItems(self) -> list[PortInterfaceItemMixin]:
459 """
460 Read-only property to access the port items (:attr:`_portItems`).
461
462 :returns: List of port items.
463 """
...
465
466 @readonly
467 def PortCount(self) -> int:
468 """
469 Read-only property to return the number of ports in :attr:`_portItems`.
470
471 :returns: The port count.
472 """
...
474
475 def IterateSinglePortDeclarations(
476 self,
477 predicate: Nullable[Callable[[SinglePortDeclarationMixin], bool]] = None
478 ) -> Generator[SinglePortDeclarationMixin, None, None]:
479 """
480 Iterate all ports per declared identifier, in declaration order.
481
482 A port yields one single declaration per identifier: ``port (a, b : in bit)`` yields two.
483
484 :param predicate: Optional, filter function to select the yielded ports. Default: all.
485 :returns: A generator to iterate all (selected) ports.
486 """
...
495
496 def AddPortItem(self, portItem: PortSignalInterfaceItem) -> None:
497 """
498 Add a port at the end of the port clause.
499
500 The port's parent is set to this language construct, and its identifiers are added to the language construct's
501 namespace, if it has one.
502
503 :param portItem: The port to add.
504 :raises ValueError: If parameter 'portItem' is ``None``.
505 :raises TypeError: If parameter 'portItem' is not of type
506 :class:`~pyVHDLModel.Interface.PortSignalInterfaceItem`.
507 :raises AlreadyInDesignError: If parameter 'portItem' already has a parent.
508 :raises DuplicatePortError: If an existing declaration of the language construct shares an identifier
509 with the port.
510
511 .. seealso::
512
513 :meth:`InsertPortItem`
514 |rarr| Insert a port at a position of the port clause.
515 :meth:`RemovePortItem`
516 |rarr| Remove a port from the port clause.
517 """
...
519
520 def InsertPortItem(self, index: int, portItem: PortSignalInterfaceItem) -> None:
521 """
522 Insert a port at a position of the port clause.
523
524 The port's parent is set to this language construct, and its identifiers are added to the language construct's
525 namespace, if it has one.
526
527 :param index: Position, from ``0`` (first) to :data:`PortCount` (append).
528 A negative index counts from the end, as for :meth:`list.insert`: ``-1`` inserts
529 before the last port.
530 :param portItem: The port to insert.
531 :raises ValueError: If parameter 'index' is ``None``.
532 :raises TypeError: If parameter 'index' is not of type :class:`int`.
533 :raises ValueError: If parameter 'index' is out of range.
534 :raises ValueError: If parameter 'portItem' is ``None``.
535 :raises TypeError: If parameter 'portItem' is not of type
536 :class:`~pyVHDLModel.Interface.PortSignalInterfaceItem`.
537 :raises AlreadyInDesignError: If parameter 'portItem' already has a parent.
538 :raises DuplicatePortError: If an existing declaration of the language construct shares an identifier
539 with the port.
540
541 .. seealso::
542
543 :meth:`AddPortItem`
544 |rarr| Add a port at the end of the port clause.
545 :meth:`RemovePortItem`
546 |rarr| Remove a port from the port clause.
547 :meth:`MovePortItem`
548 |rarr| Move a port to a position of the port clause.
549 """
...
596
597 def RemovePortItem(self, portItem: PortSignalInterfaceItem) -> None:
598 """
599 Remove a port from the port clause.
600
601 The port is detached: its parent is cleared and its identifiers are removed from the language construct's
602 namespace, if it has one. The port itself is unchanged and can be added to another language construct, or
603 inserted at another position.
604
605 :param portItem: The port to remove.
606 :raises ValueError: If parameter 'portItem' is ``None``.
607 :raises TypeError: If parameter 'portItem' is not of type
608 :class:`~pyVHDLModel.Interface.PortSignalInterfaceItem`.
609 :raises NotAChildError: If parameter 'portItem' is not a port of this language construct.
610 :raises NotInNamespaceError: If the namespace is indexed, and an identifier of the port isn't declared in it.
611 :raises NotInNamespaceError: If the namespace is indexed, and an identifier of the port refers to another
612 element, e.g. a duplicate declaration.
613
614 .. seealso::
615
616 :meth:`AddPortItem`
617 |rarr| Add a port at the end of the port clause.
618 :meth:`InsertPortItem`
619 |rarr| Insert a port at a position of the port clause.
620 :meth:`MovePortItem`
621 |rarr| Move a port to a position of the port clause.
622 """
...
646
647 def MovePortItem(self, portItem: PortSignalInterfaceItem, index: int) -> None:
648 """
649 Move a port to a position of the port clause.
650
651 The port stays a port of this language construct: only the order of the port clause changes.
652
653 :param portItem: The port to move.
654 :param index: Position of the port after the move, from ``0`` (first) to :data:`PortCount` minus one
655 (last). A negative index counts from the end, as for a :class:`list` index: ``-1`` moves the
656 port to the end.
657 :raises ValueError: If parameter 'portItem' is ``None``.
658 :raises TypeError: If parameter 'portItem' is not of type
659 :class:`~pyVHDLModel.Interface.PortSignalInterfaceItem`.
660 :raises NotAChildError: If parameter 'portItem' is not a port of this language construct.
661 :raises ValueError: If parameter 'index' is ``None``.
662 :raises TypeError: If parameter 'index' is not of type :class:`int`.
663 :raises ValueError: If parameter 'index' is out of range.
664
665 .. seealso::
666
667 :meth:`InsertPortItem`
668 |rarr| Insert a port at a position of the port clause.
669 :meth:`RemovePortItem`
670 |rarr| Remove a port from the port clause.
671 """
...
706
707 @expects("_namespace")
708 def _IndexPortItems(self) -> None:
709 """Add the ports to the host's namespace."""
...
713
714 def _VisitPortClause(self, visitor: Visitor) -> None:
715 """
716 Walk the port clause, if there are ports, with a visitor.
717
718 The ports are separated by semicolons.
719
720 :param visitor: The visitor receiving the events.
721 """
...
733
735@export
736class WithParametersMixin(
737 metaclass=ExtendedType,
738 mixin=True,
739 expects=("_AddToNamespace", "_RemoveFromNamespace", "_ClashingDeclarations", "_ParameterItemsChanged")
740):
741 """
742 A mixin-class for language constructs with a parameter list.
743
744 The host class provides ``_AddToNamespace(element)`` and ``_RemoveFromNamespace(element)``, called when a parameter is
745 inserted or removed: :class:`~pyVHDLModel.Regions.DeclarationRegionMixin` updates its namespace, a language construct
746 without a namespace implements both as no-operations.
747
748 The host class also provides ``_ClashingDeclarations(item)``, called before a parameter is inserted: it returns the
749 declarations sharing an identifier with the new item.
750
751 The host class provides ``_ParameterItemsChanged()`` too, called after a parameter is inserted, removed or moved:
752 :class:`~pyVHDLModel.Subprogram.Subprogram` clears its signature, a parameter group does nothing.
753
754 Indexing the parameters (``_IndexParameterItems()``) needs the host's namespace ``_namespace``; a host without one,
755 e.g. a parameter group, can't index them.
756
757 .. seealso::
758
759 * :class:`Subprogram <pyVHDLModel.Subprogram.Subprogram>`
760 * :class:`Parameter group <pyVHDLModel.Interface.ParameterGroup>`
761 """
762 _parameterItems: list[ParameterInterfaceItemMixin] #: List of all parameters, in declaration order.
763
764 def __init__(
765 self,
766 parameterItems: Nullable[Iterable[ParameterInterfaceItemMixin]] = None,
767 ) -> None:
768 """
769 Initializes a language construct with a parameter list.
770
771 :param parameterItems: List of all parameters, in declaration order.
772 """
...
778
779 @readonly
780 def ParameterItems(self) -> list[ParameterInterfaceItemMixin]:
781 """
782 Read-only property to access the parameter items (:attr:`_parameterItems`).
783
784 :returns: List of parameter items.
785 """
...
787
788 @readonly
789 def ParameterCount(self) -> int:
790 """
791 Read-only property to return the number of parameters in :attr:`_parameterItems`.
792
793 :returns: The parameter count.
794 """
...
796
797 def IterateSingleParameterDeclarations(
798 self,
799 predicate: Nullable[Callable[[SingleParameterDeclarationMixin], bool]] = None
800 ) -> Generator[SingleParameterDeclarationMixin, None, None]:
801 """
802 Iterate all parameters per declared identifier, in declaration order.
803
804 A parameter yields one single declaration per identifier: ``(a, b : in integer)`` yields two.
805
806 :param predicate: Optional, filter function to select the yielded parameters. Default: all.
807 :returns: A generator to iterate all (selected) parameters.
808 """
...
817
818 def AddParameterItem(self, parameterItem: ParameterInterfaceItemMixin) -> None:
819 """
820 Add a parameter at the end of the parameter list.
821
822 The parameter's parent is set to this language construct, and its identifiers are added to the language construct's
823 namespace, if it has one.
824
825 :param parameterItem: The parameter to add.
826 :raises ValueError: If parameter 'parameterItem' is ``None``.
827 :raises TypeError: If parameter 'parameterItem' is not of type
828 :class:`~pyVHDLModel.Interface.ParameterInterfaceItemMixin`.
829 :raises AlreadyInDesignError: If parameter 'parameterItem' already has a parent.
830 :raises DuplicateParameterError: If an existing declaration of the language construct shares an identifier
831 with the parameter.
832
833 .. seealso::
834
835 :meth:`InsertParameterItem`
836 |rarr| Insert a parameter at a position of the parameter list.
837 :meth:`RemoveParameterItem`
838 |rarr| Remove a parameter from the parameter list.
839 """
...
841
842 def InsertParameterItem(self, index: int, parameterItem: ParameterInterfaceItemMixin) -> None:
843 """
844 Insert a parameter at a position of the parameter list.
845
846 The parameter's parent is set to this language construct, and its identifiers are added to the language construct's
847 namespace, if it has one.
848
849 :param index: Position, from ``0`` (first) to :data:`ParameterCount` (append).
850 A negative index counts from the end, as for :meth:`list.insert`: ``-1`` inserts
851 before the last parameter.
852 :param parameterItem: The parameter to insert.
853 :raises ValueError: If parameter 'index' is ``None``.
854 :raises TypeError: If parameter 'index' is not of type :class:`int`.
855 :raises ValueError: If parameter 'index' is out of range.
856 :raises ValueError: If parameter 'parameterItem' is ``None``.
857 :raises TypeError: If parameter 'parameterItem' is not of type
858 :class:`~pyVHDLModel.Interface.ParameterInterfaceItemMixin`.
859 :raises AlreadyInDesignError: If parameter 'parameterItem' already has a parent.
860 :raises DuplicateParameterError: If an existing declaration of the language construct shares an identifier
861 with the parameter.
862
863 .. seealso::
864
865 :meth:`AddParameterItem`
866 |rarr| Add a parameter at the end of the parameter list.
867 :meth:`RemoveParameterItem`
868 |rarr| Remove a parameter from the parameter list.
869 :meth:`MoveParameterItem`
870 |rarr| Move a parameter to a position of the parameter list.
871 """
...
919
920 def RemoveParameterItem(self, parameterItem: ParameterInterfaceItemMixin) -> None:
921 """
922 Remove a parameter from the parameter list.
923
924 The parameter is detached: its parent is cleared and its identifiers are removed from the language construct's
925 namespace, if it has one. The parameter itself is unchanged and can be added to another language construct, or
926 inserted at another position.
927
928 :param parameterItem: The parameter to remove.
929 :raises ValueError: If parameter 'parameterItem' is ``None``.
930 :raises TypeError: If parameter 'parameterItem' is not of type
931 :class:`~pyVHDLModel.Interface.ParameterInterfaceItemMixin`.
932 :raises NotAChildError: If parameter 'parameterItem' is not a parameter of this language construct.
933 :raises NotInNamespaceError: If the namespace is indexed, and an identifier of the parameter isn't declared in it.
934 :raises NotInNamespaceError: If the namespace is indexed, and an identifier of the parameter refers to another
935 element, e.g. a duplicate declaration.
936
937 .. seealso::
938
939 :meth:`AddParameterItem`
940 |rarr| Add a parameter at the end of the parameter list.
941 :meth:`InsertParameterItem`
942 |rarr| Insert a parameter at a position of the parameter list.
943 :meth:`MoveParameterItem`
944 |rarr| Move a parameter to a position of the parameter list.
945 """
...
970
971 def MoveParameterItem(self, parameterItem: ParameterInterfaceItemMixin, index: int) -> None:
972 """
973 Move a parameter to a position of the parameter list.
974
975 The parameter stays a parameter of this language construct: only the order of the parameter list changes.
976
977 :param parameterItem: The parameter to move.
978 :param index: Position of the parameter after the move, from ``0`` (first) to :data:`ParameterCount`
979 minus one (last). A negative index counts from the end, as for a :class:`list` index:
980 ``-1`` moves the parameter to the end.
981 :raises ValueError: If parameter 'parameterItem' is ``None``.
982 :raises TypeError: If parameter 'parameterItem' is not of type
983 :class:`~pyVHDLModel.Interface.ParameterInterfaceItemMixin`.
984 :raises NotAChildError: If parameter 'parameterItem' is not a parameter of this language construct.
985 :raises ValueError: If parameter 'index' is ``None``.
986 :raises TypeError: If parameter 'index' is not of type :class:`int`.
987 :raises ValueError: If parameter 'index' is out of range.
988
989 .. seealso::
990
991 :meth:`InsertParameterItem`
992 |rarr| Insert a parameter at a position of the parameter list.
993 :meth:`RemoveParameterItem`
994 |rarr| Remove a parameter from the parameter list.
995 """
...
1033
1034 @expects("_namespace")
1035 def _IndexParameterItems(self) -> None:
1036 """Add the parameters to the host's namespace."""
...
1040
1041 def _VisitFormalParameterList(self, visitor: Visitor) -> None:
1042 """
1043 Walk the formal parameter list, if there are parameters, with a visitor.
1044
1045 The parameters are separated by semicolons.
1046
1047 :param visitor: The visitor receiving the events.
1048 """
...
1060
1062@export
1063class DeclarationRegionMixin(
1064 metaclass=ExtendedType,
1065 mixin=True,
1066 expects=(
1067 "_namespace",
1068 "_functions",
1069 "_procedures",
1070 "_declaredItems",
1071 "_Declarations",
1072 "_IndexDeclaredItem",
1073 "_UnindexDeclaredItem",
1074 "IndexDeclaredItems",
1075 "_Labels"
1076 )
1077):
1078 """
1079 A base-class for the concurrent, sequential and protected type declaration region mixins.
1080
1081 It carries what all regions share: adding interface items to the region's namespace, the mutators for declared items
1082 (e.g. :meth:`AddDeclaredItem`), and the hooks for declared items no region handles itself.
1083
1084 The derived region mixin-class provides the namespace ``_namespace``, the declared items ``_declaredItems`` and the
1085 lookup tables ``_functions`` and ``_procedures``; it or the host class provides the methods ``_Declarations()``,
1086 ``_IndexDeclaredItem(item)``, ``_UnindexDeclaredItem(item)`` and ``IndexDeclaredItems()``.
1087
1088 An interface item shares the declarative region of the declarative part beside it - VHDL rejects
1089 ``port (g : in bit)`` beside ``generic (g : integer)``, ``signal x`` beside ``port (x : in bit)``, and a
1090 subprogram variable named like one of its parameters, all as "identifier already used for a
1091 declaration". So they belong in the region's *own* namespace, not a separate one.
1092
1093 Which of the three a region has is known statically by the class that declares them, so each derived
1094 class calls the ones it needs from its own :meth:`IndexDeclaredItems` before delegating upwards.
1095 Interface items are added to the namespace only - ``GenericItems``/``PortItems``/``ParameterItems``
1096 already expose them as ordered lists, so no extra lookup table is needed.
1097
1098 .. seealso::
1099
1100 * :class:`Concurrent declaration region mixin <pyVHDLModel.Regions.ConcurrentDeclarationRegionMixin>`
1101 * :class:`Sequential declaration region mixin <pyVHDLModel.Regions.SequentialDeclarationRegionMixin>`
1102 * :class:`Protected type declaration region mixin <pyVHDLModel.Regions.ProtectedTypeDeclarationRegionMixin>`
1103
1104 A statement label is declared implicitly in the declarative region enclosing the statement, so the host provides the
1105 labeled statements of the region by ``_Labels()``: a host with statements gets it from its statements mixin
1106 (e.g. :class:`~pyVHDLModel.Concurrent.ConcurrentStatementsMixin`), a host without statements from
1107 :class:`WithoutStatementsMixin`.
1108 """
1109 _DECLARED_ITEM_TYPES: ClassVar[tuple[type, ...]] #: Accepted classes of declared items (:mod:`pyVHDLModel`).
1110 _areDeclaredItemsIndexed: bool #: ``True`` if :meth:`IndexDeclaredItems` filled the namespace.
1111
1112 def __init__(self) -> None:
1113 """
1114 Initializes a declaration region, which isn't indexed yet.
1115 """
...
1117
1118 def _AddToNamespace(self, element: NamedEntityMixin | MultipleNamedEntityMixin) -> None:
1119 """
1120 Add an element's identifiers to this region's namespace.
1121
1122 Nothing is added to a region not indexed yet: :meth:`IndexDeclaredItems` adds the element later. A generic
1123 subprogram is an overload (:meth:`_AddOverloadToNamespace`).
1124
1125 :param element: The named element to add, e.g. an interface item.
1126 """
...
1137
1138 def _RemoveFromNamespace(self, element: NamedEntityMixin | MultipleNamedEntityMixin) -> None:
1139 """
1140 Remove an element's identifiers from this region's namespace.
1141
1142 Nothing is removed from a region not indexed yet, as its namespace doesn't contain the element. A generic
1143 subprogram is an overload (:meth:`_RemoveOverloadFromNamespace`).
1144
1145 :param element: The named element to remove, e.g. an interface item.
1146 :raises NotInNamespaceError: If the region is indexed, and an identifier of the element isn't declared in the
1147 namespace.
1148 :raises NotInNamespaceError: If the region is indexed, and an identifier of the element refers to another element,
1149 e.g. a duplicate declaration.
1150 """
...
1161
1162 def _IndexOtherDeclaredItem(self, item: ModelEntity) -> None:
1163 """
1164 Hook for declared items the region doesn't handle itself. Derived classes may override it.
1165
1166 :param item: The declared item.
1167 """
1168
1169 def _UnindexOtherDeclaredItem(self, item: ModelEntity) -> None:
1170 """
1171 Hook to remove declared items the region doesn't handle itself. Derived classes may override it.
1172
1173 :param item: The declared item.
1174 """
1175
1176 def _RemoveDeclaredItemsFromNamespace(self) -> None:
1177 """
1178 Remove all declared items of this region from its namespace.
1179
1180 Interface items of this region and items imported from elsewhere (e.g. by a use clause) are kept.
1181 """
...
1187
1188 def _RemoveDeclaredItemEntries(
1189 self,
1190 lookupTable: dict[str, Any],
1191 item: NamedEntityMixin | MultipleNamedEntityMixin
1192 ) -> None:
1193 """
1194 Remove a declared item's entries from a lookup table and from the namespace.
1195
1196 Every identifier is checked before anything is removed.
1197
1198 :param lookupTable: The lookup table matching the declared item's kind.
1199 :param item: The declared item.
1200 :raises NotInNamespaceError: If an identifier of the declared item isn't declared in the namespace.
1201 :raises NotInNamespaceError: If an identifier of the declared item refers to another element, e.g. a duplicate
1202 declaration.
1203 """
...
1214
1215 def _IndexOverload(self, item: NamedEntityMixin | MultipleNamedEntityMixin) -> None:
1216 """
1217 Add an inserted function or procedure to its lookup table and to the namespace.
1218
1219 The list of overloads follows the declaration order. The namespace is updated by :meth:`_AddOverloadToNamespace`.
1220
1221 :param item: The inserted function or procedure.
1222 """
...
1234
1235 def _UnindexOverload(self, item: NamedEntityMixin | MultipleNamedEntityMixin) -> None:
1236 """
1237 Remove a function or procedure from its lookup table and from the namespace.
1238
1239 The namespace is updated first, by :meth:`_RemoveOverloadFromNamespace`.
1240
1241 :param item: The function or procedure to remove, still a declared item of this region.
1242 :raises NotInNamespaceError: If the identifier isn't declared in the namespace.
1243 :raises NotInNamespaceError: If the identifier refers to an element, which is no overload, e.g. a duplicate
1244 declaration.
1245 """
...
1256
1257 def _AddOverloadToNamespace(self, item: NamedEntityMixin | MultipleNamedEntityMixin) -> None:
1258 """
1259 Add a function or procedure to the namespace, if it's the overload declared last.
1260
1261 The namespace keeps one entry per identifier: the overload declared last, as after :meth:`IndexDeclaredItems`, which
1262 adds interface items first, then declared items (:meth:`_Declarations`).
1263
1264 :param item: The function or procedure, already an interface item or declared item of this region.
1265 """
...
1275
1276 def _RemoveOverloadFromNamespace(self, item: NamedEntityMixin | MultipleNamedEntityMixin) -> None:
1277 """
1278 Remove a function or procedure from the namespace.
1279
1280 Removing the overload the namespace refers to, the namespace refers to the remaining overload declared last
1281 (:meth:`_Declarations`), or the identifier is removed, if no overload remains. Removing another overload leaves the
1282 namespace unchanged. The namespace is checked before it's changed.
1283
1284 :param item: The function or procedure, still an interface item or declared item of this region.
1285 :raises NotInNamespaceError: If the identifier isn't declared in the namespace.
1286 :raises NotInNamespaceError: If the identifier refers to an element, which is no overload, e.g. a duplicate
1287 declaration.
1288 """
...
1307
1308 def _SharedRegions(self) -> tuple[DeclarationRegionMixin, ...]:
1309 """
1310 Return the other language constructs forming one declarative region with this one.
1311
1312 An entity and each of its architectures form one declarative region, as do a package and its body. Derived classes
1313 override it.
1314
1315 :returns: Tuple of declarative regions.
1316 """
...
1318
1319 def _MayShareIdentifier(self, item: ModelEntity, existing: ModelEntity) -> bool:
1320 """
1321 Check if two declarations may share an identifier in one declarative region.
1322
1323 Subprograms are overloadable. A protected type body completes its protected type, a full type completes its
1324 incomplete type, and a constant completes its deferred constant.
1325
1326 :param item: The new declaration.
1327 :param existing: The existing declaration.
1328 :returns: ``True``, if both declarations may share an identifier.
1329 """
...
1349
1350 def _ClashingDeclarations(self, item: ModelEntity) -> tuple[ModelEntity, ...]:
1351 """
1352 Return the declarations sharing an identifier with the given item, which may not share it.
1353
1354 The declarations (:meth:`_Declarations`) and the labeled statements (``_Labels()``) of this declarative region and
1355 of the language constructs sharing it (:meth:`_SharedRegions`) are searched: a statement label is declared
1356 implicitly. Items imported into the namespace (e.g. by a use clause) are no declarations.
1357
1358 :param item: The new declaration, or the new labeled statement.
1359 :returns: Tuple of clashing declarations, interface items first, then declared items in declaration order, then
1360 labeled statements.
1361 """
...
1375
1376 def _DeclaredItemsSharingIdentifiers(self, declaredItem: ModelEntity) -> list[ModelEntity]:
1377 """
1378 Return the other declared items of this region sharing an identifier with the given declared item.
1379
1380 :param declaredItem: The declared item.
1381 :returns: List of declared items, in declaration order.
1382 """
...
1393
1394 def AddDeclaredItem(self, declaredItem: ModelEntity) -> None:
1395 """
1396 Add a declared item at the end of the declarative region.
1397
1398 The declared item's parent is set to this declarative region. If the region is indexed, its identifiers are added
1399 to the region's namespace and to the lookup table matching its kind.
1400
1401 :param declaredItem: The declared item to add.
1402 :raises ValueError: If parameter 'declaredItem' is ``None``.
1403 :raises TypeError: If parameter 'declaredItem' is not a declaration allowed in this declarative
1404 region.
1405 :raises AlreadyInDesignError: If parameter 'declaredItem' already has a parent.
1406 :raises DuplicateDeclarationError: If an existing declaration of the declarative region shares an
1407 identifier with the declared item.
1408
1409 .. seealso::
1410
1411 :meth:`InsertDeclaredItem`
1412 |rarr| Insert a declared item at a position of the declarative region.
1413 :meth:`RemoveDeclaredItem`
1414 |rarr| Remove a declared item from the declarative region.
1415 """
...
1417
1418 def InsertDeclaredItem(self, index: int, declaredItem: ModelEntity) -> None:
1419 """
1420 Insert a declared item at a position of the declarative region.
1421
1422 The declared item's parent is set to this declarative region. If the region is indexed, its identifiers are added
1423 to the region's namespace and to the lookup table matching its kind.
1424
1425 An identifier is declared once per declarative region: interface items and declared items count, including those of
1426 the language construct sharing the declarative region (an entity and its architecture, a package and its body).
1427 Subprograms are overloadable: a subprogram may share its identifier with other subprograms. A protected type body
1428 may share its identifier with its protected type, a full type with its incomplete type declaration, and a constant
1429 with its deferred constant. Items imported into the namespace (e.g. by a use clause) are hidden.
1430
1431 :param index: Position, from ``0`` (first) to the number of declared items (append).
1432 A negative index counts from the end, as for :meth:`list.insert`: ``-1``
1433 inserts before the last declared item.
1434 :param declaredItem: The declared item to insert.
1435 :raises ValueError: If parameter 'index' is ``None``.
1436 :raises TypeError: If parameter 'index' is not of type :class:`int`.
1437 :raises ValueError: If parameter 'index' is out of range.
1438 :raises ValueError: If parameter 'declaredItem' is ``None``.
1439 :raises TypeError: If parameter 'declaredItem' is not a declaration allowed in this declarative
1440 region.
1441 :raises AlreadyInDesignError: If parameter 'declaredItem' already has a parent.
1442 :raises DuplicateDeclarationError: If an existing declaration of the declarative region shares an
1443 identifier with the declared item.
1444
1445 .. seealso::
1446
1447 :meth:`AddDeclaredItem`
1448 |rarr| Add a declared item at the end of the declarative region.
1449 :meth:`InsertDeclaredItemBefore`
1450 |rarr| Insert a declared item before another declared item.
1451 :meth:`InsertDeclaredItemAfter`
1452 |rarr| Insert a declared item after another declared item.
1453 :meth:`RemoveDeclaredItem`
1454 |rarr| Remove a declared item from the declarative region.
1455 :meth:`MoveDeclaredItem`
1456 |rarr| Move a declared item to a position of the declarative region.
1457 """
...
1537
1538 def InsertDeclaredItemBefore(self, declaredItem: ModelEntity, before: ModelEntity) -> None:
1539 """
1540 Insert a declared item before another declared item.
1541
1542 The declared item's parent is set to this declarative region. If the region is indexed, its identifiers are added
1543 to the region's namespace and to the lookup table matching its kind.
1544
1545 :param declaredItem: The declared item to insert.
1546 :param before: The declared item of this declarative region to insert before.
1547 :raises ValueError: If parameter 'before' is ``None``.
1548 :raises TypeError: If parameter 'before' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1549 :raises NotAChildError: If parameter 'before' is not a declared item of this declarative region.
1550 :raises ValueError: If parameter 'declaredItem' is ``None``.
1551 :raises TypeError: If parameter 'declaredItem' is not a declaration allowed in this declarative
1552 region.
1553 :raises AlreadyInDesignError: If parameter 'declaredItem' already has a parent.
1554 :raises DuplicateDeclarationError: If an existing declaration of the declarative region shares an
1555 identifier with the declared item.
1556
1557 .. seealso::
1558
1559 :meth:`InsertDeclaredItem`
1560 |rarr| Insert a declared item at a position of the declarative region.
1561 :meth:`InsertDeclaredItemAfter`
1562 |rarr| Insert a declared item after another declared item.
1563 """
...
1585
1586 def InsertDeclaredItemAfter(self, declaredItem: ModelEntity, after: ModelEntity) -> None:
1587 """
1588 Insert a declared item after another declared item.
1589
1590 The declared item's parent is set to this declarative region. If the region is indexed, its identifiers are added
1591 to the region's namespace and to the lookup table matching its kind.
1592
1593 :param declaredItem: The declared item to insert.
1594 :param after: The declared item of this declarative region to insert after.
1595 :raises ValueError: If parameter 'after' is ``None``.
1596 :raises TypeError: If parameter 'after' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1597 :raises NotAChildError: If parameter 'after' is not a declared item of this declarative region.
1598 :raises ValueError: If parameter 'declaredItem' is ``None``.
1599 :raises TypeError: If parameter 'declaredItem' is not a declaration allowed in this declarative
1600 region.
1601 :raises AlreadyInDesignError: If parameter 'declaredItem' already has a parent.
1602 :raises DuplicateDeclarationError: If an existing declaration of the declarative region shares an
1603 identifier with the declared item.
1604
1605 .. seealso::
1606
1607 :meth:`InsertDeclaredItem`
1608 |rarr| Insert a declared item at a position of the declarative region.
1609 :meth:`InsertDeclaredItemBefore`
1610 |rarr| Insert a declared item before another declared item.
1611 """
...
1633
1634 def RemoveDeclaredItem(self, declaredItem: ModelEntity) -> None:
1635 """
1636 Remove a declared item from the declarative region.
1637
1638 The declared item is detached: its parent is cleared. If the region is indexed, the declared item's identifiers are
1639 removed from the region's namespace and from the lookup table matching its kind first; they are checked before
1640 anything is changed. The declared item itself is unchanged and can be added to another declarative region, or
1641 inserted at another position.
1642
1643 The namespace refers to the overload declared last: removing it, the namespace refers to the remaining overload
1644 declared last. If another declaration shares an identifier with the declared item (e.g. a duplicate declaration
1645 read by a parser), the region is indexed again (:meth:`IndexDeclaredItems`) after the removal.
1646
1647 :param declaredItem: The declared item to remove.
1648 :raises ValueError: If parameter 'declaredItem' is ``None``.
1649 :raises TypeError: If parameter 'declaredItem' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1650 :raises NotAChildError: If parameter 'declaredItem' is not a declared item of this declarative region.
1651 :raises NotInNamespaceError: If the region is indexed, and an identifier of the declared item isn't declared in
1652 its namespace.
1653 :raises NotInNamespaceError: If the region is indexed, and an identifier of the declared item refers to another
1654 declaration, e.g. a duplicate declaration.
1655
1656 .. seealso::
1657
1658 :meth:`AddDeclaredItem`
1659 |rarr| Add a declared item at the end of the declarative region.
1660 :meth:`InsertDeclaredItem`
1661 |rarr| Insert a declared item at a position of the declarative region.
1662 :meth:`MoveDeclaredItem`
1663 |rarr| Move a declared item to a position of the declarative region.
1664 """
...
1701
1702 def MoveDeclaredItem(self, declaredItem: ModelEntity, index: int) -> None:
1703 """
1704 Move a declared item to a position of the declarative region.
1705
1706 The declared item stays a declared item of this declarative region: only the order of the declared items changes.
1707
1708 If the region is indexed, the lookup tables and the namespace follow the new order: a list of overloads (e.g. in
1709 ``Functions``) follows the declaration order, and the namespace refers to the overload declared last. If
1710 another declaration shares an identifier with the declared item (e.g. a duplicate declaration read by a parser),
1711 the region is indexed again (:meth:`IndexDeclaredItems`) after the move.
1712
1713 :param declaredItem: The declared item to move.
1714 :param index: Position of the declared item after the move, from ``0`` (first) to the number of
1715 declared items minus one (last). A negative index counts from the end, as for a
1716 :class:`list` index: ``-1`` moves the declared item to the end.
1717 :raises ValueError: If parameter 'declaredItem' is ``None``.
1718 :raises TypeError: If parameter 'declaredItem' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1719 :raises NotAChildError: If parameter 'declaredItem' is not a declared item of this declarative region.
1720 :raises ValueError: If parameter 'index' is ``None``.
1721 :raises TypeError: If parameter 'index' is not of type :class:`int`.
1722 :raises ValueError: If parameter 'index' is out of range.
1723
1724 .. seealso::
1725
1726 :meth:`MoveDeclaredItemBefore`
1727 |rarr| Move a declared item before another declared item.
1728 :meth:`MoveDeclaredItemAfter`
1729 |rarr| Move a declared item after another declared item.
1730 :meth:`InsertDeclaredItem`
1731 |rarr| Insert a declared item at a position of the declarative region.
1732 :meth:`RemoveDeclaredItem`
1733 |rarr| Remove a declared item from the declarative region.
1734 """
...
1789
1790 def MoveDeclaredItemBefore(self, declaredItem: ModelEntity, before: ModelEntity) -> None:
1791 """
1792 Move a declared item before another declared item.
1793
1794 The declared item stays a declared item of this declarative region: only the order of the declared items changes,
1795 as for :meth:`MoveDeclaredItem`. Moving a declared item before itself keeps it in place.
1796
1797 :param declaredItem: The declared item to move.
1798 :param before: The declared item of this declarative region to move before.
1799 :raises ValueError: If parameter 'before' is ``None``.
1800 :raises TypeError: If parameter 'before' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1801 :raises NotAChildError: If parameter 'before' is not a declared item of this declarative region.
1802 :raises ValueError: If parameter 'declaredItem' is ``None``.
1803 :raises TypeError: If parameter 'declaredItem' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1804 :raises NotAChildError: If parameter 'declaredItem' is not a declared item of this declarative region.
1805
1806 .. seealso::
1807
1808 :meth:`MoveDeclaredItem`
1809 |rarr| Move a declared item to a position of the declarative region.
1810 :meth:`MoveDeclaredItemAfter`
1811 |rarr| Move a declared item after another declared item.
1812 """
...
1835
1836 def MoveDeclaredItemAfter(self, declaredItem: ModelEntity, after: ModelEntity) -> None:
1837 """
1838 Move a declared item after another declared item.
1839
1840 The declared item stays a declared item of this declarative region: only the order of the declared items changes,
1841 as for :meth:`MoveDeclaredItem`. Moving a declared item after itself keeps it in place.
1842
1843 :param declaredItem: The declared item to move.
1844 :param after: The declared item of this declarative region to move after.
1845 :raises ValueError: If parameter 'after' is ``None``.
1846 :raises TypeError: If parameter 'after' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1847 :raises NotAChildError: If parameter 'after' is not a declared item of this declarative region.
1848 :raises ValueError: If parameter 'declaredItem' is ``None``.
1849 :raises TypeError: If parameter 'declaredItem' is not of type :class:`~pyVHDLModel.Base.ModelEntity`.
1850 :raises NotAChildError: If parameter 'declaredItem' is not a declared item of this declarative region.
1851
1852 .. seealso::
1853
1854 :meth:`MoveDeclaredItem`
1855 |rarr| Move a declared item to a position of the declarative region.
1856 :meth:`MoveDeclaredItemBefore`
1857 |rarr| Move a declared item before another declared item.
1858 """
...
1881
1882 def _VisitDeclaredItems(self, visitor: Visitor) -> None:
1883 """
1884 Walk the declared items in declaration order with a visitor.
1885
1886 :param visitor: The visitor receiving the events.
1887 """
...
1890
1892@export
1893class WithoutStatementsMixin(metaclass=ExtendedType, mixin=True):
1894 """
1895 A mixin-class for language constructs with a declarative region, but without statements.
1896
1897 It provides the labeled statements ``_Labels()`` the declaration region expects from its host class: none.
1898
1899 .. seealso::
1900
1901 * :class:`Package <pyVHDLModel.DesignUnit.Package>`
1902 * :class:`Package body <pyVHDLModel.DesignUnit.PackageBody>`
1903 * :class:`Protected type <pyVHDLModel.Type.ProtectedType>`
1904 * :class:`Protected type body <pyVHDLModel.Type.ProtectedTypeBody>`
1905 """
1906
1907 def _Labels(self) -> tuple[ModelEntity, ...]:
1908 """
1909 Return the labeled statements, whose labels are declared in this declarative region.
1910
1911 :returns: An empty tuple.
1912 """
...
1914
1916@export
1917class ConcurrentDeclarationRegionMixin(DeclarationRegionMixin, mixin=True):
1919 """
1920 A mixin-class for concurrent declaration regions.
1921
1922 Entities, architectures, packages, blocks and generate bodies declare items concurrently. Beside
1923 the namespace, the region keeps a lookup table per kind of declared item (:data:`Types`,
1924 :data:`Signals`, :data:`Constants`, ...).
1925
1926 .. seealso::
1927
1928 * :class:`Concurrent block statement <pyVHDLModel.Concurrent.ConcurrentBlockStatement>`
1929 * :class:`Generate branch <pyVHDLModel.Concurrent.GenerateBranch>`
1930 * :class:`Concurrent case <pyVHDLModel.Concurrent.ConcurrentCase>`
1931 * :class:`For generate statement <pyVHDLModel.Concurrent.ForGenerateStatement>`
1932 * :class:`Package <pyVHDLModel.DesignUnit.Package>`
1933 * :class:`Package body <pyVHDLModel.DesignUnit.PackageBody>`
1934 * :class:`Entity <pyVHDLModel.DesignUnit.Entity>`
1935 * :class:`Architecture <pyVHDLModel.DesignUnit.Architecture>`
1936 * :class:`Sequential declaration region <pyVHDLModel.Regions.SequentialDeclarationRegionMixin>`
1937 * :class:`Namespace <pyVHDLModel.Namespace.Namespace>`
1938 """
1939 _declaredItems: list #: List of all declared items in this concurrent declaration region.
1940 _namespace: Namespace #: The namespace of this concurrent declaration region.
1941
1944 _types: dict[str, FullType] #: Dictionary of all types declared in this concurrent declaration region.
1945 _subtypes: dict[str, Subtype] #: Dictionary of all subtypes declared in this concurrent declaration region.
1947 _constants: dict[str, Constant] #: Dictionary of all constants declared in this concurrent declaration region.
1948 _signals: dict[str, Signal] #: Dictionary of all signals declared in this concurrent declaration region.
1949 _sharedVariables: dict[str, SharedVariable] #: Dictionary of all shared variables declared in this concurrent declaration region.
1950 _files: dict[str, File] #: Dictionary of all files declared in this concurrent declaration region.
1953 _functions: dict[str, list[Function]] #: Dictionary of all functions declared in this concurrent declaration region, indexed by name; each entry is a list of overloads.
1954 _procedures: dict[str, list[Procedure]] #: Dictionary of all procedures declared in this concurrent declaration region, indexed by name; each entry is a list of overloads.
1955 _components: dict[str, Any] #: Dictionary of all components declared in this concurrent declaration region.
1956
1957 def __init__(
1958 self,
1959 namespaceName: Nullable[str] = None,
1960 declaredItems: Nullable[Iterable] = None,
1961 sharesRegionWithParent: bool = False
1962 ) -> None:
1964 """
1965 Initializes a concurrent declaration region.
1966
1967 :param namespaceName: Name of this region's namespace, usually the host's label or identifier.
1968 :param declaredItems: List of all declared items in this concurrent declaration region.
1969 :param sharesRegionWithParent: Optional, ``True`` if this region continues its parent's declarative region (an
1970 architecture its entity's, a package body its package's). Default: ``False``.
1971 """
...
1993
1994 @readonly
1995 def DeclaredItems(self) -> list:
1996 """
1997 Read-only property to access the declared items (:attr:`_declaredItems`).
1998
1999 :returns: List of declared items.
2000 """
...
2002
2003 @readonly
2004 def Types(self) -> dict[str, FullType]:
2005 """
2006 Read-only property to access the types (:attr:`_types`).
2007
2008 :returns: Dictionary of types, indexed by normalized identifier.
2009 """
...
2011
2012 @readonly
2013 def Subtypes(self) -> dict[str, Subtype]:
2014 """
2015 Read-only property to access the subtypes (:attr:`_subtypes`).
2016
2017 :returns: Dictionary of subtypes, indexed by normalized identifier.
2018 """
...
2020
2025 @readonly
2026 def Constants(self) -> dict[str, Constant]:
2027 """
2028 Read-only property to access the constants (:attr:`_constants`).
2029
2030 :returns: Dictionary of constants, indexed by normalized identifier.
2031 """
...
2033
2034 @readonly
2035 def Signals(self) -> dict[str, Signal]:
2036 """
2037 Read-only property to access the signals (:attr:`_signals`).
2038
2039 :returns: Dictionary of signals, indexed by normalized identifier.
2040 """
...
2042
2043 @readonly
2044 def SharedVariables(self) -> dict[str, SharedVariable]:
2045 """
2046 Read-only property to access the shared variables (:attr:`_sharedVariables`).
2047
2048 :returns: Dictionary of shared variables, indexed by normalized identifier.
2049 """
...
2051
2052 @readonly
2053 def Files(self) -> dict[str, File]:
2054 """
2055 Read-only property to access the files (:attr:`_files`).
2056
2057 :returns: Dictionary of files, indexed by normalized identifier.
2058 """
...
2060
2065 @readonly
2066 def Functions(self) -> dict[str, list[Function]]:
2067 """
2068 Read-only property to access the functions (:attr:`_functions`).
2069
2070 :returns: Dictionary of functions, indexed by normalized identifier; each entry is a list of overloads.
2071 """
...
2073
2074 @readonly
2075 def Procedures(self) -> dict[str, list[Procedure]]:
2076 """
2077 Read-only property to access the procedures (:attr:`_procedures`).
2078
2079 :returns: Dictionary of procedures, indexed by normalized identifier; each entry is a list of overloads.
2080 """
...
2082
2083 @readonly
2084 def Components(self) -> dict[str, Any]:
2085 """
2086 Read-only property to access the components (:attr:`_components`).
2087
2088 :returns: Dictionary of components, indexed by normalized identifier.
2089 """
...
2091
2092 def _Declarations(self) -> tuple[ModelEntity, ...]:
2093 """
2094 Return all declarations of this declarative region.
2095
2096 A host class with interface items extends the list by its interface items, listed first.
2097
2098 :returns: Tuple of declarations: the declared items, in declaration order.
2099 """
...
2101
2102 def IndexDeclaredItems(self) -> None:
2103 """
2104 Index declared items listed in the concurrent declaration region.
2105
2106 .. rubric:: Algorithm
2107
2108 1. Clear all lookup tables and remove all declared items from :attr:`_namespace`. Interface items and imported
2109 items stay in the namespace.
2110 2. Iterate all declared items:
2111
2112 * Every declared item is added to :attr:`_namespace`, except a protected type body.
2113 * If the declared item is a :class:`~pyVHDLModel.Type.ProtectedTypeBody`, skip it: it completes its protected
2114 type.
2115 * If the declared item is a :class:`~pyVHDLModel.Type.FullType`, then add an entry to :attr:`_types`.
2116 * If the declared item is a :class:`~pyVHDLModel.Type.Subtype`, then add an entry to :attr:`_subtypes`.
2117 * If the declared item is a :class:`~pyVHDLModel.Subprogram.Function`, then add an entry to :attr:`_functions`.
2118 * If the declared item is a :class:`~pyVHDLModel.Subprogram.Procedure`, then add an entry to :attr:`_procedures`.
2119 * If the declared item is a :class:`~pyVHDLModel.Object.Constant`, then add an entry to :attr:`_constants`.
2120 * If the declared item is a :class:`~pyVHDLModel.Object.Signal`, then add an entry to :attr:`_signals`.
2121 * If the declared item is a :class:`~pyVHDLModel.Object.Variable`, TODO.
2122 * If the declared item is a :class:`~pyVHDLModel.Object.SharedVariable`, then add an entry to :attr:`_sharedVariables`.
2123 * If the declared item is a :class:`~pyVHDLModel.Object.File`, then add an entry to :attr:`_files`.
2124 * If the declared item is neither of these types, call :meth:`_IndexOtherDeclaredItem`. |br|
2125 Derived classes may override this virtual function.
2126
2127 Indexing again yields the same lookup tables and namespace.
2128
2129 .. seealso::
2130
2131 :meth:`pyVHDLModel.Design.IndexPackages`
2132 Iterate all packages in the design and index declared items.
2133 :meth:`pyVHDLModel.Library.IndexPackages`
2134 Iterate all packages in the library and index declared items.
2135 :meth:`pyVHDLModel.Library._IndexOtherDeclaredItem`
2136 Iterate all packages in the library and index declared items.
2137
2138 :raises UnhandledCriticalWarningError: If an identifier is declared twice in a declarative region and no
2139 :class:`~pyTooling.Warning.WarningCollector` collects the
2140 :exc:`~pyVHDLModel.Exception.DuplicateDeclarationWarning`.
2141 """
...
2157
2158 def _IndexDeclaredItem(self, item: ModelEntity) -> None:
2159 """
2160 Add a declared item to the namespace and to the lookup table matching its kind.
2161
2162 :param item: The declared item.
2163 """
...
2216
2217 def _UnindexDeclaredItem(self, item: ModelEntity) -> None:
2218 """
2219 Remove a declared item from the namespace and from the lookup table matching its kind.
2220
2221 :param item: The declared item.
2222 """
...
2249
2251@export
2252class SequentialDeclarationRegionMixin(DeclarationRegionMixin, mixin=True):
2253 """
2254 A mixin-class for sequential declaration regions: process statements and subprogram bodies.
2255
2256 .. note::
2257
2258 VHDL's ``process_declarative_item`` and ``subprogram_declarative_item`` rules are identical, so both
2259 regions share this implementation. Compared to a concurrent region
2260 (:class:`ConcurrentDeclarationRegionMixin`, ``block_declarative_item``), a sequential region can
2261 declare a **variable**, but no signal, shared variable, component or mode view, and none of the
2262 specifications.
2263
2264 .. seealso::
2265
2266 * :class:`Process statement <pyVHDLModel.Concurrent.ProcessStatement>`
2267 * :class:`Subprogram <pyVHDLModel.Subprogram.Subprogram>`
2268 * :class:`Concurrent declaration region <pyVHDLModel.Regions.ConcurrentDeclarationRegionMixin>`
2269 * :class:`Namespace <pyVHDLModel.Namespace.Namespace>`
2270 """
2271
2272 _declaredItems: list #: List of all declared items in this sequential declaration region.
2273 _namespace: Namespace #: The namespace of this sequential declaration region.
2274
2275 _types: dict[str, FullType] #: Dictionary of all types declared in this sequential declaration region.
2276 _subtypes: dict[str, Subtype] #: Dictionary of all subtypes declared in this sequential declaration region.
2277 _constants: dict[str, Constant] #: Dictionary of all constants declared in this sequential declaration region.
2278 _variables: dict[str, Variable] #: Dictionary of all variables declared in this sequential declaration region.
2279 _files: dict[str, File] #: Dictionary of all files declared in this sequential declaration region.
2281 _functions: dict[str, list[Function]] #: Dictionary of all functions declared in this sequential declaration region, indexed by name; each entry is a list of overloads.
2282 _procedures: dict[str, list[Procedure]] #: Dictionary of all procedures declared in this sequential declaration region, indexed by name; each entry is a list of overloads.
2283
2284 def __init__(self, namespaceName: Nullable[str] = None, declaredItems: Nullable[Iterable] = None) -> None:
2285 """
2286 Initialize a sequential declaration region.
2287
2288 :param namespaceName: Name of this region's namespace, usually the host's label or identifier.
2289 :param declaredItems: The items declared in this region.
2290 """
...
2308
2309 @readonly
2310 def DeclaredItems(self) -> list:
2311 """
2312 Read-only property to access the declared items (:attr:`_declaredItems`).
2313
2314 :returns: List of declared items.
2315 """
...
2317
2318 @readonly
2319 def Namespace(self) -> Namespace:
2320 """
2321 Read-only property to access this region's namespace (:attr:`_namespace`).
2322
2323 :returns: The namespace.
2324 """
...
2326
2327 @readonly
2328 def Types(self) -> dict[str, FullType]:
2329 """
2330 Read-only property to access the declared types (:attr:`_types`).
2331
2332 :returns: Dictionary of types, indexed by normalized identifier.
2333 """
...
2335
2336 @readonly
2337 def Subtypes(self) -> dict[str, Subtype]:
2338 """
2339 Read-only property to access the declared subtypes (:attr:`_subtypes`).
2340
2341 :returns: Dictionary of subtypes, indexed by normalized identifier.
2342 """
...
2344
2345 @readonly
2346 def Constants(self) -> dict[str, Constant]:
2347 """
2348 Read-only property to access the declared constants (:attr:`_constants`).
2349
2350 :returns: Dictionary of constants, indexed by normalized identifier.
2351 """
...
2353
2354 @readonly
2355 def Variables(self) -> dict[str, Variable]:
2356 """
2357 Read-only property to access the declared variables (:attr:`_variables`).
2358
2359 :returns: Dictionary of variables, indexed by normalized identifier.
2360 """
...
2362
2363 @readonly
2364 def Files(self) -> dict[str, File]:
2365 """
2366 Read-only property to access the declared files (:attr:`_files`).
2367
2368 :returns: Dictionary of files, indexed by normalized identifier.
2369 """
...
2371
2372 @readonly
2373 def Functions(self) -> dict[str, list[Function]]:
2374 """
2375 Read-only property to access the declared functions (:attr:`_functions`).
2376
2377 :returns: Dictionary of functions, indexed by normalized identifier; each entry is a list of overloads.
2378 """
...
2380
2381 @readonly
2382 def Procedures(self) -> dict[str, list[Procedure]]:
2383 """
2384 Read-only property to access the declared procedures (:attr:`_procedures`).
2385
2386 :returns: Dictionary of procedures, indexed by normalized identifier; each entry is a list of overloads.
2387 """
...
2389
2390 def _Declarations(self) -> tuple[ModelEntity, ...]:
2391 """
2392 Return all declarations of this declarative region.
2393
2394 A host class with interface items extends the list by its interface items, listed first.
2395
2396 :returns: Tuple of declarations: the declared items, in declaration order.
2397 """
...
2399
2400 def IndexDeclaredItems(self) -> None:
2401 """
2402 Index declared items listed in the sequential declaration region.
2403
2404 All lookup tables are cleared and all declared items are removed from :attr:`_namespace` first. Then every declared
2405 item is added to :attr:`_namespace`, and additionally to the lookup table matching its kind. Items of an unhandled
2406 kind are passed to :meth:`_IndexOtherDeclaredItem`. A protected type body completes its protected type, so it's
2407 skipped. Indexing again yields the same lookup tables and namespace.
2408
2409 .. seealso::
2410
2411 :meth:`ConcurrentDeclarationRegionMixin.IndexDeclaredItems`
2412 The same algorithm for a concurrent declaration region.
2413
2414 :raises UnhandledCriticalWarningError: If an identifier is declared twice in a declarative region and no
2415 :class:`~pyTooling.Warning.WarningCollector` collects the
2416 :exc:`~pyVHDLModel.Exception.DuplicateDeclarationWarning`.
2417 """
...
2431
2432 def _IndexDeclaredItem(self, item: ModelEntity) -> None:
2433 """
2434 Add a declared item to the namespace and to the lookup table matching its kind.
2435
2436 :param item: The declared item.
2437 """
...
2474
2475 def _UnindexDeclaredItem(self, item: ModelEntity) -> None:
2476 """
2477 Remove a declared item from the namespace and from the lookup table matching its kind.
2478
2479 :param item: The declared item.
2480 """
...
2500
2502@export
2503class ProtectedTypeDeclarationRegionMixin(DeclarationRegionMixin, mixin=True):
2504 """
2505 A mixin-class for the declarative region of a protected type declaration.
2506
2507 VHDL's ``protected_type_declarative_item`` rule admits subprogram declarations only, making this the
2508 narrowest declarative region in the language. A protected type *body* differs: its declarative part
2509 matches a subprogram's, so it uses :class:`SequentialDeclarationRegionMixin`.
2510
2511 .. seealso::
2512
2513 * :class:`Protected type <pyVHDLModel.Type.ProtectedType>`
2514 * :class:`Protected type body <pyVHDLModel.Type.ProtectedTypeBody>`
2515 * :class:`Sequential declaration region <pyVHDLModel.Regions.SequentialDeclarationRegionMixin>`
2516 * :class:`Namespace <pyVHDLModel.Namespace.Namespace>`
2517 """
2518
2519 _declaredItems: list #: List of all declared items in this protected type declaration.
2520 _namespace: Namespace #: The namespace of this protected type declaration.
2521
2523 _functions: dict[str, list[Function]] #: All declared functions, indexed by name; each is a list of overloads.
2524 _procedures: dict[str, list[Procedure]] #: All declared procedures by name; each is a list of overloads.
2525
2526 def __init__(self, namespaceName: Nullable[str] = None, declaredItems: Nullable[Iterable] = None) -> None:
2527 """
2528 Initialize a protected type declaration region.
2529
2530 :param namespaceName: Name of this region's namespace, usually the protected type's identifier.
2531 :param declaredItems: The items declared in this region.
2532 """
...
2545
2546 @readonly
2547 def DeclaredItems(self) -> list:
2548 """
2549 Read-only property to access the declared items (:attr:`_declaredItems`).
2550
2551 :returns: List of all declared items.
2552 """
...
2554
2555 @readonly
2556 def Functions(self) -> dict[str, list[Function]]:
2557 """
2558 Read-only property to access the declared functions (:attr:`_functions`).
2559
2560 :returns: Dictionary of all functions, indexed by name; each entry is a list of overloads.
2561 """
...
2563
2564 @readonly
2565 def Procedures(self) -> dict[str, list[Procedure]]:
2566 """
2567 Read-only property to access the declared procedures (:attr:`_procedures`).
2568
2569 :returns: Dictionary of all procedures, indexed by name; each entry is a list of overloads.
2570 """
...
2572
2573 def _Declarations(self) -> tuple[ModelEntity, ...]:
2574 """
2575 Return all declarations of this declarative region.
2576
2577 A host class with interface items extends the list by its interface items, listed first.
2578
2579 :returns: Tuple of declarations: the declared items, in declaration order.
2580 """
...
2582
2583 def IndexDeclaredItems(self) -> None:
2584 """
2585 Index declared items listed in the protected type declaration.
2586
2587 Both lookup tables are cleared and all declared items are removed from :attr:`_namespace` first. Only subprogram
2588 declarations are legal here, so anything else is passed to :meth:`_IndexOtherDeclaredItem`. Indexing again yields
2589 the same lookup tables and namespace.
2590
2591 .. seealso::
2592
2593 :meth:`SequentialDeclarationRegionMixin.IndexDeclaredItems`
2594 The same algorithm for the protected type's body.
2595
2596 :raises UnhandledCriticalWarningError: If an identifier is declared twice in a declarative region and no
2597 :class:`~pyTooling.Warning.WarningCollector` collects the
2598 :exc:`~pyVHDLModel.Exception.DuplicateDeclarationWarning`.
2599 """
...
2608
2609 def _IndexDeclaredItem(self, item: ModelEntity) -> None:
2610 """
2611 Add a declared item to the namespace and to the lookup table matching its kind.
2612
2613 :param item: The declared item.
2614 """
...
2629
2630 def _UnindexDeclaredItem(self, item: ModelEntity) -> None:
2631 """
2632 Remove a declared item from the namespace and from the lookup table matching its kind.
2633
2634 :param item: The declared item.
2635 """
...