Coverage for pyVHDLModel/DesignUnit.py: 70%

362 statements  

« 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. 

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.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 

51 

52 

53@export 

54class Reference(ModelEntity): 

55 """ 

56 A base-class for all references. 

57 

58 .. seealso:: 

59 

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

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

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

63 """ 

64 

65 _symbols: List[Symbol] 

66 

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. 

70 

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) 

75 

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

77 

78 @readonly 

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

80 """ 

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

82 

83 :returns: A list of symbols. 

84 """ 

85 return self._symbols 

86 

87 

88@export 

89class LibraryClause(Reference): 

90 """ 

91 Represents a library clause. 

92 

93 .. admonition:: Example 

94 

95 .. code-block:: VHDL 

96 

97 library std, ieee; 

98 """ 

99 

100 @readonly 

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

102 """ 

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

104 

105 :returns: A list of library reference symbols. 

106 """ 

107 return self._symbols 

108 

109 

110@export 

111class UseClause(Reference): 

112 """ 

113 Represents a use clause. 

114 

115 .. admonition:: Example 

116 

117 .. code-block:: VHDL 

118 

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

120 """ 

121 

122 

123@export 

124class ContextReference(Reference): 

125 """ 

126 Represents a context reference. 

127 

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

129 

130 .. admonition:: Example 

131 

132 .. code-block:: VHDL 

133 

134 context ieee.ieee_std_context; 

135 """ 

136 

137 

138ContextUnion = Union[ 

139 LibraryClause, 

140 UseClause, 

141 ContextReference 

142] 

143 

144 

145@export 

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

147 """ 

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

149 """ 

150 

151 

152@export 

153class DesignUnit(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

154 """ 

155 A base-class for all design units. 

156 

157 .. seealso:: 

158 

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

160 

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

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

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

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

165 

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

167 

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

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

170 """ 

171 

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

173 

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. 

179 

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 

183 

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 

186 

187 _namespace: 'Namespace' 

188 

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. 

192 

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) 

201 

202 self._document = None 

203 

204 self._contextItems = [] 

205 self._libraryReferences = [] 

206 self._packageReferences = [] 

207 self._contextReferences = [] 

208 

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) 

218 

219 self._referencedLibraries = {} 

220 self._referencedPackages = {} 

221 self._referencedContexts = {} 

222 

223 self._dependencyVertex = None 

224 self._hierarchyVertex = None 

225 

226 self._namespace = Namespace(self._normalizedIdentifier) 

227 

228 @readonly 

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

230 return self._document 

231 

232 @Document.setter 

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

234 self._document = document 

235 

236 @property 

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

238 return self._parent 

239 

240 @Library.setter 

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

242 self._parent = library 

