Class EnumIncrementDecrementGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.EnumIncrementDecrementGenerator
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.
-
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(String operatorName, MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol) Generate the ++ or -- operator 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
-
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 symbolaggregateSymbol- The enumeration aggregate containing enum values- Returns:
- List of IR instructions
-