# ==================================================================================================================== #
# __ ___ _ ____ _ __ __ _ _ #
# _ __ _ \ \ / / | | | _ \| | | \/ | ___ __| | ___| | #
# | '_ \| | | \ \ / /| |_| | | | | | | |\/| |/ _ \ / _` |/ _ \ | #
# | |_) | |_| |\ V / | _ | |_| | |___| | | | (_) | (_| | __/ | #
# | .__/ \__, | \_/ |_| |_|____/|_____|_| |_|\___/ \__,_|\___|_| #
# |_| |___/ #
# ==================================================================================================================== #
# Authors: #
# Patrick Lehmann #
# #
# License: #
# ==================================================================================================================== #
# Copyright 2017-2026 Patrick Lehmann - Boetzingen, Germany #
# Copyright 2016-2017 Patrick Lehmann - Dresden, Germany #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
# SPDX-License-Identifier: Apache-2.0 #
# ==================================================================================================================== #
#
"""
This module contains parts of an abstract document language model for VHDL.
Symbols are entity specific wrappers for names that reference VHDL language entities.
"""
from __future__ import annotations
from enum import Flag
from typing import TYPE_CHECKING, Any, Optional as Nullable, Iterable, Mapping, Self
from pyTooling.Common import getFullyQualifiedName, getTypeName
from pyTooling.Decorators import export, notimplemented, readonly
from pyTooling.MetaClasses import ExtendedType, abstractclass
from pyVHDLModel.Base import ModelEntity, Range
from pyVHDLModel.Name import Name, AllName
if TYPE_CHECKING:
from pyVHDLModel.Visitor import Visitor
@export
class PossibleReference(Flag):
"""
Is an enumeration, representing possible targets for a reference in a :class:`~pyVHDLModel.Symbol.Symbol`.
"""
Unknown = 0
Library = 1 #: Library
Entity = 2 #: Entity
Architecture = 4 #: Architecture
Component = 8 #: Component
Package = 16 #: Package
Configuration = 32 #: Configuration
Context = 64 #: Context
Type = 128 #: Type
Subtype = 256 #: Subtype
ScalarType = 512 #: ScalarType
ArrayType = 1024 #: ArrayType
RecordType = 2048 #: RecordType
RecordElement = 4096 #: RecordElement
AccessType = 8192 #: AccessType
ProtectedType = 16384 #: ProtectedType
FileType = 32768 #: FileType
# Alias = auto() # TODO: Is this needed?
Attribute = 65536 #: Attribute
TypeAttribute = 131072 #: TypeAttribute
ValueAttribute = 262144 #: ValueAttribute
SignalAttribute = 524288 #: SignalAttribute
RangeAttribute = 1048576 #: RangeAttribute
ViewAttribute = 2097152 #: ViewAttribute
Constant = 4194304 #: Constant
Variable = 8388608 #: Variable
Signal = 16777216 #: Signal
File = 33554432 #: File
# Object = auto() # TODO: Is this needed?
EnumLiteral = 67108864 #: EnumLiteral
Procedure = 134217728 #: Procedure
Function = 268435456 #: Function
Label = 536870912 #: Label
View = 1073741824 #: View
AnyType = ScalarType | ArrayType | RecordType | ProtectedType | AccessType | FileType | Subtype #: Any possible type incl. subtypes.
Object = Constant | Variable | Signal # | File #: Any object
SubProgram = Procedure | Function #: Any subprogram
PackageMember = AnyType | Object | SubProgram | Component #: Any member of a package
SimpleNameInExpression = Constant | Variable | Signal | ScalarType | EnumLiteral | Function #: Any possible item in an expression.
@export
class Symbol(ModelEntity):
"""
Base-class for all symbol classes.
A symbol is a model entity: its parent is the model entity using it, e.g. a statement, an expression or a
declaration. A symbol is the parent of its name.
"""
_name: Name #: The name to reference the language entity.
_possibleReferences: PossibleReference #: An enumeration to filter possible references.
_reference: Nullable[Any] #: The resolved language entity, otherwise ``None``.
def __init__(
self,
name: Name,
possibleReferences: PossibleReference,
*,
parent: Nullable[ModelEntity] = None
) -> None:
"""
Initializes a symbol.
:param name: The name to reference the language entity.
:param possibleReferences: An enumeration to filter possible references.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(parent)
self._name = name
self._possibleReferences = possibleReferences
self._reference = None
if name is not None:
name.Parent = self
@readonly
def Name(self) -> Name:
"""
Read-only property to access the name (:attr:`_name`).
:returns: The name.
"""
return self._name
@readonly
def Reference(self) -> Nullable[Any]:
"""
Read-only property to access the reference (:attr:`_reference`).
:returns: The reference, or ``None`` if not set.
"""
return self._reference
@readonly
def IsResolved(self) -> bool:
"""
Check if the symbol is resolved, i.e. :attr:`_reference` is set.
:returns: ``True``, if the symbol is resolved.
"""
return self._reference is not None
[docs]
def __bool__(self) -> bool:
"""
Reports whether this symbol has been resolved.
:returns: ``True`` if the symbol references a model entity.
"""
return self._reference is not None
[docs]
def Copy(self) -> Self:
"""
Create a copy of this symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new symbol.
"""
copy = self.__class__(self._name.Copy(), self._possibleReferences)
copy._reference = self._reference
return copy
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this symbol and its name with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitSymbol(self)
self._name.Visit(visitor)
visitor.DepartSymbol(self)
[docs]
def __repr__(self) -> str:
"""
Formats a representation of the symbol.
**Format:** ``SignalSymbol: 'clk' -> <signal>``, or ``... -> ?`` while unresolved
:returns: String representation of the symbol.
"""
if self._reference is not None:
return f"{getTypeName(self)}: '{self._name!s}' -> {self._reference!s}"
return f"{getTypeName(self)}: '{self._name!s}' -> unresolved"
[docs]
def __str__(self) -> str:
"""
Formats the symbol.
**Format:** the referenced model entity once resolved, else the name plus ``?``
:returns: Formatted symbol.
"""
if self._reference is not None:
return str(self._reference)
return f"{self._name!s}?"
@export
class LibraryReferenceSymbol(Symbol):
"""
Represents a reference (name) to a library.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName`.
.. admonition:: Example
.. code-block:: VHDL
library ieee;
-- ^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to a library.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Library, parent=parent)
@property
def Library(self) -> Nullable[Library]:
"""
Property to access the library (:attr:`_reference`).
:returns: The library, or ``None`` if not set.
"""
return self._reference
@Library.setter
def Library(self, value: Library) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this library reference symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new library reference symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class PackageReferenceSymbol(Symbol):
"""
Represents a reference (name) to a package.
The internal name will be a :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
use ieee.numeric_std;
-- ^^^^^^^^^^^^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to a package.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Package, parent=parent)
@property
def Package(self) -> Nullable[Package]:
"""
Property to access the package (:attr:`_reference`).
:returns: The package, or ``None`` if not set.
"""
return self._reference
@Package.setter
def Package(self, value: Package) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this package reference symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new package reference symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class ModeViewSymbol(Symbol):
"""
Represents a reference to a mode view (VHDL-2019).
The referenced mode view is available as :data:`Reference` once resolved. A reference may also
select the converse view.
.. admonition:: Example
Referencing a mode view:
.. code-block:: VHDL
port (p : view MasterView);
-- ^^^^^^^^^^ <- Name
Referencing its converse:
.. code-block:: VHDL
port (p : view MasterView'converse);
-- ^^^^^^^^^^^^^^^^^^^ <- Name
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference to a mode view (VHDL-2019).
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.View, parent=parent)
@property
def ModeView(self) -> Nullable[ModeViewDeclaration]:
"""
Property to access the mode view (:attr:`_reference`).
:returns: The mode view, or ``None`` if not set.
"""
return self._reference
@ModeView.setter
def ModeView(self, value: ModeViewDeclaration) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this mode view symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new mode view symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class SubprogramReferenceSymbol(Symbol):
"""
Represents a reference to a subprogram.
The referenced subprogram is available as :data:`Reference` once resolved.
.. admonition:: Example
.. code-block:: VHDL
function f is new gen_fun generic map (N => 1);
-- ^^^^^^^ <- Name
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference to a subprogram.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.SubProgram, parent=parent)
@property
def Subprogram(self) -> Nullable[Subprogram]:
"""
Property to access the subprogram (:attr:`_reference`).
:returns: The subprogram, or ``None`` if not set.
"""
return self._reference
@Subprogram.setter
def Subprogram(self, value: Subprogram) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this subprogram reference symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new subprogram reference symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class ConfigurationSymbol(Symbol):
"""
Represents a reference to a configuration.
The referenced configuration is available as :data:`Reference` once resolved.
.. admonition:: Example
.. code-block:: VHDL
for U1 : comp use configuration work.cfg;
-- ^^^^^^^^ <- Name
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference to a configuration.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Configuration, parent=parent)
@property
def Configuration(self) -> Nullable[Configuration]:
"""
Property to access the configuration (:attr:`_reference`).
:returns: The configuration, or ``None`` if not set.
"""
return self._reference
@Configuration.setter
def Configuration(self, value: Configuration) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this configuration symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new configuration symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class VariableSymbol(Symbol):
"""
Represents a reference (name) to a variable.
The target of a variable assignment is such a reference.
.. admonition:: Example
.. code-block:: VHDL
v := '1';
--^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a variable symbol.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Variable, parent=parent)
@property
def Variable(self) -> Nullable[Variable]:
"""
Property to access the variable (:attr:`_reference`).
:returns: The variable, or ``None`` if not set.
"""
return self._reference
@Variable.setter
def Variable(self, value: Variable) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this variable symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new variable symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class SignalSymbol(Symbol):
"""
Represents a reference (name) to a signal.
The target of a signal assignment is such a reference.
.. admonition:: Example
.. code-block:: VHDL
s <= '1';
--^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a signal symbol.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Signal, parent=parent)
@property
def Signal(self) -> Nullable[Signal]:
"""
Property to access the signal (:attr:`_reference`).
:returns: The signal, or ``None`` if not set.
"""
return self._reference
@Signal.setter
def Signal(self, value: Signal) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this signal symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new signal symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class AggregateSymbol(Symbol):
"""
Represents a group of targets written as an aggregate on the left-hand side of an assignment.
VHDL's grammar calls it an aggregate (``target ::= name | aggregate``), but it decomposes the assigned value into its
targets: each element is a target itself, e.g. a variable or a signal, never a constant. The group has no name of its
own (:attr:`~pyVHDLModel.Symbol.Symbol.Name` is ``None``); its targets are available as :data:`Targets`, the group
is their parent.
.. admonition:: Example
.. code-block:: VHDL
(carry, sum) := add(a, b);
-- ^^^^^^^^^^^^ <- the aggregate symbol
-- ^^^^^ ^^^ <- Targets
"""
_targets: list[Symbol] #: List of the targets, in source order.
def __init__(self, targets: Iterable[Symbol], *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a group of targets.
:param targets: The targets, in source order.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
:raises ValueError: If parameter 'targets' is None.
:raises TypeError: If parameter 'targets' is not iterable.
:raises TypeError: If a target in parameter 'targets' is not a :class:`Symbol`.
:raises ValueError: If parameter 'targets' has fewer than two targets (one would read as parentheses). |br|
A single target in parentheses is no aggregate; use the target's symbol.
"""
super().__init__(None, PossibleReference.Unknown, parent=parent)
if targets is None:
raise ValueError("Parameter 'targets' is None.")
elif not isinstance(targets, Iterable):
ex = TypeError("Parameter 'targets' is not iterable.")
ex.add_note(f"Got type '{getFullyQualifiedName(targets)}'.")
raise ex
self._targets = targetList = []
possibleReferences = PossibleReference.Unknown
for target in targets:
if not isinstance(target, Symbol):
ex = TypeError("Target in parameter 'targets' is not of type 'Symbol'.")
ex.add_note(f"Got type '{getFullyQualifiedName(target)}'.")
raise ex
targetList.append(target)
possibleReferences |= target._possibleReferences
if len(targetList) < 2:
ex = ValueError("Parameter 'targets' has fewer than two targets.")
ex.add_note(f"Got {len(targetList)} target(s).")
ex.add_note("A single target in parentheses is no aggregate; use the target's symbol.")
raise ex
self._possibleReferences = possibleReferences
for target in targetList:
target.Parent = self
@readonly
def Targets(self) -> list[Symbol]:
"""
Read-only property to access the targets (:attr:`_targets`).
:returns: List of the targets, in source order.
"""
return self._targets
@readonly
def IsResolved(self) -> bool:
"""
Check if every target of the group is resolved.
:returns: ``True``, if every target is resolved.
"""
return all(target.IsResolved for target in self._targets)
[docs]
def __bool__(self) -> bool:
"""
Check if every target of the group is resolved.
:returns: ``True``, if every target is resolved.
"""
return self.IsResolved
[docs]
def Copy(self) -> Self:
"""
Create a copy of this group of targets.
The copy has no parent. Its targets are copies of this group's targets.
:returns: The new group of targets.
"""
return self.__class__([target.Copy() for target in self._targets])
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this group of targets and its targets with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitAggregateSymbol(self)
for index, target in enumerate(self._targets):
if index > 0:
visitor.VisitElementSeparator(self)
target.Visit(visitor)
visitor.DepartAggregateSymbol(self)
[docs]
def __repr__(self) -> str:
"""
Formats a representation of the group of targets.
**Format:** ``AggregateSymbol: (VariableSymbol: 'carry' -> unresolved, ...)``
:returns: String representation of the group of targets.
"""
return f"{getTypeName(self)}: ({', '.join(repr(target) for target in self._targets)})"
[docs]
def __str__(self) -> str:
"""
Formats the group of targets.
**Format:** ``(carry?, sum?)``
:returns: Formatted group of targets.
"""
return f"({', '.join(str(target) for target in self._targets)})"
@export
class ContextReferenceSymbol(Symbol):
"""
Represents a reference (name) to a context.
The internal name will be a :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
context ieee.ieee_std_context;
-- ^^^^^^^^^^^^^^^^^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to a context.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Context, parent=parent)
@property
def Context(self) -> Context:
"""
Property to access the context (:attr:`_reference`).
:returns: The context.
"""
return self._reference
@Context.setter
def Context(self, value: Context) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this context reference symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new context reference symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class PackageMemberReferenceSymbol(Symbol):
"""
Represents a reference (name) to a package member.
The internal name will be a :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
use ieee.numeric_std.unsigned;
-- ^^^^^^^^^^^^^^^^^^^^^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to a package member.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.PackageMember, parent=parent)
@property
def Member(self) -> Nullable[Package]: # TODO: typehint
"""
Property to access the member (:attr:`_reference`).
:returns: The member, or ``None`` if not set.
"""
return self._reference
@Member.setter
def Member(self, value: Package) -> None: # TODO: typehint
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this package member reference symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new package member reference symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class AllPackageMembersReferenceSymbol(Symbol):
"""
Represents a reference (name) to all package members.
The internal name will be a :class:`~pyVHDLModel.Name.AllName`.
.. admonition:: Example
.. code-block:: VHDL
use ieee.numeric_std.all;
-- ^^^^^^^^^^^^^^^^^^^^
"""
def __init__(self, name: AllName, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to all package members.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.PackageMember, parent=parent)
@property
def Members(self) -> Package: # TODO: typehint
"""
Property to access the members (:attr:`_reference`).
:returns: The members.
"""
return self._reference
@Members.setter
def Members(self, value: Package) -> None: # TODO: typehint
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this all package members reference symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new all package members reference symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class EntityInstantiationSymbol(Symbol):
"""
Represents a reference (name) to an entity in a direct entity instantiation.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName` or :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
inst : entity work.Counter;
-- ^^^^^^^^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to an entity in a direct entity instantiation.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Entity, parent=parent)
@property
def Entity(self) -> Entity:
"""
Property to access the entity (:attr:`_reference`).
:returns: The entity.
"""
return self._reference
@Entity.setter
def Entity(self, value: Entity) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this entity instantiation symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new entity instantiation symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class ComponentInstantiationSymbol(Symbol):
"""
Represents a reference (name) to an entity in a component instantiation.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName` or :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
inst : component Counter;
-- ^^^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to an entity in a component instantiation.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Component, parent=parent)
@property
def Component(self) -> Component:
"""
Property to access the component (:attr:`_reference`).
:returns: The component.
"""
return self._reference
@Component.setter
def Component(self, value: Component) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this component instantiation symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new component instantiation symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class ConfigurationInstantiationSymbol(Symbol):
"""
Represents a reference (name) to an entity in a configuration instantiation.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName` or :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
inst : configuration Counter;
-- ^^^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to an entity in a configuration instantiation.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Configuration, parent=parent)
@property
def Configuration(self) -> Configuration:
"""
Property to access the configuration (:attr:`_reference`).
:returns: The configuration.
"""
return self._reference
@Configuration.setter
def Configuration(self, value: Configuration) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this configuration instantiation symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new configuration instantiation symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class EntitySymbol(Symbol):
"""
Represents a reference (name) to an entity in an architecture declaration.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName` or :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
architecture rtl of Counter is
-- ^^^^^^^
begin
end architecture;
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to an entity in an architecture declaration.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Entity, parent=parent)
@property
def Entity(self) -> Entity:
"""
Property to access the entity (:attr:`_reference`).
:returns: The entity.
"""
return self._reference
@Entity.setter
def Entity(self, value: Entity) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this entity symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new entity symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class ArchitectureSymbol(Symbol):
"""An entity reference in an entity instantiation with architecture name."""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes an architecture symbol.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Architecture, parent=parent)
@property
def Architecture(self) -> Architecture:
"""
Property to access the architecture (:attr:`_reference`).
:returns: The architecture.
"""
return self._reference
@Architecture.setter
def Architecture(self, value: Architecture) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this architecture symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new architecture symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class PackageSymbol(Symbol):
"""
Represents a reference (name) to a package in a package body declaration.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName` or :class:`~pyVHDLModel.Name.SelectedName`.
.. admonition:: Example
.. code-block:: VHDL
package body Utilities is
-- ^^^^^^^^^
end package body;
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (name) to a package in a package body declaration.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Package, parent=parent)
@property
def Package(self) -> Package:
"""
Property to access the package (:attr:`_reference`).
:returns: The package.
"""
return self._reference
@Package.setter
def Package(self, value: Package) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this package symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new package symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class LoopSymbol(Symbol):
"""
Represents a reference (label) to a loop statement in a next or exit statement.
The internal name will be a :class:`~pyVHDLModel.Name.SimpleName`.
.. admonition:: Example
.. code-block:: VHDL
next outer when k = 1;
-- ^^^^^
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference (label) to a loop statement in a next or exit statement.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Label, parent=parent)
@property
def Loop(self) -> Nullable[LoopStatement]:
"""
Property to access the loop statement (:attr:`_reference`).
:returns: The loop statement, or ``None`` if not set.
"""
return self._reference
@Loop.setter
def Loop(self, value: LoopStatement) -> None:
self._reference = value
[docs]
def Copy(self) -> Self:
"""
Create a copy of this loop symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new loop symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class RecordElementSymbol(Symbol):
"""
Represents a reference to a record element.
The referenced language entity is available as :data:`Reference` once resolved.
.. admonition:: Example
.. code-block:: VHDL
r := (a => '1', b => '0');
-- ^ <- Name
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference to a record element.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.RecordElement, parent=parent)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this record element symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new record element symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class RangeAttributeSymbol(Symbol):
"""
A symbol referencing a range attribute.
``vector'range`` is such a reference.
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initialize a range attribute symbol.
:param name: The attribute name referencing the range.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.RangeAttribute, parent=parent)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this range attribute symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new range attribute symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class SubtypeSymbol(Symbol):
"""
Represents the base-class of all references to a type or subtype.
The referenced language entity is available as :data:`Reference` once resolved.
.. seealso::
* :class:`Simple subtype symbol <pyVHDLModel.Symbol.SimpleSubtypeSymbol>`
* :class:`Constrained scalar subtype symbol <pyVHDLModel.Symbol.ConstrainedScalarSubtypeSymbol>`
* :class:`Constrained composite subtype symbol <pyVHDLModel.Symbol.ConstrainedCompositeSubtypeSymbol>`
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a subtype symbol.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.Type | PossibleReference.Subtype, parent=parent)
@readonly
def TypeMark(self) -> str:
"""
Read-only property to return the type mark's name, as written: its identifiers joined by dots.
A simple name gives its identifier (``natural``), a selected name the identifiers of its prefixes too
(``ieee.numeric_std.unsigned``). The model doesn't resolve type marks yet, so this isn't the fully qualified name of
the denoted type.
:returns: The type mark's name.
"""
name = self._name
identifiers = [name._identifier]
while name._prefix is not None:
name = name._prefix
identifiers.append(name._identifier)
return ".".join(reversed(identifiers))
@property
def Subtype(self) -> Subtype:
"""
Property to access the subtype (:attr:`_reference`).
:returns: The subtype.
"""
return self._reference
@Subtype.setter
def Subtype(self, value: Subtype) -> None:
self._reference = value
def Copy(self) -> Self:
"""
Create a copy of this subtype symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new subtype symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class SimpleSubtypeSymbol(SubtypeSymbol):
"""
Represents a reference to a type or subtype by its type mark.
The referenced language entity is available as :data:`Reference` once resolved.
.. admonition:: Example
.. code-block:: VHDL
signal s : bit := '0';
-- ^^^ <- Name
"""
pass
@export
class Constraint(metaclass=ExtendedType, mixin=True):
"""
A mixin-class for symbols and element constraints carrying a constraint.
.. seealso::
* :class:`Scalar constraint <pyVHDLModel.Symbol.ScalarConstraint>`
* :class:`Array constraint <pyVHDLModel.Symbol.ArrayConstraint>`
* :class:`Record constraint <pyVHDLModel.Symbol.RecordConstraint>`
"""
pass
@export
class ScalarConstraint(Constraint, mixin=True):
"""
A mixin-class for a scalar constraint: a range.
The range is available as :data:`Constraint`.
.. seealso::
* :class:`Constrained scalar subtype symbol <pyVHDLModel.Symbol.ConstrainedScalarSubtypeSymbol>`
"""
_constraint: Range #: The range constraining the scalar subtype.
def __init__(self, constraint: Range) -> None:
"""
Initializes a scalar constraint.
:param constraint: The range constraining the scalar subtype.
"""
self._constraint = constraint
constraint.Parent = self
@readonly
def Constraint(self) -> Range:
"""
Read-only property to access the scalar type's range constraint (:attr:`_constraint`).
:returns: The constraint of the scalar subtype.
"""
return self._constraint
@export
class ConstrainedScalarSubtypeSymbol(SubtypeSymbol, ScalarConstraint):
"""
Represents a reference to a scalar subtype narrowed by a range.
The referenced language entity is available as :data:`Reference` once resolved. The range is
mandatory: a type mark without a range constraint is a :class:`~pyVHDLModel.Symbol.SimpleSubtypeSymbol`.
.. admonition:: Example
.. code-block:: VHDL
for i in integer range 0 to 3 loop
-- ^^^^^^^ <- Name
-- ^^^^^^ <- Constraint
A range constraint written as a range attribute is a :class:`~pyVHDLModel.Base.RangeFromName`
referring to a :class:`~pyVHDLModel.Symbol.RangeAttributeSymbol`:
.. code-block:: VHDL
subtype index is natural range vector'range;
-- ^^^^^^^ <- Name
-- ^^^^^^^^^^^^ <- Constraint
"""
def __init__(self, name: Name, constraint: Range, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference to a scalar subtype narrowed by a range.
:param name: The name to reference the language entity.
:param constraint: The range constraining the scalar subtype.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, parent=parent)
ScalarConstraint.__init__(self, constraint)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this constrained scalar subtype symbol.
The copy has no parent. The name and the range are copied; the reference, if resolved, is the same.
:returns: The new constrained scalar subtype symbol.
"""
copy = self.__class__(self._name.Copy(), self._constraint.Copy())
copy._reference = self._reference
return copy
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this constrained scalar subtype symbol, its name and its range constraint with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitConstrainedScalarSubtypeSymbol(self)
self._name.Visit(visitor)
visitor.VisitRangeConstraint(self)
self._constraint.Visit(visitor)
visitor.DepartRangeConstraint(self)
visitor.DepartConstrainedScalarSubtypeSymbol(self)
@export
class ArrayConstraint(Constraint, mixin=True):
"""
A mixin-class for an array constraint: one range per dimension.
The ranges are available as :data:`Constraints`.
.. seealso::
* :class:`Constrained array subtype symbol <pyVHDLModel.Symbol.ConstrainedArraySubtypeSymbol>`
* :class:`Array element constraint <pyVHDLModel.Symbol.ArrayElementConstraint>`
"""
_constraints: list[Range] #: List of all index ranges, one per dimension.
def __init__(self, constraints: Iterable[Range]) -> None:
"""
Initializes an array constraint.
:param constraints: List of all index ranges, one per dimension.
"""
self._constraints = constraintList = []
for constraint in constraints:
constraintList.append(constraint)
constraint.Parent = self
@readonly
def Constraints(self) -> list[Range]:
"""
Read-only property to access the constraints (:attr:`_constraints`).
:returns: List of constraints.
"""
return self._constraints
def _VisitArrayConstraint(self, visitor: Visitor) -> None:
"""
Walk the index constraint, one range per dimension, with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitIndexConstraint(self)
for index, constraint in enumerate(self._constraints):
if index > 0:
visitor.VisitElementSeparator(self)
constraint.Visit(visitor)
visitor.DepartIndexConstraint(self)
@export
class ArrayElementConstraint(ModelEntity, ArrayConstraint):
"""
Represents the constraint of an array element in a record constraint: one range per dimension.
The ranges are available as :data:`Constraints`. The constraint has no type mark of its own: the element's type is
the subtype of the record element (IEEE Std 1076-2008, 6.3: ``element_constraint ::= array_constraint |
record_constraint``).
.. admonition:: Example
.. code-block:: VHDL
signal s : rec_t(data(7 downto 0), m(0 to 1, 0 to 7));
-- ^^^^^^^^^^ <- Constraints
-- ^^^^^^^^^^^^^^ <- Constraints
.. seealso::
* :class:`Record element constraint <pyVHDLModel.Symbol.RecordElementConstraint>`
* :class:`Constrained record subtype symbol <pyVHDLModel.Symbol.ConstrainedRecordSubtypeSymbol>`
"""
def __init__(self, constraints: Iterable[Range], *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes the constraint of an array element.
:param constraints: List of all index ranges, one per dimension.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(parent)
ArrayConstraint.__init__(self, constraints)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this array element constraint.
The copy has no parent. The index ranges are copied.
:returns: The new array element constraint.
"""
return self.__class__([constraint.Copy() for constraint in self._constraints])
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this array element constraint and its index constraint with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitArrayElementConstraint(self)
self._VisitArrayConstraint(visitor)
visitor.DepartArrayElementConstraint(self)
[docs]
def __str__(self) -> str:
"""
Formats the array element constraint.
**Format:** ``(0 to 1, 0 to 7)``
:returns: Formatted array element constraint.
"""
return f"({', '.join(str(constraint) for constraint in self._constraints)})"
@export
class RecordConstraint(Constraint, mixin=True):
"""
A mixin-class for a record constraint: one element constraint per constrained record element.
The element constraints are available as :data:`Constraints`. An element constraint is an
:class:`~pyVHDLModel.Symbol.ArrayElementConstraint` or a nested :class:`~pyVHDLModel.Symbol.RecordElementConstraint`
(IEEE Std 1076-2008, 6.3: ``record_element_constraint ::= record_element_simple_name element_constraint``).
.. seealso::
* :class:`Constrained record subtype symbol <pyVHDLModel.Symbol.ConstrainedRecordSubtypeSymbol>`
* :class:`Record element constraint <pyVHDLModel.Symbol.RecordElementConstraint>`
"""
_constraints: dict[RecordElementSymbol, ArrayElementConstraint | RecordElementConstraint] #: Dictionary of the element constraint per constrained record element.
def __init__(
self,
constraints: Mapping[RecordElementSymbol, ArrayElementConstraint | RecordElementConstraint]
) -> None:
"""
Initializes a record constraint.
:param constraints: Dictionary of the element constraint per constrained record element.
"""
self._constraints = dict(constraints)
for element, constraint in self._constraints.items():
element.Parent = self
constraint.Parent = self
@readonly
def Constraints(self) -> dict[RecordElementSymbol, ArrayElementConstraint | RecordElementConstraint]:
"""
Read-only property to access the element constraints (:attr:`_constraints`).
:returns: Dictionary of element constraints, indexed by record element.
"""
return self._constraints
def _VisitRecordConstraint(self, visitor: Visitor) -> None:
"""
Walk the record constraint, each record element followed by its element constraint, with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitRecordConstraint(self)
for index, (element, constraint) in enumerate(self._constraints.items()):
if index > 0:
visitor.VisitElementSeparator(self)
element.Visit(visitor)
constraint.Visit(visitor)
visitor.DepartRecordConstraint(self)
@export
class RecordElementConstraint(ModelEntity, RecordConstraint):
"""
Represents the constraint of a record element in a record constraint: a nested record constraint.
The element constraints are available as :data:`Constraints`. The constraint has no type mark of its own: the
element's type is the subtype of the record element (IEEE Std 1076-2008, 6.3: ``element_constraint ::=
array_constraint | record_constraint``).
.. admonition:: Example
.. code-block:: VHDL
signal s : rec_t(inner(field(3 downto 0)));
-- ^^^^^^^^^^^^^^^^^ <- Constraints
.. seealso::
* :class:`Array element constraint <pyVHDLModel.Symbol.ArrayElementConstraint>`
* :class:`Constrained record subtype symbol <pyVHDLModel.Symbol.ConstrainedRecordSubtypeSymbol>`
"""
def __init__(
self,
constraints: Mapping[RecordElementSymbol, ArrayElementConstraint | RecordElementConstraint],
*,
parent: Nullable[ModelEntity] = None
) -> None:
"""
Initializes the constraint of a record element.
:param constraints: Dictionary of the element constraint per constrained record element.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(parent)
RecordConstraint.__init__(self, constraints)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this record element constraint.
The copy has no parent. The record elements and their element constraints are copied.
:returns: The new record element constraint.
"""
return self.__class__({element.Copy(): constraint.Copy() for element, constraint in self._constraints.items()})
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this record element constraint and its record constraint with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitRecordElementConstraint(self)
self._VisitRecordConstraint(visitor)
visitor.DepartRecordElementConstraint(self)
[docs]
def __str__(self) -> str:
"""
Formats the record element constraint.
**Format:** ``(field(3 downto 0))``
:returns: Formatted record element constraint.
"""
return f"({', '.join(f'{element._name!s}{constraint!s}' for element, constraint in self._constraints.items())})"
@export
@abstractclass
class ConstrainedCompositeSubtypeSymbol(SubtypeSymbol):
"""
Represents the base-class of references to constrained composite subtypes.
The referenced language entity is available as :data:`Reference` once resolved.
.. seealso::
* :class:`Constrained array subtype symbol <pyVHDLModel.Symbol.ConstrainedArraySubtypeSymbol>`
* :class:`Constrained record subtype symbol <pyVHDLModel.Symbol.ConstrainedRecordSubtypeSymbol>`
"""
@notimplemented("Model element has no walk for a visitor.")
def Visit(self, visitor: Visitor) -> None:
"""
Walk this constrained composite subtype symbol with a visitor.
The walk of its base class would drop the constraint; the array and record subclasses walk their constraint.
:param visitor: The visitor receiving the events.
:raises NotImplementedError: Always, because a subclass without a walk of its own can't walk its constraint.
"""
@export
class ConstrainedArraySubtypeSymbol(ConstrainedCompositeSubtypeSymbol, ArrayConstraint):
"""
Represents a reference to an array subtype narrowed by index ranges.
The referenced language entity is available as :data:`Reference` once resolved.
.. admonition:: Example
.. code-block:: VHDL
signal v : bit_vector(7 downto 0);
-- ^^^^^^^^^^ <- Name
-- ^^^^^^^^^^ <- Constraints
"""
def __init__(self, name: Name, constraints: Iterable, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference to an array subtype narrowed by index ranges.
:param name: The name to reference the language entity.
:param constraints: List of all index ranges, one per dimension.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, parent=parent)
ArrayConstraint.__init__(self, constraints)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this constrained array subtype symbol.
The copy has no parent. The name and the index ranges are copied; the reference, if resolved, is the same.
:returns: The new constrained array subtype symbol.
"""
copy = self.__class__(self._name.Copy(), [constraint.Copy() for constraint in self._constraints])
copy._reference = self._reference
return copy
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this constrained array subtype symbol, its name and its index constraint with a visitor.
:param visitor: The visitor receiving the events.
"""
visitor.VisitConstrainedArraySubtypeSymbol(self)
self._name.Visit(visitor)
self._VisitArrayConstraint(visitor)
visitor.DepartConstrainedArraySubtypeSymbol(self)
@export
class ConstrainedRecordSubtypeSymbol(ConstrainedCompositeSubtypeSymbol, RecordConstraint):
"""
Represents a reference to a record subtype with constrained elements.
The referenced language entity is available as :data:`Reference` once resolved. Each constrained record element has
an element constraint: an :class:`~pyVHDLModel.Symbol.ArrayElementConstraint` or a nested
:class:`~pyVHDLModel.Symbol.RecordElementConstraint`.
.. admonition:: Example
.. code-block:: VHDL
signal s : rec_t(data(7 downto 0), inner(field(3 downto 0)));
-- ^^^^^ <- Name
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <- Constraints
"""
def __init__(
self,
name: Name,
constraints: Mapping[RecordElementSymbol, ArrayElementConstraint | RecordElementConstraint],
*,
parent: Nullable[ModelEntity] = None
) -> None:
"""
Initializes a reference to a record subtype with constrained elements.
:param name: The name to reference the language entity.
:param constraints: Dictionary of the element constraint per constrained record element.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, parent=parent)
RecordConstraint.__init__(self, constraints)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this constrained record subtype symbol.
The copy has no parent. The name, the record elements and their element constraints are copied; the reference, if
resolved, is the same.
:returns: The new constrained record subtype symbol.
"""
constraints = {element.Copy(): constraint.Copy() for element, constraint in self._constraints.items()}
copy = self.__class__(self._name.Copy(), constraints)
copy._reference = self._reference
return copy
[docs]
def Visit(self, visitor: Visitor) -> None:
"""
Walk this constrained record subtype symbol, its name and its record constraint with a visitor.
Each record element is followed by its element constraint.
:param visitor: The visitor receiving the events.
"""
visitor.VisitConstrainedRecordSubtypeSymbol(self)
self._name.Visit(visitor)
self._VisitRecordConstraint(visitor)
visitor.DepartConstrainedRecordSubtypeSymbol(self)
@export
class SimpleObjectOrFunctionCallSymbol(Symbol):
"""
Represents a reference that is either an object or a parameterless function call.
Which of the two it is cannot be decided before the name is resolved. The referenced language
entity is available as :data:`Reference` once resolved.
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference that is either an object or a parameterless function call.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(name, PossibleReference.SimpleNameInExpression, parent=parent)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this simple object or function call symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new simple object or function call symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy
@export
class IndexedObjectOrFunctionCallSymbol(Symbol):
"""
Represents a reference that is either an indexed object, a function call or a type conversion.
The referenced language entity is available as :data:`Reference` once resolved.
.. attention::
All three are written the same way - ``arr(0)``, ``f(0)`` and ``integer(0)`` are indistinguishable
as syntax, so a parser produces one shape for them and only name resolution tells them apart.
.. seealso::
* :class:`Type conversion <pyVHDLModel.Expression.TypeConversion>`
* :class:`Simple object or function call <pyVHDLModel.Symbol.SimpleObjectOrFunctionCallSymbol>`
"""
def __init__(self, name: Name, *, parent: Nullable[ModelEntity] = None) -> None:
"""
Initializes a reference that is either an indexed object, a function call or a type conversion.
:param name: The name to reference the language entity.
:param parent: Optional, the parent model entity of this entity. Default: ``None``, no parent.
"""
super().__init__(
name,
PossibleReference.Object | PossibleReference.Function | PossibleReference.Type | PossibleReference.Subtype,
parent=parent
)
[docs]
def Copy(self) -> Self:
"""
Create a copy of this indexed object or function call symbol.
The copy has no parent. The name is copied; the reference, if resolved, is the same.
:returns: The new indexed object or function call symbol.
"""
copy = self.__class__(self._name.Copy())
copy._reference = self._reference
return copy