Class EnumConstructorGenerator

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

final class EnumConstructorGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for enum constructors (copy and String).

The default no-arg constructor is handled by AbstractDfnGenerator.processSyntheticConstructor. This generator handles the two parameterized constructors:

Enum fields use Java primitives:

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

Copy constructor EnumType(EnumType param):

  this._ordinal = param._ordinal  (int primitive)
  this._name = param._name        (java.lang.String)
  this._isEnumSet = param._isEnumSet  (boolean primitive)

String constructor EnumType(String param):

  // For each known enum value:
  if param._eq("VALUE_NAME"):
    this._ordinal = ordinal_literal  (int primitive)
    this._name = "VALUE_NAME"        (java.lang.String)
    this._isEnumSet = true           (boolean primitive)
    return
  // If no match: leave unset (_isEnumSet = false from default constructor)
  • Constructor Details

  • Method Details

    • generate

      List<IRInstr> generate(MethodSymbol constructorSymbol, AggregateSymbol aggregateSymbol)
      Generate a parameterized enum constructor.
      Parameters:
      constructorSymbol - The constructor method symbol
      aggregateSymbol - The enumeration aggregate
      Returns:
      List of IR instructions