Coverage for pyVHDLModel / Exception.py: 71%

147 statements  

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

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 pass 

47 

48 

49@export 

50class NotImplementedWarning(VHDLModelWarning): 

51 pass 

52 

53 

54@export 

55class VHDLModelCriticalWarning(Warning): 

56 pass 

57 

58 

59@export 

60class BlackboxWarning(VHDLModelCriticalWarning): 

61 pass 

62 

63 

64@export 

65class VHDLModelException(Exception): 

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

67 

68 

69@export 

70class LibraryExistsInDesignError(VHDLModelException): 

71 """ 

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

73 

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

75 """ 

76 

77 _library: 'Library' 

78 

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

80 """ 

81 Initializes the exception message based on given library object. 

82 

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 

87 

88 @readonly 

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

90 """ 

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

92 

93 :returns: Duplicate library (by name). 

94 """ 

95 return self._library 

96 

97 

98@export 

99class LibraryRegisteredToForeignDesignError(VHDLModelException): 

100 """ 

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

102 

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

104 """ 

105 

106 _library: 'Library' 

107 

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

109 """ 

110 Initializes the exception message based on given library object. 

111 

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 

116 

117 @readonly 

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

119 return self._library 

120 

121 

122@export 

123class LibraryNotRegisteredError(VHDLModelException): 

124 """ 

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

126 

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

128 """ 

129 

130 _library: 'Library' 

131 

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

133 """ 

134 Initializes the exception message based on given library object. 

135 

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 

140 

141 @readonly 

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

143 return self._library 

144 

145 

146@export 

147class EntityExistsInLibraryError(VHDLModelException): 

148 """ 

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

150 

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

152 """ 

153 

154 _library: 'Library' 

155 _entity: 'Entity' 

156 

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

158 """ 

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

160 

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 

167 

168 @readonly 

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

170 return self._library 

171 

172 @readonly 

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

174 return self._entity 

175 

176 

177@export 

178class ArchitectureExistsInLibraryError(VHDLModelException): 

179 """ 

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

181 

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

183 """ 

184 

185 _library: 'Library' 

186 _entity: 'Entity' 

187 _architecture: 'Architecture' 

188 

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. 

192 

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 

201 

202 @readonly 

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

204 return self._library 

205 

206 @readonly 

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

208 return self._entity 

209 

210 @readonly 

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

212 return self._architecture 

213 

214 

215@export 

216class PackageExistsInLibraryError(VHDLModelException): 

217 """ 

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

219 

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

221 """ 

222 

223 _library: 'Library' 

224 _package: 'Package' 

225 

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

227 """ 

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

229 

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 

236 

237 @readonly 

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

239 return self._library 

240 

241 @readonly 

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

243 return self._package 

244 

245 

246@export 

247class PackageBodyExistsError(VHDLModelException): 

248 """ 

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

250 

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

252 """ 

253 

254 _library: 'Library' 

255 _packageBody: 'PackageBody' 

256 

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

258 """ 

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

260 

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 

267 

268 @readonly 

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

270 return self._library 

271 

272 @property 

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

274 return self._packageBody 

275 

276 

277@export 

278class ConfigurationExistsInLibraryError(VHDLModelException): 

279 """ 

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

281 

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

283 """ 

284 

285 _library: 'Library' 

286 _configuration: 'Configuration' 

287 

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

289 """ 

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

291 

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 

298 

299 @property 

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

301 return self._library 

302 

303 @property 

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

305 return self._configuration 

306 

307 

308@export 

309class ContextExistsInLibraryError(VHDLModelException): 

310 """ 

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

312 

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

314 """ 

315 

316 _library: 'Library' 

317 _context: 'Context' 

318 

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

320 """ 

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

322 

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 

329 

330 @property 

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

332 return self._library 

333 

334 @property 

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

336 return self._context 

337 

338 

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. 

343 

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

345 """ 

346 

347 _librarySymbol: Symbol 

348 _context: 'Context' 

349 

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

351 """ 

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

353 

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 

360 

361 @property 

362 def LibrarySymbol(self) -> Symbol: 

363 return self._librarySymbol 

364 

365 @property 

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

367 return self._context