Coverage for pyVHDLModel/Exception.py: 69%
137 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-10 23:46 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-10 23:46 +0000
1# ==================================================================================================================== #
2# __ ___ _ ____ _ __ __ _ _ #
3# _ __ _ \ \ / / | | | _ \| | | \/ | ___ __| | ___| | #
4# | '_ \| | | \ \ / /| |_| | | | | | | |\/| |/ _ \ / _` |/ _ \ | #
5# | |_) | |_| |\ V / | _ | |_| | |___| | | | (_) | (_| | __/ | #
6# | .__/ \__, | \_/ |_| |_|____/|_____|_| |_|\___/ \__,_|\___|_| #
7# |_| |___/ #
8# ==================================================================================================================== #
9# Authors: #
10# Patrick Lehmann #
11# #
12# License: #
13# ==================================================================================================================== #
14# Copyright 2017-2024 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 sys import version_info
39from typing import List
41from pyTooling.Decorators import export, readonly
43from pyVHDLModel.Symbol import Symbol
46@export
47class VHDLModelException(Exception):
48 """Base-class for all exceptions (errors) raised by pyVHDLModel."""
50 # WORKAROUND: for Python <3.11
51 # Implementing a dummy method for Python versions before
52 __notes__: List[str]
53 if version_info < (3, 11): # pragma: no cover
54 def add_note(self, message: str) -> None:
55 try:
56 self.__notes__.append(message)
57 except AttributeError:
58 self.__notes__ = [message]
61@export
62class LibraryExistsInDesignError(VHDLModelException):
63 """
64 This exception is raised, when the library is already existing in the design.
66 Message: :pycode:`f"Library '{library._identifier}' already exists in design."`
67 """
69 _library: 'Library'
71 def __init__(self, library: 'Library') -> None:
72 """
73 Initializes the exception message based on given library object.
75 :param library: The library that already exists in the design.
76 """
77 super().__init__(f"Library '{library._identifier}' already exists in design.")
78 self._library = library
80 @readonly
81 def Library(self) -> 'Library':
82 """
83 Read-only property to access the duplicate library (:attr:`_library`).
85 :returns: Duplicate library (by name).
86 """
87 return self._library
90@export
91class LibraryRegisteredToForeignDesignError(VHDLModelException):
92 """
93 This exception is raised, when the library is already registered to a foreign design.
95 Message: :pycode:`f"Library '{library._identifier}' already registered in design '{library.Parent}'."`
96 """
98 _library: 'Library'
100 def __init__(self, library: 'Library') -> None:
101 """
102 Initializes the exception message based on given library object.
104 :param library: The library that is already registered to another design.
105 """
106 super().__init__(f"Library '{library._identifier}' already registered in design '{library.Parent}'.")
107 self._library = library
109 @readonly
110 def Library(self) -> 'Library':
111 return self._library
114@export
115class LibraryNotRegisteredError(VHDLModelException):
116 """
117 This exception is raised, when the library is not registered in the design.
119 Message: :pycode:`f"Library '{library._identifier}' is not registered in the design."`
120 """
122 _library: 'Library'
124 def __init__(self, library: 'Library') -> None:
125 """
126 Initializes the exception message based on given library object.
128 :param library: The library that isn't registered in the design.
129 """
130 super().__init__(f"Library '{library._identifier}' is not registered in the design.")
131 self._library = library
133 @readonly
134 def Library(self) -> 'Library':
135 return self._library
138@export
139class EntityExistsInLibraryError(VHDLModelException):
140 """
141 This exception is raised, when the entity already existing in the library.
143 Message: :pycode:`f"Entity '{entity._identifier}' already exists in library '{library._identifier}'."`
144 """
146 _library: 'Library'
147 _entity: 'Entity'
149 def __init__(self, entity: 'Entity', library: 'Library') -> None:
150 """
151 Initializes the exception message based on given entity and library objects.
153 :param entity: The entity that already exists in the library.
154 :param library: The library that already contains the entity.
155 """
156 super().__init__(f"Entity '{entity._identifier}' already exists in library '{library._identifier}'.")
157 self._library = library
158 self._entity = entity
160 @readonly
161 def Library(self) -> 'Library':
162 return self._library
164 @readonly
165 def Entity(self) -> 'Entity':
166 return self._entity
169@export
170class ArchitectureExistsInLibraryError(VHDLModelException):
171 """
172 This exception is raised, when the architecture already existing in the library.
174 Message: :pycode:`f"Architecture '{architecture._identifier}' for entity '{entity._identifier}' already exists in library '{library._identifier}'."`
175 """
177 _library: 'Library'
178 _entity: 'Entity'
179 _architecture: 'Architecture'
181 def __init__(self, architecture: 'Architecture', entity: 'Entity', library: 'Library') -> None:
182 """
183 Initializes the exception message based on given architecture, entity and library objects.
185 :param architecture: The architecture that already exists in the library.
186 :param entity: The entity the architecture refers to, which already exists in the library.
187 :param library: The library that already contains the architecture.
188 """
189 super().__init__(f"Architecture '{architecture._identifier}' for entity '{entity._identifier}' already exists in library '{library._identifier}'.")
190 self._library = library
191 self._entity = entity
192 self._architecture = architecture
194 @readonly
195 def Library(self) -> 'Library':
196 return self._library
198 @readonly
199 def Entity(self) -> 'Entity':
200 return self._entity
202 @readonly
203 def Architecture(self) -> 'Architecture':
204 return self._architecture
207@export
208class PackageExistsInLibraryError(VHDLModelException):
209 """
210 This exception is raised, when the package already existing in the library.
212 Message: :pycode:`f"Package '{package._identifier}' already exists in library '{library._identifier}'."`
213 """
215 _library: 'Library'
216 _package: 'Package'
218 def __init__(self, package: 'Package', library: 'Library') -> None:
219 """
220 Initializes the exception message based on given package and library objects.
222 :param package: The package that already exists in the library.
223 :param library: The library that already contains the package.
224 """
225 super().__init__(f"Package '{package._identifier}' already exists in library '{library._identifier}'.")
226 self._library = library
227 self._package = package
229 @readonly
230 def Library(self) -> 'Library':
231 return self._library
233 @readonly
234 def Package(self) -> 'Package':
235 return self._package
238@export
239class PackageBodyExistsError(VHDLModelException):
240 """
241 This exception is raised, when the package body already existing in the library.
243 Message: :pycode:`f"Package body '{packageBody._identifier}' already exists in library '{library._identifier}'."`
244 """
246 _library: 'Library'
247 _packageBody: 'PackageBody'
249 def __init__(self, packageBody: 'PackageBody', library: 'Library') -> None:
250 """
251 Initializes the exception message based on given package body and library objects.
253 :param packageBody: The package body that already exists in the library.
254 :param library: The library that already contains the package body.
255 """
256 super().__init__(f"Package body '{packageBody._identifier}' already exists in library '{library._identifier}'.")
257 self._library = library
258 self._packageBody = packageBody
260 @readonly
261 def Library(self) -> 'Library':
262 return self._library
264 @property
265 def PackageBody(self) -> 'PackageBody':
266 return self._packageBody
269@export
270class ConfigurationExistsInLibraryError(VHDLModelException):
271 """
272 This exception is raised, when the configuration already existing in the library.
274 Message: :pycode:`f"Configuration '{configuration._identifier}' already exists in library '{library._identifier}'."`
275 """
277 _library: 'Library'
278 _configuration: 'Configuration'
280 def __init__(self, configuration: 'Configuration', library: 'Library') -> None:
281 """
282 Initializes the exception message based on given configuration and library objects.
284 :param configuration: The configuration that already exists in the library.
285 :param library: The library that already contains the configuration.
286 """
287 super().__init__(f"Configuration '{configuration._identifier}' already exists in library '{library._identifier}'.")
288 self._library = library
289 self._configuration = configuration
291 @property
292 def Library(self) -> 'Library':
293 return self._library
295 @property
296 def Configuration(self) -> 'Configuration':
297 return self._configuration
300@export
301class ContextExistsInLibraryError(VHDLModelException):
302 """
303 This exception is raised, when the context already existing in the library.
305 Message: :pycode:`f"Context '{context._identifier}' already exists in library '{library._identifier}'."`
306 """
308 _library: 'Library'
309 _context: 'Context'
311 def __init__(self, context: 'Context', library: 'Library') -> None:
312 """
313 Initializes the exception message based on given context and library objects.
315 :param context: The context that already exists in the library.
316 :param library: The library that already contains the context.
317 """
318 super().__init__(f"Context '{context._identifier}' already exists in library '{library._identifier}'.")
319 self._library = library
320 self._context = context
322 @property
323 def Library(self) -> 'Library':
324 return self._library
326 @property
327 def Context(self) -> 'Context':
328 return self._context
331@export
332class ReferencedLibraryNotExistingError(VHDLModelException):
333 """
334 This exception is raised, when a library is referenced by a `library clause`, but doesn't exist in the design.
336 Message: :pycode:`f"Library '{librarySymbol.Name._identifier}' referenced by library clause of context '{context._identifier}' doesn't exist in design."`
337 """
339 _librarySymbol: Symbol
340 _context: 'Context'
342 def __init__(self, context: 'Context', librarySymbol: Symbol) -> None:
343 """
344 Initializes the exception message based on given context and library objects.
346 :param context: The context that already exists in the library.
347 :param librarySymbol: The library that already contains the context.
348 """
349 super().__init__(f"Library '{librarySymbol.Name._identifier}' referenced by library clause of context '{context._identifier}' doesn't exist in design.")
350 self._librarySymbol = librarySymbol
351 self._context = context
353 @property
354 def LibrarySymbol(self) -> Symbol:
355 return self._librarySymbol
357 @property
358 def Context(self) -> 'Context':
359 return self._context