Coverage for pyVHDLModel/Exception.py: 68%
132 statements
« prev ^ index » next coverage.py v7.16.0, created at 2026-08-29 03:29 +0000
« prev ^ index » next coverage.py v7.16.0, created at 2026-08-29 03:29 +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.
35The module ``Exceptions`` contains all structured errors that are raised by pyVHDLModel. Besides a default error
36message in english, each exception object contains one or multiple references to the exception's context.
37"""
38from pyTooling.Decorators import export, readonly
39from pyTooling.Warning import Warning, CriticalWarning
41from pyVHDLModel.Symbol import Symbol
44@export
45class VHDLModelWarning(Warning):
46 """
47 Base-class for all warnings raised by pyVHDLModel.
49 .. seealso::
51 * :class:`Not implemented warning <pyVHDLModel.Exception.NotImplementedWarning>`
52 """
53 pass
56@export
57class NotImplementedWarning(VHDLModelWarning):
58 """
59 Raised when a language construct is recognised but not yet modelled.
60 """
61 pass
64@export
65class VHDLModelCriticalWarning(Warning):
66 """
67 Base-class for critical warnings that likely indicate a defect in the model or its input.
69 .. seealso::
71 * :class:`Blackbox warning <pyVHDLModel.Exception.BlackboxWarning>`
72 """
73 pass
76@export
77class DuplicateDeclarationWarning(VHDLModelCriticalWarning):
78 """
79 Raised when two declarations in one declarative region share an identifier.
81 VHDL rejects this as *identifier already used for a declaration*. Overloadable declarations -
82 subprograms differing in signature - are not reported.
83 """
84 pass
87@export
88class BlackboxWarning(VHDLModelCriticalWarning):
89 """
90 Raised when a component could not be bound and is treated as a blackbox.
91 """
92 pass
95@export
96class VHDLModelException(Exception):
97 """
98 Base-class for all exceptions (errors) raised by pyVHDLModel.
100 .. seealso::
102 * :class:`Library exists in design error <pyVHDLModel.Exception.LibraryExistsInDesignError>`
103 * :class:`Registered to foreign design error <pyVHDLModel.Exception.LibraryRegisteredToForeignDesignError>`
104 * :class:`Library not registered error <pyVHDLModel.Exception.LibraryNotRegisteredError>`
105 * :class:`Entity exists in library error <pyVHDLModel.Exception.EntityExistsInLibraryError>`
106 * :class:`Architecture exists in library error <pyVHDLModel.Exception.ArchitectureExistsInLibraryError>`
107 * :class:`Package exists in library error <pyVHDLModel.Exception.PackageExistsInLibraryError>`
108 * :class:`Package body exists error <pyVHDLModel.Exception.PackageBodyExistsError>`
109 * :class:`Configuration exists in library error <pyVHDLModel.Exception.ConfigurationExistsInLibraryError>`
110 * :class:`Context exists in library error <pyVHDLModel.Exception.ContextExistsInLibraryError>`
111 * :class:`Referenced library not existing error <pyVHDLModel.Exception.ReferencedLibraryNotExistingError>`
112 """
115@export
116class LibraryExistsInDesignError(VHDLModelException):
117 """
118 This exception is raised, when the library is already existing in the design.
120 Message: :pycode:`f"Library '{library._identifier}' already exists in design."`
121 """
123 _library: 'Library' #: The library involved in this error.
125 def __init__(self, library: 'Library') -> None:
126 """
127 Initializes the exception message based on given library object.
129 :param library: The library that already exists in the design.
130 """
131 super().__init__(f"Library '{library._identifier}' already exists in design.")
132 self._library = library
134 @readonly
135 def Library(self) -> 'Library':
136 """
137 Read-only property to access the duplicate library (:attr:`_library`).
139 :returns: Duplicate library (by name).
140 """
141 return self._library
144@export
145class LibraryRegisteredToForeignDesignError(VHDLModelException):
146 """
147 This exception is raised, when the library is already registered to a foreign design.
149 Message: :pycode:`f"Library '{library._identifier}' already registered in design '{library.Parent}'."`
150 """
152 _library: 'Library' #: The library involved in this error.
154 def __init__(self, library: 'Library') -> None:
155 """
156 Initializes the exception message based on given library object.
158 :param library: The library that is already registered to another design.
159 """
160 super().__init__(f"Library '{library._identifier}' already registered in design '{library.Parent}'.")
161 self._library = library
163 @readonly
164 def Library(self) -> 'Library':
165 """
166 Read-only property to access the library (:attr:`_library`).
168 :returns: The library.
169 """
170 return self._library
173@export
174class LibraryNotRegisteredError(VHDLModelException):
175 """
176 This exception is raised, when the library is not registered in the design.
178 Message: :pycode:`f"Library '{library._identifier}' is not registered in the design."`
179 """
181 _library: 'Library' #: The library involved in this error.
183 def __init__(self, library: 'Library') -> None:
184 """
185 Initializes the exception message based on given library object.
187 :param library: The library that isn't registered in the design.
188 """
189 super().__init__(f"Library '{library._identifier}' is not registered in the design.")
190 self._library = library
192 @readonly
193 def Library(self) -> 'Library':
194 """
195 Read-only property to access the library (:attr:`_library`).
197 :returns: The library.
198 """
199 return self._library
202@export
203class EntityExistsInLibraryError(VHDLModelException):
204 """
205 This exception is raised, when the entity already existing in the library.
207 Message: :pycode:`f"Entity '{entity._identifier}' already exists in library '{library._identifier}'."`
208 """
210 _library: 'Library' #: The library involved in this error.
211 _entity: 'Entity' #: The entity involved in this error.
213 def __init__(self, entity: 'Entity', library: 'Library') -> None:
214 """
215 Initializes the exception message based on given entity and library objects.
217 :param entity: The entity that already exists in the library.
218 :param library: The library that already contains the entity.
219 """
220 super().__init__(f"Entity '{entity._identifier}' already exists in library '{library._identifier}'.")
221 self._library = library
222 self._entity = entity
224 @readonly
225 def Library(self) -> 'Library':
226 """
227 Read-only property to access the library (:attr:`_library`).
229 :returns: The library.
230 """
231 return self._library
233 @readonly
234 def Entity(self) -> 'Entity':
235 """
236 Read-only property to access the entity (:attr:`_entity`).
238 :returns: The entity.
239 """
240 return self._entity
243@export
244class ArchitectureExistsInLibraryError(VHDLModelException):
245 """
246 This exception is raised, when the architecture already existing in the library.
248 Message: :pycode:`f"Architecture '{architecture._identifier}' for entity '{entity._identifier}' already exists in library '{library._identifier}'."`
249 """
251 _library: 'Library' #: The library involved in this error.
252 _entity: 'Entity' #: The entity involved in this error.
253 _architecture: 'Architecture' #: The architecture involved in this error.
255 def __init__(self, architecture: 'Architecture', entity: 'Entity', library: 'Library') -> None:
256 """
257 Initializes the exception message based on given architecture, entity and library objects.
259 :param architecture: The architecture that already exists in the library.
260 :param entity: The entity the architecture refers to, which already exists in the library.
261 :param library: The library that already contains the architecture.
262 """
263 super().__init__(f"Architecture '{architecture._identifier}' for entity '{entity._identifier}' already exists in library '{library._identifier}'.")
264 self._library = library
265 self._entity = entity
266 self._architecture = architecture
268 @readonly
269 def Library(self) -> 'Library':
270 """
271 Read-only property to access the library (:attr:`_library`).
273 :returns: The library.
274 """
275 return self._library
277 @readonly
278 def Entity(self) -> 'Entity':
279 """
280 Read-only property to access the entity (:attr:`_entity`).
282 :returns: The entity.
283 """
284 return self._entity
286 @readonly
287 def Architecture(self) -> 'Architecture':
288 """
289 Read-only property to access the architecture (:attr:`_architecture`).
291 :returns: The architecture.
292 """
293 return self._architecture
296@export
297class PackageExistsInLibraryError(VHDLModelException):
298 """
299 This exception is raised, when the package already existing in the library.
301 Message: :pycode:`f"Package '{package._identifier}' already exists in library '{library._identifier}'."`
302 """
304 _library: 'Library' #: The library involved in this error.
305 _package: 'Package' #: The package involved in this error.
307 def __init__(self, package: 'Package', library: 'Library') -> None:
308 """
309 Initializes the exception message based on given package and library objects.
311 :param package: The package that already exists in the library.
312 :param library: The library that already contains the package.
313 """
314 super().__init__(f"Package '{package._identifier}' already exists in library '{library._identifier}'.")
315 self._library = library
316 self._package = package
318 @readonly
319 def Library(self) -> 'Library':
320 """
321 Read-only property to access the library (:attr:`_library`).
323 :returns: The library.
324 """
325 return self._library
327 @readonly
328 def Package(self) -> 'Package':
329 """
330 Read-only property to access the package (:attr:`_package`).
332 :returns: The package.
333 """
334 return self._package
337@export
338class PackageBodyExistsError(VHDLModelException):
339 """
340 This exception is raised, when the package body already existing in the library.
342 Message: :pycode:`f"Package body '{packageBody._identifier}' already exists in library '{library._identifier}'."`
343 """
345 _library: 'Library' #: The library involved in this error.
346 _packageBody: 'PackageBody' #: The package body involved in this error.
348 def __init__(self, packageBody: 'PackageBody', library: 'Library') -> None:
349 """
350 Initializes the exception message based on given package body and library objects.
352 :param packageBody: The package body that already exists in the library.
353 :param library: The library that already contains the package body.
354 """
355 super().__init__(f"Package body '{packageBody._identifier}' already exists in library '{library._identifier}'.")
356 self._library = library
357 self._packageBody = packageBody
359 @readonly
360 def Library(self) -> 'Library':
361 """
362 Read-only property to access the library (:attr:`_library`).
364 :returns: The library.
365 """
366 return self._library
368 @readonly
369 def PackageBody(self) -> 'PackageBody':
370 """
371 Read-only property to access the package body (:attr:`_packageBody`).
373 :returns: The package body.
374 """
375 return self._packageBody
378@export
379class ConfigurationExistsInLibraryError(VHDLModelException):
380 """
381 This exception is raised, when the configuration already existing in the library.
383 Message: :pycode:`f"Configuration '{configuration._identifier}' already exists in library '{library._identifier}'."`
384 """
386 _library: 'Library' #: The library involved in this error.
387 _configuration: 'Configuration' #: The configuration involved in this error.
389 def __init__(self, configuration: 'Configuration', library: 'Library') -> None:
390 """
391 Initializes the exception message based on given configuration and library objects.
393 :param configuration: The configuration that already exists in the library.
394 :param library: The library that already contains the configuration.
395 """
396 super().__init__(f"Configuration '{configuration._identifier}' already exists in library '{library._identifier}'.")
397 self._library = library
398 self._configuration = configuration
400 @readonly
401 def Library(self) -> 'Library':
402 """
403 Read-only property to access the library (:attr:`_library`).
405 :returns: The library.
406 """
407 return self._library
409 @readonly
410 def Configuration(self) -> 'Configuration':
411 """
412 Read-only property to access the configuration (:attr:`_configuration`).
414 :returns: The configuration.
415 """
416 return self._configuration
419@export
420class ContextExistsInLibraryError(VHDLModelException):
421 """
422 This exception is raised, when the context already existing in the library.
424 Message: :pycode:`f"Context '{context._identifier}' already exists in library '{library._identifier}'."`
425 """
427 _library: 'Library' #: The library involved in this error.
428 _context: 'Context' #: The context involved in this error.
430 def __init__(self, context: 'Context', library: 'Library') -> None:
431 """
432 Initializes the exception message based on given context and library objects.
434 :param context: The context that already exists in the library.
435 :param library: The library that already contains the context.
436 """
437 super().__init__(f"Context '{context._identifier}' already exists in library '{library._identifier}'.")
438 self._library = library
439 self._context = context
441 @readonly
442 def Library(self) -> 'Library':
443 """
444 Read-only property to access the library (:attr:`_library`).
446 :returns: The library.
447 """
448 return self._library
450 @readonly
451 def Context(self) -> 'Context':
452 """
453 Read-only property to access the context (:attr:`_context`).
455 :returns: The context.
456 """
457 return self._context
460@export
461class ReferencedLibraryNotExistingError(VHDLModelException):
462 """
463 This exception is raised, when a library is referenced by a `library clause`, but doesn't exist in the design.
465 Message: :pycode:`f"Library '{librarySymbol.Name._identifier}' referenced by library clause of context '{context._identifier}' doesn't exist in design."`
466 """
468 _librarySymbol: Symbol #: The library symbol that could not be resolved.
469 _context: 'Context' #: The context involved in this error.
471 def __init__(self, context: 'Context', librarySymbol: Symbol) -> None:
472 """
473 Initializes the exception message based on given context and library objects.
475 :param context: The context that already exists in the library.
476 :param librarySymbol: The library that already contains the context.
477 """
478 super().__init__(f"Library '{librarySymbol.Name._identifier}' referenced by library clause of context '{context._identifier}' doesn't exist in design.")
479 self._librarySymbol = librarySymbol
480 self._context = context
482 @readonly
483 def LibrarySymbol(self) -> Symbol:
484 """
485 Read-only property to access the library symbol (:attr:`_librarySymbol`).
487 :returns: The library symbol.
488 """
489 return self._librarySymbol
491 @readonly
492 def Context(self) -> 'Context':
493 """
494 Read-only property to access the context (:attr:`_context`).
496 :returns: The context.
497 """
498 return self._context