Coverage for pyVHDLModel/STD/StandardPkg.py: 100%

180 statements  

« prev     ^ index     » next       coverage.py v7.18.0, created at 2026-12-01 12:56 +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"""This module contains the predefined package ``std.standard`` of VHDL library ``STD``.""" 

33 

34from typing import Generator, Optional as Nullable 

35 

36from pyTooling.Common import getFullyQualifiedName 

37from pyTooling.Decorators import export, readonly 

38from pyTooling.MetaClasses import ExtendedType, abstractmethod 

39 

40from pyVHDLModel import VHDLVersion 

41from pyVHDLModel.Base import ModelEntity, SimpleRange, Direction, Mode 

42from pyVHDLModel.Name import SimpleName 

43from pyVHDLModel.Symbol import SimpleSubtypeSymbol, ConstrainedScalarSubtypeSymbol 

44from pyVHDLModel.Expression import EnumerationLiteral, CharacterEnumerationLiteral, IntegerLiteral, \ 

45 FloatingPointLiteral, PhysicalIntegerLiteral 

46from pyVHDLModel.Type import BaseType, FullType, EnumeratedType, IntegerType, RealType, PhysicalType, \ 

47 PhysicalUnit, ArrayType, Subtype, LogicalOperatorsMixin, MatchingOperatorsMixin 

48from pyVHDLModel.Interface import ParameterSimpleSignalInterfaceItem 

49from pyVHDLModel.Declaration import Attribute 

50from pyVHDLModel.Subprogram import Function, PredefinedFunction, PredefinedOperation 

51from pyVHDLModel.Predefined import PredefinedPackage, PredefinedPackageBody 

52 

53 

54@export 

55class EdgeFunctionsMixin(metaclass=ExtendedType, mixin=True, expects=("_TypeMark", "_Function")): 

56 """ 

57 A mixin-class for the enumerated types declaring the functions ``rising_edge`` and ``falling_edge`` (IEEE Std 

58 1076-2008, 16.3): ``boolean`` and ``bit`` of package ``std.standard``. 

59 

60 .. seealso:: 

61 

62 * :class:`Boolean <pyVHDLModel.STD.StandardPkg.Boolean>` 

63 * :class:`Bit <pyVHDLModel.STD.StandardPkg.Bit>` 

64 """ 

65 

66 def _CreateEdgeFunctions(self) -> list[PredefinedFunction]: 

67 """ 

68 Create the functions ``rising_edge`` and ``falling_edge`` of this type: ``(signal S : <type>) return BOOLEAN``. 

69 

70 :returns: List of predefined functions. 

71 """ 

72 functions = [] 

73 for identifier in ("rising_edge", "falling_edge"): 

74 functions.append(self._Function( 

75 identifier, 

76 SimpleSubtypeSymbol(SimpleName("boolean")), 

77 (ParameterSimpleSignalInterfaceItem(("S", ), Mode.In, self._TypeMark()), ) 

78 )) 

79 

80 return functions 

81 

82 

83@export 

84class Boolean(EnumeratedType, LogicalOperatorsMixin, EdgeFunctionsMixin): 

85 """ 

86 Represents the predefined type ``boolean`` of package ``std.standard``: ``(false, true)``. 

87 

88 Besides the operations of an enumerated type, it declares the logical operators (IEEE Std 1076-2008, 9.2.2) and the 

89 functions ``rising_edge`` and ``falling_edge`` (16.3). 

90 """ 

91 

92 def __init__(self) -> None: 

93 """ 

94 Initializes the type ``boolean``. 

95 """ 

96 super().__init__("boolean", (EnumerationLiteral("false"), EnumerationLiteral("true"))) 

97 

98 def _CreateImplicitOperations(self) -> list[PredefinedOperation]: 

99 """ 

100 Create the operations this type declares implicitly: those of an enumerated type, the logical operators, then 

101 ``rising_edge`` and ``falling_edge``. 

102 

103 :returns: List of predefined operators and predefined functions. 

104 """ 

