Coverage for pyVHDLModel/DesignUnit.py: 71%

287 statements  

« prev     ^ index     » next       coverage.py v7.15.1, created at 2026-07-13 17:58 +0000

1# ==================================================================================================================== # 

2# __ ___ _ ____ _ __ __ _ _ # 

3# _ __ _ \ \ / / | | | _ \| | | \/ | ___ __| | ___| | # 

4# | '_ \| | | \ \ / /| |_| | | | | | | |\/| |/ _ \ / _` |/ _ \ | # 

5# | |_) | |_| |\ V / | _ | |_| | |___| | | | (_) | (_| | __/ | # 

6# | .__/ \__, | \_/ |_| |_|____/|_____|_| |_|\___/ \__,_|\___|_| # 

7# |_| |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2017-2026 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. 

34 

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 

38 

39from pyTooling.Decorators import export, readonly 

40from pyTooling.MetaClasses import ExtendedType 

41from pyTooling.Graph import Vertex 

42 

43from pyVHDLModel.Common import AllowBlackboxMixin 

44from pyVHDLModel.Exception import VHDLModelException 

45from pyVHDLModel.Base import ModelEntity, NamedEntityMixin, DocumentedEntityMixin 

46from pyVHDLModel.Namespace import Namespace 

47from pyVHDLModel.Regions import ConcurrentDeclarationRegionMixin 

48from pyVHDLModel.Symbol import Symbol, PackageSymbol, EntitySymbol, LibraryReferenceSymbol 

49from pyVHDLModel.Interface import GenericInterfaceItemMixin, PortInterfaceItemMixin, WithGenericsMixin, WithPortsMixin 

50from pyVHDLModel.Object import DeferredConstant 

51from pyVHDLModel.Concurrent import ConcurrentStatement, ConcurrentStatementsMixin 

52 

53 

54@export 

55class Reference(ModelEntity): 

56 """ 

57 A base-class for all references. 

58 

59 .. seealso:: 

60 

61 * :class:`~pyVHDLModel.DesignUnit.LibraryClause` 

62 * :class:`~pyVHDLModel.DesignUnit.UseClause` 

63 * :class:`~pyVHDLModel.DesignUnit.ContextReference` 

64 """ 

65 

66 _symbols: List[Symbol] 

67 

68 def __init__(self, symbols: Iterable[Symbol], parent: Nullable[ModelEntity] = None) -> None: 

69 """ 

70 Initializes a reference by taking a list of symbols and a parent reference. 

71 

72 :param symbols: A list of symbols this reference references to. 

73 :param parent: Reference to the logical parent in the model hierarchy. 

74 """ 

75 super().__init__(parent) 

76 

77 self._symbols = [s for s in symbols] 

78 

79 @readonly 

80 def Symbols(self) -> List[Symbol]: 

81 """ 

82 Read-only property to access the symbols this reference references to (:attr:`_symbols`). 

83 

84 :returns: A list of symbols. 

85 """ 

86 return self._symbols 

87 

88 

89@export 

90class LibraryClause(Reference): 

91 """ 

92 Represents a library clause. 

93 

94 .. admonition:: Example 

95 

96 .. code-block:: VHDL 

97 

98 library std, ieee; 

99 """ 

100 

101 @readonly 

102 def Symbols(self) -> List[LibraryReferenceSymbol]: 

103 """ 

104 Read-only property to access the symbols this library clause references to (:attr:`_symbols`). 

105 

106 :returns: A list of library reference symbols. 

107 """ 

108 return self._symbols 

109 

110 

111@export 

112class UseClause(Reference): 

113 """ 

114 Represents a use clause. 

115 

116 .. admonition:: Example 

117 

118 .. code-block:: VHDL 

119 

120 use std.text_io.all, ieee.numeric_std.all; 

121 """ 

122 

123 

124@export 

125class ContextReference(Reference): 

126 """ 

127 Represents a context reference. 

128 

129 .. hint:: It's called *context reference* not *context clause* by the LRM. 

130 

131 .. admonition:: Example 

132 

133 .. code-block:: VHDL 

134 

135 context ieee.ieee_std_context; 

136 """ 

137 

138 

139ContextUnion = Union[ 

140 LibraryClause, 

141 UseClause, 

142 ContextReference 

143] 

144 

145 

146@export 

147class DesignUnitWithContextMixin(metaclass=ExtendedType, mixin=True): 

148 """ 

149 A mixin-class for all design units with a context. 

150 """ 

