Coverage for pyVHDLModel/DesignUnit.py: 70%
362 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-07 22:12 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-07 22:12 +0000
1# ==================================================================================================================== #
2# __ ___ _ ____ _ __ __ _ _ #
3# _ __ _ \ \ / / | | | _ \| | | \/ | ___ __| | ___| | #
4# | '_ \| | | \ \ / /| |_| | | | | | | |\/| |/ _ \ / _` |/ _ \ | #
5# | |_) | |_| |\ V / | _ | |_| | |___| | | | (_) | (_| | __/ | #
6# | .__/ \__, | \_/ |_| |_|____/|_____|_| |_|\___/ \__,_|\___|_| #
7# |_| |___/ #
8# ==================================================================================================================== #
9# Authors: #
10# Patrick Lehmann #
11# #
12# License: #
13# ==================================================================================================================== #
14# Copyright 2017-2025 Patrick Lehmann - Boetzingen, Germany #
15# Copyright 2016-2017 Patrick Lehmann - Dresden, Germany #
16# #
17# Licensed under the Apache License, Version 2.0 (the "License"); #
18# you may not use this file except in compliance with the License. #
19# You may obtain a copy of the License at #
20# #
21# http://www.apache.org/licenses/LICENSE-2.0 #
22# #
23# Unless required by applicable law or agreed to in writing, software #
24# distributed under the License is distributed on an "AS IS" BASIS, #
25# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
26# See the License for the specific language governing permissions and #
27# limitations under the License. #
28# #
29# SPDX-License-Identifier: Apache-2.0 #
30# ==================================================================================================================== #
31#
32"""
33This module contains parts of an abstract document language model for VHDL.
35Design units are contexts, entities, architectures, packages and their bodies as well as configurations.
36"""
37from typing import List, Dict, Union, Iterable, Optional as Nullable
39from pyTooling.Decorators import export, readonly
40from pyTooling.MetaClasses import ExtendedType
41from pyTooling.Graph import Vertex
43from pyVHDLModel.Exception import VHDLModelException
44from pyVHDLModel.Base import ModelEntity, NamedEntityMixin, DocumentedEntityMixin
45from pyVHDLModel.Namespace import Namespace
46from pyVHDLModel.Regions import ConcurrentDeclarationRegionMixin
47from pyVHDLModel.Symbol import Symbol, PackageSymbol, EntitySymbol, LibraryReferenceSymbol
48from pyVHDLModel.Interface import GenericInterfaceItemMixin, PortInterfaceItemMixin
49from pyVHDLModel.Object import DeferredConstant
50from pyVHDLModel.Concurrent import ConcurrentStatement, ConcurrentStatementsMixin
53@export
54class Reference(ModelEntity):
55 """
56 A base-class for all references.
58 .. seealso::
60 * :class:`~pyVHDLModel.DesignUnit.LibraryClause`
61 * :class:`~pyVHDLModel.DesignUnit.UseClause`
62 * :class:`~pyVHDLModel.DesignUnit.ContextReference`
63 """
65 _symbols: List[Symbol]
67 def __init__(self, symbols: Iterable[Symbol], parent: ModelEntity = None) -> None:
68 """
69 Initializes a reference by taking a list of symbols and a parent reference.
71 :param symbols: A list of symbols this reference references to.
72 :param parent: Reference to the logical parent in the model hierarchy.
73 """
74 super().__init__(parent)
76 self._symbols = [s for s in symbols]
78 @readonly
79 def Symbols(self) -> List[Symbol]:
80 """
81 Read-only property to access the symbols this reference references to (:attr:`_symbols`).
83 :returns: A list of symbols.
84 """
85 return self._symbols
88@export
89class LibraryClause(Reference):
90 """
91 Represents a library clause.
93 .. admonition:: Example
95 .. code-block:: VHDL
97 library std, ieee;
98 """
100 @readonly
101 def Symbols(self) -> List[LibraryReferenceSymbol]:
102 """
103 Read-only property to access the symbols this library clause references to (:attr:`_symbols`).
105 :returns: A list of library reference symbols.
106 """
107 return self._symbols
110@export
111class UseClause(Reference):
112 """
113 Represents a use clause.
115 .. admonition:: Example
117 .. code-block:: VHDL
119 use std.text_io.all, ieee.numeric_std.all;
120 """
123@export
124class ContextReference(Reference):
125 """
126 Represents a context reference.
128 .. hint:: It's called *context reference* not *context clause* by the LRM.
130 .. admonition:: Example
132 .. code-block:: VHDL
134 context ieee.ieee_std_context;
135 """
138ContextUnion = Union[
139 LibraryClause,
140 UseClause,
141 ContextReference
142]
145@export
146class DesignUnitWithContextMixin(metaclass=ExtendedType, mixin=True):
147 """
148 A mixin-class for all design units with a context.
149 """
152@export
153class DesignUnit(ModelEntity, NamedEntityMixin, DocumentedEntityMixin):
154 """
155 A base-class for all design units.
157 .. seealso::
159 * :class:`Primary design units <pyVHDLModel.DesignUnit.PrimaryUnit>`
161 * :class:`~pyVHDLModel.DesignUnit.Context`
162 * :class:`~pyVHDLModel.DesignUnit.Entity`
163 * :class:`~pyVHDLModel.DesignUnit.Package`
164 * :class:`~pyVHDLModel.DesignUnit.Configuration`
166 * :class:`Secondary design units <pyVHDLModel.DesignUnit.SecondaryUnit>`
168 * :class:`~pyVHDLModel.DesignUnit.Architecture`
169 * :class:`~pyVHDLModel.DesignUnit.PackageBody`
170 """
172 _document: 'Document' #: The VHDL library, the design unit was analyzed into.
174 # Either written as statements before (e.g. entity, architecture, package, ...), or as statements inside (context)
175 _contextItems: List['ContextUnion'] #: List of all context items (library, use and context clauses).
176 _libraryReferences: List['LibraryClause'] #: List of library clauses.
177 _packageReferences: List['UseClause'] #: List of use clauses.
178 _contextReferences: List['ContextReference'] #: List of context clauses.
180 _referencedLibraries: Dict[str, 'Library'] #: Referenced libraries based on explicit library clauses or implicit inheritance
181 _referencedPackages: Dict[str, Dict[str, 'Package']] #: Referenced packages based on explicit use clauses or implicit inheritance
182 _referencedContexts: Dict[str, 'Context'] #: Referenced contexts based on explicit context references or implicit inheritance
184 _dependencyVertex: Vertex[None, None, str, 'DesignUnit', None, None, None, None, None, None, None, None, None, None, None, None, None] #: Reference to the vertex in the dependency graph representing the design unit. |br| This reference is set by :meth:`~pyVHDLModel.Design.CreateDependencyGraph`.
185 _hierarchyVertex: Vertex[None, None, str, 'DesignUnit', None, None, None, None, None, None, None, None, None, None, None, None, None] #: The vertex in the hierarchy graph
187 _namespace: 'Namespace'
189 def __init__(self, identifier: str, contextItems: Nullable[Iterable[ContextUnion]] = None, documentation: Nullable[str] = None, parent: ModelEntity = None) -> None:
190 """
191 Initializes a design unit.
193 :param identifier: Identifier (name) of the design unit.
194 :param contextItems: A sequence of library, use or context clauses.
195 :param documentation: Associated documentation of the design unit.
196 :param parent: Reference to the logical parent in the model hierarchy.
197 """
198 super().__init__(parent)
199 NamedEntityMixin.__init__(self, identifier)
200 DocumentedEntityMixin.__init__(self, documentation)
202 self._document = None
204 self._contextItems = []
205 self._libraryReferences = []
206 self._packageReferences = []
207 self._contextReferences = []
209 if contextItems is not None:
210 for item in contextItems:
211 self._contextItems.append(item)
212 if isinstance(item, UseClause):
213 self._packageReferences.append(item)
214 elif isinstance(item, LibraryClause):
215 self._libraryReferences.append(item)
216 elif isinstance(item, ContextReference): 216 ↛ 210line 216 didn't jump to line 210 because the condition on line 216 was always true
217 self._contextReferences.append(item)
219 self._referencedLibraries = {}
220 self._referencedPackages = {}
221 self._referencedContexts = {}
223 self._dependencyVertex = None
224 self._hierarchyVertex = None
226 self._namespace = Namespace(self._normalizedIdentifier)
228 @readonly
229 def Document(self) -> 'Document':
230 return self._document
232 @Document.setter
233 def Document(self, document: 'Document') -> None:
234 self._document = document
236 @property
237 def Library(self) -> 'Library':
238 return self._parent
240 @Library.setter
241 def Library(self, library: 'Library') -> None:
242 self._parent = library
244 @property
245 def ContextItems(self) -> List['ContextUnion']:
246 """
247 Read-only property to access the sequence of all context items comprising library, use and context clauses
248 (:attr:`_contextItems`).
250 :returns: Sequence of context items.
251 """
252 return self._contextItems
254 @property
255 def ContextReferences(self) -> List['ContextReference']:
256 """
257 Read-only property to access the sequence of context clauses (:attr:`_contextReferences`).
259 :returns: Sequence of context clauses.
260 """
261 return self._contextReferences
263 @property
264 def LibraryReferences(self) -> List['LibraryClause']:
265 """
266 Read-only property to access the sequence of library clauses (:attr:`_libraryReferences`).
268 :returns: Sequence of library clauses.
269 """
270 return self._libraryReferences
272 @property
273 def PackageReferences(self) -> List['UseClause']:
274 """
275 Read-only property to access the sequence of use clauses (:attr:`_packageReferences`).
277 :returns: Sequence of use clauses.
278 """
279 return self._packageReferences
281 @property
282 def ReferencedLibraries(self) -> Dict[str, 'Library']:
283 return self._referencedLibraries
285 @property
286 def ReferencedPackages(self) -> Dict[str, 'Package']:
287 return self._referencedPackages
289 @property
290 def ReferencedContexts(self) -> Dict[str, 'Context']:
291 return self._referencedContexts
293 @property
294 def DependencyVertex(self) -> Vertex:
295 """
296 Read-only property to access the corresponding dependency vertex (:attr:`_dependencyVertex`).
298 The dependency vertex references this design unit by its value field.
300 :returns: The corresponding dependency vertex.
301 """
302 return self._dependencyVertex
304 @property
305 def HierarchyVertex(self) -> Vertex:
306 """
307 Read-only property to access the corresponding hierarchy vertex (:attr:`_hierarchyVertex`).
309 The hierarchy vertex references this design unit by its value field.
311 :returns: The corresponding hierarchy vertex.
312 """
313 return self._hierarchyVertex
316@export
317class PrimaryUnit(DesignUnit):
318 """
319 A base-class for all primary design units.
321 .. seealso::
323 * :class:`~pyVHDLModel.DesignUnit.Context`
324 * :class:`~pyVHDLModel.DesignUnit.Entity`
325 * :class:`~pyVHDLModel.DesignUnit.Package`
326 * :class:`~pyVHDLModel.DesignUnit.Configuration`
327 """
330@export
331class SecondaryUnit(DesignUnit):
332 """
333 A base-class for all secondary design units.
335 .. seealso::
337 * :class:`~pyVHDLModel.DesignUnit.Architecture`
338 * :class:`~pyVHDLModel.DesignUnit.PackageBody`
339 """
342@export
343class Context(PrimaryUnit):
344 """
345 Represents a context declaration.
347 A context contains a generic list of all its items (library clauses, use clauses and context references) in
348 :data:`_references`.
350 Furthermore, when a context gets initialized, the item kinds get separated into individual lists:
352 * :class:`~pyVHDLModel.DesignUnit.LibraryClause` |rarr| :data:`_libraryReferences`
353 * :class:`~pyVHDLModel.DesignUnit.UseClause` |rarr| :data:`_packageReferences`
354 * :class:`~pyVHDLModel.DesignUnit.ContextReference` |rarr| :data:`_contextReferences`
356 When :meth:`pyVHDLModel.Design.LinkContexts` got called, these lists were processed and the fields:
358 * :data:`_referencedLibraries` (:pycode:`Dict[libName, Library]`)
359 * :data:`_referencedPackages` (:pycode:`Dict[libName, [pkgName, Package]]`)
360 * :data:`_referencedContexts` (:pycode:`Dict[libName, [ctxName, Context]]`)
362 are populated.
364 .. admonition:: Example
366 .. code-block:: VHDL
368 context ctx is
369 -- ...
370 end context;
371 """
373 _references: List[ContextUnion]
375 def __init__(self, identifier: str, references: Nullable[Iterable[ContextUnion]] = None, documentation: Nullable[str] = None, parent: ModelEntity = None) -> None:
376 super().__init__(identifier, None, documentation, parent)
378 self._references = []
379 self._libraryReferences = []
380 self._packageReferences = []
381 self._contextReferences = []
383 if references is not None:
384 for reference in references:
385 self._references.append(reference)
386 reference._parent = self
388 if isinstance(reference, LibraryClause):
389 self._libraryReferences.append(reference)
390 elif isinstance(reference, UseClause): 390 ↛ 392line 390 didn't jump to line 392 because the condition on line 390 was always true
391 self._packageReferences.append(reference)
392 elif isinstance(reference, ContextReference):
393 self._contextReferences.append(reference)
394 else:
395 raise VHDLModelException() # FIXME: needs exception message
397 @property
398 def LibraryReferences(self) -> List[LibraryClause]:
399 return self._libraryReferences
401 @property
402 def PackageReferences(self) -> List[UseClause]:
403 return self._packageReferences
405 @property
406 def ContextReferences(self) -> List[ContextReference]:
407 return self._contextReferences
409 def __str__(self) -> str:
410 lib = self._parent._identifier + "?" if self._parent is not None else ""
412 return f"Context: {lib}.{self._identifier}"
415@export
416class Package(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin):
417 """
418 Represents a package declaration.
420 .. admonition:: Example
422 .. code-block:: VHDL
424 package pkg is
425 -- ...
426 end package;
427 """
429 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in this package.
430 _packageBody: Nullable["PackageBody"]
432 _genericItems: List[GenericInterfaceItemMixin]
434 _deferredConstants: Dict[str, DeferredConstant]
435 _components: Dict[str, 'Component']
437 def __init__(
438 self,
439 identifier: str,
440 contextItems: Nullable[Iterable[ContextUnion]] = None,
441 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None,
442 declaredItems: Nullable[Iterable] = None,
443 documentation: Nullable[str] = None,
444 allowBlackbox: Nullable[bool] = None,
445 parent: ModelEntity = None
446 ) -> None:
447 """
448 Initialize a package.
450 :param identifier: Name of the VHDL package.
451 :param contextItems:
452 :param genericItems:
453 :param declaredItems:
454 :param documentation:
455 :param allowBlackbox: Specify if blackboxes are allowed in this design.
456 :param parent: The parent model entity (library) of this VHDL package.
457 """
458 super().__init__(identifier, contextItems, documentation, parent)
459 DesignUnitWithContextMixin.__init__(self)
460 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
462 self._allowBlackbox = allowBlackbox
463 self._packageBody = None
465 # TODO: extract to mixin
466 self._genericItems = [] # TODO: convert to dict
467 if genericItems is not None: 467 ↛ 468line 467 didn't jump to line 468 because the condition on line 467 was never true
468 for generic in genericItems:
469 self._genericItems.append(generic)
470 generic._parent = self
472 self._deferredConstants = {}
473 self._components = {}
475 @property
476 def AllowBlackbox(self) -> bool:
477 """
478 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`).
480 :returns: If blackboxes are allowed.
481 """
482 if self._allowBlackbox is None:
483 return self._parent.AllowBlackbox
484 else:
485 return self._allowBlackbox
487 @AllowBlackbox.setter
488 def AllowBlackbox(self, value: Nullable[bool]) -> None:
489 self._allowBlackbox = value
491 @property
492 def PackageBody(self) -> Nullable["PackageBody"]:
493 return self._packageBody
495 @property
496 def GenericItems(self) -> List[GenericInterfaceItemMixin]:
497 return self._genericItems
499 @property
500 def DeclaredItems(self) -> List:
501 return self._declaredItems
503 @property
504 def DeferredConstants(self):
505 return self._deferredConstants
507 @property
508 def Components(self):
509 return self._components
511 def _IndexOtherDeclaredItem(self, item):
512 if isinstance(item, DeferredConstant):
513 for normalizedIdentifier in item.NormalizedIdentifiers:
514 self._deferredConstants[normalizedIdentifier] = item
515 elif isinstance(item, Component):
516 self._components[item.NormalizedIdentifier] = item
517 else:
518 super()._IndexOtherDeclaredItem(item)
520 def __str__(self) -> str:
521 lib = self._parent._identifier if self._parent is not None else "%"
523 return f"Package: '{lib}.{self._identifier}'"
525 def __repr__(self) -> str:
526 lib = self._parent._identifier if self._parent is not None else "%"
528 return f"{lib}.{self._identifier}"
531@export
532class PackageBody(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin):
533 """
534 Represents a package body declaration.
536 .. admonition:: Example
538 .. code-block:: VHDL
540 package body pkg is
541 -- ...
542 end package body;
543 """
545 _package: PackageSymbol
547 def __init__(
548 self,
549 packageSymbol: PackageSymbol,
550 contextItems: Nullable[Iterable[ContextUnion]] = None,
551 declaredItems: Nullable[Iterable] = None,
552 documentation: Nullable[str] = None,
553 parent: ModelEntity = None
554 ) -> None:
555 super().__init__(packageSymbol.Name.Identifier, contextItems, documentation, parent)
556 DesignUnitWithContextMixin.__init__(self)
557 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
559 self._package = packageSymbol
560 packageSymbol._parent = self
562 @property
563 def Package(self) -> PackageSymbol:
564 return self._package
566 @property
567 def DeclaredItems(self) -> List:
568 return self._declaredItems
570 def LinkDeclaredItemsToPackage(self) -> None:
571 pass
573 def __str__(self) -> str:
574 lib = self._parent._identifier + "?" if self._parent is not None else ""
576 return f"Package Body: {lib}.{self._identifier}(body)"
578 def __repr__(self) -> str:
579 lib = self._parent._identifier + "?" if self._parent is not None else ""
581 return f"{lib}.{self._identifier}(body)"
584@export
585class Entity(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin):
586 """
587 Represents an entity declaration.
589 .. admonition:: Example
591 .. code-block:: VHDL
593 entity ent is
594 -- ...
595 end entity;
596 """
598 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in this package.
600 _genericItems: List[GenericInterfaceItemMixin]
601 _portItems: List[PortInterfaceItemMixin]
603 _architectures: Dict[str, 'Architecture']
605 def __init__(
606 self,
607 identifier: str,
608 contextItems: Nullable[Iterable[ContextUnion]] = None,
609 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None,
610 portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None,
611 declaredItems: Nullable[Iterable] = None,
612 statements: Nullable[Iterable[ConcurrentStatement]] = None,
613 documentation: Nullable[str] = None,
614 allowBlackbox: Nullable[bool] = None,
615 parent: ModelEntity = None
616 ) -> None:
617 super().__init__(identifier, contextItems, documentation, parent)
618 DesignUnitWithContextMixin.__init__(self)
619 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
620 ConcurrentStatementsMixin.__init__(self, statements)
622 self._allowBlackbox = allowBlackbox
624 # TODO: extract to mixin
625 self._genericItems = []
626 if genericItems is not None: 626 ↛ 627line 626 didn't jump to line 627 because the condition on line 626 was never true
627 for item in genericItems:
628 self._genericItems.append(item)
629 item._parent = self
631 # TODO: extract to mixin
632 self._portItems = []
633 if portItems is not None: 633 ↛ 634line 633 didn't jump to line 634 because the condition on line 633 was never true
634 for item in portItems:
635 self._portItems.append(item)
636 item._parent = self
638 self._architectures = {}
640 @property
641 def AllowBlackbox(self) -> bool:
642 """
643 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`).
645 :returns: If blackboxes are allowed.
646 """
647 if self._allowBlackbox is None:
648 return self._parent.AllowBlackbox
649 else:
650 return self._allowBlackbox
652 @AllowBlackbox.setter
653 def AllowBlackbox(self, value: Nullable[bool]) -> None:
654 self._allowBlackbox = value
656 # TODO: extract to mixin for generics
657 @property
658 def GenericItems(self) -> List[GenericInterfaceItemMixin]:
659 return self._genericItems
661 # TODO: extract to mixin for ports
662 @property
663 def PortItems(self) -> List[PortInterfaceItemMixin]:
664 return self._portItems
666 @property
667 def Architectures(self) -> Dict[str, 'Architecture']:
668 return self._architectures
670 def __str__(self) -> str:
671 lib = self._parent._identifier if self._parent is not None else "%"
672 archs = ', '.join(self._architectures.keys()) if self._architectures else "%"
674 return f"Entity: '{lib}.{self._identifier}({archs})'"
676 def __repr__(self) -> str:
677 lib = self._parent._identifier if self._parent is not None else "%"
678 archs = ', '.join(self._architectures.keys()) if self._architectures else "%"
680 return f"{lib}.{self._identifier}({archs})"
683@export
684class Architecture(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin):
685 """
686 Represents an architecture declaration.
688 .. admonition:: Example
690 .. code-block:: VHDL
692 architecture rtl of ent is
693 -- ...
694 begin
695 -- ...
696 end architecture;
697 """
699 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in this package.
700 _entity: EntitySymbol
702 def __init__(
703 self,
704 identifier: str,
705 entity: EntitySymbol,
706 contextItems: Nullable[Iterable[Context]] = None,
707 declaredItems: Nullable[Iterable] = None,
708 statements: Iterable['ConcurrentStatement'] = None,
709 documentation: Nullable[str] = None,
710 allowBlackbox: Nullable[bool] = None,
711 parent: ModelEntity = None
712 ) -> None:
713 super().__init__(identifier, contextItems, documentation, parent)
714 DesignUnitWithContextMixin.__init__(self)
715 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems)
716 ConcurrentStatementsMixin.__init__(self, statements)
718 self._allowBlackbox = allowBlackbox
720 self._entity = entity
721 entity._parent = self
723 @property
724 def Entity(self) -> EntitySymbol:
725 return self._entity
727 @property
728 def AllowBlackbox(self) -> bool:
729 """
730 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`).
732 :returns: If blackboxes are allowed.
733 """
734 if self._allowBlackbox is None:
735 return self._parent.AllowBlackbox
736 else:
737 return self._allowBlackbox
739 @AllowBlackbox.setter
740 def AllowBlackbox(self, value: Nullable[bool]) -> None:
741 self._allowBlackbox = value
743 def __str__(self) -> str:
744 lib = self._parent._identifier if self._parent is not None else "%"
745 ent = self._entity._name._identifier if self._entity is not None else "%"
747 return f"Architecture: {lib}.{ent}({self._identifier})"
749 def __repr__(self) -> str:
750 lib = self._parent._identifier if self._parent is not None else "%"
751 ent = self._entity._name._identifier if self._entity is not None else "%"
753 return f"{lib}.{ent}({self._identifier})"
756@export
757class Component(ModelEntity, NamedEntityMixin, DocumentedEntityMixin):
758 """
759 Represents a configuration declaration.
761 .. admonition:: Example
763 .. code-block:: VHDL
765 component ent is
766 -- ...
767 end component;
768 """
770 _allowBlackbox: Nullable[bool] #: Allow component to be a blackbox.
771 _isBlackBox: Nullable[bool] #: Component is a blackbox.
773 _genericItems: List[GenericInterfaceItemMixin]
774 _portItems: List[PortInterfaceItemMixin]
776 _entity: Nullable[Entity]
778 def __init__(
779 self,
780 identifier: str,
781 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None,
782 portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None,
783 documentation: Nullable[str] = None,
784 allowBlackbox: Nullable[bool] = None,
785 parent: ModelEntity = None
786 ) -> None:
787 super().__init__(parent)
788 NamedEntityMixin.__init__(self, identifier)
789 DocumentedEntityMixin.__init__(self, documentation)
791 self._allowBlackbox = allowBlackbox
792 self._isBlackBox = None
793 self._entity = None
795 # TODO: extract to mixin
796 self._genericItems = []
797 if genericItems is not None:
798 for item in genericItems:
799 self._genericItems.append(item)
800 item._parent = self
802 # TODO: extract to mixin
803 self._portItems = []
804 if portItems is not None:
805 for item in portItems:
806 self._portItems.append(item)
807 item._parent = self
809 @property
810 def AllowBlackbox(self) -> bool:
811 """
812 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`).
814 :returns: If blackboxes are allowed.
815 """
816 if self._allowBlackbox is None:
817 return self._parent.AllowBlackbox
818 else:
819 return self._allowBlackbox
821 @AllowBlackbox.setter
822 def AllowBlackbox(self, value: Nullable[bool]) -> None:
823 self._allowBlackbox = value
825 @property
826 def IsBlackbox(self) -> bool:
827 """
828 Read-only property returning true, if this component is a blackbox (:attr:`_isBlackbox`).
830 :returns: If this component is a blackbox.
831 """
832 return self._isBlackBox
834 @property
835 def GenericItems(self) -> List[GenericInterfaceItemMixin]:
836 return self._genericItems
838 @property
839 def PortItems(self) -> List[PortInterfaceItemMixin]:
840 return self._portItems
842 @property
843 def Entity(self) -> Nullable[Entity]:
844 return self._entity
846 @Entity.setter
847 def Entity(self, value: Entity) -> None:
848 self._entity = value
849 self._isBlackBox = False
852@export
853class Configuration(PrimaryUnit, DesignUnitWithContextMixin):
854 """
855 Represents a configuration declaration.
857 .. admonition:: Example
859 .. code-block:: VHDL
861 configuration cfg of ent is
862 for rtl
863 -- ...
864 end for;
865 end configuration;
866 """
868 def __init__(
869 self,
870 identifier: str,
871 contextItems: Nullable[Iterable[Context]] = None,
872 documentation: Nullable[str] = None,
873 parent: ModelEntity = None
874 ) -> None:
875 super().__init__(identifier, contextItems, documentation, parent)
876 DesignUnitWithContextMixin.__init__(self)
878 def __str__(self) -> str:
879 lib = self._parent._identifier if self._parent is not None else "%"
881 return f"Configuration: {lib}.{self._identifier}"
883 def __repr__(self) -> str:
884 lib = self._parent._identifier if self._parent is not None else "%"
886 return f"{lib}.{self._identifier}"