Skip to content

factories

Build semantic sidecar entities and visible binding wrappers in one place so analyzer visitors can focus on traversal and rule orchestration.

Classes:

SemanticEntityFactory

SemanticEntityFactory(context: SemanticContext)

Create semantic symbols, functions, structs, modules, and visible bindings with consistent ids and qualified names. attributes: context: type: SemanticContext

Methods:

Source code in src/irx/analysis/factories.py
58
59
60
61
62
63
64
65
def __init__(self, context: SemanticContext) -> None:
    """
    title: Initialize SemanticEntityFactory.
    parameters:
      context:
        type: SemanticContext
    """
    self.context = context

make_callable_resolution

make_callable_resolution(
    function: SemanticFunction,
) -> CallableResolution
Source code in src/irx/analysis/factories.py
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def make_callable_resolution(
    self,
    function: SemanticFunction,
) -> CallableResolution:
    """
    title: Create one resolved callable wrapper.
    parameters:
      function:
        type: SemanticFunction
    returns:
      type: CallableResolution
    """
    return CallableResolution(
        function=function,
        signature=function.signature,
    )

make_class

make_class(
    module_key: ModuleKey, node: ClassDefStmt
) -> SemanticClass
Source code in src/irx/analysis/factories.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def make_class(
    self,
    module_key: ModuleKey,
    node: astx.ClassDefStmt,
) -> SemanticClass:
    """
    title: Create one semantic class entity.
    parameters:
      module_key:
        type: ModuleKey
      node:
        type: astx.ClassDefStmt
    returns:
      type: SemanticClass
    """
    return SemanticClass(
        symbol_id=self.context.next_symbol_id("class"),
        name=node.name,
        module_key=module_key,
        qualified_name=qualified_class_name(module_key, node.name),
        declaration=node,
    )

make_class_binding

make_class_binding(
    class_: SemanticClass,
) -> SemanticBinding
Source code in src/irx/analysis/factories.py
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def make_class_binding(
    self,
    class_: SemanticClass,
) -> SemanticBinding:
    """
    title: Create a visible binding for a class.
    parameters:
      class_:
        type: SemanticClass
    returns:
      type: SemanticBinding
    """
    return SemanticBinding(
        kind="class",
        module_key=class_.module_key,
        qualified_name=class_.qualified_name,
        class_=class_,
    )

make_class_member

make_class_member(
    class_: SemanticClass,
    *,
    name: str,
    kind: ClassMemberKind,
    declaration: AST,
    visibility: VisibilityKind,
    is_static: bool,
    is_constant: bool,
    is_mutable: bool,
    type_: DataType | None = None,
    signature: FunctionSignature | None = None,
    signature_key: str | None = None,
    overrides: str | None = None,
    dispatch_slot: int | None = None,
    lowered_function: SemanticFunction | None = None,
) -> SemanticClassMember
Source code in src/irx/analysis/factories.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
def make_class_member(
    self,
    class_: SemanticClass,
    *,
    name: str,
    kind: ClassMemberKind,
    declaration: astx.AST,
    visibility: astx.VisibilityKind,
    is_static: bool,
    is_constant: bool,
    is_mutable: bool,
    type_: astx.DataType | None = None,
    signature: FunctionSignature | None = None,
    signature_key: str | None = None,
    overrides: str | None = None,
    dispatch_slot: int | None = None,
    lowered_function: SemanticFunction | None = None,
) -> SemanticClassMember:
    """
    title: Create one semantic class-member record.
    parameters:
      class_:
        type: SemanticClass
      name:
        type: str
      kind:
        type: ClassMemberKind
      declaration:
        type: astx.AST
      visibility:
        type: astx.VisibilityKind
      is_static:
        type: bool
      is_constant:
        type: bool
      is_mutable:
        type: bool
      type_:
        type: astx.DataType | None
      signature:
        type: FunctionSignature | None
      signature_key:
        type: str | None
      overrides:
        type: str | None
      dispatch_slot:
        type: int | None
      lowered_function:
        type: SemanticFunction | None
    returns:
      type: SemanticClassMember
    """
    prefix = (
        "class_attr"
        if kind is ClassMemberKind.ATTRIBUTE
        else "class_method"
    )
    return SemanticClassMember(
        symbol_id=self.context.next_symbol_id(prefix),
        name=name,
        qualified_name=qualified_class_member_name(
            class_.module_key,
            class_.name,
            name,
            signature_key if kind is ClassMemberKind.METHOD else None,
        ),
        owner_name=class_.name,
        owner_qualified_name=class_.qualified_name,
        kind=kind,
        visibility=visibility,
        is_static=is_static,
        is_constant=is_constant,
        is_mutable=is_mutable,
        declaration=declaration,
        type_=clone_type(type_) if type_ is not None else None,
        signature=signature,
        signature_key=signature_key,
        overrides=overrides,
        dispatch_slot=dispatch_slot,
        lowered_function=lowered_function,
    )

