Coverage for pyVHDLModel/Exception.py: 68%

132 statements  

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

34 

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 

40 

41from pyVHDLModel.Symbol import Symbol 

42 

43 

44@export 

45class VHDLModelWarning(Warning): 

46 """ 

47 Base-class for all warnings raised by pyVHDLModel. 

48 

49 .. seealso:: 

50 

51 * :class:`Not implemented warning <pyVHDLModel.Exception.NotImplementedWarning>` 

52 """ 

53 pass 

54 

55 

56@export 

57class NotImplementedWarning(VHDLModelWarning): 

58 """ 

59 Raised when a language construct is recognised but not yet modelled. 

60 """ 

61 pass 

62 

63 

64@export 

65class VHDLModelCriticalWarning(Warning): 

66 """ 

67 Base-class for critical warnings that likely indicate a defect in the model or its input. 

68 

69 .. seealso:: 

70 

71 * :class:`Blackbox warning <pyVHDLModel.Exception.BlackboxWarning>` 

72 """ 

73 pass 

74 

75 

76@export 

77class DuplicateDeclarationWarning(VHDLModelCriticalWarning): 

78 """ 

79 Raised when two declarations in one declarative region share an identifier. 

80 

81 VHDL rejects this as *identifier already used for a declaration*. Overloadable declarations - 

82 subprograms differing in signature - are not reported. 

83 """ 

84 pass 

85 

86 

87@export 

88class BlackboxWarning(VHDLModelCriticalWarning): 

89 """ 

90 Raised when a component could not be bound and is treated as a blackbox. 

91 """ 

92 pass 

93 

94 

95@export 

96class VHDLModelException(Exception): 

97 """ 

98 Base-class for all exceptions (errors) raised by pyVHDLModel. 

99 

100 .. seealso:: 

101 

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

113 

114 

115@export 

116class LibraryExistsInDesignError(VHDLModelException): 

117 """ 

118 This exception is raised, when the library is already existing in the design. 

119 

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

121 """ 

122 

123 _library: 'Library' #: The library involved in this error. 

124 

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

126 """ 

127 Initializes the exception message based on given library object. 

128 

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 

133 

134 @readonly 

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

136 """ 

137 Read-only property to access the duplicate library (:attr:`_library`). 

138 

139 :returns: Duplicate library (by name). 

140 """ 

141 return self._library 

142 

143 

144@export 

145class LibraryRegisteredToForeignDesignError(VHDLModelException): 

146 """ 

147 This exception is raised, when the library is already registered to a foreign design. 

148 

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

150 """ 

151 

152 _library: 'Library' #: The library involved in this error. 

153 

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

155 """ 

156 Initializes the exception message based on given library object. 

157 

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 

162 

163 @readonly 

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

165 """ 

166 Read-only property to access the library (:attr:`_library`). 

167 

168 :returns: The library. 

169 """ 

170 return self._library 

171 

172 

173@export 

174class LibraryNotRegisteredError(VHDLModelException): 

175 """ 

176 This exception is raised, when the library is not registered in the design. 

177 

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

179 """ 

180 

181 _library: 'Library' #: The library involved in this error. 

182 

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

184 """ 

185 Initializes the exception message based on given library object. 

186 

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 

191 

192 @readonly 

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

194 """ 

195 Read-only property to access the library (:attr:`_library`). 

196 

197 :returns: The library. 

198 """ 

199 return self._library 

200 

201 

202@export 

203class EntityExistsInLibraryError(VHDLModelException): 

204 """ 

205 This exception is raised, when the entity already existing in the library. 

206 

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

208 """ 

209 

210 _library: 'Library' #: The library involved in this error. 

211 _entity: 'Entity' #: The entity involved in this error. 

212 

213 def __init__(self, entity: 'Entity', library: 'Library') -> None: 

214 """ 

215 Initializes the exception message based on given entity and library objects. 

216 

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 

223 

224 @readonly 

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

226 """ 

227 Read-only property to access the library (:attr:`_library`). 

228 

229 :returns: The library. 

230 """ 

231 return self._library 

232 

233 @readonly 

234 def Entity(self) -> 'Entity': 

235 """ 

236 Read-only property to access the entity (:attr:`_entity`). 

237 

238 :returns: The entity. 

239 """ 

240 return self._entity 

241 

242 

243@export 

244class ArchitectureExistsInLibraryError(VHDLModelException): 

245 """ 

246 This exception is raised, when the architecture already existing in the library. 

247 

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

249 """ 

250 

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. 

254 

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. 

258 

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 

267 

268 @readonly 

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

270 """ 

271 Read-only property to access the library (:attr:`_library`). 

272 

273 :returns: The library. 

274 """ 

275 return self._library 

276 

277 @readonly 

278 def Entity(self) -> 'Entity': 

279 """ 