151 

152 

153@export 

154class DesignUnit(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

155 """ 

156 A base-class for all design units. 

157 

158 .. seealso:: 

159 

160 * :class:`Primary design units <pyVHDLModel.DesignUnit.PrimaryUnit>` 

161 

162 * :class:`~pyVHDLModel.DesignUnit.Context` 

163 * :class:`~pyVHDLModel.DesignUnit.Entity` 

164 * :class:`~pyVHDLModel.DesignUnit.Package` 

165 * :class:`~pyVHDLModel.DesignUnit.Configuration` 

166 

167 * :class:`Secondary design units <pyVHDLModel.DesignUnit.SecondaryUnit>` 

168 

169 * :class:`~pyVHDLModel.DesignUnit.Architecture` 

170 * :class:`~pyVHDLModel.DesignUnit.PackageBody` 

171 """ 

172 

173 _document: 'Document' #: The VHDL library, the design unit was analyzed into. 

174 

175 # Either written as statements before (e.g. entity, architecture, package, ...), or as statements inside (context) 

176 _contextItems: List['ContextUnion'] #: List of all context items (library, use and context clauses). 

177 _libraryReferences: List['LibraryClause'] #: List of library clauses. 

178 _packageReferences: List['UseClause'] #: List of use clauses. 

179 _contextReferences: List['ContextReference'] #: List of context clauses. 

180 

181 _referencedLibraries: Dict[str, 'Library'] #: Referenced libraries based on explicit library clauses or implicit inheritance 

182 _referencedPackages: Dict[str, Dict[str, 'Package']] #: Referenced packages based on explicit use clauses or implicit inheritance 

183 _referencedContexts: Dict[str, 'Context'] #: Referenced contexts based on explicit context references or implicit inheritance 

184 

185 _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`. 

186 _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 

188 _namespace: 'Namespace' 

189 

190 def __init__(self, identifier: str, contextItems: Nullable[Iterable[ContextUnion]] = None, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

191 """ 

192 Initializes a design unit. 

193 

194 :param identifier: Identifier (name) of the design unit. 

195 :param contextItems: A sequence of library, use or context clauses. 

196 :param documentation: Associated documentation of the design unit. 

197 :param parent: Reference to the logical parent in the model hierarchy. 

198 """ 

199 super().__init__(parent) 

200 NamedEntityMixin.__init__(self, identifier) 

201 DocumentedEntityMixin.__init__(self, documentation) 

202 

203 self._document = None 

204 

205 self._contextItems = [] 

206 self._libraryReferences = [] 

207 self._packageReferences = [] 

208 self._contextReferences = [] 

209 

210 if contextItems is not None: 

211 for item in contextItems: 

212 self._contextItems.append(item) 

213 if isinstance(item, UseClause): 

214 self._packageReferences.append(item) 

215 elif isinstance(item, LibraryClause): 

216 self._libraryReferences.append(item) 

217 elif isinstance(item, ContextReference): 217 ↛ 211line 217 didn't jump to line 211 because the condition on line 217 was always true

218 self._contextReferences.append(item) 

219 

220 self._referencedLibraries = {} 

221 self._referencedPackages = {} 

222 self._referencedContexts = {} 

223 

224 self._dependencyVertex = None 

225 self._hierarchyVertex = None 

226 

227 self._namespace = Namespace(self._normalizedIdentifier) 

228 

229 @readonly 

230 def Document(self) -> 'Document': 

231 return self._document 

232 

233 @Document.setter 

234 def Document(self, document: 'Document') -> None: 

235 self._document = document 

236 

237 @property 

238 def Library(self) -> 'Library': 

239 return self._parent 

240 

241 @Library.setter 

242 def Library(self, library: 'Library') -> None: 

243 self._parent = library 

244 

245 @property 

246 def ContextItems(self) -> List['ContextUnion']: 

247 """ 

248 Read-only property to access the sequence of all context items comprising library, use and context clauses 

249 (:attr:`_contextItems`). 

250 

251 :returns: Sequence of context items. 

252 """ 

253 return self._contextItems 

254 

255 @property 

256 def ContextReferences(self) -> List['ContextReference']: 

257 """ 

258 Read-only property to access the sequence of context clauses (:attr:`_contextReferences`). 

259 

260 :returns: Sequence of context clauses. 

261 """ 

262 return self._contextReferences 

263 

264 @property 

265 def LibraryReferences(self) -> List['LibraryClause']: 

266 """ 

267 Read-only property to access the sequence of library clauses (:attr:`_libraryReferences`). 

268 

269 :returns: Sequence of library clauses. 

270 """ 

271 return self._libraryReferences 

272 

273 @property 

274 def PackageReferences(self) -> List['UseClause']: 

275 """ 

276 Read-only property to access the sequence of use clauses (:attr:`_packageReferences`). 

277 

278 :returns: Sequence of use clauses. 

279 """ 

280 return self._packageReferences 

281 

282 @property 

283 def ReferencedLibraries(self) -> Dict[str, 'Library']: 

284 return self._referencedLibraries 

285 

286 @property 

287 def ReferencedPackages(self) -> Dict[str, 'Package']: 

288 return self._referencedPackages 

289 

290 @property 

291 def ReferencedContexts(self) -> Dict[str, 'Context']: 

292 return self._referencedContexts 

293 

294 @property 

295 def DependencyVertex(self) -> Vertex: 

296 """ 

297 Read-only property to access the corresponding dependency vertex (:attr:`_dependencyVertex`). 

298 

299 The dependency vertex references this design unit by its value field. 

300 

301 :returns: The corresponding dependency vertex. 

302 """ 

303 return self._dependencyVertex 

304 

305 @property 

306 def HierarchyVertex(self) -> Vertex: 

307 """ 

308 Read-only property to access the corresponding hierarchy vertex (:attr:`_hierarchyVertex`). 

309 

310 The hierarchy vertex references this design unit by its value field. 

311 

312 :returns: The corresponding hierarchy vertex. 

313 """ 

314 return self._hierarchyVertex 

315 

316 

317@export 

318class PrimaryUnit(DesignUnit): 

319 """ 

320 A base-class for all primary design units. 

321 

322 .. seealso:: 

323 

324 * :class:`~pyVHDLModel.DesignUnit.Context` 

325 * :class:`~pyVHDLModel.DesignUnit.Entity` 

326 * :class:`~pyVHDLModel.DesignUnit.Package` 

327 * :class:`~pyVHDLModel.DesignUnit.Configuration` 

328 """ 

329 

330 

331@export 

332class SecondaryUnit(DesignUnit): 

333 """ 

334 A base-class for all secondary design units. 

335 

336 .. seealso:: 

337 

338 * :class:`~pyVHDLModel.DesignUnit.Architecture` 

339 * :class:`~pyVHDLModel.DesignUnit.PackageBody` 

340 """ 

341 

342 

343@export 

344class Context(PrimaryUnit): 

345 """ 

346 Represents a context declaration. 

347 

348 A context contains a generic list of all its items (library clauses, use clauses and context references) in 

349 :data:`_references`. 

350 

351 Furthermore, when a context gets initialized, the item kinds get separated into individual lists: 

352 

353 * :class:`~pyVHDLModel.DesignUnit.LibraryClause` |rarr| :data:`_libraryReferences` 

354 * :class:`~pyVHDLModel.DesignUnit.UseClause` |rarr| :data:`_packageReferences` 

355 * :class:`~pyVHDLModel.DesignUnit.ContextReference` |rarr| :data:`_contextReferences` 

356 

357 When :meth:`pyVHDLModel.Design.LinkContexts` got called, these lists were processed and the fields: 

358 

359 * :data:`_referencedLibraries` (:pycode:`Dict[libName, Library]`) 

360 * :data:`_referencedPackages` (:pycode:`Dict[libName, [pkgName, Package]]`) 

361 * :data:`_referencedContexts` (:pycode:`Dict[libName, [ctxName, Context]]`) 

362 

363 are populated. 

364 

365 .. admonition:: Example 

366 

367 .. code-block:: VHDL 

368 

369 context ctx is 

370 -- ... 

371 end context; 

372 """ 

373 

374 _references: List[ContextUnion] 

375 

376 def __init__(self, identifier: str, references: Nullable[Iterable[ContextUnion]] = None, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

377 super().__init__(identifier, None, documentation, parent) 

378 

379 self._references = [] 

380 self._libraryReferences = [] 

381 self._packageReferences = [] 

382 self._contextReferences = [] 

383 

384 if references is not None: 

385 for reference in references: 

386 self._references.append(reference) 

387 reference.Parent = self 

388 

389 if isinstance(reference, LibraryClause): 

390 self._libraryReferences.append(reference) 

391 elif isinstance(reference, UseClause): 391 ↛ 393line 391 didn't jump to line 393 because the condition on line 391 was always true

392 self._packageReferences.append(reference) 

393 elif isinstance(reference, ContextReference): 

394 self._contextReferences.append(reference) 

395 else: 

396 raise VHDLModelException() # FIXME: needs exception message 

397 

398 @property 

399 def LibraryReferences(self) -> List[LibraryClause]: 

400 return self._libraryReferences 

401 

402 @property 

403 def PackageReferences(self) -> List[UseClause]: 

404 return self._packageReferences 

405 

406 @property 

407 def ContextReferences(self) -> List[ContextReference]: 

408 return self._contextReferences 

409 

410 def __str__(self) -> str: 

411 lib = self._parent._identifier + "?" if self._parent is not None else "" 

412 

413 return f"Context: {lib}.{self._identifier}" 

414 

415 

416@export 

417class Package(PrimaryUnit, DesignUnitWithContextMixin, WithGenericsMixin, ConcurrentDeclarationRegionMixin, AllowBlackboxMixin): 

418 """ 

419 Represents a package declaration. 

420 

421 .. admonition:: Example 

422 

423 .. code-block:: VHDL 

424 

425 package pkg is 

426 -- ... 

427 end package; 

428 """ 

429 

430 _packageBody: Nullable["PackageBody"] 

431 

432 _deferredConstants: Dict[str, DeferredConstant] 

433 _components: Dict[str, 'Component'] 

434 

435 def __init__( 

436 self, 

437 identifier: str, 

438 contextItems: Nullable[Iterable[ContextUnion]] = None, 

439 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None, 

440 declaredItems: Nullable[Iterable] = None, 

441 documentation: Nullable[str] = None, 

442 allowBlackbox: Nullable[bool] = None, 

443 parent: Nullable[ModelEntity] = None 

444 ) -> None: 

445 """ 

446 Initialize a package. 

447 

448 :param identifier: Name of the VHDL package. 

449 :param contextItems: 

450 :param genericItems: 

451 :param declaredItems: 

452 :param documentation: 

453 :param allowBlackbox: Specify if blackboxes are allowed in this design. 

454 :param parent: The parent model entity (library) of this VHDL package. 

455 """ 

456 super().__init__(identifier, contextItems, documentation, parent) 

457 DesignUnitWithContextMixin.__init__(self) 

458 WithGenericsMixin.__init__(self, genericItems) 

459 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

460 AllowBlackboxMixin.__init__(self, allowBlackbox) 

461 

462 self._packageBody = None 

463 

464 self._deferredConstants = {} 

465 self._components = {} 

466 

467 @property 

468 def PackageBody(self) -> Nullable["PackageBody"]: 

469 return self._packageBody 

470 

471 @property 

472 def DeclaredItems(self) -> List: 

473 return self._declaredItems 

474 

475 @property 

476 def DeferredConstants(self): 

477 return self._deferredConstants 

478 

479 @property 

480 def Components(self): 

481 return self._components 

482 

483 def _IndexOtherDeclaredItem(self, item): 

484 if isinstance(item, DeferredConstant): 

485 for normalizedIdentifier in item.NormalizedIdentifiers: 

486 self._deferredConstants[normalizedIdentifier] = item 

487 elif isinstance(item, Component): 

488 self._components[item._normalizedIdentifier] = item 

489 else: 

490 super()._IndexOtherDeclaredItem(item) 

491 

492 def __str__(self) -> str: 

493 lib = self._parent._identifier if self._parent is not None else "%" 

494 

495 return f"Package: '{lib}.{self._identifier}'" 

496 

497 def __repr__(self) -> str: 

498 lib = self._parent._identifier if self._parent is not None else "%" 

499 

500 return f"{lib}.{self._identifier}" 

501 

502 

503@export 

504class PackageBody(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin): 

505 """ 

506 Represents a package body declaration. 

507 

508 .. admonition:: Example 

509 

510 .. code-block:: VHDL 

511 

512 package body pkg is 

513 -- ... 

514 end package body; 

515 """ 

516 

517 _package: PackageSymbol 

518 

519 def __init__( 

520 self, 

521 packageSymbol: PackageSymbol, 

522 contextItems: Nullable[Iterable[ContextUnion]] = None, 

523 declaredItems: Nullable[Iterable] = None, 

524 documentation: Nullable[str] = None, 

525 parent: Nullable[ModelEntity] = None 

526 ) -> None: 

527 super().__init__(packageSymbol.Name.Identifier, contextItems, documentation, parent) 

528 DesignUnitWithContextMixin.__init__(self) 

529 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

530 

531 self._package = packageSymbol 

532 packageSymbol.Parent = self 

533 

534 @property 

535 def Package(self) -> PackageSymbol: 

536 return self._package 

537 

538 @property 

539 def DeclaredItems(self) -> List: 

540 return self._declaredItems 

541 

542 def LinkDeclaredItemsToPackage(self) -> None: 

543 pass 

544 

545 def __str__(self) -> str: 

546 lib = self._parent._identifier + "?" if self._parent is not None else "" 

547 

548 return f"Package Body: {lib}.{self._identifier}(body)" 

549 

550 def __repr__(self) -> str: 

551 lib = self._parent._identifier + "?" if self._parent is not None else "" 

552 

553 return f"{lib}.{self._identifier}(body)" 

554 

555 

556@export 

557class Entity(PrimaryUnit, DesignUnitWithContextMixin, WithGenericsMixin, WithPortsMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin, AllowBlackboxMixin): 

558 """ 

559 Represents an entity declaration. 

560 

561 .. admonition:: Example 

562 

563 .. code-block:: VHDL 

564 

565 entity ent is 

566 -- ... 

567 end entity; 

568 """ 

569 

570 _architectures: Dict[str, 'Architecture'] 

571 

572 def __init__( 

573 self, 

574 identifier: str, 

575 contextItems: Nullable[Iterable[ContextUnion]] = None, 

576 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None, 

577 portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None, 

578 declaredItems: Nullable[Iterable] = None, 

579 statements: Nullable[Iterable[ConcurrentStatement]] = None, 

580 documentation: Nullable[str] = None, 

581 allowBlackbox: Nullable[bool] = None, 

582 parent: Nullable[ModelEntity] = None 

583 ) -> None: 

584 super().__init__(identifier, contextItems, documentation, parent) 

585 DesignUnitWithContextMixin.__init__(self) 

586 WithGenericsMixin.__init__(self, genericItems) 

587 WithPortsMixin.__init__(self, portItems) 

588 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

589 ConcurrentStatementsMixin.__init__(self, statements) 

590 AllowBlackboxMixin.__init__(self, allowBlackbox) 

591 

592 self._architectures = {} 

593 

594 @property 

595 def Architectures(self) -> Dict[str, 'Architecture']: 

596 return self._architectures 

597 

598 def __str__(self) -> str: 

599 lib = self._parent._identifier if self._parent is not None else "%" 

600 archs = ', '.join(self._architectures.keys()) if self._architectures else "%" 

601 

602 return f"Entity: '{lib}.{self._identifier}({archs})'" 

603 

604 def __repr__(self) -> str: 

605 lib = self._parent._identifier if self._parent is not None else "%" 

606 archs = ', '.join(self._architectures.keys()) if self._architectures else "%" 

607 

608 return f"{lib}.{self._identifier}({archs})" 

609 

610 

611@export 

612class Architecture(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin, AllowBlackboxMixin): 

613 """ 

614 Represents an architecture declaration. 

615 

616 .. admonition:: Example 

617 

618 .. code-block:: VHDL 

619 

620 architecture rtl of ent is 

621 -- ... 

622 begin 

623 -- ... 

624 end architecture; 

625 """ 

626 

627 _entity: EntitySymbol 

628 

629 def __init__( 

630 self, 

631 identifier: str, 

632 entity: EntitySymbol, 

633 contextItems: Nullable[Iterable[Context]] = None, 

634 declaredItems: Nullable[Iterable] = None, 

635 statements: Iterable['ConcurrentStatement'] = None, 

636 documentation: Nullable[str] = None, 

637 allowBlackbox: Nullable[bool] = None, 

638 parent: Nullable[ModelEntity] = None 

639 ) -> None: 

640 super().__init__(identifier, contextItems, documentation, parent) 

641 DesignUnitWithContextMixin.__init__(self) 

642 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

643 ConcurrentStatementsMixin.__init__(self, statements) 

644 AllowBlackboxMixin.__init__(self, allowBlackbox) 

645 

646 self._entity = entity 

647 entity.Parent = self 

648 

649 @property 

650 def Entity(self) -> EntitySymbol: # FIXME: change to entitySymbol, offer entity directly, but raise exception if not resolved. 

651 return self._entity 

652 

653 def __str__(self) -> str: 

654 lib = self._parent._identifier if self._parent is not None else "%" 

655 ent = self._entity._name._identifier if self._entity is not None else "%" 

656 

657 return f"Architecture: {lib}.{ent}({self._identifier})" 

658 

659 def __repr__(self) -> str: 

660 lib = self._parent._identifier if self._parent is not None else "%" 

661 ent = self._entity._name._identifier if self._entity is not None else "%" 

662 

663 return f"{lib}.{ent}({self._identifier})" 

664 

665 

666@export 

667class Component(ModelEntity, NamedEntityMixin, DocumentedEntityMixin, AllowBlackboxMixin): 

668 """ 

669 Represents a configuration declaration. 

670 

671 .. admonition:: Example 

672 

673 .. code-block:: VHDL 

674 

675 component ent is 

676 -- ... 

677 end component; 

678 """ 

679 

680 _isBlackBox: Nullable[bool] #: Component is a blackbox. 

681 

682 _genericItems: List[GenericInterfaceItemMixin] 

683 _portItems: List[PortInterfaceItemMixin] 

684 

685 _entity: Nullable[Entity] 

686 

687 def __init__( 

688 self, 

689 identifier: str, 

690 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None, 

691 portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None, 

692 documentation: Nullable[str] = None, 

693 allowBlackbox: Nullable[bool] = None, 

694 parent: Nullable[ModelEntity] = None 

695 ) -> None: 

696 super().__init__(parent) 

697 NamedEntityMixin.__init__(self, identifier) 

698 DocumentedEntityMixin.__init__(self, documentation) 

699 AllowBlackboxMixin.__init__(self, allowBlackbox) 

700 

701 self._isBlackBox = None 

702 self._entity = None 

703 

704 # TODO: extract to mixin 

705 self._genericItems = [] 

706 if genericItems is not None: 

707 for item in genericItems: 

708 self._genericItems.append(item) 

709 item.Parent = self 

710 

711 # TODO: extract to mixin 

712 self._portItems = [] 

713 if portItems is not None: 

714 for item in portItems: 

715 self._portItems.append(item) 

716 item.Parent = self 

717 

718 @property 

719 def IsBlackbox(self) -> Nullable[bool]: 

720 """ 

721 Read-only property returning true, if this component is a blackbox (:attr:`_isBlackbox`). 

722 

723 If components were not linked to matching entities, this property returns None. 

724 

725 :returns: If this component is a blackbox. 

726 """ 

727 return self._isBlackBox 

728 

729 @property 

730 def GenericItems(self) -> List[GenericInterfaceItemMixin]: 

731 return self._genericItems 

732 

733 @property 

734 def PortItems(self) -> List[PortInterfaceItemMixin]: 

735 return self._portItems 

736 

737 @property 

738 def Entity(self) -> Nullable[Entity]: 

739 return self._entity 

740 

741 @Entity.setter 

742 def Entity(self, value: Entity) -> None: 

743 self._entity = value 

744 self._isBlackBox = False 

745 

746 def __str__(self) -> str: 

747 return f"Component: {self._identifier}" 

748 

749 def __repr__(self) -> str: 

750 if isinstance(self._parent, Package): 

751 return f"{self._parent!r}:{self._identifier}" 

752 elif isinstance(self._parent, Architecture): 

753 return f"{self._parent!r}:{self._identifier}" 

754 

755 

756@export 

757class Configuration(PrimaryUnit, DesignUnitWithContextMixin): 

758 """ 

759 Represents a configuration declaration. 

760 

761 .. admonition:: Example 

762 

763 .. code-block:: VHDL 

764 

765 configuration cfg of ent is 

766 for rtl 

767 -- ... 

768 end for; 

769 end configuration; 

770 """ 

771 

772 def __init__( 

773 self, 

774 identifier: str, 

775 contextItems: Nullable[Iterable[Context]] = None, 

776 documentation: Nullable[str] = None, 

777 parent: Nullable[ModelEntity] = None 

778 ) -> None: 

779 super().__init__(identifier, contextItems, documentation, parent) 

780 DesignUnitWithContextMixin.__init__(self) 

781 

782 def __str__(self) -> str: 

783 lib = self._parent._identifier if self._parent is not None else "%" 

784 

785 return f"Configuration: {lib}.{self._identifier}" 

786 

787 def __repr__(self) -> str: 

788 lib = self._parent._identifier if self._parent is not None else "%" 

789 

790 return f"{lib}.{self._identifier}"