pyVHDLModel.Exception

pyVHDLModel/Exception.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# ==================================================================================================================== #
#             __     ___   _ ____  _     __  __           _      _                                                     #
#   _ __  _   \ \   / / | | |  _ \| |   |  \/  | ___   __| | ___| |                                                    #
#  | '_ \| | | \ \ / /| |_| | | | | |   | |\/| |/ _ \ / _` |/ _ \ |                                                    #
#  | |_) | |_| |\ V / |  _  | |_| | |___| |  | | (_) | (_| |  __/ |                                                    #
#  | .__/ \__, | \_/  |_| |_|____/|_____|_|  |_|\___/ \__,_|\___|_|                                                    #
#  |_|    |___/                                                                                                        #
# ==================================================================================================================== #
# Authors:                                                                                                             #
#   Patrick Lehmann                                                                                                    #
#                                                                                                                      #
# License:                                                                                                             #
# ==================================================================================================================== #
# Copyright 2017-2023 Patrick Lehmann - Boetzingen, Germany                                                            #
# Copyright 2016-2017 Patrick Lehmann - Dresden, Germany                                                               #
#                                                                                                                      #
# Licensed under the Apache License, Version 2.0 (the "License");                                                      #
# you may not use this file except in compliance with the License.                                                     #
# You may obtain a copy of the License at                                                                              #
#                                                                                                                      #
#   http://www.apache.org/licenses/LICENSE-2.0                                                                         #
#                                                                                                                      #
# Unless required by applicable law or agreed to in writing, software                                                  #
# distributed under the License is distributed on an "AS IS" BASIS,                                                    #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                                             #
# See the License for the specific language governing permissions and                                                  #
# limitations under the License.                                                                                       #
#                                                                                                                      #
# SPDX-License-Identifier: Apache-2.0                                                                                  #
# ==================================================================================================================== #
#
"""
This module contains parts of an abstract document language model for VHDL.

The module ``Exceptions`` contains all structured errors that are raised by pyVHDLModel. Besides a default error
message in english, each exception object contains one or multiple references to the exception's context.
"""
from sys    import version_info
from typing import List

from pyTooling.Decorators import export

from pyVHDLModel.Symbol import Symbol


@export
class VHDLModelException(Exception):
	"""Base-class for all exceptions (errors) raised by pyVHDLModel."""

	# WORKAROUND: for Python <3.11
	# Implementing a dummy method for Python versions before
	__notes__: List[str]
	if version_info < (3, 11):  # pragma: no cover
		def add_note(self, message: str):
			try:
				self.__notes__.append(message)
			except AttributeError:
				self.__notes__ = [message]


@export
class LibraryExistsInDesignError(VHDLModelException):
	"""
	This exception is raised, when the library is already existing in the design.

	Message: :pycode:`f"Library '{library.Identifier}' already exists in design."`
	"""

	_library: 'Library'

	def __init__(self, library: 'Library'):
		"""
		Initializes the exception message based on given library object.

		:param library: The library that already exists in the design.
		"""
		super().__init__(f"Library '{library.Identifier}' already exists in design.")
		self._library = library

	@property
	def Library(self) -> 'Library':
		return self._library


@export
class LibraryRegisteredToForeignDesignError(VHDLModelException):
	"""
	This exception is raised, when the library is already registered to a foreign design.

	Message: :pycode:`f"Library '{library.Identifier}' already registered in design '{library.Parent}'."`
	"""

	_library: 'Library'

	def __init__(self, library: 'Library'):
		"""
		Initializes the exception message based on given library object.

		:param library: The library that is already registered to another design.
		"""
		super().__init__(f"Library '{library.Identifier}' already registered in design '{library.Parent}'.")
		self._library = library

	@property
	def Library(self) -> 'Library':
		return self._library


@export
class LibraryNotRegisteredError(VHDLModelException):
	"""
	This exception is raised, when the library is not registered in the design.

	Message: :pycode:`f"Library '{library.Identifier}' is not registered in the design."`
	"""

	_library: 'Library'

	def __init__(self, library: 'Library'):
		"""
		Initializes the exception message based on given library object.

		:param library: The library that isn't registered in the design.
		"""
		super().__init__(f"Library '{library.Identifier}' is not registered in the design.")
		self._library = library

	@property
	def Library(self) -> 'Library':
		return self._library


@export
class EntityExistsInLibraryError(VHDLModelException):
	"""
	This exception is raised, when the entity already existing in the library.

	Message: :pycode:`f"Entity '{entity.Identifier}' already exists in library '{library.Identifier}'."`
	"""

	_library: 'Library'
	_entity: 'Entity'

	def __init__(self, entity: 'Entity', library: 'Library'):
		"""
		Initializes the exception message based on given entity and library objects.

		:param entity:  The entity that already exists in the library.
		:param library: The library that already contains the entity.
		"""
		super().__init__(f"Entity '{entity.Identifier}' already exists in library '{library.Identifier}'.")
		self._library = library
		self._entity = entity

	@property
	def Library(self) -> 'Library':
		return self._library

	@property
	def Entity(self) -> 'Entity':
		return self._entity


