Coverage for pyVHDLModel / Common.py: 72%

65 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-24 22:37 +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 

35Common definitions and Mixins are used by many classes in the model as base-classes. 

36""" 

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

38 

39from pyTooling.Decorators import export, readonly 

40from pyTooling.MetaClasses import ExtendedType 

41 

42from pyVHDLModel.Base import ModelEntity, LabeledEntityMixin 

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

44from pyVHDLModel.Symbol import Symbol 

45from pyVHDLModel.Association import ParameterAssociationItem 

46 

47 

48ExpressionUnion = Union[ 

49 BaseExpression, 

50 QualifiedExpression, 

51 FunctionCall, 

52 TypeConversion, 

53 # ConstantOrSymbol, TODO: ObjectSymbol 

54 Literal, 

55] 

56 

57 

58@export 

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

60 _allowBlackbox: Nullable[bool] #: Allow blackboxes for components in language entity. 

61 

62 def __init__(self, allowBlackbox: Nullable[bool] = None) -> None: 

63 self._allowBlackbox = allowBlackbox 

64 

65 @property 

66 def AllowBlackbox(self) -> bool: 

67 """ 

68 Read-only property to check if a design supports blackboxes (:attr:`_allowBlackbox`). 

69 

70 .. rubric:: Algorithm 

71 

72 1. If allow blackbox property is locally set, return the local value, 

73 2. Otherwise, return allow blackbox value from parent object. 

74 

75 :returns: If blackboxes are allowed. 

76 """ 

77 if self._allowBlackbox is None: 

78 return self._parent.AllowBlackbox 

79 else: 

80 return self._allowBlackbox 

81 

82 @AllowBlackbox.setter 

83 def AllowBlackbox(self, value: Nullable[bool]) -> None: 

84 self._allowBlackbox = value 

85 

86 

87@export 

88class Statement(ModelEntity, LabeledEntityMixin): 

89 """ 

90 A ``Statement`` is a base-class for all statements. 

91 """ 

92 def __init__(self, label: Nullable[str] = None, parent=None) -> None: 

93 super().__init__(parent) 

94 LabeledEntityMixin.__init__(self, label) 

95 

96 

97@export 

98class ProcedureCallMixin(metaclass=ExtendedType, mixin=True): 

99 _procedure: Symbol # TODO: implement a ProcedureSymbol 

100 _parameterMappings: List[ParameterAssociationItem] 

101 

102 def __init__(self, procedureName: Symbol, parameterMappings: Nullable[Iterable[ParameterAssociationItem]] = None) -> None: 

103 self._procedure = procedureName 

104 procedureName._parent = self 

105 

106 # TODO: extract to mixin 

107 self._parameterMappings = [] 

108 if parameterMappings is not None: 

109 for parameterMapping in parameterMappings: 

110 self._parameterMappings.append(parameterMapping) 

111 parameterMapping._parent = self 

112 

113 @readonly 

114 def Procedure(self) -> Symbol: 

115 return self._procedure 

116 

117 @property 

118 def ParameterMappings(self) -> List[ParameterAssociationItem]: 

119 return self._parameterMappings 

120 

121 

122@export 

123class AssignmentMixin(metaclass=ExtendedType, mixin=True): 

124 """A mixin-class for all assignment statements.""" 

125 

126 _target: Symbol 

127 

128 def __init__(self, target: Symbol) -> None: 

129 self._target = target 

130 target._parent = self 

131 

132 @property 

133 def Target(self) -> Symbol: 

134 return self._target 

135 

136 

137@export 

138class SignalAssignmentMixin(AssignmentMixin, mixin=True): 

139 """A mixin-class for all signal assignment statements.""" 

140 

141 

142@export 

143class VariableAssignmentMixin(AssignmentMixin, mixin=True): 

144 """A mixin-class for all variable assignment statements.""" 

145 

146 # FIXME: move to sequential? 

147 _expression: ExpressionUnion 

148 

149 def __init__(self, target: Symbol, expression: ExpressionUnion) -> None: 

150 super().__init__(target) 

151 

152 self._expression = expression 

153 expression._parent = self 

154 

155 @property 

156 def Expression(self) -> ExpressionUnion: 

157 return self._expression