105 operations = super()._CreateImplicitOperations() 

106 operations.extend(self._CreateLogicalOperators()) 

107 operations.extend(self._CreateEdgeFunctions()) 

108 

109 return operations 

110 

111 

112@export 

113class Bit(EnumeratedType, LogicalOperatorsMixin, MatchingOperatorsMixin, EdgeFunctionsMixin): 

114 """ 

115 Represents the predefined type ``bit`` of package ``std.standard``: ``('0', '1')``. 

116 

117 Besides the operations of an enumerated type, it declares the logical operators (IEEE Std 1076-2008, 9.2.2), the 

118 condition operator ``"??"`` (9.2.9), the matching relational operators (9.2.3) and the functions ``rising_edge`` and 

119 ``falling_edge`` (16.3). 

120 """ 

121 

122 def __init__(self) -> None: 

123 """ 

124 Initializes the type ``bit``. 

125 """ 

126 super().__init__("bit", (CharacterEnumerationLiteral("0"), CharacterEnumerationLiteral("1"))) 

127 

128 def _CreateImplicitOperations(self) -> list[PredefinedOperation]: 

129 """ 

130 Create the operations this type declares implicitly: those of an enumerated type, the logical operators, the 

131 condition operator ``"??"``, the matching relational operators ``"?="``, ``"?/="``, ``"?<"``, ``"?<="``, 

132 ``"?>"`` and ``"?>="``, then ``rising_edge`` and ``falling_edge``. 

133 

134 :returns: List of predefined operators and predefined functions. 

135 """ 

136 operations = super()._CreateImplicitOperations() 

137 operations.extend(self._CreateLogicalOperators()) 

138 operations.append(self._UnaryOperator("??", SimpleSubtypeSymbol(SimpleName("boolean")))) 

139 operations.extend(self._CreateMatchingOperators()) 

140 operations.extend(self._CreateEdgeFunctions()) 

141 

142 return operations 

143 

144 

145@export 

146class Real(RealType): 

147 """ 

148 Represents the predefined type ``real`` of package ``std.standard``: an IEEE 754 double. 

149 

150 Besides the operations of a floating-point type, it declares the overloads of ``to_string`` with the number of 

151 digits after the decimal point (``DIGITS``) and with a format specification (``FORMAT``) (IEEE Std 1076-2008, 16.3). 

152 """ 

153 

154 def __init__(self) -> None: 

155 """ 

156 Initializes the type ``real``. 

157 

158 Its range is ``-1.7976931348623157e308 to 1.7976931348623157e308``. 

159 """ 

160 super().__init__("real", SimpleRange( 

161 FloatingPointLiteral(-1.7976931348623157e308), 

162 FloatingPointLiteral(1.7976931348623157e308), 

163 Direction.To 

164 )) 

165 

166 def _CreateImplicitOperations(self) -> list[PredefinedOperation]: 

167 """ 

168 Create the operations this type declares implicitly: those of a floating-point type, then 

169 ``to_string (VALUE : real; DIGITS : natural) return string`` and 

170 ``to_string (VALUE : real; FORMAT : string) return string``. 

171 

172 :returns: List of predefined operators and predefined functions. 

173 """ 

174 operations = super()._CreateImplicitOperations() 

175 for identifier, subtype in ( 

176 ("DIGITS", "natural"), 

177 ("FORMAT", "string") 

178 ): 

179 operations.append(self._Function( 

180 "to_string", 

181 SimpleSubtypeSymbol(SimpleName("string")), 

182 ( 

183 self._Parameter("VALUE", self._TypeMark()), 

184 self._Parameter(identifier, SimpleSubtypeSymbol(SimpleName(subtype))) 

185 ) 

186 )) 

187 

188 return operations 

189 

190 

191@export 

192class Time(PhysicalType): 

