Class ControlFlowChainGenerator

java.lang.Object
org.ek9lang.compiler.phase7.ControlFlowChainGenerator
All Implemented Interfaces:
Function<ControlFlowChainDetails,List<IRInstr>>

public final class ControlFlowChainGenerator extends Object implements Function<ControlFlowChainDetails,List<IRInstr>>
Unified generator for all EK9 control flow constructs using CONTROL_FLOW_CHAIN.

This generator replaces multiple specialized generators: - QuestionBlockGenerator → generateQuestionOperator() - GuardedAssignmentBlockGenerator → generateGuardedAssignment() - Future: If/else and switch statement generators

Key architectural benefits: - Single source of truth for all control flow logic - Consistent memory management patterns across all constructs - Unified optimization metadata for backend code generation - Reduced code duplication and maintenance burden

  • Constructor Details

  • Method Details

    • apply

      public List<IRInstr> apply(ControlFlowChainDetails details)
      Specified by:
      apply in interface Function<ControlFlowChainDetails,List<IRInstr>>
    • generateQuestionOperator

      public List<IRInstr> generateQuestionOperator(ExprProcessingDetails exprDetails)
      Generate SWITCH_CHAIN_BLOCK for Question operator (?). Converts "operand?" to a two-case chain: null check + _isSet() default. Question operator is self-contained - no RETAIN/SCOPE_REGISTER needed on input.
    • generateQuestionOperatorForVariable

      public List<IRInstr> generateQuestionOperatorForVariable(ISymbol variableSymbol, String resultVariable, BasicDetails basicDetails)
      Generate SWITCH_CHAIN_BLOCK for Question operator applied to a variable. Used by guarded assignment composition.
    • generateGuardedAssignment

      public List<IRInstr> generateGuardedAssignment(ISymbol lhsSymbol, List<IRInstr> assignmentEvaluation, String assignmentResult, BasicDetails basicDetails)
      Generate SWITCH_CHAIN_BLOCK for guarded assignment (:=?). Composes question operator logic: assign only if LHS is null OR !LHS._isSet().