Class FieldSetStatusGenerator

java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.FieldSetStatusGenerator

final class FieldSetStatusGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for the _fieldSetStatus() method.

This method returns a Bits value where each bit represents whether a field is set (1) or not set (0). The bit position corresponds to the field's declaration order:

  • Bit 0 = field 0 status
  • Bit 1 = field 1 status
  • Bit N = field N status

Using Bits instead of Integer removes the 32-field limit and provides a cleaner API for checking field status.

The generated code follows this pattern:

Bits _fieldSetStatus():
  result = Bits()    // Empty Bits (set but with 0 bits)

  // For each field:
  isSet = field._isSet()
  result._addAss(isSet)  // Append bit: result += isSet

  return result

Callers can use:

  • status._eq(other) - compare if two objects have identical set fields
  • status._empty() - check if no fields are set
  • status._xor(other) - find fields set differently

This approach enables:

  • Unlimited field count (no 32-field limit)
  • Efficient field status comparison with single method call
  • IR optimizer can cache results across expressions

Note: EK9 guarantees fields are always initialized (to unset values), so null checks are not needed. The _isSet() call handles the tri-state semantics (absent/unset/set) at the type level.

See Also:
  • Constructor Details

  • Method Details

    • generate

      List<IRInstr> generate(MethodSymbol methodSymbol, AggregateSymbol aggregateSymbol)
      Generate the _fieldSetStatus method IR for the given aggregate.
      Parameters:
      methodSymbol - The _fieldSetStatus method symbol
      aggregateSymbol - The aggregate containing the method
      Returns:
      List of IR instructions implementing the method