Coverage for pyVHDLModel/Subprogram.py: 66%

68 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-10 23:46 +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 

35Subprograms are procedures, functions and methods. 

36""" 

37from typing import List, Optional as Nullable 

38 

39from pyTooling.Decorators import export, readonly 

40from pyTooling.MetaClasses import ExtendedType 

41 

42from pyVHDLModel.Base import ModelEntity, NamedEntityMixin, DocumentedEntityMixin 

43from pyVHDLModel.Type import Subtype, ProtectedType 

44from pyVHDLModel.Sequential import SequentialStatement 

45 

46 

47@export 

48class Subprogram(ModelEntity, NamedEntityMixin, DocumentedEntityMixin): 

49 _genericItems: List['GenericInterfaceItem'] 

50 _parameterItems: List['ParameterInterfaceItem'] 

51 _declaredItems: List 

52 _statements: List['SequentialStatement'] 

53 _isPure: bool 

54 

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

56 super().__init__(parent) 

57 NamedEntityMixin.__init__(self, identifier) 

58 DocumentedEntityMixin.__init__(self, documentation) 

59 

60 self._genericItems = [] # TODO: convert to dict 

61 self._parameterItems = [] # TODO: convert to dict 

62 self._declaredItems = [] # TODO: use mixin class 

63 self._statements = [] # TODO: use mixin class 

64 self._isPure = isPure 

65 

66 @readonly 

67 def GenericItems(self) -> List['GenericInterfaceItem']: 

68 return self._genericItems 

69 

70 @readonly 

71 def ParameterItems(self) -> List['ParameterInterfaceItem']: 

72 return self._parameterItems 

73 

74 @readonly 

75 def DeclaredItems(self) -> List: 

76 return self._declaredItems 

77 

78 @readonly 

79 def Statements(self) -> List['SequentialStatement']: 

80 return self._statements 

81 

82 @readonly 

83 def IsPure(self) -> bool: 

84 return self._isPure 

85 

86 

87@export 

88class Procedure(Subprogram): 

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

90 super().__init__(identifier, False, documentation, parent) 

91 

92 

93@export 

94class Function(Subprogram): 

95 _returnType: Subtype 

96 

97 def __init__(self, identifier: str, isPure: bool = True, documentation: Nullable[str] = None, parent: ModelEntity = None) -> None: 

98 super().__init__(identifier, isPure, documentation, parent) 

99 

100 # FIXME: return type is missing 

101 

102 @readonly 

103 def ReturnType(self) -> Subtype: 

104 return self._returnType 

105 

106 

107@export 

108class MethodMixin(metaclass=ExtendedType, mixin=True): 

109 """A ``Method`` is a mixin class for all subprograms in a protected type.""" 

110 

111 _protectedType: ProtectedType 

112 

113 def __init__(self, protectedType: ProtectedType) -> None: 

114 self._protectedType = protectedType 

115 protectedType._parent = self 

116 

117 @readonly 

118 def ProtectedType(self) -> ProtectedType: 

119 return self._protectedType 

120 

121 

122@export 

123class ProcedureMethod(Procedure, MethodMixin): 

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

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

126 MethodMixin.__init__(self, protectedType) 

127 

128 

129@export 

130class FunctionMethod(Function, MethodMixin): 

131 def __init__(self, identifier: str, isPure: bool = True, documentation: Nullable[str] = None, protectedType: Nullable[ProtectedType] = None, parent: ModelEntity = None) -> None: 

132 super().__init__(identifier, isPure, documentation, parent) 

133 MethodMixin.__init__(self, protectedType)