Coverage for pyVHDLModel / Declaration.py: 68%

80 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 

35 

36""" 

37from enum import unique, Enum 

38from typing import List, Iterable, Union, Optional as Nullable 

39 

40from pyTooling.Decorators import export, readonly 

41 

42from pyVHDLModel.Base import ModelEntity, NamedEntityMixin, DocumentedEntityMixin 

43from pyVHDLModel.Expression import BaseExpression, QualifiedExpression, FunctionCall, TypeConversion, Literal 

44from pyVHDLModel.Name import Name 

45from pyVHDLModel.Symbol import Symbol 

46 

47 

48 

49ExpressionUnion = Union[ 

50 BaseExpression, 

51 QualifiedExpression, 

52 FunctionCall, 

53 TypeConversion, 

54 # ConstantOrSymbol, TODO: ObjectSymbol 

55 Literal, 

56] 

57 

58 

59@export 

60@unique 

61class EntityClass(Enum): 

62 """An ``EntityClass`` is an enumeration. It represents a VHDL language entity class (``entity``, ``label``, ...).""" 

63 

64 Entity = 0 #: Entity 

65 Architecture = 1 #: Architecture 

66 Configuration = 2 #: Configuration 

67 Procedure = 3 #: Procedure 

68 Function = 4 #: Function 

69 Package = 5 #: Package 

70 Type = 6 #: Type 

71 Subtype = 7 #: Subtype 

72 Constant = 8 #: Constant 

73 Signal = 9 #: Signal 

74 Variable = 10 #: Variable 

75 Component = 11 #: Component 

76 Label = 12 #: Label 

77 Literal = 13 #: Literal 

78 Units = 14 #: Units 

79 Group = 15 #: Group 

80 File = 16 #: File 

81 Property = 17 #: Property 

82 Sequence = 18 #: Sequence 

83 View = 19 #: View 

84 Others = 20 #: Others 

85 

86 

87@export 

88class Attribute(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

89 """ 

90 Represents an attribute declaration. 

91 

92 .. admonition:: Example 

93 

94 .. code-block:: VHDL 

95 

96 attribute TotalBits : natural; 

97 """ 

98 

99 _subtype: Symbol 

100 

101 def __init__( 

102 self, 

103 identifier: str, 

104 subtype: Symbol, 

105 documentation: Nullable[str] = None, 

106 parent: ModelEntity = None 

107 ) -> None: 

108 super().__init__(parent) 

109 NamedEntityMixin.__init__(self, identifier) 

110 DocumentedEntityMixin.__init__(self, documentation) 

111 

112 self._subtype = subtype 

113 subtype._parent = self 

114 

115 @readonly 

116 def Subtype(self) -> None: 

117 return self._subtype 

118 

119 

120@export 

121class AttributeSpecification(ModelEntity, DocumentedEntityMixin): 

122 """ 

123 Represents an attribute specification. 

124 

125 .. admonition:: Example 

126 

127 .. code-block:: VHDL 

128 

129 attribute TotalBits of BusType : subtype is 32; 

130 """ 

131 

132 _identifiers: List[Name] 

133 _attribute: Name 

134 _entityClass: EntityClass 

135 _expression: ExpressionUnion 

136 

137 def __init__( 

138 self, 

139 identifiers: Iterable[Name], 

140 attribute: Name, 

141 entityClass: EntityClass, 

142 expression: ExpressionUnion, 

143 documentation: Nullable[str] = None, 

144 parent: ModelEntity = None 

145 ) -> None: 

146 super().__init__(parent) 

147 DocumentedEntityMixin.__init__(self, documentation) 

148 

149 self._identifiers = [] # TODO: convert to dict 

150 for identifier in identifiers: 

151 self._identifiers.append(identifier) 

152 identifier._parent = self 

153 

154 self._attribute = attribute 

155 attribute._parent = self 

156 

157 self._entityClass = entityClass 

158 

159 self._expression = expression 

160 expression._parent = self 

161 

162 @readonly 

163 def Identifiers(self) -> List[Name]: 

164 return self._identifiers 

165 

166 @readonly 

167 def Attribute(self) -> Name: 

168 return self._attribute 

169 

170 @readonly 

171 def EntityClass(self) -> EntityClass: 

172 return self._entityClass 

173 

174 @readonly 

175 def Expression(self) -> ExpressionUnion: 

176 return self._expression 

177 

178 

179# TODO: move somewhere else 

180@export 

181class Alias(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

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

183 """ 

184 Initializes underlying ``BaseType``. 

185 

186 :param identifier: Name of the type. 

187 """ 

188 super().__init__(parent) 

189 NamedEntityMixin.__init__(self, identifier) 

190 DocumentedEntityMixin.__init__(self, documentation)