@export
class ArchitectureExistsInLibraryError(VHDLModelException):
	"""
	This exception is raised, when the architecture already existing in the library.

	Message: :pycode:`f"Architecture '{architecture.Identifier}' for entity '{entity.Identifier}' already exists in library '{library.Identifier}'."`
	"""

	_library: 'Library'
	_entity: 'Entity'
	_architecture: 'Architecture'

	def __init__(self, architecture: 'Architecture', entity: 'Entity', library: 'Library'):
		"""
		Initializes the exception message based on given architecture, entity and library objects.

		:param architecture: The architecture that already exists in the library.
		:param entity:       The entity the architecture refers to, which already exists in the library.
		:param library:      The library that already contains the architecture.
		"""
		super().__init__(f"Architecture '{architecture.Identifier}' for entity '{entity.Identifier}' already exists in library '{library.Identifier}'.")
		self._library = library
		self._entity = entity
		self._architecture = architecture

	@property
	def Library(self) -> 'Library':
		return self._library

	@property
	def Entity(self) -> 'Entity':
		return self._entity

	@property
	def Architecture(self) -> 'Architecture':
		return self._architecture


@export
class PackageExistsInLibraryError(VHDLModelException):
	"""
	This exception is raised, when the package already existing in the library.

	Message: :pycode:`f"Package '{package.Identifier}' already exists in library '{library.Identifier}'."`
	"""

	_library: 'Library'
	_package: 'Package'

	def __init__(self, package: 'Package', library: 'Library'):
		"""
		Initializes the exception message based on given package and library objects.

		:param package: The package that already exists in the library.
		:param library: The library that already contains the package.
		"""
		super().__init__(f"Package '{package.Identifier}' already exists in library '{library.Identifier}'.")
		self._library = library
		self._package = package

	@property
	def Library(self) -> 'Library':
		return self._library

	@property
	def Package(self) -> 'Package':
		return self._package


@export
class PackageBodyExistsError(VHDLModelException):
	"""
	This exception is raised, when the package body already existing in the library.

	Message: :pycode:`f"Package body '{packageBody.Identifier}' already exists in library '{library.Identifier}'."`
	"""

	_library: 'Library'
	_packageBody: 'PackageBody'

	def __init__(self, packageBody: 'PackageBody', library: 'Library'):
		"""
		Initializes the exception message based on given package body and library objects.

		:param packageBody: The package body that already exists in the library.
		:param library:     The library that already contains the package body.
		"""
		super().__init__(f"Package body '{packageBody.Identifier}' already exists in library '{library.Identifier}'.")
		self._library = library
		self._packageBody = packageBody

	@property
	def Library(self) -> 'Library':
		return self._library

	@property
	def PackageBody(self) -> 'PackageBody':
		return self._packageBody


@export
class ConfigurationExistsInLibraryError(VHDLModelException):
	"""
	This exception is raised, when the configuration already existing in the library.

	Message: :pycode:`f"Configuration '{configuration.Identifier}' already exists in library '{library.Identifier}'."`
	"""

	_library: 'Library'
	_configuration: 'Configuration'

	def __init__(self, configuration: 'Configuration', library: 'Library'):
		"""
		Initializes the exception message based on given configuration and library objects.

		:param configuration: The configuration that already exists in the library.
		:param library:       The library that already contains the configuration.
		"""
		super().__init__(f"Configuration '{configuration.Identifier}' already exists in library '{library.Identifier}'.")
		self._library = library
		self._configuration = configuration

	@property
	def Library(self) -> 'Library':
		return self._library

	@property
	def Configuration(self) -> 'Configuration':
		return self._configuration


@export
class ContextExistsInLibraryError(VHDLModelException):
	"""
	This exception is raised, when the context already existing in the library.

	Message: :pycode:`f"Context '{context.Identifier}' already exists in library '{library.Identifier}'."`
	"""

	_library: 'Library'
	_context: 'Context'

	def __init__(self, context: 'Context', library: 'Library'):
		"""
		Initializes the exception message based on given context and library objects.

		:param context: The context that already exists in the library.
		:param library: The library that already contains the context.
		"""
		super().__init__(f"Context '{context.Identifier}' already exists in library '{library.Identifier}'.")
		self._library = library
		self._context = context

	@property
	def Library(self) -> 'Library':
		return self._library

	@property
	def Context(self) -> 'Context':
		return self._context


@export
class ReferencedLibraryNotExistingError(VHDLModelException):
	"""
	This exception is raised, when a library is referenced by a `library clause`, but doesn't exist in the design.

	Message: :pycode:`f"Library '{librarySymbol.Name.Identifier}' referenced by library clause of context '{context.Identifier}' doesn't exist in design."`
	"""

	_librarySymbol: Symbol
	_context: 'Context'

	def __init__(self, context: 'Context', librarySymbol: Symbol):
		"""
		Initializes the exception message based on given context and library objects.

		:param context:       The context that already exists in the library.
		:param librarySymbol: The library that already contains the context.
		"""
		super().__init__(f"Library '{librarySymbol.Name.Identifier}' referenced by library clause of context '{context.Identifier}' doesn't exist in design.")
		self._librarySymbol = librarySymbol
		self._context = context

	@property
	def LibrarySymbol(self) -> Symbol:
		return self._librarySymbol

	@property
	def Context(self) -> 'Context':
		return self._context