Coverage for pyVHDLModel/Exception.py: 69%

137 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 22:15 +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. 

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 sys import version_info 

39from typing import List 

40 

41from pyTooling.Decorators import export, readonly 

42 

43from pyVHDLModel.Symbol import Symbol 

44 

45 

46@export 

47class VHDLModelException(Exception): 

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

49 

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] 

59 

60 

61@export 

62class LibraryExistsInDesignError(VHDLModelException): 

63 """ 

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

65 

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

67 """ 

68 

69 _library: 'Library' 

70 

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

72 """ 

73 Initializes the exception message based on given library object. 

74 

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 

79 

80 @readonly 

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

82 """ 

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

84 

85 :returns: Duplicate library (by name). 

86 """ 

87 return self._library 

88 

89 

90@export 

91class LibraryRegisteredToForeignDesignError(VHDLModelException): 

92 """ 

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

94 

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

96 """ 

97 

98 _library: 'Library' 

99 

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

101 """ 

102 Initializes the exception message based on given library object. 

103 

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 

108 

109 @readonly 

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

111 return self._library 

112 

113 

114@export 

115class LibraryNotRegisteredError(VHDLModelException): 

116 """ 

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

118 

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

120 """ 

121 

122 _library: 'Library' 

123 

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

125 """ 

126 Initializes the exception message based on given library object. 

127 

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 

132 

133 @readonly 

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

135 return self._library 

136 

137 

138@export 

139class EntityExistsInLibraryError(VHDLModelException): 

140 """ 

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

142 

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

144 """ 

145 

146 _library: 'Library' 

147 _entity: 'Entity' 

148 

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

150 """ 

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

152 

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 

159 

160 @readonly 

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

162 return self._library 

163 

164 @readonly 

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

166 return self._entity 

167 

168 

169@export 

170class ArchitectureExistsInLibraryError(VHDLModelException): 

171 """ 

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

173 

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

175 """ 

176 

177 _library: 'Library' 

178 _entity: 'Entity' 

179 _architecture: 'Architecture' 

180 

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. 

184 

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 

193 

194 @readonly 

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

196 return self._library 

197 

198 @readonly 

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

200 return self._entity 

201 

202 @readonly 

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

204 return self._architecture 

205 

206 

207@export 

208class PackageExistsInLibraryError(VHDLModelException): 

209 """ 

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

211 

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

213 """ 

214 

215 _library: 'Library' 

216 _package: 'Package' 

217 

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

219 """ 

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

221 

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 

228 

229 @readonly 

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

231 return self._library 

232 

233 @readonly 

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

235 return self._package 

236 

237 

238@export 

239class PackageBodyExistsError(VHDLModelException): 

240 """ 

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

242 

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

244 """ 

245 

246 _library: 'Library' 

247 _packageBody: 'PackageBody' 

248 

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

250 """ 

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

252 

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 

259 

260 @readonly 

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

262 return self._library 

263 

264 @property 

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

266 return self._packageBody 

267 

268 

269@export 

270class ConfigurationExistsInLibraryError(VHDLModelException): 

271 """ 

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

273 

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

275 """ 

276 

277 _library: 'Library' 

278 _configuration: 'Configuration' 

279 

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

281 """ 

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

283 

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 

290 

291 @property 

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

293 return self._library 

294 

295 @property 

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

297 return self._configuration 

298 

299 

300@export 

301class ContextExistsInLibraryError(VHDLModelException): 

302 """ 

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

304 

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

306 """ 

307 

308 _library: 'Library' 

309 _context: 'Context' 

310 

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

312 """ 

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

314 

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 

321 

322 @property 

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

324 return self._library 

325 

326 @property 

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

328 return self._context 

329 

330 

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. 

335 

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

337 """ 

338 

339 _librarySymbol: Symbol 

340 _context: 'Context' 

341 

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

343 """ 

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

345 

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 

352 

353 @property 

354 def LibrarySymbol(self) -> Symbol: 

355 return self._librarySymbol 

356 

357 @property 

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

359 return self._context