l0_c_cleanup::CCleanup class

Defined in module l0_c_cleanup (l0_c_cleanup.py).

Recursive value cleanup and allocation/ARC runtime operations.

Public static attributes

static CNames names
static CEmitterState state
static CValues values

Public functions

auto emit_value_cleanup(self, str c_expr, Type ty) -> None
Emit C code to clean up an owned by-value variable.
auto emit_struct_cleanup(self, str c_ptr_expr, StructType struct_type) -> None
Emit cleanup code for all owned fields in a struct.
auto emit_enum_cleanup(self, str c_ptr_expr, EnumType enum_type) -> None
Emit cleanup code for owned fields in an enum's active variant.
auto emit_drop_finish_call(self, str c_ptr_expr) -> None
Emit the runtime call that completes a generated drop.
auto emit_string_retain(self, str c_expr) -> None
Emit an ARC string retain runtime call.
auto emit_string_release(self, str c_expr) -> None
Emit an ARC string release runtime call.
auto emit_alloc_obj(self, str c_ptr_type, str c_base_type, str c_temp_name) -> None
Emit a heap allocation runtime call.

Protected functions

auto _emit_cleanup_by_type(self, str c_expr, Type ty) -> None
Emit recursive cleanup code for any ARC-managed data inside a type.
auto _emit_enum_value_cleanup(self, str c_expr, EnumType enum_type) -> None
Emit C cleanup code for an enum by-value variable.
auto _emit_enum_cleanup_switch(self, EnumType enum_type, str c_tag_expr, Callable[[str, str], str] field_expr_for_variant_field, *bool missing_info_is_ice) -> None
Emit a cleanup switch over the active variant of an enum value.
auto _iter_variant_cleanup_fields(self, EnumType enum_type, str variant_name, list variant_field_types[Type]) -> list[tuple[str, Type]]
Pair variant field names with their resolved field types.
auto _enum_has_arc_data(self, EnumInfo enum_info) -> bool
Report whether any enum payload field requires ARC-aware cleanup.
auto _emit_field_cleanup(self, str field_expr, Type field_type) -> None
Emit recursive cleanup for a field.

Function documentation

None l0_c_cleanup::CCleanup::emit_value_cleanup(self, str c_expr, Type ty)

Emit C code to clean up an owned by-value variable.

Parameters
c_expr C expression evaluating to the value.
ty The L0 Type of the value.

None l0_c_cleanup::CCleanup::emit_struct_cleanup(self, str c_ptr_expr, StructType struct_type)

Emit cleanup code for all owned fields in a struct.

Parameters
c_ptr_expr C expression evaluating to a pointer to the struct.
struct_type The L0 struct type.

None l0_c_cleanup::CCleanup::emit_enum_cleanup(self, str c_ptr_expr, EnumType enum_type)

Emit cleanup code for owned fields in an enum's active variant.

Parameters
c_ptr_expr C expression evaluating to a pointer to the enum.
enum_type The L0 enum type.

None l0_c_cleanup::CCleanup::emit_string_retain(self, str c_expr)

Emit an ARC string retain runtime call.

Parameters
c_expr C expression evaluating to an l0_string.

None l0_c_cleanup::CCleanup::emit_string_release(self, str c_expr)

Emit an ARC string release runtime call.

Parameters
c_expr C expression evaluating to an l0_string.

None l0_c_cleanup::CCleanup::emit_alloc_obj(self, str c_ptr_type, str c_base_type, str c_temp_name)

Emit a heap allocation runtime call.

Parameters
c_ptr_type C pointer type string.
c_base_type C base object type string.
c_temp_name Name of temporary to hold the pointer.

None l0_c_cleanup::CCleanup::_emit_cleanup_by_type(self, str c_expr, Type ty) protected

Emit recursive cleanup code for any ARC-managed data inside a type.

Parameters
c_expr C expression evaluating to the by-value object to clean up.
ty The L0 type describing c_expr.

None l0_c_cleanup::CCleanup::_emit_enum_cleanup_switch(self, EnumType enum_type, str c_tag_expr, Callable[[str, str], str] field_expr_for_variant_field, *bool missing_info_is_ice) protected

Emit a cleanup switch over the active variant of an enum value.

Parameters
enum_type Enum type whose payload cleanup is being emitted.
c_tag_expr C expression yielding the enum tag to switch on.
field_expr_for_variant_field Callback that maps variant and field names to the corresponding C lvalue expression.
missing_info_is_ice Whether missing enum metadata should raise an internal compiler error.

list[tuple[str, Type]] l0_c_cleanup::CCleanup::_iter_variant_cleanup_fields(self, EnumType enum_type, str variant_name, list variant_field_types[Type]) protected

Pair variant field names with their resolved field types.

Parameters
enum_type Enum type owning the variant.
variant_name Variant whose fields are being cleaned up.
variant_field_types Resolved payload field types for the variant.
Returns A list of "(field_name, field_type)" pairs, or an empty list when the AST declaration cannot be matched to the resolved payload types.

bool l0_c_cleanup::CCleanup::_enum_has_arc_data(self, EnumInfo enum_info) protected

Report whether any enum payload field requires ARC-aware cleanup.

Parameters
enum_info Resolved enum metadata to inspect.
Returns True if any variant payload contains ARC-managed data.