Class ControlFlowChainInstr

java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
org.ek9lang.compiler.ir.instructions.ControlFlowChainInstr
All Implemented Interfaces:
CompositeInstr, INode

public final class ControlFlowChainInstr extends IRInstr implements CompositeInstr
Unified IR instruction for all EK9 control flow constructs.

This instruction replaces and unifies the following specialized IR opcodes: - QUESTION_BLOCK (Question operator ?) - ASSIGN_IF_UNSET_BLOCK (Assign-if-unset :=?) - Future: IF_BLOCK, SWITCH_BLOCK constructs

Key architectural benefits: - Single source of truth for all control flow logic - Consistent memory management across all constructs - Enhanced backend optimization opportunities - Reduced IR complexity and maintenance burden

Backends can optimize based on chainType hints and optimization metadata: - QUESTION_OPERATOR: Null check + method call optimization - IF_ELSE/IF_ELSE_IF: Standard conditional branching - SWITCH/SWITCH_ENUM: Jump tables, binary search, or sequential evaluation

  • Method Details

    • controlFlowChain

      public static ControlFlowChainInstr controlFlowChain(ControlFlowChainDetails details)
      Create a unified switch chain block instruction.
    • isLoop

      public boolean isLoop()
      True when this chain is a loop: its condition-chain lists run once per iteration.
    • nestedLists

      public List<CompositeInstr.NestedList> nestedLists()
      Description copied from interface: CompositeInstr
      Every nested list, in the order the IR text renders them. Absent (null) lists are omitted.
      Specified by:
      nestedLists in interface CompositeInstr
    • withNestedLists

      public IRInstr withNestedLists(UnaryOperator<List<IRInstr>> rewrite)
      Description copied from interface: CompositeInstr
      A copy with every nested list replaced by rewrite of it - exactly the lists CompositeInstr.nestedLists() reports, in that order; this when no list changed.
      Specified by:
      withNestedLists in interface CompositeInstr
    • getChainType

      public String getChainType()
      Get the type of control flow construct.
    • getConditionChain

      public List<ConditionCaseDetails> getConditionChain()
      Get the sequential condition chain.
    • getDefaultBodyEvaluation

      public List<IRInstr> getDefaultBodyEvaluation()
      Get the default/else case evaluation instructions.
    • getDefaultResult

      public String getDefaultResult()
      Get the default case result variable.
    • getScopeId

      public String getScopeId()
      Get the scope ID for memory management.
    • getTryBlockDetails

      public TryBlockDetails getTryBlockDetails()
      Get the try block details (for TRY_CATCH_FINALLY).
    • getReturnVariableSetup

      public List<IRInstr> getReturnVariableSetup()
      The instructions that declare/initialise this chain's RETURN variable (the <- rtn <- ... of an expression-form try/switch/if). Exposed because a back end must be able to pre-scan every instruction list the emission walk descends into -- the native cleanup-pad pass hoists an entry-block alloca per SCOPE_REGISTERed object, and a return variable declared here that it could not see got an INLINE alloca that a landingpad above it does not dominate ("instruction does not dominate all uses").
    • getEvaluationVariableSetup

      public List<IRInstr> getEvaluationVariableSetup()
      The instructions that evaluate this chain's control/evaluation variable (a guard's switch v <- ...). Same pre-scan requirement as getReturnVariableSetup().
    • getFinallyBlockEvaluation

      public List<IRInstr> getFinallyBlockEvaluation()
    • hasEvaluationVariable

      public boolean hasEvaluationVariable()
      Check if this construct has an evaluation variable.
    • hasReturnVariable

      public boolean hasReturnVariable()
      Check if this construct has a return variable.
    • hasDefaultCase

      public boolean hasDefaultCase()
      Check if this construct has a default case.
    • toString

      public String toString()
      Overrides:
      toString in class IRInstr