Coverage for pyVHDLModel/Common.py: 64%
52 statements
« prev ^ index » next coverage.py v7.6.7, created at 2024-11-22 22:15 +0000
« 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.
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
39from pyTooling.Decorators import export, readonly
40from pyTooling.MetaClasses import ExtendedType
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
48ExpressionUnion = Union[
49 BaseExpression,
50 QualifiedExpression,
51 FunctionCall,
52 TypeConversion,
53 # ConstantOrSymbol, TODO: ObjectSymbol
54 Literal,
55]
58@export
59class Statement(ModelEntity, LabeledEntityMixin):
60 """
61 A ``Statement`` is a base-class for all statements.
62 """
63 def __init__(self, label: Nullable[str] = None, parent=None) -> None:
64 super().__init__(parent)
65 LabeledEntityMixin.__init__(self, label)
68@export
69class ProcedureCallMixin(metaclass=ExtendedType, mixin=True):
70 _procedure: Symbol # TODO: implement a ProcedureSymbol
71 _parameterMappings: List[ParameterAssociationItem]
73 def __init__(self, procedureName: Symbol, parameterMappings: Nullable[Iterable[ParameterAssociationItem]] = None) -> None:
74 self._procedure = procedureName
75 procedureName._parent = self
77 # TODO: extract to mixin
78 self._parameterMappings = []
79 if parameterMappings is not None:
80 for parameterMapping in parameterMappings:
81 self._parameterMappings.append(parameterMapping)
82 parameterMapping._parent = self
84 @readonly
85 def Procedure(self) -> Symbol:
86 return self._procedure
88 @property
89 def ParameterMappings(self) -> List[ParameterAssociationItem]:
90 return self._parameterMappings
93@export
94class AssignmentMixin(metaclass=ExtendedType, mixin=True):
95 """A mixin-class for all assignment statements."""
97 _target: Symbol
99 def __init__(self, target: Symbol) -> None:
100 self._target = target
101 target._parent = self
103 @property
104 def Target(self) -> Symbol:
105 return self._target
108@export
109class SignalAssignmentMixin(AssignmentMixin, mixin=True):
110 """A mixin-class for all signal assignment statements."""
113@export
114class VariableAssignmentMixin(AssignmentMixin, mixin=True):
115 """A mixin-class for all variable assignment statements."""
117 # FIXME: move to sequential?
118 _expression: ExpressionUnion
120 def __init__(self, target: Symbol, expression: ExpressionUnion) -> None:
121 super().__init__(target)
123 self._expression = expression
124 expression._parent = self
126 @property
127 def Expression(self) -> ExpressionUnion:
128 return self._expression