193 """ 

194 Represents the predefined type ``time`` of package ``std.standard``: femtoseconds in 64 bits. 

195 

196 Its units range from ``fs`` to ``hr``. Besides the operations of a physical type, it declares the overload of 

197 ``to_string`` with the unit of the result (``UNIT``) (IEEE Std 1076-2008, 16.3). 

198 """ 

199 

200 def __init__(self) -> None: 

201 """ 

202 Initializes the type ``time``. 

203 

204 Its range is ``-2**63 to 2**63 - 1``, its primary unit ``fs``, its secondary units ``ps``, ``ns``, ``us``, ``ms``, 

205 ``sec``, ``min`` and ``hr``. 

206 """ 

207 super().__init__( 

208 "time", 

209 SimpleRange(IntegerLiteral(-2**63), IntegerLiteral(2**63 - 1), Direction.To), 

210 primaryUnit=PhysicalUnit("fs"), 

211 secondaryUnits=( 

212 PhysicalUnit("ps", PhysicalIntegerLiteral(1000, "fs")), 

213 PhysicalUnit("ns", PhysicalIntegerLiteral(1000, "ps")), 

214 PhysicalUnit("us", PhysicalIntegerLiteral(1000, "ns")), 

215 PhysicalUnit("ms", PhysicalIntegerLiteral(1000, "us")), 

216 PhysicalUnit("sec", PhysicalIntegerLiteral(1000, "ms")), 

217 PhysicalUnit("min", PhysicalIntegerLiteral(60, "sec")), 

218 PhysicalUnit("hr", PhysicalIntegerLiteral(60, "min")), 

219 ) 

220 ) 

221 

222 def _CreateImplicitOperations(self) -> list[PredefinedOperation]: 

223 """ 

224 Create the operations this type declares implicitly: those of a physical type, then 

225 ``to_string (VALUE : time; UNIT : time) return string``. 

226 

227 :returns: List of predefined operators and predefined functions. 

228 """ 

229 operations = super()._CreateImplicitOperations() 

230 operations.append(self._Function( 

231 "to_string", 

232 SimpleSubtypeSymbol(SimpleName("string")), 

233 (self._Parameter("VALUE", self._TypeMark()), self._Parameter("UNIT", self._TypeMark())) 

234 )) 

235 

236 return operations 

237 

238 

239@export 

240class BitVector(ArrayType): 

241 """ 

242 Represents the predefined type ``bit_vector`` of package ``std.standard``: ``array (natural range <>) of bit``. 

243 

244 Besides the operations of a one-dimensional array type of ``bit``, it declares the functions ``to_ostring`` and 

245 ``to_hstring`` (IEEE Std 1076-2008, 5.3.2.4). 

246 """ 

247 

248 def __init__(self) -> None: 

249 """ 

250 Initializes the type ``bit_vector``. 

251 """ 

252 super().__init__( 

253 "bit_vector", 

254 (SimpleSubtypeSymbol(SimpleName("natural")), ), 

255 SimpleSubtypeSymbol(SimpleName("bit")) 

256 ) 

257 

258 def _CreateImplicitOperations(self) -> list[PredefinedOperation]: 

259 """ 

260 Create the operations this type declares implicitly: those of a one-dimensional array type of ``bit``, then 

261 ``to_ostring (VALUE : bit_vector) return string`` and ``to_hstring (VALUE : bit_vector) return string``. 

262 

263 :returns: List of predefined operators and predefined functions. 

264 """ 

265 operations = super()._CreateImplicitOperations() 

266 for identifier in ("to_ostring", "to_hstring"): 

267 operations.append(self._Function( 

268 identifier, 

269 SimpleSubtypeSymbol(SimpleName("string")), 

270 (self._Parameter("VALUE", self._TypeMark()), ) 

271 )) 

272 

273 return operations 

274 

275 

276@export 

