Class EnumIncrementDecrementGenerator

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

final class EnumIncrementDecrementGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for the enum ++ (_inc) and -- (_dec) operators.

Enum fields use Java primitives:

  • _ordinal: int (primitive)
  • _name: java.lang.String
  • _isEnumSet: boolean (primitive)

These operators enable navigation between enum values by mutating in place:

  • ++ (increment): Mutates to the next enum value, or unsets if at the last value
  • -- (decrement): Mutates to the previous enum value, or unsets if at the first value

The generated IR follows this pattern for ++ (increment):

void _inc():
  if !this._isSet() -> return (no-op)
  ordinal = this._ordinal (int primitive)

  // Each case mutates to the NEXT enum value
  if ordinal == 0:     // Red++
    this._ordinal = 1
    this._name = "Green"
    return
  if ordinal == 1:     // Green++
    this._ordinal = 2
    this._name = "Blue"
    return

  // BOUNDARY: Blue++ -> unset this
  this._isEnumSet = false
  return

The enum values and their ordinals are known at compile time from the ConstantSymbol instances in the enumeration's scope.

  • Constructor Details

    • EnumIncrementDecrementGenerator

      EnumIncrementDecrementGenerator(IRGenerationContext stackContext)
  • Method Details

    • generate

      List<IRInstr> generate(String operatorName, MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol)
      Generate the ++ or -- operator for an enumeration.
      Parameters:
      operatorName - The operator symbol ("++" for increment, "--" for decrement)
      operatorSymbol - The operator method symbol
      aggregateSymbol - The enumeration aggregate containing enum values
      Returns:
      List of IR instructions