Class EnumIteratorGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.EnumIteratorGenerator
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractSyntheticGenerator
AbstractSyntheticGenerator.ScopeSetup -
Field Summary
Fields inherited from class AbstractSyntheticGenerator
stackContext -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongenerate(MethodSymbol methodSymbol, AggregateSymbol aggregateSymbol) Generate the iterator() method for an enumeration.Methods inherited from class AbstractSyntheticGenerator
aggregateHasOperator, createDebugInfo, createSynthesisScope, generateAnyFieldSetGuard, generateBinaryOperatorGuards, generateBooleanBranch, generateBooleanReturnBlock, generateConstructorCall, generateConstructorCall, generateConstructorCall, generateConstructorCallWithArgs, generateFieldLoad, generateFieldLoad, generateFieldSetStatusCheck, generateIsSetGuard, generateIsSetGuard, generateLabelName, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCall, generateMethodCallNoArg, generateResultReturnBlock, generateResultReturnBlock, generateStringLiteralLoad, generateTempName, generateThisIsSetGuard, generateThisIsSetGuard, generateUnsetReturnBlock, generateUnsetReturnBlockWithLabel, generateUnsetReturnBlockWithLabel, generateVoidMethodCall, getBitsTypeName, getBooleanTypeName, getIntegerTypeName, getReturnBlockHelper, getStringTypeName, getSuperTypeName, getSyntheticFields, getTypeName, getVoidTypeName, initializeScope, initializeScopeNoReturn, isAnyType, isTraitType, superHasOperator
-
Constructor Details
-
EnumIteratorGenerator
EnumIteratorGenerator(IRGenerationContext stackContext)
-
-
Method Details
-
generate
Generate the iterator() method for an enumeration.- Parameters:
methodSymbol- The iterator method symbolaggregateSymbol- The enumeration aggregate containing enum values- Returns:
- List of IR instructions
-