Coverage for pyVHDLModel / Exception.py: 71%
147 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 22:17 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-21 22:17 +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.
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 pass
49@export
50class NotImplementedWarning(VHDLModelWarning):
51 pass
54@export
55class VHDLModelCriticalWarning(Warning):
56 pass
59@export
60class BlackboxWarning(VHDLModelCriticalWarning):
61 pass
64@export
65class VHDLModelException(Exception):
66 """Base-class for all exceptions (errors) raised by pyVHDLModel."""
69@export
70class LibraryExistsInDesignError(VHDLModelException):
71 """
72 This exception is raised, when the library is already existing in the design.
74 Message: :pycode:`f"Library '{library._identifier}' already exists in design."`
75 """
77 _library: 'Library'
79 def __init__(self, library: 'Library') -> None:
80 """
81 Initializes the exception message based on given library object.
83 :param library: The library that already exists in the design.
84 """
85 super().__init__(f"Library '{library._identifier}' already exists in design.")
86 self._library = library
88 @readonly
89 def Library(self) -> 'Library':
90 """
91 Read-only property to access the duplicate library (:attr:`_library`).
93 :returns: Duplicate library (by name).
94 """
95 return self._library
98@export
99class LibraryRegisteredToForeignDesignError(VHDLModelException):
100 """
101 This exception is raised, when the library is already registered to a foreign design.
103 Message: :pycode:`f"Library '{library._identifier}' already registered in design '{library.Parent}'."`
104 """
106 _library: 'Library'
108 def __init__(self, library: 'Library') -> None:
109 """
110 Initializes the exception message based on given library object.
112 :param library: The library that is already registered to another design.
113 """
114 super().__init__(f"Library '{library._identifier}' already registered in design '{library.Parent}'.")
115 self._library = library
117 @readonly
118 def Library(self) -> 'Library':
119 return self._library
122@export
123class LibraryNotRegisteredError(VHDLModelException):
124 """
125 This exception is raised, when the library is not registered in the design.
127 Message: :pycode:`f"Library '{library._identifier}' is not registered in the design."`
128 """
130 _library: 'Library'
132 def __init__(self, library: 'Library') -> None:
133 """
134 Initializes the exception message based on given library object.
136 :param library: The library that isn't registered in the design.
137 """
138 super().__init__(f"Library '{library._identifier}' is not registered in the design.")
139 self._library = library
141 @readonly
142 def Library(self) -> 'Library':
143 return self._library
146@export
147class EntityExistsInLibraryError(VHDLModelException):
148 """
149 This exception is raised, when the entity already existing in the library.
151 Message: :pycode:`f"Entity '{entity._identifier}' already exists in library '{library._identifier}'."`
152 """
154 _library: 'Library'
155 _entity: 'Entity'
157 def __init__(self, entity: 'Entity', library: 'Library') -> None:
158 """
159 Initializes the exception message based on given entity and library objects.
161 :param entity: The entity that already exists in the library.
162 :param library: The library that already contains the entity.
163 """
164 super().__init__(f"Entity '{entity._identifier}' already exists in library '{library._identifier}'.")
165 self._library = library
166 self._entity = entity
168 @readonly
169 def Library(self) -> 'Library':
170 return self._library
172 @readonly
173 def Entity(self) -> 'Entity':
174 return self._entity
177@export
178class ArchitectureExistsInLibraryError(VHDLModelException):
179 """
180 This exception is raised, when the architecture already existing in the library.
182 Message: :pycode:`f"Architecture '{architecture._identifier}' for entity '{entity._identifier}' already exists in library '{library._identifier}'."`
183 """
185 _library: 'Library'
186 _entity: 'Entity'
187 _architecture: 'Architecture'
189 def __init__(self, architecture: 'Architecture', entity: 'Entity', library: 'Library') -> None:
190 """
191 Initializes the exception message based on given architecture, entity and library objects.
193 :param architecture: The architecture that already exists in the library.
194 :param entity: The entity the architecture refers to, which already exists in the library.
195 :param library: The library that already contains the architecture.
196 """
197 super().__init__(f"Architecture '{architecture._identifier}' for entity '{entity._identifier}' already exists in library '{library._identifier}'.")
198 self._library = library
199 self._entity = entity
200 self._architecture = architecture
202 @readonly
203 def Library(self) -> 'Library':
204 return self._library
206 @readonly
207 def Entity(self) -> 'Entity':
208 return self._entity
210 @readonly
211 def Architecture(self) -> 'Architecture':
212 return self._architecture
215@export
216class PackageExistsInLibraryError(VHDLModelException):
217 """
218 This exception is raised, when the package already existing in the library.
220 Message: :pycode:`f"Package '{package._identifier}' already exists in library '{library._identifier}'."`
221 """
223 _library: 'Library'
224 _package: 'Package'
226 def __init__(self, package: 'Package', library: 'Library') -> None:
227 """
228 Initializes the exception message based on given package and library objects.
230 :param package: The package that already exists in the library.
231 :param library: The library that already contains the package.
232 """
233 super().__init__(f"Package '{package._identifier}' already exists in library '{library._identifier}'.")
234 self._library = library
235 self._package = package
237 @readonly
238 def Library(self) -> 'Library':
239 return self._library
241 @readonly
242 def Package(self) -> 'Package':
243 return self._package
246@export
247class PackageBodyExistsError(VHDLModelException):
248 """
249 This exception is raised, when the package body already existing in the library.
251 Message: :pycode:`f"Package body '{packageBody._identifier}' already exists in library '{library._identifier}'."`
252 """
254 _library: 'Library'
255 _packageBody: 'PackageBody'
257 def __init__(self, packageBody: 'PackageBody', library: 'Library') -> None:
258 """
259 Initializes the exception message based on given package body and library objects.
261 :param packageBody: The package body that already exists in the library.
262 :param library: The library that already contains the package body.
263 """
264 super().__init__(f"Package body '{packageBody._identifier}' already exists in library '{library._identifier}'.")
265 self._library = library
266 self._packageBody = packageBody
268 @readonly
269 def Library(self) -> 'Library':
270 return self._library
272 @property
273 def PackageBody(self) -> 'PackageBody':
274 return self._packageBody
277@export
278class ConfigurationExistsInLibraryError(VHDLModelException):
279 """
280 This exception is raised, when the configuration already existing in the library.
282 Message: :pycode:`f"Configuration '{configuration._identifier}' already exists in library '{library._identifier}'."`
283 """
285 _library: 'Library'
286 _configuration: 'Configuration'
288 def __init__(self, configuration: 'Configuration', library: 'Library') -> None:
289 """
290 Initializes the exception message based on given configuration and library objects.
292 :param configuration: The configuration that already exists in the library.
293 :param library: The library that already contains the configuration.
294 """
295 super().__init__(f"Configuration '{configuration._identifier}' already exists in library '{library._identifier}'.")
296 self._library = library
297 self._configuration = configuration
299 @property
300 def Library(self) -> 'Library':
301 return self._library
303 @property
304 def Configuration(self) -> 'Configuration':
305 return self._configuration
308@export
309class ContextExistsInLibraryError(VHDLModelException):
310 """
311 This exception is raised, when the context already existing in the library.
313 Message: :pycode:`f"Context '{context._identifier}' already exists in library '{library._identifier}'."`
314 """
316 _library: 'Library'
317 _context: 'Context'
319 def __init__(self, context: 'Context', library: 'Library') -> None:
320 """
321 Initializes the exception message based on given context and library objects.
323 :param context: The context that already exists in the library.
324 :param library: The library that already contains the context.
325 """
326 super().__init__(f"Context '{context._identifier}' already exists in library '{library._identifier}'.")
327 self._library = library
328 self._context = context
330 @property
331 def Library(self) -> 'Library':
332 return self._library
334 @property
335 def Context(self) -> 'Context':
336 return self._context
339@export
340class ReferencedLibraryNotExistingError(VHDLModelException):
341 """
342 This exception is raised, when a library is referenced by a `library clause`, but doesn't exist in the design.
344 Message: :pycode:`f"Library '{librarySymbol.Name._identifier}' referenced by library clause of context '{context._identifier}' doesn't exist in design."`
345 """
347 _librarySymbol: Symbol
348 _context: 'Context'
350 def __init__(self, context: 'Context', librarySymbol: Symbol) -> None:
351 """
352 Initializes the exception message based on given context and library objects.
354 :param context: The context that already exists in the library.
355 :param librarySymbol: The library that already contains the context.
356 """
357 super().__init__(f"Library '{librarySymbol.Name._identifier}' referenced by library clause of context '{context._identifier}' doesn't exist in design.")
358 self._librarySymbol = librarySymbol
359 self._context = context
361 @property
362 def LibrarySymbol(self) -> Symbol:
363 return self._librarySymbol
365 @property
366 def Context(self) -> 'Context':
367 return self._context