Class ToStringGenerator

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

final class ToStringGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for the _string ($) operator.

The generated code follows this pattern:

String _string():
  result = "ClassName("
  needsSeparator = false

  // For each field:
  if field._isSet():
    if needsSeparator:
      result = result + ", "
    result = result + "fieldName="
    result = result + field.$()
    needsSeparator = true
  else:
    if needsSeparator:
      result = result + ", "
    result = result + "fieldName=?"
    needsSeparator = true

  result = result + ")"
  return result

Key semantic requirements:

  • Returns String (always set)
  • Format: "ClassName(field1=value1, field2=value2)"
  • SET fields show their string value via $
  • UNSET fields show "?" as placeholder
  • Uses simple class name (not fully qualified)
  • Constructor Details

  • Method Details

    • generate

      List<IRInstr> generate(MethodSymbol operatorSymbol, AggregateSymbol aggregateSymbol)
      Generate the _string operator IR for the given aggregate.
      Parameters:
      operatorSymbol - The _string operator symbol
      aggregateSymbol - The aggregate containing the operator
      Returns:
      List of IR instructions implementing the operator