243 

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`). 

249 

250 :returns: Sequence of context items. 

251 """ 

252 return self._contextItems 

253 

254 @property 

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

256 """ 

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

258 

259 :returns: Sequence of context clauses. 

260 """ 

261 return self._contextReferences 

262 

263 @property 

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

265 """ 

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

267 

268 :returns: Sequence of library clauses. 

269 """ 

270 return self._libraryReferences 

271 

272 @property 

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

274 """ 

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

276 

277 :returns: Sequence of use clauses. 

278 """ 

279 return self._packageReferences 

280 

281 @property 

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

283 return self._referencedLibraries 

284 

285 @property 

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

287 return self._referencedPackages 

288 

289 @property 

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

291 return self._referencedContexts 

292 

293 @property 

294 def DependencyVertex(self) -> Vertex: 

295 """ 

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

297 

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

299 

300 :returns: The corresponding dependency vertex. 

301 """ 

302 return self._dependencyVertex 

303 

304 @property 

305 def HierarchyVertex(self) -> Vertex: 

306 """ 

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

308 

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

310 

311 :returns: The corresponding hierarchy vertex. 

312 """ 

313 return self._hierarchyVertex 

314 

315 

316@export 

317class PrimaryUnit(DesignUnit): 

318 """ 

319 A base-class for all primary design units. 

320 

321 .. seealso:: 

322 

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

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

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

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

327 """ 

328 

329 

330@export 

331class SecondaryUnit(DesignUnit): 

332 """ 

333 A base-class for all secondary design units. 

334 

335 .. seealso:: 

336 

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

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

339 """ 

340 

341 

342@export 

343class Context(PrimaryUnit): 

344 """ 

345 Represents a context declaration. 

346 

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

348 :data:`_references`. 

349 

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

351 

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

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

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

355 

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

357 

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

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

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

361 

362 are populated. 

363 

364 .. admonition:: Example 

365 

366 .. code-block:: VHDL 

367 

368 context ctx is 

369 -- ... 

370 end context; 

371 """ 

372 

373 _references: List[ContextUnion] 

374 

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) 

377 

378 self._references = [] 

379 self._libraryReferences = [] 

380 self._packageReferences = [] 

381 self._contextReferences = [] 

382 

383 if references is not None: 

384 for reference in references: 

385 self._references.append(reference) 

386 reference._parent = self 

387 

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 

396 

397 @property 

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

399 return self._libraryReferences 

400 

401 @property 

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

403 return self._packageReferences 

404 

405 @property 

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

407 return self._contextReferences 

408 

409 def __str__(self) -> str: 

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

411 

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

413 

414 

415@export 

416class Package(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin): 

417 """ 

418 Represents a package declaration. 

419 

420 .. admonition:: Example 

421 

422 .. code-block:: VHDL 

423 

424 package pkg is 

425 -- ... 

426 end package; 

427 """ 

428 

429 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in this package. 

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 

462 self._allowBlackbox = allowBlackbox 

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 AllowBlackbox(self) -> bool: 

477 """ 

478 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`). 

479 

480 :returns: If blackboxes are allowed. 

481 """ 

482 if self._allowBlackbox is None: 

483 return self._parent.AllowBlackbox 

484 else: 

485 return self._allowBlackbox 

486 

487 @AllowBlackbox.setter 

488 def AllowBlackbox(self, value: Nullable[bool]) -> None: 

489 self._allowBlackbox = value 

490 

491 @property 

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

493 return self._packageBody 

494 

495 @property 

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

497 return self._genericItems 

498 

499 @property 

500 def DeclaredItems(self) -> List: 

501 return self._declaredItems 

502 

503 @property 

504 def DeferredConstants(self): 

505 return self._deferredConstants 

506 

507 @property 

508 def Components(self): 

509 return self._components 

510 

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) 

519 

520 def __str__(self) -> str: 

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

522 

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

524 

525 def __repr__(self) -> str: 

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

527 

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

529 

530 

531@export 

532class PackageBody(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin): 

533 """ 

534 Represents a package body declaration. 

535 

536 .. admonition:: Example 

537 

538 .. code-block:: VHDL 

539 

540 package body pkg is 

541 -- ... 

542 end package body; 

543 """ 

544 

545 _package: PackageSymbol 

546 

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) 

558 

559 self._package = packageSymbol 

560 packageSymbol._parent = self 

561 

562 @property 

563 def Package(self) -> PackageSymbol: 

564 return self._package 

565 

566 @property 

567 def DeclaredItems(self) -> List: 

568 return self._declaredItems 

569 

570 def LinkDeclaredItemsToPackage(self) -> None: 

571 pass 

572 

573 def __str__(self) -> str: 

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

575 

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

577 

578 def __repr__(self) -> str: 

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

580 

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

582 

583 

584@export 

585class Entity(PrimaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin): 

586 """ 

587 Represents an entity declaration. 

588 

589 .. admonition:: Example 

590 

591 .. code-block:: VHDL 

592 

593 entity ent is 

594 -- ... 

595 end entity; 

596 """ 

597 

598 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in this package. 

599 

600 _genericItems: List[GenericInterfaceItemMixin] 

601 _portItems: List[PortInterfaceItemMixin] 

602 

603 _architectures: Dict[str, 'Architecture'] 

604 

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) 

621 

622 self._allowBlackbox = allowBlackbox 

623 

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 

630 

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 

637 

638 self._architectures = {} 

639 

640 @property 

641 def AllowBlackbox(self) -> bool: 

642 """ 

