Coverage for pyVHDLModel/Instantiation.py: 62%

48 statements  

« prev     ^ index     » next       coverage.py v7.15.1, created at 2026-07-13 17:58 +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 

35Instantiations of packages, procedures, functions and protected types. 

36""" 

37from typing import List, Optional as Nullable 

38 

39from pyTooling.Decorators import export, readonly 

40from pyTooling.MetaClasses import ExtendedType 

41 

42from pyVHDLModel import VHDLModelException 

43from pyVHDLModel.Base import ModelEntity 

44from pyVHDLModel.DesignUnit import Package 

45from pyVHDLModel.Association import GenericAssociationItem 

46from pyVHDLModel.Subprogram import Procedure, Function, Subprogram 

47from pyVHDLModel.Symbol import PackageReferenceSymbol 

48 

49 

50@export 

51class GenericInstantiationMixin(metaclass=ExtendedType, mixin=True): 

52 def __init__(self) -> None: 

53 pass 

54 

55 

56@export 

57class GenericEntityInstantiationMixin(GenericInstantiationMixin, mixin=True): 

58 def __init__(self) -> None: 

59 pass 

60 

61 

62@export 

63class SubprogramInstantiationMixin(GenericInstantiationMixin, mixin=True): 

64 _subprogramReference: Subprogram # FIXME: is this a subprogram symbol? 

65 

66 def __init__(self) -> None: 

67 super().__init__() 

68 self._subprogramReference = None 

69 

70 

71@export 

72class ProcedureInstantiation(Procedure, SubprogramInstantiationMixin): 

73 pass 

74 

75 

76@export 

77class FunctionInstantiation(Function, SubprogramInstantiationMixin): 

78 pass 

79 

80 

81@export 

82class PackageInstantiation(Package, GenericInstantiationMixin): # TODO: maybe a PackageBase class is needed to share members. 

83 _packageReference: PackageReferenceSymbol 

84 _genericAssociations: List[GenericAssociationItem] 

85 

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

87 super().__init__(identifier, documentation=documentation, parent=parent) 

88 GenericEntityInstantiationMixin.__init__(self) 

89 

90 self._packageReference = genericPackage 

91 self._packageReference.Parent = self 

92 

93 # TODO: extract to mixin 

94 self._genericAssociations = [] 

95 

96 @readonly 

97 def PackageReference(self) -> PackageReferenceSymbol: 

98 return self._packageReference 

99 

100 @readonly 

101 def GenericAssociations(self) -> List[GenericAssociationItem]: 

102 return self._genericAssociations 

103 

104 def Instantiate(self): 

105 genericPackage: Package = self._packageReference.Package 

106 if genericPackage is None: 

107 raise VHDLModelException(f"PackageInstantiation '{self.Identifier}' isn't linked to the generic package '{self._packageReference.Name}'.") 

108 

109 # TODO: components might need to be copied and derived 

110 for componentName, component in genericPackage._components.items(): 

111 self._components[componentName] = component 

112 

113 # FIXME: handle other package members