277class UniversalTypeMixin(metaclass=ExtendedType, mixin=True): 

278 """ 

279 A mixin-class for the anonymous types *universal_integer* and *universal_real* of package ``std.standard``. 

280 

281 A numeric literal is of a universal type (IEEE Std 1076-2008, 9.3.2), so are some predefined attributes (16.2) and 

282 the division of two values of one physical type (9.2.7). An operation of a universal type yields a universal 

283 expression (9.5). A value of a universal type converts implicitly to another type of its type class 

284 (:meth:`IsImplicitlyConvertibleTo`), if it is a convertible universal operand (9.3.6): a numeric literal, an 

285 attribute or the division of two values of one physical type, but not the result of an operation of a universal 

286 type. The conversion is applied, if the innermost complete context determines a unique numeric target type and has 

287 no legal interpretation without the conversion. 

288 

289 .. seealso:: 

290 

291 * :class:`Type universal_integer <pyVHDLModel.STD.StandardPkg.UniversalInteger>` 

292 * :class:`Type universal_real <pyVHDLModel.STD.StandardPkg.UniversalReal>` 

293 """ 

294 

295 @abstractmethod 

296 def IsImplicitlyConvertibleTo(self, targetType: BaseType) -> bool: 

297 """ 

298 Check if a value of this universal type converts implicitly to a type (IEEE Std 1076-2008, 9.3.6). 

299 

300 :param targetType: The type or subtype a context expects. A subtype stands for its base type. 

301 :returns: ``True``, if a value converts implicitly to the type. 

302 """ 

303 

304 

305@export 

306class UniversalInteger(IntegerType, UniversalTypeMixin): 

307 """ 

308 Represents the anonymous type *universal_integer* of package ``std.standard``: 64 bits, like GHDL's. 

309 

310 It declares the operations of an integer type. Its values convert implicitly to every other integer type 

311 (IEEE Std 1076-2008, 5.2.3.1, 9.3.6). 

312 """ 

313 

314 def __init__(self, *, parent: Nullable[ModelEntity] = None) -> None: 

315 """ 

316 Initializes the type *universal_integer*. 

317 

318 Its range is ``-2**63 to 2**63 - 1``. 

319 

320 :param parent: Optional, the parent model entity, the package ``std.standard``. Default: ``None``, no parent. 

321 """ 

322 super().__init__( 

323 "universal_integer", 

324 SimpleRange(IntegerLiteral(-2**63), IntegerLiteral(2**63 - 1), Direction.To), 

325 parent=parent 

326 ) 

327 

328 def IsImplicitlyConvertibleTo(self, targetType: BaseType) -> bool: 

329 """ 

330 Check if a value of *universal_integer* converts implicitly to a type (IEEE Std 1076-2008, 5.2.3.1, 9.3.6). 

331 

332 It converts to every integer type, except *universal_integer* itself. A subtype stands for its base type; a 

333 subtype, whose type mark isn't resolved, has none. 

334 

335 :param targetType: The type or subtype a context expects. 

336 :returns: ``True``, if the base type of the target is an integer type other than *universal_integer*. 

337 :raises ValueError: If parameter 'targetType' is None. 

338 :raises TypeError: If parameter 'targetType' is not of type :class:`~pyVHDLModel.Type.BaseType`. 

339 """ 

340 if targetType is None: 

341 raise ValueError("Parameter 'targetType' is None.") 

342 elif not isinstance(targetType, BaseType): 

343 ex = TypeError("Parameter 'targetType' is not of type 'BaseType'.") 

344 ex.add_note(f"Got type '{getFullyQualifiedName(targetType)}'.") 

345 raise ex 

346 

347 baseType = targetType.BaseType 

348 return isinstance(baseType, IntegerType) and not isinstance(baseType, UniversalInteger) 

349 

350 

351@export 

352class UniversalReal(RealType, UniversalTypeMixin): 

