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 src/irx/astx/classes.py
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
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 src/irx/astx/classes.py
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
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,
    )

BaseMethodCall

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

Bases: DataType

Methods:

Source code in src/irx/astx/classes.py
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
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 src/irx/astx/classes.py
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
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,
    )

ClassConstruct

ClassConstruct(class_name: str)

Bases: DataType

Methods:

Source code in src/irx/astx/classes.py
248
249
250
251
252
253
254
255
256
257
258
259
260
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 src/irx/astx/classes.py
270
271
272
273
274
275
276
277
278
279
280
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)

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,
    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] kind: type: astx.ASTKind

Methods:

Source code in src/irx/astx/classes.py
112
113
114
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
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,
    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
      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,
    )
    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 src/irx/astx/classes.py
191
192
193
194
195
196
197
198
199
200
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
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)
        }

    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], attrs_dict),
        **cast(dict[str, astx.base.ReprStruct], methods_dict),
    }
    return self._prepare_struct(
        key,
        cast(astx.base.ReprStruct, value),
        simplified,
    )

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 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 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)

MethodCall

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

Bases: DataType

Methods:

Source code in src/irx/astx/classes.py
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
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 src/irx/astx/classes.py
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
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,
    )

StaticFieldAccess

StaticFieldAccess(class_name: str, field_name: str)

Bases: DataType

Methods:

Source code in src/irx/astx/classes.py
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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 src/irx/astx/classes.py
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
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,
    )

StaticMethodCall

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

Bases: DataType

Methods:

Source code in src/irx/astx/classes.py
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
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 src/irx/astx/classes.py
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
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,
    )