Class EnumIteratorGenerator

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

final class EnumIteratorGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for the enum iterator() method.

The iterator() method returns an Iterator of the enumeration type, allowing enumerations to be used in for-in loops:

for colour in Colour
  stdout.println($colour)

This generator produces a high-level ENUM_ITERATOR_IMPL instruction that abstracts the iterator implementation. The backend is responsible for generating the actual iterator class with:

  • Public static fields for each enum value
  • Class initializer to set _ordinal and _name on each value
  • Anonymous iterator class extending the parameterized Iterator type
  • hasNext(), next(), and _isSet() method implementations

This approach allows each backend (JVM, LLVM) to generate optimal code for its target platform without prescribing implementation details in the IR.

  • Constructor Details

  • Method Details

    • generate

      List<IRInstr> generate(MethodSymbol methodSymbol, AggregateSymbol aggregateSymbol)
      Generate the iterator() method for an enumeration.
      Parameters:
      methodSymbol - The iterator method symbol
      aggregateSymbol - The enumeration aggregate containing enum values
      Returns:
      List of IR instructions