353 """ 

354 Represents the anonymous type *universal_real* of package ``std.standard``: an IEEE 754 double. 

355 

356 Besides the operations of a floating-point type, it declares the multiplying operators with an operand of the 

357 anonymous type *universal_integer*: ``"*"`` of *universal_real* and *universal_integer*, ``"*"`` of 

358 *universal_integer* and *universal_real*, ``"/"`` of *universal_real* and *universal_integer* (IEEE Std 1076-2008, 

359 9.2.7). Its values convert implicitly to every other floating-point type (5.2.5.1, 9.3.6). 

360 """ 

361 

362 def __init__(self, *, parent: Nullable[ModelEntity] = None) -> None: 

363 """ 

364 Initializes the type *universal_real*. 

365 

366 Its range is ``-1.7976931348623157e308 to 1.7976931348623157e308``. 

367 

368 :param parent: Optional, the parent model entity, the package ``std.standard``. Default: ``None``, no parent. 

369 """ 

370 super().__init__("universal_real", SimpleRange( 

371 FloatingPointLiteral(-1.7976931348623157e308), 

372 FloatingPointLiteral(1.7976931348623157e308), 

373 Direction.To 

374 ), parent=parent) 

375 

376 def _CreateImplicitOperations(self) -> list[PredefinedOperation]: 

377 """ 

378 Create the operations this type declares implicitly: those of a floating-point type, then 

379 ``"*" (L : universal_real; R : universal_integer)``, ``"*" (L : universal_integer; R : universal_real)`` and 

380 ``"/" (L : universal_real; R : universal_integer)``, each returning *universal_real*. 

381 

382 :returns: List of predefined operators and predefined functions. 

383 """ 

384 operations = super()._CreateImplicitOperations() 

385 for operatorSymbol, left, right in ( 

386 ("*", self._TypeMark(), SimpleSubtypeSymbol(SimpleName("universal_integer"))), 

387 ("*", SimpleSubtypeSymbol(SimpleName("universal_integer")), self._TypeMark()), 

388 ("/", self._TypeMark(), SimpleSubtypeSymbol(SimpleName("universal_integer"))) 

389 ): 

390 operations.append(self._Operator( 

391 operatorSymbol, 

392 self._TypeMark(), 

393 (self._Parameter("L", left), self._Parameter("R", right)) 

394 )) 

395 

396 return operations 

397 

398 def IsImplicitlyConvertibleTo(self, targetType: BaseType) -> bool: 

399 """ 

400 Check if a value of *universal_real* converts implicitly to a type (IEEE Std 1076-2008, 5.2.5.1, 9.3.6). 

401 

402 It converts to every floating-point type, except *universal_real* itself. A subtype stands for its base type; a 

403 subtype, whose type mark isn't resolved, has none. 

404 

405 :param targetType: The type or subtype a context expects. 

406 :returns: ``True``, if the base type of the target is a floating-point type other than *universal_real*. 

407 :raises ValueError: If parameter 'targetType' is None. 

408 :raises TypeError: If parameter 'targetType' is not of type :class:`~pyVHDLModel.Type.BaseType`. 

409 """ 

410 if targetType is None: 

411 raise ValueError("Parameter 'targetType' is None.") 

412 elif not isinstance(targetType, BaseType): 

413 ex = TypeError("Parameter 'targetType' is not of type 'BaseType'.") 

414 ex.add_note(f"Got type '{getFullyQualifiedName(targetType)}'.") 

415 raise ex 

416 

417 baseType = targetType.BaseType 

418 return isinstance(baseType, RealType) and not isinstance(baseType, UniversalReal) 

419 

420 

421@export 

422class Standard(PredefinedPackage): 