make_function

make_function(
    module_key: ModuleKey,
    prototype: FunctionPrototype,
    *,
    signature: FunctionSignature,
    definition: FunctionDef | None = None,
    args: tuple[SemanticSymbol, ...] | None = None,
) -> SemanticFunction
Source code in src/irx/analysis/factories.py
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
232
233
234
def make_function(
    self,
    module_key: ModuleKey,
    prototype: astx.FunctionPrototype,
    *,
    signature: FunctionSignature,
    definition: astx.FunctionDef | None = None,
    args: tuple[SemanticSymbol, ...] | None = None,
) -> SemanticFunction:
    """
    title: Create one semantic function entity.
    parameters:
      module_key:
        type: ModuleKey
      prototype:
        type: astx.FunctionPrototype
      signature:
        type: FunctionSignature
      definition:
        type: astx.FunctionDef | None
      args:
        type: tuple[SemanticSymbol, Ellipsis] | None
    returns:
      type: SemanticFunction
    """
    semantic_args = args
    if semantic_args is None:
        semantic_args = tuple(
            self.make_parameter_symbol(module_key, argument)
            for argument in prototype.args.nodes
        )
    return SemanticFunction(
        symbol_id=self.context.next_symbol_id("fn"),
        name=prototype.name,
        return_type=clone_type(signature.return_type),
        args=semantic_args,
        signature=signature,
        prototype=prototype,
        definition=definition,
        module_key=module_key,
        qualified_name=qualified_function_name(module_key, prototype.name),
    )

make_function_binding

make_function_binding(
    function: SemanticFunction,
) -> SemanticBinding
Source code in src/irx/analysis/factories.py
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
def make_function_binding(
    self,
    function: SemanticFunction,
) -> SemanticBinding:
    """
    title: Create a visible binding for a function.
    parameters:
      function:
        type: SemanticFunction
    returns:
      type: SemanticBinding
    """
    return SemanticBinding(
        kind="function",
        module_key=function.module_key,
        qualified_name=function.qualified_name,
        function=function,
    )

make_function_signature

make_function_signature(
    prototype: FunctionPrototype,
    *,
    calling_convention: CallingConvention,
    is_variadic: bool,
    is_extern: bool,
    symbol_name: str,
    required_runtime_features: tuple[str, ...] = (),
    ffi: FFICallableInfo | None = None,
) -> FunctionSignature
Source code in src/irx/analysis/factories.py
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
def make_function_signature(
    self,
    prototype: astx.FunctionPrototype,
    *,
    calling_convention: CallingConvention,
    is_variadic: bool,
    is_extern: bool,
    symbol_name: str,
    required_runtime_features: tuple[str, ...] = (),
    ffi: FFICallableInfo | None = None,
) -> FunctionSignature:
    """
    title: Create one canonical semantic function signature.
    parameters:
      prototype:
        type: astx.FunctionPrototype
      calling_convention:
        type: CallingConvention
      is_variadic:
        type: bool
      is_extern:
        type: bool
      symbol_name:
        type: str
      required_runtime_features:
        type: tuple[str, Ellipsis]
      ffi:
        type: FFICallableInfo | None
    returns:
      type: FunctionSignature
    """
    return FunctionSignature(
        name=prototype.name,
        parameters=tuple(
            self.make_parameter_spec(argument)
            for argument in prototype.args.nodes
        ),
        return_type=clone_type(prototype.return_type),
        calling_convention=calling_convention,
        is_variadic=is_variadic,
        is_extern=is_extern,
        symbol_name=symbol_name,
        required_runtime_features=required_runtime_features,
        ffi=ffi,
    )

make_import_binding

make_import_binding(
    *,
    local_name: str,
    requested_name: str,
    source_module_key: ModuleKey,
    binding: SemanticBinding,
) -> ResolvedImportBinding
Source code in src/irx/analysis/factories.py
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
def make_import_binding(
    self,
    *,
    local_name: str,
    requested_name: str,
    source_module_key: ModuleKey,
    binding: SemanticBinding,
) -> ResolvedImportBinding:
    """
    title: Create one resolved import binding record.
    parameters:
      local_name:
        type: str
      requested_name:
        type: str
      source_module_key:
        type: ModuleKey
      binding:
        type: SemanticBinding
    returns:
      type: ResolvedImportBinding
    """
    return ResolvedImportBinding(
        local_name=local_name,
        requested_name=requested_name,
        source_module_key=source_module_key,
        binding=binding,
    )

