Class EnumFirstLastGenerator
java.lang.Object
org.ek9lang.compiler.phase7.synthesis.AbstractSyntheticGenerator
org.ek9lang.compiler.phase7.synthesis.EnumFirstLastGenerator
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.
-
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
-
EnumFirstLastGenerator
EnumFirstLastGenerator(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 first, "#>" for last)operatorSymbol- The operator method symbolaggregateSymbol- The enumeration aggregate containing enum values- Returns:
- List of IR instructions
-