pyGHDL.dom.Misc

This module implements derived classes for VHDL constructs not covered by another module, e.g. an alias.

Classes


Classes

class pyGHDL.dom.Misc.Alias(node, aliasName, name, subtype=None, documentation=None)[source]

This class implements a pyGHDL.dom object derived from pyVHDLModel.Declaration.Alias.

Represents an alias declaration.

Name is a Symbol - like every other cross-reference in this model - rather than a bare Name, so it participates in the usual resolve-later mechanism (Reference / IsResolved). Unlike PackageReferenceSymbol and similar, there is no single fixed PossibleReference value that always fits: an alias without a subtype indication can refer to almost anything nameable (an object, a type, a subprogram, a literal, …), while an alias with a subtype indication can - per the LRM - only ever refer to an object (a constant, variable, signal, or file); the possibleReferences passed to the Symbol should reflect whichever case applies.

Example

alias a : bit_vector(3 downto 0) is s(3 downto 0);
--        ^^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^
--        optional Subtype           Name

alias b is s;
--          ^
--          Name

Inheritance

Inheritance diagram of Alias

Parameters:
__init__(node, aliasName, name, subtype=None, documentation=None)[source]

Initializes an alias declaration.

Parameters:
  • node (Iir) – The IIR node this object was translated from.

  • aliasName (str) – The alias’ identifier.

  • name (Symbol) – Reference to the name being aliased.

  • subtype (Symbol) – Optional, reference to the alias’ subtype, or None if none was given.

  • documentation (str) – Optional, the documentation comment associated with this declaration.

Return type:

None

classmethod parse(aliasNode)[source]

Translates the IIR node of the alias declaration to an Alias.

Parameters:

aliasNode (Iir) – The IIR node of the alias declaration.

Returns:

The translated alias declaration.

_iirNode: Iir

The IIR node in libghdl’s tree this DOM object was translated from.

_position: Position

The IIR node’s position in the source file, resolved on first access and then cached.

DenoteBy(name, region, place, symbol)[source]

Determine the model entity a name denoting this alias denotes, as a part of a type mark.

The type mark is an attribute name like al'subtype. An alias with a subtype indication denotes itself, an object alias; otherwise, the declaration its name references says what it denotes (e.g. an object or a type).

Parameters:
  • name (Name) – The name denoting this declaration, a part of the type mark.

  • region (DeclarativeRegionMixin) – The declarative region containing the type mark.

  • place (ModelEntity) – The declaration containing the type mark.

  • symbol (Symbol) – The type mark.

Return type:

ModelEntity | None

Returns:

The denoted model entity, or None if it can’t be resolved (reported as a warning).

Raises:
  • UnhandledCriticalWarningError – If the alias’ name isn’t resolved, and no WarningCollector collects the UnresolvedTypeMarkWarning.

  • UnhandledCriticalWarningError – If the declaration the alias’ name references can’t be denoted, and no WarningCollector collects the UnresolvedTypeMarkWarning.

property Documentation: str | None

Read-only property to access the model entity’s documentation (_documentation).

Returns:

Associated documentation of a model entity.

GetAncestor(type)

Return the closest ancestor of the given type found by walking the parent chain upwards.

Iterates the parent chain - starting at this model entity - upwards (toward the root of the model) until an ancestor of the requested type is found.

Parameters:

type (Type) – Class (type) of the ancestor to find.

Return type:

ModelEntity

Returns:

The closest ancestor of the requested type.

Raises:

AncestorNotFoundError – If the root of the model is reached without finding an ancestor of the requested type.

GetIdentifier(normalizedIdentifier)

Return the identifier as declared, for the model entity’s normalized identifier.

Parameters:

normalizedIdentifier (str) – The model entity’s normalized (lower case) identifier.

Return type:

str

Returns:

The identifier in its declared spelling.

classmethod GetMethodsWithAttributes(predicate=None)

Return the class’ methods that carry at least one matching attribute.

Parameters:

predicate (type[TAttr] | Iterable[type[TAttr]] | None) – Optional, an attribute class, an iterable of attribute classes, or None to accept every attribute.

Return type:

dict[Callable[..., Any], tuple[Attribute, ...]]

Returns:

Dictionary of methods and the matching attributes attached to them.

Raises:
  • ValueError – If an element of parameter ‘predicate’ is not a sub-class of Attribute.

  • ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.

property Identifier: str

Read-only property to access the model entity’s identifier (_identifier).

Returns:

Name of a model entity.

property IsOverloadable: bool

Check if this alias is overloadable: it has no subtype indication, and its name may denote a subprogram or an enumeration literal.