423 """ 

424 Predefined package ``std.standard`` (IEEE Std 1076-2008, 16.3). 

425 

426 Its declarations, in the order of the standard: 

427 

428 * types ``boolean``, ``bit``, ``character``, ``severity_level``, ``integer``, ``real`` and ``time`` 

429 * subtype ``delay_length`` and function ``now`` 

430 * subtypes ``natural`` and ``positive`` 

431 * types ``string``, ``boolean_vector`` and ``bit_vector`` 

432 * aliases ``to_bstring``, ``to_binary_string`` (of ``to_string``), ``to_octal_string`` (of ``to_ostring``) and 

433 ``to_hex_string`` (of ``to_hstring``) of ``bit_vector``, e.g. ``alias TO_BSTRING is TO_STRING [BIT_VECTOR return 

434 STRING];`` 

435 * types ``integer_vector``, ``real_vector`` and ``time_vector`` 

436 * types ``file_open_kind`` and ``file_open_status`` 

437 * attribute ``foreign`` 

438 

439 With :data:`VHDLVersion.VHDL2019 <pyVHDLModel.VHDLVersion.VHDL2019>`, it declares the additions of IEEE Std 

440 1076-2019, 16.3: the type ``direction`` (named as in the IEEE package source; ``range_direction`` in the LRM) before 

441 ``boolean``, the literal ``read_write_mode`` after ``append_mode`` of ``file_open_kind`` and the types 

442 ``file_open_state`` and ``file_origin_kind`` after ``file_open_status``. Each scalar type, *universal_integer* and 

443 *universal_real* too, defines its range record (:attr:`~pyVHDLModel.Type.ScalarType.RangeRecord`, 5.3.3.2), e.g. 

444 ``boolean_range_record``: an implicit declaration following its type, visible by its name. 

445 

446 The types declare their predefined operations (:attr:`~pyVHDLModel.Type.FullType.ImplicitOperations`), ``real`` and 

447 ``time`` also the overloads of ``to_string`` (:class:`Real`, :class:`Time`), ``bit_vector`` also ``to_ostring`` and 

448 ``to_hstring`` (:class:`BitVector`). The implementation-defined ranges are GHDL's: ``integer`` has 32 bits, ``real`` 

449 is an IEEE 754 double, ``time`` counts femtoseconds in 64 bits. With VHDL-2019, ``integer`` has 64 bits, the range 

450 IEEE Std 1076-2019, 5.2.3.2 requires; ``natural`` and ``positive`` follow. 

451 

452 The anonymous types *universal_integer* (:class:`UniversalInteger`) and *universal_real* (:class:`UniversalReal`) 

453 aren't declarations: no name denotes them (:attr:`AnonymousTypes`). Their predefined operations are declarations of 

454 the package, which a use clause makes visible (:meth:`IterateDeclarations`). 

455 

456 With :data:`VHDLVersion.VHDL2019 <pyVHDLModel.VHDLVersion.VHDL2019>`, each array type, whose element type has a 

457 string representation, declares ``to_string``, e.g. ``string`` and ``integer_vector`` (IEEE Std 1076-2019, 5.3.2.4). 

458 

459 .. seealso:: 

460 

461 Matching :class:`Package Body <pyVHDLModel.STD.StandardPkg.Standard_Body>` declaration. 

462 """ 

463 

464 _anonymousTypes: dict[str, FullType] #: The anonymous types *universal_integer* and *universal_real*, by pseudo-name. 

465 

466 def __init__(self, vhdlVersion: VHDLVersion = VHDLVersion.VHDL2008) -> None: 

467 """ 

468 Initializes the ``standard`` package. 

469 

470 :param vhdlVersion: Optional, the VHDL version of the declarations. Default: ``VHDLVersion.VHDL2008``. 

471 :raises ValueError: If parameter 'vhdlVersion' is None. 

472 :raises TypeError: If parameter 'vhdlVersion' is not of type :class:`~pyVHDLModel.VHDLVersion`. 

473 :raises ValueError: If parameter 'vhdlVersion' is not a supported VHDL version (VHDL-2008, VHDL-2019). 

474 """ 

475 super().__init__(vhdlVersion) 