643 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`). 

644 

645 :returns: If blackboxes are allowed. 

646 """ 

647 if self._allowBlackbox is None: 

648 return self._parent.AllowBlackbox 

649 else: 

650 return self._allowBlackbox 

651 

652 @AllowBlackbox.setter 

653 def AllowBlackbox(self, value: Nullable[bool]) -> None: 

654 self._allowBlackbox = value 

655 

656 # TODO: extract to mixin for generics 

657 @property 

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

659 return self._genericItems 

660 

661 # TODO: extract to mixin for ports 

662 @property 

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

664 return self._portItems 

665 

666 @property 

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

668 return self._architectures 

669 

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 "%" 

673 

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

675 

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 "%" 

679 

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

681 

682 

683@export 

684class Architecture(SecondaryUnit, DesignUnitWithContextMixin, ConcurrentDeclarationRegionMixin, ConcurrentStatementsMixin): 

685 """ 

686 Represents an architecture declaration. 

687 

688 .. admonition:: Example 

689 

690 .. code-block:: VHDL 

691 

692 architecture rtl of ent is 

693 -- ... 

694 begin 

695 -- ... 

696 end architecture; 

697 """ 

698 

699 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in this package. 

700 _entity: EntitySymbol 

701 

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) 

717 

718 self._allowBlackbox = allowBlackbox 

719 

720 self._entity = entity 

721 entity._parent = self 

722 

723 @property 

724 def Entity(self) -> EntitySymbol: 

725 return self._entity 

726 

727 @property 

728 def AllowBlackbox(self) -> bool: 

729 """ 

730 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`). 

731 

732 :returns: If blackboxes are allowed. 

733 """ 

734 if self._allowBlackbox is None: 

735 return self._parent.AllowBlackbox 

736 else: 

737 return self._allowBlackbox 

738 

739 @AllowBlackbox.setter 

740 def AllowBlackbox(self, value: Nullable[bool]) -> None: 

741 self._allowBlackbox = value 

742 

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 "%" 

746 

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

748 

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 "%" 

752 

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

754 

755 

756@export 

757class Component(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

758 """ 

759 Represents a configuration declaration. 

760 

761 .. admonition:: Example 

762 

763 .. code-block:: VHDL 

764 

765 component ent is 

766 -- ... 

767 end component; 

768 """ 

769 

770 _allowBlackbox: Nullable[bool] #: Allow component to be a blackbox. 

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

772 

773 _genericItems: List[GenericInterfaceItemMixin] 

774 _portItems: List[PortInterfaceItemMixin] 

775 

776 _entity: Nullable[Entity] 

777 

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) 

790 

791 self._allowBlackbox = allowBlackbox 

792 self._isBlackBox = None 

793 self._entity = None 

794 

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 

801 

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 

808 

809 @property 

810 def AllowBlackbox(self) -> bool: 

811 """ 

812 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`). 

813 

814 :returns: If blackboxes are allowed. 

815 """ 

816 if self._allowBlackbox is None: 

817 return self._parent.AllowBlackbox 

818 else: 

819 return self._allowBlackbox 

820 

821 @AllowBlackbox.setter 

822 def AllowBlackbox(self, value: Nullable[bool]) -> None: 

823 self._allowBlackbox = value 

824 

825 @property 

826 def IsBlackbox(self) -> bool: 

827 """ 

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

829 

830 :returns: If this component is a blackbox. 

831 """ 

832 return self._isBlackBox 

833 

834 @property 

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

836 return self._genericItems 

837 

838 @property 

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

840 return self._portItems 

841 

842 @property 

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

844 return self._entity 

845 

846 @Entity.setter 

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

848 self._entity = value 

849 self._isBlackBox = False 

850 

851 

852@export 

853class Configuration(PrimaryUnit, DesignUnitWithContextMixin): 

854 """ 

855 Represents a configuration declaration. 

856 

857 .. admonition:: Example 

858 

859 .. code-block:: VHDL 

860 

861 configuration cfg of ent is 

862 for rtl 

863 -- ... 

864 end for; 

865 end configuration; 

866 """ 

867 

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) 

877 

878 def __str__(self) -> str: 

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

880 

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

882 

883 def __repr__(self) -> str: 

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

885 

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