Skip to content

classes

Provide explicit class-type references and class-definition nodes that host compilers can use before higher-level surface syntax exists in Arx.

Classes:

BaseFieldAccess

BaseFieldAccess(
    receiver: AST, base_class_name: str, field_name: str
)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
def __init__(
    self,
    receiver: astx.AST,
    base_class_name: str,
    field_name: str,
) -> None:
    """
    title: Initialize one base-qualified field access expression.
    parameters:
      receiver:
        type: astx.AST
      base_class_name:
        type: str
      field_name:
        type: str
    """
    super().__init__()
    self.receiver = receiver
    self.base_class_name = base_class_name
    self.field_name = field_name
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a base-qualified field access.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"BASE-FIELD-ACCESS[{self.base_class_name}.{self.field_name}]"
    value = {
        "receiver": self.receiver.get_struct(simplified),
    }
    return self._prepare_struct(
        key,
        cast(astx.base.ReprStruct, value),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

BaseMethodCall

BaseMethodCall(
    receiver: AST,
    base_class_name: str,
    method_name: str,
    args: Iterable[DataType],
)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
def __init__(
    self,
    receiver: astx.AST,
    base_class_name: str,
    method_name: str,
    args: Iterable[astx.DataType],
) -> None:
    """
    title: Initialize one base-qualified method call expression.
    parameters:
      receiver:
        type: astx.AST
      base_class_name:
        type: str
      method_name:
        type: str
      args:
        type: Iterable[astx.DataType]
    """
    super().__init__()
    self.receiver = receiver
    self.base_class_name = base_class_name
    self.method_name = method_name
    self.args = tuple(args)
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a base-qualified method call.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"BASE-METHOD-CALL[{self.base_class_name}.{self.method_name}]"
    arg_nodes = astx.ASTNodes[astx.DataType]("args")
    for arg in self.args:
        arg_nodes.append(arg)
    value = {
        "receiver": self.receiver.get_struct(simplified),
        "args": arg_nodes.get_struct(simplified),
    }
    return self._prepare_struct(
        key,
        cast(astx.base.ReprStruct, value),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ClassConstruct

ClassConstruct(class_name: str)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
263
264
265
266
267
268
269
270
271
272
273
274
275
def __init__(
    self,
    class_name: str,
) -> None:
    """
    title: Initialize one default class construction expression.
    parameters:
      class_name:
        type: str
    """
    super().__init__()
    self.class_name = class_name
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
285
286
287
288
289
290
291
292
293
294
295
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for class construction.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"CLASS-CONSTRUCT[{self.class_name}]"
    return self._prepare_struct(key, self.class_name, simplified)

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ClassDefStmt

ClassDefStmt(
    name: str,
    *,
    bases: Iterable[ClassType] | ASTNodes[ClassType] = (),
    attributes: Iterable[VariableDeclaration]
    | ASTNodes[VariableDeclaration] = (),
    decorators: Iterable[Expr] | ASTNodes[Expr] = (),
    methods: Iterable[FunctionDef]
    | ASTNodes[FunctionDef] = (),
    visibility: VisibilityKind = public,
    is_abstract: bool = False,
    loc: SourceLocation = NO_SOURCE_LOCATION,
    parent: ASTNodes[AST] | None = None,
)

Bases: StructDeclStmt

Represent one top-level class declaration with explicit base-class references and inherited struct-like member containers. attributes: bases: type: astx.ASTNodes[ClassType] is_abstract: type: bool kind: type: astx.ASTKind

Methods:

Source code in packages/irx/src/irx/astx/classes.py
115
116
117
118
119
120
121
122
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
def __init__(
    self,
    name: str,
    *,
    bases: Iterable[ClassType] | astx.ASTNodes[ClassType] = (),
    attributes: (
        Iterable[astx.VariableDeclaration]
        | astx.ASTNodes[astx.VariableDeclaration]
    ) = (),
    decorators: Iterable[astx.Expr] | astx.ASTNodes[astx.Expr] = (),
    methods: Iterable[astx.FunctionDef]
    | astx.ASTNodes[astx.FunctionDef] = (),
    visibility: astx.VisibilityKind = astx.VisibilityKind.public,
    is_abstract: bool = False,
    loc: astx.SourceLocation = astx.base.NO_SOURCE_LOCATION,
    parent: astx.ASTNodes[astx.AST] | None = None,
) -> None:
    """
    title: Initialize one class definition statement.
    parameters:
      name:
        type: str
      bases:
        type: Iterable[ClassType] | astx.ASTNodes[ClassType]
      attributes:
        type: >-
          Iterable[astx.VariableDeclaration] |
          astx.ASTNodes[astx.VariableDeclaration]
      decorators:
        type: Iterable[astx.Expr] | astx.ASTNodes[astx.Expr]
      methods:
        type: Iterable[astx.FunctionDef] | astx.ASTNodes[astx.FunctionDef]
      visibility:
        type: astx.VisibilityKind
      is_abstract:
        type: bool
      loc:
        type: astx.SourceLocation
      parent:
        type: astx.ASTNodes[astx.AST] | None
    """
    super().__init__(
        name=name,
        attributes=attributes,
        decorators=decorators,
        methods=methods,
        visibility=visibility,
        loc=loc,
        parent=parent,
    )
    self.is_abstract = is_abstract
    if isinstance(bases, astx.ASTNodes):
        self.bases = bases
    else:
        self.bases = astx.ASTNodes[ClassType]()
        for base in bases:
            self.bases.append(base)
    self.kind = astx.ASTKind.StructDefStmtKind

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a class definition.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    vis = dict(zip(("public", "private", "protected"), ("+", "-", "#")))
    key = f"CLASS-DEF[{vis[self.visibility.name]}{self.name}]"

    bases_dict: astx.base.ReprStruct = {}
    if self.bases:
        bases_dict = {"bases": self.bases.get_struct(simplified)}

    decorators_dict: astx.base.ReprStruct = {}
    if self.decorators:
        decorators_dict = {
            "decorators": self.decorators.get_struct(simplified)
        }

    abstract_dict: astx.base.ReprStruct = {}
    if self.is_abstract:
        abstract_dict = {"abstract": self.is_abstract}

    attrs_dict: astx.base.ReprStruct = {}
    if self.attributes:
        attrs_dict = {"attributes": self.attributes.get_struct(simplified)}

    methods_dict: astx.base.ReprStruct = {}
    if self.methods:
        methods_dict = {"methods": self.methods.get_struct(simplified)}

    value = {
        **cast(dict[str, astx.base.ReprStruct], bases_dict),
        **cast(dict[str, astx.base.ReprStruct], decorators_dict),
        **cast(dict[str, astx.base.ReprStruct], abstract_dict),
        **cast(dict[str, astx.base.ReprStruct], attrs_dict),
        **cast(dict[str, astx.base.ReprStruct], methods_dict),
    }
    return self._prepare_struct(
        key,
        cast(astx.base.ReprStruct, value),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

ClassType

ClassType(
    name: str,
    *,
    resolved_name: str | None = None,
    module_key: str | None = None,
    qualified_name: str | None = None,
    ancestor_qualified_names: tuple[str, ...] = (),
)

Bases: AnyType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def __init__(
    self,
    name: str,
    *,
    resolved_name: str | None = None,
    module_key: str | None = None,
    qualified_name: str | None = None,
    ancestor_qualified_names: tuple[str, ...] = (),
) -> None:
    """
    title: Initialize one named class type reference.
    parameters:
      name:
        type: str
      resolved_name:
        type: str | None
      module_key:
        type: str | None
      qualified_name:
        type: str | None
      ancestor_qualified_names:
        type: tuple[str, Ellipsis]
    """
    super().__init__()
    self.name = name
    self.resolved_name = resolved_name
    self.module_key = module_key
    self.qualified_name = qualified_name
    self.ancestor_qualified_names = ancestor_qualified_names

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
81
82
83
84
85
86
87
88
89
90
91
92
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a class type reference.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"CLASS-TYPE[{self.name}]"
    value = self.qualified_name or self.name
    return self._prepare_struct(key, value, simplified)

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

MethodCall

MethodCall(
    receiver: AST,
    method_name: str,
    args: Iterable[DataType],
)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
def __init__(
    self,
    receiver: astx.AST,
    method_name: str,
    args: Iterable[astx.DataType],
) -> None:
    """
    title: Initialize one instance method call expression.
    parameters:
      receiver:
        type: astx.AST
      method_name:
        type: str
      args:
        type: Iterable[astx.DataType]
    """
    super().__init__()
    self.receiver = receiver
    self.method_name = method_name
    self.args = tuple(args)
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for an instance method call.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"METHOD-CALL[{self.method_name}]"
    arg_nodes = astx.ASTNodes[astx.DataType]("args")
    for arg in self.args:
        arg_nodes.append(arg)
    value = {
        "receiver": self.receiver.get_struct(simplified),
        "args": arg_nodes.get_struct(simplified),
    }
    return self._prepare_struct(
        key,
        cast(astx.base.ReprStruct, value),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

StaticFieldAccess

StaticFieldAccess(class_name: str, field_name: str)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
def __init__(
    self,
    class_name: str,
    field_name: str,
) -> None:
    """
    title: Initialize one static field access expression.
    parameters:
      class_name:
        type: str
      field_name:
        type: str
    """
    super().__init__()
    self.class_name = class_name
    self.field_name = field_name
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a static field access.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"STATIC-FIELD-ACCESS[{self.class_name}.{self.field_name}]"
    return self._prepare_struct(
        key,
        f"{self.class_name}.{self.field_name}",
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )

StaticMethodCall

StaticMethodCall(
    class_name: str,
    method_name: str,
    args: Iterable[DataType],
)

Bases: DataType

Methods:

Source code in packages/irx/src/irx/astx/classes.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
def __init__(
    self,
    class_name: str,
    method_name: str,
    args: Iterable[astx.DataType],
) -> None:
    """
    title: Initialize one static method call expression.
    parameters:
      class_name:
        type: str
      method_name:
        type: str
      args:
        type: Iterable[astx.DataType]
    """
    super().__init__()
    self.class_name = class_name
    self.method_name = method_name
    self.args = tuple(args)
    self.type_ = AnyType()

get_struct

get_struct(simplified: bool = False) -> ReprStruct
Source code in packages/irx/src/irx/astx/classes.py
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
def get_struct(self, simplified: bool = False) -> astx.base.ReprStruct:
    """
    title: Build one repr structure for a static method call.
    parameters:
      simplified:
        type: bool
    returns:
      type: astx.base.ReprStruct
    """
    key = f"STATIC-METHOD-CALL[{self.class_name}.{self.method_name}]"
    arg_nodes = astx.ASTNodes[astx.DataType]("args")
    for arg in self.args:
        arg_nodes.append(arg)
    value = {
        "args": arg_nodes.get_struct(simplified),
    }
    return self._prepare_struct(
        key,
        cast(astx.base.ReprStruct, value),
        simplified,
    )

to_json

to_json(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
400
401
402
403
404
405
406
407
408
409
def to_json(self, simplified: bool = False) -> str:
    """
    title: Return an json string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return json.dumps(self.get_struct(simplified=simplified), indent=2)

to_yaml

to_yaml(simplified: bool = False) -> str
Source code in packages/astx/src/astx/base.py
387
388
389
390
391
392
393
394
395
396
397
398
def to_yaml(self, simplified: bool = False) -> str:
    """
    title: Return an yaml string that represents the object.
    parameters:
      simplified:
        type: bool
    returns:
      type: str
    """
    return str(
        yaml.dump(self.get_struct(simplified=simplified), sort_keys=False)
    )