Coverage for pyVHDLModel/Association.py: 61%

32 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 22:13 +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 

35Associations are used in generic maps, port maps and parameter maps. 

36""" 

37from typing import Optional as Nullable, Union 

38 

39from pyTooling.Decorators import export, readonly 

40 

41from pyVHDLModel.Base import ModelEntity 

42from pyVHDLModel.Symbol import Symbol 

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

44 

45 

46ExpressionUnion = Union[ 

47 BaseExpression, 

48 QualifiedExpression, 

49 FunctionCall, 

50 TypeConversion, 

51 # ConstantOrSymbol, TODO: ObjectSymbol 

52 Literal, 

53] 

54 

55 

56@export 

57class AssociationItem(ModelEntity): 

58 """ 

59 A base-class for all association items. 

60 """ 

61 

62 _formal: Nullable[Symbol] 

63 _actual: ExpressionUnion 

64 

65 def __init__(self, actual: ExpressionUnion, formal: Nullable[Symbol] = None) -> None: 

66 super().__init__() 

67 

68 self._formal = formal 

69 if formal is not None: 

70 formal._parent = self 

71 

72 self._actual = actual 

73 # actual._parent = self # FIXME: actual is provided as None 

74 

75 @readonly 

76 def Formal(self) -> Nullable[Symbol]: # TODO: can also be a conversion function !! 

77 return self._formal 

78 

79 @readonly 

80 def Actual(self) -> ExpressionUnion: 

81 return self._actual 

82 

83 def __str__(self) -> str: 

84 if self._formal is None: 

85 return str(self._actual) 

86 else: 

87 return f"{self._formal!s} => {self._actual!s}" 

88 

89 

90@export 

91class GenericAssociationItem(AssociationItem): 

92 """ 

93 A base-class for all generic association items used in generic map aspects. 

94 """ 

95 

96 

97@export 

98class PortAssociationItem(AssociationItem): 

99 """ 

100 A base-class for all port association items used in port map aspects. 

101 """ 

102 

103 

104@export 

105class ParameterAssociationItem(AssociationItem): 

106 """ 

107 A base-class for all parameter association items used in parameter map aspects. 

108 """