Coverage for pyVHDLModel/Instantiation.py: 77%

43 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 22:15 +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 

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.Base import ModelEntity 

43from pyVHDLModel.DesignUnit import PrimaryUnit 

44from pyVHDLModel.Association import GenericAssociationItem 

45from pyVHDLModel.Subprogram import Procedure, Function, Subprogram 

46from pyVHDLModel.Symbol import PackageReferenceSymbol 

47 

48 

49@export 

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

51 def __init__(self) -> None: 

52 pass 

53 

54 

55@export 

56class GenericEntityInstantiationMixin(GenericInstantiationMixin, mixin=True): 

57 def __init__(self) -> None: 

58 pass 

59 

60 

61@export 

62class SubprogramInstantiationMixin(GenericInstantiationMixin, mixin=True): 

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

64 

65 def __init__(self) -> None: 

66 super().__init__() 

67 self._subprogramReference = None 

68 

69 

70@export 

71class ProcedureInstantiation(Procedure, SubprogramInstantiationMixin): 

72 pass 

73 

74 

75@export 

76class FunctionInstantiation(Function, SubprogramInstantiationMixin): 

77 pass 

78 

79 

80@export 

81class PackageInstantiation(PrimaryUnit, GenericInstantiationMixin): 

82 _packageReference: PackageReferenceSymbol 

83 _genericAssociations: List[GenericAssociationItem] 

84 

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

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

87 GenericEntityInstantiationMixin.__init__(self) 

88 

89 self._packageReference = uninstantiatedPackage 

90 # uninstantiatedPackage._parent = self # FIXME: uninstantiatedPackage is provided as int 

91 

92 # TODO: extract to mixin 

93 self._genericAssociations = [] 

94 

95 @readonly 

96 def PackageReference(self) -> PackageReferenceSymbol: 

97 return self._packageReference 

98 

99 @readonly 

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

101 return self._genericAssociations