Class PromotionCallGenerator

java.lang.Object
org.ek9lang.compiler.phase7.support.PromotionCallGenerator
All Implemented Interfaces:
Function<PromotionParams, PromotedVariable>

public final class PromotionCallGenerator extends Object implements Function<PromotionParams, PromotedVariable>
CONCERN: Type promotion call generation using the #^ operator. RESPONSIBILITY: Generate IR instructions to call _promote() with ARC compliance. REUSABILITY: Assignment promotion, parameter promotion, any context requiring type coercion.

Encapsulates the pattern: 1. Look up return type of #^ operator on source type 2. Create CallDetails for _promote() call 3. Execute operator call 4. Apply memory management (RETAIN/SCOPE_REGISTER)

Type promotion occurs when a value of one type needs to be converted to a compatible type (e.g., Integer to Float, Character to String). The #^ operator maps to the _promote() method on the source type.

  • Constructor Details

  • Method Details

    • apply

      public PromotedVariable apply(PromotionParams params)
      Generate IR instructions to call the #^ promotion operator on a variable.
      Specified by:
      apply in interface Function<PromotionParams, PromotedVariable>
      Parameters:
      params - Promotion parameters containing source type, variable, and debug info
      Returns:
      PromotedVariable containing the new variable name and promotion instructions
    • getPromotedType

      public ISymbol getPromotedType(ISymbol sourceType)
      Get the type that results from promoting the given type using #^. This looks up the return type of the #^ method on the source type.
      Parameters:
      sourceType - The type to be promoted
      Returns:
      The type that results from promotion
      Throws:
      CompilerException - if the type does not have a _promote method