Class DelegationGenerator

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

final class DelegationGenerator extends AbstractSyntheticGenerator
Generates synthetic IR for trait delegation methods.

When a class delegates a trait to a field (e.g., "with trait of Processor by proc"), the compiler creates synthetic wrapper methods that forward calls to the delegate field. This generator creates the IR for those forwarding methods.

The generated code follows this pattern:

ReturnType methodName(params...):
  delegate = this.delegateFieldName  // Load delegate field
  result = delegate.methodName(params...)  // Forward call
  return result  // Return delegate's result

For void methods:

Void methodName(params...):
  delegate = this.delegateFieldName
  delegate.methodName(params...)
  return
  • Constructor Details

  • Method Details

    • generate

      List<IRInstr> generate(MethodSymbol methodSymbol, AggregateSymbol aggregateSymbol)
      Generate delegation IR for a synthetic delegation method.
      Parameters:
      methodSymbol - The delegation method symbol
      aggregateSymbol - The aggregate containing the method
      Returns:
      List of IR instructions implementing the delegation