The resolved name (Reference) decides, else the name’s possible references, e.g. alias To_SLV is To_StdLogicVector [std_ulogic_vector return std_logic_vector];.

Returns:

True, if this alias is overloadable.

IterateImplicitDeclarations()

Iterate the declarations this declaration implies.

An enumerated type implies its enumeration literals, a physical type its units; they override this method.

Return type:

Generator[tuple[str, ModelEntity]]

Returns:

A generator to iterate (normalized designator, declaration) pairs, in declaration order: none.

IterateTypeMarks(region)[source]

Iterate the type marks of this alias: the type mark of its subtype indication, if it has one.

Parameters:

region (DeclarativeRegionMixin) – The declarative region declaring this alias.

Return type:

Generator[tuple[DeclarativeRegionMixin, ModelEntity, SubtypeSymbol]]

Returns:

A generator to iterate (region, place, type mark) tuples: the alias’ subtype indication, if given.

property Name: Symbol

Read-only property to access the name (_name).

Returns:

The name.

property NormalizedIdentifier: str

Read-only property to access the model entity’s normalized identifier (_normalizedIdentifier).

See also

Returns:

Normalized name of a model entity.

property Parent: ModelEntity

Property to access the model entity’s parent element reference in a logical hierarchy (_parent).

Returns:

Reference to the parent entity.

property Position: Position

Cached read-only property to access an IIR’s position in source code (_position).

If _position is None, resolve the position object from _iirNode

Returns:

The IIR’s position in the source file.

ResetReferences(designUnit, region)[source]

Reset the reference of this alias’ name, if it has no subtype indication, and the references of its type marks.

Parameters:
  • designUnit (DesignUnit) – The design unit containing this declaration.

  • region (DeclarativeRegionMixin) – The declarative region declaring this declaration.

Return type:

None

ResolveReferences(designUnit, region)[source]

Resolve the name of this alias, if it has no subtype indication, then its type marks.

The name is resolved, if it’s a simple name or an expanded name lib.pkg.item (IsExpandedName) and denotes a declaration, which isn’t overloadable, e.g. a type or an object (LookupName()); the alias isn’t overloadable then (IsOverloadable). The name of an implicitly declared operation (_IMPLICIT_OPERATIONS, an operator symbol) isn’t looked up, as the model doesn’t represent these.

Parameters:
  • designUnit (DesignUnit) – The design unit containing this declaration.

  • region (DeclarativeRegionMixin) – The declarative region declaring this declaration.

Raises:
  • UnhandledCriticalWarningError – If the name can’t be resolved, and no WarningCollector collects the UnresolvedNameWarning.

  • UnhandledCriticalWarningError – If a type mark can’t be resolved, and no WarningCollector collects the UnresolvedTypeMarkWarning.

Return type:

None

property Subtype: SubtypeSymbol | None

Read-only property to access the subtype (_subtype).

Returns:

The subtype, or None if not set.

Visit(visitor)[source]

Walk this alias declaration, its subtype (if any) and its name with a visitor.

Parameters:

visitor (Visitor) – The visitor receiving the events.

Return type:

None

_IMPLICIT_OPERATIONS: ClassVar[frozenset[str]] = frozenset({'deallocate', 'endfile', 'file_close', 'file_open', 'flush', 'maximum', 'minimum', 'read', 'to_binary_string', 'to_bstring', 'to_hex_string', 'to_hstring', 'to_octal_string', 'to_ostring', 'to_string', 'write'})

Normalized identifiers of implicitly declared operations (IEEE Std 1076-2008, 5), which aren’t represented.

__getstate__()

Return the object’s state for pickling, collecting every slot of the class hierarchy.

Return type:

dict[str, Any]

Returns:

Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If a slot was never assigned, so it has no value to serialize.

__new__(**kwargs)
__setstate__(state)

Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.

Parameters:

state (dict[str, Any]) – Dictionary of slot names and their values.

Raises:

ExtendedTypeError – If the given state misses a slot or carries an unexpected one.

Return type:

None

__str__()[source]

Formats the alias declaration.

Format: alias myAlias : bit is target, or without the subtype when none was given

Return type:

str

Returns:

Formatted alias declaration.

_documentation: str | None

The associated documentation of a model entity.

_identifier: str

The identifier of a model entity.

_name: Symbol

Reference to the name being aliased.

_normalizedIdentifier: str

The normalized (lower case) identifier of a model entity.

_parent: ModelEntity

Reference to a parent entity in the logical model hierarchy.

_subtype: SubtypeSymbol | None

Reference to the alias’ subtype, or None if none was given.