Class EnumFirstLastGenerator

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

final class EnumFirstLastGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for the enum #< (first) and #> (last) operators.

Enum fields use Java primitives:

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

These operators return the first/last enum value by constructing a new enum instance with the known primitive ordinal and name:

EnumType _prefix():  // #<
  result = new EnumType()
  result._ordinal = 0       (int primitive)
  result._name = "FIRST_VALUE"  (java.lang.String)
  result._isEnumSet = true  (boolean primitive)
  return result

EnumType _suffix():  // #>
  result = new EnumType()
  result._ordinal = N-1
  result._name = "LAST_VALUE"
  result._isEnumSet = true
  return result

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

  • Constructor Details

  • 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 first, "#>" for last)
      operatorSymbol - The operator method symbol
      aggregateSymbol - The enumeration aggregate containing enum values
      Returns:
      List of IR instructions