pyGHDL.dom

Document object model (DOM) for pyGHDL.libghdl based on pyVHDLModel.

Submodules

Exceptions

  • DOMException: The exception is raised when an IIR node cannot be translated to a pyVHDLModel object.

Classes

  • Position: Represents the source code position of a IIR node in a source file.

  • DOMMixin: Mixin adding the originating IIR node and its source code position to a pyGHDL.dom object.


Exceptions

exception pyGHDL.dom.DOMException(message='')[source]

The exception is raised when an IIR node cannot be translated to a pyVHDLModel object.

It reports a node kind the translation does not handle, or a node whose shape does not match what the surrounding construct expects. The message names the kind and, where available, the source position.

Inheritance

Inheritance diagram of DOMException

Parameters:

message (str)

Return type:

None


Classes

class pyGHDL.dom.Position(filename, line, column)[source]

Represents the source code position of a IIR node in a source file.

Inheritance

Inheritance diagram of Position

Parameters:
__init__(filename, line, column)[source]

Initializes a source code position.

Parameters:
  • filename (Path) – The source file this position refers to.

  • line (int) – The line number in the source file, starting at 1.

  • column (int) – The character offset within the line, starting at 0.

Return type:

None

_filename: Path

The source file this position refers to.

_line: int

The line number in the source file, starting at 1.

_column: int

The character offset within the line, starting at 0.

classmethod parse(node)[source]

Return the source code position of a IIR node.

Parameters:

node (TypeVar(Iir, bound= c_int)) – The IIR node to read the position of.

Return type:

Position

Returns:

The node’s position in its source file.

Raises:

ValueError – If parameter node is Null_Iir.

property Filename: Path

Read-only property to access the filename this source code position refers to (_filename).

Returns:

The source code position’s filename.

property Line: int

Read-only property to access the line number this source code position refers to (_line).

Returns:

The source code position’s line.

property Column: int

Read-only property to access the column this source code position refers to (_column).

Returns:

The source code position’s column.

__str__()[source]

Formats the source code position as <filename>:<line>:<column>.

Return type:

str

Returns:

A string representation of this source code position.

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.

class pyGHDL.dom.DOMMixin(node)[source]

Mixin adding the originating IIR node and its source code position to a pyGHDL.dom object.

Every class in pyGHDL.dom that mirrors a pyVHDLModel class inherits this mixin, so a model object can always be traced back to the node in libghdl’s tree it was translated from.

Inheritance

Inheritance diagram of DOMMixin

Parameters:

node (Iir)

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.

__init__(node)[source]

Initializes the mixin with the IIR node a DOM object was translated from.

The source code position is not resolved here, but on first access of Position.

Parameters:

node (TypeVar(Iir, bound= c_int)) – The IIR node in libghdl’s tree this DOM object was translated from.

Return type:

None

_iirNode: Iir

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

_position: <pyTooling.Decorators.readonly object at 0x7f3f462456d0>

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

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.