make_module

make_module(
    module_key: ModuleKey,
    *,
    display_name: str | None = None,
) -> SemanticModule
Source code in src/irx/analysis/factories.py
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
def make_module(
    self,
    module_key: ModuleKey,
    *,
    display_name: str | None = None,
) -> SemanticModule:
    """
    title: Create one semantic module entity.
    parameters:
      module_key:
        type: ModuleKey
      display_name:
        type: str | None
    returns:
      type: SemanticModule
    """
    return SemanticModule(
        module_key=module_key,
        display_name=display_name,
    )

make_module_binding

make_module_binding(
    module: SemanticModule,
) -> SemanticBinding
Source code in src/irx/analysis/factories.py
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
def make_module_binding(
    self,
    module: SemanticModule,
) -> SemanticBinding:
    """
    title: Create a visible binding for a module.
    parameters:
      module:
        type: SemanticModule
    returns:
      type: SemanticBinding
    """
    return SemanticBinding(
        kind="module",
        module_key=module.module_key,
        qualified_name=str(module.module_key),
        module=module,
    )

make_parameter_spec

make_parameter_spec(argument: Argument) -> ParameterSpec
Source code in src/irx/analysis/factories.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
def make_parameter_spec(
    self,
    argument: astx.Argument,
) -> ParameterSpec:
    """
    title: Create one canonical semantic parameter specification.
    parameters:
      argument:
        type: astx.Argument
    returns:
      type: ParameterSpec
    """
    return ParameterSpec(
        name=argument.name,
        type_=clone_type(argument.type_),
        passing_kind=ParameterPassingKind.BY_VALUE,
    )

make_parameter_symbol

make_parameter_symbol(
    module_key: ModuleKey, argument: Argument
) -> SemanticSymbol
Source code in src/irx/analysis/factories.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
def make_parameter_symbol(
    self,
    module_key: ModuleKey,
    argument: astx.Argument,
) -> SemanticSymbol:
    """
    title: Create one function-parameter semantic symbol.
    parameters:
      module_key:
        type: ModuleKey
      argument:
        type: astx.Argument
    returns:
      type: SemanticSymbol
    """
    return self.make_variable_symbol(
        module_key,
        argument.name,
        argument.type_,
        is_mutable=True,
        declaration=argument,
        kind="argument",
    )

make_struct

make_struct(
    module_key: ModuleKey, node: StructDefStmt
) -> SemanticStruct
Source code in src/irx/analysis/factories.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
def make_struct(
    self,
    module_key: ModuleKey,
    node: astx.StructDefStmt,
) -> SemanticStruct:
    """
    title: Create one semantic struct entity.
    parameters:
      module_key:
        type: ModuleKey
      node:
        type: astx.StructDefStmt
    returns:
      type: SemanticStruct
    """
    return SemanticStruct(
        symbol_id=self.context.next_symbol_id("struct"),
        name=node.name,
        module_key=module_key,
        qualified_name=qualified_struct_name(module_key, node.name),
        declaration=node,
    )

make_struct_binding

make_struct_binding(
    struct: SemanticStruct,
) -> SemanticBinding
Source code in src/irx/analysis/factories.py
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
def make_struct_binding(
    self,
    struct: SemanticStruct,
) -> SemanticBinding:
    """
    title: Create a visible binding for a struct.
    parameters:
      struct:
        type: SemanticStruct
    returns:
      type: SemanticBinding
    """
    return SemanticBinding(
        kind="struct",
        module_key=struct.module_key,
        qualified_name=struct.qualified_name,
        struct=struct,
    )

make_variable_symbol

make_variable_symbol(
    module_key: ModuleKey,
    name: str,
    type_: DataType,
    *,
    is_mutable: bool,
    declaration: AST | None,
    kind: str = "variable",
) -> SemanticSymbol
Source code in src/irx/analysis/factories.py
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def make_variable_symbol(
    self,
    module_key: ModuleKey,
    name: str,
    type_: astx.DataType,
    *,
    is_mutable: bool,
    declaration: astx.AST | None,
    kind: str = "variable",
) -> SemanticSymbol:
    """
    title: Create a variable-like semantic symbol.
    parameters:
      module_key:
        type: ModuleKey
      name:
        type: str
      type_:
        type: astx.DataType
      is_mutable:
        type: bool
      declaration:
        type: astx.AST | None
      kind:
        type: str
    returns:
      type: SemanticSymbol
    """
    return variable_symbol(
        self.context.next_symbol_id(kind),
        module_key,
        name,
        clone_type(type_),
        is_mutable=is_mutable,
        declaration=declaration,
        kind=kind,
    )