Skip to content

system

Classes:

AssertStmt

AssertStmt(
    condition: Expr,
    message: Expr | None = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: ASTNodes[AST] | None = None,
)

Bases: StatementType

Represent one fatal assertion statement with an optional failure message. attributes: condition: type: astx.Expr message: type: astx.Expr | None loc: type: astx.SourceLocation

Methods:

Source code in src/irx/astx/system.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def __init__(
    self,
    condition: astx.Expr,
    message: astx.Expr | None = None,
    loc: astx.SourceLocation = astx.base.NO_SOURCE_LOCATION,
    parent: astx.ASTNodes[astx.AST] | None = None,
) -> None:
    """
    title: Initialize AssertStmt.
    parameters:
      condition:
        type: astx.Expr
      message:
        type: astx.Expr | None
      loc:
        type: astx.SourceLocation
      parent:
        type: astx.ASTNodes[astx.AST] | None
    """
    super().__init__(loc=loc, parent=parent)
    self.loc: astx.SourceLocation = loc
    self.condition: astx.Expr = condition
    self.message: astx.Expr | None = message

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in src/irx/astx/system.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the AST structure of the assertion statement.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"ASSERT[{id(self)}]" if simplified else "ASSERT"
    value: astx.base.DictDataTypesStruct = {
        "condition": self.condition.get_struct(simplified),
    }
    if self.message is not None:
        value["message"] = self.message.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

Cast

Cast(value: DataType, target_type: Any)

Bases: DataType

Methods:

Source code in src/irx/astx/system.py
145
146
147
148
149
150
151
152
153
154
155
156
def __init__(self, value: astx.DataType, target_type: Any) -> None:
    """
    title: Initialize Cast.
    parameters:
      value:
        type: astx.DataType
      target_type:
        type: Any
    """
    super().__init__()
    self.value = value
    self.target_type = target_type

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in src/irx/astx/system.py
158
159
160
161
162
163
164
165
166
167
168
169
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the structured representation of the cast expression.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"Cast[{self.target_type}]"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

PrintExpr

PrintExpr(message: Expr)

Bases: Expr

It would be nice to support more arguments similar to the ones supported by Python (*args, sep=' ', end='', file=None, flush=False).

Methods:

Source code in src/irx/astx/system.py
105
106
107
108
109
110
111
112
113
114
def __init__(self, message: astx.Expr) -> None:
    """
    title: Initialize the PrintExpr.
    parameters:
      message:
        type: astx.Expr
    """
    super().__init__()
    self.message = message
    self._name = f"print_msg_{next(PrintExpr._counter)}"

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in src/irx/astx/system.py
116
117
118
119
120
121
122
123
124
125
126
127
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Return the AST structure of the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"FunctionCall[{self}]"
    value = self.message.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)