pyGHDL.dom.Range

This module implements derived range classes from pyVHDLModel.Base.

Classes

  • SimpleRange: A range with both bounds given as expressions, e.g. 0 to 7.

  • RangeFromName: A range denoted by a name, so its bounds are inferred from whatever that name references.


Classes

class pyGHDL.dom.Range.SimpleRange(node, leftBound, rightBound, direction)[source]

A range with both bounds given as expressions, e.g. 0 to 7.

This class implements a pyGHDL.dom object derived from pyVHDLModel.Base.SimpleRange.

Inheritance

Inheritance diagram of SimpleRange

Parameters:
__init__(node, leftBound, rightBound, direction)[source]

Initialize a simple range.

Parameters:
  • node (TypeVar(Iir, bound= c_int)) – The IIR node this object was translated from.

  • leftBound (BaseExpression | QualifiedExpression | FunctionCall | TypeConversion | Literal) – The range’s left bound.

  • rightBound (BaseExpression | QualifiedExpression | FunctionCall | TypeConversion | Literal) – The range’s right bound.

  • direction (Direction) – The range’s direction (to or downto).

Return type:

None

_iirNode

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

_position

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

property Direction: <pyTooling.Decorators.readonly object at 0x7f3f462fb4d0>

Read-only property to access the range’s direction (_direction).

Returns:

The direction.

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:

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

classmethod GetMethodsWithAttributes(predicate: TAttr | Iterable[TAttr] | None = None) Dict[Callable, Tuple[Attribute, ...]]
Parameters:

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

Return type:

Dict[Callable, 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 LeftBound: BaseExpression | QualifiedExpression | FunctionCall | TypeConversion | Literal

Read-only property to access the range’s left bound (_leftBound).

Returns:

The left bound.

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: <pyTooling.Decorators.readonly object at 0x7f3f462456d0>

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.

property RightBound: BaseExpression | QualifiedExpression | FunctionCall | TypeConversion | Literal

Read-only property to access the range’s right bound (_rightBound).

Returns:

The right bound.

__getstate__() Dict[str, Any]

Helper for pickle.

Return type:

Dict[str, Any]

__str__()[source]

Formats the simple range.

Format: 0 to 7

Return type:

str

Returns:

Formatted simple range.

_direction

The range’s direction, either ascending (to) or descending (downto).

_leftBound

The range’s left bound.

_parent

Reference to a parent entity in the logical model hierarchy.

_rightBound

The range’s right bound.

class pyGHDL.dom.Range.RangeFromName(node, symbol)[source]

A range denoted by a name, so its bounds are inferred from whatever that name references.

The name is represented by a Symbol, so the bounds become available once that symbol is resolved. A constrained subtype indication keeps its type mark and its range constraint, because it’s carried by a ConstrainedScalarSubtypeSymbol.

Note

Two forms reach this class, because a parser can’t tell them apart beyond “a name, optionally with a range constraint”:

  • a range attribute like vector'range, and

  • a discrete subtype indication like bit or integer range 0 to 7.

VHDL’s grammar puts the latter one level up (discrete_range ::= discrete_subtype_indication | range), so representing both as a range deviates from the rule split deliberately.

This class implements a pyGHDL.dom object derived from pyVHDLModel.Base.RangeFromName.

Inheritance

Inheritance diagram of RangeFromName

Parameters:
__init__(node, symbol)[source]

Initialize a range denoted by a name.

Parameters:
  • node (TypeVar(Iir, bound= c_int)) – The IIR node this object was translated from.

  • symbol (Symbol) – The symbol referencing the range attribute or discrete subtype.

Return type:

None

_iirNode

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

_position

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

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:

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

classmethod GetMethodsWithAttributes(predicate: TAttr | Iterable[TAttr] | None = None) Dict[Callable, Tuple[Attribute, ...]]
Parameters:

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

Return type:

Dict[Callable, 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 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: <pyTooling.Decorators.readonly object at 0x7f3f462456d0>

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.

property Symbol: Symbol

Read-only property to access the referenced symbol (_symbol).

Returns:

The symbol.

__getstate__() Dict[str, Any]

Helper for pickle.

Return type:

Dict[str, Any]

__str__()[source]

Formats the range denoted by a name.

Format: v'range

Return type:

str

Returns:

Formatted range denoted by a name.

_parent

Reference to a parent entity in the logical model hierarchy.

_symbol

Reference to the name the range’s bounds are inferred from.