Class CastInstr

java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.CastInstr
All Implemented Interfaces:
INode

public final class CastInstr extends IRInstr
IR instruction for explicit type casting.

Used when the value on the stack needs to be cast to a different type, particularly in Scenario 2 wrapper delegation where the delegate method returns Any but the wrapper method returns a more specific type.

Format: CAST result = source, targetType

Backend translation:

  • JVM: CHECKCAST target_type
  • LLVM: bitcast or no-op (depending on representation)
  • Method Details

    • cast

      public static CastInstr cast(String result, String source, String targetType, DebugInfo debugInfo)
      Create instruction to cast source to target type and store in result.

      Pattern: CAST result = source, targetType

      Parameters:
      result - The variable to store the casted result
      source - The variable containing the value to cast
      targetType - The fully qualified type to cast to
      debugInfo - Debug information for source mapping (can be null)
      Returns:
      CAST instruction
    • cast

      public static CastInstr cast(String result, String source, String targetType)
      Create instruction to cast source to target type and store in result (no debug info).
      Parameters:
      result - The variable to store the casted result
      source - The variable containing the value to cast
      targetType - The fully qualified type to cast to
      Returns:
      CAST instruction
    • getSource

      public String getSource()
      Get the source variable name being casted.
    • getTargetType

      public String getTargetType()
      Get the fully qualified target type to cast to.