Skip to content

Enum value

woke.ast.ir.declaration.enum_value module #

EnumValue class #

Bases: DeclarationAbc

Definition of an enum value inside an enum definition.

Example

GoLeft, GoRight, GoStraight, SitStill in the following enum definition:

enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }

Source code in woke/ast/ir/declaration/enum_value.py
class EnumValue(DeclarationAbc):
    """
    Definition of an enum value inside an enum definition.

    !!! example
        `GoLeft`, `GoRight`, `GoStraight`, `SitStill` in the following enum definition:
        ```solidity
        enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
        ```
    """

    _ast_node: SolcEnumValue
    _parent: EnumDefinition

    def __init__(self, init: IrInitTuple, value: SolcEnumValue, parent: SolidityAbc):
        super().__init__(init, value, parent)

    def _parse_name_location(self) -> Tuple[int, int]:
        src = self._ast_node.src
        return src.byte_offset, src.byte_offset + src.byte_length

    @property
    def parent(self) -> EnumDefinition:
        """
        Returns:
            Parent IR node.
        """
        return self._parent

    @property
    def canonical_name(self) -> str:
        return f"{self._parent.canonical_name}.{self._name}"

    @property
    def declaration_string(self) -> str:
        return self.name

parent: EnumDefinition property #

Returns:

Type Description
EnumDefinition

Parent IR node.