280 Read-only property to access the entity (:attr:`_entity`). 

281 

282 :returns: The entity. 

283 """ 

284 return self._entity 

285 

286 @readonly 

287 def Architecture(self) -> 'Architecture': 

288 """ 

289 Read-only property to access the architecture (:attr:`_architecture`). 

290 

291 :returns: The architecture. 

292 """ 

293 return self._architecture 

294 

295 

296@export 

297class PackageExistsInLibraryError(VHDLModelException): 

298 """ 

299 This exception is raised, when the package already existing in the library. 

300 

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

302 """ 

303 

304 _library: 'Library' #: The library involved in this error. 

305 _package: 'Package' #: The package involved in this error. 

306 

307 def __init__(self, package: 'Package', library: 'Library') -> None: 

308 """ 

309 Initializes the exception message based on given package and library objects. 

310 

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 

317 

318 @readonly 

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

320 """ 

321 Read-only property to access the library (:attr:`_library`). 

322 

323 :returns: The library. 

324 """ 

325 return self._library 

326 

327 @readonly 

328 def Package(self) -> 'Package': 

329 """ 

330 Read-only property to access the package (:attr:`_package`). 

331 

332 :returns: The package. 

333 """ 

334 return self._package 

335 

336 

337@export 

338class PackageBodyExistsError(VHDLModelException): 

339 """ 

340 This exception is raised, when the package body already existing in the library. 

341 

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

343 """ 

344 

345 _library: 'Library' #: The library involved in this error. 

346 _packageBody: 'PackageBody' #: The package body involved in this error. 

347 

348 def __init__(self, packageBody: 'PackageBody', library: 'Library') -> None: 

349 """ 

350 Initializes the exception message based on given package body and library objects. 

351 

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 

358 

359 @readonly 

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

361 """ 

362 Read-only property to access the library (:attr:`_library`). 

363 

364 :returns: The library. 

365 """ 

366 return self._library 

367 

368 @readonly 

369 def PackageBody(self) -> 'PackageBody': 

370 """ 

371 Read-only property to access the package body (:attr:`_packageBody`). 

372 

373 :returns: The package body. 

374 """ 

375 return self._packageBody 

376 

377 

378@export 

379class ConfigurationExistsInLibraryError(VHDLModelException): 

380 """ 

381 This exception is raised, when the configuration already existing in the library. 

382 

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

384 """ 

385 

386 _library: 'Library' #: The library involved in this error. 

387 _configuration: 'Configuration' #: The configuration involved in this error. 

388 

389 def __init__(self, configuration: 'Configuration', library: 'Library') -> None: 

390 """ 

391 Initializes the exception message based on given configuration and library objects. 

392 

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 

399 

400 @readonly 

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

402 """ 

403 Read-only property to access the library (:attr:`_library`). 

404 

405 :returns: The library. 

406 """ 

407 return self._library 

408 

409 @readonly 

410 def Configuration(self) -> 'Configuration': 

411 """ 

412 Read-only property to access the configuration (:attr:`_configuration`). 

413 

414 :returns: The configuration. 

415 """ 

416 return self._configuration 

417 

418 

419@export 

420class ContextExistsInLibraryError(VHDLModelException): 

421 """ 

422 This exception is raised, when the context already existing in the library. 

423 

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

425 """ 

426 

427 _library: 'Library' #: The library involved in this error. 

428 _context: 'Context' #: The context involved in this error. 

429 

430 def __init__(self, context: 'Context', library: 'Library') -> None: 

431 """ 

432 Initializes the exception message based on given context and library objects. 

433 

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 

440 

441 @readonly 

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

443 """ 

444 Read-only property to access the library (:attr:`_library`). 

445 

446 :returns: The library. 

447 """ 

448 return self._library 

449 

450 @readonly 

451 def Context(self) -> 'Context': 

452 """ 

453 Read-only property to access the context (:attr:`_context`). 

454 

455 :returns: The context. 

456 """ 

457 return self._context 

458 

459 

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. 

464 

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

466 """ 

467 

468 _librarySymbol: Symbol #: The library symbol that could not be resolved. 

469 _context: 'Context' #: The context involved in this error. 

470 

471 def __init__(self, context: 'Context', librarySymbol: Symbol) -> None: 

472 """ 

473 Initializes the exception message based on given context and library objects. 

474 

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 

481 

482 @readonly 

483 def LibrarySymbol(self) -> Symbol: 

484 """ 

485 Read-only property to access the library symbol (:attr:`_librarySymbol`). 

486 

487 :returns: The library symbol. 

488 """ 

489 return self._librarySymbol 

490 

491 @readonly 

492 def Context(self) -> 'Context': 

493 """ 

494 Read-only property to access the context (:attr:`_context`). 

495 

496 :returns: The context. 

497 """ 

498 return self._context