Skip to content

astx

ASTx.

AST

AST(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

AST main expression class.

Source code in src/astx/base.py
138
139
140
141
142
143
144
145
146
147
148
149
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct

Return a structure that represents the node object.

Source code in src/astx/base.py
207
208
209
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a structure that represents the node object."""

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ASTKind

Bases: Enum

The expression kind class used for downcasting.

Argument

Argument(name: str, type_: ExprType, mutability: MutabilityKind = MutabilityKind.constant, default: Expr = UNDEFINED, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Variable

AST class for argument definition.

Source code in src/astx/callables.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(
    self,
    name: str,
    type_: ExprType,
    mutability: MutabilityKind = MutabilityKind.constant,
    default: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(name=name, loc=loc, parent=parent)
    self.mutability = mutability
    self.type_ = type_
    self.default = default
    self.kind = ASTKind.ArgumentKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/callables.py
58
59
60
61
62
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = f"Argument[{self.name}, {self.type_}] = {self.default}"
    value = cast(ReprStruct, self.default)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Arguments

Arguments(*args: Argument, **kwargs: Any)

Bases: ASTNodes

AST class for argument definition.

Source code in src/astx/callables.py
69
70
71
72
def __init__(self, *args: Argument, **kwargs: Any) -> None:
    super().__init__(**kwargs)
    for arg in args:
        self.append(arg)

append

append(value: AST) -> None

Append a new node to the stack.

Source code in src/astx/base.py
259
260
261
def append(self, value: AST) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/callables.py
78
79
80
81
82
83
84
85
86
87
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    args_nodes = []

    for node in self.nodes:
        args_nodes.append(node.get_struct(simplified))

    key = str(self)
    value = cast(ReprStruct, args_nodes)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

BinaryOp

BinaryOp(op_code: str, lhs: DataType, rhs: DataType, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: DataTypeOps

AST class for the binary operator.

Source code in src/astx/datatypes.py
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def __init__(
    self,
    op_code: str,
    lhs: DataType,
    rhs: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the BinaryOp instance."""
    super().__init__()

    self.loc = loc
    self.op_code = op_code
    self.lhs = lhs
    self.rhs = rhs
    self.kind = ASTKind.BinaryOpKind

    if not (
        issubclass(lhs.type_, (Number, BinaryOp, DataType))
        and issubclass(rhs.type_, (Number, BinaryOp, DataType))
    ):
        raise Exception(
            "For now, binary operators are just allowed for numbers."
            f"LHS: {lhs.type_}, RHS: {rhs.type_}"
        )

    if lhs.type_ == rhs.type_:
        self.type_ = lhs.type_
    else:
        # type inference
        self.type_ = max([lhs.type_, rhs.type_], key=lambda v: v.nbytes)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure that represents the object.

Source code in src/astx/datatypes.py
158
159
160
161
162
163
164
165
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure that represents the object."""
    key = f"BINARY[{self.op_code}]"
    lhs = {"lhs": self.lhs.get_struct(simplified)}
    rhs = {"rhs": self.rhs.get_struct(simplified)}

    content: ReprStruct = {**lhs, **rhs}
    return self._prepare_struct(key, content, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Block

Block(name: str = 'entry', loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: ASTNodes

The AST tree.

Source code in src/astx/base.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
def __init__(
    self,
    name: str = "entry",
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name
    # note: maybe it would be nice to add options for rules, so
    #       it could have specific rules for the type of AST
    #       accepted
    self.nodes: list[AST] = []
    self.position: int = 0

append

append(value: AST) -> None

Append a new node to the stack.

Source code in src/astx/base.py
259
260
261
def append(self, value: AST) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/blocks.py
19
20
21
22
23
24
25
26
27
28
29
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    block_nodes = []

    for node in self.nodes:
        block_nodes.append(node.get_struct(simplified))

    key = "BLOCK"
    value = cast(ReprStruct, block_nodes)

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Boolean

Boolean(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

Boolean data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

DataType

DataType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST main expression class.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

DataTypeOps

DataTypeOps(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

Overload some magic functions used for the main operations.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Expr

Expr(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AST

AST main expression class.

Source code in src/astx/base.py
138
139
140
141
142
143
144
145
146
147
148
149
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct abstractmethod

get_struct(simplified: bool = False) -> ReprStruct

Return a structure that represents the node object.

Source code in src/astx/base.py
207
208
209
@abstractmethod
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a structure that represents the node object."""

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Float16

Float16(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Floating

Float16 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

Float32

Float32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Floating

Float32 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

Float64

Float64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Floating

Float64 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

Floating

Floating(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Number

AST for the literal float number.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

ForCountLoop

ForCountLoop(initializer: InlineVariableDeclaration, condition: Expr, update: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for a simple Count-Controlled For Loop statement.

This is a very basic for loop, used by languages like C or C++.

Source code in src/astx/flows.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def __init__(
    self,
    initializer: InlineVariableDeclaration,
    condition: Expr,
    update: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the ForStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.initializer = initializer
    self.condition = condition
    self.update = update
    self.body = body
    self.kind = ASTKind.ForCountKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    for_init = {"initialization": self.initializer.get_struct(simplified)}
    for_cond = {"condition": self.condition.get_struct(simplified)}
    for_update = {"update": self.update.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-COUNT-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_init),
        **cast(DictDataTypesStruct, for_cond),
        **cast(DictDataTypesStruct, for_update),
        **cast(DictDataTypesStruct, for_body),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ForRangeLoop

ForRangeLoop(variable: InlineVariableDeclaration, start: Expr, end: Expr, step: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for For Loop Range statement.

Source code in src/astx/flows.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(
    self,
    variable: InlineVariableDeclaration,
    start: Expr,
    end: Expr,
    step: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the ForStmt instance."""
    super().__init__(loc=loc, parent=parent)
    self.variable = variable
    self.start = start
    self.end = end
    self.step = step
    self.body = body
    self.kind = ASTKind.ForRangeKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    for_start = {"start": self.start.get_struct(simplified)}
    for_end = {"end": self.end.get_struct(simplified)}
    for_step = {"step": self.step.get_struct(simplified)}
    for_body = self.body.get_struct(simplified)

    key = "FOR-RANGE-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, for_start),
        **cast(DictDataTypesStruct, for_end),
        **cast(DictDataTypesStruct, for_step),
        **cast(DictDataTypesStruct, for_body),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Function

Function(prototype: FunctionPrototype, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for function definition.

Source code in src/astx/callables.py
206
207
208
209
210
211
212
213
214
215
216
217
def __init__(
    self,
    prototype: FunctionPrototype,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Function instance."""
    super().__init__(loc=loc, parent=parent)
    self.prototype = prototype
    self.body = body
    self.kind = ASTKind.FunctionKind

name property

name: str

Return the function prototype name.

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Get the AST structure that represent the object.

Source code in src/astx/callables.py
237
238
239
240
241
242
243
244
245
246
247
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Get the AST structure that represent the object."""
    fn_args = self.prototype.args.get_struct(simplified)
    fn_body = self.body.get_struct(simplified)

    key = f"FUNCTION[{self.prototype.name}]"
    args_struct = {"args": fn_args}
    body_struct = {"body": fn_body}

    value: ReprStruct = {**args_struct, **body_struct}
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

FunctionCall

FunctionCall(fn: Function, args: tuple[DataType, ...], loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

AST class for function call.

Source code in src/astx/callables.py
 97
 98
 99
100
101
102
103
104
105
106
107
108
def __init__(
    self,
    fn: Function,
    args: tuple[DataType, ...],
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Call instance."""
    super().__init__(loc=loc, parent=parent)
    self.fn = fn
    self.args = args
    self.kind = ASTKind.CallKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/callables.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    call_params = []

    for node in self.args:
        call_params.append(node.get_struct(simplified))

    key = f"FUNCTION-CALL[{self.fn.name}]"
    value = cast(
        ReprStruct,
        {
            f"Parameters ({len(call_params)})": {
                f"param({idx})": param
                for idx, param in enumerate(call_params)
            }
        },
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

FunctionPrototype

FunctionPrototype(name: str, args: Arguments, return_type: ExprType, scope: ScopeKind = ScopeKind.global_, visibility: VisibilityKind = VisibilityKind.public, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for function prototype declaration.

Source code in src/astx/callables.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def __init__(
    self,
    name: str,
    args: Arguments,
    return_type: ExprType,
    scope: ScopeKind = ScopeKind.global_,
    visibility: VisibilityKind = VisibilityKind.public,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the FunctionPrototype instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name
    self.args = args
    self.return_type = return_type
    self.loc = loc
    self.kind = ASTKind.PrototypeKind
    self.scope = scope
    self.visibility = visibility

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Get the AST structure that represent the object.

Source code in src/astx/callables.py
166
167
168
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Get the AST structure that represent the object."""
    raise Exception("Visitor method not necessary")

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

FunctionReturn

FunctionReturn(value: DataType, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for function return statement.

Source code in src/astx/callables.py
177
178
179
180
181
182
183
184
185
186
def __init__(
    self,
    value: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Return instance."""
    super().__init__(loc=loc, parent=parent)
    self.value = value
    self.kind = ASTKind.ReturnKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/callables.py
192
193
194
195
196
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = "RETURN"
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

If

If(condition: Expr, then: Block, else_: Optional[Block] = None, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for if statement.

Source code in src/astx/flows.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(
    self,
    condition: Expr,
    then: Block,
    else_: Optional[Block] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the If instance."""
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.condition = condition
    self.then = then
    self.else_ = else_
    self.kind = ASTKind.IfKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    if_condition = {"condition": self.condition.get_struct(simplified)}
    if_then = {"then-block": self.then.get_struct(simplified)}
    if_else: ReprStruct = {}

    if self.else_ is not None:
        if_else = {"else-block": self.else_.get_struct(simplified)}

    key = "IF-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, if_condition),
        **cast(DictDataTypesStruct, if_then),
        **cast(DictDataTypesStruct, if_else),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

InlineVariableDeclaration

InlineVariableDeclaration(name: str, type_: ExprType, mutability: MutabilityKind = MutabilityKind.constant, visibility: VisibilityKind = VisibilityKind.public, scope: ScopeKind = ScopeKind.local, value: Expr = UNDEFINED, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

AST class for inline variable declaration expression.

Can be used in expressions like for loops.

Source code in src/astx/variables.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    name: str,
    type_: ExprType,
    mutability: MutabilityKind = MutabilityKind.constant,
    visibility: VisibilityKind = VisibilityKind.public,
    scope: ScopeKind = ScopeKind.local,
    value: Expr = UNDEFINED,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(loc=loc, parent=parent)
    self.mutability = mutability
    self.scope = scope
    self.visibility = visibility
    self.name = name
    self.type_ = type_
    self.value = value
    self.kind = ASTKind.VarDeclKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
109
110
111
112
113
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int16

Int16(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int16 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int32

Int32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int32 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int64

Int64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int64 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Int8

Int8(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: SignedInteger

Int8 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Integer

Integer(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Number

Integer number data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

Literal

Literal(*args, **kwargs)

Bases: DataTypeOps

Literal Data type.

Source code in src/astx/datatypes.py
299
300
301
def __init__(self, *args, **kwargs) -> None:  # type: ignore
    super().__init__(*args, **kwargs)
    self.ref = uuid4().hex

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralBoolean

LiteralBoolean(value: bool, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralBoolean data type class.

Source code in src/astx/datatypes.py
481
482
483
484
485
486
487
488
def __init__(
    self, value: bool, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralBoolean."""
    super().__init__(loc)
    self.value = value
    self.type_ = Boolean
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat16

LiteralFloat16(value: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralFloat16 data type class.

Source code in src/astx/datatypes.py
497
498
499
500
501
502
503
504
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat16."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float16
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat32

LiteralFloat32(value: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralFloat32 data type class.

Source code in src/astx/datatypes.py
513
514
515
516
517
518
519
520
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat32."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float32
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralFloat64

LiteralFloat64(value: float, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralFloat64 data type class.

Source code in src/astx/datatypes.py
529
530
531
532
533
534
535
536
def __init__(
    self, value: float, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralFloat64."""
    super().__init__(loc)
    self.value = value
    self.type_ = Float64
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt128

LiteralInt128(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt128 data type class.

Source code in src/astx/datatypes.py
385
386
387
388
389
390
391
392
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt128."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int128
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt16

LiteralInt16(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt16 data type class.

Source code in src/astx/datatypes.py
337
338
339
340
341
342
343
344
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt16."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int16
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt32

LiteralInt32(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt32 data type class.

Source code in src/astx/datatypes.py
353
354
355
356
357
358
359
360
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt32."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int32
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt64

LiteralInt64(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt64 data type class.

Source code in src/astx/datatypes.py
369
370
371
372
373
374
375
376
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt64."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int64
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralInt8

LiteralInt8(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralInt8 data type class.

Source code in src/astx/datatypes.py
321
322
323
324
325
326
327
328
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralInt8."""
    super().__init__(loc)
    self.value = value
    self.type_ = Int8
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt128

LiteralUInt128(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt128 data type class.

Source code in src/astx/datatypes.py
465
466
467
468
469
470
471
472
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt128."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt128
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt16

LiteralUInt16(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt16 data type class.

Source code in src/astx/datatypes.py
417
418
419
420
421
422
423
424
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt16."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt16
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt32

LiteralUInt32(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt32 data type class.

Source code in src/astx/datatypes.py
433
434
435
436
437
438
439
440
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt32."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt32
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt64

LiteralUInt64(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt64 data type class.

Source code in src/astx/datatypes.py
449
450
451
452
453
454
455
456
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt64."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt64
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

LiteralUInt8

LiteralUInt8(value: int, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Literal

LiteralUInt8 data type class.

Source code in src/astx/datatypes.py
401
402
403
404
405
406
407
408
def __init__(
    self, value: int, loc: SourceLocation = NO_SOURCE_LOCATION
) -> None:
    """Initialize LiteralUInt8."""
    super().__init__(loc)
    self.value = value
    self.type_ = UInt8
    self.loc = loc

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST representation for the object.

Source code in src/astx/datatypes.py
308
309
310
311
312
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST representation for the object."""
    key = f"Literal[{self.type_}]: {self.value}"
    value = self.value
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Module

Module(name: str = 'main', loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Block

AST main expression class.

Source code in src/astx/packages.py
49
50
51
52
53
54
55
56
def __init__(
    self,
    name: str = "main",
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the AST instance."""
    super().__init__(name=name, loc=loc)
    self.kind = ASTKind.ModuleKind

block property

block: list[AST]

Define an alias for self.nodes.

append

append(value: AST) -> None

Append a new node to the stack.

Source code in src/astx/base.py
259
260
261
def append(self, value: AST) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
67
68
69
70
71
72
73
74
75
76
77
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    block_node = []

    for node in self.nodes:
        block_node.append(node.get_struct(simplified))

    key = f"MODULE[{self.name}]"
    value = cast(ReprStruct, block_node)

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

MutabilityKind

Bases: Enum

Definition for different kind of mutability.

Number

Number(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataTypeOps

Number data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

OperatorType

OperatorType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataType

AST main expression class.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

Package

Package(name: str = 'main', modules: list[Module] = [], packages: list[Package] = [], loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: ASTNodes

AST class for Package.

Source code in src/astx/packages.py
88
89
90
91
92
93
94
95
96
97
98
99
def __init__(
    self,
    name: str = "main",
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the AST instance."""
    super().__init__(loc=loc)
    self.name = name
    self.modules = copy.deepcopy(modules)
    self.packages = copy.deepcopy(packages)

append

append(value: AST) -> None

Append a new node to the stack.

Source code in src/astx/base.py
259
260
261
def append(self, value: AST) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    packages = []
    modules = []

    for package in self.packages:
        packages.append(package.get_struct(simplified))

    for module in self.modules:
        modules.append(module.get_struct(simplified))

    key = str(self)
    value = cast(
        ReprStruct,
        {
            "modules": modules,
            "packages": packages,
        },
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Program

Program(name: str = 'main', target: Target = Target('', ''), modules: list[Module] = [], packages: list[Package] = [], loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: Package

AST class for Program.

Source code in src/astx/packages.py
134
135
136
137
138
139
140
141
142
143
144
145
146
def __init__(
    self,
    name: str = "main",
    target: Target = Target("", ""),
    modules: list[Module] = [],
    packages: list[Package] = [],
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the AST instance."""
    super().__init__(
        name=name, modules=modules, packages=packages, loc=loc
    )
    self.target = copy.deepcopy(target)

append

append(value: AST) -> None

Append a new node to the stack.

Source code in src/astx/base.py
259
260
261
def append(self, value: AST) -> None:
    """Append a new node to the stack."""
    self.nodes.append(value)

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    packages = []
    modules = []

    for package in self.packages:
        packages.append(package.get_struct(simplified))

    for module in self.modules:
        modules.append(module.get_struct(simplified))

    key = str(self)
    value = cast(
        ReprStruct,
        {
            "modules": modules,
            "packages": packages,
        },
    )

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ScopeKind

Bases: Enum

Definition for different kind of scopes.

SignedInteger

SignedInteger(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Integer

Signed integer number data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

StatementType

StatementType(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: AST

AST main expression class.

Source code in src/astx/base.py
138
139
140
141
142
143
144
145
146
147
148
149
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

Target

Target(datalayout: str, triple: str)

Bases: Expr

Define the Architecture target for the program.

Source code in src/astx/packages.py
30
31
32
33
34
def __init__(self, datalayout: str, triple: str) -> None:
    """Initialize the AST instance."""
    super().__init__()
    self.datalayout = datalayout
    self.triple = triple

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/packages.py
36
37
38
39
40
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = "TARGET"
    value = f"{self.datalayout}, {self.triple}"
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt128

UInt128(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt8 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt16

UInt16(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt8 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt32

UInt32(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt8 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt64

UInt64(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt8 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UInt8

UInt8(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: UnsignedInteger

UInt8 data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
317
318
319
320
321
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    key = "DATA-TYPE"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UnaryOp

UnaryOp(op_code: str, operand: DataType, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: DataTypeOps

AST class for the unary operator.

Source code in src/astx/datatypes.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
def __init__(
    self,
    op_code: str,
    operand: DataType,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the UnaryOp instance."""
    super().__init__()
    self.loc = loc
    self.op_code = op_code
    self.operand = operand
    self.kind = ASTKind.UnaryOpKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/datatypes.py
110
111
112
113
114
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    key = f"UNARY[{self.op_code}]"
    value = self.operand.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

Undefined

Undefined(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Expr

Undefined expression class.

Source code in src/astx/base.py
138
139
140
141
142
143
144
145
146
147
148
149
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the AST instance."""
    self.kind = ASTKind.GenericKind
    self.loc = loc
    self.ref = ""
    self.comment = ""
    self.parent = parent
    self._update_parent()

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a simple structure that represents the object.

Source code in src/astx/base.py
286
287
288
289
290
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a simple structure that represents the object."""
    value = "UNDEFINED"
    key = "DATA-TYPE"
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

UnsignedInteger

UnsignedInteger(loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: Integer

Unsigned integer number data type expression.

Source code in src/astx/base.py
301
302
303
304
305
306
307
308
309
310
311
def __init__(
    self,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    super().__init__(loc)
    self.name = f"temp_{DataType._tmp_id}"
    DataType._tmp_id += 1
    # set it as a generic data type
    self.type_: ExprType = DataType
    self.parent = parent

Variable

Variable(name: str, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: DataTypeOps

AST class for the variable usage.

Source code in src/astx/variables.py
154
155
156
157
158
159
160
161
162
def __init__(
    self,
    name: str,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the Variable instance."""
    super().__init__(loc=loc, parent=parent)
    self.name = name

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
168
169
170
171
172
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = f"Variable[{self.name}]"
    value = self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

VariableAssignment

VariableAssignment(name: str, value: Expr, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for variable declaration.

Source code in src/astx/variables.py
123
124
125
126
127
128
129
130
131
132
133
134
135
def __init__(
    self,
    name: str,
    value: Expr,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(loc=loc, parent=parent)
    self.loc = loc
    self.name = name
    self.value = value
    self.kind = ASTKind.VariableAssignmentKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
141
142
143
144
145
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

VariableDeclaration

VariableDeclaration(name: str, type_: ExprType, mutability: MutabilityKind = MutabilityKind.constant, visibility: VisibilityKind = VisibilityKind.public, scope: ScopeKind = ScopeKind.local, value: Expr = UNDEFINED, parent: Optional[ASTNodes] = None, loc: SourceLocation = NO_SOURCE_LOCATION)

Bases: StatementType

AST class for variable declaration.

Source code in src/astx/variables.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def __init__(
    self,
    name: str,
    type_: ExprType,
    mutability: MutabilityKind = MutabilityKind.constant,
    visibility: VisibilityKind = VisibilityKind.public,
    scope: ScopeKind = ScopeKind.local,
    value: Expr = UNDEFINED,
    parent: Optional[ASTNodes] = None,
    loc: SourceLocation = NO_SOURCE_LOCATION,
) -> None:
    """Initialize the VarExprAST instance."""
    super().__init__(loc=loc, parent=parent)
    self.mutability = mutability
    self.scope = scope
    self.visibility = visibility
    self.name = name
    self.type_ = type_
    self.value = value
    self.kind = ASTKind.VarDeclKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return a string that represents the object.

Source code in src/astx/variables.py
63
64
65
66
67
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return a string that represents the object."""
    key = str(self)
    value = self.value.get_struct(simplified)
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

VisibilityKind

Bases: Enum

Definition of different kind of visibility.

While

While(condition: Expr, body: Block, loc: SourceLocation = NO_SOURCE_LOCATION, parent: Optional[ASTNodes] = None)

Bases: StatementType

AST class for while statement.

Source code in src/astx/flows.py
186
187
188
189
190
191
192
193
194
195
196
197
def __init__(
    self,
    condition: Expr,
    body: Block,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: Optional[ASTNodes] = None,
) -> None:
    """Initialize the While instance."""
    super().__init__(loc=loc, parent=parent)
    self.condition = condition
    self.body = body
    self.kind = ASTKind.WhileKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct

Return the AST structure of the object.

Source code in src/astx/flows.py
203
204
205
206
207
208
209
210
211
212
213
214
def get_struct(self, simplified: bool = False) -> ReprStruct:
    """Return the AST structure of the object."""
    while_condition = self.condition.get_struct(simplified)
    while_body = self.body.get_struct(simplified)

    key = "WHILE-STMT"
    value: ReprStruct = {
        **cast(DictDataTypesStruct, while_condition),
        **cast(DictDataTypesStruct, while_body),
    }

    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str

Return an json string that represents the object.

Source code in src/astx/base.py
217
218
219
def to_json(self, simplified: bool = False) -> str:
    """Return an json string that represents the object."""
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str

Return an yaml string that represents the object.

Source code in src/astx/base.py
211
212
213
214
215
def to_yaml(self, simplified: bool = False) -> str:
    """Return an yaml string that represents the object."""
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

get_version

get_version() -> str

Return the program version.

Source code in src/astx/__init__.py
103
104
105
106
107
108
def get_version() -> str:
    """Return the program version."""
    try:
        return importlib_metadata.version(__name__)
    except importlib_metadata.PackageNotFoundError:  # pragma: no cover
        return "0.15.0"  # semantic-release