Coverage for pyVHDLModel / DesignUnit.py: 70%

334 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-24 22:37 +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 

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: 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: 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: 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, 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 _genericItems: List[GenericInterfaceItemMixin] 

433 

434 _deferredConstants: Dict[str, DeferredConstant] 

435 _components: Dict[str, 'Component'] 

436 

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. 

449 

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) 

461 AllowBlackboxMixin.__init__(self, allowBlackbox) 

462 

463 self._packageBody = None 

464 

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 

471 

472 self._deferredConstants = {} 

473 self._components = {} 

474 

475 @property 

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

477 return self._packageBody 

478 

479 @property 

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

481 return self._genericItems 

482 

483 @property 

484 def DeclaredItems(self) -> List: 

485 return self._declaredItems 

486 

487 @property 

488 def DeferredConstants(self): 

489 return self._deferredConstants 

490 

491 @property 

492 def Components(self): 

493 return self._components 

494 

495 def _IndexOtherDeclaredItem(self, item): 

496 if isinstance(item, DeferredConstant): 

497 for normalizedIdentifier in item.NormalizedIdentifiers: 

498 self._deferredConstants[normalizedIdentifier] = item 

499 elif isinstance(item, Component): 

500 self._components[item.NormalizedIdentifier] = item 

501 else: 

502 super()._IndexOtherDeclaredItem(item) 

503 

504 def __str__(self) -> str: 

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

506 

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

508 

509 def __repr__(self) -> str: 

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

511 

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

513 

514 

515@export 

516class PackageBody(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin): 

517 """ 

518 Represents a package body declaration. 

519 

520 .. admonition:: Example 

521 

522 .. code-block:: VHDL 

523 

524 package body pkg is 

525 -- ... 

526 end package body; 

527 """ 

528 

529 _package: PackageSymbol 

530 

531 def __init__( 

532 self, 

533 packageSymbol: PackageSymbol, 

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

535 declaredItems: Nullable[Iterable] = None, 

536 documentation: Nullable[str] = None, 

537 parent: ModelEntity = None 

538 ) -> None: 

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

540 DesignUnitWithContextMixin.__init__(self) 

541 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

542 

543 self._package = packageSymbol 

544 packageSymbol._parent = self 

545 

546 @property 

547 def Package(self) -> PackageSymbol: 

548 return self._package 

549 

550 @property 

551 def DeclaredItems(self) -> List: 

552 return self._declaredItems 

553 

554 def LinkDeclaredItemsToPackage(self) -> None: 

555 pass 

556 

557 def __str__(self) -> str: 

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

559 

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

561 

562 def __repr__(self) -> str: 

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

564 

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

566 

567 

568@export 

569class Entity(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin, AllowBlackboxMixin): 

570 """ 

571 Represents an entity declaration. 

572 

573 .. admonition:: Example 

574 

575 .. code-block:: VHDL 

576 

577 entity ent is 

578 -- ... 

579 end entity; 

580 """ 

581 

582 _genericItems: List[GenericInterfaceItemMixin] 

583 _portItems: List[PortInterfaceItemMixin] 

584 

585 _architectures: Dict[str, 'Architecture'] 

586 

587 def __init__( 

588 self, 

589 identifier: str, 

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

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

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

593 declaredItems: Nullable[Iterable] = None, 

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

595 documentation: Nullable[str] = None, 

596 allowBlackbox: Nullable[bool] = None, 

597 parent: ModelEntity = None 

598 ) -> None: 

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

600 DesignUnitWithContextMixin.__init__(self) 

601 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

602 ConcurrentStatementsMixin.__init__(self, statements) 

603 AllowBlackboxMixin.__init__(self, allowBlackbox) 

604 

605 # TODO: extract to mixin 

606 self._genericItems = [] 

607 if genericItems is not None: 607 ↛ 608line 607 didn't jump to line 608 because the condition on line 607 was never true

608 for item in genericItems: 

609 self._genericItems.append(item) 

610 item._parent = self 

611 

612 # TODO: extract to mixin 

613 self._portItems = [] 

614 if portItems is not None: 614 ↛ 615line 614 didn't jump to line 615 because the condition on line 614 was never true

615 for item in portItems: 

616 self._portItems.append(item) 

617 item._parent = self 

618 

619 self._architectures = {} 

620 

621 # TODO: extract to mixin for generics 

622 @property 

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