476 

477 self._anonymousTypes = { 

478 "universal_integer": UniversalInteger(parent=self), 

479 "universal_real": UniversalReal(parent=self) 

480 } 

481 

482 if vhdlVersion is VHDLVersion.VHDL2019: 

483 literals = "ascending", "descending" 

484 direction = EnumeratedType("direction", [EnumerationLiteral(literal) for literal in literals]) 

485 self._DeclareItem(direction, self._types) 

486 

487 self._DeclareItem(Boolean(), self._types) 

488 self._DeclareItem(Bit(), self._types) 

489 

490 controlCharacters = \ 

491 "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "lf", "vt", "ff", "cr", "so", "si", \ 

492 "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fsp", "gsp", "rsp", "usp" 

493 characters = [] 

494 for position in range(256): 

495 if position < 32: 

496 characters.append(EnumerationLiteral(controlCharacters[position])) 

497 elif position == 127: 

498 characters.append(EnumerationLiteral("del")) 

499 elif 128 <= position < 160: 

500 characters.append(EnumerationLiteral(f"c{position}")) 

501 else: 

502 characters.append(CharacterEnumerationLiteral(chr(position))) 

503 

504 self._DeclareItem(EnumeratedType("character", characters), self._types) 

505 

506 levels = "note", "warning", "error", "failure" 

507 self._DeclareItem(EnumeratedType("severity_level", [EnumerationLiteral(level) for level in levels]), self._types) 

508 

509 if vhdlVersion is VHDLVersion.VHDL2019: 

510 integerHigh = 2**63 - 1 

511 else: 

512 integerHigh = 2**31 - 1 

513 integerRange = SimpleRange(IntegerLiteral(-integerHigh - 1), IntegerLiteral(integerHigh), Direction.To) 

514 integer = IntegerType("integer", integerRange) 

515 self._DeclareItem(integer, self._types) 

516 

517 self._DeclareItem(Real(), self._types) 

518 

519 time = Time() 

520 self._DeclareItem(time, self._types) 

521 

522 delayLengthRange = SimpleRange( 

523 PhysicalIntegerLiteral(0, "fs"), 

524 PhysicalIntegerLiteral(2**63 - 1, "fs"), 

525 Direction.To 

526 ) 

527 delayLengthSymbol = ConstrainedScalarSubtypeSymbol(SimpleName("time"), delayLengthRange) 

528 delayLength = Subtype("delay_length", delayLengthSymbol) 

529 delayLength._baseType = time 

530 self._DeclareItem(delayLength, self._subtypes) 

531 

532 now = Function("now", self._TypeMark("delay_length"), isPure=False) 

533 self._DeclareSubprogram(now, self._functions) 

534 

535 for identifier, low in ( 

536 ("natural", 0), 

537 ("positive", 1) 

538 ): 

539 subtypeRange = SimpleRange(IntegerLiteral(low), IntegerLiteral(integerHigh), Direction.To) 

540 subtype = Subtype(identifier, ConstrainedScalarSubtypeSymbol(SimpleName("integer"), subtypeRange)) 

541 subtype._baseType = integer 

542 self._DeclareItem(subtype, self._subtypes) 

543 

544 self._DeclareItem(ArrayType("string", (self._TypeMark("positive"),), self._TypeMark("character")), self._types) 

545 self._DeclareItem(ArrayType("boolean_vector", (self._TypeMark("natural"),), self._TypeMark("boolean")), self._types) 

546 self._DeclareItem(BitVector(), self._types) 

547 for identifier, name in ( 

548 ("to_bstring", "to_string"), 

549 ("to_binary_string", "to_string"), 

550 ("to_octal_string", "to_ostring"), 

551 ("to_hex_string", "to_hstring") 

552 ): 

553 self._DeclareAlias(identifier, name, (self._TypeMark("bit_vector"), ), self._TypeMark("string")) 

554 

