Coverage for pyVHDLModel/Interface.py: 59%

173 statements  

« prev     ^ index     » next       coverage.py v7.15.1, created at 2026-07-13 17:58 +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 

35Interface items are used in generic, port and parameter declarations. 

36""" 

37from typing import Iterable, Optional as Nullable, List, Iterator 

38 

39from pyTooling.Decorators import export, readonly 

40from pyTooling.MetaClasses import ExtendedType 

41 

42from pyVHDLModel.Symbol import Symbol 

43from pyVHDLModel.Base import ModelEntity, DocumentedEntityMixin, NamedEntityMixin, OptionallyNamedEntityMixin 

44from pyVHDLModel.Base import ExpressionUnion, Mode 

45from pyVHDLModel.Object import Constant, Signal, Variable, File 

46from pyVHDLModel.Subprogram import Procedure, Function 

47from pyVHDLModel.Type import Type 

48 

49 

50@export 

51class InterfaceItemMixin(DocumentedEntityMixin, mixin=True): 

52 """An ``InterfaceItem`` is a base-class for all mixin-classes for all interface items.""" 

53 

54 def __init__(self, documentation: Nullable[str] = None) -> None: 

55 super().__init__(documentation) 

56 

57 

58@export 

59class InterfaceItemWithModeMixin(metaclass=ExtendedType, mixin=True): 

60 """An ``InterfaceItemWithMode`` is a mixin-class to provide a ``Mode`` to interface items.""" 

61 

62 _mode: Mode 

63 

64 def __init__(self, mode: Mode) -> None: 

65 self._mode = mode 

66 

67 @readonly 

68 def Mode(self) -> Mode: 

69 return self._mode 

70 

71 

72@export 

73class GenericInterfaceItemMixin(InterfaceItemMixin, mixin=True): 

74 """A ``GenericInterfaceItem`` is a mixin class for all generic interface items.""" 

75 

76 

77@export 

78class PortInterfaceItemMixin(InterfaceItemMixin, InterfaceItemWithModeMixin, mixin=True): 

79 """A ``PortInterfaceItem`` is a mixin class for all port interface items.""" 

80 

81 def __init__(self, mode: Mode) -> None: 

82 super().__init__() 

83 InterfaceItemWithModeMixin.__init__(self, mode) 

84 

85 

86@export 

87class ParameterInterfaceItemMixin(InterfaceItemMixin, mixin=True): 

88 """A ``ParameterInterfaceItem`` is a mixin class for all parameter interface items.""" 

89 

90 

91@export 

92class GenericConstantInterfaceItem(Constant, GenericInterfaceItemMixin, InterfaceItemWithModeMixin): 

93 def __init__( 

94 self, 

95 identifiers: Iterable[str], 

96 mode: Mode, 

97 subtype: Symbol, 

98 defaultExpression: Nullable[ExpressionUnion] = None, 

99 documentation: Nullable[str] = None, 

100 parent: Nullable[ModelEntity] = None 

101 ) -> None: 

102 super().__init__(identifiers, subtype, defaultExpression, documentation, parent) 

103 GenericInterfaceItemMixin.__init__(self) 

104 InterfaceItemWithModeMixin.__init__(self, mode) 

105 

106 

107@export 

108class GenericTypeInterfaceItem(Type, GenericInterfaceItemMixin): 

109 def __init__(self, identifier: str, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

110 super().__init__(identifier, documentation, parent) 

111 GenericInterfaceItemMixin.__init__(self) 

112 

113 

114@export 

115class GenericSubprogramInterfaceItem(GenericInterfaceItemMixin): 

116 pass 

117 

118 

119@export 

120class GenericProcedureInterfaceItem(Procedure, GenericInterfaceItemMixin): 

121 def __init__(self, identifier: str, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

122 super().__init__(identifier, documentation, parent) 

123 GenericInterfaceItemMixin.__init__(self) 

124 

125 

126@export 

127class GenericFunctionInterfaceItem(Function, GenericInterfaceItemMixin): 

128 def __init__(self, identifier: str, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

129 super().__init__(identifier, documentation, parent) 

130 GenericInterfaceItemMixin.__init__(self) 

131 

132 

133@export 

134class InterfacePackage(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

135 def __init__(self, identifier: str, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

136 super().__init__(parent) 

137 NamedEntityMixin.__init__(self, identifier) 

138 DocumentedEntityMixin.__init__(self, documentation) 

139 

140 

141@export 

142class GenericPackageInterfaceItem(InterfacePackage, GenericInterfaceItemMixin): 

143 def __init__(self, identifier: str, documentation: Nullable[str] = None, parent: Nullable[ModelEntity] = None) -> None: 

144 super().__init__(identifier, documentation, parent) 

145 GenericInterfaceItemMixin.__init__(self) 

146 

147 

148@export 

149class PortSignalInterfaceItem(Signal, PortInterfaceItemMixin): 

150 def __init__( 

151 self, 

152 identifiers: Iterable[str], 

153 mode: Mode, 

154 subtype: Symbol, 

155 defaultExpression: Nullable[ExpressionUnion] = None, 

156 documentation: Nullable[str] = None, 

157 parent: Nullable[ModelEntity] = None 

158 ) -> None: 

159 super().__init__(identifiers, subtype, defaultExpression, documentation, parent) 

160 PortInterfaceItemMixin.__init__(self, mode) 

161 

162 

163@export 

164class ParameterConstantInterfaceItem(Constant, ParameterInterfaceItemMixin, InterfaceItemWithModeMixin): 

165 def __init__( 

166 self, 

167 identifiers: Iterable[str], 

168 mode: Mode, 

169 subtype: Symbol, 

170 defaultExpression: Nullable[ExpressionUnion] = None, 

171 documentation: Nullable[str] = None, 

172 parent: Nullable[ModelEntity] = None 

173 ) -> None: 

174 super().__init__(identifiers, subtype, defaultExpression, documentation, parent) 

175 ParameterInterfaceItemMixin.__init__(self) 

176 InterfaceItemWithModeMixin.__init__(self, mode) 

177 

178 

179@export 

180class ParameterVariableInterfaceItem(Variable, ParameterInterfaceItemMixin, InterfaceItemWithModeMixin): 

181 def __init__( 

182 self, 

183 identifiers: Iterable[str], 

184 mode: Mode, 

185 subtype: Symbol, 

186 defaultExpression: Nullable[ExpressionUnion] = None, 

187 documentation: Nullable[str] = None, 

188 parent: Nullable[ModelEntity] = None 

189 ) -> None: 

190 super().__init__(identifiers, subtype, defaultExpression, documentation, parent) 

191 ParameterInterfaceItemMixin.__init__(self) 

192 InterfaceItemWithModeMixin.__init__(self, mode) 

193 

194 

195@export 

196class ParameterSignalInterfaceItem(Signal, ParameterInterfaceItemMixin, InterfaceItemWithModeMixin): 

197 def __init__( 

198 self, 

199 identifiers: Iterable[str], 

200 mode: Mode, 

201 subtype: Symbol, 

202 defaultExpression: Nullable[ExpressionUnion] = None, 

203 documentation: Nullable[str] = None, 

204 parent: Nullable[ModelEntity] = None 

205 ) -> None: 

206 super().__init__(identifiers, subtype, defaultExpression, documentation, parent) 

207 ParameterInterfaceItemMixin.__init__(self) 

208 InterfaceItemWithModeMixin.__init__(self, mode) 

209 

210 

211@export 

212class ParameterFileInterfaceItem(File, ParameterInterfaceItemMixin): 

213 def __init__( 

214 self, 

215 identifiers: Iterable[str], 

216 subtype: Symbol, 

217 documentation: Nullable[str] = None, 

218 parent: Nullable[ModelEntity] = None 

219 ) -> None: 

220 super().__init__(identifiers, subtype, documentation, parent) 

221 ParameterInterfaceItemMixin.__init__(self) 

222 

223 

224@export 

225class WithGenericsMixin(metaclass=ExtendedType, mixin=True): 

226 _genericItems: List[GenericInterfaceItemMixin] 

227 

228 def __init__( 

229 self, 

230 genericItems: Nullable[Iterable[GenericInterfaceItemMixin]] = None, 

231 ) -> None: 

232 self._genericItems = [] 

233 if genericItems is not None: 233 ↛ 234line 233 didn't jump to line 234 because the condition on line 233 was never true

234 for item in genericItems: 

235 self._genericItems.append(item) 

236 item.Parent = self 

237 

238 @property 

239 def GenericItems(self) -> List[GenericInterfaceItemMixin]: 

240 return self._genericItems 

241 

242 @property 

243 def GenericCount(self) -> int: 

244 return len(self._genericItems) 

245 

246 

247@export 

248class WithPortsMixin(metaclass=ExtendedType, mixin=True): 

249 _portItems: List[PortInterfaceItemMixin] 

250 

251 def __init__( 

252 self, 

253 portItems: Nullable[Iterable[PortInterfaceItemMixin]] = None, 

254 ) -> None: 

255 self._portItems = [] 

256 if portItems is not None: 256 ↛ 257line 256 didn't jump to line 257 because the condition on line 256 was never true

257 for item in portItems: 

258 self._portItems.append(item) 

259 item.Parent = self 

260 

261 @property 

262 def PortItems(self) -> List[PortInterfaceItemMixin]: 

263 return self._portItems 

264 

265 @property 

266 def PortCount(self) -> int: 

267 return len(self._portItems) 

268 

269 

270@export 

271class WithParametersMixin(metaclass=ExtendedType, mixin=True): 

272 _parameterItems: List[ParameterInterfaceItemMixin] 

273 

274 def __init__( 

275 self, 

276 parameterItems: Nullable[Iterable[ParameterInterfaceItemMixin]] = None, 

277 ) -> None: 

278 self._parameterItems = [] 

279 if parameterItems is not None: 

280 for item in parameterItems: 

281 self._parameterItems.append(item) 

282 item.Parent = self 

283 

284 @property 

285 def ParameterItems(self) -> List[ParameterInterfaceItemMixin]: 

286 return self._parameterItems 

287 

288 @property 

289 def ParameterCount(self) -> int: 

290 return len(self._parameterItems) 

291 

292 

293@export 

294class InterfaceGroup(ModelEntity, OptionallyNamedEntityMixin, DocumentedEntityMixin): 

295 def __init__( 

296 self, 

297 name: Nullable[str] = None, 

298 documentation: Nullable[str] = None, 

299 parent: Nullable[ModelEntity] = None 

300 ) -> None: 

301 """Initialize a PortGroup with a list of ports and optional name.""" 

302 super().__init__(parent) 

303 OptionallyNamedEntityMixin.__init__(self, name) 

304 DocumentedEntityMixin.__init__(self, documentation) 

305 

306 

307@export 

308class GenericGroup(InterfaceGroup): 

309 def __init__( 

310 self, 

311 genericItems: Iterable[GenericInterfaceItemMixin], 

312 name: Nullable[str] = None, 

313 documentation: Nullable[str] = None, 

314 parent: Nullable[ModelEntity] = None 

315 ) -> None: 

316 super().__init__(name, documentation, parent) 

317 WithGenericsMixin.__init__(self, genericItems) 

318 

319 def __len__(self) -> int: 

320 return len(self._genericItems) 

321 

322 def __iter__(self) -> Iterator[GenericInterfaceItemMixin]: 

323 return iter(self._genericItems) 

324 

325 def __str__(self) -> str: 

326 return f"GenericGroup {self._identifier} ({len(self._genericItems)}) - generics: {', '.join(p._identifier for p in self._genericItems)})" 

327 

328 

329@export 

330class PortGroup(InterfaceGroup, WithPortsMixin): 

331 def __init__( 

332 self, 

333 portItems: Iterable[PortInterfaceItemMixin], 

334 name: Nullable[str] = None, 

335 documentation: Nullable[str] = None, 

336 parent: Nullable[ModelEntity] = None 

337 ) -> None: 

338 super().__init__(name, documentation, parent) 

339 WithPortsMixin.__init__(self, portItems) 

340 

341 def __len__(self) -> int: 

342 return len(self._portItems) 

343 

344 def __iter__(self) -> Iterator[PortInterfaceItemMixin]: 

345 return iter(self._portItems) 

346 

347 def __str__(self) -> str: 

348 return f"PortGroup: {self._identifier} ({len(self._portItems)}) - ports: {', '.join(p._identifier for p in self._portItems)})" 

349 

350 

351@export 

352class ParameterGroup(InterfaceGroup): 

353 def __init__( 

354 self, 

355 parameterItems: Iterable[ParameterInterfaceItemMixin], 

356 name: Nullable[str] = None, 

357 documentation: Nullable[str] = None, 

358 parent: Nullable[ModelEntity] = None 

359 ) -> None: 

360 super().__init__(name, documentation, parent) 

361 WithParametersMixin.__init__(self, parameterItems) 

362 

363 def __len__(self) -> int: 

364 return len(self._parameterItems) 

365 

366 def __iter__(self) -> Iterator[ParameterInterfaceItemMixin]: 

367 return iter(self._parameterItems) 

368 

369 def __str__(self) -> str: 

370 return f"ParameterGroup {self._identifier} ({len(self._parameterItems)}) - parameters: {', '.join(p._identifier for p in self._parameterItems)})"