624 return self._genericItems 

625 

626 # TODO: extract to mixin for ports 

627 @property 

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

629 return self._portItems 

630 

631 @property 

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

633 return self._architectures 

634 

635 def __str__(self) -> str: 

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

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

638 

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

640 

641 def __repr__(self) -> str: 

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

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

644 

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

646 

647 

648@export 

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

650 """ 

651 Represents an architecture declaration. 

652 

653 .. admonition:: Example 

654 

655 .. code-block:: VHDL 

656 

657 architecture rtl of ent is 

658 -- ... 

659 begin 

660 -- ... 

661 end architecture; 

662 """ 

663 

664 _entity: EntitySymbol 

665 

666 def __init__( 

667 self, 

668 identifier: str, 

669 entity: EntitySymbol, 

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

671 declaredItems: Nullable[Iterable] = None, 

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

673 documentation: Nullable[str] = None, 

674 allowBlackbox: Nullable[bool] = None, 

675 parent: ModelEntity = None 

676 ) -> None: 

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

678 DesignUnitWithContextMixin.__init__(self) 

679 ConcurrentDeclarationRegionMixin.__init__(self, declaredItems) 

680 ConcurrentStatementsMixin.__init__(self, statements) 

681 AllowBlackboxMixin.__init__(self, allowBlackbox) 

682 

683 self._entity = entity 

684 entity._parent = self 

685 

686 @property 

687 def Entity(self) -> EntitySymbol: 

688 return self._entity 

689 

690 def __str__(self) -> str: 

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

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

693 

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

695 

696 def __repr__(self) -> str: 

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

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

699 

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

701 

702 

703@export 

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

705 """ 

706 Represents a configuration declaration. 

707 

708 .. admonition:: Example 

709 

710 .. code-block:: VHDL 

711 

712 component ent is 

713 -- ... 

714 end component; 

715 """ 

716 

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

718 

719 _genericItems: List[GenericInterfaceItemMixin] 

720 _portItems: List[PortInterfaceItemMixin] 

721 

722 _entity: Nullable[Entity] 

723 

724 def __init__( 

725 self, 

726 identifier: str, 

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

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

729 documentation: Nullable[str] = None, 

730 allowBlackbox: Nullable[bool] = None, 

731 parent: ModelEntity = None 

732 ) -> None: 

733 super().__init__(parent) 

734 NamedEntityMixin.__init__(self, identifier) 

735 DocumentedEntityMixin.__init__(self, documentation) 

736 AllowBlackboxMixin.__init__(self, allowBlackbox) 

737 

738 self._isBlackBox = None 

739 self._entity = None 

740 

741 # TODO: extract to mixin 

742 self._genericItems = [] 

743 if genericItems is not None: 

744 for item in genericItems: 

745 self._genericItems.append(item) 

746 item._parent = self 

747 

748 # TODO: extract to mixin 

749 self._portItems = [] 

750 if portItems is not None: 

751 for item in portItems: 

752 self._portItems.append(item) 

753 item._parent = self 

754 

755 @property 

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

757 """ 

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

759 

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

761 

762 :returns: If this component is a blackbox. 

763 """ 

764 return self._isBlackBox 

765 

766 @property 

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

768 return self._genericItems 

769 

770 @property 

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

772 return self._portItems 

773 

774 @property 

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

776 return self._entity 

777 

778 @Entity.setter 

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

780 self._entity = value 

781 self._isBlackBox = False 

782 

783 def __str__(self) -> str: 

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

785 

786 def __repr__(self) -> str: 

787 if isinstance(self._parent, Package): 

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

789 elif isinstance(self._parent, Architecture): 

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

791 

792 

793@export 

794class Configuration(PrimaryUnit, DesignUnitWithContextMixin): 

795 """ 

796 Represents a configuration declaration. 

797 

798 .. admonition:: Example 

799 

800 .. code-block:: VHDL 

801 

802 configuration cfg of ent is 

803 for rtl 

804 -- ... 

805 end for; 

806 end configuration; 

807 """ 

808 

809 def __init__( 

810 self, 

811 identifier: str, 

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

813 documentation: Nullable[str] = None, 

814 parent: ModelEntity = None 

815 ) -> None: 

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

817 DesignUnitWithContextMixin.__init__(self) 

818 

819 def __str__(self) -> str: 

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

821 

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

823 

824 def __repr__(self) -> str: 

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

826 

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