555 for identifier, element in ( 

556 ("integer_vector", "integer"), 

557 ("real_vector", "real"), 

558 ("time_vector", "time") 

559 ): 

560 self._DeclareItem(ArrayType(identifier, (self._TypeMark("natural"),), self._TypeMark(element)), self._types) 

561 

562 if vhdlVersion is VHDLVersion.VHDL2019: 

563 kinds = "read_mode", "write_mode", "append_mode", "read_write_mode" 

564 else: 

565 kinds = "read_mode", "write_mode", "append_mode" 

566 self._DeclareItem(EnumeratedType("file_open_kind", [EnumerationLiteral(kind) for kind in kinds]), self._types) 

567 

568 statuses = "open_ok", "status_error", "name_error", "mode_error" 

569 fileOpenStatus = EnumeratedType("file_open_status", [EnumerationLiteral(status) for status in statuses]) 

570 self._DeclareItem(fileOpenStatus, self._types) 

571 

572 if vhdlVersion is VHDLVersion.VHDL2019: 

573 for identifier, literals in ( 

574 ("file_open_state", ("state_open", "state_closed")), 

575 ("file_origin_kind", ("file_origin_begin", "file_origin_current", "file_origin_end")) 

576 ): 

577 enumeration = EnumeratedType(identifier, [EnumerationLiteral(literal) for literal in literals]) 

578 self._DeclareItem(enumeration, self._types) 

579 

580 self.AddDeclaredItem(Attribute("foreign", self._TypeMark("string"))) 

581 

582 @readonly 

583 def AnonymousTypes(self) -> dict[str, FullType]: 

584 """ 

585 Read-only property to access the anonymous types *universal_integer* and *universal_real* (:attr:`_anonymousTypes`). 

586 

587 They aren't declared items and no name denotes them (IEEE Std 1076-2008, 5.2.3.1, 5.2.5.1); the type marks of 

588 implicit operations name them by their pseudo-names 

589 (:meth:`~pyVHDLModel.Type.FullType.ResolveImplicitOperationTypeMarks`). 

590 

591 :returns: Dictionary of anonymous types, indexed by pseudo-name. 

592 """ 

593 return self._anonymousTypes 

594 

595 def IndexDeclaredItems(self) -> None: 

596 """ 

597 Index the declared items, then the range records of the anonymous types (:attr:`AnonymousTypes`) as implicit 

598 declarations (:meth:`~pyVHDLModel.Namespace.Namespace.AddImplicitDeclarations`), since VHDL-2019. 

599 

600 :raises UnhandledCriticalWarningError: If an identifier is declared twice in a declarative region and no 

601 :class:`~pyTooling.Warning.WarningCollector` collects the 

602 :exc:`~pyVHDLModel.Exception.DuplicateDeclarationWarning`. 

603 """ 

604 super().IndexDeclaredItems() 

605 

606 for anonymousType in self._anonymousTypes.values(): 

607 self._namespace.AddImplicitDeclarations(anonymousType) 

608 

609 def IterateDeclarations(self) -> Generator[ModelEntity, None, None]: 

610 """ 

611 Iterate the declarations of this package a use clause can make potentially visible: those of a package, then the 

612 predefined operations and the range record of each anonymous type (:attr:`AnonymousTypes`). 

613 

614 :returns: A generator to iterate the declarations, in declaration order. 

615 """ 

616 yield from super().IterateDeclarations() 

617 for anonymousType in self._anonymousTypes.values(): 

618 yield from anonymousType.ImplicitOperations 

619 yield from anonymousType.IterateImplicitDeclarations() 

620 

621 

622@export 

623class Standard_Body(PredefinedPackageBody): 

624 """ 

625 Predefined package body of package ``std.standard``. 

626 

627 .. seealso:: 

628 

629 Matching :class:`Package <pyVHDLModel.STD.StandardPkg.Standard>` declaration. 

630 """